29 for (
const auto& [f, def] :
old_world().flags2annex())
32 bootstrapping_ =
false;
34 for (
auto mut :
old_world().copy_externals())
44 if (old_mut->
is_external()) new_mut->make_external();
52 for (
auto&& repl :
repls)
53 if (
auto&& man = repl->isa<
ReplMan>())
54 apply(std::move(man->repls_));
61 for (
auto arg : app->args())
63 repls.emplace_back(std::unique_ptr<Repl>(
static_cast<Repl*
>(stage.release())));
75 for (
auto arg : app->args())
77 repls.emplace_back(std::unique_ptr<Repl>(
static_cast<Repl*
>(stage.release())));
78 man_->apply(std::move(repls));
88 for (
auto&& repl :
man().repls())
89 ILOG(
" 🔹 `{}`", repl->name());
97 for (
auto&& repl :
man().repls())
98 if (
auto subst = repl->replace(def))
todo =
true, def = subst;
110 phases_ = std::move(
phases);
111 name_ += fixed_point_ ?
" tt" :
" ff";
118 for (
auto arg : args->projs())
121 if (
auto pm = stage->isa<
PassManPhase>(); pm && pm-> man().empty())
continue;
122 if (
auto rp = stage->isa<
ReplMan >(); rp && rp->
repls().empty())
continue;
124 phases.emplace_back(std::unique_ptr<Phase>(
static_cast<Phase*
>(stage.release())));
131 auto& man =
static_cast<PhaseMan&
>(stage);
132 apply(man.fixed_point(), std::move(man.phases_));
137 for (
bool todo =
true;
todo; ++iter) {
142 for (
auto& phase :
phases()) {
144 todo |= phase->todo();
150 for (
auto& old_phase :
phases()) {
151 auto new_phase = std::unique_ptr<Phase>(
static_cast<Phase*
>(old_phase->recreate().release()));
152 swap(new_phase, old_phase);
165 man_ = std::make_unique<PassMan>(
world(),
annex());
167 for (
auto arg : app->args())
169 passes.emplace_back(std::unique_ptr<Pass>(
static_cast<Pass*
>(stage.release())));
171 man_->apply(std::move(passes));
176 swap(man_, pmp.man_);
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 current your 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.
World & new_world()
Create new Defs into this.
virtual void rewrite_annex(flags_t, const Def *)
void start() override
Actual entry.
virtual bool analyze()
You can do an optional fixed-point loop on the RWPhase::old_world before rewriting.
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)
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