Handle ARM machine constantpool entry with non-lazy ptr.
[oota-llvm.git] / lib / Target / ARM / ARMJITInfo.h
1 //===- ARMJITInfo.h - ARM implementation of the JIT interface  --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
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 "ARMMachineFunctionInfo.h"
18 #include "llvm/CodeGen/MachineConstantPool.h"
19 #include "llvm/CodeGen/MachineFunction.h"
20 #include "llvm/CodeGen/MachineJumpTableInfo.h"
21 #include "llvm/Target/TargetJITInfo.h"
22 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/ADT/SmallVector.h"
24
25 namespace llvm {
26   class ARMTargetMachine;
27
28   class ARMJITInfo : public TargetJITInfo {
29     ARMTargetMachine &TM;
30
31     // ConstPoolId2AddrMap - A map from constant pool ids to the corresponding
32     // CONSTPOOL_ENTRY addresses.
33     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;
38
39     // PCLabelMap - A map from PC labels to addresses.
40     DenseMap<unsigned, intptr_t> PCLabelMap;
41
42   public:
43     explicit ARMJITInfo(ARMTargetMachine &tm) : TM(tm) { useGOT = false; }
44
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     /// emitGlobalValueNonLazyPtr - Use the specified MachineCodeEmitter object
53     /// to emit a Mac OS X non-lazy pointer which contains the address of the
54     /// specified ptr.
55     virtual void *emitGlobalValueNonLazyPtr(const GlobalValue *GV, void *Ptr,
56                                             MachineCodeEmitter &MCE);
57
58     /// emitFunctionStub - Use the specified MachineCodeEmitter object to emit a
59     /// small native function that simply calls the function at the specified
60     /// address.
61     virtual void *emitFunctionStub(const Function* F, void *Fn,
62                                    MachineCodeEmitter &MCE);
63
64     /// getLazyResolverFunction - Expose the lazy resolver to the JIT.
65     virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn);
66
67     /// relocate - Before the JIT can run a block of code that has been emitted,
68     /// it must rewrite the code to contain the actual addresses of any
69     /// referenced global symbols.
70     virtual void relocate(void *Function, MachineRelocation *MR,
71                           unsigned NumRelocs, unsigned char* GOTBase);
72
73     /// hasCustomConstantPool - Allows a target to specify that constant
74     /// pool address resolution is handled by the target.
75     virtual bool hasCustomConstantPool() const { return true; }
76
77     /// hasCustomJumpTables - Allows a target to specify that jumptables
78     /// are emitted by the target.
79     virtual bool hasCustomJumpTables() const { return true; }
80
81     /// allocateSeparateGVMemory - If true, globals should be placed in
82     /// separately allocated heap memory rather than in the same
83     /// code memory allocated by MachineCodeEmitter.
84     virtual bool allocateSeparateGVMemory() const {
85 #ifdef __APPLE__
86       return true;
87 #else
88       return false;
89 #endif
90     }
91
92     /// Initialize - Initialize internal stage. Get the list of constant pool
93     /// Resize constant pool ids to CONSTPOOL_ENTRY addresses map.
94     void Initialize(const MachineFunction &MF) {
95       const ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>();
96       ConstPoolId2AddrMap.resize(AFI->getNumConstPoolEntries());
97       JumpTableId2AddrMap.resize(AFI->getNumJumpTables());
98     }
99
100     /// getConstantPoolEntryAddr - The ARM target puts all constant
101     /// pool entries into constant islands. This returns the address of the
102     /// constant pool entry of the specified index.
103     intptr_t getConstantPoolEntryAddr(unsigned CPI) const {
104       assert(CPI < ConstPoolId2AddrMap.size());
105       return ConstPoolId2AddrMap[CPI];
106     }
107
108     /// addConstantPoolEntryAddr - Map a Constant Pool Index to the address
109     /// where its associated value is stored. When relocations are processed,
110     /// this value will be used to resolve references to the constant.
111     void addConstantPoolEntryAddr(unsigned CPI, intptr_t Addr) {
112       assert(CPI < ConstPoolId2AddrMap.size());
113       ConstPoolId2AddrMap[CPI] = Addr;
114     }
115
116     /// getJumpTableBaseAddr - The ARM target inline all jump tables within
117     /// text section of the function. This returns the address of the base of
118     /// the jump table of the specified index.
119     intptr_t getJumpTableBaseAddr(unsigned JTI) const {
120       assert(JTI < JumpTableId2AddrMap.size());
121       return JumpTableId2AddrMap[JTI];
122     }
123
124     /// addJumpTableBaseAddr - Map a jump table index to the address where
125     /// the corresponding inline jump table is emitted. When relocations are
126     /// processed, this value will be used to resolve references to the
127     /// jump table.
128     void addJumpTableBaseAddr(unsigned JTI, intptr_t Addr) {
129       assert(JTI < JumpTableId2AddrMap.size());
130       JumpTableId2AddrMap[JTI] = Addr;
131     }
132
133     /// getPCLabelAddr - Retrieve the address of the PC label of the specified id.
134     intptr_t getPCLabelAddr(unsigned Id) const {
135       DenseMap<unsigned, intptr_t>::const_iterator I = PCLabelMap.find(Id);
136       assert(I != PCLabelMap.end());
137       return I->second;
138     }
139
140     /// addPCLabelAddr - Remember the address of the specified PC label.
141     void addPCLabelAddr(unsigned Id, intptr_t Addr) {
142       PCLabelMap.insert(std::make_pair(Id, Addr));
143     }
144
145   private:
146     /// resolveRelocDestAddr - Resolve the resulting address of the relocation
147     /// if it's not already solved. Constantpool entries must be resolved by
148     /// ARM target.
149     intptr_t resolveRelocDestAddr(MachineRelocation *MR) const;
150   };
151 }
152
153 #endif