30 for (
const auto& [f, def] :
world().flags2annex())
33 bootstrapping_ =
false;
35 for (
auto mut :
world().externals().muts())
52 for (
const auto& [f, def] :
old_world().flags2annex())
55 bootstrapping_ =
false;
57 for (
auto mut :
old_world().externals().muts())
67 return analysis_->todo();
85 for (
auto&& repl :
repls)
86 if (
auto&& man = repl->isa<
ReplMan>())
87 apply(std::move(man->repls_));
94 for (
auto arg : app->args())
96 repls.emplace_back(std::unique_ptr<Repl>(
static_cast<Repl*
>(stage.release())));
107 auto repls =
Repls();
108 for (
auto arg : app->args())
110 repls.emplace_back(std::unique_ptr<Repl>(
static_cast<Repl*
>(stage.release())));
111 man_->apply(std::move(repls));
116 swap(man_, rmp.man_);
121 for (
auto&& repl :
man().repls())
122 ILOG(
" 🔹 `{}`", repl->name());
130 for (
auto&& repl :
man().repls())
131 if (
auto subst = repl->replace(def))
todo =
true, def = subst;
143 phases_ = std::move(
phases);
144 name_ += fixed_point_ ?
" tt" :
" ff";
151 for (
auto arg : args->projs())
154 if (
auto pm = stage->isa<
PassManPhase>(); pm && pm-> man().empty())
continue;
155 if (
auto rp = stage->isa<
ReplMan >(); rp && rp->
repls().empty())
continue;
157 phases.emplace_back(std::unique_ptr<Phase>(
static_cast<Phase*
>(stage.release())));
164 auto& man =
static_cast<PhaseMan&
>(stage);
165 apply(man.fixed_point(), std::move(man.phases_));
170 for (
bool todo =
true;
todo; ++iter) {
175 for (
auto& phase :
phases()) {
177 todo |= phase->todo();
183 for (
auto& old_phase :
phases()) {
184 auto new_phase = std::unique_ptr<Phase>(
static_cast<Phase*
>(old_phase->recreate().release()));
185 swap(new_phase, old_phase);
198 man_ = std::make_unique<PassMan>(
world(),
annex());
200 for (
auto arg : app->args())
202 passes.emplace_back(std::unique_ptr<Pass>(
static_cast<Pass*
>(stage.release())));
204 man_->apply(std::move(passes));
209 swap(man_, pmp.man_);
void start() override
Actual entry.
virtual void rewrite_external(Def *)
virtual void reset()
Clears all members and sets todo() to false for next round in a fixed-point iteration.
virtual void rewrite_annex(flags_t, const Def *)
static auto uncurry_args(const Def *def)
T * as_mut() const
Asserts that this is a mutable, casts constness away and performs a static_cast to T.
bool is_external() const noexcept
static T as(const Def *def)
Wraps a PassMan pipeline as a Phase.
PassManPhase(World &world, std::unique_ptr< PassMan > &&man)
void apply(const App *) final
Invoked if your Stage has additional args.
All Passes that want to be registered in the PassMan must implement this interface.
PhaseMan(World &world, flags_t annex)
void start() final
Actual entry.
void apply(bool, Phases &&)
bool todo_
Set to true to indicate that you want to rerun all Phasees in your current fixed-point PhaseMan.
Phase(World &world, std::string name)
virtual void run()
Entry point and generates some debug output; invokes Phase::start.
virtual void start()=0
Actual entry.
virtual bool analyze()
You can do an optional fixed-point loop on the RWPhase::old_world before rewriting.
World & new_world()
Create new Defs into this.
virtual void rewrite_annex(flags_t, const Def *)
void start() override
Actual entry.
World & old_world()
Get old Defs from here.
virtual void rewrite_external(Def *)
const Def * rewrite(const Def *) final
const ReplMan & man() const
void start() final
Actual entry.
ReplManPhase(World &world, std::unique_ptr< ReplMan > &&man)
void apply(const App *) final
Invoked if your Stage has additional args.
const auto & repls() const
ReplMan(World &world, flags_t annex)
void add(std::unique_ptr< Repl > &&repl)
Simple Stage that searches for a pattern and replaces it.
Repl(World &world, flags_t annex)
friend void swap(Rewriter &rw1, Rewriter &rw2) noexcept
std::deque< Def2Def > old2news_
virtual const Def * rewrite(const Def *)
Common base for Phase and Pass.
static auto create(const Flags2Stages &stages, const Def *def)
std::string_view name() const
World & verify()
Verifies that all externals() and annexes() are Def::is_closed(), if MIM_ENABLE_CHECKS.
void debug_dump()
Dump in Debug build if World::log::level is Log::Level::Debug.
const Def * register_annex(flags_t f, const Def *)
std::deque< std::unique_ptr< Pass > > Passes
std::deque< std::unique_ptr< Repl > > Repls
std::deque< std::unique_ptr< Phase > > Phases