Tidy up #includes, deleting a bunch of unnecessary #includes.
[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 "llvm/Support/DataTypes.h"
22
23 namespace llvm {
24   class Function;
25   class GlobalValue;
26   class MachineCodeEmitter;
27   class MachineRelocation;
28
29   /// TargetJITInfo - Target specific information required by the Just-In-Time
30   /// code generator.
31   class TargetJITInfo {
32   public:
33     virtual ~TargetJITInfo() {}
34
35     /// replaceMachineCodeForFunction - Make it so that calling the function
36     /// whose machine code is at OLD turns into a call to NEW, perhaps by
37     /// overwriting OLD with a branch to NEW.  This is used for self-modifying
38     /// code.
39     ///
40     virtual void replaceMachineCodeForFunction(void *Old, void *New) = 0;
41
42     /// emitGlobalValueIndirectSym - Use the specified MachineCodeEmitter object
43     /// to emit an indirect symbol which contains the address of the specified
44     /// ptr.
45     virtual void *emitGlobalValueIndirectSym(const GlobalValue* GV, void *ptr,
46                                              MachineCodeEmitter &MCE) {
47       assert(0 && "This target doesn't implement emitGlobalValueIndirectSym!");
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(const Function* F, void *Fn,
55                                    MachineCodeEmitter &MCE) {
56       assert(0 && "This target doesn't implement emitFunctionStub!");
57       return 0;
58     }
59
60     /// getPICJumpTableEntry - Returns the value of the jumptable entry for the
61     /// specific basic block.
62     virtual uintptr_t getPICJumpTableEntry(uintptr_t BB, uintptr_t JTBase) {
63       assert(0 && "This target doesn't implement getPICJumpTableEntry!");
64       return 0;
65     }
66
67     /// LazyResolverFn - This typedef is used to represent the function that
68     /// unresolved call points should invoke.  This is a target specific
69     /// function that knows how to walk the stack and find out which stub the
70     /// call is coming from.
71     typedef void (*LazyResolverFn)();
72
73     /// JITCompilerFn - This typedef is used to represent the JIT function that
74     /// lazily compiles the function corresponding to a stub.  The JIT keeps
75     /// track of the mapping between stubs and LLVM Functions, the target
76     /// provides the ability to figure out the address of a stub that is called
77     /// by the LazyResolverFn.
78     typedef void* (*JITCompilerFn)(void *);
79
80     /// getLazyResolverFunction - This method is used to initialize the JIT,
81     /// giving the target the function that should be used to compile a
82     /// function, and giving the JIT the target function used to do the lazy
83     /// resolving.
84     virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn) {
85       assert(0 && "Not implemented for this target!");
86       return 0;
87     }
88
89     /// relocate - Before the JIT can run a block of code that has been emitted,
90     /// it must rewrite the code to contain the actual addresses of any
91     /// referenced global symbols.
92     virtual void relocate(void *Function, MachineRelocation *MR,
93                           unsigned NumRelocs, unsigned char* GOTBase) {
94       assert(NumRelocs == 0 && "This target does not have relocations!");
95     }
96     
97
98     /// allocateThreadLocalMemory - Each target has its own way of
99     /// handling thread local variables. This method returns a value only
100     /// meaningful to the target.
101     virtual char* allocateThreadLocalMemory(size_t size) {
102       assert(0 && "This target does not implement thread local storage!");
103       return 0;
104     }
105
106     /// needsGOT - Allows a target to specify that it would like the
107     // JIT to manage a GOT for it.
108     bool needsGOT() const { return useGOT; }
109
110     /// hasCustomConstantPool - Allows a target to specify that constant
111     /// pool address resolution is handled by the target.
112     virtual bool hasCustomConstantPool() const { return false; }
113
114     /// hasCustomJumpTables - Allows a target to specify that jumptables
115     /// are emitted by the target.
116     virtual bool hasCustomJumpTables() const { return false; }
117
118     /// allocateSeparateGVMemory - If true, globals should be placed in
119     /// separately allocated heap memory rather than in the same
120     /// code memory allocated by MachineCodeEmitter.
121     virtual bool allocateSeparateGVMemory() const { return false; }
122   protected:
123     bool useGOT;
124   };
125 } // End llvm namespace
126
127 #endif