1 //===- ARMJITInfo.h - ARM implementation of the JIT interface --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the declaration of the ARMJITInfo class.
12 //===----------------------------------------------------------------------===//
17 #include "ARMMachineFunctionInfo.h"
18 #include "llvm/CodeGen/MachineConstantPool.h"
19 #include "llvm/CodeGen/MachineFunction.h"
20 #include "llvm/CodeGen/MachineJumpTableInfo.h"
21 #include "llvm/Target/TargetJITInfo.h"
22 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/ADT/SmallVector.h"
26 class ARMTargetMachine;
28 class ARMJITInfo : public TargetJITInfo {
29 // ConstPoolId2AddrMap - A map from constant pool ids to the corresponding
30 // CONSTPOOL_ENTRY addresses.
31 SmallVector<intptr_t, 16> ConstPoolId2AddrMap;
33 // JumpTableId2AddrMap - A map from inline jumptable ids to the
34 // corresponding inline jump table bases.
35 SmallVector<intptr_t, 16> JumpTableId2AddrMap;
37 // PCLabelMap - A map from PC labels to addresses.
38 DenseMap<unsigned, intptr_t> PCLabelMap;
40 // IsPIC - True if the relocation model is PIC. This is used to determine
41 // how to codegen function stubs.
45 explicit ARMJITInfo() : IsPIC(false) { useGOT = false; }
47 /// replaceMachineCodeForFunction - Make it so that calling the function
48 /// whose machine code is at OLD turns into a call to NEW, perhaps by
49 /// overwriting OLD with a branch to NEW. This is used for self-modifying
52 virtual void replaceMachineCodeForFunction(void *Old, void *New);
54 /// emitGlobalValueNonLazyPtr - Use the specified MachineCodeEmitter object
55 /// to emit a Mac OS X non-lazy pointer which contains the address of the
57 virtual void *emitGlobalValueNonLazyPtr(const GlobalValue *GV, void *Ptr,
58 MachineCodeEmitter &MCE);
60 /// emitFunctionStub - Use the specified MachineCodeEmitter object to emit a
61 /// small native function that simply calls the function at the specified
63 virtual void *emitFunctionStub(const Function* F, void *Fn,
64 MachineCodeEmitter &MCE);
66 /// getLazyResolverFunction - Expose the lazy resolver to the JIT.
67 virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn);
69 /// relocate - Before the JIT can run a block of code that has been emitted,
70 /// it must rewrite the code to contain the actual addresses of any
71 /// referenced global symbols.
72 virtual void relocate(void *Function, MachineRelocation *MR,
73 unsigned NumRelocs, unsigned char* GOTBase);
75 /// hasCustomConstantPool - Allows a target to specify that constant
76 /// pool address resolution is handled by the target.
77 virtual bool hasCustomConstantPool() const { return true; }
79 /// hasCustomJumpTables - Allows a target to specify that jumptables
80 /// are emitted by the target.
81 virtual bool hasCustomJumpTables() const { return true; }
83 /// allocateSeparateGVMemory - If true, globals should be placed in
84 /// separately allocated heap memory rather than in the same
85 /// code memory allocated by MachineCodeEmitter.
86 virtual bool allocateSeparateGVMemory() const {
94 /// Initialize - Initialize internal stage for the function being JITted.
95 /// Resize constant pool ids to CONSTPOOL_ENTRY addresses map; resize
96 /// jump table ids to jump table bases map; remember if codegen relocation
98 void Initialize(const MachineFunction &MF, bool isPIC) {
99 const ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
100 ConstPoolId2AddrMap.resize(AFI->getNumConstPoolEntries());
101 JumpTableId2AddrMap.resize(AFI->getNumJumpTables());
105 /// getConstantPoolEntryAddr - The ARM target puts all constant
106 /// pool entries into constant islands. This returns the address of the
107 /// constant pool entry of the specified index.
108 intptr_t getConstantPoolEntryAddr(unsigned CPI) const {
109 assert(CPI < ConstPoolId2AddrMap.size());
110 return ConstPoolId2AddrMap[CPI];
113 /// addConstantPoolEntryAddr - Map a Constant Pool Index to the address
114 /// where its associated value is stored. When relocations are processed,
115 /// this value will be used to resolve references to the constant.
116 void addConstantPoolEntryAddr(unsigned CPI, intptr_t Addr) {
117 assert(CPI < ConstPoolId2AddrMap.size());
118 ConstPoolId2AddrMap[CPI] = Addr;
121 /// getJumpTableBaseAddr - The ARM target inline all jump tables within
122 /// text section of the function. This returns the address of the base of
123 /// the jump table of the specified index.
124 intptr_t getJumpTableBaseAddr(unsigned JTI) const {
125 assert(JTI < JumpTableId2AddrMap.size());
126 return JumpTableId2AddrMap[JTI];
129 /// addJumpTableBaseAddr - Map a jump table index to the address where
130 /// the corresponding inline jump table is emitted. When relocations are
131 /// processed, this value will be used to resolve references to the
133 void addJumpTableBaseAddr(unsigned JTI, intptr_t Addr) {
134 assert(JTI < JumpTableId2AddrMap.size());
135 JumpTableId2AddrMap[JTI] = Addr;
138 /// getPCLabelAddr - Retrieve the address of the PC label of the specified id.
139 intptr_t getPCLabelAddr(unsigned Id) const {
140 DenseMap<unsigned, intptr_t>::const_iterator I = PCLabelMap.find(Id);
141 assert(I != PCLabelMap.end());
145 /// addPCLabelAddr - Remember the address of the specified PC label.
146 void addPCLabelAddr(unsigned Id, intptr_t Addr) {
147 PCLabelMap.insert(std::make_pair(Id, Addr));
151 /// resolveRelocDestAddr - Resolve the resulting address of the relocation
152 /// if it's not already solved. Constantpool entries must be resolved by
154 intptr_t resolveRelocDestAddr(MachineRelocation *MR) const;