LLVM: include/llvm/SandboxIR/PassManager.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#ifndef LLVM_SANDBOXIR_PASSMANAGER_H
19#define LLVM_SANDBOXIR_PASSMANAGER_H
20
22#include
23
28
30
32
33
34template <typename ParentPass, typename ContainedPass>
36public:
37
40
41protected:
42
44
54
55public:
56
61
62 static constexpr char EndToken = '\0';
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
84 "setPassPipeline called on a non-empty sandboxir::PassManager");
85
86
87
88
89 if (Pipeline.empty())
90 return;
91
92
93 std::string PipelineStr = std::string(Pipeline) + EndToken;
94 Pipeline = StringRef(PipelineStr);
95
98 errs() << "Found empty pass name.\n";
99 exit(1);
100 }
101
102
104 if (Pass == nullptr) {
105 errs() << "Pass '" << PassName << "' not registered!\n";
106 exit(1);
107 }
109 };
110
111 enum class State {
112 ScanName,
113 ScanArgs,
114 ArgsEnded,
115 } CurrentState = State::ScanName;
116 int PassBeginIdx = 0;
117 int ArgsBeginIdx;
119 int NestedArgs = 0;
120 for (auto [Idx, C] : enumerate(Pipeline)) {
121 switch (CurrentState) {
122 case State::ScanName:
124
126 ArgsBeginIdx = Idx + 1;
127 ++NestedArgs;
128 CurrentState = State::ScanArgs;
129 break;
130 }
132 errs() << "Unexpected '>' in pass pipeline.\n";
133 exit(1);
134 }
136
137
138 AddPass(Pipeline.slice(PassBeginIdx, Idx), StringRef());
139 PassBeginIdx = Idx + 1;
140 }
141 break;
142 case State::ScanArgs:
143
144
146 ++NestedArgs;
147 break;
148 }
150 --NestedArgs;
151 if (NestedArgs == 0) {
152
153 AddPass(PassName, Pipeline.slice(ArgsBeginIdx, Idx));
154 CurrentState = State::ArgsEnded;
155 } else if (NestedArgs < 0) {
156 errs() << "Unexpected '>' in pass pipeline.\n";
157 exit(1);
158 }
159 break;
160 }
162 errs() << "Missing '>' in pass pipeline. End-of-string reached while "
163 "reading arguments for pass '"
165 exit(1);
166 }
167 break;
168 case State::ArgsEnded:
169
170
172 PassBeginIdx = Idx + 1;
173 CurrentState = State::ScanName;
174 } else {
175 errs() << "Expected delimiter or end-of-string after pass "
176 "arguments.\n";
177 exit(1);
178 }
179 break;
180 }
181 }
182 }
183
184#ifndef NDEBUG
194 dbgs() << "\n";
195 }
196#endif
197
199 OS << this->getName() << "\n";
200 for (const auto &PassPtr : Passes)
201 PassPtr->printPipeline(OS);
202 }
203};
204
206 : public PassManager<FunctionPass, FunctionPass> {
207public:
213};
214
216 : public PassManager<RegionPass, RegionPass> {
217public:
223};
224
225}
226
227#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
This file defines the DenseMap class.
static bool runOnFunction(Function &F, bool PostInlining)
static StringRef getName(Value *V)
static const char PassName[]
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
StringRef slice(size_t Start, size_t End) const
Return a reference to the substring from [Start, End).
This class implements an extremely fast bulk output stream that can only output to a stream.
FunctionPassManager(StringRef Name, StringRef Pipeline, CreatePassFunc CreatePass)
Definition PassManager.h:209
FunctionPassManager(StringRef Name)
Definition PassManager.h:208
PassManager(const PassManager &)=delete
void addPass(std::unique_ptr< ContainedPass > Pass)
Adds Pass to the pass pipeline.
Definition PassManager.h:57
void printPipeline(raw_ostream &OS) const override
Similar to print() but prints one pass per line. Used for testing.
Definition PassManager.h:198
static constexpr char EndToken
Definition PassManager.h:62
PassManager(StringRef Name)
Definition PassManager.h:45
void setPassPipeline(StringRef Pipeline, CreatePassFunc CreatePass)
Parses Pipeline as a comma-separated sequence of pass names and sets the pass pipeline,...
Definition PassManager.h:82
PassManager(PassManager &&)=default
static constexpr char BeginArgsToken
Definition PassManager.h:63
void print(raw_ostream &OS) const override
Definition PassManager.h:185
~PassManager() override=default
std::function< std::unique_ptr< ContainedPass >(StringRef, StringRef)> CreatePassFunc
Definition PassManager.h:38
PassManager(StringRef Name, StringRef Pipeline, CreatePassFunc CreatePass)
Definition PassManager.h:46
PassManager & operator=(const PassManager &)=delete
LLVM_DUMP_METHOD void dump() const override
Definition PassManager.h:192
static constexpr char PassDelimToken
Definition PassManager.h:65
SmallVector< std::unique_ptr< ContainedPass > > Passes
The list of passes that this pass manager will run.
Definition PassManager.h:43
static constexpr char EndArgsToken
Definition PassManager.h:64
The base class of a Sandbox IR Pass.
const std::string Name
The pass name.
virtual void print(raw_ostream &OS) const
RegionPassManager(StringRef Name)
Definition PassManager.h:218
RegionPassManager(StringRef Name, StringRef Pipeline, CreatePassFunc CreatePass)
Definition PassManager.h:219
The main job of the Region is to point to new instructions generated by vectorization passes.
A SandboxIR Value has users. This is the base class.
@ C
The default llvm calling convention, compatible with C.
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
void interleave(ForwardIterator begin, ForwardIterator end, UnaryFunctor each_fn, NullaryFunctor between_fn)
An STL-style algorithm similar to std::for_each that applies a second functor between every pair of e...
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.