36 template<
class P,
class... Args>
static void run(Args&&... args) {
37 P p(std::forward<Args>(args)...);
60 void start()
override;
69 void start()
override;
79 void start()
override;
86 template<
class... Args>
90 man_.template add<P>(std::forward<Args>(args)...);
91 name_ = std::string(man_.
passes().back()->name()) +
".pass_phase";
105 , man_(
std::move(man)) {}
107 void start()
override { man_->run(); }
110 std::unique_ptr<PassMan> man_;
119 void start()
override;
123 const auto&
phases()
const {
return phases_; }
128 template<
class P,
class... Args>
auto add(Args&&... args) {
129 if constexpr (std::is_base_of_v<Pass, P>) {
130 return add<PassPhase<P>>(std::forward<Args>(args)...);
132 auto p = std::make_unique<P>(
world(), std::forward<Args&&>(args)...);
133 auto phase = p.get();
134 phases_.emplace_back(std::move(p));
135 if (phase->is_dirty()) phases_.emplace_back(std::make_unique<Cleanup>(
world()));
142 std::deque<std::unique_ptr<Phase>> phases_;
154 , elide_empty_(elide_empty) {}
156 void start()
override;
164 const Scope* scope_ =
nullptr;
175 , elide_empty_(elide_empty) {}
181 while (!queue.
empty()) {
182 auto mut = queue.
pop();
183 if (
auto m = mut->isa<
M>(); m && m->is_closed() && (!elide_empty_ || m->is_set()))
visit(curr_mut_ = m);
185 for (
auto op : mut->extended_ops())
Removes unreachable and dead code by rebuilding the whole World into a new one and swapping afterward...
void start() override
Actual entry.
Transitively visits all reachable closed mutables (Def::is_closed()) in World.
void start() override
Actual entry.
ClosedMutPhase(World &world, std::string_view name, bool elide_empty)
virtual void visit(M *)=0
Like a RWPhase but starts with a fixed-point loop of FPPhase::analyze beforehand.
FPPhase(World &world, std::string_view name)
void start() override
Actual entry.
Wraps a PassMan pipeline as a Phase.
void start() override
Actual entry.
PassManPhase(World &world, std::unique_ptr< PassMan > &&man)
An optimizer that combines several optimizations in an optimal way.
const auto & passes() const
void run()
Run all registered passes on the whole World.
PassPhase(World &world, Args &&... args)
void start() override
Actual entry.
As opposed to a Pass, a Phase does one thing at a time and does not mix with other Phases.
virtual void start()=0
Actual entry.
Phase(World &world, std::string_view name, bool dirty)
virtual void run()
Entry point and generates some debug output; invokes Phase::start.
static void run(Args &&... args)
Runs a single Phase.
std::string_view name() const
Organizes several Phases as a pipeline.
const auto & phases() const
auto add(Args &&... args)
Add a Phase.
void start() override
Actual entry.
Visits the current Phase::world and constructs a new RWPhase::world along the way.
RWPhase(World &world, std::string_view name)
void start() override
Actual entry.
Recurseivly rewrites part of a program into the provided World.
Transitively visits all reachable Scopes in World that do not have free variables.
void start() override
Actual entry.
ScopePhase(World &world, std::string_view name, bool elide_empty)
virtual void visit(const Scope &)=0
const Scope & scope() const
A Scope represents a region of Defs that are live from the view of an entry's Var.
The World represents the whole program and manages creation of Thorin nodes (Defs).
const auto & externals() const