X86JITInfo.h revision 5788d1a169db3346a612a13113348d2709bdd15b
11e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner//===- 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 1751cc3c13eac78da242f0518fc42580e48dd5304fNicolas Geoffray#include "llvm/Function.h" 181e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner#include "llvm/Target/TargetJITInfo.h" 191e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner 201e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattnernamespace llvm { 21c4c6257c1a154279bf10e9498d46d6c1793dbaa7Evan Cheng class X86TargetMachine; 224482715f3d1c165be82bd5aed07231f956e472efChris Lattner 231e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner class X86JITInfo : public TargetJITInfo { 24c4c6257c1a154279bf10e9498d46d6c1793dbaa7Evan Cheng X86TargetMachine &TM; 255788d1a169db3346a612a13113348d2709bdd15bEvan Cheng uintptr_t PICBase; 2646fa139e26be6ebc00be2fb45820c2560dd22a32Nicolas Geoffray char* TLSOffset; 271e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner public: 2846fa139e26be6ebc00be2fb45820c2560dd22a32Nicolas Geoffray explicit X86JITInfo(X86TargetMachine &tm) : TM(tm) { 2946fa139e26be6ebc00be2fb45820c2560dd22a32Nicolas Geoffray useGOT = 0; 3046fa139e26be6ebc00be2fb45820c2560dd22a32Nicolas Geoffray TLSOffset = 0; 3146fa139e26be6ebc00be2fb45820c2560dd22a32Nicolas Geoffray } 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 409ed2f80910160bbf8051d91cd74c82d4619885b4Evan Cheng /// emitGlobalValueIndirectSym - Use the specified MachineCodeEmitter 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, 449ed2f80910160bbf8051d91cd74c82d4619885b4Evan Cheng MachineCodeEmitter &MCE); 45be8c03fc66b75fa775e1f47d62a1b0d803fced1cEvan Cheng 4689d64e262cb4eb075e039bcc10813f77d60f1ed8Chris Lattner /// emitFunctionStub - Use the specified MachineCodeEmitter object to emit a 4789d64e262cb4eb075e039bcc10813f77d60f1ed8Chris Lattner /// small native function that simply calls the function at the specified 4889d64e262cb4eb075e039bcc10813f77d60f1ed8Chris Lattner /// address. 4951cc3c13eac78da242f0518fc42580e48dd5304fNicolas Geoffray virtual void *emitFunctionStub(const Function* F, void *Fn, 5051cc3c13eac78da242f0518fc42580e48dd5304fNicolas Geoffray MachineCodeEmitter &MCE); 5189d64e262cb4eb075e039bcc10813f77d60f1ed8Chris Lattner 522a3e08b5961353fa3faeadf81f481ae9f5463427Evan Cheng /// getPICJumpTableEntry - Returns the value of the jumptable entry for the 532a3e08b5961353fa3faeadf81f481ae9f5463427Evan Cheng /// specific basic block. 545788d1a169db3346a612a13113348d2709bdd15bEvan Cheng virtual uintptr_t getPICJumpTableEntry(uintptr_t BB, uintptr_t JTBase); 552a3e08b5961353fa3faeadf81f481ae9f5463427Evan Cheng 5689d64e262cb4eb075e039bcc10813f77d60f1ed8Chris Lattner /// getLazyResolverFunction - Expose the lazy resolver to the JIT. 5789d64e262cb4eb075e039bcc10813f77d60f1ed8Chris Lattner virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn); 5889d64e262cb4eb075e039bcc10813f77d60f1ed8Chris Lattner 5989d64e262cb4eb075e039bcc10813f77d60f1ed8Chris Lattner /// relocate - Before the JIT can run a block of code that has been emitted, 6089d64e262cb4eb075e039bcc10813f77d60f1ed8Chris Lattner /// it must rewrite the code to contain the actual addresses of any 6189d64e262cb4eb075e039bcc10813f77d60f1ed8Chris Lattner /// referenced global symbols. 6289d64e262cb4eb075e039bcc10813f77d60f1ed8Chris Lattner virtual void relocate(void *Function, MachineRelocation *MR, 63908bc862d58bdb66d22a6a58bddb4e108a64e469Andrew Lenharth unsigned NumRelocs, unsigned char* GOTBase); 6446fa139e26be6ebc00be2fb45820c2560dd22a32Nicolas Geoffray 6546fa139e26be6ebc00be2fb45820c2560dd22a32Nicolas Geoffray /// allocateThreadLocalMemory - Each target has its own way of 6646fa139e26be6ebc00be2fb45820c2560dd22a32Nicolas Geoffray /// handling thread local variables. This method returns a value only 6746fa139e26be6ebc00be2fb45820c2560dd22a32Nicolas Geoffray /// meaningful to the target. 6846fa139e26be6ebc00be2fb45820c2560dd22a32Nicolas Geoffray virtual char* allocateThreadLocalMemory(size_t size); 692a3e08b5961353fa3faeadf81f481ae9f5463427Evan Cheng 702a3e08b5961353fa3faeadf81f481ae9f5463427Evan Cheng /// setPICBase / getPICBase - Getter / setter of PICBase, used to compute 712a3e08b5961353fa3faeadf81f481ae9f5463427Evan Cheng /// PIC jumptable entry. 725788d1a169db3346a612a13113348d2709bdd15bEvan Cheng void setPICBase(uintptr_t Base) { PICBase = Base; } 735788d1a169db3346a612a13113348d2709bdd15bEvan Cheng uintptr_t getPICBase() const { return PICBase; } 741e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner }; 751e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner} 761e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner 771e60a9165dc4d6ce5650dacc026f2942696af920Chris Lattner#endif 78