Jlm
Loading...
Searching...
No Matches
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
17namespace jlm::rvsdg
18{
19
21{
22public:
24
25 [[nodiscard]] std::string
27
30};
31
33{
34public:
36
38 explicit ThetaNode(rvsdg::Region & parent);
39
40public:
68
79
80 [[nodiscard]] const ThetaOperation &
81 GetOperation() const noexcept override;
82
84 create(rvsdg::Region * parent)
85 {
86 return new ThetaNode(*parent);
87 }
88
94
97 {
98 auto result = subregion()->result(0);
99 JLM_ASSERT(is<const ControlType>(result->Type()));
100 return result;
101 }
102
103 inline void
105 {
106 auto node = TryGetOwnerNode<Node>(*predicate()->origin());
107
108 predicate()->divert_to(p);
109 if (node && node->IsDead())
110 remove(node);
111 }
112
128 LoopVar
129 AddLoopVar(rvsdg::Output * origin);
130
149 void
150 RemoveLoopVars(std::vector<LoopVar> loopVars);
151
152 ThetaNode *
153 copy(rvsdg::Region * region, rvsdg::SubstitutionMap & smap) const override;
154
170 [[nodiscard]] LoopVar
171 MapInputLoopVar(const rvsdg::Input & input) const;
172
188 [[nodiscard]] LoopVar
189 MapPreLoopVar(const rvsdg::Output & argument) const;
190
206 [[nodiscard]] LoopVar
207 MapPostLoopVar(const rvsdg::Input & result) const;
208
224 [[nodiscard]] std::variant<LoopVar, PredicateVar>
225 mapResult(const rvsdg::Input & result) const;
226
242 [[nodiscard]] LoopVar
243 MapOutputLoopVar(const rvsdg::Output & output) const;
244
251 [[nodiscard]] std::vector<LoopVar>
252 GetLoopVars() const;
253
261 static bool
262 reduceStaticallyKnownPredicate(Node & node);
263};
264
265static inline bool
267{
268 return loopVar.post->origin() == loopVar.pre;
269}
270
271}
272
273#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
rvsdg::Region * subregion() const noexcept
Definition theta.hpp:90
void set_predicate(jlm::rvsdg::Output *p)
Definition theta.hpp:104
RegionResult * predicate() const noexcept
Definition theta.hpp:96
~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:266
static void remove(Node *node)
Definition region.hpp:1035
NodeType * TryGetOwnerNode(const rvsdg::Input &input) noexcept
Checks if this is an input to a node of specified type.
Definition node.hpp:872
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
Description of the loop predicate variable.
Definition theta.hpp:73
rvsdg::Input * predicate
Use of the predicate variable at end of loop.
Definition theta.hpp:77