#include <mim/plug/ll/ll.h>
Public Types | |
| enum class | Rt { embed , ext } |
| How the C runtime wrappers (compiled to a <name>.ll via add_mim_runtime) reach the output. More... | |
| using | Super = NestPhase<Lam> |
Public Member Functions | |
| Emitter (World &world, std::string name, std::ostream &ostream) | |
| void | start () override |
| Actual entry. | |
| void | visit (const Nest &) override |
| void | emit_imported (Lam *) |
| virtual std::string | prepare () |
| virtual void | emit_epilogue (Lam *lam) |
| void | finalize () |
| std::string | emit_bb (BB &bb, const Def *def) |
| virtual std::optional< std::string > | isa_targetspecific_intrinsic (BB &, const Def *) |
| template<class... Args> | |
| void | declare (std::format_string< Args... > s, Args &&... args) |
| void | rt_mode (Rt rt) |
| bool | load_rt_module (std::string_view filename) |
| Locates the runtime module rt/<filename> (produced by add_mim_runtime) in the driver's search paths, reads it, and stores it for Rt::embed splicing. | |
| template<class... Args> | |
| void | declare_rt (std::format_string< Args... > sig, Args &&... args) |
Declares a runtime wrapper sig (implemented in a C runtime, see add_mim_runtime) and records that the runtime is required by this module. | |
| Public Member Functions inherited from mim::NestPhase< Lam > | |
| NestPhase (World &world, std::string name, bool elide_empty, bool schedule=false) | |
| NestPhase (World &world, flags_t annex, bool elide_empty, bool schedule=false) | |
| const Nest & | nest () const |
| Public Member Functions inherited from mim::ClosedMutPhase< M > | |
| ClosedMutPhase (World &world, std::string name, bool elide_empty, bool schedule=false) | |
| ClosedMutPhase (World &world, flags_t annex, bool elide_empty, bool schedule=false) | |
| bool | elide_empty () const |
| bool | schedule () const |
| 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 Attributes | |
| fe::Tab | tab = fe::Tab::spaces() |
Protected Member Functions | |
| std::ostream & | ostream () const |
| std::string | emit (const Def *def) |
| Recursively emits code. | |
| std::string | emit_unsafe (const Def *def) |
| As above but yielding an empty string is permitted. | |
| const Scheduler::Schedule & | schedule () const |
| The Scheduler::schedule of the function currently being emitted; see Emitter::visit. | |
| std::string | id (const Def *, bool force_bb=false) const |
| virtual std::string | convert (const Def *type, bool simd=true) |
Converts type to its LLVM representation as a value (simd) or in memory (!simd). | |
| std::string | convert_ret_pi (const Pi *) |
| std::optional< std::pair< nat_t, const Def * > > | vectorize (const Def *type) const |
Lane count and element type if a value of type is an LLVM vector. | |
| bool | has_vec (const Def *type) const |
Whether type's value representation contains an LLVM vector and hence differs from its memory one. | |
| void | emit_phi (Lam *callee, const Def *phi, std::string arg, Lam *pred) |
Registers arg as an incoming phi value for phi in callee, coming from predecessor pred. | |
| void | emit_phi_args (Lam *callee, const App *app, Lam *pred) |
Wires all non-mem.M arguments of app into callee's phis, coming from predecessor pred. | |
| virtual std::string | emit_slot (BB &bb, const App *app, const Def *pointee, const Def *) |
Emits the storage backing a mem.slot of type pointee and yields the pointer value. | |
| Protected Member Functions inherited from mim::ClosedMutPhase< M > | |
| virtual void | visit (M *)=0 |
| M * | root () const |
Protected Attributes | |
| Lam * | curr_lam_ = nullptr |
| std::ostream & | ostream_ |
| Scheduler | scheduler_ |
| Scheduler::Schedule | schedule_ |
| DefMap< std::string > | locals_ |
| std::array< DefMap< std::string >, 2 > | types_ |
| Indexed by the simd flag of Emitter::convert. | |
| LamMap< BB > | lam2bb_ |
| std::set< std::string > | decls_ |
| std::ostringstream | type_decls_ |
| std::ostringstream | vars_decls_ |
| std::ostringstream | func_decls_ |
| std::ostringstream | func_impls_ |
| LamMap< const Def * > | simd_phi_ |
| LamMap< std::pair< u64, bool > > | loop_md_ |
| bool | simd_ = true |
| Rt | rt_ = Rt::embed |
| bool | rt_used_ = false |
| std::string | rt_module_ |
| Protected Attributes inherited from mim::Phase | |
| std::string | name_ |
Static Protected Attributes | |
| static constexpr u64 | LoopMdBase = 1000 |
| Loop-metadata node id per ll.vec/ll.novec-annotated loop header, and whether it may vectorize; LoopMdBase and LoopMdBase + 1 hold the shared enable/disable hints, the per-loop nodes follow, clear of the ids the embedded runtime module brings along. | |
Friends | |
| void | mim_ll_convert (Emitter &e, const Def *type, bool simd, std::string &res) |
| The heavy, target-independent emitter methods are compiled once into libmim_ll (see ll.cpp). | |
| void | mim_ll_finalize (Emitter &e) |
| void | mim_ll_emit_epilogue (Emitter &e, Lam *lam) |
| void | mim_ll_emit_bb (Emitter &e, BB &bb, const Def *def, std::string &res) |
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. | |
| using mim::plug::ll::Emitter::Super = NestPhase<Lam> |
|
strong |
|
inline |
Definition at line 130 of file ll.h.
References mim::Phase::driver(), mim::World::driver(), mim::Driver::is_loaded(), mim::Driver::load(), mim_ll_convert, mim_ll_emit_bb, mim_ll_emit_epilogue, mim_ll_finalize, mim::Phase::name(), ostream(), ostream_, and mim::Phase::world().
Referenced by mim_ll_convert, mim_ll_emit_bb, mim_ll_emit_epilogue, mim_ll_finalize, and mim::plug::ll::Emit::start().
|
inlineprotectedvirtual |
Converts type to its LLVM representation as a value (simd) or in memory (!simd).
Only values use LLVM vectors; memory keeps the plain array layout C expects.
Reimplemented in mim::plug::nvptx::HostEmitter.
Definition at line 220 of file ll.h.
Referenced by mim::plug::nvptx::HostEmitter::convert(), convert_ret_pi(), emit_imported(), emit_slot(), mim::plug::nvptx::DeviceEmitter::emit_slot(), mim::plug::nvptx::DeviceEmitter::isa_targetspecific_intrinsic(), prepare(), and mim::plug::nvptx::DeviceEmitter::prepare().
|
inlineprotected |
Definition at line 389 of file ll.h.
References convert(), mim::Pi::dom(), mim::plug::mem::strip_mem_ty(), and mim::Phase::world().
Referenced by emit_imported(), prepare(), and mim::plug::nvptx::DeviceEmitter::prepare().
|
inline |
Definition at line 162 of file ll.h.
References mim::Phase::args(), and decls_.
Referenced by declare_rt(), mim::plug::nvptx::DeviceEmitter::isa_targetspecific_intrinsic(), mim::plug::nvptx::HostEmitter::isa_targetspecific_intrinsic(), and mim::plug::nvptx::DeviceEmitter::prepare().
|
inline |
Declares a runtime wrapper sig (implemented in a C runtime, see add_mim_runtime) and records that the runtime is required by this module.
In Rt::ext mode the declaration is emitted like any other declare. In Rt::embed mode the wrapper's definition is spliced into the output, so emitting a declare as well would be a redefinition — hence it is suppressed here.
Definition at line 187 of file ll.h.
References mim::Phase::args(), declare(), ext, rt_, and rt_used_.
|
inlineprotected |
Recursively emits code.
mem-typed defs yield an empty string, which this variant asserts against.
Definition at line 197 of file ll.h.
References emit_unsafe().
Referenced by mim::plug::nvptx::DeviceEmitter::isa_targetspecific_intrinsic(), and mim::plug::nvptx::HostEmitter::isa_targetspecific_intrinsic().
Definition at line 153 of file ll.h.
Referenced by emit_unsafe().
|
inlinevirtual |
Reimplemented in mim::plug::nvptx::HostEmitter.
Definition at line 151 of file ll.h.
Referenced by mim::plug::nvptx::HostEmitter::emit_epilogue(), and visit().
|
inline |
Definition at line 499 of file ll.h.
References convert(), convert_ret_pi(), mim::Lam::doms(), func_decls_, mim::Axm::isa(), mim::Pi::ret_pi(), and mim::Lam::type().
Referenced by visit().
|
inlineprotected |
Registers arg as an incoming phi value for phi in callee, coming from predecessor pred.
Definition at line 233 of file ll.h.
References mim::Def::blame(), id(), lam2bb_, locals_, MIM_LL_BE, and mim::ClosedMutPhase< M >::root().
Referenced by emit_phi_args().
|
inlineprotected |
Wires all non-mem.M arguments of app into callee's phis, coming from predecessor pred.
Definition at line 244 of file ll.h.
References mim::App::arg(), emit_phi(), emit_unsafe(), mim::Axm::isa(), mim::Def::num_tvars(), and mim::Def::var().
|
inlineprotectedvirtual |
Emits the storage backing a mem.slot of type pointee and yields the pointer value.
The generic backend allocates on the stack; targets may override (e.g. a global in a specific address space). Kept inline on purpose so Emitter retains no vtable key function (else its vtable would live in a single module and break derived backends loaded from a separate plugin).
Reimplemented in mim::plug::nvptx::DeviceEmitter.
Definition at line 258 of file ll.h.
References mim::plug::ll::BB::body(), convert(), and mim::Def::unique_name().
|
inlineprotected |
As above but yielding an empty string is permitted.
Definition at line 204 of file ll.h.
References curr_lam_, emit_bb(), lam2bb_, locals_, scheduler_, and mim::Scheduler::smart().
Referenced by emit(), emit_phi_args(), mim::plug::nvptx::DeviceEmitter::isa_targetspecific_intrinsic(), and mim::plug::nvptx::HostEmitter::isa_targetspecific_intrinsic().
|
inline |
|
inlineprotected |
|
inlineprotected |
Definition at line 377 of file ll.h.
References mim::Def::isa_mut(), and mim::Def::unique_name().
Referenced by emit_phi(), mim::plug::nvptx::DeviceEmitter::isa_targetspecific_intrinsic(), mim::plug::nvptx::HostEmitter::isa_targetspecific_intrinsic(), prepare(), mim::plug::nvptx::DeviceEmitter::prepare(), and mim::plug::nvptx::HostEmitter::start().
|
inlinevirtual |
Reimplemented in mim::plug::nvptx::DeviceEmitter, and mim::plug::nvptx::HostEmitter.
|
inline |
Locates the runtime module rt/<filename> (produced by add_mim_runtime) in the driver's search paths, reads it, and stores it for Rt::embed splicing.
Backends share this instead of duplicating the lookup: ll loads ll_rt.ll, nvptx loads nvptx_rt.ll, and so on — one merged module per plugin.
Definition at line 485 of file ll.h.
References mim::Phase::driver(), mim::World::log(), rt_module_, and mim::Phase::world().
Referenced by mim::plug::nvptx::emit_host().
|
inlineprotected |
Definition at line 193 of file ll.h.
References ostream_.
Referenced by mim::plug::nvptx::DeviceEmitter::DeviceEmitter(), mim::plug::nvptx::emit_device(), mim::plug::nvptx::emit_host(), Emitter(), mim::plug::nvptx::HostEmitter::HostEmitter(), and start().
|
inlinevirtual |
Reimplemented in mim::plug::nvptx::DeviceEmitter, and mim::plug::nvptx::HostEmitter.
Definition at line 513 of file ll.h.
References convert(), convert_ret_pi(), func_impls_, id(), mim::Axm::isa(), locals_, mim::Phase::name(), mim::Def::num_ops(), and mim::ClosedMutPhase< M >::root().
Referenced by mim::plug::nvptx::DeviceEmitter::prepare(), mim::plug::nvptx::HostEmitter::prepare(), and visit().
|
inline |
|
inlineprotected |
The Scheduler::schedule of the function currently being emitted; see Emitter::visit.
Definition at line 214 of file ll.h.
References schedule_.
|
inlineoverridevirtual |
Actual entry.
Reimplemented from mim::ClosedMutPhase< M >.
Reimplemented in mim::plug::nvptx::HostEmitter.
Definition at line 399 of file ll.h.
References decls_, embed, func_decls_, func_impls_, loop_md_, LoopMdBase, MIM_LL_BE, ostream(), rt_, rt_module_, rt_used_, mim::Phase::start(), type_decls_, and vars_decls_.
Referenced by mim::plug::nvptx::DeviceEmitter::start(), and mim::plug::nvptx::HostEmitter::start().
|
inlineprotected |
Lane count and element type if a value of type is an LLVM vector.
Definition at line 345 of file ll.h.
References mim::plug::ll::is_simd(), and simd_.
|
inlineoverridevirtual |
Implements mim::NestPhase< Lam >.
Definition at line 443 of file ll.h.
References mim::plug::ll::BB::BB(), mim::Def::blame(), curr_lam_, emit_epilogue(), emit_imported(), finalize(), mim::Lam::isa_basicblock(), lam2bb_, locals_, MIM_LL_BE, mim::NestPhase< Lam >::nest(), prepare(), mim::ClosedMutPhase< M >::root(), mim::Scheduler::schedule(), schedule_, and scheduler_.
The heavy, target-independent emitter methods are compiled once into libmim_ll (see ll.cpp).
libmim_nvptx reaches them through these extern "C" shims instead of recompiling the bodies; Emitter caches the pointers via GET_FUN_PTR in its constructor.
Definition at line 1158 of file ll.cpp.
References Emitter(), MIM_EXPORT, and mim_ll_convert.
Referenced by Emitter(), and mim_ll_convert.
Definition at line 1163 of file ll.cpp.
References Emitter(), MIM_EXPORT, and mim_ll_emit_bb.
Referenced by Emitter(), and mim_ll_emit_bb.
Definition at line 1162 of file ll.cpp.
References Emitter(), MIM_EXPORT, and mim_ll_emit_epilogue.
Referenced by Emitter(), and mim_ll_emit_epilogue.
|
friend |
Definition at line 1161 of file ll.cpp.
References Emitter(), MIM_EXPORT, and mim_ll_finalize.
Referenced by Emitter(), and mim_ll_finalize.
|
protected |
Definition at line 264 of file ll.h.
Referenced by emit_unsafe(), and visit().
|
protected |
|
protected |
Definition at line 275 of file ll.h.
Referenced by emit_imported(), and start().
|
protected |
Definition at line 276 of file ll.h.
Referenced by prepare(), mim::plug::nvptx::DeviceEmitter::prepare(), and start().
Definition at line 270 of file ll.h.
Referenced by mim::plug::nvptx::HostEmitter::emit_epilogue(), emit_phi(), emit_unsafe(), mim::plug::nvptx::DeviceEmitter::prepare(), mim::plug::nvptx::HostEmitter::prepare(), and visit().
|
protected |
Definition at line 268 of file ll.h.
Referenced by emit_phi(), emit_unsafe(), prepare(), mim::plug::nvptx::DeviceEmitter::prepare(), and visit().
|
staticconstexprprotected |
Loop-metadata node id per ll.vec/ll.novec-annotated loop header, and whether it may vectorize; LoopMdBase and LoopMdBase + 1 hold the shared enable/disable hints, the per-loop nodes follow, clear of the ids the embedded runtime module brings along.
Definition at line 282 of file ll.h.
Referenced by start().
|
protected |
Definition at line 286 of file ll.h.
Referenced by declare_rt(), rt_mode(), and start().
|
protected |
Definition at line 288 of file ll.h.
Referenced by load_rt_module(), and start().
|
protected |
Definition at line 287 of file ll.h.
Referenced by declare_rt(), and start().
|
protected |
Definition at line 267 of file ll.h.
Referenced by schedule(), and visit().
|
protected |
Definition at line 266 of file ll.h.
Referenced by emit_unsafe(), and visit().
|
protected |
Definition at line 285 of file ll.h.
Referenced by mim::plug::nvptx::DeviceEmitter::DeviceEmitter(), has_vec(), and vectorize().
|
protected |
|
protected |
Indexed by the simd flag of Emitter::convert.
|
protected |
Definition at line 274 of file ll.h.
Referenced by mim::plug::nvptx::DeviceEmitter::emit_slot(), mim::plug::nvptx::DeviceEmitter::prepare(), start(), and mim::plug::nvptx::HostEmitter::start().