131d157ae1ac2cd9c787dc3c1d28e64c682803844Jia Liu//===-- X86JITInfo.h - X86 implementation of the JIT interface --*- C++ -*-===//
20e0a7a45d3d0a8c865a078459d2e1c6d8967a100Misha Brukman//
31e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner//                     The LLVM Compiler Infrastructure
41e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner//
54ee451de366474b9c228b4e5fa573795a715216dChris Lattner// This file is distributed under the University of Illinois Open Source
64ee451de366474b9c228b4e5fa573795a715216dChris Lattner// License. See LICENSE.TXT for details.
70e0a7a45d3d0a8c865a078459d2e1c6d8967a100Misha Brukman//
81e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner//===----------------------------------------------------------------------===//
91e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner//
101e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner// This file contains the X86 implementation of the TargetJITInfo class.
111e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner//
121e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner//===----------------------------------------------------------------------===//
131e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner
141e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner#ifndef X86JITINFO_H
151e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner#define X86JITINFO_H
161e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner
17a3f99f90338d89354384ca25f53ca4450a1a9d18Bruno Cardoso Lopes#include "llvm/CodeGen/JITCodeEmitter.h"
180b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Function.h"
191e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner#include "llvm/Target/TargetJITInfo.h"
201e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner
211e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattnernamespace llvm {
22c4c6257c1a154279bf10e9498d46d6c1793dbaa7Evan Cheng  class X86TargetMachine;
23d0da6ff3ad761dc5eb00cbe32b850de7b0bf27b6Evan Cheng  class X86Subtarget;
244482715f3d1c165be82bd5aed07231f956e472efChris Lattner
251e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner  class X86JITInfo : public TargetJITInfo {
26c4c6257c1a154279bf10e9498d46d6c1793dbaa7Evan Cheng    X86TargetMachine &TM;
27d0da6ff3ad761dc5eb00cbe32b850de7b0bf27b6Evan Cheng    const X86Subtarget *Subtarget;
285788d1a169db3346a612a13113348d2709bdd15bEvan Cheng    uintptr_t PICBase;
2946fa139e26be6ebc00be2fb45820c2560dd22a32Nicolas Geoffray    char* TLSOffset;
301e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner  public:
31d0da6ff3ad761dc5eb00cbe32b850de7b0bf27b6Evan Cheng    explicit X86JITInfo(X86TargetMachine &tm);
321e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner
331e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner    /// replaceMachineCodeForFunction - Make it so that calling the function
341e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner    /// whose machine code is at OLD turns into a call to NEW, perhaps by
351e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner    /// overwriting OLD with a branch to NEW.  This is used for self-modifying
361e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner    /// code.
371e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner    ///
38f70e0c216c074bd2ae2b08178f5512849545db4eChris Lattner    virtual void replaceMachineCodeForFunction(void *Old, void *New);
390e0a7a45d3d0a8c865a078459d2e1c6d8967a100Misha Brukman
40a3f99f90338d89354384ca25f53ca4450a1a9d18Bruno Cardoso Lopes    /// emitGlobalValueIndirectSym - Use the specified JITCodeEmitter object
419ed2f80910160bbf8051d91cd74c82d4619885b4Evan Cheng    /// to emit an indirect symbol which contains the address of the specified
429ed2f80910160bbf8051d91cd74c82d4619885b4Evan Cheng    /// ptr.
439ed2f80910160bbf8051d91cd74c82d4619885b4Evan Cheng    virtual void *emitGlobalValueIndirectSym(const GlobalValue* GV, void *ptr,
44a3f99f90338d89354384ca25f53ca4450a1a9d18Bruno Cardoso Lopes                                             JITCodeEmitter &JCE);
45be8c03fc66b75fa775e1f47d62a1b0d803fced1cEvan Cheng
46108c838093704650378b194fe9afc5ebb9e91455Jeffrey Yasskin    // getStubLayout - Returns the size and alignment of the largest call stub
47108c838093704650378b194fe9afc5ebb9e91455Jeffrey Yasskin    // on X86.
48108c838093704650378b194fe9afc5ebb9e91455Jeffrey Yasskin    virtual StubLayout getStubLayout();
49108c838093704650378b194fe9afc5ebb9e91455Jeffrey Yasskin
50a3f99f90338d89354384ca25f53ca4450a1a9d18Bruno Cardoso Lopes    /// emitFunctionStub - Use the specified JITCodeEmitter object to emit a
5189d64e262cb4eb075e039bcc10813f77d60f1ed8Chris Lattner    /// small native function that simply calls the function at the specified
5289d64e262cb4eb075e039bcc10813f77d60f1ed8Chris Lattner    /// address.
53108c838093704650378b194fe9afc5ebb9e91455Jeffrey Yasskin    virtual void *emitFunctionStub(const Function* F, void *Target,
54a3f99f90338d89354384ca25f53ca4450a1a9d18Bruno Cardoso Lopes                                   JITCodeEmitter &JCE);
5589d64e262cb4eb075e039bcc10813f77d60f1ed8Chris Lattner
562a3e08b5961353fa3faeadf81f481ae9f5463427Evan Cheng    /// getPICJumpTableEntry - Returns the value of the jumptable entry for the
572a3e08b5961353fa3faeadf81f481ae9f5463427Evan Cheng    /// specific basic block.
585788d1a169db3346a612a13113348d2709bdd15bEvan Cheng    virtual uintptr_t getPICJumpTableEntry(uintptr_t BB, uintptr_t JTBase);
592a3e08b5961353fa3faeadf81f481ae9f5463427Evan Cheng
6089d64e262cb4eb075e039bcc10813f77d60f1ed8Chris Lattner    /// getLazyResolverFunction - Expose the lazy resolver to the JIT.
6189d64e262cb4eb075e039bcc10813f77d60f1ed8Chris Lattner    virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn);
6289d64e262cb4eb075e039bcc10813f77d60f1ed8Chris Lattner
6389d64e262cb4eb075e039bcc10813f77d60f1ed8Chris Lattner    /// relocate - Before the JIT can run a block of code that has been emitted,
6489d64e262cb4eb075e039bcc10813f77d60f1ed8Chris Lattner    /// it must rewrite the code to contain the actual addresses of any
6589d64e262cb4eb075e039bcc10813f77d60f1ed8Chris Lattner    /// referenced global symbols.
6689d64e262cb4eb075e039bcc10813f77d60f1ed8Chris Lattner    virtual void relocate(void *Function, MachineRelocation *MR,
67908bc862d58bdb66d22a6a58bddb4e108a64e469Andrew Lenharth                          unsigned NumRelocs, unsigned char* GOTBase);
68a20e1e7ef596842127794372244fd5c646f71296Chad Rosier
6946fa139e26be6ebc00be2fb45820c2560dd22a32Nicolas Geoffray    /// allocateThreadLocalMemory - Each target has its own way of
7046fa139e26be6ebc00be2fb45820c2560dd22a32Nicolas Geoffray    /// handling thread local variables. This method returns a value only
7146fa139e26be6ebc00be2fb45820c2560dd22a32Nicolas Geoffray    /// meaningful to the target.
7246fa139e26be6ebc00be2fb45820c2560dd22a32Nicolas Geoffray    virtual char* allocateThreadLocalMemory(size_t size);
732a3e08b5961353fa3faeadf81f481ae9f5463427Evan Cheng
742a3e08b5961353fa3faeadf81f481ae9f5463427Evan Cheng    /// setPICBase / getPICBase - Getter / setter of PICBase, used to compute
752a3e08b5961353fa3faeadf81f481ae9f5463427Evan Cheng    /// PIC jumptable entry.
765788d1a169db3346a612a13113348d2709bdd15bEvan Cheng    void setPICBase(uintptr_t Base) { PICBase = Base; }
775788d1a169db3346a612a13113348d2709bdd15bEvan Cheng    uintptr_t getPICBase() const { return PICBase; }
781e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner  };
791e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner}
801e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner
811e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner#endif
82