Unbreak build with gcc 4.3: provide missed includes and silence most annoying warnings.
[oota-llvm.git] / include / llvm / Target / TargetJITInfo.h
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 <vector>
21 #include <cassert>
22 #include "llvm/Support/DataTypes.h"
23
24 namespace llvm {
25   class Function;
26   class FunctionPassManager;
27   class MachineBasicBlock;
28   class MachineCodeEmitter;
29   class MachineRelocation;
30
31   /// TargetJITInfo - Target specific information required by the Just-In-Time
32   /// code generator.
33   class TargetJITInfo {
34   public:
35     virtual ~TargetJITInfo() {}
36
37     /// replaceMachineCodeForFunction - Make it so that calling the function
38     /// whose machine code is at OLD turns into a call to NEW, perhaps by
39     /// overwriting OLD with a branch to NEW.  This is used for self-modifying
40     /// code.
41     ///
42     virtual void replaceMachineCodeForFunction(void *Old, void *New) = 0;
43
44     /// emitGlobalValueLazyPtr - Use the specified MachineCodeEmitter object to
45     /// emit a lazy pointer which contains the address of the specified GV.
46     virtual void *emitGlobalValueLazyPtr(void *GV, MachineCodeEmitter &MCE) {
47       assert(0 && "This target doesn't implement emitGlobalValueLazyPtr!");
48       return 0;
49     }
50
51     /// emitFunctionStub - Use the specified MachineCodeEmitter 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(void *Fn, MachineCodeEmitter &MCE) {
55       assert(0 && "This target doesn't implement emitFunctionStub!");
56       return 0;
57     }
58
59     /// getPICJumpTableEntry - Returns the value of the jumptable entry for the
60     /// specific basic block.
61     virtual intptr_t getPICJumpTableEntry(intptr_t BB, intptr_t JTBase) {
62       assert(0 && "This target doesn't implement getPICJumpTableEntry!");
63       return 0;
64     }
65
66     /// LazyResolverFn - This typedef is used to represent the function that
67     /// unresolved call points should invoke.  This is a target specific
68     /// function that knows how to walk the stack and find out which stub the
69     /// call is coming from.
70     typedef void (*LazyResolverFn)();
71
72     /// JITCompilerFn - This typedef is used to represent the JIT function that
73     /// lazily compiles the function corresponding to a stub.  The JIT keeps
74     /// track of the mapping between stubs and LLVM Functions, the target
75     /// provides the ability to figure out the address of a stub that is called
76     /// by the LazyResolverFn.
77     typedef void* (*JITCompilerFn)(void *);
78
79     /// getLazyResolverFunction - This method is used to initialize the JIT,
80     /// giving the target the function that should be used to compile a
81     /// function, and giving the JIT the target function used to do the lazy
82     /// resolving.
83     virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn) {
84       assert(0 && "Not implemented for this target!");
85       return 0;
86     }
87
88     /// relocate - Before the JIT can run a block of code that has been emitted,
89     /// it must rewrite the code to contain the actual addresses of any
90     /// referenced global symbols.
91     virtual void relocate(void *Function, MachineRelocation *MR,
92                           unsigned NumRelocs, unsigned char* GOTBase) {
93       assert(NumRelocs == 0 && "This target does not have relocations!");
94     }
95
96     /// needsGOT - Allows a target to specify that it would like the
97     // JIT to manage a GOT for it.
98     bool needsGOT() const { return useGOT; }
99
100   protected:
101     bool useGOT;
102   };
103 } // End llvm namespace
104
105 #endif