TargetJITInfo.h revision c96a8e7df1ffeebc5fb876f5eef380e8547ce14f
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
23namespace llvm {
24  class Function;
25  class GlobalValue;
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    /// emitGlobalValueNonLazyPtr - Use the specified MachineCodeEmitter object
44    /// to emit a Mac OS X non-lazy pointer which contains the address of the
45    /// specified ptr.
46    virtual void *emitGlobalValueNonLazyPtr(const GlobalValue* GV, void *ptr,
47                                            MachineCodeEmitter &MCE) {
48      assert(0 && "This target doesn't implement emitGlobalValueNonLazyPtr!");
49      return 0;
50    }
51
52    /// emitFunctionStub - Use the specified MachineCodeEmitter object to emit a
53    /// small native function that simply calls the function at the specified
54    /// address.  Return the address of the resultant function.
55    virtual void *emitFunctionStub(const Function* F, void *Fn,
56                                   MachineCodeEmitter &MCE) {
57      assert(0 && "This target doesn't implement emitFunctionStub!");
58      return 0;
59    }
60
61    /// getPICJumpTableEntry - Returns the value of the jumptable entry for the
62    /// specific basic block.
63    virtual intptr_t getPICJumpTableEntry(intptr_t BB, intptr_t JTBase) {
64      assert(0 && "This target doesn't implement getPICJumpTableEntry!");
65      return 0;
66    }
67
68    /// LazyResolverFn - This typedef is used to represent the function that
69    /// unresolved call points should invoke.  This is a target specific
70    /// function that knows how to walk the stack and find out which stub the
71    /// call is coming from.
72    typedef void (*LazyResolverFn)();
73
74    /// JITCompilerFn - This typedef is used to represent the JIT function that
75    /// lazily compiles the function corresponding to a stub.  The JIT keeps
76    /// track of the mapping between stubs and LLVM Functions, the target
77    /// provides the ability to figure out the address of a stub that is called
78    /// by the LazyResolverFn.
79    typedef void* (*JITCompilerFn)(void *);
80
81    /// getLazyResolverFunction - This method is used to initialize the JIT,
82    /// giving the target the function that should be used to compile a
83    /// function, and giving the JIT the target function used to do the lazy
84    /// resolving.
85    virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn) {
86      assert(0 && "Not implemented for this target!");
87      return 0;
88    }
89
90    /// relocate - Before the JIT can run a block of code that has been emitted,
91    /// it must rewrite the code to contain the actual addresses of any
92    /// referenced global symbols.
93    virtual void relocate(void *Function, MachineRelocation *MR,
94                          unsigned NumRelocs, unsigned char* GOTBase) {
95      assert(NumRelocs == 0 && "This target does not have relocations!");
96    }
97
98
99    /// allocateThreadLocalMemory - Each target has its own way of
100    /// handling thread local variables. This method returns a value only
101    /// meaningful to the target.
102    virtual char* allocateThreadLocalMemory(size_t size) {
103      assert(0 && "This target does not implement thread local storage!");
104      return 0;
105    }
106
107    /// needsGOT - Allows a target to specify that it would like the
108    // JIT to manage a GOT for it.
109    bool needsGOT() const { return useGOT; }
110
111    /// hasCustomConstantPool - Allows a target to specify that constant
112    /// pool address resolution is handled by the target.
113    virtual bool hasCustomConstantPool() const { return false; }
114
115    /// allocateSeparateGVMemory - If true, globals should be placed in
116    /// separately allocated heap memory rather than in the same
117    /// code memory allocated by MachineCodeEmitter.
118    virtual bool allocateSeparateGVMemory() const { return false; }
119  protected:
120    bool useGOT;
121  };
122} // End llvm namespace
123
124#endif
125