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