TargetJITInfo.h revision 8b67f774e9c38b7718b2b300b628388f966df4e0
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/System/DataTypes.h" 22 23namespace llvm { 24 class Function; 25 class GlobalValue; 26 class JITCodeEmitter; 27 class MachineRelocation; 28 29 /// TargetJITInfo - Target specific information required by the Just-In-Time 30 /// code generator. 31 class TargetJITInfo { 32 public: 33 virtual ~TargetJITInfo() {} 34 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 38 /// code. 39 /// 40 virtual void replaceMachineCodeForFunction(void *Old, void *New) = 0; 41 42 /// emitGlobalValueIndirectSym - Use the specified JITCodeEmitter object 43 /// to emit an indirect symbol which contains the address of the specified 44 /// ptr. 45 virtual void *emitGlobalValueIndirectSym(const GlobalValue* GV, void *ptr, 46 JITCodeEmitter &JCE) { 47 assert(0 && "This target doesn't implement emitGlobalValueIndirectSym!"); 48 return 0; 49 } 50 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!"); 57 return 0; 58 } 59 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!"); 66 } 67 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!"); 72 return 0; 73 } 74 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)(); 80 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 *); 87 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 91 /// resolving. 92 virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn) { 93 assert(0 && "Not implemented for this target!"); 94 return 0; 95 } 96 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!"); 103 } 104 105 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!"); 111 return 0; 112 } 113 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; } 117 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; } 121 122 /// hasCustomJumpTables - Allows a target to specify that jumptables 123 /// are emitted by the target. 124 virtual bool hasCustomJumpTables() const { return false; } 125 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; } 130 protected: 131 bool useGOT; 132 }; 133} // End llvm namespace 134 135#endif 136