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.

153 lines
6.0 KiB

  1. //===-- llvm/CodeGen/GCStrategy.h - Garbage collection ----------*- 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. // GCStrategy coordinates code generation algorithms and implements some itself
  11. // in order to generate code compatible with a target code generator as
  12. // specified in a function's 'gc' attribute. Algorithms are enabled by setting
  13. // flags in a subclass's constructor, and some virtual methods can be
  14. // overridden.
  15. //
  16. // When requested, the GCStrategy will be populated with data about each
  17. // function which uses it. Specifically:
  18. //
  19. // - Safe points
  20. // Garbage collection is generally only possible at certain points in code.
  21. // GCStrategy can request that the collector insert such points:
  22. //
  23. // - At and after any call to a subroutine
  24. // - Before returning from the current function
  25. // - Before backwards branches (loops)
  26. //
  27. // - Roots
  28. // When a reference to a GC-allocated object exists on the stack, it must be
  29. // stored in an alloca registered with llvm.gcoot.
  30. //
  31. // This information can used to emit the metadata tables which are required by
  32. // the target garbage collector runtime.
  33. //
  34. //===----------------------------------------------------------------------===//
  35. #ifndef LLVM_CODEGEN_GCSTRATEGY_H
  36. #define LLVM_CODEGEN_GCSTRATEGY_H
  37. #include "llvm/CodeGen/GCMetadata.h"
  38. #include "llvm/CodeGen/MachineFunction.h"
  39. #include "llvm/Support/Registry.h"
  40. #include <string>
  41. namespace llvm {
  42. class GCStrategy;
  43. /// The GC strategy registry uses all the defaults from Registry.
  44. ///
  45. typedef Registry<GCStrategy> GCRegistry;
  46. /// GCStrategy describes a garbage collector algorithm's code generation
  47. /// requirements, and provides overridable hooks for those needs which cannot
  48. /// be abstractly described.
  49. class GCStrategy {
  50. public:
  51. typedef std::vector<GCFunctionInfo*> list_type;
  52. typedef list_type::iterator iterator;
  53. private:
  54. friend class GCModuleInfo;
  55. const Module *M;
  56. std::string Name;
  57. list_type Functions;
  58. protected:
  59. unsigned NeededSafePoints; ///< Bitmask of required safe points.
  60. bool CustomReadBarriers; ///< Default is to insert loads.
  61. bool CustomWriteBarriers; ///< Default is to insert stores.
  62. bool CustomRoots; ///< Default is to pass through to backend.
  63. bool CustomSafePoints; ///< Default is to use NeededSafePoints
  64. ///< to find safe points.
  65. bool InitRoots; ///< If set, roots are nulled during lowering.
  66. bool UsesMetadata; ///< If set, backend must emit metadata tables.
  67. public:
  68. GCStrategy();
  69. virtual ~GCStrategy();
  70. /// getName - The name of the GC strategy, for debugging.
  71. ///
  72. const std::string &getName() const { return Name; }
  73. /// getModule - The module within which the GC strategy is operating.
  74. ///
  75. const Module &getModule() const { return *M; }
  76. /// needsSafePoitns - True if safe points of any kind are required. By
  77. // default, none are recorded.
  78. bool needsSafePoints() const {
  79. return CustomSafePoints || NeededSafePoints != 0;
  80. }
  81. /// needsSafePoint(Kind) - True if the given kind of safe point is
  82. // required. By default, none are recorded.
  83. bool needsSafePoint(GC::PointKind Kind) const {
  84. return (NeededSafePoints & 1 << Kind) != 0;
  85. }
  86. /// customWriteBarrier - By default, write barriers are replaced with simple
  87. /// store instructions. If true, then
  88. /// performCustomLowering must instead lower them.
  89. bool customWriteBarrier() const { return CustomWriteBarriers; }
  90. /// customReadBarrier - By default, read barriers are replaced with simple
  91. /// load instructions. If true, then
  92. /// performCustomLowering must instead lower them.
  93. bool customReadBarrier() const { return CustomReadBarriers; }
  94. /// customRoots - By default, roots are left for the code generator so it
  95. /// can generate a stack map. If true, then
  96. // performCustomLowering must delete them.
  97. bool customRoots() const { return CustomRoots; }
  98. /// customSafePoints - By default, the GC analysis will find safe
  99. /// points according to NeededSafePoints. If true,
  100. /// then findCustomSafePoints must create them.
  101. bool customSafePoints() const { return CustomSafePoints; }
  102. /// initializeRoots - If set, gcroot intrinsics should initialize their
  103. // allocas to null before the first use. This is
  104. // necessary for most GCs and is enabled by default.
  105. bool initializeRoots() const { return InitRoots; }
  106. /// usesMetadata - If set, appropriate metadata tables must be emitted by
  107. /// the back-end (assembler, JIT, or otherwise).
  108. bool usesMetadata() const { return UsesMetadata; }
  109. /// begin/end - Iterators for function metadata.
  110. ///
  111. iterator begin() { return Functions.begin(); }
  112. iterator end() { return Functions.end(); }
  113. /// insertFunctionMetadata - Creates metadata for a function.
  114. ///
  115. GCFunctionInfo *insertFunctionInfo(const Function &F);
  116. /// initializeCustomLowering/performCustomLowering - If any of the actions
  117. /// are set to custom, performCustomLowering must be overriden to transform
  118. /// the corresponding actions to LLVM IR. initializeCustomLowering is
  119. /// optional to override. These are the only GCStrategy methods through
  120. /// which the LLVM IR can be modified.
  121. virtual bool initializeCustomLowering(Module &F);
  122. virtual bool performCustomLowering(Function &F);
  123. virtual bool findCustomSafePoints(GCFunctionInfo& FI, MachineFunction& MF);
  124. };
  125. }
  126. #endif