LLVM  4.0.0
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 #ifndef LLVM_PASSINFO_H
14 #define LLVM_PASSINFO_H
15 
16 #include "llvm/ADT/StringRef.h"
17 
18 #include <cassert>
19 #include <vector>
20 
21 namespace llvm {
22 
23 class Pass;
24 class 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 ///
32 class PassInfo {
33 public:
34  typedef Pass* (*NormalCtor_t)();
35  typedef Pass *(*TargetMachineCtor_t)(TargetMachine *);
36 
37 private:
38  StringRef PassName; // Nice name for Pass
39  StringRef PassArgument; // Command Line argument to run this pass
40  const void *PassID;
41  const bool IsCFGOnlyPass; // Pass only looks at the CFG.
42  const bool IsAnalysis; // True if an analysis pass.
43  const bool IsAnalysisGroup; // True if an analysis group.
44  std::vector<const PassInfo *> ItfImpl; // Interfaces implemented by this pass
45 
46  NormalCtor_t NormalCtor;
47  TargetMachineCtor_t TargetMachineCtor;
48 
49 public:
50  /// PassInfo ctor - Do not call this directly, this should only be invoked
51  /// through RegisterPass.
52  PassInfo(StringRef name, StringRef arg, const void *pi, NormalCtor_t normal,
53  bool isCFGOnly, bool is_analysis,
54  TargetMachineCtor_t machine = nullptr)
55  : PassName(name), PassArgument(arg), PassID(pi), IsCFGOnlyPass(isCFGOnly),
56  IsAnalysis(is_analysis), IsAnalysisGroup(false), NormalCtor(normal),
57  TargetMachineCtor(machine) {}
58  /// PassInfo ctor - Do not call this directly, this should only be invoked
59  /// through RegisterPass. This version is for use by analysis groups; it
60  /// does not auto-register the pass.
61  PassInfo(StringRef name, const void *pi)
62  : PassName(name), PassArgument(""), PassID(pi), IsCFGOnlyPass(false),
63  IsAnalysis(false), IsAnalysisGroup(true), NormalCtor(nullptr),
64  TargetMachineCtor(nullptr) {}
65 
66  /// getPassName - Return the friendly name for the pass, never returns null
67  ///
68  StringRef getPassName() const { return PassName; }
69 
70  /// getPassArgument - Return the command line option that may be passed to
71  /// 'opt' that will cause this pass to be run. This will return null if there
72  /// is no argument.
73  ///
74  StringRef getPassArgument() const { return PassArgument; }
75 
76  /// getTypeInfo - Return the id object for the pass...
77  /// TODO : Rename
78  const void *getTypeInfo() const { return PassID; }
79 
80  /// Return true if this PassID implements the specified ID pointer.
81  bool isPassID(const void *IDPtr) const { return PassID == IDPtr; }
82 
83  /// isAnalysisGroup - Return true if this is an analysis group, not a normal
84  /// pass.
85  ///
86  bool isAnalysisGroup() const { return IsAnalysisGroup; }
87  bool isAnalysis() const { return IsAnalysis; }
88 
89  /// isCFGOnlyPass - return true if this pass only looks at the CFG for the
90  /// function.
91  bool isCFGOnlyPass() const { return IsCFGOnlyPass; }
92 
93  /// getNormalCtor - Return a pointer to a function, that when called, creates
94  /// an instance of the pass and returns it. This pointer may be null if there
95  /// is no default constructor for the pass.
96  ///
98  return NormalCtor;
99  }
101  NormalCtor = Ctor;
102  }
103 
104  /// getTargetMachineCtor - Return a pointer to a function, that when called
105  /// with a TargetMachine, creates an instance of the pass and returns it.
106  /// This pointer may be null if there is no constructor with a TargetMachine
107  /// for the pass.
108  ///
109  TargetMachineCtor_t getTargetMachineCtor() const { return TargetMachineCtor; }
111  TargetMachineCtor = Ctor;
112  }
113 
114  /// createPass() - Use this method to create an instance of this pass.
115  Pass *createPass() const {
116  assert((!isAnalysisGroup() || NormalCtor) &&
117  "No default implementation found for analysis group!");
118  assert(NormalCtor &&
119  "Cannot call createPass on PassInfo without default ctor!");
120  return NormalCtor();
121  }
122 
123  /// addInterfaceImplemented - This method is called when this pass is
124  /// registered as a member of an analysis group with the RegisterAnalysisGroup
125  /// template.
126  ///
127  void addInterfaceImplemented(const PassInfo *ItfPI) {
128  ItfImpl.push_back(ItfPI);
129  }
130 
131  /// getInterfacesImplemented - Return a list of all of the analysis group
132  /// interfaces implemented by this pass.
133  ///
134  const std::vector<const PassInfo*> &getInterfacesImplemented() const {
135  return ItfImpl;
136  }
137 
138 private:
139  void operator=(const PassInfo &) = delete;
140  PassInfo(const PassInfo &) = delete;
141 };
142 
143 }
144 
145 #endif
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:81
void setNormalCtor(NormalCtor_t Ctor)
Definition: PassInfo.h:100
TargetMachineCtor_t getTargetMachineCtor() const
getTargetMachineCtor - Return a pointer to a function, that when called with a TargetMachine, creates an instance of the pass and returns it.
Definition: PassInfo.h:109
const std::vector< const PassInfo * > & getInterfacesImplemented() const
getInterfacesImplemented - Return a list of all of the analysis group interfaces implemented by this ...
Definition: PassInfo.h:134
aarch64 AArch64 CCMP Pass
bool isCFGOnlyPass() const
isCFGOnlyPass - return true if this pass only looks at the CFG for the function.
Definition: PassInfo.h:91
const void * getTypeInfo() const
getTypeInfo - Return the id object for the pass...
Definition: PassInfo.h:78
bool isAnalysis() const
Definition: PassInfo.h:87
Pass * createPass() const
createPass() - Use this method to create an instance of this pass.
Definition: PassInfo.h:115
PassInfo(StringRef name, StringRef arg, const void *pi, NormalCtor_t normal, bool isCFGOnly, bool is_analysis, TargetMachineCtor_t machine=nullptr)
PassInfo ctor - Do not call this directly, this should only be invoked through RegisterPass.
Definition: PassInfo.h:52
void addInterfaceImplemented(const PassInfo *ItfPI)
addInterfaceImplemented - This method is called when this pass is registered as a member of an analys...
Definition: PassInfo.h:127
bool isAnalysisGroup() const
isAnalysisGroup - Return true if this is an analysis group, not a normal pass.
Definition: PassInfo.h:86
bool isPassID(const void *IDPtr) const
Return true if this PassID implements the specified ID pointer.
Definition: PassInfo.h:81
StringRef getPassArgument() const
getPassArgument - Return the command line option that may be passed to 'opt' that will cause this pas...
Definition: PassInfo.h:74
void setTargetMachineCtor(TargetMachineCtor_t Ctor)
Definition: PassInfo.h:110
Function Alias Analysis false
NormalCtor_t getNormalCtor() const
getNormalCtor - Return a pointer to a function, that when called, creates an instance of the pass and...
Definition: PassInfo.h:97
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:32
Pass *(* TargetMachineCtor_t)(TargetMachine *)
Definition: PassInfo.h:35
Basic Alias true
StringRef getPassName() const
getPassName - Return the friendly name for the pass, never returns null
Definition: PassInfo.h:68
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:61
Primary interface to the complete machine description for the target machine.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
Pass *(* NormalCtor_t)()
Definition: PassInfo.h:34