18#ifndef LLVM_SANDBOXIR_PASSMANAGER_H
19#define LLVM_SANDBOXIR_PASSMANAGER_H
32template <
typename ParentPass,
typename ContainedPass>
98 "setPassPipeline called on a non-empty sandboxir::PassManager");
103 if (Pipeline.
empty())
107 std::string PipelineStr = std::string(Pipeline) +
EndToken;
113 errs() <<
"Found empty pass name.\n";
119 if (
Pass ==
nullptr) {
120 errs() <<
"Pass '" <<
PassName <<
"' not registered!\n";
132 } CurrentState = State::ScanName;
133 int PassBeginIdx = 0;
135 int AuxArgsBeginIdx = 0;
139 int NestedAuxArgs = 0;
141 switch (CurrentState) {
142 case State::ScanName:
146 ArgsBeginIdx = Idx + 1;
148 CurrentState = State::ScanArgs;
154 AuxArgsBeginIdx = Idx + 1;
156 CurrentState = State::ScanAuxArgs;
161 errs() <<
"Unexpected '" <<
C <<
"' in pass pipeline.\n";
168 PassBeginIdx = Idx + 1;
171 case State::ScanArgs:
180 if (NestedArgs == 0) {
182 AddPass(
PassName, Pipeline.
slice(ArgsBeginIdx, Idx), AuxArg);
183 CurrentState = State::ArgsEnded;
184 }
else if (NestedArgs < 0) {
185 errs() <<
"Unexpected '>' in pass pipeline.\n";
191 errs() <<
"Missing '>' in pass pipeline. End-of-string reached while "
192 "reading arguments for pass '"
197 case State::ArgsEnded:
201 PassBeginIdx = Idx + 1;
203 CurrentState = State::ScanName;
205 errs() <<
"Expected delimiter or end-of-string after pass "
210 case State::ScanAuxArgs:
217 if (NestedAuxArgs == 0) {
218 AuxArg = Pipeline.
slice(AuxArgsBeginIdx, Idx);
219 CurrentState = State::AuxArgsEnded;
220 }
else if (NestedAuxArgs < 0) {
222 <<
"' in pass pipeline.\n";
229 <<
"' in pass pipeline. End-of-string reached while "
230 "reading arguments for pass '"
235 case State::AuxArgsEnded:
238 CurrentState = State::ScanName;
241 PassBeginIdx = Idx + 1;
243 CurrentState = State::ScanName;
246 ArgsBeginIdx = Idx + 1;
247 CurrentState = State::ScanArgs;
249 errs() <<
"Expected delimiter, begin-of-args or end-of-string after "
250 "pass aux argument.\n";
274 for (
const auto &PassPtr :
Passes)
275 PassPtr->printPipeline(OS);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
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.
Represent a constant reference to a string, i.e.
constexpr bool empty() const
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)
FunctionPassManager(StringRef Name)
PassManager(const PassManager &)=delete
static constexpr char EndAuxArgsToken
void addPass(std::unique_ptr< ContainedPass > Pass)
Adds Pass to the pass pipeline.
std::function< std::unique_ptr< ContainedPass >( StringRef, StringRef, StringRef)> CreatePassFunc
void printPipeline(raw_ostream &OS) const override
Similar to print() but prints one pass per line. Used for testing.
static constexpr char EndToken
PassManager(StringRef Name)
void setPassPipeline(StringRef Pipeline, CreatePassFunc CreatePass)
Parses Pipeline as a comma-separated sequence of pass names and sets the pass pipeline,...
PassManager(PassManager &&)=default
static constexpr char BeginArgsToken
void print(raw_ostream &OS) const override
~PassManager() override=default
PassManager(StringRef Name, StringRef Pipeline, CreatePassFunc CreatePass)
PassManager & operator=(const PassManager &)=delete
LLVM_DUMP_METHOD void dump() const override
static constexpr char PassDelimToken
SmallVector< std::unique_ptr< ContainedPass > > Passes
The list of passes that this pass manager will run.
static constexpr char BeginAuxArgsToken
static constexpr char EndArgsToken
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)
RegionPassManager(StringRef Name, StringRef Pipeline, CreatePassFunc CreatePass)
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.