blob: 3610a6e479f1614bb4a97588dea8361673950aef [file] [log] [blame]
Evan Cheng148b6a42007-07-05 21:15:40 +00001//===- ARMJITInfo.h - ARM implementation of the JIT interface --*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-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 Cheng148b6a42007-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 Chengf1bbb952008-11-08 00:51:41 +000017#include "ARMMachineFunctionInfo.h"
Evan Cheng25e04782008-11-04 00:50:32 +000018#include "llvm/CodeGen/MachineConstantPool.h"
Evan Cheng4df60f52008-11-07 09:06:08 +000019#include "llvm/CodeGen/MachineFunction.h"
20#include "llvm/CodeGen/MachineJumpTableInfo.h"
Evan Chengf1bbb952008-11-08 00:51:41 +000021#include "llvm/Target/TargetJITInfo.h"
Evan Cheng25e04782008-11-04 00:50:32 +000022#include "llvm/ADT/DenseMap.h"
Evan Cheng938b9d82008-10-31 19:55:13 +000023#include "llvm/ADT/SmallVector.h"
Evan Cheng148b6a42007-07-05 21:15:40 +000024
25namespace llvm {
26 class ARMTargetMachine;
27
28 class ARMJITInfo : public TargetJITInfo {
29 ARMTargetMachine &TM;
Evan Cheng0f282432008-10-29 23:55:43 +000030
31 // ConstPoolId2AddrMap - A map from constant pool ids to the corresponding
32 // CONSTPOOL_ENTRY addresses.
Evan Cheng4df60f52008-11-07 09:06:08 +000033 SmallVector<intptr_t, 16> ConstPoolId2AddrMap;
34
35 // JumpTableId2AddrMap - A map from inline jumptable ids to the
36 // corresponding inline jump table bases.
37 SmallVector<intptr_t, 16> JumpTableId2AddrMap;
Evan Cheng0f282432008-10-29 23:55:43 +000038
Evan Cheng25e04782008-11-04 00:50:32 +000039 // PCLabelMap - A map from PC labels to addresses.
40 DenseMap<unsigned, intptr_t> PCLabelMap;
41
Evan Cheng148b6a42007-07-05 21:15:40 +000042 public:
Jim Grosbachbc6d8762008-10-28 18:25:49 +000043 explicit ARMJITInfo(ARMTargetMachine &tm) : TM(tm) { useGOT = false; }
Evan Cheng148b6a42007-07-05 21:15:40 +000044
45 /// replaceMachineCodeForFunction - Make it so that calling the function
46 /// whose machine code is at OLD turns into a call to NEW, perhaps by
47 /// overwriting OLD with a branch to NEW. This is used for self-modifying
48 /// code.
49 ///
50 virtual void replaceMachineCodeForFunction(void *Old, void *New);
51
52 /// emitFunctionStub - Use the specified MachineCodeEmitter object to emit a
53 /// small native function that simply calls the function at the specified
54 /// address.
Nicolas Geoffray51cc3c12008-04-16 20:46:05 +000055 virtual void *emitFunctionStub(const Function* F, void *Fn,
56 MachineCodeEmitter &MCE);
Evan Cheng148b6a42007-07-05 21:15:40 +000057
58 /// getLazyResolverFunction - Expose the lazy resolver to the JIT.
59 virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn);
60
61 /// relocate - Before the JIT can run a block of code that has been emitted,
62 /// it must rewrite the code to contain the actual addresses of any
63 /// referenced global symbols.
64 virtual void relocate(void *Function, MachineRelocation *MR,
65 unsigned NumRelocs, unsigned char* GOTBase);
Evan Cheng25e04782008-11-04 00:50:32 +000066
Jim Grosbachbc6d8762008-10-28 18:25:49 +000067 /// hasCustomConstantPool - Allows a target to specify that constant
68 /// pool address resolution is handled by the target.
69 virtual bool hasCustomConstantPool() const { return true; }
70
Evan Cheng4df60f52008-11-07 09:06:08 +000071 /// hasCustomJumpTables - Allows a target to specify that jumptables
72 /// are emitted by the target.
73 virtual bool hasCustomJumpTables() const { return true; }
74
Evan Chengb0b53492008-11-04 09:30:48 +000075 /// allocateSeparateGVMemory - If true, globals should be placed in
76 /// separately allocated heap memory rather than in the same
77 /// code memory allocated by MachineCodeEmitter.
78 virtual bool allocateSeparateGVMemory() const {
79#ifdef __APPLE__
80 return true;
81#else
82 return false;
83#endif
84 }
85
Evan Cheng25e04782008-11-04 00:50:32 +000086 /// Initialize - Initialize internal stage. Get the list of constant pool
87 /// Resize constant pool ids to CONSTPOOL_ENTRY addresses map.
Evan Cheng4df60f52008-11-07 09:06:08 +000088 void Initialize(const MachineFunction &MF) {
Evan Chengf1bbb952008-11-08 00:51:41 +000089 const ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
90 ConstPoolId2AddrMap.resize(AFI->getNumConstPoolEntries());
91 JumpTableId2AddrMap.resize(AFI->getNumJumpTables());
Evan Cheng938b9d82008-10-31 19:55:13 +000092 }
93
Evan Cheng0f282432008-10-29 23:55:43 +000094 /// getConstantPoolEntryAddr - The ARM target puts all constant
Evan Cheng4df60f52008-11-07 09:06:08 +000095 /// pool entries into constant islands. This returns the address of the
96 /// constant pool entry of the specified index.
Evan Cheng938b9d82008-10-31 19:55:13 +000097 intptr_t getConstantPoolEntryAddr(unsigned CPI) const {
98 assert(CPI < ConstPoolId2AddrMap.size());
99 return ConstPoolId2AddrMap[CPI];
Evan Cheng0f282432008-10-29 23:55:43 +0000100 }
Jim Grosbachbc6d8762008-10-28 18:25:49 +0000101
Evan Cheng4df60f52008-11-07 09:06:08 +0000102 /// addConstantPoolEntryAddr - Map a Constant Pool Index to the address
Jim Grosbachbc6d8762008-10-28 18:25:49 +0000103 /// where its associated value is stored. When relocations are processed,
104 /// this value will be used to resolve references to the constant.
Evan Cheng938b9d82008-10-31 19:55:13 +0000105 void addConstantPoolEntryAddr(unsigned CPI, intptr_t Addr) {
106 assert(CPI < ConstPoolId2AddrMap.size());
107 ConstPoolId2AddrMap[CPI] = Addr;
Evan Cheng0f282432008-10-29 23:55:43 +0000108 }
Evan Cheng25e04782008-11-04 00:50:32 +0000109
Evan Cheng4df60f52008-11-07 09:06:08 +0000110 /// getJumpTableBaseAddr - The ARM target inline all jump tables within
111 /// text section of the function. This returns the address of the base of
112 /// the jump table of the specified index.
113 intptr_t getJumpTableBaseAddr(unsigned JTI) const {
114 assert(JTI < JumpTableId2AddrMap.size());
115 return JumpTableId2AddrMap[JTI];
116 }
117
118 /// addJumpTableBaseAddr - Map a jump table index to the address where
119 /// the corresponding inline jump table is emitted. When relocations are
120 /// processed, this value will be used to resolve references to the
121 /// jump table.
122 void addJumpTableBaseAddr(unsigned JTI, intptr_t Addr) {
123 assert(JTI < JumpTableId2AddrMap.size());
124 JumpTableId2AddrMap[JTI] = Addr;
125 }
126
Evan Cheng25e04782008-11-04 00:50:32 +0000127 /// getPCLabelAddr - Retrieve the address of the PC label of the specified id.
128 intptr_t getPCLabelAddr(unsigned Id) const {
129 DenseMap<unsigned, intptr_t>::const_iterator I = PCLabelMap.find(Id);
130 assert(I != PCLabelMap.end());
131 return I->second;
132 }
133
134 /// addPCLabelAddr - Remember the address of the specified PC label.
135 void addPCLabelAddr(unsigned Id, intptr_t Addr) {
136 PCLabelMap.insert(std::make_pair(Id, Addr));
137 }
138
139 private:
Evan Cheng4df60f52008-11-07 09:06:08 +0000140 /// resolveRelocDestAddr - Resolve the resulting address of the relocation
Evan Cheng25e04782008-11-04 00:50:32 +0000141 /// if it's not already solved. Constantpool entries must be resolved by
142 /// ARM target.
Evan Cheng4df60f52008-11-07 09:06:08 +0000143 intptr_t resolveRelocDestAddr(MachineRelocation *MR) const;
Evan Cheng148b6a42007-07-05 21:15:40 +0000144 };
145}
146
147#endif