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#include <mim/pass/pass.h>
5
6namespace mim::plug::affine {
7
8/// Lowers the for axiom to actual control flow in CPS.
9/// It basically mimics this implementation:
10/// ```
11/// .con %affine.For_impl
12/// (m: .Nat , n: .Nat , Ts: «n; *»)
13/// (begin: .Idx m, end: .Idx m, step: .Idx m, init: «i: n; Ts#i»,
14/// body: .Cn [iter: .Idx m, acc: «i: n; Ts#i», yield: .Cn [«i: n; Ts#i»]],
15/// exit: .Cn [«i: n; Ts#i»]
16/// ) =
17/// .con head(iter: .Idx m, acc: «i: n; Ts#i») =
18/// .con new_body() = body (iter, acc, .cn acc: «i: n; Ts#i» =
19/// .let iter2 = %core.wrap.add %core.mode.nsuw (iter, step);
20/// head (iter2, acc));
21/// .con new_exit() = exit (acc);
22/// (new_exit, new_body)#(%core.icmp.ul (iter, end)) ();
23/// head(begin, init);
24/// ```
25/// However, we merge `init`/`acc` into the signature, as it may contain a `mem`.
26/// In this case we have to equip `new_body`/`new_exit` with a `mem` as well.
27/// @todo We probably want to have phases which fix such things so we don't have to do this in C++.
28class LowerFor : public RWPass<LowerFor, Lam> {
29public:
31 : RWPass(man, "lower_affine_for") {}
32
33 Ref rewrite(Ref) override;
34
35private:
36 Def2Def rewritten_;
37};
38
39} // 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:85
Lowers the for axiom to actual control flow in CPS.
Definition lower_for.h:28
Ref rewrite(Ref) override
Definition lower_for.cpp:32
The affine Plugin
Definition affine.h:7
DefMap< const Def * > Def2Def
Definition def.h:59