MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
mim::RWBase Class Referenceabstract

Common base of the two rewriting Phases: RWPhase rebuilds the World, InplaceRWPhase stays in it. More...

#include <mim/phase.h>

Inheritance diagram for mim::RWBase:
[legend]

Public Member Functions

Analysis
Analysisanalysis ()
const Analysisanalysis () const
const Deflattice (const Def *def) const
 Returns the abstract value computed by the associated Analysis for def, or nullptr if no value is available.
const Defabstracted (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< 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 ()
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 ()
Worldworld ()
virtual void push ()
virtual void pop ()
virtual const Defmap (const Def *old_def, const Def *new_def)
const Defmap_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 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.
virtual const Defrewrite_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< 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

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

  1. all World::annexes() - if rewrite_annexes() says so - during which is_bootstrapping() is true, and then
  2. all World::externals() during which it is false.

If an associated Analysis is provided, the rewrite can query its abstract results through lattice().

Note
You can override
See also
RWBase

Definition at line 345 of file phase.h.

Constructor & Destructor Documentation

◆ RWBase() [1/4]

◆ RWBase() [2/4]

mim::RWBase::RWBase ( World & world,
flags_t annex,
Analysis * analysis )
inlineprotected

◆ RWBase() [3/4]

mim::RWBase::RWBase ( World & world,
std::string name,
Analysis * analysis,
std::unique_ptr< World > && new_world )
inlineprotected

◆ RWBase() [4/4]

mim::RWBase::RWBase ( World & world,
flags_t annex,
Analysis * analysis,
std::unique_ptr< World > && new_world )
inlineprotected

Member Function Documentation

◆ abstracted()

const Def * mim::RWBase::abstracted ( const Def * def) const
inline

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

◆ analysis() [1/2]

◆ analysis() [2/2]

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

Definition at line 374 of file phase.h.

References mim::Phase::Analysis.

◆ analyze()

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

◆ finalize()

virtual void mim::RWBase::finalize ( )
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().

◆ is_bootstrapping()

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

◆ lattice()

const Def * mim::RWBase::lattice ( const Def * def) const
inline

Returns the abstract value computed by the associated Analysis for def, or nullptr if no value is available.

Note
def is a Def of the World the Analysis ran on - the old one in the case of an RWPhase.

Definition at line 379 of file phase.h.

Referenced by abstracted().

◆ rewrite_annex()

virtual void mim::RWBase::rewrite_annex ( flags_t ,
Sym ,
const Def *  )
pure virtual

Implemented in mim::InplaceRWPhase, and mim::RWPhase.

Referenced by start().

◆ rewrite_annexes()

virtual bool mim::RWBase::rewrite_annexes ( ) const
pure virtual

Should start() walk the annex roots as well?

Implemented in mim::InplaceRWPhase, and mim::RWPhase.

Referenced by start().

◆ rewrite_external()

virtual void mim::RWBase::rewrite_external ( Def * )
pure virtual

◆ rewrite_root()

virtual const Def * mim::RWBase::rewrite_root ( const Def * def)
inlineprotectedvirtual

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

◆ start()


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