Jlm
Loading...
Searching...
No Matches
gamma.hpp
Go to the documentation of this file.
1/*
2 * Copyright 2010 2011 2012 2013 2014 Helge Bahmann <hcb@chaoticmind.net>
3 * Copyright 2013 2014 2016 Nico Reißmann <nico.reissmann@gmail.com>
4 * See COPYING for terms of redistribution.
5 */
6
7#ifndef JLM_RVSDG_GAMMA_HPP
8#define JLM_RVSDG_GAMMA_HPP
9
10#include <optional>
11
12#include <jlm/rvsdg/control.hpp>
14
15namespace jlm::rvsdg
16{
17
18class Output;
19class Type;
20
22{
23public:
24 ~GammaOperation() noexcept override;
25
29
31 size_t numAlternatives,
32 std::vector<std::shared_ptr<const Type>> matchContentTypes) noexcept
36 {}
37
38 inline size_t
43
44 [[nodiscard]] std::string
45 debug_string() const override;
46
47 [[nodiscard]] std::unique_ptr<Operation>
48 copy() const override;
49
50 bool
51 operator==(const Operation & other) const noexcept override;
52
56 [[nodiscard]] std::shared_ptr<const Type>
57 GetMatchContentType(std::size_t alternative) const;
58
59private:
61 std::vector<std::shared_ptr<const Type>> MatchContentTypes_;
62};
63
99{
100public:
102
103private:
105
106 GammaNode(
107 rvsdg::Output & predicate,
108 size_t nalternatives,
110
111public:
116 {
124 std::vector<rvsdg::Output *> matchContent;
125 };
126
130 struct EntryVar
131 {
139 std::vector<rvsdg::Output *> branchArgument;
140 };
141
145 struct ExitVar
146 {
150 std::vector<rvsdg::Input *> branchResult;
155 };
156
157 [[nodiscard]] const GammaOperation &
159
161 create(jlm::rvsdg::Output * predicate, size_t nalternatives)
162 {
163 return new GammaNode(*predicate, nalternatives, {});
164 }
165
166 static GammaNode &
169 size_t numAlternatives,
170 std::vector<std::shared_ptr<const Type>> matchContentTypes)
171 {
172 return *new GammaNode(predicate, numAlternatives, std::move(matchContentTypes));
173 }
174
175 static GammaNode &
176 Create(jlm::rvsdg::Output & predicate, std::unique_ptr<GammaOperation> op)
177 {
178 return *new GammaNode(predicate, std::move(op));
179 }
180
181 inline rvsdg::Input *
183
196 EntryVar
197 AddEntryVar(rvsdg::Output * origin);
198
199 MatchVar
201
205 std::vector<EntryVar>
207
225 std::variant<MatchVar, EntryVar>
226 MapInput(const rvsdg::Input & input) const;
227
245 std::variant<MatchVar, EntryVar>
247
264 const rvsdg::Input &
266
283 Input &
285
299 ExitVar
300 AddExitVar(const std::vector<rvsdg::Output *> & values);
301
305 std::vector<ExitVar>
307
316 std::vector<Output *>
318 {
319 std::vector<Output *> outputs;
320 for (auto & output : Outputs())
321 {
322 if (match(output))
323 {
324 outputs.push_back(&output);
325 }
326 }
327
328 return outputs;
329 }
330
347 ExitVar
349
365 ExitVar
367
380 const Output &
381 mapBranchResultToOutput(const Input & input) const;
382
395 Output &
397
409 void
410 RemoveExitVars(const std::vector<Output *> & gammaOutputs);
411
421 void
422 RemoveEntryVars(const std::vector<EntryVar> & entryVars);
423
429 void
431 {
433 [](const Output & output)
434 {
435 return output.IsDead();
436 });
438 }
439
440 GammaNode *
442
443private:
456 EntryVar
457 GetEntryVar(std::size_t index) const;
458
459 std::unique_ptr<GammaOperation> Operation_;
460};
461
481std::optional<rvsdg::Output *>
483
484/* gamma node method definitions */
485
486inline rvsdg::Input *
491
511bool
513
539bool
541
564bool
566
567}
568
569#endif
Conditional operator / pattern matching.
Definition gamma.hpp:99
void RemoveEntryVars(const std::vector< EntryVar > &entryVars)
Removes the given entry variables.
Definition gamma.cpp:459
const GammaOperation & GetOperation() const noexcept override
Definition gamma.cpp:254
ExitVar MapOutputExitVar(const rvsdg::Output &output) const
Maps gamma output to exit variable description.
Definition gamma.cpp:397
const rvsdg::Input & mapBranchArgumentToInput(const rvsdg::Output &output) const
Maps branch subregion entry argument to its corresponding gamma input.
Definition gamma.cpp:344
static GammaNode & Create(jlm::rvsdg::Output &predicate, std::unique_ptr< GammaOperation > op)
Definition gamma.hpp:176
std::unique_ptr< GammaOperation > Operation_
Definition gamma.hpp:459
std::variant< MatchVar, EntryVar > MapInput(const rvsdg::Input &input) const
Maps gamma input to its role (match variable or entry variable).
Definition gamma.cpp:316
GammaNode * copy(jlm::rvsdg::Region *region, SubstitutionMap &smap) const override
Copy a node with substitutions.
Definition gamma.cpp:478
EntryVar AddEntryVar(rvsdg::Output *origin)
Routes a variable into the gamma branches.
Definition gamma.cpp:260
EntryVar GetEntryVar(std::size_t index) const
Gets entry variable by index.
Definition gamma.cpp:278
static GammaNode * create(jlm::rvsdg::Output *predicate, size_t nalternatives)
Definition gamma.hpp:161
std::variant< MatchVar, EntryVar > MapBranchArgument(const rvsdg::Output &output) const
Maps branch subregion entry argument to its role (pattern match or entry variable).
Definition gamma.cpp:330
std::vector< ExitVar > GetExitVars() const
Gets all exit variables for this gamma.
Definition gamma.cpp:381
static GammaNode & Create(jlm::rvsdg::Output &predicate, size_t numAlternatives, std::vector< std::shared_ptr< const Type > > matchContentTypes)
Definition gamma.hpp:167
const Output & mapBranchResultToOutput(const Input &input) const
Maps branch subregion exit result to its corresponding gamma output.
Definition gamma.cpp:421
std::vector< EntryVar > GetEntryVars() const
Gets all entry variables for this gamma.
Definition gamma.cpp:305
void RemoveExitVars(const std::vector< Output * > &gammaOutputs)
Removes the exit variables corresponding to the given gammaOutputs.
Definition gamma.cpp:439
ExitVar MapBranchResultExitVar(const rvsdg::Input &input) const
Maps gamma region exit result to exit variable description.
Definition gamma.cpp:409
rvsdg::Input * predicate() const noexcept
Definition gamma.hpp:487
~GammaNode() noexcept override
ExitVar AddExitVar(const std::vector< rvsdg::Output * > &values)
Routes per-branch result of gamma to output.
Definition gamma.cpp:362
MatchVar GetMatchVar() const
Definition gamma.cpp:292
std::vector< Output * > GetOutputsWhere(const F &match)
Gets all gamma outputs that match the condition defined by match.
Definition gamma.hpp:317
std::shared_ptr< const Type > GetMatchContentType(std::size_t alternative) const
Returns the type of pattern matching content produced in a branch.
Definition gamma.cpp:218
std::unique_ptr< Operation > copy() const override
Definition gamma.cpp:205
GammaOperation(size_t numAlternatives) noexcept
Definition gamma.hpp:26
bool operator==(const Operation &other) const noexcept override
Definition gamma.cpp:211
GammaOperation(size_t numAlternatives, std::vector< std::shared_ptr< const Type > > matchContentTypes) noexcept
Definition gamma.hpp:30
std::vector< std::shared_ptr< const Type > > MatchContentTypes_
Definition gamma.hpp:61
std::string debug_string() const override
Definition gamma.cpp:199
~GammaOperation() noexcept override
Definition gamma.cpp:195
size_t nalternatives() const noexcept
Definition gamma.hpp:39
OutputIteratorRange Outputs() noexcept
Definition node.hpp:657
rvsdg::Region * region() const noexcept
Definition node.hpp:761
bool IsDead() const noexcept
Definition node.hpp:295
Represent acyclic RVSDG subgraphs.
Definition region.hpp:213
StructuralOutput * output(size_t index) const noexcept
StructuralInput * input(size_t index) const noexcept
bool ReduceGammaControlConstant(Node &node)
Definition gamma.cpp:171
bool ReduceGammaWithStaticallyKnownPredicate(Node &node)
Definition gamma.cpp:158
static std::vector< jlm::rvsdg::Output * > outputs(const Node *node)
Definition node.hpp:1058
NodeType * TryGetOwnerNode(const rvsdg::Input &input) noexcept
Checks if this is an input to a node of specified type.
Definition node.hpp:872
std::optional< rvsdg::Output * > GetGammaInvariantOrigin(const GammaNode &gamma, const GammaNode::ExitVar &exitvar)
Determines whether a gamma exit var is path-invariant.
Definition gamma.cpp:509
bool ReduceGammaInvariantVariables(Node &node)
Definition gamma.cpp:186
A variable routed into all gamma regions.
Definition gamma.hpp:131
rvsdg::Input * input
Variable at entry point (input to gamma node).
Definition gamma.hpp:135
std::vector< rvsdg::Output * > branchArgument
Variable inside each of the branch regions (argument per subregion).
Definition gamma.hpp:139
A variable routed out of all gamma regions as result.
Definition gamma.hpp:146
rvsdg::Output * output
Output of gamma.
Definition gamma.hpp:154
std::vector< rvsdg::Input * > branchResult
Variable exit points (results per subregion).
Definition gamma.hpp:150
The match/discriminator variable of this gamma node.
Definition gamma.hpp:116
rvsdg::Input * input
The variable matched over (i.e. the "selector" of the gamma branch).
Definition gamma.hpp:120
std::vector< rvsdg::Output * > matchContent
The content of the match per branch.
Definition gamma.hpp:124