PassInfo.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //===- llvm/PassInfo.h - Pass Info class ------------------------*- 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 defines and implements the PassInfo class.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_PASSINFO_H
  14. #define LLVM_PASSINFO_H
  15. #include <cassert>
  16. #include <vector>
  17. namespace llvm {
  18. class Pass;
  19. class TargetMachine;
  20. //===---------------------------------------------------------------------------
  21. /// PassInfo class - An instance of this class exists for every pass known by
  22. /// the system, and can be obtained from a live Pass by calling its
  23. /// getPassInfo() method. These objects are set up by the RegisterPass<>
  24. /// template.
  25. ///
  26. class PassInfo {
  27. public:
  28. typedef Pass* (*NormalCtor_t)();
  29. typedef Pass *(*TargetMachineCtor_t)(TargetMachine *);
  30. private:
  31. const char *const PassName; // Nice name for Pass
  32. const char *const PassArgument; // Command Line argument to run this pass
  33. const void *PassID;
  34. const bool IsCFGOnlyPass; // Pass only looks at the CFG.
  35. const bool IsAnalysis; // True if an analysis pass.
  36. const bool IsAnalysisGroup; // True if an analysis group.
  37. std::vector<const PassInfo*> ItfImpl;// Interfaces implemented by this pass
  38. NormalCtor_t NormalCtor;
  39. TargetMachineCtor_t TargetMachineCtor;
  40. public:
  41. /// PassInfo ctor - Do not call this directly, this should only be invoked
  42. /// through RegisterPass.
  43. PassInfo(const char *name, const char *arg, const void *pi,
  44. NormalCtor_t normal, bool isCFGOnly, bool is_analysis,
  45. TargetMachineCtor_t machine = nullptr)
  46. : PassName(name), PassArgument(arg), PassID(pi),
  47. IsCFGOnlyPass(isCFGOnly),
  48. IsAnalysis(is_analysis), IsAnalysisGroup(false), NormalCtor(normal),
  49. TargetMachineCtor(machine) {}
  50. /// PassInfo ctor - Do not call this directly, this should only be invoked
  51. /// through RegisterPass. This version is for use by analysis groups; it
  52. /// does not auto-register the pass.
  53. PassInfo(const char *name, const void *pi)
  54. : PassName(name), PassArgument(""), PassID(pi),
  55. IsCFGOnlyPass(false),
  56. IsAnalysis(false), IsAnalysisGroup(true), NormalCtor(nullptr),
  57. TargetMachineCtor(nullptr) {}
  58. /// getPassName - Return the friendly name for the pass, never returns null
  59. ///
  60. const char *getPassName() const { return PassName; }
  61. /// getPassArgument - Return the command line option that may be passed to
  62. /// 'opt' that will cause this pass to be run. This will return null if there
  63. /// is no argument.
  64. ///
  65. const char *getPassArgument() const { return PassArgument; }
  66. /// getTypeInfo - Return the id object for the pass...
  67. /// TODO : Rename
  68. const void *getTypeInfo() const { return PassID; }
  69. /// Return true if this PassID implements the specified ID pointer.
  70. bool isPassID(const void *IDPtr) const {
  71. return PassID == IDPtr;
  72. }
  73. /// isAnalysisGroup - Return true if this is an analysis group, not a normal
  74. /// pass.
  75. ///
  76. bool isAnalysisGroup() const { return IsAnalysisGroup; }
  77. bool isAnalysis() const { return IsAnalysis; }
  78. /// isCFGOnlyPass - return true if this pass only looks at the CFG for the
  79. /// function.
  80. bool isCFGOnlyPass() const { return IsCFGOnlyPass; }
  81. /// getNormalCtor - Return a pointer to a function, that when called, creates
  82. /// an instance of the pass and returns it. This pointer may be null if there
  83. /// is no default constructor for the pass.
  84. ///
  85. NormalCtor_t getNormalCtor() const {
  86. return NormalCtor;
  87. }
  88. void setNormalCtor(NormalCtor_t Ctor) {
  89. NormalCtor = Ctor;
  90. }
  91. /// getTargetMachineCtor - Return a pointer to a function, that when called
  92. /// with a TargetMachine, creates an instance of the pass and returns it.
  93. /// This pointer may be null if there is no constructor with a TargetMachine
  94. /// for the pass.
  95. ///
  96. TargetMachineCtor_t getTargetMachineCtor() const { return TargetMachineCtor; }
  97. void setTargetMachineCtor(TargetMachineCtor_t Ctor) {
  98. TargetMachineCtor = Ctor;
  99. }
  100. /// createPass() - Use this method to create an instance of this pass.
  101. Pass *createPass() const {
  102. assert((!isAnalysisGroup() || NormalCtor) &&
  103. "No default implementation found for analysis group!");
  104. assert(NormalCtor &&
  105. "Cannot call createPass on PassInfo without default ctor!");
  106. return NormalCtor();
  107. }
  108. /// addInterfaceImplemented - This method is called when this pass is
  109. /// registered as a member of an analysis group with the RegisterAnalysisGroup
  110. /// template.
  111. ///
  112. void addInterfaceImplemented(const PassInfo *ItfPI) {
  113. ItfImpl.push_back(ItfPI);
  114. }
  115. /// getInterfacesImplemented - Return a list of all of the analysis group
  116. /// interfaces implemented by this pass.
  117. ///
  118. const std::vector<const PassInfo*> &getInterfacesImplemented() const {
  119. return ItfImpl;
  120. }
  121. private:
  122. void operator=(const PassInfo &) = delete;
  123. PassInfo(const PassInfo &) = delete;
  124. };
  125. }
  126. #endif