MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
gpu.cpp
Go to the documentation of this file.
1#include "mim/plug/gpu/gpu.h"
2
3#include <mim/config.h>
4#include <mim/pass.h>
5#include <mim/phase.h>
6#include <mim/plugin.h>
7
8#include <mim/plug/mem/mem.h>
9
10using namespace mim;
11using namespace mim::plug;
12
13// TODO: decide whether gpu::alloc -> mem::alloc or mem::malloc -> gpu::alloc makes more sense
14void reg_stages(Flags2Stages& stages) {
16 if (auto malloc = Axm::isa<mem::malloc>(def)) {
17 auto [type, addr_space] = malloc->decurry()->args<2>();
18 if (Axm::isa<gpu::addr_space_global>(addr_space)) {
19 auto [mem, _] = malloc->args<2>();
20 World& w = type->world();
21 return w.app(w.app(w.annex<gpu::alloc>(), type), mem);
22 }
23 } else if (auto free = Axm::isa<mem::free>(def)) {
24 auto [type, addr_space] = free->decurry()->args<2>();
25 if (Axm::isa<gpu::addr_space_global>(addr_space)) {
26 auto [mem, ptr] = free->args<2>();
27 World& w = type->world();
28 return w.app(w.app(w.annex<gpu::free>(), type), {mem, ptr});
29 }
30 }
31 return {};
32 });
33}
34
35extern "C" MIM_EXPORT Plugin mim_get_plugin() { return {"gpu", nullptr, reg_stages, nullptr}; }
void reg_stages(Flags2Stages &stages)
Definition affine.cpp:11
static auto isa(const Def *def)
Definition axm.h:107
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition world.h:31
#define MIM_EXPORT
Definition config.h:17
void reg_stages(Flags2Stages &stages)
Definition gpu.cpp:14
The mem Plugin
Definition mem.h:11
Definition ast.h:14
absl::flat_hash_map< flags_t, std::function< std::unique_ptr< Stage >(World &)> > Flags2Stages
Maps an an axiom of a Stage to a function that creates one.
Definition plugin.h:22
mim::Plugin mim_get_plugin()
#define MIM_REPL(__stages, __annex,...)
Definition phase.h:188
Basic info and registration function pointer to be returned from a specific plugin.
Definition plugin.h:30