PassInfo.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/PassInfo.h - Pass Info class ------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines and implements the PassInfo class.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_PASSINFO_H
  18. #define LLVM_PASSINFO_H
  19. #include "llvm/ADT/StringRef.h"
  20. #include <cassert>
  21. #include <vector>
  22. namespace llvm {
  23. class Pass;
  24. //===---------------------------------------------------------------------------
  25. /// PassInfo class - An instance of this class exists for every pass known by
  26. /// the system, and can be obtained from a live Pass by calling its
  27. /// getPassInfo() method. These objects are set up by the RegisterPass<>
  28. /// template.
  29. ///
  30. class PassInfo {
  31. public:
  32. using NormalCtor_t = Pass* (*)();
  33. private:
  34. StringRef PassName; // Nice name for Pass
  35. StringRef PassArgument; // Command Line argument to run this pass
  36. const void *PassID;
  37. const bool IsCFGOnlyPass = false; // Pass only looks at the CFG.
  38. const bool IsAnalysis; // True if an analysis pass.
  39. const bool IsAnalysisGroup; // True if an analysis group.
  40. std::vector<const PassInfo *> ItfImpl; // Interfaces implemented by this pass
  41. NormalCtor_t NormalCtor = nullptr;
  42. public:
  43. /// PassInfo ctor - Do not call this directly, this should only be invoked
  44. /// through RegisterPass.
  45. PassInfo(StringRef name, StringRef arg, const void *pi, NormalCtor_t normal,
  46. bool isCFGOnly, bool is_analysis)
  47. : PassName(name), PassArgument(arg), PassID(pi), IsCFGOnlyPass(isCFGOnly),
  48. IsAnalysis(is_analysis), IsAnalysisGroup(false), NormalCtor(normal) {}
  49. /// PassInfo ctor - Do not call this directly, this should only be invoked
  50. /// through RegisterPass. This version is for use by analysis groups; it
  51. /// does not auto-register the pass.
  52. PassInfo(StringRef name, const void *pi)
  53. : PassName(name), PassID(pi), IsAnalysis(false), IsAnalysisGroup(true) {}
  54. PassInfo(const PassInfo &) = delete;
  55. PassInfo &operator=(const PassInfo &) = delete;
  56. /// getPassName - Return the friendly name for the pass, never returns null
  57. StringRef getPassName() const { return PassName; }
  58. /// getPassArgument - Return the command line option that may be passed to
  59. /// 'opt' that will cause this pass to be run. This will return null if there
  60. /// is no argument.
  61. StringRef getPassArgument() const { return PassArgument; }
  62. /// getTypeInfo - Return the id object for the pass...
  63. /// TODO : Rename
  64. const void *getTypeInfo() const { return PassID; }
  65. /// Return true if this PassID implements the specified ID pointer.
  66. bool isPassID(const void *IDPtr) const { return PassID == IDPtr; }
  67. /// isAnalysisGroup - Return true if this is an analysis group, not a normal
  68. /// pass.
  69. bool isAnalysisGroup() const { return IsAnalysisGroup; }
  70. bool isAnalysis() const { return IsAnalysis; }
  71. /// isCFGOnlyPass - return true if this pass only looks at the CFG for the
  72. /// function.
  73. bool isCFGOnlyPass() const { return IsCFGOnlyPass; }
  74. /// getNormalCtor - Return a pointer to a function, that when called, creates
  75. /// an instance of the pass and returns it. This pointer may be null if there
  76. /// is no default constructor for the pass.
  77. NormalCtor_t getNormalCtor() const {
  78. return NormalCtor;
  79. }
  80. void setNormalCtor(NormalCtor_t Ctor) {
  81. NormalCtor = Ctor;
  82. }
  83. /// createPass() - Use this method to create an instance of this pass.
  84. Pass *createPass() const {
  85. assert((!isAnalysisGroup() || NormalCtor) &&
  86. "No default implementation found for analysis group!");
  87. assert(NormalCtor &&
  88. "Cannot call createPass on PassInfo without default ctor!");
  89. return NormalCtor();
  90. }
  91. /// addInterfaceImplemented - This method is called when this pass is
  92. /// registered as a member of an analysis group with the RegisterAnalysisGroup
  93. /// template.
  94. void addInterfaceImplemented(const PassInfo *ItfPI) {
  95. ItfImpl.push_back(ItfPI);
  96. }
  97. /// getInterfacesImplemented - Return a list of all of the analysis group
  98. /// interfaces implemented by this pass.
  99. const std::vector<const PassInfo*> &getInterfacesImplemented() const {
  100. return ItfImpl;
  101. }
  102. };
  103. } // end namespace llvm
  104. #endif // LLVM_PASSINFO_H
  105. #ifdef __GNUC__
  106. #pragma GCC diagnostic pop
  107. #endif