#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 = mim::Emitter<std::string, std::string, BB, Emitter> |
Public Member Functions | |
| Emitter (World &world, std::string name, std::ostream &ostream) | |
| bool | is_valid (std::string_view s) |
| void | start () override |
| Actual entry. | |
| 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) |
| void | rt_module (std::string ll) |
| Provides the textual LLVM IR of the runtime module to splice in Rt::embed mode. | |
| 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) | |
| const Nest & | nest () const |
| Public Member Functions inherited from mim::ClosedMutPhase< Lam > | |
| ClosedMutPhase (World &world, std::string name, 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. | |
Protected Member Functions | |
| std::string | id (const Def *, bool force_bb=false) const |
| virtual std::string | convert (const Def *type, bool simd=true) |
| std::string | convert_ret_pi (const Pi *) |
| 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::Emitter< std::string, std::string, BB, Emitter > | |
| Emitter (World &world, std::string name, std::ostream &ostream, bool schedule=false) | |
| virtual bool | direct_style () |
| std::ostream & | ostream () const |
| std::string | emit (const Def *def) |
| Recursively emits code. | |
| std::string | emit_unsafe (const Def *def) |
| As above but returning !child().is_valid(value) is permitted. | |
| void | visit (const Nest &nest) override |
| const Scheduler::Schedule & | schedule () const |
| The Scheduler::schedule of the function currently being emitted; see Emitter::visit. | |
| Protected Member Functions inherited from mim::ClosedMutPhase< Lam > | |
| virtual void | visit (Lam *)=0 |
| Lam * | root () const |
Protected Attributes | |
| absl::btree_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< u64 > | loop_md_ |
| Rt | rt_ = Rt::embed |
| bool | rt_used_ = false |
| std::string | rt_module_ |
| Protected Attributes inherited from mim::Emitter< std::string, std::string, BB, Emitter > | |
| Lam * | curr_lam_ |
| std::ostream & | ostream_ |
| Scheduler | scheduler_ |
| Scheduler::Schedule | schedule_ |
| DefMap< std::string > | locals_ |
| DefMap< std::string > | globals_ |
| DefMap< std::string > | types_ |
| LamMap< BB > | lam2bb_ |
| Protected Attributes inherited from mim::Phase | |
| std::string | name_ |
Static Protected Attributes | |
| static constexpr u64 | LoopMdBase = 1000 |
| Loop-metadata node id per ll.vec-annotated loop header (see emit_epilogue_impl); numbered from LoopMdBase + 1 to stay 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. | |
| Public Attributes inherited from mim::Emitter< std::string, std::string, BB, Emitter > | |
| fe::Tab | tab |
| using mim::plug::ll::Emitter::Super = mim::Emitter<std::string, std::string, BB, Emitter> |
|
strong |
|
inline |
Definition at line 128 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(), mim::Emitter< std::string, std::string, BB, Emitter >::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 |
Reimplemented in mim::plug::ll_nvptx::DeviceEmitter, and mim::plug::ll_nvptx::HostEmitter.
Definition at line 194 of file ll.h.
Referenced by mim::plug::ll_nvptx::DeviceEmitter::convert(), mim::plug::ll_nvptx::HostEmitter::convert(), convert_ret_pi(), emit_imported(), emit_slot(), and prepare().
|
inlineprotected |
Definition at line 332 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::ll_nvptx::DeviceEmitter::prepare().
|
inline |
Definition at line 157 of file ll.h.
References mim::Phase::args(), and decls_.
Referenced by declare_rt(), mim::plug::ll_nvptx::DeviceEmitter::isa_targetspecific_intrinsic(), mim::plug::ll_nvptx::HostEmitter::isa_targetspecific_intrinsic(), and mim::plug::ll_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_.
|
inlinevirtual |
Reimplemented in mim::plug::ll_nvptx::HostEmitter.
Definition at line 146 of file ll.h.
Referenced by mim::plug::ll_nvptx::HostEmitter::emit_epilogue().
|
inline |
Definition at line 383 of file ll.h.
References convert(), convert_ret_pi(), func_decls_, mim::Axm::isa(), mim::Pi::ret_pi(), and mim::Lam::type().
|
inlineprotected |
Registers arg as an incoming phi value for phi in callee, coming from predecessor pred.
Definition at line 202 of file ll.h.
References id(), mim::Emitter< std::string, std::string, BB, Emitter >::lam2bb_, and mim::Emitter< std::string, std::string, BB, Emitter >::locals_.
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 208 of file ll.h.
References mim::App::arg(), emit_phi(), mim::Emitter< std::string, std::string, BB, Emitter >::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::ll_nvptx::DeviceEmitter.
Definition at line 222 of file ll.h.
References mim::plug::ll::BB::body(), convert(), and mim::Def::unique_name().
|
inlineprotected |
Definition at line 318 of file ll.h.
References mim::Def::isa_mut(), and mim::Def::unique_name().
Referenced by emit_phi(), mim::plug::ll_nvptx::DeviceEmitter::isa_targetspecific_intrinsic(), mim::plug::ll_nvptx::HostEmitter::isa_targetspecific_intrinsic(), prepare(), mim::plug::ll_nvptx::DeviceEmitter::prepare(), and mim::plug::ll_nvptx::HostEmitter::start().
|
inline |
|
inlinevirtual |
Reimplemented in mim::plug::ll_nvptx::DeviceEmitter, and mim::plug::ll_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, ll_nvptx loads ll_nvptx_rt.ll, and so on — one merged module per plugin.
Definition at line 369 of file ll.h.
References mim::Phase::driver(), mim::World::log(), rt_module_, and mim::Phase::world().
Referenced by mim::plug::ll_nvptx::emit_host().
|
inlinevirtual |
Reimplemented in mim::plug::ll_nvptx::DeviceEmitter, and mim::plug::ll_nvptx::HostEmitter.
Definition at line 397 of file ll.h.
References convert(), convert_ret_pi(), func_impls_, id(), mim::Def::is_external(), mim::plug::ll::is_simd(), mim::Axm::isa(), mim::Emitter< std::string, std::string, BB, Emitter >::locals_, mim::Phase::name(), mim::Def::num_ops(), mim::ClosedMutPhase< Lam >::root(), mim::Def::unique_name(), and mim::Def::vars().
Referenced by mim::plug::ll_nvptx::DeviceEmitter::prepare(), and mim::plug::ll_nvptx::HostEmitter::prepare().
|
inline |
Definition at line 170 of file ll.h.
References rt_.
Referenced by mim::plug::ll_nvptx::emit_host().
|
inline |
Provides the textual LLVM IR of the runtime module to splice in Rt::embed mode.
Definition at line 172 of file ll.h.
References rt_module_.
|
inlineoverridevirtual |
Actual entry.
Reimplemented from mim::ClosedMutPhase< Lam >.
Reimplemented in mim::plug::ll_nvptx::HostEmitter.
Definition at line 342 of file ll.h.
References decls_, embed, func_decls_, func_impls_, loop_md_, LoopMdBase, MIM_LL_BE, mim::Emitter< std::string, std::string, BB, Emitter >::ostream(), rt_, rt_module_, rt_used_, mim::Phase::start(), type_decls_, and vars_decls_.
Referenced by mim::plug::ll_nvptx::DeviceEmitter::start(), and mim::plug::ll_nvptx::HostEmitter::start().
The heavy, target-independent emitter methods are compiled once into libmim_ll (see ll.cpp).
libmim_ll_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 1134 of file ll.cpp.
References Emitter(), MIM_EXPORT, and mim_ll_convert.
Referenced by Emitter(), and mim_ll_convert.
Definition at line 1139 of file ll.cpp.
References Emitter(), MIM_EXPORT, and mim_ll_emit_bb.
Referenced by Emitter(), and mim_ll_emit_bb.
Definition at line 1138 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 1137 of file ll.cpp.
References Emitter(), MIM_EXPORT, and mim_ll_finalize.
Referenced by Emitter(), and mim_ll_finalize.
|
protected |
|
protected |
Definition at line 231 of file ll.h.
Referenced by emit_imported(), and start().
|
protected |
Definition at line 232 of file ll.h.
Referenced by prepare(), mim::plug::ll_nvptx::DeviceEmitter::prepare(), and start().
|
staticconstexprprotected |
Loop-metadata node id per ll.vec-annotated loop header (see emit_epilogue_impl); numbered from LoopMdBase + 1 to stay clear of the ids the embedded runtime module brings along.
Definition at line 238 of file ll.h.
Referenced by start().
Definition at line 241 of file ll.h.
Referenced by declare_rt(), rt_mode(), and start().
|
protected |
Definition at line 243 of file ll.h.
Referenced by load_rt_module(), rt_module(), and start().
|
protected |
Definition at line 242 of file ll.h.
Referenced by declare_rt(), and start().
|
protected |
|
protected |
Definition at line 230 of file ll.h.
Referenced by mim::plug::ll_nvptx::DeviceEmitter::emit_slot(), mim::plug::ll_nvptx::DeviceEmitter::prepare(), start(), and mim::plug::ll_nvptx::HostEmitter::start().