blob: feb7eea6aabc4a6933ec8bd1759fa0961943780b [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
17#include "llvm/Target/TargetJITInfo.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 Cheng25e04782008-11-04 00:50:32 +000021#include "llvm/ADT/DenseMap.h"
Evan Cheng938b9d82008-10-31 19:55:13 +000022#include "llvm/ADT/SmallVector.h"
Evan Cheng148b6a42007-07-05 21:15:40 +000023
24namespace llvm {
25 class ARMTargetMachine;
26
27 class ARMJITInfo : public TargetJITInfo {
28 ARMTargetMachine &TM;
Evan Cheng0f282432008-10-29 23:55:43 +000029
30 // ConstPoolId2AddrMap - A map from constant pool ids to the corresponding
31 // CONSTPOOL_ENTRY addresses.
Evan Cheng4df60f52008-11-07 09:06:08 +000032 SmallVector<intptr_t, 16> ConstPoolId2AddrMap;
33
34 // JumpTableId2AddrMap - A map from inline jumptable ids to the
35 // corresponding inline jump table bases.
36 SmallVector<intptr_t, 16> JumpTableId2AddrMap;
Evan Cheng0f282432008-10-29 23:55:43 +000037
Evan Cheng25e04782008-11-04 00:50:32 +000038 // PCLabelMap - A map from PC labels to addresses.
39 DenseMap<unsigned, intptr_t> PCLabelMap;
40
Evan Cheng148b6a42007-07-05 21:15:40 +000041 public:
Jim Grosbachbc6d8762008-10-28 18:25:49 +000042 explicit ARMJITInfo(ARMTargetMachine &tm) : TM(tm) { useGOT = false; }
Evan Cheng148b6a42007-07-05 21:15:40 +000043
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
47 /// code.
48 ///
49 virtual void replaceMachineCodeForFunction(void *Old, void *New);
50
51 /// emitFunctionStub - Use the specified MachineCodeEmitter object to emit a
52 /// small native function that simply calls the function at the specified
53 /// address.
Nicolas Geoffray51cc3c12008-04-16 20:46:05 +000054 virtual void *emitFunctionStub(const Function* F, void *Fn,
55 MachineCodeEmitter &MCE);
Evan Cheng148b6a42007-07-05 21:15:40 +000056
57 /// getLazyResolverFunction - Expose the lazy resolver to the JIT.
58 virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn);
59
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);
Evan Cheng25e04782008-11-04 00:50:32 +000065
Jim Grosbachbc6d8762008-10-28 18:25:49 +000066 /// hasCustomConstantPool - Allows a target to specify that constant
67 /// pool address resolution is handled by the target.
68 virtual bool hasCustomConstantPool() const { return true; }
69
Evan Cheng4df60f52008-11-07 09:06:08 +000070 /// hasCustomJumpTables - Allows a target to specify that jumptables
71 /// are emitted by the target.
72 virtual bool hasCustomJumpTables() const { return true; }
73
Evan Chengb0b53492008-11-04 09:30:48 +000074 /// 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 {
78#ifdef __APPLE__
79 return true;
80#else
81 return false;
82#endif
83 }
84
Evan Cheng25e04782008-11-04 00:50:32 +000085 /// Initialize - Initialize internal stage. Get the list of constant pool
86 /// Resize constant pool ids to CONSTPOOL_ENTRY addresses map.
Evan Cheng4df60f52008-11-07 09:06:08 +000087 void Initialize(const MachineFunction &MF) {
Evan Cheng413a89f2008-11-07 22:57:53 +000088 ConstPoolId2AddrMap.resize(MF.getConstantPool()->getConstants().size());
Evan Cheng4df60f52008-11-07 09:06:08 +000089 JumpTableId2AddrMap.resize(MF.getJumpTableInfo()->getJumpTables().size());
Evan Cheng938b9d82008-10-31 19:55:13 +000090 }
91
Evan Cheng0f282432008-10-29 23:55:43 +000092 /// getConstantPoolEntryAddr - The ARM target puts all constant
Evan Cheng4df60f52008-11-07 09:06:08 +000093 /// pool entries into constant islands. This returns the address of the
94 /// constant pool entry of the specified index.
Evan Cheng938b9d82008-10-31 19:55:13 +000095 intptr_t getConstantPoolEntryAddr(unsigned CPI) const {
96 assert(CPI < ConstPoolId2AddrMap.size());
97 return ConstPoolId2AddrMap[CPI];
Evan Cheng0f282432008-10-29 23:55:43 +000098 }
Jim Grosbachbc6d8762008-10-28 18:25:49 +000099
Evan Cheng4df60f52008-11-07 09:06:08 +0000100 /// addConstantPoolEntryAddr - Map a Constant Pool Index to the address
Jim Grosbachbc6d8762008-10-28 18:25:49 +0000101 /// where its associated value is stored. When relocations are processed,
102 /// this value will be used to resolve references to the constant.
Evan Cheng938b9d82008-10-31 19:55:13 +0000103 void addConstantPoolEntryAddr(unsigned CPI, intptr_t Addr) {
104 assert(CPI < ConstPoolId2AddrMap.size());
105 ConstPoolId2AddrMap[CPI] = Addr;
Evan Cheng0f282432008-10-29 23:55:43 +0000106 }
Evan Cheng25e04782008-11-04 00:50:32 +0000107
Evan Cheng4df60f52008-11-07 09:06:08 +0000108 /// 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];
114 }
115
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
119 /// jump table.
120 void addJumpTableBaseAddr(unsigned JTI, intptr_t Addr) {
121 assert(JTI < JumpTableId2AddrMap.size());
122 JumpTableId2AddrMap[JTI] = Addr;
123 }
124
Evan Cheng25e04782008-11-04 00:50:32 +0000125 /// 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());
129 return I->second;
130 }
131
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));
135 }
136
137 private:
Evan Cheng4df60f52008-11-07 09:06:08 +0000138 /// resolveRelocDestAddr - Resolve the resulting address of the relocation
Evan Cheng25e04782008-11-04 00:50:32 +0000139 /// if it's not already solved. Constantpool entries must be resolved by
140 /// ARM target.
Evan Cheng4df60f52008-11-07 09:06:08 +0000141 intptr_t resolveRelocDestAddr(MachineRelocation *MR) const;
Evan Cheng148b6a42007-07-05 21:15:40 +0000142 };
143}
144
145#endif