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