blob: b1c01910f6f1b5c41bae03430150247236cc2b88 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  | 
//===-- SparcV9CodeEmitter.h ------------------------------------*- C++ -*-===//
// 
//
//===----------------------------------------------------------------------===//
#ifndef SPARCV9CODEEMITTER_H
#define SPARCV9CODEEMITTER_H
#include "llvm/BasicBlock.h"
#include "llvm/CodeGen/MachineCodeEmitter.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/Target/TargetMachine.h"
class GlobalValue;
class MachineInstr;
class MachineOperand;
class SparcV9CodeEmitter : public MachineFunctionPass {
  TargetMachine &TM;
  MachineCodeEmitter &MCE;
  const BasicBlock *currBB;
  // Tracks which instruction references which BasicBlock
  std::vector<std::pair<const BasicBlock*,
                        std::pair<unsigned*,MachineInstr*> > > BBRefs;
  // Tracks where each BasicBlock starts
  std::map<const BasicBlock*, long> BBLocations;
  // Tracks locations of Constants which are laid out in memory (e.g. FP)
  // But we also need to map Constants to ConstantPool indices
  std::map<const Constant*, unsigned> ConstantMap;
public:
  SparcV9CodeEmitter(TargetMachine &T, MachineCodeEmitter &M);
  ~SparcV9CodeEmitter();
  /// runOnMachineFunction - emits the given machine function to memory.
  ///
  bool runOnMachineFunction(MachineFunction &F);
  /// emitWord - writes out the given 32-bit value to memory at the current PC.
  ///
  void emitWord(unsigned Val);
    
  /// getBinaryCodeForInstr - This function, generated by the
  /// CodeEmitterGenerator using TableGen, produces the binary encoding for
  /// machine instructions.
  ///
  unsigned getBinaryCodeForInstr(MachineInstr &MI);
  /// emitFarCall - produces a code sequence to make a call to a destination
  /// that does not fit in the 30 bits that a call instruction allows.
  ///
  void emitFarCall(uint64_t Addr);
private:    
  /// getMachineOpValue - 
  ///
  int64_t getMachineOpValue(MachineInstr &MI, MachineOperand &MO);
  /// emitBasicBlock - 
  ///
  void emitBasicBlock(MachineBasicBlock &MBB);
  /// getValueBit - 
  ///
  unsigned getValueBit(int64_t Val, unsigned bit);
  /// getGlobalAddress - 
  ///
  void* getGlobalAddress(GlobalValue *V, MachineInstr &MI,
                         bool isPCRelative);
  /// emitFarCall - 
  ///
  unsigned getRealRegNum(unsigned fakeReg, MachineInstr &MI);
};
#endif
  |