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