MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
schedule.h
Go to the documentation of this file.
1#pragma once
2
3#include "mim/analyses/cfg.h"
4
5namespace mim {
6
7template<bool> class DomTreeBase;
9
10class Scheduler {
11public:
12 /// @name Construction
13 ///@{
14 Scheduler() = default;
15 explicit Scheduler(const Scope&);
16 Scheduler(const Scheduler&) = delete;
17 Scheduler(Scheduler&& other) noexcept
18 : Scheduler() {
19 swap(*this, other);
20 }
21 Scheduler& operator=(Scheduler other) noexcept { return swap(*this, other), *this; }
22 ///@}
23
24 /// @name Getters
25 ///@{
26 const Scope& scope() const { return *scope_; }
27 const F_CFG& cfg() const { return *cfg_; }
28 const CFNode* cfg(Def* mut) const { return cfg()[mut]; }
29 const DomTree& domtree() const { return *domtree_; }
30 const Uses& uses(const Def* def) const {
31 auto i = def2uses_.find(def);
32 assert(i != def2uses_.end());
33 return i->second;
34 }
35 ///@}
36
37 /// @name Compute Schedules
38 ///@{
39 Def* early(const Def*);
40 Def* late(const Def*);
41 Def* smart(const Def*);
42 ///@}
43
44 /// @name Schedule Mutabales
45 /// Order of Mutables within a Scope.
46 ///@{
47 using Schedule = std::vector<Def*>;
48 static Schedule schedule(const Scope&);
49 ///@}
50
51 friend void swap(Scheduler& s1, Scheduler& s2) noexcept {
52 using std::swap;
53 swap(s1.scope_, s2.scope_);
54 swap(s1.cfg_, s2.cfg_);
55 swap(s1.domtree_, s2.domtree_);
56 swap(s1.early_, s2.early_);
57 swap(s1.late_, s2.late_);
58 swap(s1.smart_, s2.smart_);
59 swap(s1.def2uses_, s2.def2uses_);
60 }
61
62private:
63 const Scope* scope_ = nullptr;
64 const F_CFG* cfg_ = nullptr;
65 const DomTree* domtree_ = nullptr;
66 DefMap<Def*> early_;
67 DefMap<Def*> late_;
68 DefMap<Def*> smart_;
69 DefMap<Uses> def2uses_;
70};
71
72} // namespace mim
A Control-Flow Graph.
Definition scope.h:8
A Control-Flow Node.
Definition cfg.h:27
Base class for all Defs.
Definition def.h:223
A Dominance Tree.
Definition schedule.h:7
const F_CFG & cfg() const
Definition schedule.h:27
Scheduler(Scheduler &&other) noexcept
Definition schedule.h:17
const CFNode * cfg(Def *mut) const
Definition schedule.h:28
Scheduler(const Scheduler &)=delete
Def * smart(const Def *)
Definition schedule.cpp:84
const DomTree & domtree() const
Definition schedule.h:29
static Schedule schedule(const Scope &)
Definition schedule.cpp:112
Scheduler & operator=(Scheduler other) noexcept
Definition schedule.h:21
Def * early(const Def *)
Definition schedule.cpp:49
const Uses & uses(const Def *def) const
Definition schedule.h:30
Def * late(const Def *)
Definition schedule.cpp:65
friend void swap(Scheduler &s1, Scheduler &s2) noexcept
Definition schedule.h:51
Scheduler()=default
std::vector< Def * > Schedule
Definition schedule.h:47
const Scope & scope() const
Definition schedule.h:26
A Scope represents a region of Defs that are live from the view of an entry's Var.
Definition scope.h:20
Definition cfg.h:11
GIDMap< const Def *, To > DefMap
Definition def.h:58
absl::flat_hash_set< Use, UseHash, UseEq > Uses
Definition def.h:136