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