MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
lower_index.h
Go to the documentation of this file.
1#pragma once
2
3#include <mim/phase.h>
4
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.constant 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.
24class LowerIndex : public RWPhase {
25public:
28
29 const Def* rewrite(const Def*) final;
30 const Def* rewrite_imm_App(const App*) final;
31
32private:
33 const Def* mem_ = nullptr; ///< The current mem while lowering the body of a `%affine.map`
34};
35
36} // namespace mim::plug::affine::phase
Base class for all Defs.
Definition def.h:261
flags_t annex() const
Definition phase.h:81
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition phase.h:316
World & world()=delete
Hides both and forbids direct access.
The World represents the whole program and manages creation of MimIR nodes (Defs).
Definition world.h:36
LowerIndex(World &world, flags_t annex)
Definition lower_index.h:26
const Def * rewrite_imm_App(const App *) final
const Def * rewrite(const Def *) final
u64 flags_t
Definition types.h:39