1 //===- ARMJITInfo.h - ARM implementation of the JIT interface --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the declaration of the ARMJITInfo class.
12 //===----------------------------------------------------------------------===//
17 #include "llvm/Target/TargetJITInfo.h"
18 #include "llvm/CodeGen/MachineConstantPool.h"
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/SmallVector.h"
23 class ARMTargetMachine;
25 class ARMJITInfo : public TargetJITInfo {
28 // MCPEs - List of the constant pool entries for the current machine
29 // function that's being processed.
30 const std::vector<MachineConstantPoolEntry> *MCPEs;
32 // ConstPoolId2AddrMap - A map from constant pool ids to the corresponding
33 // CONSTPOOL_ENTRY addresses.
34 SmallVector<intptr_t, 32> ConstPoolId2AddrMap;
36 // PCLabelMap - A map from PC labels to addresses.
37 DenseMap<unsigned, intptr_t> PCLabelMap;
40 explicit ARMJITInfo(ARMTargetMachine &tm) : TM(tm) { useGOT = false; }
42 /// replaceMachineCodeForFunction - Make it so that calling the function
43 /// whose machine code is at OLD turns into a call to NEW, perhaps by
44 /// overwriting OLD with a branch to NEW. This is used for self-modifying
47 virtual void replaceMachineCodeForFunction(void *Old, void *New);
49 /// emitFunctionStub - Use the specified MachineCodeEmitter object to emit a
50 /// small native function that simply calls the function at the specified
52 virtual void *emitFunctionStub(const Function* F, void *Fn,
53 MachineCodeEmitter &MCE);
55 /// getLazyResolverFunction - Expose the lazy resolver to the JIT.
56 virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn);
58 /// relocate - Before the JIT can run a block of code that has been emitted,
59 /// it must rewrite the code to contain the actual addresses of any
60 /// referenced global symbols.
61 virtual void relocate(void *Function, MachineRelocation *MR,
62 unsigned NumRelocs, unsigned char* GOTBase);
64 /// hasCustomConstantPool - Allows a target to specify that constant
65 /// pool address resolution is handled by the target.
66 virtual bool hasCustomConstantPool() const { return true; }
68 /// allocateSeparateGVMemory - If true, globals should be placed in
69 /// separately allocated heap memory rather than in the same
70 /// code memory allocated by MachineCodeEmitter.
71 virtual bool allocateSeparateGVMemory() const {
79 /// Initialize - Initialize internal stage. Get the list of constant pool
80 /// Resize constant pool ids to CONSTPOOL_ENTRY addresses map.
81 void Initialize(const std::vector<MachineConstantPoolEntry> *mcpes) {
83 ConstPoolId2AddrMap.resize(MCPEs->size());
86 /// getConstantPoolEntryAddr - The ARM target puts all constant
87 /// pool entries into constant islands. Resolve the constant pool index
88 /// into the address where the constant is stored.
89 intptr_t getConstantPoolEntryAddr(unsigned CPI) const {
90 assert(CPI < ConstPoolId2AddrMap.size());
91 return ConstPoolId2AddrMap[CPI];
94 /// addConstantPoolEntryAddr - Map a Constant Pool Index (CPI) to the address
95 /// where its associated value is stored. When relocations are processed,
96 /// this value will be used to resolve references to the constant.
97 void addConstantPoolEntryAddr(unsigned CPI, intptr_t Addr) {
98 assert(CPI < ConstPoolId2AddrMap.size());
99 ConstPoolId2AddrMap[CPI] = Addr;
102 /// getPCLabelAddr - Retrieve the address of the PC label of the specified id.
103 intptr_t getPCLabelAddr(unsigned Id) const {
104 DenseMap<unsigned, intptr_t>::const_iterator I = PCLabelMap.find(Id);
105 assert(I != PCLabelMap.end());
109 /// addPCLabelAddr - Remember the address of the specified PC label.
110 void addPCLabelAddr(unsigned Id, intptr_t Addr) {
111 PCLabelMap.insert(std::make_pair(Id, Addr));
115 /// resolveRelocationAddr - Resolve the resulting address of the relocation
116 /// if it's not already solved. Constantpool entries must be resolved by
118 intptr_t resolveRelocationAddr(MachineRelocation *MR) const;