Rebuilds old_world() into new_world() and then swaps them. More...
#include <mim/phase.h>
Public Member Functions | |
Construction | |
| RWPhase (World &world, std::string name, Analysis *analysis=nullptr) | |
| RWPhase (World &world, flags_t annex, Analysis *analysis=nullptr) | |
Analysis | |
| Analysis * | analysis () |
| const Analysis * | analysis () const |
| const Def * | lattice (const Def *old_def) const |
| Returns the abstract value computed by the associated Analysis for the given old-world Def, or nullptr if no value is available. | |
| const Def * | abstracted (const Def *old_def) const |
Returns lattice(old_def) if it differs from old_def (i.e. we learned something), otherwise nullptr. | |
| virtual bool | analyze () |
| Runs the optional pre-analysis on RWPhase::old_world(), typically to a fixed point, before rewriting begins. | |
Rewrite | |
| virtual void | rewrite_annex (flags_t, Sym, const Def *) |
| virtual void | rewrite_external (Def *) |
| bool | is_bootstrapping () const |
| Returns whether we are currently bootstrapping (rewriting annexes). | |
World | |
| |
| World & | world ()=delete |
| Hides both and forbids direct access. | |
| World & | old_world () |
| Get old Defs from here. | |
| World & | new_world () |
| Create new Defs into this. | |
| 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 () |
| Log & | log () const |
| std::string_view | name () const |
| flags_t | annex () const |
| const 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 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 (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. | |
| 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_ |
Rebuilds old_world() into new_world() and then swaps them.
It recursively rewrites
During bootstrapping, rewrites that depend on other annexes may need to be skipped, since those annexes might not yet exist in the new world.
If an associated Analysis is provided, the rewrite can query its abstract results through lattice().
Definition at line 316 of file phase.h.
References mim::Phase::Analysis, analysis(), mim::Phase::name(), mim::Phase::Phase(), mim::Rewriter::Rewriter(), and world().
Referenced by mim::plug::mem::phase::AddMem::AddMem(), mim::BetaRed::BetaRed(), mim::BetaRed::BetaRed(), mim::plug::clos::phase::BranchClosElim::BranchClosElim(), mim::BranchNormalize::BranchNormalize(), mim::Cleanup::Cleanup(), mim::Cleanup::Cleanup(), mim::plug::clos::phase::Clos2SJLJ::Clos2SJLJ(), mim::plug::clos::phase::ClosConv::ClosConv(), mim::plug::clos::phase::ClosConvPrep::ClosConvPrep(), mim::plug::cps::Conv::Conv(), mim::EtaConv::EtaConv(), mim::EtaConv::EtaConv(), mim::plug::autodiff::phase::Eval::Eval(), mim::plug::tensor::phase::Fuse::Fuse(), mim::LamSpec::LamSpec(), mim::plug::tensor::phase::Lower::Lower(), mim::plug::matrix::phase::LowerAff::LowerAff(), mim::plug::affine::phase::LowerFor::LowerFor(), mim::plug::tensor::phase::LowerGetSet::LowerGetSet(), mim::plug::affine::phase::LowerIndex::LowerIndex(), mim::plug::tensor::phase::LowerMapReduce::LowerMapReduce(), mim::plug::matrix::phase::LowerMatrixHighLevelMapRed::LowerMatrixHighLevelMapRed(), mim::plug::matrix::phase::LowerMatrixMediumLevel::LowerMatrixMediumLevel(), mim::plug::buffer::LowerPtr::LowerPtr(), mim::plug::regex::LowerRegex::LowerRegex(), mim::plug::tensor::phase::LowerToMem::LowerToMem(), mim::plug::clos::phase::LowerTypedClos::LowerTypedClos(), mim::plug::clos::phase::LowerTypedClosPrep::LowerTypedClosPrep(), mim::PrefixCleanup::PrefixCleanup(), mim::Repl::Repl(), mim::RetWrap::RetWrap(), mim::Scalarize::Scalarize(), mim::plug::mem::phase::SEO::SEO(), mim::plug::gpu::phase::SplitApply::SplitApply(), mim::plug::gpu::phase::SplitOffKernels::SplitOffKernels(), mim::plug::gpu::phase::SplitOffKernels::SplitOffKernels(), and mim::TailRecElim::TailRecElim().
Definition at line 320 of file phase.h.
References mim::Phase::Analysis, analysis(), mim::Phase::annex(), mim::Phase::Phase(), mim::Rewriter::Rewriter(), and world().
Returns lattice(old_def) if it differs from old_def (i.e. we learned something), otherwise nullptr.
Definition at line 336 of file phase.h.
References lattice().
Referenced by mim::plug::mem::phase::SEO::rewrite_imm_App().
|
inline |
Definition at line 328 of file phase.h.
References mim::Phase::Analysis.
|
inline |
Definition at line 329 of file phase.h.
References mim::Phase::Analysis.
|
virtual |
Runs the optional pre-analysis on RWPhase::old_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, and mim::RetWrap.
Definition at line 148 of file phase.cpp.
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 356 of file phase.h.
Referenced by mim::plug::mem::phase::AddMem::rewrite(), 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::buffer::LowerPtr::rewrite_imm_App(), mim::plug::clos::phase::BranchClosElim::rewrite_imm_App(), mim::plug::clos::phase::ClosConvPrep::rewrite_imm_App(), mim::plug::matrix::phase::LowerAff::rewrite_imm_App(), mim::plug::matrix::phase::LowerMatrixHighLevelMapRed::rewrite_imm_App(), mim::plug::matrix::phase::LowerMatrixMediumLevel::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::TailRecElim::rewrite_imm_App(), 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::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(), and mim::TailRecElim::rewrite_mut_Lam().
Returns the abstract value computed by the associated Analysis for the given old-world Def, or nullptr if no value is available.
Definition at line 333 of file phase.h.
Referenced by abstracted().
|
inline |
Create new Defs into this.
Definition at line 368 of file phase.h.
References mim::Rewriter::world().
Referenced by mim::plug::affine::phase::LowerIndex::rewrite(), mim::plug::clos::phase::LowerTypedClos::rewrite(), mim::EtaConv::rewrite_annex(), rewrite_annex(), mim::EtaConv::rewrite_imm_App(), mim::LamSpec::rewrite_imm_App(), mim::plug::affine::phase::LowerFor::rewrite_imm_App(), mim::plug::affine::phase::LowerIndex::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::cps::Conv::rewrite_imm_App(), mim::plug::matrix::phase::LowerMatrixHighLevelMapRed::rewrite_imm_App(), mim::plug::matrix::phase::LowerMatrixMediumLevel::rewrite_imm_App(), mim::plug::mem::phase::AddMem::rewrite_imm_App(), mim::plug::mem::phase::SEO::rewrite_imm_App(), mim::plug::regex::LowerRegex::rewrite_imm_App(), mim::plug::tensor::phase::Lower::rewrite_imm_App(), mim::plug::tensor::phase::LowerToMem::rewrite_imm_App(), mim::Scalarize::rewrite_imm_App(), mim::TailRecElim::rewrite_imm_App(), 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::EtaConv::rewrite_imm_Var(), 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::RetWrap::rewrite_mut_Lam(), mim::Scalarize::rewrite_mut_Lam(), mim::TailRecElim::rewrite_mut_Lam(), mim::plug::clos::phase::ClosConv::start(), mim::plug::clos::phase::LowerTypedClos::start(), mim::plug::gpu::phase::SplitApply::start(), and start().
|
inline |
Get old Defs from here.
Definition at line 367 of file phase.h.
References mim::Phase::world().
Referenced by mim::BetaRed::analyze(), mim::EtaConv::analyze(), mim::plug::clos::phase::ClosConvPrep::analyze(), mim::plug::clos::phase::LowerTypedClosPrep::analyze(), mim::plug::gpu::phase::SplitOffKernels::analyze(), mim::RetWrap::analyze(), mim::plug::autodiff::phase::Eval::augment_(), mim::plug::clos::phase::LowerTypedClos::rewrite(), mim::LamSpec::rewrite_imm_App(), mim::plug::matrix::phase::LowerMatrixHighLevelMapRed::rewrite_imm_App(), mim::RetWrap::rewrite_mut_Lam(), mim::plug::clos::phase::ClosConv::start(), mim::plug::clos::phase::LowerTypedClos::start(), mim::plug::gpu::phase::SplitApply::start(), mim::plug::gpu::phase::SplitOffKernels::start(), mim::plug::mem::phase::AddMem::start(), start(), and mim::Repl::world().
Reimplemented in mim::EtaConv.
Definition at line 158 of file phase.cpp.
References mim::World::annexes(), mim::World::Annexes::attach(), new_world(), and mim::Rewriter::rewrite().
Referenced by mim::plug::clos::phase::ClosConv::start(), mim::plug::clos::phase::LowerTypedClos::start(), mim::plug::gpu::phase::SplitOffKernels::start(), and start().
|
virtual |
Reimplemented in mim::EtaConv, and mim::PrefixCleanup.
Definition at line 160 of file phase.cpp.
References mim::Def::as_mut(), mim::Def::is_external(), and mim::Rewriter::rewrite().
Referenced by start().
|
overrideprotectedvirtual |
Actual entry.
Implements mim::Phase.
Reimplemented in mim::plug::gpu::phase::SplitApply, and mim::plug::gpu::phase::SplitOffKernels.
Definition at line 128 of file phase.cpp.
References analyze(), mim::Phase::driver(), mim::Driver::flags(), mim::Flags::max_fp_iters, mim::Phase::name(), new_world(), old_world(), rewrite_annex(), rewrite_external(), mim::Rewriter::swap, mim::Phase::todo(), and VLOG.
Referenced by mim::plug::mem::phase::AddMem::start(), and mim::plug::tensor::phase::LowerToMem::start().
|
delete |
Hides both and forbids direct access.
Referenced by mim::plug::mem::phase::AddMem::AddMem(), mim::plug::autodiff::phase::Eval::augment_app(), mim::plug::autodiff::phase::Eval::augment_extract(), mim::plug::autodiff::phase::Eval::augment_lam(), mim::plug::autodiff::phase::Eval::augment_pack(), mim::plug::autodiff::phase::Eval::augment_tuple(), mim::BetaRed::BetaRed(), mim::BetaRed::BetaRed(), mim::plug::clos::phase::BranchClosElim::BranchClosElim(), mim::BranchNormalize::BranchNormalize(), mim::Cleanup::Cleanup(), mim::Cleanup::Cleanup(), mim::plug::clos::phase::Clos2SJLJ::Clos2SJLJ(), mim::plug::clos::phase::ClosConv::ClosConv(), mim::plug::clos::phase::ClosConvPrep::ClosConvPrep(), mim::plug::cps::Conv::Conv(), mim::plug::autodiff::phase::Eval::derive_(), mim::EtaConv::EtaConv(), mim::EtaConv::EtaConv(), mim::plug::tensor::phase::Fuse::Fuse(), mim::LamSpec::LamSpec(), mim::plug::tensor::phase::Lower::Lower(), mim::plug::matrix::phase::LowerAff::LowerAff(), mim::plug::affine::phase::LowerFor::LowerFor(), mim::plug::tensor::phase::LowerGetSet::LowerGetSet(), mim::plug::affine::phase::LowerIndex::LowerIndex(), mim::plug::tensor::phase::LowerMapReduce::LowerMapReduce(), mim::plug::matrix::phase::LowerMatrixHighLevelMapRed::LowerMatrixHighLevelMapRed(), mim::plug::matrix::phase::LowerMatrixMediumLevel::LowerMatrixMediumLevel(), mim::plug::buffer::LowerPtr::LowerPtr(), mim::plug::regex::LowerRegex::LowerRegex(), mim::plug::tensor::phase::LowerToMem::LowerToMem(), mim::plug::clos::phase::LowerTypedClos::LowerTypedClos(), mim::plug::clos::phase::LowerTypedClosPrep::LowerTypedClosPrep(), mim::PrefixCleanup::PrefixCleanup(), mim::plug::gpu::phase::RemoveDoubleSyncs::RemoveDoubleSyncs(), mim::RetWrap::RetWrap(), RWPhase(), RWPhase(), mim::Scalarize::Scalarize(), mim::plug::mem::phase::SEO::SEO(), mim::plug::gpu::phase::SplitApply::SplitApply(), mim::plug::gpu::phase::SplitOffKernels::SplitOffKernels(), mim::plug::gpu::phase::SplitOffKernels::SplitOffKernels(), and mim::TailRecElim::TailRecElim().