Jlm
Loading...
Searching...
No Matches
LoopUnswitching.hpp
Go to the documentation of this file.
1/*
2 * Copyright 2017 Nico Reißmann <nico.reissmann@gmail.com>
3 * See COPYING for terms of redistribution.
4 */
5
6#ifndef JLM_LLVM_OPT_LOOPUNSWITCHING_HPP
7#define JLM_LLVM_OPT_LOOPUNSWITCHING_HPP
8
10
11namespace jlm::rvsdg
12{
13class GammaNode;
14class Node;
15class Region;
16class SubstitutionMap;
17class ThetaNode;
18}
19
20namespace jlm::llvm
21{
22
23class ThetaGammaPredicateCorrelation;
24
30{
31public:
32 virtual ~LoopUnswitchingHeuristic() noexcept;
33
34 virtual bool
35 shouldUnswitchLoop(ThetaGammaPredicateCorrelation & correlation) const noexcept = 0;
36};
37
45{
46public:
48
49 bool
50 shouldUnswitchLoop(ThetaGammaPredicateCorrelation & correlation) const noexcept override;
51
52 static std::shared_ptr<const LoopUnswitchingDefaultHeuristic>
53 create();
54};
55
107class LoopUnswitching final : public rvsdg::Transformation
108{
109public:
110 class Statistics;
111
112 ~LoopUnswitching() noexcept override;
113
114 explicit LoopUnswitching(std::shared_ptr<const LoopUnswitchingHeuristic> heuristic)
115 : Transformation("LoopUnswitching"),
116 heuristic_(std::move(heuristic))
117 {}
118
119 void
121
122 static void
123 CreateAndRun(
124 rvsdg::RvsdgModule & rvsdgModule,
126 std::shared_ptr<const LoopUnswitchingHeuristic> heuristic);
127
128private:
129 void
130 HandleRegion(rvsdg::Region & region);
131
132 bool
133 UnswitchLoop(rvsdg::ThetaNode & thetaNode);
134
135 static rvsdg::GammaNode *
136 IsUnswitchable(const rvsdg::ThetaNode & thetaNode);
137
138 static void
139 SinkNodesIntoGamma(rvsdg::GammaNode & gammaNode, const rvsdg::ThetaNode & thetaNode);
140
141 static std::vector<std::vector<rvsdg::Node *>>
142 CollectPredicateNodes(const rvsdg::ThetaNode & thetaNode, const rvsdg::GammaNode & gammaNode);
143
144 static void
145 CopyPredicateNodes(
146 rvsdg::Region & target,
147 rvsdg::SubstitutionMap & substitutionMap,
148 const std::vector<std::vector<rvsdg::Node *>> & nodes);
149
157 static bool
158 allLoopVarsAreRoutedThroughGamma(
159 const rvsdg::ThetaNode & thetaNode,
160 const rvsdg::GammaNode & gammaNode);
161
162 std::shared_ptr<const LoopUnswitchingHeuristic> heuristic_;
163};
164
165}
166
167#endif
static jlm::util::StatisticsCollector statisticsCollector
std::vector< rvsdg::Node * > nodes
~LoopUnswitchingDefaultHeuristic() noexcept override
virtual bool shouldUnswitchLoop(ThetaGammaPredicateCorrelation &correlation) const noexcept=0
virtual ~LoopUnswitchingHeuristic() noexcept
std::shared_ptr< const LoopUnswitchingHeuristic > heuristic_
~LoopUnswitching() noexcept override
Conditional operator / pattern matching.
Definition gamma.hpp:99
Represent acyclic RVSDG subgraphs.
Definition region.hpp:213
Global memory state passed between functions.