Misha Brukman | a9f7f6e | 2003-05-30 20:17:33 +0000 | [diff] [blame] | 1 | //===-- SparcV9CodeEmitter.h ------------------------------------*- C++ -*-===// |
| 2 | // |
John Criswell | 856ba76 | 2003-10-21 15:17:13 +0000 | [diff] [blame] | 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 | // |
Brian Gaeke | b75a316 | 2004-04-15 20:23:13 +0000 | [diff] [blame] | 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. |
Misha Brukman | a9f7f6e | 2003-05-30 20:17:33 +0000 | [diff] [blame] | 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 16 | |
| 17 | #ifndef SPARCV9CODEEMITTER_H |
| 18 | #define SPARCV9CODEEMITTER_H |
| 19 | |
Misha Brukman | 0d60345 | 2003-05-27 22:41:44 +0000 | [diff] [blame] | 20 | #include "llvm/BasicBlock.h" |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/MachineCodeEmitter.h" |
| 22 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Misha Brukman | a9f7f6e | 2003-05-30 20:17:33 +0000 | [diff] [blame] | 23 | #include "llvm/Target/TargetMachine.h" |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 24 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 25 | namespace llvm { |
| 26 | |
Misha Brukman | f86aaa8 | 2003-06-02 04:12:39 +0000 | [diff] [blame] | 27 | class GlobalValue; |
| 28 | class MachineInstr; |
| 29 | class MachineOperand; |
| 30 | |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 31 | class SparcV9CodeEmitter : public MachineFunctionPass { |
Misha Brukman | a2196c1 | 2003-06-04 20:01:13 +0000 | [diff] [blame] | 32 | TargetMachine &TM; |
| 33 | MachineCodeEmitter &MCE; |
Chris Lattner | 6856d11 | 2003-07-26 23:04:00 +0000 | [diff] [blame] | 34 | const BasicBlock *currBB; |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 35 | |
Misha Brukman | f86aaa8 | 2003-06-02 04:12:39 +0000 | [diff] [blame] | 36 | // Tracks which instruction references which BasicBlock |
Chris Lattner | 6856d11 | 2003-07-26 23:04:00 +0000 | [diff] [blame] | 37 | std::vector<std::pair<const BasicBlock*, |
Misha Brukman | f86aaa8 | 2003-06-02 04:12:39 +0000 | [diff] [blame] | 38 | std::pair<unsigned*,MachineInstr*> > > BBRefs; |
| 39 | // Tracks where each BasicBlock starts |
Chris Lattner | 6856d11 | 2003-07-26 23:04:00 +0000 | [diff] [blame] | 40 | std::map<const BasicBlock*, long> BBLocations; |
Misha Brukman | a2196c1 | 2003-06-04 20:01:13 +0000 | [diff] [blame] | 41 | |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 42 | public: |
Misha Brukman | a2196c1 | 2003-06-04 20:01:13 +0000 | [diff] [blame] | 43 | SparcV9CodeEmitter(TargetMachine &T, MachineCodeEmitter &M); |
| 44 | ~SparcV9CodeEmitter(); |
Misha Brukman | a9f7f6e | 2003-05-30 20:17:33 +0000 | [diff] [blame] | 45 | |
Brian Gaeke | b75a316 | 2004-04-15 20:23:13 +0000 | [diff] [blame] | 46 | const char *getPassName() const { return "SparcV9 Machine Code Emitter"; } |
| 47 | |
Misha Brukman | a21b8e8 | 2003-07-29 20:52:56 +0000 | [diff] [blame] | 48 | /// runOnMachineFunction - emits the given machine function to memory. |
| 49 | /// |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 50 | bool runOnMachineFunction(MachineFunction &F); |
Misha Brukman | a21b8e8 | 2003-07-29 20:52:56 +0000 | [diff] [blame] | 51 | |
| 52 | /// emitWord - writes out the given 32-bit value to memory at the current PC. |
| 53 | /// |
Misha Brukman | a2196c1 | 2003-06-04 20:01:13 +0000 | [diff] [blame] | 54 | void emitWord(unsigned Val); |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 55 | |
Misha Brukman | a21b8e8 | 2003-07-29 20:52:56 +0000 | [diff] [blame] | 56 | /// getBinaryCodeForInstr - This function, generated by the |
| 57 | /// CodeEmitterGenerator using TableGen, produces the binary encoding for |
| 58 | /// machine instructions. |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 59 | /// |
Misha Brukman | f86aaa8 | 2003-06-02 04:12:39 +0000 | [diff] [blame] | 60 | unsigned getBinaryCodeForInstr(MachineInstr &MI); |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 61 | |
Misha Brukman | a21b8e8 | 2003-07-29 20:52:56 +0000 | [diff] [blame] | 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. |
Misha Brukman | 0897c60 | 2003-08-06 16:20:22 +0000 | [diff] [blame] | 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); |
Misha Brukman | a21b8e8 | 2003-07-29 20:52:56 +0000 | [diff] [blame] | 67 | |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 68 | private: |
Misha Brukman | a21b8e8 | 2003-07-29 20:52:56 +0000 | [diff] [blame] | 69 | /// getMachineOpValue - |
| 70 | /// |
Misha Brukman | f86aaa8 | 2003-06-02 04:12:39 +0000 | [diff] [blame] | 71 | int64_t getMachineOpValue(MachineInstr &MI, MachineOperand &MO); |
Misha Brukman | a21b8e8 | 2003-07-29 20:52:56 +0000 | [diff] [blame] | 72 | |
| 73 | /// emitBasicBlock - |
| 74 | /// |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 75 | void emitBasicBlock(MachineBasicBlock &MBB); |
Misha Brukman | a21b8e8 | 2003-07-29 20:52:56 +0000 | [diff] [blame] | 76 | |
| 77 | /// getValueBit - |
| 78 | /// |
| 79 | unsigned getValueBit(int64_t Val, unsigned bit); |
| 80 | |
| 81 | /// getGlobalAddress - |
| 82 | /// |
Misha Brukman | f86aaa8 | 2003-06-02 04:12:39 +0000 | [diff] [blame] | 83 | void* getGlobalAddress(GlobalValue *V, MachineInstr &MI, |
| 84 | bool isPCRelative); |
Misha Brukman | a21b8e8 | 2003-07-29 20:52:56 +0000 | [diff] [blame] | 85 | /// emitFarCall - |
| 86 | /// |
Misha Brukman | 173e250 | 2003-07-14 23:26:03 +0000 | [diff] [blame] | 87 | unsigned getRealRegNum(unsigned fakeReg, MachineInstr &MI); |
Misha Brukman | 07d4516 | 2003-07-15 19:09:43 +0000 | [diff] [blame] | 88 | |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 91 | } // End llvm namespace |
| 92 | |
Misha Brukman | 0cc640e | 2003-05-27 21:45:05 +0000 | [diff] [blame] | 93 | #endif |