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
20 #include "llvm/Support/ErrorHandling.h"
21 #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 llvm_unreachable("This target doesn't implement "
50 "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 llvm_unreachable("This target doesn't implement emitFunctionStub!");
73 /// getPICJumpTableEntry - Returns the value of the jumptable entry for the
74 /// specific basic block.
75 virtual uintptr_t getPICJumpTableEntry(uintptr_t BB, uintptr_t JTBase) {
76 llvm_unreachable("This target doesn't implement getPICJumpTableEntry!");
79 /// LazyResolverFn - This typedef is used to represent the function that
80 /// unresolved call points should invoke. This is a target specific
81 /// function that knows how to walk the stack and find out which stub the
82 /// call is coming from.
83 typedef void (*LazyResolverFn)();
85 /// JITCompilerFn - This typedef is used to represent the JIT function that
86 /// lazily compiles the function corresponding to a stub. The JIT keeps
87 /// track of the mapping between stubs and LLVM Functions, the target
88 /// provides the ability to figure out the address of a stub that is called
89 /// by the LazyResolverFn.
90 typedef void* (*JITCompilerFn)(void *);
92 /// getLazyResolverFunction - This method is used to initialize the JIT,
93 /// giving the target the function that should be used to compile a
94 /// function, and giving the JIT the target function used to do the lazy
96 virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn) {
97 llvm_unreachable("Not implemented for this target!");
100 /// relocate - Before the JIT can run a block of code that has been emitted,
101 /// it must rewrite the code to contain the actual addresses of any
102 /// referenced global symbols.
103 virtual void relocate(void *Function, MachineRelocation *MR,
104 unsigned NumRelocs, unsigned char* GOTBase) {
105 assert(NumRelocs == 0 && "This target does not have relocations!");
109 /// allocateThreadLocalMemory - Each target has its own way of
110 /// handling thread local variables. This method returns a value only
111 /// meaningful to the target.
112 virtual char* allocateThreadLocalMemory(size_t size) {
113 llvm_unreachable("This target does not implement thread local storage!");
116 /// needsGOT - Allows a target to specify that it would like the
117 /// JIT to manage a GOT for it.
118 bool needsGOT() const { return useGOT; }
120 /// hasCustomConstantPool - Allows a target to specify that constant
121 /// pool address resolution is handled by the target.
122 virtual bool hasCustomConstantPool() const { return false; }
124 /// hasCustomJumpTables - Allows a target to specify that jumptables
125 /// are emitted by the target.
126 virtual bool hasCustomJumpTables() const { return false; }
128 /// allocateSeparateGVMemory - If true, globals should be placed in
129 /// separately allocated heap memory rather than in the same
130 /// code memory allocated by JITCodeEmitter.
131 virtual bool allocateSeparateGVMemory() const { return false; }
135 } // End llvm namespace