Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

137 lines
5.6 KiB

  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. #ifndef LLVM_TARGET_TARGETJITINFO_H
  17. #define LLVM_TARGET_TARGETJITINFO_H
  18. #include "llvm/Support/DataTypes.h"
  19. #include "llvm/Support/ErrorHandling.h"
  20. #include <cassert>
  21. namespace llvm {
  22. class Function;
  23. class GlobalValue;
  24. class JITCodeEmitter;
  25. class MachineRelocation;
  26. /// TargetJITInfo - Target specific information required by the Just-In-Time
  27. /// code generator.
  28. class TargetJITInfo {
  29. virtual void anchor();
  30. public:
  31. virtual ~TargetJITInfo() {}
  32. /// replaceMachineCodeForFunction - Make it so that calling the function
  33. /// whose machine code is at OLD turns into a call to NEW, perhaps by
  34. /// overwriting OLD with a branch to NEW. This is used for self-modifying
  35. /// code.
  36. ///
  37. virtual void replaceMachineCodeForFunction(void *Old, void *New) = 0;
  38. /// emitGlobalValueIndirectSym - Use the specified JITCodeEmitter object
  39. /// to emit an indirect symbol which contains the address of the specified
  40. /// ptr.
  41. virtual void *emitGlobalValueIndirectSym(const GlobalValue* GV, void *ptr,
  42. JITCodeEmitter &JCE) {
  43. llvm_unreachable("This target doesn't implement "
  44. "emitGlobalValueIndirectSym!");
  45. }
  46. /// Records the required size and alignment for a call stub in bytes.
  47. struct StubLayout {
  48. size_t Size;
  49. size_t Alignment;
  50. };
  51. /// Returns the maximum size and alignment for a call stub on this target.
  52. virtual StubLayout getStubLayout() {
  53. llvm_unreachable("This target doesn't implement getStubLayout!");
  54. }
  55. /// emitFunctionStub - Use the specified JITCodeEmitter object to emit a
  56. /// small native function that simply calls the function at the specified
  57. /// address. The JITCodeEmitter must already have storage allocated for the
  58. /// stub. Return the address of the resultant function, which may have been
  59. /// aligned from the address the JCE was set up to emit at.
  60. virtual void *emitFunctionStub(const Function* F, void *Target,
  61. JITCodeEmitter &JCE) {
  62. llvm_unreachable("This target doesn't implement emitFunctionStub!");
  63. }
  64. /// getPICJumpTableEntry - Returns the value of the jumptable entry for the
  65. /// specific basic block.
  66. virtual uintptr_t getPICJumpTableEntry(uintptr_t BB, uintptr_t JTBase) {
  67. llvm_unreachable("This target doesn't implement getPICJumpTableEntry!");
  68. }
  69. /// LazyResolverFn - This typedef is used to represent the function that
  70. /// unresolved call points should invoke. This is a target specific
  71. /// function that knows how to walk the stack and find out which stub the
  72. /// call is coming from.
  73. typedef void (*LazyResolverFn)();
  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. /// getLazyResolverFunction - This method is used to initialize the JIT,
  81. /// giving the target the function that should be used to compile a
  82. /// function, and giving the JIT the target function used to do the lazy
  83. /// resolving.
  84. virtual LazyResolverFn getLazyResolverFunction(JITCompilerFn) {
  85. llvm_unreachable("Not implemented for this target!");
  86. }
  87. /// relocate - Before the JIT can run a block of code that has been emitted,
  88. /// it must rewrite the code to contain the actual addresses of any
  89. /// referenced global symbols.
  90. virtual void relocate(void *Function, MachineRelocation *MR,
  91. unsigned NumRelocs, unsigned char* GOTBase) {
  92. assert(NumRelocs == 0 && "This target does not have relocations!");
  93. }
  94. /// allocateThreadLocalMemory - Each target has its own way of
  95. /// handling thread local variables. This method returns a value only
  96. /// meaningful to the target.
  97. virtual char* allocateThreadLocalMemory(size_t size) {
  98. llvm_unreachable("This target does not implement thread local storage!");
  99. }
  100. /// needsGOT - Allows a target to specify that it would like the
  101. /// JIT to manage a GOT for it.
  102. bool needsGOT() const { return useGOT; }
  103. /// hasCustomConstantPool - Allows a target to specify that constant
  104. /// pool address resolution is handled by the target.
  105. virtual bool hasCustomConstantPool() const { return false; }
  106. /// hasCustomJumpTables - Allows a target to specify that jumptables
  107. /// are emitted by the target.
  108. virtual bool hasCustomJumpTables() const { return false; }
  109. /// allocateSeparateGVMemory - If true, globals should be placed in
  110. /// separately allocated heap memory rather than in the same
  111. /// code memory allocated by JITCodeEmitter.
  112. virtual bool allocateSeparateGVMemory() const { return false; }
  113. protected:
  114. bool useGOT;
  115. };
  116. } // End llvm namespace
  117. #endif