llir-opt  0.0.1
Low-Level Post-Link Optimiser for OCaml and C
live_variables.h
1 // This file if part of the llir-opt project.
2 // Licensing information can be found in the LICENSE file.
3 // (C) 2018 Nandor Licker. All rights reserved.
4 
5 #pragma once
6 
7 #include <set>
8 #include <unordered_set>
9 #include <vector>
10 
11 #include "core/inst.h"
12 #include "core/analysis/loop_nesting.h"
13 
14 class Block;
15 class Func;
16 class Inst;
17 
18 
19 
23 class LiveVariables final {
24 public:
28  LiveVariables(const Func *func);
29 
34 
38  std::vector<ConstRef<Inst>> LiveOut(const Inst *inst);
39 
40 private:
41  using InstSet = std::unordered_set<ConstRef<Inst>>;
42 
44  void TraverseDAG(const Block *block);
46  void TraverseNode(const Block *block);
48  void TraverseLoop(LoopNesting::Loop *loop);
50  void KillDef(InstSet &live, const Inst *inst);
51 
52 private:
54  LoopNesting loops_;
56  std::unordered_map
57  < const Block *
58  , std::pair<InstSet, InstSet>
59  > live_;
61  std::unordered_map
62  < const Inst *
63  , InstSet
64  > liveCache_;
66  const Block *liveBlock_ = nullptr;
67 };
Inst
Definition: inst.h:53
LiveVariables::LiveOut
std::vector< ConstRef< Inst > > LiveOut(const Inst *inst)
Definition: live_variables.cpp:30
Func
Definition: func.h:30
LoopNesting
Definition: loop_nesting.h:28
LiveVariables
Definition: live_variables.h:23
LiveVariables::LiveVariables
LiveVariables(const Func *func)
Definition: live_variables.cpp:14
LoopNesting::Loop
Structure representing a loop.
Definition: loop_nesting.h:31
Block
Definition: block.h:29
LiveVariables::~LiveVariables
~LiveVariables()
Definition: live_variables.cpp:24