MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
mim::RWPhase Class Reference

Rebuilds old_world() into new_world() and then swaps them. More...

#include <mim/phase.h>

Inheritance diagram for mim::RWPhase:
[legend]

Public Member Functions

Construction
 RWPhase (World &world, std::string name, Analysis *analysis=nullptr)
 RWPhase (World &world, flags_t annex, Analysis *analysis=nullptr)
Analysis
Analysisanalysis ()
const Analysisanalysis () const
const Deflattice (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 Defabstracted (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
Worldworld ()=delete
 Hides both and forbids direct access.
Worldold_world ()
 Get old Defs from here.
Worldnew_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< Phaserecreate ()
 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< Phasetake_resolved ()
 The Phase to use instead; nullptr means elide.
Worldworld ()
Driverdriver ()
Loglog () 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 ()
Worldworld ()
virtual void push ()
virtual void pop ()
virtual const Defmap (const Def *old_def, const Def *new_def)
const Defmap (const Def *old_def, Defs new_defs)
const Defmap (Defs old_defs, const Def *new_def)
const Defmap (Defs old_defs, Defs new_defs)
virtual const Deflookup (const Def *old_def)
 Lookup old_def by searching in reverse through the stack of maps.
virtual const Defrewrite (const Def *)
virtual const Defrewrite_imm (const Def *)
virtual const Defrewrite_mut (Def *)
virtual const Defrewrite_stub (Def *, Def *)
virtual DefVec rewrite (Defs)
virtual const Defrewrite_imm_Seq (const Seq *seq)
virtual const Defrewrite_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< Phasecreate (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< Def2Defold2news_

Detailed Description

Rebuilds old_world() into new_world() and then swaps them.

It recursively rewrites

  1. all old World::annexes() (during which RWPhase::is_bootstrapping() is true, and then
  2. all old World::externals() (during which it is false).

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().

Note
You can override
See also
RWPhase

Definition at line 312 of file phase.h.

Constructor & Destructor Documentation

◆ RWPhase() [1/2]

mim::RWPhase::RWPhase ( World & world,
std::string name,
Analysis * analysis = nullptr )
inline

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().

◆ RWPhase() [2/2]

mim::RWPhase::RWPhase ( World & world,
flags_t annex,
Analysis * analysis = nullptr )
inline

Member Function Documentation

◆ abstracted()

const Def * mim::RWPhase::abstracted ( const Def * old_def) const
inline

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().

◆ analysis() [1/2]

Analysis * mim::RWPhase::analysis ( )
inline

Definition at line 328 of file phase.h.

References mim::Phase::Analysis.

Referenced by RWPhase(), and RWPhase().

◆ analysis() [2/2]

const Analysis * mim::RWPhase::analysis ( ) const
inline

Definition at line 329 of file phase.h.

References mim::Phase::Analysis.

◆ analyze()

bool mim::RWPhase::analyze ( )
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().

◆ is_bootstrapping()

bool mim::RWPhase::is_bootstrapping ( ) const
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().

◆ lattice()

const Def * mim::RWPhase::lattice ( const Def * old_def) const
inline

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().

◆ new_world()

World & mim::RWPhase::new_world ( )
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().

◆ old_world()

◆ rewrite_annex()

◆ rewrite_external()

void mim::RWPhase::rewrite_external ( Def * old_mut)
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().

◆ start()

◆ world()

World & mim::RWPhase::world ( )
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().


The documentation for this class was generated from the following files: