1235633Sdim//===-- ARMJITInfo.h - ARM implementation of the JIT interface -*- C++ -*-===// 2193323Sed// 3193323Sed// The LLVM Compiler Infrastructure 4193323Sed// 5193323Sed// This file is distributed under the University of Illinois Open Source 6193323Sed// License. See LICENSE.TXT for details. 7193323Sed// 8193323Sed//===----------------------------------------------------------------------===// 9193323Sed// 10193323Sed// This file contains the declaration of the ARMJITInfo class. 11193323Sed// 12193323Sed//===----------------------------------------------------------------------===// 13193323Sed 14193323Sed#ifndef ARMJITINFO_H 15193323Sed#define ARMJITINFO_H 16193323Sed 17193323Sed#include "ARMMachineFunctionInfo.h" 18252723Sdim#include "llvm/ADT/DenseMap.h" 19252723Sdim#include "llvm/ADT/SmallVector.h" 20193323Sed#include "llvm/CodeGen/MachineConstantPool.h" 21193323Sed#include "llvm/CodeGen/MachineFunction.h" 22193323Sed#include "llvm/CodeGen/MachineJumpTableInfo.h" 23193323Sed#include "llvm/Target/TargetJITInfo.h" 24193323Sed 25193323Sednamespace llvm { 26193323Sed class ARMTargetMachine; 27193323Sed 28193323Sed class ARMJITInfo : public TargetJITInfo { 29193323Sed // ConstPoolId2AddrMap - A map from constant pool ids to the corresponding 30193323Sed // CONSTPOOL_ENTRY addresses. 31193323Sed SmallVector<intptr_t, 16> ConstPoolId2AddrMap; 32193323Sed 33193323Sed // JumpTableId2AddrMap - A map from inline jumptable ids to the 34193323Sed // corresponding inline jump table bases. 35193323Sed SmallVector<intptr_t, 16> JumpTableId2AddrMap; 36193323Sed 37193323Sed // PCLabelMap - A map from PC labels to addresses. 38193323Sed DenseMap<unsigned, intptr_t> PCLabelMap; 39193323Sed 40193323Sed // Sym2IndirectSymMap - A map from symbol (GlobalValue and ExternalSymbol) 41193323Sed // addresses to their indirect symbol addresses. 42193323Sed DenseMap<void*, intptr_t> Sym2IndirectSymMap; 43193323Sed 44193323Sed // IsPIC - True if the relocation model is PIC. This is used to determine 45193323Sed // how to codegen function stubs. 46193323Sed bool IsPIC; 47193323Sed 48193323Sed public: 49193323Sed explicit ARMJITInfo() : IsPIC(false) { useGOT = false; } 50193323Sed 51193323Sed /// replaceMachineCodeForFunction - Make it so that calling the function 52193323Sed /// whose machine code is at OLD turns into a call to NEW, perhaps by 53193323Sed /// overwriting OLD with a branch to NEW. This is used for self-modifying 54193323Sed /// code. 55193323Sed /// 56193323Sed virtual void replaceMachineCodeForFunction(void *Old, void *New); 57193323Sed 58193323Sed /// emitGlobalValueIndirectSym - Use the specified JITCodeEmitter object 59193323Sed /// to emit an indirect symbol which contains the address of the specified 60193323Sed /// ptr. 61193323Sed virtual void *emitGlobalValueIndirectSym(const GlobalValue* GV, void *ptr, 62193323Sed JITCodeEmitter &JCE); 63193323Sed 64199989Srdivacky // getStubLayout - Returns the size and alignment of the largest call stub 65199989Srdivacky // on ARM. 66199989Srdivacky virtual StubLayout getStubLayout(); 67199989Srdivacky 68193323Sed /// emitFunctionStub - Use the specified JITCodeEmitter object to emit a 69193323Sed /// small native function that simply calls the function at the specified 70193323Sed /// address. 71193323Sed virtual void *emitFunctionStub(const Function* F, void *Fn, 72193323Sed JITCodeEmitter &JCE); 73193323Sed 74193323Sed /// getLazyResolverFunction - Expose the lazy resolver to the JIT. 75193323Sed virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn); 76193323Sed 77193323Sed /// relocate - Before the JIT can run a block of code that has been emitted, 78193323Sed /// it must rewrite the code to contain the actual addresses of any 79193323Sed /// referenced global symbols. 80193323Sed virtual void relocate(void *Function, MachineRelocation *MR, 81193323Sed unsigned NumRelocs, unsigned char* GOTBase); 82193323Sed 83193323Sed /// hasCustomConstantPool - Allows a target to specify that constant 84193323Sed /// pool address resolution is handled by the target. 85193323Sed virtual bool hasCustomConstantPool() const { return true; } 86193323Sed 87193323Sed /// hasCustomJumpTables - Allows a target to specify that jumptables 88193323Sed /// are emitted by the target. 89193323Sed virtual bool hasCustomJumpTables() const { return true; } 90193323Sed 91193323Sed /// allocateSeparateGVMemory - If true, globals should be placed in 92193323Sed /// separately allocated heap memory rather than in the same 93193323Sed /// code memory allocated by JITCodeEmitter. 94193323Sed virtual bool allocateSeparateGVMemory() const { 95193323Sed#ifdef __APPLE__ 96193323Sed return true; 97193323Sed#else 98193323Sed return false; 99193323Sed#endif 100193323Sed } 101193323Sed 102193323Sed /// Initialize - Initialize internal stage for the function being JITted. 103193323Sed /// Resize constant pool ids to CONSTPOOL_ENTRY addresses map; resize 104193323Sed /// jump table ids to jump table bases map; remember if codegen relocation 105193323Sed /// model is PIC. 106193323Sed void Initialize(const MachineFunction &MF, bool isPIC) { 107193323Sed const ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); 108218893Sdim ConstPoolId2AddrMap.resize(AFI->getNumPICLabels()); 109193323Sed JumpTableId2AddrMap.resize(AFI->getNumJumpTables()); 110193323Sed IsPIC = isPIC; 111193323Sed } 112193323Sed 113193323Sed /// getConstantPoolEntryAddr - The ARM target puts all constant 114193323Sed /// pool entries into constant islands. This returns the address of the 115193323Sed /// constant pool entry of the specified index. 116193323Sed intptr_t getConstantPoolEntryAddr(unsigned CPI) const { 117193323Sed assert(CPI < ConstPoolId2AddrMap.size()); 118193323Sed return ConstPoolId2AddrMap[CPI]; 119193323Sed } 120193323Sed 121193323Sed /// addConstantPoolEntryAddr - Map a Constant Pool Index to the address 122193323Sed /// where its associated value is stored. When relocations are processed, 123193323Sed /// this value will be used to resolve references to the constant. 124193323Sed void addConstantPoolEntryAddr(unsigned CPI, intptr_t Addr) { 125193323Sed assert(CPI < ConstPoolId2AddrMap.size()); 126193323Sed ConstPoolId2AddrMap[CPI] = Addr; 127193323Sed } 128193323Sed 129193323Sed /// getJumpTableBaseAddr - The ARM target inline all jump tables within 130193323Sed /// text section of the function. This returns the address of the base of 131193323Sed /// the jump table of the specified index. 132193323Sed intptr_t getJumpTableBaseAddr(unsigned JTI) const { 133193323Sed assert(JTI < JumpTableId2AddrMap.size()); 134193323Sed return JumpTableId2AddrMap[JTI]; 135193323Sed } 136193323Sed 137193323Sed /// addJumpTableBaseAddr - Map a jump table index to the address where 138193323Sed /// the corresponding inline jump table is emitted. When relocations are 139193323Sed /// processed, this value will be used to resolve references to the 140193323Sed /// jump table. 141193323Sed void addJumpTableBaseAddr(unsigned JTI, intptr_t Addr) { 142193323Sed assert(JTI < JumpTableId2AddrMap.size()); 143193323Sed JumpTableId2AddrMap[JTI] = Addr; 144193323Sed } 145193323Sed 146210299Sed /// getPCLabelAddr - Retrieve the address of the PC label of the 147210299Sed /// specified id. 148193323Sed intptr_t getPCLabelAddr(unsigned Id) const { 149193323Sed DenseMap<unsigned, intptr_t>::const_iterator I = PCLabelMap.find(Id); 150193323Sed assert(I != PCLabelMap.end()); 151193323Sed return I->second; 152193323Sed } 153193323Sed 154193323Sed /// addPCLabelAddr - Remember the address of the specified PC label. 155193323Sed void addPCLabelAddr(unsigned Id, intptr_t Addr) { 156193323Sed PCLabelMap.insert(std::make_pair(Id, Addr)); 157193323Sed } 158193323Sed 159193323Sed /// getIndirectSymAddr - Retrieve the address of the indirect symbol of the 160193323Sed /// specified symbol located at address. Returns 0 if the indirect symbol 161193323Sed /// has not been emitted. 162193323Sed intptr_t getIndirectSymAddr(void *Addr) const { 163193323Sed DenseMap<void*,intptr_t>::const_iterator I= Sym2IndirectSymMap.find(Addr); 164193323Sed if (I != Sym2IndirectSymMap.end()) 165193323Sed return I->second; 166193323Sed return 0; 167193323Sed } 168193323Sed 169193323Sed /// addIndirectSymAddr - Add a mapping from address of an emitted symbol to 170193323Sed /// its indirect symbol address. 171193323Sed void addIndirectSymAddr(void *SymAddr, intptr_t IndSymAddr) { 172193323Sed Sym2IndirectSymMap.insert(std::make_pair(SymAddr, IndSymAddr)); 173193323Sed } 174193323Sed 175193323Sed private: 176193323Sed /// resolveRelocDestAddr - Resolve the resulting address of the relocation 177193323Sed /// if it's not already solved. Constantpool entries must be resolved by 178193323Sed /// ARM target. 179193323Sed intptr_t resolveRelocDestAddr(MachineRelocation *MR) const; 180193323Sed }; 181193323Sed} 182193323Sed 183193323Sed#endif 184