MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
lower_for.h
Go to the documentation of this file.
1#pragma once
2
3#include <mim/def.h>
4
5#include <mim/pass/pass.h>
6
7namespace mim::plug::affine {
8
9/// Lowers the for axiom to actual control flow in CPS.
10/// It basically mimics this implementation:
11/// ```
12/// con %affine.For_impl
13/// (m: Nat , n: Nat , Ts: «n; *»)
14/// (begin: Idx m, end: Idx m, step: Idx m, init: «i: n; Ts#i»,
15/// body: Cn [iter: Idx m, acc: «i: n; Ts#i», yield: Cn [«i: n; Ts#i»]],
16/// exit: Cn [«i: n; Ts#i»]
17/// ) =
18/// con head(iter: Idx m, acc: «i: n; Ts#i») =
19/// con new_body() = body (iter, acc, cn acc: «i: n; Ts#i» =
20/// let iter2 = %core.wrap.add %core.mode.nsuw (iter, step);
21/// head (iter2, acc));
22/// con new_exit() = exit (acc);
23/// (new_exit, new_body)#(%core.icmp.ul (iter, end)) ();
24/// head(begin, init);
25/// ```
26/// However, we merge `init`/`acc` into the signature, as it may contain a `mem`.
27/// In this case we have to equip `new_body`/`new_exit` with a `mem` as well.
28/// @todo We probably want to have phases which fix such things so we don't have to do this in C++.
29class LowerFor : public RWPass<LowerFor, Lam> {
30public:
32 : RWPass(man, "lower_affine_for") {}
33
34 Ref rewrite(Ref) override;
35
36private:
37 Def2Def rewritten_;
38};
39
40} // namespace mim::plug::affine
An optimizer that combines several optimizations in an optimal way.
Definition pass.h:107
PassMan & man()
Definition pass.h:30
Inherit from this class using CRTP, if your Pass does not need state and a fixed-point iteration.
Definition pass.h:220
Helper class to retrieve Infer::arg if present.
Definition def.h:86
Lowers the for axiom to actual control flow in CPS.
Definition lower_for.h:29
Ref rewrite(Ref) override
Definition lower_for.cpp:32
The affine Plugin
Definition affine.h:7
DefMap< const Def * > Def2Def
Definition def.h:60