1 //===- llvm/PassInfo.h - Pass Info class ------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines and implements the PassInfo class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_PASSINFO_H
15 #define LLVM_PASSINFO_H
17 #include "llvm/ADT/StringRef.h"
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<>
33 using NormalCtor_t = Pass* (*)();
36 StringRef PassName; // Nice name for Pass
37 StringRef PassArgument; // Command Line argument to run this pass
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;
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) {}
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) {}
59 PassInfo(const PassInfo &) = delete;
60 PassInfo &operator=(const PassInfo &) = delete;
62 /// getPassName - Return the friendly name for the pass, never returns null
63 StringRef getPassName() const { return PassName; }
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
68 StringRef getPassArgument() const { return PassArgument; }
70 /// getTypeInfo - Return the id object for the pass...
72 const void *getTypeInfo() const { return PassID; }
74 /// Return true if this PassID implements the specified ID pointer.
75 bool isPassID(const void *IDPtr) const { return PassID == IDPtr; }
77 /// isAnalysisGroup - Return true if this is an analysis group, not a normal
79 bool isAnalysisGroup() const { return IsAnalysisGroup; }
80 bool isAnalysis() const { return IsAnalysis; }
82 /// isCFGOnlyPass - return true if this pass only looks at the CFG for the
84 bool isCFGOnlyPass() const { return IsCFGOnlyPass; }
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 {
92 void setNormalCtor(NormalCtor_t Ctor) {
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!");
101 "Cannot call createPass on PassInfo without default ctor!");
105 /// addInterfaceImplemented - This method is called when this pass is
106 /// registered as a member of an analysis group with the RegisterAnalysisGroup
108 void addInterfaceImplemented(const PassInfo *ItfPI) {
109 ItfImpl.push_back(ItfPI);
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 {
119 } // end namespace llvm
121 #endif // LLVM_PASSINFO_H