LLVM  6.0.0svn
PassInfo.h
Go to the documentation of this file.
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.
90  return NormalCtor;
91  }
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
Pass interface - Implemented by all &#39;passes&#39;.
Definition: Pass.h:81
void setNormalCtor(NormalCtor_t Ctor)
Definition: PassInfo.h:92
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
void addInterfaceImplemented(const PassInfo *ItfPI)
addInterfaceImplemented - This method is called when this pass is registered as a member of an analys...
Definition: PassInfo.h:108
NormalCtor_t getNormalCtor() const
getNormalCtor - Return a pointer to a function, that when called, creates an instance of the pass and...
Definition: PassInfo.h:89
const void * getTypeInfo() const
getTypeInfo - Return the id object for the pass...
Definition: PassInfo.h:72
PassInfo(StringRef name, StringRef arg, const void *pi, NormalCtor_t normal, bool isCFGOnly, bool is_analysis)
PassInfo ctor - Do not call this directly, this should only be invoked through RegisterPass.
Definition: PassInfo.h:48
PassInfo class - An instance of this class exists for every pass known by the system, and can be obtained from a live Pass by calling its getPassInfo() method.
Definition: PassInfo.h:31
print lazy value Lazy Value Info Printer Pass
PassInfo & operator=(const PassInfo &)=delete
Pass * createPass() const
createPass() - Use this method to create an instance of this pass.
Definition: PassInfo.h:97
Basic Alias true
Pass *(*)() NormalCtor_t
Definition: PassInfo.h:33
bool isAnalysisGroup() const
isAnalysisGroup - Return true if this is an analysis group, not a normal pass.
Definition: PassInfo.h:79
StringRef getPassName() const
getPassName - Return the friendly name for the pass, never returns null
Definition: PassInfo.h:63
bool isPassID(const void *IDPtr) const
Return true if this PassID implements the specified ID pointer.
Definition: PassInfo.h:75
bool isCFGOnlyPass() const
isCFGOnlyPass - return true if this pass only looks at the CFG for the function.
Definition: PassInfo.h:84
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static const char * name
PassInfo(StringRef name, const void *pi)
PassInfo ctor - Do not call this directly, this should only be invoked through RegisterPass.
Definition: PassInfo.h:56
bool isAnalysis() const
Definition: PassInfo.h:80
const std::vector< const PassInfo * > & getInterfacesImplemented() const
getInterfacesImplemented - Return a list of all of the analysis group interfaces implemented by this ...
Definition: PassInfo.h:114
StringRef getPassArgument() const
getPassArgument - Return the command line option that may be passed to &#39;opt&#39; that will cause this pas...
Definition: PassInfo.h:68
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49