Common base of the two rewriting Phases: RWPhase rebuilds the World, InplaceRWPhase stays in it. More...
#include <mim/phase.h>
Public Member Functions | |
Analysis | |
| Analysis * | analysis () |
| const Analysis * | analysis () const |
| const Def * | lattice (const Def *def) const |
Returns the abstract value computed by the associated Analysis for def, or nullptr if no value is available. | |
| const Def * | abstracted (const Def *def) const |
Returns lattice(def) if it differs from def (i.e. we learned something), otherwise nullptr. | |
| virtual bool | analyze () |
| Runs the optional pre-analysis on Phase::world, typically to a fixed point, before rewriting begins. | |
Rewrite | |
| virtual bool | rewrite_annexes () const =0 |
| virtual void | rewrite_annex (flags_t, Sym, const Def *)=0 |
| virtual void | rewrite_external (Def *)=0 |
| bool | is_bootstrapping () const |
| Returns whether we are currently bootstrapping (rewriting annexes). | |
| Public Member Functions inherited from mim::Phase | |
| Phase (World &world, std::string name) | |
| Phase (World &world, flags_t annex) | |
| virtual | ~Phase ()=default |
| virtual std::unique_ptr< Phase > | recreate () |
| Creates a new instance; needed by a fixed-point PhaseMan. | |
| virtual void | apply (const App *) |
| Invoked if your Phase has additional args. | |
| virtual void | apply (Phase &) |
| Dito, but invoked by Phase::recreate. | |
| virtual bool | redirects () const |
| If true, Phase::create uses take_resolved(). | |
| virtual std::unique_ptr< Phase > | take_resolved () |
| The Phase to use instead; nullptr means elide. | |
| World & | world () |
| Driver & | driver () |
| const fe::Log & | log () const |
| std::string_view | name () const |
| flags_t | annex () const |
| const fe::Vector< std::string > & | args () |
| Command-line arguments passed to this Phase's plugin via -X <plugin>:<arg>. | |
| bool | todo () const |
| void | invalidate (bool todo=true) |
| Signals that another round of fixed-point iteration is required, either as part of. | |
| virtual void | run () |
| Entry point and generates some debug output; invokes Phase::start. | |
| void | profile_count (std::string_view key, uint64_t n=1) |
Adds n to the custom fe::Profiler counter key of the current run; no-op unless profiling is enabled. | |
| Public Member Functions inherited from mim::Rewriter | |
| template<class D = Def> | |
| D * | curr_mut () const |
| Rewriter (std::unique_ptr< World > &&ptr) | |
| Rewriter (World &world) | |
| virtual | ~Rewriter () |
| void | reset (std::unique_ptr< World > &&ptr) |
| void | reset () |
| World & | world () |
| virtual void | push () |
| virtual void | pop () |
| virtual const Def * | map (const Def *old_def, const Def *new_def) |
| const Def * | map_root (const Def *old_def, const Def *new_def) |
| Like map() but records into the root map, so the entry outlives the current push()/pop() scope. | |
| const Def * | map (const Def *old_def, Defs new_defs) |
| const Def * | map (Defs old_defs, const Def *new_def) |
| const Def * | map (Defs old_defs, Defs new_defs) |
| virtual const Def * | lookup (const Def *old_def) |
| Lookup old_def by searching in reverse through the stack of maps. | |
| virtual const Def * | rewrite (const Def *) |
| virtual const Def * | rewrite_imm (const Def *) |
| virtual const Def * | rewrite_mut (Def *) |
| virtual const Def * | rewrite_stub (Def *, Def *) |
| virtual DefVec | rewrite (Defs) |
| virtual const Def * | rewrite_imm_Seq (const Seq *seq) |
| virtual const Def * | rewrite_mut_Seq (Seq *seq) |
Protected Member Functions | |
| void | start () override |
| Actual entry. | |
| virtual const Def * | rewrite_root (const Def *def) |
| Rewrites a root - i.e. an annex or an external. | |
| virtual void | finalize () |
| Run after all roots have been walked - but for an RWPhase still before the two worlds are swapped. | |
Construction | |
Rewrite in place: Phase::world and Rewriter::world are the same. | |
| RWBase (World &world, std::string name, Analysis *analysis) | |
| RWBase (World &world, flags_t annex, Analysis *analysis) | |
| RWBase (World &world, std::string name, Analysis *analysis, std::unique_ptr< World > &&new_world) | |
Rewrite the World of Phase::world into new_world. | |
| RWBase (World &world, flags_t annex, Analysis *analysis, std::unique_ptr< World > &&new_world) | |
| Protected Member Functions inherited from mim::Rewriter | |
| auto | enter (Def *new_mut) |
Updates curr_mut() to new_mut and restores it at the end of the scope. | |
Additional Inherited Members | |
| Static Public Member Functions inherited from mim::Phase | |
| static std::unique_ptr< Phase > | create (const Flags2Phases &phases, const Def *def) |
| template<class A, class P> | |
| static void | hook (Flags2Phases &phases) |
| template<class P, class... Args> | |
| static void | run (Args &&... args) |
| Runs a single Phase. | |
| Protected Attributes inherited from mim::Phase | |
| std::string | name_ |
| Protected Attributes inherited from mim::Rewriter | |
| std::deque< Def2Def > | old2news_ |
Common base of the two rewriting Phases: RWPhase rebuilds the World, InplaceRWPhase stays in it.
Both are a Phase and a Rewriter, both run an optional analyze() to a fixed point, and both then rewrite
If an associated Analysis is provided, the rewrite can query its abstract results through lattice().
Definition at line 350 of file phase.h.
References mim::Phase::Analysis, analysis(), mim::Phase::name(), mim::Phase::Phase(), mim::Rewriter::Rewriter(), and mim::Phase::world().
Referenced by mim::InplaceRWPhase::InplaceRWPhase(), mim::InplaceRWPhase::InplaceRWPhase(), mim::RWPhase::RWPhase(), and mim::RWPhase::RWPhase().
Definition at line 354 of file phase.h.
References mim::Phase::Analysis, analysis(), mim::Phase::annex(), mim::Phase::Phase(), mim::Rewriter::Rewriter(), and mim::Phase::world().
|
inlineprotected |
Rewrite the World of Phase::world into new_world.
Definition at line 360 of file phase.h.
References mim::Phase::Analysis, analysis(), mim::Phase::name(), mim::Phase::Phase(), mim::Rewriter::Rewriter(), and mim::Phase::world().
|
inlineprotected |
Definition at line 364 of file phase.h.
References mim::Phase::Analysis, analysis(), mim::Phase::annex(), mim::Phase::Phase(), mim::Rewriter::Rewriter(), and mim::Phase::world().
Returns lattice(def) if it differs from def (i.e. we learned something), otherwise nullptr.
Definition at line 382 of file phase.h.
References lattice().
Referenced by mim::plug::mem::phase::SEO::rewrite_imm_App().
|
inline |
Definition at line 373 of file phase.h.
References mim::Phase::Analysis.
Referenced by mim::InplaceRWPhase::InplaceRWPhase(), mim::InplaceRWPhase::InplaceRWPhase(), RWBase(), RWBase(), RWBase(), RWBase(), mim::RWPhase::RWPhase(), and mim::RWPhase::RWPhase().
|
inline |
Definition at line 374 of file phase.h.
References mim::Phase::Analysis.
|
virtual |
Runs the optional pre-analysis on Phase::world, typically to a fixed point, before rewriting begins.
If analysis() is set, this is the natural place to iterate until Phase::todo() becomes false. If no Analysis is needed, simply return false.
Reimplemented in mim::BetaRed, mim::EtaConv, mim::plug::clos::phase::ClosConvPrep, mim::plug::clos::phase::LowerTypedClosPrep, mim::plug::gpu::phase::SplitOffKernels, mim::plug::mem::phase::AddMem, mim::plug::mem::phase::SEO, mim::RetWrap, and mim::StaticArgOpt.
Definition at line 179 of file phase.cpp.
Referenced by mim::plug::mem::phase::SEO::analyze(), and start().
|
inlineprotectedvirtual |
Run after all roots have been walked - but for an RWPhase still before the two worlds are swapped.
This is where you drain a worklist of rewrites your hooks deferred (see e.g. clos::phase::ClosConv).
Reimplemented in mim::plug::clos::phase::ClosConv, and mim::plug::clos::phase::LowerTypedClos.
Definition at line 415 of file phase.h.
Referenced by start().
|
inline |
Returns whether we are currently bootstrapping (rewriting annexes).
While bootstrapping, you have to skip rewrites that refer to other annexes, as they might not yet be available.
Definition at line 403 of file phase.h.
Referenced by mim::plug::clos::phase::LowerTypedClos::rewrite(), mim::plug::mem::phase::AddMem::rewrite(), mim::plug::tensor::phase::LowerToMem::rewrite(), mim::plug::clos::phase::LowerTypedClos::rewrite_imm(), mim::LamSpec::rewrite_imm_App(), mim::plug::affine::phase::LowerFor::rewrite_imm_App(), mim::plug::affine::phase::LowerIndex::rewrite_imm_App(), mim::plug::autodiff::phase::Eval::rewrite_imm_App(), mim::plug::btensor::phase::LowerMapReduce::rewrite_imm_App(), mim::plug::buffer::LowerPtr::rewrite_imm_App(), mim::plug::clos::phase::BranchClosElim::rewrite_imm_App(), mim::plug::clos::phase::ClosConv::rewrite_imm_App(), mim::plug::clos::phase::ClosConvPrep::rewrite_imm_App(), mim::plug::clos::phase::LowerTypedClos::rewrite_imm_App(), mim::plug::mem::phase::AddMem::rewrite_imm_App(), mim::plug::regex::LowerRegex::rewrite_imm_App(), mim::plug::tensor::phase::LowerToMem::rewrite_imm_App(), mim::Scalarize::rewrite_imm_App(), mim::StaticArgOpt::rewrite_imm_App(), mim::plug::clos::phase::ClosConv::rewrite_imm_Extract(), mim::plug::clos::phase::ClosConv::rewrite_imm_Pi(), mim::plug::mem::phase::AddMem::rewrite_imm_Pi(), mim::Scalarize::rewrite_imm_Pi(), mim::plug::clos::phase::LowerTypedClosPrep::rewrite_imm_Tuple(), mim::plug::mem::phase::AddMem::rewrite_imm_Tuple(), mim::plug::clos::phase::Clos2SJLJ::rewrite_mut_Lam(), mim::plug::clos::phase::ClosConv::rewrite_mut_Lam(), mim::plug::cps::Conv::rewrite_mut_Lam(), mim::plug::mem::phase::AddMem::rewrite_mut_Lam(), mim::plug::tensor::phase::LowerToMem::rewrite_mut_Lam(), mim::Scalarize::rewrite_mut_Lam(), mim::StaticArgOpt::rewrite_mut_Lam(), and mim::plug::clos::phase::ClosConv::rewrite_mut_Pi().
Implemented in mim::InplaceRWPhase, and mim::RWPhase.
Referenced by start().
|
pure virtual |
Should start() walk the annex roots as well?
Implemented in mim::InplaceRWPhase, and mim::RWPhase.
Referenced by start().
|
pure virtual |
Implemented in mim::InplaceRWPhase, mim::plug::clos::phase::ClosConv, mim::plug::clos::phase::LowerTypedClos, and mim::RWPhase.
Referenced by start().
Rewrites a root - i.e. an annex or an external.
Defaults to rewrite(); override if roots need to be exempt from some of your rewrites.
Reimplemented in mim::EtaConv.
Definition at line 411 of file phase.h.
References mim::Rewriter::rewrite().
Referenced by mim::InplaceRWPhase::rewrite_annex(), mim::RWPhase::rewrite_annex(), mim::InplaceRWPhase::rewrite_external(), mim::plug::clos::phase::ClosConv::rewrite_external(), mim::plug::clos::phase::LowerTypedClos::rewrite_external(), and mim::RWPhase::rewrite_external().
|
overrideprotectedvirtual |
Actual entry.
Implements mim::Phase.
Reimplemented in mim::plug::gpu::phase::SplitApply, mim::plug::gpu::phase::SplitOffKernels, and mim::RWPhase.
Definition at line 151 of file phase.cpp.
References analyze(), mim::World::curr_gid(), mim::Phase::driver(), finalize(), mim::Driver::flags(), mim::Phase::log(), mim::Flags::max_fp_iters, mim::Phase::name(), mim::Phase::profile_count(), rewrite_annex(), rewrite_annexes(), rewrite_external(), mim::Phase::todo(), mim::Phase::world(), and mim::Rewriter::world().
Referenced by mim::RWPhase::start().