LLVM 22.0.0git
PassInfo.h
Go to the documentation of this file.
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.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_PASSINFO_H
14#define LLVM_PASSINFO_H
15
16#include "llvm/ADT/StringRef.h"
17#include <cassert>
18
19namespace llvm {
20
21class Pass;
22
23//===---------------------------------------------------------------------------
24/// PassInfo class - An instance of this class exists for every pass known by
25/// the system, and can be obtained from a live Pass by calling its
26/// getPassInfo() method. These objects are set up by the RegisterPass<>
27/// template.
28///
29class PassInfo {
30public:
31 using NormalCtor_t = Pass* (*)();
32
33private:
34 StringRef PassName; // Nice name for Pass
35 StringRef PassArgument; // Command Line argument to run this pass
36 const void *PassID;
37 const bool IsCFGOnlyPass = false; // Pass only looks at the CFG.
38 const bool IsAnalysis; // True if an analysis pass.
39 NormalCtor_t NormalCtor = nullptr;
40
41public:
42 /// PassInfo ctor - Do not call this directly, this should only be invoked
43 /// through RegisterPass.
44 PassInfo(StringRef name, StringRef arg, const void *pi, NormalCtor_t normal,
45 bool isCFGOnly, bool is_analysis)
46 : PassName(name), PassArgument(arg), PassID(pi), IsCFGOnlyPass(isCFGOnly),
47 IsAnalysis(is_analysis), NormalCtor(normal) {}
48
49 PassInfo(const PassInfo &) = delete;
50 PassInfo &operator=(const PassInfo &) = delete;
51
52 /// getPassName - Return the friendly name for the pass, never returns null
53 StringRef getPassName() const { return PassName; }
54
55 /// getPassArgument - Return the command line option that may be passed to
56 /// 'opt' that will cause this pass to be run. This will return null if there
57 /// is no argument.
58 StringRef getPassArgument() const { return PassArgument; }
59
60 /// getTypeInfo - Return the id object for the pass...
61 /// TODO : Rename
62 const void *getTypeInfo() const { return PassID; }
63
64 /// Return true if this PassID implements the specified ID pointer.
65 bool isPassID(const void *IDPtr) const { return PassID == IDPtr; }
66
67 bool isAnalysis() const { return IsAnalysis; }
68
69 /// isCFGOnlyPass - return true if this pass only looks at the CFG for the
70 /// function.
71 bool isCFGOnlyPass() const { return IsCFGOnlyPass; }
72
73 /// getNormalCtor - Return a pointer to a function, that when called, creates
74 /// an instance of the pass and returns it. This pointer may be null if there
75 /// is no default constructor for the pass.
77 return NormalCtor;
78 }
80 NormalCtor = Ctor;
81 }
82
83 /// createPass() - Use this method to create an instance of this pass.
84 Pass *createPass() const {
85 assert(NormalCtor &&
86 "Cannot call createPass on PassInfo without default ctor!");
87 return NormalCtor();
88 }
89};
90
91} // end namespace llvm
92
93#endif // LLVM_PASSINFO_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static const char * name
bool isPassID(const void *IDPtr) const
Return true if this PassID implements the specified ID pointer.
Definition PassInfo.h:65
PassInfo & operator=(const PassInfo &)=delete
Pass *(*)() NormalCtor_t
Definition PassInfo.h:31
NormalCtor_t getNormalCtor() const
getNormalCtor - Return a pointer to a function, that when called, creates an instance of the pass and...
Definition PassInfo.h:76
bool isAnalysis() const
Definition PassInfo.h:67
PassInfo(const PassInfo &)=delete
void setNormalCtor(NormalCtor_t Ctor)
Definition PassInfo.h:79
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:44
StringRef getPassArgument() const
getPassArgument - Return the command line option that may be passed to 'opt' that will cause this pas...
Definition PassInfo.h:58
StringRef getPassName() const
getPassName - Return the friendly name for the pass, never returns null
Definition PassInfo.h:53
bool isCFGOnlyPass() const
isCFGOnlyPass - return true if this pass only looks at the CFG for the function.
Definition PassInfo.h:71
Pass * createPass() const
createPass() - Use this method to create an instance of this pass.
Definition PassInfo.h:84
const void * getTypeInfo() const
getTypeInfo - Return the id object for the pass... TODO : Rename
Definition PassInfo.h:62
Pass interface - Implemented by all 'passes'.
Definition Pass.h:99
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
This is an optimization pass for GlobalISel generic memory operations.