blob: 2a3a7f8f37c5145e6e60915748f90bd57377147b [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"
19#include "llvm/ADT/DenseMap.h"
Evan Cheng938b9d82008-10-31 19:55:13 +000020#include "llvm/ADT/SmallVector.h"
Evan Cheng148b6a42007-07-05 21:15:40 +000021
22namespace llvm {
23 class ARMTargetMachine;
24
25 class ARMJITInfo : public TargetJITInfo {
26 ARMTargetMachine &TM;
Evan Cheng0f282432008-10-29 23:55:43 +000027
Evan Cheng25e04782008-11-04 00:50:32 +000028 // MCPEs - List of the constant pool entries for the current machine
29 // function that's being processed.
30 const std::vector<MachineConstantPoolEntry> *MCPEs;
31
Evan Cheng0f282432008-10-29 23:55:43 +000032 // ConstPoolId2AddrMap - A map from constant pool ids to the corresponding
33 // CONSTPOOL_ENTRY addresses.
Evan Cheng938b9d82008-10-31 19:55:13 +000034 SmallVector<intptr_t, 32> ConstPoolId2AddrMap;
Evan Cheng0f282432008-10-29 23:55:43 +000035
Evan Cheng25e04782008-11-04 00:50:32 +000036 // PCLabelMap - A map from PC labels to addresses.
37 DenseMap<unsigned, intptr_t> PCLabelMap;
38
Evan Cheng148b6a42007-07-05 21:15:40 +000039 public:
Jim Grosbachbc6d8762008-10-28 18:25:49 +000040 explicit ARMJITInfo(ARMTargetMachine &tm) : TM(tm) { useGOT = false; }
Evan Cheng148b6a42007-07-05 21:15:40 +000041
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
45 /// code.
46 ///
47 virtual void replaceMachineCodeForFunction(void *Old, void *New);
48
49 /// emitFunctionStub - Use the specified MachineCodeEmitter object to emit a
50 /// small native function that simply calls the function at the specified
51 /// address.
Nicolas Geoffray51cc3c12008-04-16 20:46:05 +000052 virtual void *emitFunctionStub(const Function* F, void *Fn,
53 MachineCodeEmitter &MCE);
Evan Cheng148b6a42007-07-05 21:15:40 +000054
55 /// getLazyResolverFunction - Expose the lazy resolver to the JIT.
56 virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn);
57
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);
Evan Cheng25e04782008-11-04 00:50:32 +000063
Jim Grosbachbc6d8762008-10-28 18:25:49 +000064 /// hasCustomConstantPool - Allows a target to specify that constant
65 /// pool address resolution is handled by the target.
66 virtual bool hasCustomConstantPool() const { return true; }
67
Evan Chengb0b53492008-11-04 09:30:48 +000068 /// 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 {
72#ifdef __APPLE__
73 return true;
74#else
75 return false;
76#endif
77 }
78
Evan Cheng25e04782008-11-04 00:50:32 +000079 /// 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) {
82 MCPEs = mcpes;
83 ConstPoolId2AddrMap.resize(MCPEs->size());
Evan Cheng938b9d82008-10-31 19:55:13 +000084 }
85
Evan Cheng0f282432008-10-29 23:55:43 +000086 /// getConstantPoolEntryAddr - The ARM target puts all constant
Jim Grosbachbc6d8762008-10-28 18:25:49 +000087 /// pool entries into constant islands. Resolve the constant pool index
88 /// into the address where the constant is stored.
Evan Cheng938b9d82008-10-31 19:55:13 +000089 intptr_t getConstantPoolEntryAddr(unsigned CPI) const {
90 assert(CPI < ConstPoolId2AddrMap.size());
91 return ConstPoolId2AddrMap[CPI];
Evan Cheng0f282432008-10-29 23:55:43 +000092 }
Jim Grosbachbc6d8762008-10-28 18:25:49 +000093
Evan Cheng938b9d82008-10-31 19:55:13 +000094 /// addConstantPoolEntryAddr - Map a Constant Pool Index (CPI) to the address
Jim Grosbachbc6d8762008-10-28 18:25:49 +000095 /// where its associated value is stored. When relocations are processed,
96 /// this value will be used to resolve references to the constant.
Evan Cheng938b9d82008-10-31 19:55:13 +000097 void addConstantPoolEntryAddr(unsigned CPI, intptr_t Addr) {
98 assert(CPI < ConstPoolId2AddrMap.size());
99 ConstPoolId2AddrMap[CPI] = Addr;
Evan Cheng0f282432008-10-29 23:55:43 +0000100 }
Evan Cheng25e04782008-11-04 00:50:32 +0000101
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());
106 return I->second;
107 }
108
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));
112 }
113
114 private:
115 /// resolveRelocationAddr - Resolve the resulting address of the relocation
116 /// if it's not already solved. Constantpool entries must be resolved by
117 /// ARM target.
118 intptr_t resolveRelocationAddr(MachineRelocation *MR) const;
Evan Cheng148b6a42007-07-05 21:15:40 +0000119 };
120}
121
122#endif