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

#include <mim/axm.h>

Inheritance diagram for mim::Axm:
[legend]

Classes

class  IsA
 
struct  IsANode
 

Public Member Functions

Normalization

For a curried App of an Axm, you only want to trigger normalization at specific spots.

For this reason, MimIR maintains a Def::curry_ counter that each App decrements. The Axm::normalizer() will be triggered when Axm::curry() becomes 0. These are also the spots that you can mim::test / mim::force / mim::IsA. After that, the counter will be set to Axm::trip(). E.g., let's say an Axm has this type:

A -> B -> C -> D -> E
^ |
| |
+---------+

Using an initial value as 5 for Axm::curry and 3 as Axm::trip has the effect that here

x a b c1 d1 e1 c2 d2 e2 c3 d3 e3

the Axm::normalizer will be triggered after App'ing e1, e2, and e3.

NormalizeFn normalizer () const
 
u8 curry () const
 
u8 trip () const
 
Annex Name

See also
annex_name "Annex Name"
plugin_t plugin () const
 
tag_t tag () const
 
sub_t sub () const
 
flags_t base () const
 
- Public Member Functions inherited from mim::Def
Worldworld () const noexcept
 
constexpr flags_t flags () const noexcept
 
constexpr u32 gid () const noexcept
 Global id - unique number for this Def.
 
constexpr u32 tid () const noexcept
 Trie id - only used in Trie.
 
constexpr u32 mark () const noexcept
 Used internally by free_vars().
 
constexpr size_t hash () const noexcept
 
constexpr Node node () const noexcept
 
std::string_view node_name () const
 
u32 judge () const noexcept
 
bool is_form () const noexcept
 
bool is_intro () const noexcept
 
bool is_elim () const noexcept
 
bool is_meta () const noexcept
 
const Deftype () const noexcept
 Yields the "raw" type of this Def (maybe nullptr).
 
const Defunfold_type () const
 Yields the type of this Def and builds a new Type (UInc n) if necessary.
 
bool is_term () const
 
const Defarity () const
 
std::optional< nat_tisa_lit_arity () const
 
nat_t as_lit_arity () const
 
template<size_t N = std::dynamic_extent>
constexpr auto ops () const noexcept
 
const Defop (size_t i) const noexcept
 
constexpr size_t num_ops () const noexcept
 
Defset (size_t i, const Def *)
 Successively set from left to right.
 
Defreset (size_t i, const Def *def)
 Successively reset from left to right.
 
Defset (Defs ops)
 Def::set ops all at once.
 
Defreset (Defs ops)
 Def::reset ops all at once.
 
Defunset ()
 Unsets all Def::ops; works even, if not set at all or partially.
 
bool is_set () const
 Yields true if empty or the last op is set.
 
Defs deps () const noexcept
 
const Defdep (size_t i) const noexcept
 
size_t num_deps () const noexcept
 
bool has_dep () const
 
bool has_dep (Dep d) const
 
bool has_dep (unsigned u) const
 
nat_t num_projs () const
 Yields Def::as_lit_arity(), if it is in fact a Lit, or 1 otherwise.
 
nat_t num_tprojs () const
 As above but yields 1, if Flags::scalarize_threshold is exceeded.
 
const Defproj (nat_t a, nat_t i) const
 Similar to World::extract while assuming an arity of a, but also works on Sigmas and Arrays.
 
const Defproj (nat_t i) const
 As above but takes Def::num_projs as arity.
 
const Deftproj (nat_t i) const
 As above but takes Def::num_tprojs.
 
template<nat_t A = std::dynamic_extent, class F>
auto projs (F f) const
 Splits this Def via Def::projections into an Array (if A == std::dynamic_extent) or std::array (otherwise).
 
template<class F>
auto tprojs (F f) const
 
template<class F>
auto projs (nat_t a, F f) const
 
template<nat_t A = std::dynamic_extent>
auto projs () const
 
auto tprojs () const
 
auto projs (nat_t a) const
 
nat_t num_vars () noexcept
 
nat_t num_tvars () noexcept
 
const Defvar (nat_t a, nat_t i) noexcept
 
const Defvar (nat_t i) noexcept
 
const Deftvar (nat_t i) noexcept
 
template<nat_t A = std::dynamic_extent, class F>
auto vars (F f) noexcept
 
template<class F>
auto tvars (F f) noexcept
 
template<nat_t A = std::dynamic_extent>
auto vars () noexcept
 
auto tvars () noexcept
 
template<class F>
auto vars (nat_t a, F f) noexcept
 
auto vars (nat_t a) noexcept
 
const Defvar ()
 Not necessarily a Var: E.g., if the return type is [], this will yield ().
 
const Varhas_var ()
 Only returns not nullptr, if Var of this mutable has ever been created.
 
const Varhas_var () const
 As above if this is a mutable.
 
Muts local_muts () const
 Mutables reachable by following immutable deps(); mut->local_muts() is by definition the set { mut }.
 
Vars local_vars () const
 Vars reachable by following immutable deps().
 
Vars free_vars () const
 Compute a global solution by transitively following mutables as well.
 
Vars free_vars ()
 
Muts users ()
 Set of mutables where this mutable is locally referenced.
 
bool is_open () const
 Has free_vars()?
 
bool is_closed () const
 Has no free_vars()?
 
bool is_external () const
 
void make_external ()
 
void make_internal ()
 
void transfer_external (Def *to)
 
template<class T = Def>
const T * isa_imm () const
 
template<class T = Def>
const T * as_imm () const
 
template<class T = Def, class R>
const T * isa_imm (R(T::*f)() const) const
 
template<class T = Def, bool invert = false>
T * isa_mut () const
 If this is mutable, it will cast constness away and perform a dynamic_cast to T.
 
template<class T = Def, bool invert = false>
T * as_mut () const
 Asserts that this is a mutable, casts constness away and performs a static_cast to T.
 
Dbg dbg () const
 
Loc loc () const
 
Sym sym () const
 
std::string unique_name () const
 name + "_" + Def::gid
 
template<bool Ow = false>
const Defset (Loc l) const
 
template<bool Ow = false>
Defset (Loc l)
 
template<bool Ow = false>
const Defset (Sym s) const
 
template<bool Ow = false>
Defset (Sym s)
 
template<bool Ow = false>
const Defset (std::string s) const
 
template<bool Ow = false>
Defset (std::string s)
 
template<bool Ow = false>
const Defset (Loc l, Sym s) const
 
template<bool Ow = false>
Defset (Loc l, Sym s)
 
template<bool Ow = false>
const Defset (Loc l, std::string s) const
 
template<bool Ow = false>
Defset (Loc l, std::string s)
 
template<bool Ow = false>
const Defset (Dbg d) const
 
template<bool Ow = false>
Defset (Dbg d)
 
const Defdebug_prefix (std::string) const
 
const Defdebug_suffix (std::string) const
 
Defstub (World &w, const Def *type)
 
Defstub (const Def *type)
 
const Defrebuild (World &w, const Def *type, Defs ops) const
 Def::rebuilds this Def while using new_op as substitute for its i'th Def::op.
 
const Defrebuild (const Def *type, Defs ops) const
 
virtual const Defimmutabilize ()
 Tries to make an immutable from a mutable.
 
bool is_immutabilizable ()
 
const Defrefine (size_t i, const Def *new_op) const
 
template<size_t N = std::dynamic_extent>
constexpr auto reduce (const Def *arg) const noexcept
 
virtual constexpr size_t reduction_offset () const noexcept
 First Def::op that needs to be dealt with during reduction; e.g.
 
virtual const Defcheck (size_t, const Def *def)
 
virtual const Defcheck ()
 
const Defzonk () const
 
void dump () const
 
void dump (int max) const
 
void write (int max) const
 
void write (int max, const char *file) const
 
std::ostream & stream (std::ostream &, int max) const
 
void dot (std::ostream &os, uint32_t max=0xFFFFFF, bool types=false) const
 
void dot (const char *file=nullptr, uint32_t max=0xFFFFFF, bool types=false) const
 Same as above but write to file or std::cout if file is nullptr.
 
void dot (const std::string &file, uint32_t max=0xFFFFFF, bool types=false) const
 
- Public Member Functions inherited from mim::Setters< Axm >
const Axmset (Loc l) const
 
Axmset (Loc l)
 
const Axmset (Sym s) const
 
Axmset (Sym s)
 
const Axmset (std::string s) const
 
Axmset (std::string s)
 
const Axmset (Loc l, Sym s) const
 
Axmset (Loc l, Sym s)
 
const Axmset (Loc l, std::string s) const
 
Axmset (Loc l, std::string s)
 
const Axmset (Dbg d) const
 
Axmset (Dbg d)
 

Static Public Member Functions

Normalization - Helpers
static std::tuple< const Axm *, u8, u8get (const Def *def)
 Yields currying counter of def.
 
static std::pair< u8, u8infer_curry_and_trip (const Def *type)
 
isa/as
template<class Id, bool DynCast = true>
static auto isa (const Def *def)
 
template<class Id, bool DynCast = true>
static auto isa (Id id, const Def *def)
 
template<class Id>
static auto as (const Def *def)
 
template<class Id>
static auto as (Id id, const Def *def)
 

Static Public Attributes

static constexpr u8 Trip_End = u8(-1)
 
static constexpr auto Node = mim::Node::Axm
 

Private Member Functions

const Defrebuild_ (World &, const Def *, Defs) const override
 

Friends

class World
 

Additional Inherited Members

- Protected Member Functions inherited from mim::Def
 Def (World *, Node, const Def *type, Defs ops, flags_t flags)
 Constructor for an immutable Def.
 
 Def (Node, const Def *type, Defs ops, flags_t flags)
 As above but World retrieved from type.
 
 Def (Node, const Def *type, size_t num_ops, flags_t flags)
 Constructor for a mutable Def.
 
virtual ~Def ()=default
 
Sym sym (const char *) const
 
Sym sym (std::string_view) const
 
Sym sym (std::string) const
 
- Protected Attributes inherited from mim::Def
Dbg dbg_
 
union { 
 
NormalizeFn normalizer_
 Axm only: Axms use this member to store their normalizer.
 
const Axmaxm_
 App only: Curried Apps of Axms use this member to propagate the Axm.
 
const Varvar_
 Mutable only: Var of a mutable.
 
Worldworld_
 
};  
 
flags_t flags_
 
u8 curry_ = 0
 
u8 trip_ = 0
 

Detailed Description

Definition at line 9 of file axm.h.


Class Documentation

◆ mim::Axm::IsANode

struct mim::Axm::IsANode
template<class T>
struct mim::Axm::IsANode< T >

Type of IsA::def_.

Definition at line 63 of file axm.h.

Class Members
typedef App type App

Member Function Documentation

◆ as() [1/2]

template<class Id>
static auto mim::Axm::as ( const Def * def)
inlinestatic

◆ as() [2/2]

template<class Id>
static auto mim::Axm::as ( Id id,
const Def * def )
inlinestatic

Definition at line 126 of file axm.h.

References isa().

◆ base()

flags_t mim::Axm::base ( ) const
inline

Definition at line 57 of file axm.h.

References mim::Def::flags(), and mim::Annex::flags2base().

◆ curry()

u8 mim::Axm::curry ( ) const
inline

Definition at line 37 of file axm.h.

References mim::Def::curry_.

Referenced by infer_curry_and_trip(), isa(), isa(), and rebuild_().

◆ get()

std::tuple< const Axm *, u8, u8 > mim::Axm::get ( const Def * def)
static

Yields currying counter of def.

Returns
{nullptr, 0, 0} if no Axm is present.

Definition at line 38 of file axm.cpp.

References get().

Referenced by mim::World::app(), get(), isa(), isa(), and mim::World::raw_app().

◆ infer_curry_and_trip()

std::pair< u8, u8 > mim::Axm::infer_curry_and_trip ( const Def * type)
static

Definition at line 14 of file axm.cpp.

References curry(), infer_curry_and_trip(), trip(), and mim::Def::type().

Referenced by mim::ast::AxmDecl::emit(), and infer_curry_and_trip().

◆ isa() [1/2]

template<class Id, bool DynCast = true>
static auto mim::Axm::isa ( const Def * def)
inlinestatic
See also
Matching Axioms

Definition at line 104 of file axm.h.

References mim::Annex::Base, curry(), and get().

Referenced by mim::plug::clos::LowerTypedClosPrep::analyze(), as(), as(), mim::plug::autodiff::autodiff_type_fun(), mim::plug::regex::compare_re(), mim::ll::Emitter::emit_bb(), mim::ll::Emitter::emit_epilogue(), mim::ll::Emitter::emit_imported(), mim::plug::regex::equals_any(), mim::plug::regex::equals_any(), mim::plug::regex::equals_any(), mim::plug::regex::flatten_in_arg(), mim::plug::clos::ClosLit::fnc_as_lam(), mim::plug::regex::get_range(), mim::plug::clos::ClosLit::isa_clos_lit, mim::plug::math::isa_f(), mim::plug::math::match_f(), mim::plug::mem::mem_def(), mim::plug::regex::merge_ranges(), mim::plug::autodiff::normalize_add(), mim::plug::core::normalize_bitcast(), mim::plug::regex::normalize_disj(), mim::plug::core::normalize_pe(), mim::plug::regex::normalize_quant(), mim::plug::matrix::normalize_read(), mim::plug::matrix::normalize_shape(), mim::plug::core::normalize_trait(), mim::plug::matrix::op_read(), mim::ll::Emitter::prepare(), mim::plug::mem::replace_mem(), mim::plug::affine::LowerFor::rewrite(), mim::plug::autodiff::AutoDiffEval::rewrite(), mim::plug::autodiff::AutoDiffZero::rewrite(), mim::plug::autodiff::AutoDiffZeroCleanup::rewrite(), mim::plug::clos::ClosConvPrep::rewrite(), mim::plug::clos::LowerTypedClosPrep::rewrite(), mim::plug::mem::Alloc2Malloc::rewrite(), mim::plug::mem::RememElim::rewrite(), mim::plug::mem::SSAConstr::rewrite(), mim::plug::refly::RemoveDbgPerm::rewrite(), mim::plug::regex::LowerRegex::rewrite(), mim::plug::matrix::LowerMatrixHighLevelMapRed::rewrite_(), mim::plug::matrix::LowerMatrixMediumLevel::rewrite_(), mim::plug::clos::ClosConvPrep::rewrite_arg(), mim::plug::matrix::LowerMatrixLowLevel::rewrite_imm(), mim::plug::mem::strip_mem(), and mim::plug::mem::strip_mem_ty().

◆ isa() [2/2]

template<class Id, bool DynCast = true>
static auto mim::Axm::isa ( Id id,
const Def * def )
inlinestatic

Definition at line 114 of file axm.h.

References curry(), and get().

◆ normalizer()

NormalizeFn mim::Axm::normalizer ( ) const
inline

Definition at line 36 of file axm.h.

Referenced by rebuild_().

◆ plugin()

plugin_t mim::Axm::plugin ( ) const
inline

Definition at line 54 of file axm.h.

References mim::Def::flags(), and mim::Annex::flags2plugin().

Referenced by mim::Axm::IsA< Id, D >::plugin(), and rebuild_().

◆ rebuild_()

const Def * mim::Axm::rebuild_ ( World & w,
const Def * t,
Defs  ) const
overrideprivatevirtual

◆ sub()

sub_t mim::Axm::sub ( ) const
inline

◆ tag()

tag_t mim::Axm::tag ( ) const
inline

Definition at line 55 of file axm.h.

References mim::Def::flags(), and mim::Annex::flags2tag().

Referenced by rebuild_(), and mim::Axm::IsA< Id, D >::tag().

◆ trip()

u8 mim::Axm::trip ( ) const
inline

Definition at line 38 of file axm.h.

References mim::Def::trip_.

Referenced by infer_curry_and_trip(), and rebuild_().

Friends And Related Symbol Documentation

◆ World

friend class World
friend

Definition at line 136 of file axm.h.

References World.

Referenced by rebuild_(), and World.

Member Data Documentation

◆ Node

auto mim::Axm::Node = mim::Node::Axm
staticconstexpr

Definition at line 131 of file axm.h.

◆ Trip_End

u8 mim::Axm::Trip_End = u8(-1)
staticconstexpr

Definition at line 130 of file axm.h.

Referenced by mim::World::app(), and mim::World::raw_app().


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