1 //===- Target/TargetJITInfo.h - Target Information for JIT ------*- 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 exposes an abstract interface used by the Just-In-Time code
11 // generator to perform target-specific activities, such as emitting stubs. If
12 // a TargetMachine supports JIT code generation, it should provide one of these
13 // objects through the getJITInfo() method.
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_TARGET_TARGETJITINFO_H
18 #define LLVM_TARGET_TARGETJITINFO_H
21 #include "llvm/Support/ErrorHandling.h"
22 #include "llvm/Support/DataTypes.h"
28 class MachineRelocation;
30 /// TargetJITInfo - Target specific information required by the Just-In-Time
33 virtual void anchor();
35 virtual ~TargetJITInfo() {}
37 /// replaceMachineCodeForFunction - Make it so that calling the function
38 /// whose machine code is at OLD turns into a call to NEW, perhaps by
39 /// overwriting OLD with a branch to NEW. This is used for self-modifying
42 virtual void replaceMachineCodeForFunction(void *Old, void *New) = 0;
44 /// emitGlobalValueIndirectSym - Use the specified JITCodeEmitter object
45 /// to emit an indirect symbol which contains the address of the specified
47 virtual void *emitGlobalValueIndirectSym(const GlobalValue* GV, void *ptr,
48 JITCodeEmitter &JCE) {
49 assert(0 && "This target doesn't implement emitGlobalValueIndirectSym!");
53 /// Records the required size and alignment for a call stub in bytes.
58 /// Returns the maximum size and alignment for a call stub on this target.
59 virtual StubLayout getStubLayout() {
60 llvm_unreachable("This target doesn't implement getStubLayout!");
63 /// emitFunctionStub - Use the specified JITCodeEmitter object to emit a
64 /// small native function that simply calls the function at the specified
65 /// address. The JITCodeEmitter must already have storage allocated for the
66 /// stub. Return the address of the resultant function, which may have been
67 /// aligned from the address the JCE was set up to emit at.
68 virtual void *emitFunctionStub(const Function* F, void *Target,
69 JITCodeEmitter &JCE) {
70 assert(0 && "This target doesn't implement emitFunctionStub!");
74 /// getPICJumpTableEntry - Returns the value of the jumptable entry for the
75 /// specific basic block.
76 virtual uintptr_t getPICJumpTableEntry(uintptr_t BB, uintptr_t JTBase) {
77 assert(0 && "This target doesn't implement getPICJumpTableEntry!");
81 /// LazyResolverFn - This typedef is used to represent the function that
82 /// unresolved call points should invoke. This is a target specific
83 /// function that knows how to walk the stack and find out which stub the
84 /// call is coming from.
85 typedef void (*LazyResolverFn)();
87 /// JITCompilerFn - This typedef is used to represent the JIT function that
88 /// lazily compiles the function corresponding to a stub. The JIT keeps
89 /// track of the mapping between stubs and LLVM Functions, the target
90 /// provides the ability to figure out the address of a stub that is called
91 /// by the LazyResolverFn.
92 typedef void* (*JITCompilerFn)(void *);
94 /// getLazyResolverFunction - This method is used to initialize the JIT,
95 /// giving the target the function that should be used to compile a
96 /// function, and giving the JIT the target function used to do the lazy
98 virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn) {
99 assert(0 && "Not implemented for this target!");
103 /// relocate - Before the JIT can run a block of code that has been emitted,
104 /// it must rewrite the code to contain the actual addresses of any
105 /// referenced global symbols.
106 virtual void relocate(void *Function, MachineRelocation *MR,
107 unsigned NumRelocs, unsigned char* GOTBase) {
108 assert(NumRelocs == 0 && "This target does not have relocations!");
112 /// allocateThreadLocalMemory - Each target has its own way of
113 /// handling thread local variables. This method returns a value only
114 /// meaningful to the target.
115 virtual char* allocateThreadLocalMemory(size_t size) {
116 assert(0 && "This target does not implement thread local storage!");
120 /// needsGOT - Allows a target to specify that it would like the
121 /// JIT to manage a GOT for it.
122 bool needsGOT() const { return useGOT; }
124 /// hasCustomConstantPool - Allows a target to specify that constant
125 /// pool address resolution is handled by the target.
126 virtual bool hasCustomConstantPool() const { return false; }
128 /// hasCustomJumpTables - Allows a target to specify that jumptables
129 /// are emitted by the target.
130 virtual bool hasCustomJumpTables() const { return false; }
132 /// allocateSeparateGVMemory - If true, globals should be placed in
133 /// separately allocated heap memory rather than in the same
134 /// code memory allocated by JITCodeEmitter.
135 virtual bool allocateSeparateGVMemory() const { return false; }
139 } // End llvm namespace