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 "llvm/Target/TargetJITInfo.h"
18 #include "llvm/CodeGen/MachineConstantPool.h"
19 #include "llvm/CodeGen/MachineFunction.h"
20 #include "llvm/CodeGen/MachineJumpTableInfo.h"
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/ADT/SmallVector.h"
25 class ARMTargetMachine;
27 class ARMJITInfo : public TargetJITInfo {
30 // ConstPoolId2AddrMap - A map from constant pool ids to the corresponding
31 // CONSTPOOL_ENTRY addresses.
32 SmallVector<intptr_t, 16> ConstPoolId2AddrMap;
34 // JumpTableId2AddrMap - A map from inline jumptable ids to the
35 // corresponding inline jump table bases.
36 SmallVector<intptr_t, 16> JumpTableId2AddrMap;
38 // PCLabelMap - A map from PC labels to addresses.
39 DenseMap<unsigned, intptr_t> PCLabelMap;
42 explicit ARMJITInfo(ARMTargetMachine &tm) : TM(tm) { useGOT = false; }
44 /// replaceMachineCodeForFunction - Make it so that calling the function
45 /// whose machine code is at OLD turns into a call to NEW, perhaps by
46 /// overwriting OLD with a branch to NEW. This is used for self-modifying
49 virtual void replaceMachineCodeForFunction(void *Old, void *New);
51 /// emitFunctionStub - Use the specified MachineCodeEmitter object to emit a
52 /// small native function that simply calls the function at the specified
54 virtual void *emitFunctionStub(const Function* F, void *Fn,
55 MachineCodeEmitter &MCE);
57 /// getLazyResolverFunction - Expose the lazy resolver to the JIT.
58 virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn);
60 /// relocate - Before the JIT can run a block of code that has been emitted,
61 /// it must rewrite the code to contain the actual addresses of any
62 /// referenced global symbols.
63 virtual void relocate(void *Function, MachineRelocation *MR,
64 unsigned NumRelocs, unsigned char* GOTBase);
66 /// hasCustomConstantPool - Allows a target to specify that constant
67 /// pool address resolution is handled by the target.
68 virtual bool hasCustomConstantPool() const { return true; }
70 /// hasCustomJumpTables - Allows a target to specify that jumptables
71 /// are emitted by the target.
72 virtual bool hasCustomJumpTables() const { return true; }
74 /// allocateSeparateGVMemory - If true, globals should be placed in
75 /// separately allocated heap memory rather than in the same
76 /// code memory allocated by MachineCodeEmitter.
77 virtual bool allocateSeparateGVMemory() const {
85 /// Initialize - Initialize internal stage. Get the list of constant pool
86 /// Resize constant pool ids to CONSTPOOL_ENTRY addresses map.
87 void Initialize(const MachineFunction &MF) {
88 ConstPoolId2AddrMap.resize(MF.getConstantPool()->getConstants().size());
89 JumpTableId2AddrMap.resize(MF.getJumpTableInfo()->getJumpTables().size());
92 /// getConstantPoolEntryAddr - The ARM target puts all constant
93 /// pool entries into constant islands. This returns the address of the
94 /// constant pool entry of the specified index.
95 intptr_t getConstantPoolEntryAddr(unsigned CPI) const {
96 assert(CPI < ConstPoolId2AddrMap.size());
97 return ConstPoolId2AddrMap[CPI];
100 /// addConstantPoolEntryAddr - Map a Constant Pool Index to the address
101 /// where its associated value is stored. When relocations are processed,
102 /// this value will be used to resolve references to the constant.
103 void addConstantPoolEntryAddr(unsigned CPI, intptr_t Addr) {
104 assert(CPI < ConstPoolId2AddrMap.size());
105 ConstPoolId2AddrMap[CPI] = Addr;
108 /// getJumpTableBaseAddr - The ARM target inline all jump tables within
109 /// text section of the function. This returns the address of the base of
110 /// the jump table of the specified index.
111 intptr_t getJumpTableBaseAddr(unsigned JTI) const {
112 assert(JTI < JumpTableId2AddrMap.size());
113 return JumpTableId2AddrMap[JTI];
116 /// addJumpTableBaseAddr - Map a jump table index to the address where
117 /// the corresponding inline jump table is emitted. When relocations are
118 /// processed, this value will be used to resolve references to the
120 void addJumpTableBaseAddr(unsigned JTI, intptr_t Addr) {
121 assert(JTI < JumpTableId2AddrMap.size());
122 JumpTableId2AddrMap[JTI] = Addr;
125 /// getPCLabelAddr - Retrieve the address of the PC label of the specified id.
126 intptr_t getPCLabelAddr(unsigned Id) const {
127 DenseMap<unsigned, intptr_t>::const_iterator I = PCLabelMap.find(Id);
128 assert(I != PCLabelMap.end());
132 /// addPCLabelAddr - Remember the address of the specified PC label.
133 void addPCLabelAddr(unsigned Id, intptr_t Addr) {
134 PCLabelMap.insert(std::make_pair(Id, Addr));
138 /// resolveRelocDestAddr - Resolve the resulting address of the relocation
139 /// if it's not already solved. Constantpool entries must be resolved by
141 intptr_t resolveRelocDestAddr(MachineRelocation *MR) const;