blob: a35611eaa3aae8fc806c3a12ba5eb10a17ce19db [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- ARMJITInfo.h - ARM implementation of the JIT interface --*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +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 Chengd3c573a2008-11-08 00:51:41 +000017#include "ARMMachineFunctionInfo.h"
Evan Cheng5a033a62008-11-04 00:50:32 +000018#include "llvm/CodeGen/MachineConstantPool.h"
Evan Cheng0f63ae12008-11-07 09:06:08 +000019#include "llvm/CodeGen/MachineFunction.h"
20#include "llvm/CodeGen/MachineJumpTableInfo.h"
Evan Chengd3c573a2008-11-08 00:51:41 +000021#include "llvm/Target/TargetJITInfo.h"
Evan Cheng5a033a62008-11-04 00:50:32 +000022#include "llvm/ADT/DenseMap.h"
Evan Chengb562f8b2008-10-31 19:55:13 +000023#include "llvm/ADT/SmallVector.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000024
25namespace llvm {
26 class ARMTargetMachine;
27
28 class ARMJITInfo : public TargetJITInfo {
Evan Chengf07a9b62008-10-29 23:55:43 +000029 // ConstPoolId2AddrMap - A map from constant pool ids to the corresponding
30 // CONSTPOOL_ENTRY addresses.
Evan Cheng0f63ae12008-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 Chengf07a9b62008-10-29 23:55:43 +000036
Evan Cheng5a033a62008-11-04 00:50:32 +000037 // PCLabelMap - A map from PC labels to addresses.
38 DenseMap<unsigned, intptr_t> PCLabelMap;
39
Evan Chengba96b1a2008-11-08 07:38:22 +000040 // IsPIC - True if the relocation model is PIC. This is used to determine
41 // how to codegen function stubs.
42 bool IsPIC;
43
Dan Gohmanf17a25c2007-07-18 16:29:46 +000044 public:
Evan Chengba96b1a2008-11-08 07:38:22 +000045 explicit ARMJITInfo() : IsPIC(false) { useGOT = false; }
Dan Gohmanf17a25c2007-07-18 16:29:46 +000046
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
50 /// code.
51 ///
52 virtual void replaceMachineCodeForFunction(void *Old, void *New);
53
Evan Cheng8af22c42008-11-10 01:08:07 +000054 /// emitGlobalValueIndirectSym - Use the specified MachineCodeEmitter object
55 /// to emit an indirect symbol which contains the address of the specified
56 /// ptr.
57 virtual void *emitGlobalValueIndirectSym(const GlobalValue* GV, void *ptr,
Evan Cheng2d011f92008-11-08 01:31:27 +000058 MachineCodeEmitter &MCE);
59
Dan Gohmanf17a25c2007-07-18 16:29:46 +000060 /// emitFunctionStub - Use the specified MachineCodeEmitter object to emit a
61 /// small native function that simply calls the function at the specified
62 /// address.
Nicolas Geoffray2b483b52008-04-16 20:46:05 +000063 virtual void *emitFunctionStub(const Function* F, void *Fn,
64 MachineCodeEmitter &MCE);
Dan Gohmanf17a25c2007-07-18 16:29:46 +000065
66 /// getLazyResolverFunction - Expose the lazy resolver to the JIT.
67 virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn);
68
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);
Evan Cheng5a033a62008-11-04 00:50:32 +000074
Jim Grosbachcd40d892008-10-28 18:25:49 +000075 /// hasCustomConstantPool - Allows a target to specify that constant
76 /// pool address resolution is handled by the target.
77 virtual bool hasCustomConstantPool() const { return true; }
78
Evan Cheng0f63ae12008-11-07 09:06:08 +000079 /// hasCustomJumpTables - Allows a target to specify that jumptables
80 /// are emitted by the target.
81 virtual bool hasCustomJumpTables() const { return true; }
82
Evan Cheng4a8e3b42008-11-04 09:30:48 +000083 /// 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 {
87#ifdef __APPLE__
88 return true;
89#else
90 return false;
91#endif
92 }
93
Evan Chengba96b1a2008-11-08 07:38:22 +000094 /// 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
97 /// model is PIC.
98 void Initialize(const MachineFunction &MF, bool isPIC) {
Evan Chengd3c573a2008-11-08 00:51:41 +000099 const ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
100 ConstPoolId2AddrMap.resize(AFI->getNumConstPoolEntries());
101 JumpTableId2AddrMap.resize(AFI->getNumJumpTables());
Evan Chengba96b1a2008-11-08 07:38:22 +0000102 IsPIC = isPIC;
Evan Chengb562f8b2008-10-31 19:55:13 +0000103 }
104
Evan Chengf07a9b62008-10-29 23:55:43 +0000105 /// getConstantPoolEntryAddr - The ARM target puts all constant
Evan Cheng0f63ae12008-11-07 09:06:08 +0000106 /// pool entries into constant islands. This returns the address of the
107 /// constant pool entry of the specified index.
Evan Chengb562f8b2008-10-31 19:55:13 +0000108 intptr_t getConstantPoolEntryAddr(unsigned CPI) const {
109 assert(CPI < ConstPoolId2AddrMap.size());
110 return ConstPoolId2AddrMap[CPI];
Evan Chengf07a9b62008-10-29 23:55:43 +0000111 }
Jim Grosbachcd40d892008-10-28 18:25:49 +0000112
Evan Cheng0f63ae12008-11-07 09:06:08 +0000113 /// addConstantPoolEntryAddr - Map a Constant Pool Index to the address
Jim Grosbachcd40d892008-10-28 18:25:49 +0000114 /// where its associated value is stored. When relocations are processed,
115 /// this value will be used to resolve references to the constant.
Evan Chengb562f8b2008-10-31 19:55:13 +0000116 void addConstantPoolEntryAddr(unsigned CPI, intptr_t Addr) {
117 assert(CPI < ConstPoolId2AddrMap.size());
118 ConstPoolId2AddrMap[CPI] = Addr;
Evan Chengf07a9b62008-10-29 23:55:43 +0000119 }
Evan Cheng5a033a62008-11-04 00:50:32 +0000120
Evan Cheng0f63ae12008-11-07 09:06:08 +0000121 /// 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];
127 }
128
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
132 /// jump table.
133 void addJumpTableBaseAddr(unsigned JTI, intptr_t Addr) {
134 assert(JTI < JumpTableId2AddrMap.size());
135 JumpTableId2AddrMap[JTI] = Addr;
136 }
137
Evan Cheng5a033a62008-11-04 00:50:32 +0000138 /// 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());
142 return I->second;
143 }
144
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));
148 }
149
150 private:
Evan Cheng0f63ae12008-11-07 09:06:08 +0000151 /// resolveRelocDestAddr - Resolve the resulting address of the relocation
Evan Cheng5a033a62008-11-04 00:50:32 +0000152 /// if it's not already solved. Constantpool entries must be resolved by
153 /// ARM target.
Evan Cheng0f63ae12008-11-07 09:06:08 +0000154 intptr_t resolveRelocDestAddr(MachineRelocation *MR) const;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000155 };
156}
157
158#endif