Jlm
theta.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2012 2013 2014 Helge Bahmann <hcb@chaoticmind.net>
3  * Copyright 2013 2014 Nico Reißmann <nico.reissmann@gmail.com>
4  * See COPYING for terms of redistribution.
5  */
6 
7 #ifndef JLM_RVSDG_THETA_HPP
8 #define JLM_RVSDG_THETA_HPP
9 
10 #include <jlm/rvsdg/control.hpp>
11 #include <jlm/rvsdg/region.hpp>
13 #include <jlm/util/HashSet.hpp>
14 
15 #include <optional>
16 
17 namespace jlm::rvsdg
18 {
19 
20 class ThetaOperation final : public StructuralOperation
21 {
22 public:
23  ~ThetaOperation() noexcept override;
24 
25  [[nodiscard]] std::string
26  debug_string() const override;
27 
28  [[nodiscard]] std::unique_ptr<Operation>
29  copy() const override;
30 };
31 
32 class ThetaNode final : public StructuralNode
33 {
34 public:
35  ~ThetaNode() noexcept override;
36 
37 private:
38  explicit ThetaNode(rvsdg::Region & parent);
39 
40 public:
49  struct LoopVar
50  {
67  };
68 
69  [[nodiscard]] const ThetaOperation &
70  GetOperation() const noexcept override;
71 
72  static ThetaNode *
73  create(rvsdg::Region * parent)
74  {
75  return new ThetaNode(*parent);
76  }
77 
78  [[nodiscard]] rvsdg::Region *
79  subregion() const noexcept
80  {
81  return StructuralNode::subregion(0);
82  }
83 
84  [[nodiscard]] RegionResult *
85  predicate() const noexcept
86  {
87  auto result = subregion()->result(0);
88  JLM_ASSERT(is<const ControlType>(result->Type()));
89  return result;
90  }
91 
92  inline void
94  {
95  auto node = TryGetOwnerNode<Node>(*predicate()->origin());
96 
97  predicate()->divert_to(p);
98  if (node && node->IsDead())
99  remove(node);
100  }
101 
117  LoopVar
118  AddLoopVar(rvsdg::Output * origin);
119 
138  void
139  RemoveLoopVars(std::vector<LoopVar> loopVars);
140 
141  ThetaNode *
142  copy(rvsdg::Region * region, rvsdg::SubstitutionMap & smap) const override;
143 
159  [[nodiscard]] LoopVar
160  MapInputLoopVar(const rvsdg::Input & input) const;
161 
177  [[nodiscard]] LoopVar
178  MapPreLoopVar(const rvsdg::Output & argument) const;
179 
195  [[nodiscard]] LoopVar
196  MapPostLoopVar(const rvsdg::Input & result) const;
197 
213  [[nodiscard]] LoopVar
214  MapOutputLoopVar(const rvsdg::Output & output) const;
215 
222  [[nodiscard]] std::vector<LoopVar>
223  GetLoopVars() const;
224 };
225 
226 static inline bool
228 {
229  return loopVar.post->origin() == loopVar.pre;
230 }
231 
232 }
233 
234 #endif
Represents the result of a region.
Definition: region.hpp:120
Represent acyclic RVSDG subgraphs.
Definition: region.hpp:213
rvsdg::Region * subregion(size_t index) const noexcept
RegionResult * predicate() const noexcept
Definition: theta.hpp:85
rvsdg::Region * subregion() const noexcept
Definition: theta.hpp:79
void set_predicate(jlm::rvsdg::Output *p)
Definition: theta.hpp:93
~ThetaNode() noexcept override
std::unique_ptr< Operation > copy() const override
Definition: theta.cpp:25
~ThetaOperation() noexcept override
std::string debug_string() const override
Definition: theta.cpp:19
#define JLM_ASSERT(x)
Definition: common.hpp:16
static bool ThetaLoopVarIsInvariant(const ThetaNode::LoopVar &loopVar) noexcept
Definition: theta.hpp:227
static void remove(Node *node)
Definition: region.hpp:932
Description of a loop-carried variable.
Definition: theta.hpp:50
rvsdg::Output * pre
Variable before iteration (input argument to subregion).
Definition: theta.hpp:58
rvsdg::Output * output
Variable at loop exit (output of theta).
Definition: theta.hpp:66
rvsdg::Input * input
Variable at loop entry (input to theta).
Definition: theta.hpp:54
rvsdg::Input * post
Variable after iteration (output result from subregion).
Definition: theta.hpp:62