LLVM API Documentation
00001 //===- llvm/PassInfo.h - Pass Info class ------------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines and implements the PassInfo class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 #ifndef LLVM_PASSINFO_H 00014 #define LLVM_PASSINFO_H 00015 00016 #include <cassert> 00017 #include <vector> 00018 00019 namespace llvm { 00020 00021 class Pass; 00022 class TargetMachine; 00023 00024 //===--------------------------------------------------------------------------- 00025 /// PassInfo class - An instance of this class exists for every pass known by 00026 /// the system, and can be obtained from a live Pass by calling its 00027 /// getPassInfo() method. These objects are set up by the RegisterPass<> 00028 /// template. 00029 /// 00030 class PassInfo { 00031 public: 00032 typedef Pass* (*NormalCtor_t)(); 00033 typedef Pass *(*TargetMachineCtor_t)(TargetMachine *); 00034 00035 private: 00036 const char *const PassName; // Nice name for Pass 00037 const char *const PassArgument; // Command Line argument to run this pass 00038 const void *PassID; 00039 const bool IsCFGOnlyPass; // Pass only looks at the CFG. 00040 const bool IsAnalysis; // True if an analysis pass. 00041 const bool IsAnalysisGroup; // True if an analysis group. 00042 std::vector<const PassInfo*> ItfImpl;// Interfaces implemented by this pass 00043 00044 NormalCtor_t NormalCtor; 00045 TargetMachineCtor_t TargetMachineCtor; 00046 00047 public: 00048 /// PassInfo ctor - Do not call this directly, this should only be invoked 00049 /// through RegisterPass. 00050 PassInfo(const char *name, const char *arg, const void *pi, 00051 NormalCtor_t normal, bool isCFGOnly, bool is_analysis, 00052 TargetMachineCtor_t machine = nullptr) 00053 : PassName(name), PassArgument(arg), PassID(pi), 00054 IsCFGOnlyPass(isCFGOnly), 00055 IsAnalysis(is_analysis), IsAnalysisGroup(false), NormalCtor(normal), 00056 TargetMachineCtor(machine) {} 00057 /// PassInfo ctor - Do not call this directly, this should only be invoked 00058 /// through RegisterPass. This version is for use by analysis groups; it 00059 /// does not auto-register the pass. 00060 PassInfo(const char *name, const void *pi) 00061 : PassName(name), PassArgument(""), PassID(pi), 00062 IsCFGOnlyPass(false), 00063 IsAnalysis(false), IsAnalysisGroup(true), NormalCtor(nullptr), 00064 TargetMachineCtor(nullptr) {} 00065 00066 /// getPassName - Return the friendly name for the pass, never returns null 00067 /// 00068 const char *getPassName() const { return PassName; } 00069 00070 /// getPassArgument - Return the command line option that may be passed to 00071 /// 'opt' that will cause this pass to be run. This will return null if there 00072 /// is no argument. 00073 /// 00074 const char *getPassArgument() const { return PassArgument; } 00075 00076 /// getTypeInfo - Return the id object for the pass... 00077 /// TODO : Rename 00078 const void *getTypeInfo() const { return PassID; } 00079 00080 /// Return true if this PassID implements the specified ID pointer. 00081 bool isPassID(const void *IDPtr) const { 00082 return PassID == IDPtr; 00083 } 00084 00085 /// isAnalysisGroup - Return true if this is an analysis group, not a normal 00086 /// pass. 00087 /// 00088 bool isAnalysisGroup() const { return IsAnalysisGroup; } 00089 bool isAnalysis() const { return IsAnalysis; } 00090 00091 /// isCFGOnlyPass - return true if this pass only looks at the CFG for the 00092 /// function. 00093 bool isCFGOnlyPass() const { return IsCFGOnlyPass; } 00094 00095 /// getNormalCtor - Return a pointer to a function, that when called, creates 00096 /// an instance of the pass and returns it. This pointer may be null if there 00097 /// is no default constructor for the pass. 00098 /// 00099 NormalCtor_t getNormalCtor() const { 00100 return NormalCtor; 00101 } 00102 void setNormalCtor(NormalCtor_t Ctor) { 00103 NormalCtor = Ctor; 00104 } 00105 00106 /// getTargetMachineCtor - Return a pointer to a function, that when called 00107 /// with a TargetMachine, creates an instance of the pass and returns it. 00108 /// This pointer may be null if there is no constructor with a TargetMachine 00109 /// for the pass. 00110 /// 00111 TargetMachineCtor_t getTargetMachineCtor() const { return TargetMachineCtor; } 00112 void setTargetMachineCtor(TargetMachineCtor_t Ctor) { 00113 TargetMachineCtor = Ctor; 00114 } 00115 00116 /// createPass() - Use this method to create an instance of this pass. 00117 Pass *createPass() const { 00118 assert((!isAnalysisGroup() || NormalCtor) && 00119 "No default implementation found for analysis group!"); 00120 assert(NormalCtor && 00121 "Cannot call createPass on PassInfo without default ctor!"); 00122 return NormalCtor(); 00123 } 00124 00125 /// addInterfaceImplemented - This method is called when this pass is 00126 /// registered as a member of an analysis group with the RegisterAnalysisGroup 00127 /// template. 00128 /// 00129 void addInterfaceImplemented(const PassInfo *ItfPI) { 00130 ItfImpl.push_back(ItfPI); 00131 } 00132 00133 /// getInterfacesImplemented - Return a list of all of the analysis group 00134 /// interfaces implemented by this pass. 00135 /// 00136 const std::vector<const PassInfo*> &getInterfacesImplemented() const { 00137 return ItfImpl; 00138 } 00139 00140 private: 00141 void operator=(const PassInfo &) LLVM_DELETED_FUNCTION; 00142 PassInfo(const PassInfo &) LLVM_DELETED_FUNCTION; 00143 }; 00144 00145 } 00146 00147 #endif