Misha Brukman | a9f7f6e | 2003-05-30 20:17:33 +0000 | [diff] [blame] | 1 | //===-- SparcV9CodeEmitter.h ------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // |
| 4 | //===----------------------------------------------------------------------===// |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 5 | |
| 6 | #ifndef SPARCV9CODEEMITTER_H |
| 7 | #define SPARCV9CODEEMITTER_H |
| 8 | |
Misha Brukman | 0d60345 | 2003-05-27 22:41:44 +0000 | [diff] [blame] | 9 | #include "llvm/BasicBlock.h" |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 10 | #include "llvm/CodeGen/MachineCodeEmitter.h" |
| 11 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Misha Brukman | a9f7f6e | 2003-05-30 20:17:33 +0000 | [diff] [blame] | 12 | #include "llvm/Target/TargetMachine.h" |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 13 | |
Misha Brukman | f86aaa8 | 2003-06-02 04:12:39 +0000 | [diff] [blame] | 14 | class GlobalValue; |
| 15 | class MachineInstr; |
| 16 | class MachineOperand; |
| 17 | |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 18 | class SparcV9CodeEmitter : public MachineFunctionPass { |
Misha Brukman | a2196c1 | 2003-06-04 20:01:13 +0000 | [diff] [blame] | 19 | TargetMachine &TM; |
| 20 | MachineCodeEmitter &MCE; |
Chris Lattner | 6856d11 | 2003-07-26 23:04:00 +0000 | [diff] [blame] | 21 | const BasicBlock *currBB; |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 22 | |
Misha Brukman | f86aaa8 | 2003-06-02 04:12:39 +0000 | [diff] [blame] | 23 | // Tracks which instruction references which BasicBlock |
Chris Lattner | 6856d11 | 2003-07-26 23:04:00 +0000 | [diff] [blame] | 24 | std::vector<std::pair<const BasicBlock*, |
Misha Brukman | f86aaa8 | 2003-06-02 04:12:39 +0000 | [diff] [blame] | 25 | std::pair<unsigned*,MachineInstr*> > > BBRefs; |
| 26 | // Tracks where each BasicBlock starts |
Chris Lattner | 6856d11 | 2003-07-26 23:04:00 +0000 | [diff] [blame] | 27 | std::map<const BasicBlock*, long> BBLocations; |
Misha Brukman | a2196c1 | 2003-06-04 20:01:13 +0000 | [diff] [blame] | 28 | |
Misha Brukman | f86aaa8 | 2003-06-02 04:12:39 +0000 | [diff] [blame] | 29 | // Tracks locations of Constants which are laid out in memory (e.g. FP) |
Misha Brukman | a2196c1 | 2003-06-04 20:01:13 +0000 | [diff] [blame] | 30 | // But we also need to map Constants to ConstantPool indices |
| 31 | std::map<const Constant*, unsigned> ConstantMap; |
Misha Brukman | f86aaa8 | 2003-06-02 04:12:39 +0000 | [diff] [blame] | 32 | |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 33 | public: |
Misha Brukman | a2196c1 | 2003-06-04 20:01:13 +0000 | [diff] [blame] | 34 | SparcV9CodeEmitter(TargetMachine &T, MachineCodeEmitter &M); |
| 35 | ~SparcV9CodeEmitter(); |
Misha Brukman | a9f7f6e | 2003-05-30 20:17:33 +0000 | [diff] [blame] | 36 | |
Misha Brukman | a21b8e8 | 2003-07-29 20:52:56 +0000 | [diff] [blame] | 37 | /// runOnMachineFunction - emits the given machine function to memory. |
| 38 | /// |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 39 | bool runOnMachineFunction(MachineFunction &F); |
Misha Brukman | a21b8e8 | 2003-07-29 20:52:56 +0000 | [diff] [blame] | 40 | |
| 41 | /// emitWord - writes out the given 32-bit value to memory at the current PC. |
| 42 | /// |
Misha Brukman | a2196c1 | 2003-06-04 20:01:13 +0000 | [diff] [blame] | 43 | void emitWord(unsigned Val); |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 44 | |
Misha Brukman | a21b8e8 | 2003-07-29 20:52:56 +0000 | [diff] [blame] | 45 | /// getBinaryCodeForInstr - This function, generated by the |
| 46 | /// CodeEmitterGenerator using TableGen, produces the binary encoding for |
| 47 | /// machine instructions. |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 48 | /// |
Misha Brukman | f86aaa8 | 2003-06-02 04:12:39 +0000 | [diff] [blame] | 49 | unsigned getBinaryCodeForInstr(MachineInstr &MI); |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 50 | |
Misha Brukman | a21b8e8 | 2003-07-29 20:52:56 +0000 | [diff] [blame] | 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. |
Misha Brukman | 0897c60 | 2003-08-06 16:20:22 +0000 | [diff] [blame^] | 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); |
Misha Brukman | a21b8e8 | 2003-07-29 20:52:56 +0000 | [diff] [blame] | 56 | |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 57 | private: |
Misha Brukman | a21b8e8 | 2003-07-29 20:52:56 +0000 | [diff] [blame] | 58 | /// getMachineOpValue - |
| 59 | /// |
Misha Brukman | f86aaa8 | 2003-06-02 04:12:39 +0000 | [diff] [blame] | 60 | int64_t getMachineOpValue(MachineInstr &MI, MachineOperand &MO); |
Misha Brukman | a21b8e8 | 2003-07-29 20:52:56 +0000 | [diff] [blame] | 61 | |
| 62 | /// emitBasicBlock - |
| 63 | /// |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 64 | void emitBasicBlock(MachineBasicBlock &MBB); |
Misha Brukman | a21b8e8 | 2003-07-29 20:52:56 +0000 | [diff] [blame] | 65 | |
| 66 | /// getValueBit - |
| 67 | /// |
| 68 | unsigned getValueBit(int64_t Val, unsigned bit); |
| 69 | |
| 70 | /// getGlobalAddress - |
| 71 | /// |
Misha Brukman | f86aaa8 | 2003-06-02 04:12:39 +0000 | [diff] [blame] | 72 | void* getGlobalAddress(GlobalValue *V, MachineInstr &MI, |
| 73 | bool isPCRelative); |
Misha Brukman | a21b8e8 | 2003-07-29 20:52:56 +0000 | [diff] [blame] | 74 | /// emitFarCall - |
| 75 | /// |
Misha Brukman | 173e250 | 2003-07-14 23:26:03 +0000 | [diff] [blame] | 76 | unsigned getRealRegNum(unsigned fakeReg, MachineInstr &MI); |
Misha Brukman | 07d4516 | 2003-07-15 19:09:43 +0000 | [diff] [blame] | 77 | |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | #endif |