Evan Cheng | 148b6a4 | 2007-07-05 21:15:40 +0000 | [diff] [blame] | 1 | //===- ARMJITInfo.h - ARM implementation of the JIT interface --*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Evan Cheng | 148b6a4 | 2007-07-05 21:15:40 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains the declaration of the ARMJITInfo class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef ARMJITINFO_H |
| 15 | #define ARMJITINFO_H |
| 16 | |
| 17 | #include "llvm/Target/TargetJITInfo.h" |
Evan Cheng | 25e0478 | 2008-11-04 00:50:32 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineConstantPool.h" |
Evan Cheng | 4df60f5 | 2008-11-07 09:06:08 +0000 | [diff] [blame^] | 19 | #include "llvm/CodeGen/MachineFunction.h" |
| 20 | #include "llvm/CodeGen/MachineJumpTableInfo.h" |
Evan Cheng | 25e0478 | 2008-11-04 00:50:32 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/DenseMap.h" |
Evan Cheng | 938b9d8 | 2008-10-31 19:55:13 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/SmallVector.h" |
Evan Cheng | 148b6a4 | 2007-07-05 21:15:40 +0000 | [diff] [blame] | 23 | |
| 24 | namespace llvm { |
| 25 | class ARMTargetMachine; |
| 26 | |
| 27 | class ARMJITInfo : public TargetJITInfo { |
| 28 | ARMTargetMachine &TM; |
Evan Cheng | 0f28243 | 2008-10-29 23:55:43 +0000 | [diff] [blame] | 29 | |
Evan Cheng | 25e0478 | 2008-11-04 00:50:32 +0000 | [diff] [blame] | 30 | // MCPEs - List of the constant pool entries for the current machine |
| 31 | // function that's being processed. |
| 32 | const std::vector<MachineConstantPoolEntry> *MCPEs; |
| 33 | |
Evan Cheng | 0f28243 | 2008-10-29 23:55:43 +0000 | [diff] [blame] | 34 | // ConstPoolId2AddrMap - A map from constant pool ids to the corresponding |
| 35 | // CONSTPOOL_ENTRY addresses. |
Evan Cheng | 4df60f5 | 2008-11-07 09:06:08 +0000 | [diff] [blame^] | 36 | SmallVector<intptr_t, 16> ConstPoolId2AddrMap; |
| 37 | |
| 38 | // JumpTableId2AddrMap - A map from inline jumptable ids to the |
| 39 | // corresponding inline jump table bases. |
| 40 | SmallVector<intptr_t, 16> JumpTableId2AddrMap; |
Evan Cheng | 0f28243 | 2008-10-29 23:55:43 +0000 | [diff] [blame] | 41 | |
Evan Cheng | 25e0478 | 2008-11-04 00:50:32 +0000 | [diff] [blame] | 42 | // PCLabelMap - A map from PC labels to addresses. |
| 43 | DenseMap<unsigned, intptr_t> PCLabelMap; |
| 44 | |
Evan Cheng | 148b6a4 | 2007-07-05 21:15:40 +0000 | [diff] [blame] | 45 | public: |
Jim Grosbach | bc6d876 | 2008-10-28 18:25:49 +0000 | [diff] [blame] | 46 | explicit ARMJITInfo(ARMTargetMachine &tm) : TM(tm) { useGOT = false; } |
Evan Cheng | 148b6a4 | 2007-07-05 21:15:40 +0000 | [diff] [blame] | 47 | |
| 48 | /// replaceMachineCodeForFunction - Make it so that calling the function |
| 49 | /// whose machine code is at OLD turns into a call to NEW, perhaps by |
| 50 | /// overwriting OLD with a branch to NEW. This is used for self-modifying |
| 51 | /// code. |
| 52 | /// |
| 53 | virtual void replaceMachineCodeForFunction(void *Old, void *New); |
| 54 | |
| 55 | /// emitFunctionStub - Use the specified MachineCodeEmitter object to emit a |
| 56 | /// small native function that simply calls the function at the specified |
| 57 | /// address. |
Nicolas Geoffray | 51cc3c1 | 2008-04-16 20:46:05 +0000 | [diff] [blame] | 58 | virtual void *emitFunctionStub(const Function* F, void *Fn, |
| 59 | MachineCodeEmitter &MCE); |
Evan Cheng | 148b6a4 | 2007-07-05 21:15:40 +0000 | [diff] [blame] | 60 | |
| 61 | /// getLazyResolverFunction - Expose the lazy resolver to the JIT. |
| 62 | virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn); |
| 63 | |
| 64 | /// relocate - Before the JIT can run a block of code that has been emitted, |
| 65 | /// it must rewrite the code to contain the actual addresses of any |
| 66 | /// referenced global symbols. |
| 67 | virtual void relocate(void *Function, MachineRelocation *MR, |
| 68 | unsigned NumRelocs, unsigned char* GOTBase); |
Evan Cheng | 25e0478 | 2008-11-04 00:50:32 +0000 | [diff] [blame] | 69 | |
Jim Grosbach | bc6d876 | 2008-10-28 18:25:49 +0000 | [diff] [blame] | 70 | /// hasCustomConstantPool - Allows a target to specify that constant |
| 71 | /// pool address resolution is handled by the target. |
| 72 | virtual bool hasCustomConstantPool() const { return true; } |
| 73 | |
Evan Cheng | 4df60f5 | 2008-11-07 09:06:08 +0000 | [diff] [blame^] | 74 | /// hasCustomJumpTables - Allows a target to specify that jumptables |
| 75 | /// are emitted by the target. |
| 76 | virtual bool hasCustomJumpTables() const { return true; } |
| 77 | |
Evan Cheng | b0b5349 | 2008-11-04 09:30:48 +0000 | [diff] [blame] | 78 | /// allocateSeparateGVMemory - If true, globals should be placed in |
| 79 | /// separately allocated heap memory rather than in the same |
| 80 | /// code memory allocated by MachineCodeEmitter. |
| 81 | virtual bool allocateSeparateGVMemory() const { |
| 82 | #ifdef __APPLE__ |
| 83 | return true; |
| 84 | #else |
| 85 | return false; |
| 86 | #endif |
| 87 | } |
| 88 | |
Evan Cheng | 25e0478 | 2008-11-04 00:50:32 +0000 | [diff] [blame] | 89 | /// Initialize - Initialize internal stage. Get the list of constant pool |
| 90 | /// Resize constant pool ids to CONSTPOOL_ENTRY addresses map. |
Evan Cheng | 4df60f5 | 2008-11-07 09:06:08 +0000 | [diff] [blame^] | 91 | void Initialize(const MachineFunction &MF) { |
| 92 | MCPEs = &MF.getConstantPool()->getConstants(); |
Evan Cheng | 25e0478 | 2008-11-04 00:50:32 +0000 | [diff] [blame] | 93 | ConstPoolId2AddrMap.resize(MCPEs->size()); |
Evan Cheng | 4df60f5 | 2008-11-07 09:06:08 +0000 | [diff] [blame^] | 94 | JumpTableId2AddrMap.resize(MF.getJumpTableInfo()->getJumpTables().size()); |
Evan Cheng | 938b9d8 | 2008-10-31 19:55:13 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Evan Cheng | 0f28243 | 2008-10-29 23:55:43 +0000 | [diff] [blame] | 97 | /// getConstantPoolEntryAddr - The ARM target puts all constant |
Evan Cheng | 4df60f5 | 2008-11-07 09:06:08 +0000 | [diff] [blame^] | 98 | /// pool entries into constant islands. This returns the address of the |
| 99 | /// constant pool entry of the specified index. |
Evan Cheng | 938b9d8 | 2008-10-31 19:55:13 +0000 | [diff] [blame] | 100 | intptr_t getConstantPoolEntryAddr(unsigned CPI) const { |
| 101 | assert(CPI < ConstPoolId2AddrMap.size()); |
| 102 | return ConstPoolId2AddrMap[CPI]; |
Evan Cheng | 0f28243 | 2008-10-29 23:55:43 +0000 | [diff] [blame] | 103 | } |
Jim Grosbach | bc6d876 | 2008-10-28 18:25:49 +0000 | [diff] [blame] | 104 | |
Evan Cheng | 4df60f5 | 2008-11-07 09:06:08 +0000 | [diff] [blame^] | 105 | /// addConstantPoolEntryAddr - Map a Constant Pool Index to the address |
Jim Grosbach | bc6d876 | 2008-10-28 18:25:49 +0000 | [diff] [blame] | 106 | /// where its associated value is stored. When relocations are processed, |
| 107 | /// this value will be used to resolve references to the constant. |
Evan Cheng | 938b9d8 | 2008-10-31 19:55:13 +0000 | [diff] [blame] | 108 | void addConstantPoolEntryAddr(unsigned CPI, intptr_t Addr) { |
| 109 | assert(CPI < ConstPoolId2AddrMap.size()); |
| 110 | ConstPoolId2AddrMap[CPI] = Addr; |
Evan Cheng | 0f28243 | 2008-10-29 23:55:43 +0000 | [diff] [blame] | 111 | } |
Evan Cheng | 25e0478 | 2008-11-04 00:50:32 +0000 | [diff] [blame] | 112 | |
Evan Cheng | 4df60f5 | 2008-11-07 09:06:08 +0000 | [diff] [blame^] | 113 | /// getJumpTableBaseAddr - The ARM target inline all jump tables within |
| 114 | /// text section of the function. This returns the address of the base of |
| 115 | /// the jump table of the specified index. |
| 116 | intptr_t getJumpTableBaseAddr(unsigned JTI) const { |
| 117 | assert(JTI < JumpTableId2AddrMap.size()); |
| 118 | return JumpTableId2AddrMap[JTI]; |
| 119 | } |
| 120 | |
| 121 | /// addJumpTableBaseAddr - Map a jump table index to the address where |
| 122 | /// the corresponding inline jump table is emitted. When relocations are |
| 123 | /// processed, this value will be used to resolve references to the |
| 124 | /// jump table. |
| 125 | void addJumpTableBaseAddr(unsigned JTI, intptr_t Addr) { |
| 126 | assert(JTI < JumpTableId2AddrMap.size()); |
| 127 | JumpTableId2AddrMap[JTI] = Addr; |
| 128 | } |
| 129 | |
Evan Cheng | 25e0478 | 2008-11-04 00:50:32 +0000 | [diff] [blame] | 130 | /// getPCLabelAddr - Retrieve the address of the PC label of the specified id. |
| 131 | intptr_t getPCLabelAddr(unsigned Id) const { |
| 132 | DenseMap<unsigned, intptr_t>::const_iterator I = PCLabelMap.find(Id); |
| 133 | assert(I != PCLabelMap.end()); |
| 134 | return I->second; |
| 135 | } |
| 136 | |
| 137 | /// addPCLabelAddr - Remember the address of the specified PC label. |
| 138 | void addPCLabelAddr(unsigned Id, intptr_t Addr) { |
| 139 | PCLabelMap.insert(std::make_pair(Id, Addr)); |
| 140 | } |
| 141 | |
| 142 | private: |
Evan Cheng | 4df60f5 | 2008-11-07 09:06:08 +0000 | [diff] [blame^] | 143 | /// resolveRelocDestAddr - Resolve the resulting address of the relocation |
Evan Cheng | 25e0478 | 2008-11-04 00:50:32 +0000 | [diff] [blame] | 144 | /// if it's not already solved. Constantpool entries must be resolved by |
| 145 | /// ARM target. |
Evan Cheng | 4df60f5 | 2008-11-07 09:06:08 +0000 | [diff] [blame^] | 146 | intptr_t resolveRelocDestAddr(MachineRelocation *MR) const; |
Evan Cheng | 148b6a4 | 2007-07-05 21:15:40 +0000 | [diff] [blame] | 147 | }; |
| 148 | } |
| 149 | |
| 150 | #endif |