Changes For Bug 352
[oota-llvm.git] / lib / Target / SparcV9 / SparcV9CodeEmitter.h
1 //===-- SparcV9CodeEmitter.h ------------------------------------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 // 
10 // Target-specific portions of the machine code emitter for the SparcV9.
11 // This class interfaces with the JIT's Emitter in order to turn MachineInstrs
12 // into words of binary machine code. Its code is partially generated by
13 // TableGen's CodeEmitterGenerator.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef SPARCV9CODEEMITTER_H
18 #define SPARCV9CODEEMITTER_H
19
20 #include "llvm/BasicBlock.h"
21 #include "llvm/CodeGen/MachineCodeEmitter.h"
22 #include "llvm/CodeGen/MachineFunctionPass.h"
23 #include "llvm/Target/TargetMachine.h"
24
25 namespace llvm {
26
27 class GlobalValue;
28 class MachineInstr;
29 class MachineOperand;
30
31 class SparcV9CodeEmitter : public MachineFunctionPass {
32   TargetMachine &TM;
33   MachineCodeEmitter &MCE;
34   const BasicBlock *currBB;
35
36   // Tracks which instruction references which BasicBlock
37   std::vector<std::pair<const BasicBlock*,
38                         std::pair<unsigned*,MachineInstr*> > > BBRefs;
39   // Tracks where each BasicBlock starts
40   std::map<const BasicBlock*, long> BBLocations;
41
42 public:
43   SparcV9CodeEmitter(TargetMachine &T, MachineCodeEmitter &M);
44   ~SparcV9CodeEmitter();
45
46   const char *getPassName() const { return "SparcV9 Machine Code Emitter"; }
47
48   /// runOnMachineFunction - emits the given machine function to memory.
49   ///
50   bool runOnMachineFunction(MachineFunction &F);
51
52   /// emitWord - writes out the given 32-bit value to memory at the current PC.
53   ///
54   void emitWord(unsigned Val);
55     
56   /// getBinaryCodeForInstr - This function, generated by the
57   /// CodeEmitterGenerator using TableGen, produces the binary encoding for
58   /// machine instructions.
59   ///
60   unsigned getBinaryCodeForInstr(MachineInstr &MI);
61
62   /// emitFarCall - produces a code sequence to make a call to a destination
63   /// that does not fit in the 30 bits that a call instruction allows.
64   /// If the function F is non-null, this also saves the return address in
65   /// the LazyResolver map of the JITResolver.
66   void emitFarCall(uint64_t Addr, Function *F = 0);
67
68 private:    
69   /// getMachineOpValue - 
70   ///
71   int64_t getMachineOpValue(MachineInstr &MI, MachineOperand &MO);
72
73   /// emitBasicBlock - 
74   ///
75   void emitBasicBlock(MachineBasicBlock &MBB);
76
77   /// getValueBit - 
78   ///
79   unsigned getValueBit(int64_t Val, unsigned bit);
80
81   /// getGlobalAddress - 
82   ///
83   void* getGlobalAddress(GlobalValue *V, MachineInstr &MI,
84                          bool isPCRelative);
85   /// emitFarCall - 
86   ///
87   unsigned getRealRegNum(unsigned fakeReg, MachineInstr &MI);
88
89 };
90
91 } // End llvm namespace
92
93 #endif