Unweaken vtables as per http://llvm.org/docs/CodingStandards.html#ll_virtual_anch
[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/ErrorHandling.h"
22 #include "llvm/Support/DataTypes.h"
23
24 namespace llvm {
25   class Function;
26   class GlobalValue;
27   class JITCodeEmitter;
28   class MachineRelocation;
29
30   /// TargetJITInfo - Target specific information required by the Just-In-Time
31   /// code generator.
32   class TargetJITInfo {
33     virtual void anchor();
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     /// emitGlobalValueIndirectSym - Use the specified JITCodeEmitter object
45     /// to emit an indirect symbol which contains the address of the specified
46     /// ptr.
47     virtual void *emitGlobalValueIndirectSym(const GlobalValue* GV, void *ptr,
48                                              JITCodeEmitter &JCE) {
49       assert(0 && "This target doesn't implement emitGlobalValueIndirectSym!");
50       return 0;
51     }
52
53     /// Records the required size and alignment for a call stub in bytes.
54     struct StubLayout {
55       size_t Size;
56       size_t Alignment;
57     };
58     /// Returns the maximum size and alignment for a call stub on this target.
59     virtual StubLayout getStubLayout() {
60       llvm_unreachable("This target doesn't implement getStubLayout!");
61       StubLayout Result = {0, 0};
62       return Result;
63     }
64
65     /// emitFunctionStub - Use the specified JITCodeEmitter object to emit a
66     /// small native function that simply calls the function at the specified
67     /// address.  The JITCodeEmitter must already have storage allocated for the
68     /// stub.  Return the address of the resultant function, which may have been
69     /// aligned from the address the JCE was set up to emit at.
70     virtual void *emitFunctionStub(const Function* F, void *Target,
71                                    JITCodeEmitter &JCE) {
72       assert(0 && "This target doesn't implement emitFunctionStub!");
73       return 0;
74     }
75
76     /// getPICJumpTableEntry - Returns the value of the jumptable entry for the
77     /// specific basic block.
78     virtual uintptr_t getPICJumpTableEntry(uintptr_t BB, uintptr_t JTBase) {
79       assert(0 && "This target doesn't implement getPICJumpTableEntry!");
80       return 0;
81     }
82
83     /// LazyResolverFn - This typedef is used to represent the function that
84     /// unresolved call points should invoke.  This is a target specific
85     /// function that knows how to walk the stack and find out which stub the
86     /// call is coming from.
87     typedef void (*LazyResolverFn)();
88
89     /// JITCompilerFn - This typedef is used to represent the JIT function that
90     /// lazily compiles the function corresponding to a stub.  The JIT keeps
91     /// track of the mapping between stubs and LLVM Functions, the target
92     /// provides the ability to figure out the address of a stub that is called
93     /// by the LazyResolverFn.
94     typedef void* (*JITCompilerFn)(void *);
95
96     /// getLazyResolverFunction - This method is used to initialize the JIT,
97     /// giving the target the function that should be used to compile a
98     /// function, and giving the JIT the target function used to do the lazy
99     /// resolving.
100     virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn) {
101       assert(0 && "Not implemented for this target!");
102       return 0;
103     }
104
105     /// relocate - Before the JIT can run a block of code that has been emitted,
106     /// it must rewrite the code to contain the actual addresses of any
107     /// referenced global symbols.
108     virtual void relocate(void *Function, MachineRelocation *MR,
109                           unsigned NumRelocs, unsigned char* GOTBase) {
110       assert(NumRelocs == 0 && "This target does not have relocations!");
111     }
112     
113
114     /// allocateThreadLocalMemory - Each target has its own way of
115     /// handling thread local variables. This method returns a value only
116     /// meaningful to the target.
117     virtual char* allocateThreadLocalMemory(size_t size) {
118       assert(0 && "This target does not implement thread local storage!");
119       return 0;
120     }
121
122     /// needsGOT - Allows a target to specify that it would like the
123     /// JIT to manage a GOT for it.
124     bool needsGOT() const { return useGOT; }
125
126     /// hasCustomConstantPool - Allows a target to specify that constant
127     /// pool address resolution is handled by the target.
128     virtual bool hasCustomConstantPool() const { return false; }
129
130     /// hasCustomJumpTables - Allows a target to specify that jumptables
131     /// are emitted by the target.
132     virtual bool hasCustomJumpTables() const { return false; }
133
134     /// allocateSeparateGVMemory - If true, globals should be placed in
135     /// separately allocated heap memory rather than in the same
136     /// code memory allocated by JITCodeEmitter.
137     virtual bool allocateSeparateGVMemory() const { return false; }
138   protected:
139     bool useGOT;
140   };
141 } // End llvm namespace
142
143 #endif