LLVM API Documentation

TargetJITInfo.h

Go to the documentation of this file.
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 MachineCodeEmitter;
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 MachineCodeEmitter 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                                              MachineCodeEmitter &MCE) {
00047       assert(0 && "This target doesn't implement emitGlobalValueIndirectSym!");
00048       return 0;
00049     }
00050 
00051     /// emitFunctionStub - Use the specified MachineCodeEmitter 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                                    MachineCodeEmitter &MCE) {
00056       assert(0 && "This target doesn't implement emitFunctionStub!");
00057       return 0;
00058     }
00059 
00060     /// getPICJumpTableEntry - Returns the value of the jumptable entry for the
00061     /// specific basic block.
00062     virtual uintptr_t getPICJumpTableEntry(uintptr_t BB, uintptr_t JTBase) {
00063       assert(0 && "This target doesn't implement getPICJumpTableEntry!");
00064       return 0;
00065     }
00066 
00067     /// LazyResolverFn - This typedef is used to represent the function that
00068     /// unresolved call points should invoke.  This is a target specific
00069     /// function that knows how to walk the stack and find out which stub the
00070     /// call is coming from.
00071     typedef void (*LazyResolverFn)();
00072 
00073     /// JITCompilerFn - This typedef is used to represent the JIT function that
00074     /// lazily compiles the function corresponding to a stub.  The JIT keeps
00075     /// track of the mapping between stubs and LLVM Functions, the target
00076     /// provides the ability to figure out the address of a stub that is called
00077     /// by the LazyResolverFn.
00078     typedef void* (*JITCompilerFn)(void *);
00079 
00080     /// getLazyResolverFunction - This method is used to initialize the JIT,
00081     /// giving the target the function that should be used to compile a
00082     /// function, and giving the JIT the target function used to do the lazy
00083     /// resolving.
00084     virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn) {
00085       assert(0 && "Not implemented for this target!");
00086       return 0;
00087     }
00088 
00089     /// relocate - Before the JIT can run a block of code that has been emitted,
00090     /// it must rewrite the code to contain the actual addresses of any
00091     /// referenced global symbols.
00092     virtual void relocate(void *Function, MachineRelocation *MR,
00093                           unsigned NumRelocs, unsigned char* GOTBase) {
00094       assert(NumRelocs == 0 && "This target does not have relocations!");
00095     }
00096     
00097 
00098     /// allocateThreadLocalMemory - Each target has its own way of
00099     /// handling thread local variables. This method returns a value only
00100     /// meaningful to the target.
00101     virtual char* allocateThreadLocalMemory(size_t size) {
00102       assert(0 && "This target does not implement thread local storage!");
00103       return 0;
00104     }
00105 
00106     /// needsGOT - Allows a target to specify that it would like the
00107     // JIT to manage a GOT for it.
00108     bool needsGOT() const { return useGOT; }
00109 
00110     /// hasCustomConstantPool - Allows a target to specify that constant
00111     /// pool address resolution is handled by the target.
00112     virtual bool hasCustomConstantPool() const { return false; }
00113 
00114     /// hasCustomJumpTables - Allows a target to specify that jumptables
00115     /// are emitted by the target.
00116     virtual bool hasCustomJumpTables() const { return false; }
00117 
00118     /// allocateSeparateGVMemory - If true, globals should be placed in
00119     /// separately allocated heap memory rather than in the same
00120     /// code memory allocated by MachineCodeEmitter.
00121     virtual bool allocateSeparateGVMemory() const { return false; }
00122   protected:
00123     bool useGOT;
00124   };
00125 } // End llvm namespace
00126 
00127 #endif