LLVM API Documentation
00001 //===- Target/TargetJITInfo.h - Target Information for JIT ------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file exposes an abstract interface used by the Just-In-Time code 00011 // generator to perform target-specific activities, such as emitting stubs. If 00012 // a TargetMachine supports JIT code generation, it should provide one of these 00013 // objects through the getJITInfo() method. 00014 // 00015 //===----------------------------------------------------------------------===// 00016 00017 #ifndef LLVM_TARGET_TARGETJITINFO_H 00018 #define LLVM_TARGET_TARGETJITINFO_H 00019 00020 #include <cassert> 00021 #include "llvm/Support/DataTypes.h" 00022 00023 namespace llvm { 00024 class Function; 00025 class GlobalValue; 00026 class JITCodeEmitter; 00027 class MachineRelocation; 00028 00029 /// TargetJITInfo - Target specific information required by the Just-In-Time 00030 /// code generator. 00031 class TargetJITInfo { 00032 public: 00033 virtual ~TargetJITInfo() {} 00034 00035 /// replaceMachineCodeForFunction - Make it so that calling the function 00036 /// whose machine code is at OLD turns into a call to NEW, perhaps by 00037 /// overwriting OLD with a branch to NEW. This is used for self-modifying 00038 /// code. 00039 /// 00040 virtual void replaceMachineCodeForFunction(void *Old, void *New) = 0; 00041 00042 /// emitGlobalValueIndirectSym - Use the specified JITCodeEmitter object 00043 /// to emit an indirect symbol which contains the address of the specified 00044 /// ptr. 00045 virtual void *emitGlobalValueIndirectSym(const GlobalValue* GV, void *ptr, 00046 JITCodeEmitter &JCE) { 00047 assert(0 && "This target doesn't implement emitGlobalValueIndirectSym!"); 00048 return 0; 00049 } 00050 00051 /// emitFunctionStub - Use the specified JITCodeEmitter object to emit a 00052 /// small native function that simply calls the function at the specified 00053 /// address. Return the address of the resultant function. 00054 virtual void *emitFunctionStub(const Function* F, void *Fn, 00055 JITCodeEmitter &JCE) { 00056 assert(0 && "This target doesn't implement emitFunctionStub!"); 00057 return 0; 00058 } 00059 00060 /// emitFunctionStubAtAddr - Use the specified JITCodeEmitter object to 00061 /// emit a small native function that simply calls Fn. Emit the stub into 00062 /// the supplied buffer. 00063 virtual void emitFunctionStubAtAddr(const Function* F, void *Fn, 00064 void *Buffer, JITCodeEmitter &JCE) { 00065 assert(0 && "This target doesn't implement emitFunctionStubAtAddr!"); 00066 } 00067 00068 /// getPICJumpTableEntry - Returns the value of the jumptable entry for the 00069 /// specific basic block. 00070 virtual uintptr_t getPICJumpTableEntry(uintptr_t BB, uintptr_t JTBase) { 00071 assert(0 && "This target doesn't implement getPICJumpTableEntry!"); 00072 return 0; 00073 } 00074 00075 /// LazyResolverFn - This typedef is used to represent the function that 00076 /// unresolved call points should invoke. This is a target specific 00077 /// function that knows how to walk the stack and find out which stub the 00078 /// call is coming from. 00079 typedef void (*LazyResolverFn)(); 00080 00081 /// JITCompilerFn - This typedef is used to represent the JIT function that 00082 /// lazily compiles the function corresponding to a stub. The JIT keeps 00083 /// track of the mapping between stubs and LLVM Functions, the target 00084 /// provides the ability to figure out the address of a stub that is called 00085 /// by the LazyResolverFn. 00086 typedef void* (*JITCompilerFn)(void *); 00087 00088 /// getLazyResolverFunction - This method is used to initialize the JIT, 00089 /// giving the target the function that should be used to compile a 00090 /// function, and giving the JIT the target function used to do the lazy 00091 /// resolving. 00092 virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn) { 00093 assert(0 && "Not implemented for this target!"); 00094 return 0; 00095 } 00096 00097 /// relocate - Before the JIT can run a block of code that has been emitted, 00098 /// it must rewrite the code to contain the actual addresses of any 00099 /// referenced global symbols. 00100 virtual void relocate(void *Function, MachineRelocation *MR, 00101 unsigned NumRelocs, unsigned char* GOTBase) { 00102 assert(NumRelocs == 0 && "This target does not have relocations!"); 00103 } 00104 00105 00106 /// allocateThreadLocalMemory - Each target has its own way of 00107 /// handling thread local variables. This method returns a value only 00108 /// meaningful to the target. 00109 virtual char* allocateThreadLocalMemory(size_t size) { 00110 assert(0 && "This target does not implement thread local storage!"); 00111 return 0; 00112 } 00113 00114 /// needsGOT - Allows a target to specify that it would like the 00115 /// JIT to manage a GOT for it. 00116 bool needsGOT() const { return useGOT; } 00117 00118 /// hasCustomConstantPool - Allows a target to specify that constant 00119 /// pool address resolution is handled by the target. 00120 virtual bool hasCustomConstantPool() const { return false; } 00121 00122 /// hasCustomJumpTables - Allows a target to specify that jumptables 00123 /// are emitted by the target. 00124 virtual bool hasCustomJumpTables() const { return false; } 00125 00126 /// allocateSeparateGVMemory - If true, globals should be placed in 00127 /// separately allocated heap memory rather than in the same 00128 /// code memory allocated by JITCodeEmitter. 00129 virtual bool allocateSeparateGVMemory() const { return false; } 00130 protected: 00131 bool useGOT; 00132 }; 00133 } // End llvm namespace 00134 00135 #endif