LLVM API Documentation
00001 //===- Target/TargetJITInfo.h - Target Information for JIT ------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source 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 00022 namespace llvm { 00023 class Function; 00024 class FunctionPassManager; 00025 class MachineCodeEmitter; 00026 class MachineRelocation; 00027 00028 /// TargetJITInfo - Target specific information required by the Just-In-Time 00029 /// code generator. 00030 class TargetJITInfo { 00031 public: 00032 virtual ~TargetJITInfo() {} 00033 00034 /// addPassesToJITCompile - Add passes to the specified pass manager to 00035 /// implement a fast code generator for this target. 00036 /// 00037 virtual void addPassesToJITCompile(FunctionPassManager &PM) = 0; 00038 00039 /// replaceMachineCodeForFunction - Make it so that calling the function 00040 /// whose machine code is at OLD turns into a call to NEW, perhaps by 00041 /// overwriting OLD with a branch to NEW. This is used for self-modifying 00042 /// code. 00043 /// 00044 virtual void replaceMachineCodeForFunction(void *Old, void *New) = 0; 00045 00046 /// emitFunctionStub - Use the specified MachineCodeEmitter object to emit a 00047 /// small native function that simply calls the function at the specified 00048 /// address. Return the address of the resultant function. 00049 virtual void *emitFunctionStub(void *Fn, MachineCodeEmitter &MCE) { 00050 assert(0 && "This target doesn't implement emitFunctionStub!"); 00051 return 0; 00052 } 00053 00054 /// LazyResolverFn - This typedef is used to represent the function that 00055 /// unresolved call points should invoke. This is a target specific 00056 /// function that knows how to walk the stack and find out which stub the 00057 /// call is coming from. 00058 typedef void (*LazyResolverFn)(); 00059 00060 /// JITCompilerFn - This typedef is used to represent the JIT function that 00061 /// lazily compiles the function corresponding to a stub. The JIT keeps 00062 /// track of the mapping between stubs and LLVM Functions, the target 00063 /// provides the ability to figure out the address of a stub that is called 00064 /// by the LazyResolverFn. 00065 typedef void* (*JITCompilerFn)(void *); 00066 00067 /// getLazyResolverFunction - This method is used to initialize the JIT, 00068 /// giving the target the function that should be used to compile a 00069 /// function, and giving the JIT the target function used to do the lazy 00070 /// resolving. 00071 virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn) { 00072 assert(0 && "Not implemented for this target!"); 00073 return 0; 00074 } 00075 00076 /// relocate - Before the JIT can run a block of code that has been emitted, 00077 /// it must rewrite the code to contain the actual addresses of any 00078 /// referenced global symbols. 00079 virtual void relocate(void *Function, MachineRelocation *MR, 00080 unsigned NumRelocs) { 00081 assert(NumRelocs == 0 && "This target does not have relocations!"); 00082 } 00083 }; 00084 } // End llvm namespace 00085 00086 #endif