[Alignment][NFC] Use Align with TargetLowering::setMinFunctionAlignment
[llvm-core.git] / include / llvm / PassInfo.h
blob686fc044ebcb33abc846834bac957c858a524ed0
1 //===- llvm/PassInfo.h - Pass Info class ------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines and implements the PassInfo class.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_PASSINFO_H
14 #define LLVM_PASSINFO_H
16 #include "llvm/ADT/StringRef.h"
17 #include <cassert>
18 #include <vector>
20 namespace llvm {
22 class Pass;
24 //===---------------------------------------------------------------------------
25 /// PassInfo class - An instance of this class exists for every pass known by
26 /// the system, and can be obtained from a live Pass by calling its
27 /// getPassInfo() method. These objects are set up by the RegisterPass<>
28 /// template.
29 ///
30 class PassInfo {
31 public:
32 using NormalCtor_t = Pass* (*)();
34 private:
35 StringRef PassName; // Nice name for Pass
36 StringRef PassArgument; // Command Line argument to run this pass
37 const void *PassID;
38 const bool IsCFGOnlyPass = false; // Pass only looks at the CFG.
39 const bool IsAnalysis; // True if an analysis pass.
40 const bool IsAnalysisGroup; // True if an analysis group.
41 std::vector<const PassInfo *> ItfImpl; // Interfaces implemented by this pass
42 NormalCtor_t NormalCtor = nullptr;
44 public:
45 /// PassInfo ctor - Do not call this directly, this should only be invoked
46 /// through RegisterPass.
47 PassInfo(StringRef name, StringRef arg, const void *pi, NormalCtor_t normal,
48 bool isCFGOnly, bool is_analysis)
49 : PassName(name), PassArgument(arg), PassID(pi), IsCFGOnlyPass(isCFGOnly),
50 IsAnalysis(is_analysis), IsAnalysisGroup(false), NormalCtor(normal) {}
52 /// PassInfo ctor - Do not call this directly, this should only be invoked
53 /// through RegisterPass. This version is for use by analysis groups; it
54 /// does not auto-register the pass.
55 PassInfo(StringRef name, const void *pi)
56 : PassName(name), PassID(pi), IsAnalysis(false), IsAnalysisGroup(true) {}
58 PassInfo(const PassInfo &) = delete;
59 PassInfo &operator=(const PassInfo &) = delete;
61 /// getPassName - Return the friendly name for the pass, never returns null
62 StringRef getPassName() const { return PassName; }
64 /// getPassArgument - Return the command line option that may be passed to
65 /// 'opt' that will cause this pass to be run. This will return null if there
66 /// is no argument.
67 StringRef getPassArgument() const { return PassArgument; }
69 /// getTypeInfo - Return the id object for the pass...
70 /// TODO : Rename
71 const void *getTypeInfo() const { return PassID; }
73 /// Return true if this PassID implements the specified ID pointer.
74 bool isPassID(const void *IDPtr) const { return PassID == IDPtr; }
76 /// isAnalysisGroup - Return true if this is an analysis group, not a normal
77 /// pass.
78 bool isAnalysisGroup() const { return IsAnalysisGroup; }
79 bool isAnalysis() const { return IsAnalysis; }
81 /// isCFGOnlyPass - return true if this pass only looks at the CFG for the
82 /// function.
83 bool isCFGOnlyPass() const { return IsCFGOnlyPass; }
85 /// getNormalCtor - Return a pointer to a function, that when called, creates
86 /// an instance of the pass and returns it. This pointer may be null if there
87 /// is no default constructor for the pass.
88 NormalCtor_t getNormalCtor() const {
89 return NormalCtor;
91 void setNormalCtor(NormalCtor_t Ctor) {
92 NormalCtor = Ctor;
95 /// createPass() - Use this method to create an instance of this pass.
96 Pass *createPass() const {
97 assert((!isAnalysisGroup() || NormalCtor) &&
98 "No default implementation found for analysis group!");
99 assert(NormalCtor &&
100 "Cannot call createPass on PassInfo without default ctor!");
101 return NormalCtor();
104 /// addInterfaceImplemented - This method is called when this pass is
105 /// registered as a member of an analysis group with the RegisterAnalysisGroup
106 /// template.
107 void addInterfaceImplemented(const PassInfo *ItfPI) {
108 ItfImpl.push_back(ItfPI);
111 /// getInterfacesImplemented - Return a list of all of the analysis group
112 /// interfaces implemented by this pass.
113 const std::vector<const PassInfo*> &getInterfacesImplemented() const {
114 return ItfImpl;
118 } // end namespace llvm
120 #endif // LLVM_PASSINFO_H