1 //===- Target/TargetJITInfo.h - Target Information for JIT ------*- 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 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. 14 // 15 //===----------------------------------------------------------------------===// 16 17 #ifndef LLVM_TARGET_TARGETJITINFO_H 18 #define LLVM_TARGET_TARGETJITINFO_H 19 20 #include <cassert> 21 #include "llvm/Support/ErrorHandling.h" 22 #include "llvm/Support/DataTypes.h" 23 24 namespace llvm { 25 class Function; 26 class GlobalValue; 27 class JITCodeEmitter; 28 class MachineRelocation; 29 30 /// TargetJITInfo - Target specific information required by the Just-In-Time 31 /// code generator. 32 class TargetJITInfo { 33 public: 34 virtual ~TargetJITInfo() {} 35 36 /// replaceMachineCodeForFunction - Make it so that calling the function 37 /// whose machine code is at OLD turns into a call to NEW, perhaps by 38 /// overwriting OLD with a branch to NEW. This is used for self-modifying 39 /// code. 40 /// 41 virtual void replaceMachineCodeForFunction(void *Old, void *New) = 0; 42 43 /// emitGlobalValueIndirectSym - Use the specified JITCodeEmitter object 44 /// to emit an indirect symbol which contains the address of the specified 45 /// ptr. 46 virtual void *emitGlobalValueIndirectSym(const GlobalValue* GV, void *ptr, 47 JITCodeEmitter &JCE) { 48 assert(0 && "This target doesn't implement emitGlobalValueIndirectSym!"); 49 return 0; 50 } 51 52 /// Records the required size and alignment for a call stub in bytes. 53 struct StubLayout { 54 size_t Size; 55 size_t Alignment; 56 }; 57 /// Returns the maximum size and alignment for a call stub on this target. 58 virtual StubLayout getStubLayout() { 59 llvm_unreachable("This target doesn't implement getStubLayout!"); 60 StubLayout Result = {0, 0}; 61 return Result; 62 } 63 64 /// emitFunctionStub - Use the specified JITCodeEmitter object to emit a 65 /// small native function that simply calls the function at the specified 66 /// address. The JITCodeEmitter must already have storage allocated for the 67 /// stub. Return the address of the resultant function, which may have been 68 /// aligned from the address the JCE was set up to emit at. 69 virtual void *emitFunctionStub(const Function* F, void *Target, 70 JITCodeEmitter &JCE) { 71 assert(0 && "This target doesn't implement emitFunctionStub!"); 72 return 0; 73 } 74 75 /// getPICJumpTableEntry - Returns the value of the jumptable entry for the 76 /// specific basic block. 77 virtual uintptr_t getPICJumpTableEntry(uintptr_t BB, uintptr_t JTBase) { 78 assert(0 && "This target doesn't implement getPICJumpTableEntry!"); 79 return 0; 80 } 81 82 /// LazyResolverFn - This typedef is used to represent the function that 83 /// unresolved call points should invoke. This is a target specific 84 /// function that knows how to walk the stack and find out which stub the 85 /// call is coming from. 86 typedef void (*LazyResolverFn)(); 87 88 /// JITCompilerFn - This typedef is used to represent the JIT function that 89 /// lazily compiles the function corresponding to a stub. The JIT keeps 90 /// track of the mapping between stubs and LLVM Functions, the target 91 /// provides the ability to figure out the address of a stub that is called 92 /// by the LazyResolverFn. 93 typedef void* (*JITCompilerFn)(void *); 94 95 /// getLazyResolverFunction - This method is used to initialize the JIT, 96 /// giving the target the function that should be used to compile a 97 /// function, and giving the JIT the target function used to do the lazy 98 /// resolving. 99 virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn) { 100 assert(0 && "Not implemented for this target!"); 101 return 0; 102 } 103 104 /// relocate - Before the JIT can run a block of code that has been emitted, 105 /// it must rewrite the code to contain the actual addresses of any 106 /// referenced global symbols. 107 virtual void relocate(void *Function, MachineRelocation *MR, 108 unsigned NumRelocs, unsigned char* GOTBase) { 109 assert(NumRelocs == 0 && "This target does not have relocations!"); 110 } 111 112 113 /// allocateThreadLocalMemory - Each target has its own way of 114 /// handling thread local variables. This method returns a value only 115 /// meaningful to the target. 116 virtual char* allocateThreadLocalMemory(size_t size) { 117 assert(0 && "This target does not implement thread local storage!"); 118 return 0; 119 } 120 121 /// needsGOT - Allows a target to specify that it would like the 122 /// JIT to manage a GOT for it. 123 bool needsGOT() const { return useGOT; } 124 125 /// hasCustomConstantPool - Allows a target to specify that constant 126 /// pool address resolution is handled by the target. 127 virtual bool hasCustomConstantPool() const { return false; } 128 129 /// hasCustomJumpTables - Allows a target to specify that jumptables 130 /// are emitted by the target. 131 virtual bool hasCustomJumpTables() const { return false; } 132 133 /// allocateSeparateGVMemory - If true, globals should be placed in 134 /// separately allocated heap memory rather than in the same 135 /// code memory allocated by JITCodeEmitter. 136 virtual bool allocateSeparateGVMemory() const { return false; } 137 protected: 138 bool useGOT; 139 }; 140 } // End llvm namespace 141 142 #endif 143