21using Repls = std::deque<std::unique_ptr<Repl>>;
22using Phases = std::deque<std::unique_ptr<Phase>>;
48 template<
class P,
class... Args>
49 static void run(Args&&... args) {
50 P p(std::forward<Args>(args)...);
94 void start()
override;
97 bool bootstrapping_ =
true;
114 , analysis_(analysis) {}
118 , analysis_(analysis) {}
147 void start()
override;
151 bool bootstrapping_ =
true;
173 void add(std::unique_ptr<Repl>&& repl) { repls_.emplace_back(std::move(repl)); }
174 const auto&
repls()
const {
return repls_; }
182#define MIM_CONCAT_INNER(a, b) a##b
183#define MIM_CONCAT(a, b) MIM_CONCAT_INNER(a, b)
185#define MIM_REPL(__stages, __annex, ...) MIM_REPL_IMPL(__stages, __annex, __LINE__, __VA_ARGS__)
188#define MIM_REPL_IMPL(__stages, __annex, __id, ...) \
189 struct MIM_CONCAT(Repl_, __id) : ::mim::Repl { \
190 MIM_CONCAT(Repl_, __id)(::mim::World & world, ::mim::flags_t annex) \
191 : Repl(world, annex) {} \
193 const ::mim::Def* replace(const ::mim::Def* def) final __VA_ARGS__ \
195 ::mim::Stage::hook<__annex, MIM_CONCAT(Repl_, __id)>(__stages)
241 void apply(
const App*)
final;
242 void apply(
Stage&)
final;
250 std::unique_ptr<PassMan> man_;
262 void apply(
bool,
Phases&&);
263 void apply(
const App*)
final;
264 void apply(
Stage&)
final;
271 const auto&
phases()
const {
return phases_; }
284template<class
M =
Def>
304 const bool elide_empty_;
309template<
class M = Def>
This Phase will recursively Rewriter::rewrite.
void start() override
Actual entry.
Analysis(World &world, std::string name)
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 *)
bool is_bootstrapping() const
Analysis(World &world, flags_t annex)
Cleanup(World &world, flags_t annex)
ClosedMutPhase(World &world, std::string name, bool elide_empty)
void start() override
Actual entry.
ClosedMutPhase(World &world, flags_t annex, bool elide_empty)
virtual void visit(M *)=0
NestPhase(World &world, flags_t annex, bool elide_empty)
virtual void visit(const Nest &)=0
const Nest & nest() const
NestPhase(World &world, std::string name, bool elide_empty)
Builds a nesting tree of all immutables‍/binders.
PassManPhase(World &world, flags_t annex)
PassManPhase(World &world, std::unique_ptr< PassMan > &&man)
void start() final
Actual entry.
const PassMan & man() const
An optimizer that combines several optimizations in an optimal way.
Organizes several Phases in a a pipeline.
PhaseMan(World &world, flags_t annex)
const auto & phases() const
As opposed to a Pass, a Phase does one thing at a time and does not mix with other 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)
static void run(Args &&... args)
Runs a single Phase.
Phase(World &world, flags_t annex)
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.
RWPhase(World &world, flags_t annex, Analysis *analysis=nullptr)
virtual void rewrite_annex(flags_t, const Def *)
bool is_bootstrapping() const
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
void start() override
Actual entry.
World & world()=delete
Hides both and forbids direct access.
World & old_world()
Get old Defs from here.
virtual void rewrite_external(Def *)
const Def * rewrite(const Def *) final
ReplManPhase(World &world, flags_t annex)
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.
void apply(Stage &stage) final
Dito, but invoked by Stage::recreate.
const auto & repls() const
const Def * replace(const Def *) final
ReplMan(World &world, flags_t annex)
void add(std::unique_ptr< Repl > &&repl)
Simple Stage that searches for a pattern and replaces it.
virtual const Def * replace(const Def *def)=0
Repl(World &world, flags_t annex)
Rewriter(std::unique_ptr< World > &&ptr)
Common base for Phase and Pass.
std::string_view name() const
Stage(World &world, std::string name)
The World represents the whole program and manages creation of MimIR nodes (Defs).
std::deque< std::unique_ptr< Repl > > Repls
std::deque< std::unique_ptr< Phase > > Phases