30 for (
const auto& [flags, e] :
world().annexes())
33 bootstrapping_ =
false;
35 for (
auto mut :
world().externals().muts())
45 for (
auto d : mut->
deps())
55 for (
auto v : var->tprojs()) {
57 if (
auto [i, ins] =
lattice_.emplace(v, v); !ins && i->second != v) {
74 VLOG(
"iteration: {}", i++);
79 for (
const auto& [flags, e] :
old_world().annexes())
82 bootstrapping_ =
false;
84 for (
auto mut :
old_world().externals().muts())
94 return analysis_->todo();
104 if (old_mut->
is_external()) new_mut->externalize();
112 for (
auto&& repl :
repls)
113 if (
auto&& man = repl->isa<
ReplMan>())
114 apply(std::move(man->repls_));
116 add(std::move(repl));
121 for (
auto arg : app->args())
123 repls.emplace_back(std::unique_ptr<Repl>(
static_cast<Repl*
>(stage.release())));
134 auto repls =
Repls();
135 for (
auto arg : app->args())
137 repls.emplace_back(std::unique_ptr<Repl>(
static_cast<Repl*
>(stage.release())));
138 man_->apply(std::move(repls));
143 swap(man_, rmp.man_);
148 for (
auto&& repl :
man().repls())
149 ILOG(
" 🔹 `{}`", repl->name());
157 for (
auto&& repl :
man().repls())
158 if (
auto subst = repl->replace(def))
todo =
true, def = subst;
170 phases_ = std::move(
phases);
171 name_ += fixed_point_ ?
" tt" :
" ff";
178 for (
auto arg : args->projs())
181 if (
auto pm = stage->isa<
PassManPhase>(); pm && pm-> man().empty())
continue;
182 if (
auto rp = stage->isa<
ReplMan >(); rp && rp->
repls().empty())
continue;
184 phases.emplace_back(std::unique_ptr<Phase>(
static_cast<Phase*
>(stage.release())));
191 auto& man =
static_cast<PhaseMan&
>(stage);
193 for (
auto& old_phase : man.phases())
194 new_phases.emplace_back(std::unique_ptr<Phase>(
static_cast<Phase*
>(old_phase->recreate().release())));
195 apply(man.fixed_point(), std::move(new_phases));
200 for (
bool todo =
true;
todo; ++iter) {
205 for (
auto& phase :
phases()) {
207 todo |= phase->todo();
213 for (
auto& old_phase :
phases()) {
214 auto new_phase = std::unique_ptr<Phase>(
static_cast<Phase*
>(old_phase->recreate().release()));
215 swap(new_phase, old_phase);
228 man_ = std::make_unique<PassMan>(
world(),
annex());
230 for (
auto arg : app->args())
232 passes.emplace_back(std::unique_ptr<Pass>(
static_cast<Pass*
>(stage.release())));
234 man_->apply(std::move(passes));
239 swap(man_, pmp.man_);
void start() override
Actual entry.
virtual void rewrite_annex(flags_t, Sym, const Def *)
Enter enter(Def *new_mut)
virtual void rewrite_external(Def *)
virtual Def * rewrite_deps(Def *)
Walks mut's dependencies under its curr_mut() scope.
virtual void reset()
Clears the rewriter map and resets Phase::todo() for the next fixed-point iteration.
Def * rewrite_mut(Def *) override
Default "visit a mutable" entry point: maps mut -> mut, seeds Lam binder vars to top (v -> v) in the ...
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.
Defs deps() const noexcept
std::pair< D *, const Var * > isa_binder() const
Is this a mutable that introduces a Var?
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 &&)
void invalidate(bool todo=true)
Signals that another round of fixed-point iteration is required, either as part of.
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()
Runs the optional pre-analysis on RWPhase::old_world(), typically to a fixed point,...
World & new_world()
Create new Defs into this.
virtual void rewrite_annex(flags_t, Sym, 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
virtual const Def * map(const Def *old_def, const Def *new_def)
std::deque< Def2Def > old2news_
virtual const Def * rewrite(const Def *)
Common base for Phase and Pass.
std::string_view name() const
static std::unique_ptr< Stage > create(const Flags2Stages &stages, const Def *def)
const Def * attach(flags_t, Sym, const Def *)
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.
std::deque< std::unique_ptr< Pass > > Passes
std::deque< std::unique_ptr< Repl > > Repls
std::deque< std::unique_ptr< Phase > > Phases