blob: ee4c863543e7a71b9ea8d6c28415088669697d49 [file] [log] [blame]
Jia Liub22310f2012-02-18 12:03:15 +00001//===-- ARMJITInfo.h - ARM implementation of the JIT interface -*- C++ -*-===//
Evan Cheng9546a5c2007-07-05 21:15:40 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Evan Cheng9546a5c2007-07-05 21:15:40 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file contains the declaration of the ARMJITInfo class.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef ARMJITINFO_H
15#define ARMJITINFO_H
16
Evan Cheng454ff532008-11-08 00:51:41 +000017#include "ARMMachineFunctionInfo.h"
Chandler Carruth802d7552012-12-04 07:12:27 +000018#include "llvm/ADT/DenseMap.h"
19#include "llvm/ADT/SmallVector.h"
Evan Cheng6dd08b62008-11-04 00:50:32 +000020#include "llvm/CodeGen/MachineConstantPool.h"
Evan Cheng7095cd22008-11-07 09:06:08 +000021#include "llvm/CodeGen/MachineFunction.h"
22#include "llvm/CodeGen/MachineJumpTableInfo.h"
Evan Cheng454ff532008-11-08 00:51:41 +000023#include "llvm/Target/TargetJITInfo.h"
Evan Cheng9546a5c2007-07-05 21:15:40 +000024
25namespace llvm {
26 class ARMTargetMachine;
27
28 class ARMJITInfo : public TargetJITInfo {
Evan Cheng19d64ba2008-10-29 23:55:43 +000029 // ConstPoolId2AddrMap - A map from constant pool ids to the corresponding
30 // CONSTPOOL_ENTRY addresses.
Evan Cheng7095cd22008-11-07 09:06:08 +000031 SmallVector<intptr_t, 16> ConstPoolId2AddrMap;
32
33 // JumpTableId2AddrMap - A map from inline jumptable ids to the
34 // corresponding inline jump table bases.
35 SmallVector<intptr_t, 16> JumpTableId2AddrMap;
Evan Cheng19d64ba2008-10-29 23:55:43 +000036
Evan Cheng6dd08b62008-11-04 00:50:32 +000037 // PCLabelMap - A map from PC labels to addresses.
38 DenseMap<unsigned, intptr_t> PCLabelMap;
39
Evan Cheng02771dc2008-11-10 23:14:47 +000040 // Sym2IndirectSymMap - A map from symbol (GlobalValue and ExternalSymbol)
41 // addresses to their indirect symbol addresses.
42 DenseMap<void*, intptr_t> Sym2IndirectSymMap;
43
Evan Cheng98161f52008-11-08 07:38:22 +000044 // IsPIC - True if the relocation model is PIC. This is used to determine
45 // how to codegen function stubs.
46 bool IsPIC;
47
Evan Cheng9546a5c2007-07-05 21:15:40 +000048 public:
Evan Cheng98161f52008-11-08 07:38:22 +000049 explicit ARMJITInfo() : IsPIC(false) { useGOT = false; }
Evan Cheng9546a5c2007-07-05 21:15:40 +000050
51 /// replaceMachineCodeForFunction - Make it so that calling the function
52 /// whose machine code is at OLD turns into a call to NEW, perhaps by
53 /// overwriting OLD with a branch to NEW. This is used for self-modifying
54 /// code.
55 ///
Craig Topper6bc27bf2014-03-10 02:09:33 +000056 void replaceMachineCodeForFunction(void *Old, void *New) override;
Evan Cheng9546a5c2007-07-05 21:15:40 +000057
Bruno Cardoso Lopesa194c3a2009-05-30 20:51:52 +000058 /// emitGlobalValueIndirectSym - Use the specified JITCodeEmitter object
Evan Cheng9f3058f2008-11-10 01:08:07 +000059 /// to emit an indirect symbol which contains the address of the specified
60 /// ptr.
Craig Topper6bc27bf2014-03-10 02:09:33 +000061 void *emitGlobalValueIndirectSym(const GlobalValue* GV, void *ptr,
62 JITCodeEmitter &JCE) override;
Evan Chengffdd91e2008-11-08 01:31:27 +000063
Jeffrey Yasskinf2ad5712009-11-23 23:35:19 +000064 // getStubLayout - Returns the size and alignment of the largest call stub
65 // on ARM.
Craig Topper6bc27bf2014-03-10 02:09:33 +000066 StubLayout getStubLayout() override;
Jeffrey Yasskinf2ad5712009-11-23 23:35:19 +000067
Bruno Cardoso Lopesa194c3a2009-05-30 20:51:52 +000068 /// emitFunctionStub - Use the specified JITCodeEmitter object to emit a
Evan Cheng9546a5c2007-07-05 21:15:40 +000069 /// small native function that simply calls the function at the specified
70 /// address.
Craig Topper6bc27bf2014-03-10 02:09:33 +000071 void *emitFunctionStub(const Function* F, void *Fn,
72 JITCodeEmitter &JCE) override;
Evan Cheng9546a5c2007-07-05 21:15:40 +000073
74 /// getLazyResolverFunction - Expose the lazy resolver to the JIT.
Craig Topper6bc27bf2014-03-10 02:09:33 +000075 LazyResolverFn getLazyResolverFunction(JITCompilerFn) override;
Evan Cheng9546a5c2007-07-05 21:15:40 +000076
77 /// relocate - Before the JIT can run a block of code that has been emitted,
78 /// it must rewrite the code to contain the actual addresses of any
79 /// referenced global symbols.
Craig Topper6bc27bf2014-03-10 02:09:33 +000080 void relocate(void *Function, MachineRelocation *MR,
81 unsigned NumRelocs, unsigned char* GOTBase) override;
Evan Cheng6dd08b62008-11-04 00:50:32 +000082
Jim Grosbachff2b4942008-10-28 18:25:49 +000083 /// hasCustomConstantPool - Allows a target to specify that constant
84 /// pool address resolution is handled by the target.
Craig Topper6bc27bf2014-03-10 02:09:33 +000085 bool hasCustomConstantPool() const override { return true; }
Jim Grosbachff2b4942008-10-28 18:25:49 +000086
Evan Cheng7095cd22008-11-07 09:06:08 +000087 /// hasCustomJumpTables - Allows a target to specify that jumptables
88 /// are emitted by the target.
Craig Topper6bc27bf2014-03-10 02:09:33 +000089 bool hasCustomJumpTables() const override { return true; }
Evan Cheng7095cd22008-11-07 09:06:08 +000090
Evan Cheng9340be42008-11-04 09:30:48 +000091 /// allocateSeparateGVMemory - If true, globals should be placed in
92 /// separately allocated heap memory rather than in the same
Bruno Cardoso Lopesa194c3a2009-05-30 20:51:52 +000093 /// code memory allocated by JITCodeEmitter.
Craig Topper6bc27bf2014-03-10 02:09:33 +000094 bool allocateSeparateGVMemory() const override {
Evan Cheng9340be42008-11-04 09:30:48 +000095#ifdef __APPLE__
96 return true;
97#else
98 return false;
99#endif
100 }
101
Evan Cheng98161f52008-11-08 07:38:22 +0000102 /// Initialize - Initialize internal stage for the function being JITted.
103 /// Resize constant pool ids to CONSTPOOL_ENTRY addresses map; resize
104 /// jump table ids to jump table bases map; remember if codegen relocation
105 /// model is PIC.
106 void Initialize(const MachineFunction &MF, bool isPIC) {
Evan Cheng454ff532008-11-08 00:51:41 +0000107 const ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
Evan Chengdfce83c2011-01-17 08:03:18 +0000108 ConstPoolId2AddrMap.resize(AFI->getNumPICLabels());
Evan Cheng454ff532008-11-08 00:51:41 +0000109 JumpTableId2AddrMap.resize(AFI->getNumJumpTables());
Evan Cheng98161f52008-11-08 07:38:22 +0000110 IsPIC = isPIC;
Evan Cheng20dbb3b2008-10-31 19:55:13 +0000111 }
112
Evan Cheng19d64ba2008-10-29 23:55:43 +0000113 /// getConstantPoolEntryAddr - The ARM target puts all constant
Evan Cheng7095cd22008-11-07 09:06:08 +0000114 /// pool entries into constant islands. This returns the address of the
115 /// constant pool entry of the specified index.
Evan Cheng20dbb3b2008-10-31 19:55:13 +0000116 intptr_t getConstantPoolEntryAddr(unsigned CPI) const {
117 assert(CPI < ConstPoolId2AddrMap.size());
118 return ConstPoolId2AddrMap[CPI];
Evan Cheng19d64ba2008-10-29 23:55:43 +0000119 }
Jim Grosbachff2b4942008-10-28 18:25:49 +0000120
Evan Cheng7095cd22008-11-07 09:06:08 +0000121 /// addConstantPoolEntryAddr - Map a Constant Pool Index to the address
Jim Grosbachff2b4942008-10-28 18:25:49 +0000122 /// where its associated value is stored. When relocations are processed,
123 /// this value will be used to resolve references to the constant.
Evan Cheng20dbb3b2008-10-31 19:55:13 +0000124 void addConstantPoolEntryAddr(unsigned CPI, intptr_t Addr) {
125 assert(CPI < ConstPoolId2AddrMap.size());
126 ConstPoolId2AddrMap[CPI] = Addr;
Evan Cheng19d64ba2008-10-29 23:55:43 +0000127 }
Evan Cheng6dd08b62008-11-04 00:50:32 +0000128
Evan Cheng7095cd22008-11-07 09:06:08 +0000129 /// getJumpTableBaseAddr - The ARM target inline all jump tables within
130 /// text section of the function. This returns the address of the base of
131 /// the jump table of the specified index.
132 intptr_t getJumpTableBaseAddr(unsigned JTI) const {
133 assert(JTI < JumpTableId2AddrMap.size());
134 return JumpTableId2AddrMap[JTI];
135 }
136
137 /// addJumpTableBaseAddr - Map a jump table index to the address where
138 /// the corresponding inline jump table is emitted. When relocations are
139 /// processed, this value will be used to resolve references to the
140 /// jump table.
141 void addJumpTableBaseAddr(unsigned JTI, intptr_t Addr) {
142 assert(JTI < JumpTableId2AddrMap.size());
143 JumpTableId2AddrMap[JTI] = Addr;
144 }
145
Jim Grosbach84511e12010-06-02 21:53:11 +0000146 /// getPCLabelAddr - Retrieve the address of the PC label of the
147 /// specified id.
Evan Cheng6dd08b62008-11-04 00:50:32 +0000148 intptr_t getPCLabelAddr(unsigned Id) const {
149 DenseMap<unsigned, intptr_t>::const_iterator I = PCLabelMap.find(Id);
150 assert(I != PCLabelMap.end());
151 return I->second;
152 }
153
154 /// addPCLabelAddr - Remember the address of the specified PC label.
155 void addPCLabelAddr(unsigned Id, intptr_t Addr) {
156 PCLabelMap.insert(std::make_pair(Id, Addr));
157 }
158
Evan Cheng02771dc2008-11-10 23:14:47 +0000159 /// getIndirectSymAddr - Retrieve the address of the indirect symbol of the
160 /// specified symbol located at address. Returns 0 if the indirect symbol
161 /// has not been emitted.
162 intptr_t getIndirectSymAddr(void *Addr) const {
163 DenseMap<void*,intptr_t>::const_iterator I= Sym2IndirectSymMap.find(Addr);
164 if (I != Sym2IndirectSymMap.end())
165 return I->second;
166 return 0;
167 }
168
169 /// addIndirectSymAddr - Add a mapping from address of an emitted symbol to
170 /// its indirect symbol address.
171 void addIndirectSymAddr(void *SymAddr, intptr_t IndSymAddr) {
172 Sym2IndirectSymMap.insert(std::make_pair(SymAddr, IndSymAddr));
173 }
174
Evan Cheng6dd08b62008-11-04 00:50:32 +0000175 private:
Evan Cheng7095cd22008-11-07 09:06:08 +0000176 /// resolveRelocDestAddr - Resolve the resulting address of the relocation
Evan Cheng6dd08b62008-11-04 00:50:32 +0000177 /// if it's not already solved. Constantpool entries must be resolved by
178 /// ARM target.
Evan Cheng7095cd22008-11-07 09:06:08 +0000179 intptr_t resolveRelocDestAddr(MachineRelocation *MR) const;
Evan Cheng9546a5c2007-07-05 21:15:40 +0000180 };
181}
182
183#endif