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 with
10/// 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` bridge lowers to: widen each runtime `idxs#i : Idx (sin#i)` to `Idx 0` via `%core.conv.u`, apply
18/// the (now core-arithmetic) function `f`, and narrow each result back to its target `Idx (sout#j)` via `%core.conv.u`.
19///
20/// The division-based semiops (`ceildiv`, `floordiv`, `mod`) are not yet lowered (they require `%core.div`, which threads
21/// a `%mem.M`); they currently raise an error.
22class LowerIndex : public RWPhase {
23public:
26
27 const Def* rewrite(const Def*) final;
28 const Def* rewrite_imm_App(const App*) final;
29};
30
31} // namespace mim::plug::affine::phase
Base class for all Defs.
Definition def.h:246
RWPhase(World &world, std::string name, Analysis *analysis=nullptr)
Definition phase.h:194
World & world()=delete
Hides both and forbids direct access.
flags_t annex() const
Definition pass.h:81
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:24
const Def * rewrite_imm_App(const App *) final
const Def * rewrite(const Def *) final
u64 flags_t
Definition types.h:39