28 std::string_view
name()
const {
return name_; }
37 template<
class P,
class... Args>
static void run(Args&&... args) {
38 P p(std::forward<Args>(args)...);
63 void start()
override;
72 void start()
override;
82 void start()
override;
89 template<
class... Args>
93 man_.template add<P>(std::forward<Args>(args)...);
94 set_name(std::string(man_.
passes().back()->name()) +
".pass_phase");
108 , man_(
std::move(man)) {}
110 void start()
override { man_->run(); }
113 std::unique_ptr<PassMan> man_;
122 void start()
override;
126 const auto&
phases()
const {
return phases_; }
131 template<
class P,
class... Args>
auto add(Args&&... args) {
132 if constexpr (std::is_base_of_v<Pass, P>) {
135 auto p = std::make_unique<P>(
world(), std::forward<Args&&>(args)...);
136 auto phase = p.get();
137 phases_.emplace_back(std::move(p));
138 if (phase->is_dirty()) phases_.emplace_back(std::make_unique<Cleanup>(
world()));
145 std::deque<std::unique_ptr<Phase>> phases_;
156 , elide_empty_(elide_empty) {}
160 for (
auto mut :
world().externals()) queue.
push(mut);
162 while (!queue.
empty()) {
163 auto mut = queue.
pop();
164 if (
auto m = mut->isa<
M>(); m && m->is_closed() && (!elide_empty_ || m->is_set()))
visit(root_ = m);
166 for (
auto local_mut : mut->mut_local_muts()) queue.
push(local_mut);
191 return std::move(collector.
muts);
Removes unreachable and dead code by rebuilding the whole World into a new one and swapping afterward...
void start() override
Actual entry.
Transitively collects all closed mutables (Def::is_closed) in a World.
static Vector< M * > collect(World &world)
Wrapper to directly receive all closed mutables as Vector.
ClosedCollector(World &world)
virtual void visit(M *mut)
Transitively visits all reachable closed mutables (Def::is_closed()) in World.
ClosedMutPhase(World &world, std::string_view name, bool dirty, bool elide_empty)
void start() override
Actual entry.
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.
Like ClosedMutPhase but computes a Nest for each NestPhase::visit.
virtual void visit(const Nest &)=0
const Nest & nest() const
NestPhase(World &world, std::string_view name, bool dirty, bool elide_empty)
Builds a nesting tree of all immutables‍/binders.
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.
void run()
Run all registered passes on the whole World.
const auto & passes() const
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.
static void run(Args &&... args)
Runs a single Phase.
Phase(World &world, std::string_view name, bool dirty)
virtual void run()
Entry point and generates some debug output; invokes Phase::start.
std::string_view name() const
virtual void start()=0
Actual entry.
void set_name(std::string name)
Organizes several Phases as a pipeline.
auto add(Args &&... args)
Add a Phase.
void start() override
Actual entry.
const auto & phases() const
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.
This is a thin wrapper for absl::InlinedVector<T, N, / A> which in turn is a drop-in replacement for ...
The World represents the whole program and manages creation of MimIR nodes (Defs).