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