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" |
| 19 | #include "llvm/ADT/DenseMap.h" |
Evan Cheng | 938b9d8 | 2008-10-31 19:55:13 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/SmallVector.h" |
Evan Cheng | 148b6a4 | 2007-07-05 21:15:40 +0000 | [diff] [blame] | 21 | |
| 22 | namespace llvm { |
| 23 | class ARMTargetMachine; |
| 24 | |
| 25 | class ARMJITInfo : public TargetJITInfo { |
| 26 | ARMTargetMachine &TM; |
Evan Cheng | 0f28243 | 2008-10-29 23:55:43 +0000 | [diff] [blame] | 27 | |
Evan Cheng | 25e0478 | 2008-11-04 00:50:32 +0000 | [diff] [blame^] | 28 | // MCPEs - List of the constant pool entries for the current machine |
| 29 | // function that's being processed. |
| 30 | const std::vector<MachineConstantPoolEntry> *MCPEs; |
| 31 | |
Evan Cheng | 0f28243 | 2008-10-29 23:55:43 +0000 | [diff] [blame] | 32 | // ConstPoolId2AddrMap - A map from constant pool ids to the corresponding |
| 33 | // CONSTPOOL_ENTRY addresses. |
Evan Cheng | 938b9d8 | 2008-10-31 19:55:13 +0000 | [diff] [blame] | 34 | SmallVector<intptr_t, 32> ConstPoolId2AddrMap; |
Evan Cheng | 0f28243 | 2008-10-29 23:55:43 +0000 | [diff] [blame] | 35 | |
Evan Cheng | 25e0478 | 2008-11-04 00:50:32 +0000 | [diff] [blame^] | 36 | // PCLabelMap - A map from PC labels to addresses. |
| 37 | DenseMap<unsigned, intptr_t> PCLabelMap; |
| 38 | |
Evan Cheng | 148b6a4 | 2007-07-05 21:15:40 +0000 | [diff] [blame] | 39 | public: |
Jim Grosbach | bc6d876 | 2008-10-28 18:25:49 +0000 | [diff] [blame] | 40 | explicit ARMJITInfo(ARMTargetMachine &tm) : TM(tm) { useGOT = false; } |
Evan Cheng | 148b6a4 | 2007-07-05 21:15:40 +0000 | [diff] [blame] | 41 | |
| 42 | /// replaceMachineCodeForFunction - Make it so that calling the function |
| 43 | /// whose machine code is at OLD turns into a call to NEW, perhaps by |
| 44 | /// overwriting OLD with a branch to NEW. This is used for self-modifying |
| 45 | /// code. |
| 46 | /// |
| 47 | virtual void replaceMachineCodeForFunction(void *Old, void *New); |
| 48 | |
| 49 | /// emitFunctionStub - Use the specified MachineCodeEmitter object to emit a |
| 50 | /// small native function that simply calls the function at the specified |
| 51 | /// address. |
Nicolas Geoffray | 51cc3c1 | 2008-04-16 20:46:05 +0000 | [diff] [blame] | 52 | virtual void *emitFunctionStub(const Function* F, void *Fn, |
| 53 | MachineCodeEmitter &MCE); |
Evan Cheng | 148b6a4 | 2007-07-05 21:15:40 +0000 | [diff] [blame] | 54 | |
| 55 | /// getLazyResolverFunction - Expose the lazy resolver to the JIT. |
| 56 | virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn); |
| 57 | |
| 58 | /// relocate - Before the JIT can run a block of code that has been emitted, |
| 59 | /// it must rewrite the code to contain the actual addresses of any |
| 60 | /// referenced global symbols. |
| 61 | virtual void relocate(void *Function, MachineRelocation *MR, |
| 62 | unsigned NumRelocs, unsigned char* GOTBase); |
Evan Cheng | 25e0478 | 2008-11-04 00:50:32 +0000 | [diff] [blame^] | 63 | |
Jim Grosbach | bc6d876 | 2008-10-28 18:25:49 +0000 | [diff] [blame] | 64 | /// hasCustomConstantPool - Allows a target to specify that constant |
| 65 | /// pool address resolution is handled by the target. |
| 66 | virtual bool hasCustomConstantPool() const { return true; } |
| 67 | |
Evan Cheng | 25e0478 | 2008-11-04 00:50:32 +0000 | [diff] [blame^] | 68 | /// Initialize - Initialize internal stage. Get the list of constant pool |
| 69 | /// Resize constant pool ids to CONSTPOOL_ENTRY addresses map. |
| 70 | void Initialize(const std::vector<MachineConstantPoolEntry> *mcpes) { |
| 71 | MCPEs = mcpes; |
| 72 | ConstPoolId2AddrMap.resize(MCPEs->size()); |
Evan Cheng | 938b9d8 | 2008-10-31 19:55:13 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Evan Cheng | 0f28243 | 2008-10-29 23:55:43 +0000 | [diff] [blame] | 75 | /// getConstantPoolEntryAddr - The ARM target puts all constant |
Jim Grosbach | bc6d876 | 2008-10-28 18:25:49 +0000 | [diff] [blame] | 76 | /// pool entries into constant islands. Resolve the constant pool index |
| 77 | /// into the address where the constant is stored. |
Evan Cheng | 938b9d8 | 2008-10-31 19:55:13 +0000 | [diff] [blame] | 78 | intptr_t getConstantPoolEntryAddr(unsigned CPI) const { |
| 79 | assert(CPI < ConstPoolId2AddrMap.size()); |
| 80 | return ConstPoolId2AddrMap[CPI]; |
Evan Cheng | 0f28243 | 2008-10-29 23:55:43 +0000 | [diff] [blame] | 81 | } |
Jim Grosbach | bc6d876 | 2008-10-28 18:25:49 +0000 | [diff] [blame] | 82 | |
Evan Cheng | 938b9d8 | 2008-10-31 19:55:13 +0000 | [diff] [blame] | 83 | /// addConstantPoolEntryAddr - Map a Constant Pool Index (CPI) to the address |
Jim Grosbach | bc6d876 | 2008-10-28 18:25:49 +0000 | [diff] [blame] | 84 | /// where its associated value is stored. When relocations are processed, |
| 85 | /// this value will be used to resolve references to the constant. |
Evan Cheng | 938b9d8 | 2008-10-31 19:55:13 +0000 | [diff] [blame] | 86 | void addConstantPoolEntryAddr(unsigned CPI, intptr_t Addr) { |
| 87 | assert(CPI < ConstPoolId2AddrMap.size()); |
| 88 | ConstPoolId2AddrMap[CPI] = Addr; |
Evan Cheng | 0f28243 | 2008-10-29 23:55:43 +0000 | [diff] [blame] | 89 | } |
Evan Cheng | 25e0478 | 2008-11-04 00:50:32 +0000 | [diff] [blame^] | 90 | |
| 91 | /// getPCLabelAddr - Retrieve the address of the PC label of the specified id. |
| 92 | intptr_t getPCLabelAddr(unsigned Id) const { |
| 93 | DenseMap<unsigned, intptr_t>::const_iterator I = PCLabelMap.find(Id); |
| 94 | assert(I != PCLabelMap.end()); |
| 95 | return I->second; |
| 96 | } |
| 97 | |
| 98 | /// addPCLabelAddr - Remember the address of the specified PC label. |
| 99 | void addPCLabelAddr(unsigned Id, intptr_t Addr) { |
| 100 | PCLabelMap.insert(std::make_pair(Id, Addr)); |
| 101 | } |
| 102 | |
| 103 | private: |
| 104 | /// resolveRelocationAddr - Resolve the resulting address of the relocation |
| 105 | /// if it's not already solved. Constantpool entries must be resolved by |
| 106 | /// ARM target. |
| 107 | intptr_t resolveRelocationAddr(MachineRelocation *MR) const; |
Evan Cheng | 148b6a4 | 2007-07-05 21:15:40 +0000 | [diff] [blame] | 108 | }; |
| 109 | } |
| 110 | |
| 111 | #endif |