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/DataTypes.h"
27 class MachineRelocation;
29 /// TargetJITInfo - Target specific information required by the Just-In-Time
33 virtual ~TargetJITInfo() {}
35 /// replaceMachineCodeForFunction - Make it so that calling the function
36 /// whose machine code is at OLD turns into a call to NEW, perhaps by
37 /// overwriting OLD with a branch to NEW. This is used for self-modifying
40 virtual void replaceMachineCodeForFunction(void *Old, void *New) = 0;
42 /// emitGlobalValueIndirectSym - Use the specified JITCodeEmitter object
43 /// to emit an indirect symbol which contains the address of the specified
45 virtual void *emitGlobalValueIndirectSym(const GlobalValue* GV, void *ptr,
46 JITCodeEmitter &JCE) {
47 assert(0 && "This target doesn't implement emitGlobalValueIndirectSym!");
51 /// emitFunctionStub - Use the specified JITCodeEmitter object to emit a
52 /// small native function that simply calls the function at the specified
53 /// address. Return the address of the resultant function.
54 virtual void *emitFunctionStub(const Function* F, void *Fn,
55 JITCodeEmitter &JCE) {
56 assert(0 && "This target doesn't implement emitFunctionStub!");
60 /// emitFunctionStubAtAddr - Use the specified JITCodeEmitter object to
61 /// emit a small native function that simply calls Fn. Emit the stub into
62 /// the supplied buffer.
63 virtual void emitFunctionStubAtAddr(const Function* F, void *Fn,
64 void *Buffer, JITCodeEmitter &JCE) {
65 assert(0 && "This target doesn't implement emitFunctionStubAtAddr!");
68 /// getPICJumpTableEntry - Returns the value of the jumptable entry for the
69 /// specific basic block.
70 virtual uintptr_t getPICJumpTableEntry(uintptr_t BB, uintptr_t JTBase) {
71 assert(0 && "This target doesn't implement getPICJumpTableEntry!");
75 /// LazyResolverFn - This typedef is used to represent the function that
76 /// unresolved call points should invoke. This is a target specific
77 /// function that knows how to walk the stack and find out which stub the
78 /// call is coming from.
79 typedef void (*LazyResolverFn)();
81 /// JITCompilerFn - This typedef is used to represent the JIT function that
82 /// lazily compiles the function corresponding to a stub. The JIT keeps
83 /// track of the mapping between stubs and LLVM Functions, the target
84 /// provides the ability to figure out the address of a stub that is called
85 /// by the LazyResolverFn.
86 typedef void* (*JITCompilerFn)(void *);
88 /// getLazyResolverFunction - This method is used to initialize the JIT,
89 /// giving the target the function that should be used to compile a
90 /// function, and giving the JIT the target function used to do the lazy
92 virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn) {
93 assert(0 && "Not implemented for this target!");
97 /// relocate - Before the JIT can run a block of code that has been emitted,
98 /// it must rewrite the code to contain the actual addresses of any
99 /// referenced global symbols.
100 virtual void relocate(void *Function, MachineRelocation *MR,
101 unsigned NumRelocs, unsigned char* GOTBase) {
102 assert(NumRelocs == 0 && "This target does not have relocations!");
106 /// allocateThreadLocalMemory - Each target has its own way of
107 /// handling thread local variables. This method returns a value only
108 /// meaningful to the target.
109 virtual char* allocateThreadLocalMemory(size_t size) {
110 assert(0 && "This target does not implement thread local storage!");
114 /// needsGOT - Allows a target to specify that it would like the
115 /// JIT to manage a GOT for it.
116 bool needsGOT() const { return useGOT; }
118 /// hasCustomConstantPool - Allows a target to specify that constant
119 /// pool address resolution is handled by the target.
120 virtual bool hasCustomConstantPool() const { return false; }
122 /// hasCustomJumpTables - Allows a target to specify that jumptables
123 /// are emitted by the target.
124 virtual bool hasCustomJumpTables() const { return false; }
126 /// allocateSeparateGVMemory - If true, globals should be placed in
127 /// separately allocated heap memory rather than in the same
128 /// code memory allocated by JITCodeEmitter.
129 virtual bool allocateSeparateGVMemory() const { return false; }
133 } // End llvm namespace