1 //===- llvm/PassInfo.h - Pass Info class ------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file defines and implements the PassInfo class. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_PASSINFO_H 14 #define LLVM_PASSINFO_H 15 16 #include "llvm/ADT/StringRef.h" 17 #include <cassert> 18 #include <vector> 19 20 namespace llvm { 21 22 class Pass; 23 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 34 private: 35 StringRef PassName; // Nice name for Pass 36 StringRef PassArgument; // Command Line argument to run this pass 37 const void *PassID; 38 const bool IsCFGOnlyPass = false; // Pass only looks at the CFG. 39 const bool IsAnalysis; // True if an analysis pass. 40 NormalCtor_t NormalCtor = nullptr; 41 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), NormalCtor(normal) {} 49 50 PassInfo(const PassInfo &) = delete; 51 PassInfo &operator=(const PassInfo &) = delete; 52 53 /// getPassName - Return the friendly name for the pass, never returns null 54 StringRef getPassName() const { return PassName; } 55 56 /// getPassArgument - Return the command line option that may be passed to 57 /// 'opt' that will cause this pass to be run. This will return null if there 58 /// is no argument. 59 StringRef getPassArgument() const { return PassArgument; } 60 61 /// getTypeInfo - Return the id object for the pass... 62 /// TODO : Rename 63 const void *getTypeInfo() const { return PassID; } 64 65 /// Return true if this PassID implements the specified ID pointer. 66 bool isPassID(const void *IDPtr) const { return PassID == IDPtr; } 67 68 bool isAnalysis() const { return IsAnalysis; } 69 70 /// isCFGOnlyPass - return true if this pass only looks at the CFG for the 71 /// function. 72 bool isCFGOnlyPass() const { return IsCFGOnlyPass; } 73 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 84 /// createPass() - Use this method to create an instance of this pass. 85 Pass *createPass() const { 86 assert(NormalCtor && 87 "Cannot call createPass on PassInfo without default ctor!"); 88 return NormalCtor(); 89 } 90 }; 91 92 } // end namespace llvm 93 94 #endif // LLVM_PASSINFO_H 95