30 for (
const auto& [f, def] :
world().flags2annex())
33 bootstrapping_ =
false;
35 for (
auto mut :
world().externals().muts())
49 VLOG(
"iteration: {}", i++);
54 for (
const auto& [f, def] :
old_world().flags2annex())
57 bootstrapping_ =
false;
59 for (
auto mut :
old_world().externals().muts())
69 return analysis_->todo();
87 for (
auto&& repl :
repls)
88 if (
auto&& man = repl->isa<
ReplMan>())
89 apply(std::move(man->repls_));
96 for (
auto arg : app->args())
98 repls.emplace_back(std::unique_ptr<Repl>(
static_cast<Repl*
>(stage.release())));
109 auto repls =
Repls();
110 for (
auto arg : app->args())
112 repls.emplace_back(std::unique_ptr<Repl>(
static_cast<Repl*
>(stage.release())));
113 man_->apply(std::move(repls));
118 swap(man_, rmp.man_);
123 for (
auto&& repl :
man().repls())
124 ILOG(
" 🔹 `{}`", repl->name());
132 for (
auto&& repl :
man().repls())
133 if (
auto subst = repl->replace(def))
todo =
true, def = subst;
145 phases_ = std::move(
phases);
146 name_ += fixed_point_ ?
" tt" :
" ff";
153 for (
auto arg : args->projs())
156 if (
auto pm = stage->isa<
PassManPhase>(); pm && pm-> man().empty())
continue;
157 if (
auto rp = stage->isa<
ReplMan >(); rp && rp->
repls().empty())
continue;
159 phases.emplace_back(std::unique_ptr<Phase>(
static_cast<Phase*
>(stage.release())));
166 auto& man =
static_cast<PhaseMan&
>(stage);
167 apply(man.fixed_point(), std::move(man.phases_));
172 for (
bool todo =
true;
todo; ++iter) {
177 for (
auto& phase :
phases()) {
179 todo |= phase->todo();
185 for (
auto& old_phase :
phases()) {
186 auto new_phase = std::unique_ptr<Phase>(
static_cast<Phase*
>(old_phase->recreate().release()));
187 swap(new_phase, old_phase);
200 man_ = std::make_unique<PassMan>(
world(),
annex());
202 for (
auto arg : app->args())
204 passes.emplace_back(std::unique_ptr<Pass>(
static_cast<Pass*
>(stage.release())));
206 man_->apply(std::move(passes));
211 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