MimIR
0.4-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
lower_index.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <
mim/phase.h
>
4
5
namespace
mim::plug::affine::phase
{
6
7
/// Lowers the affine index algebra to core arithmetic.
8
///
9
/// The opaque affine.Index type is rewritten to the wide `Idx 0` (i64) carrier, and the index operations are computed
10
/// with wrap-around (`core.Mode::none`) arithmetic, so negation/subtraction are correct via two's complement:
11
/// * `affine.lit n` ↦ `n` reinterpreted as an `Idx 0`,
12
/// * `affine.op.add (a, b)` ↦ `core.wrap.add none (a, b)`,
13
/// * `affine.op.sub (a, b)` ↦ `core.wrap.sub none (a, b)`,
14
/// * `affine.op.neg a` ↦ `core.wrap.sub none (0, a)`,
15
/// * `affine.semiop.mul (a, c)` ↦ `core.wrap.mul none (a, c)`.
16
///
17
/// The `affine.map f idxs mem` bridge lowers to: widen each runtime `idxs#i : Idx (sin#i)` to `Idx 0` via
18
/// `core.conv.u`, apply the (now core-arithmetic) function `f`, and
19
/// narrow each result back to its target `Idx (sout#j)` via `core.conv.u`.
20
///
21
/// The division-based semiops (`ceildiv`, `floordiv`, `mod`) lower to `core.div`, which threads a `mem.M`. The mem is
22
/// taken from the enclosing `affine.map`'s mem operand (tracked in #mem_), advanced through the div chain, and
23
/// returned alongside the result.
24
class
LowerIndex
:
public
RWPhase
{
25
public
:
26
LowerIndex
(
World
&
world
,
flags_t
annex
)
27
:
RWPhase
(
world
,
annex
) {}
28
29
const
Def
*
rewrite
(
const
Def
*)
final
;
30
const
Def
*
rewrite_imm_App
(
const
App
*)
final
;
31
32
private
:
33
const
Def
* mem_ =
nullptr
;
///< The current mem while lowering the body of a `affine.map`
34
};
35
36
}
// namespace mim::plug::affine::phase
mim::App
Definition
lam.h:224
mim::Def
Base class for all Defs.
Definition
def.h:273
mim::Phase::annex
flags_t annex() const
Definition
phase.h:81
mim::RWPhase::RWPhase
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition
phase.h:431
mim::RWPhase::world
World & world()=delete
Hides both and forbids direct access.
mim::World
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition
world.h:40
mim::plug::affine::phase::LowerIndex::LowerIndex
LowerIndex(World &world, flags_t annex)
Definition
lower_index.h:26
mim::plug::affine::phase::LowerIndex::rewrite_imm_App
const Def * rewrite_imm_App(const App *) final
Definition
lower_index.cpp:21
mim::plug::affine::phase::LowerIndex::rewrite
const Def * rewrite(const Def *) final
Definition
lower_index.cpp:15
mim::plug::affine::phase
Definition
lower_for.h:5
mim::flags_t
u64 flags_t
Definition
types.h:39
phase.h
include
mim
plug
affine
phase
lower_index.h
Generated by
1.18.0