Jlm
PredicateCorrelation.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2025 Nico Reißmann <nico.reissmann@gmail.com>
3  * See COPYING for terms of redistribution.
4  */
5 
6 #ifndef JLM_LLVM_OPT_PREDICATECORRELATION_HPP
7 #define JLM_LLVM_OPT_PREDICATECORRELATION_HPP
8 
9 #include <jlm/rvsdg/gamma.hpp>
10 #include <jlm/rvsdg/theta.hpp>
12 
13 #include <optional>
14 #include <variant>
15 #include <vector>
16 
17 namespace jlm
18 {
19 
20 namespace rvsdg
21 {
22 class Region;
23 class ThetaNode;
24 }
25 
26 namespace util
27 {
28 class StatisticsCollector;
29 }
30 }
31 
32 namespace jlm::llvm
33 {
34 
38 enum class CorrelationType
39 {
44 
50 
56 };
57 
62 {
63 public:
65  {
67  };
68 
69  using CorrelationData = std::variant<MatchCorrelationData>;
70 
71 private:
73  const CorrelationType type,
77  : type_(type),
81  {}
82 
83 public:
84  [[nodiscard]] CorrelationType
85  type() const noexcept
86  {
87  return type_;
88  }
89 
90  [[nodiscard]] rvsdg::GammaNode &
91  gammaNode1() const noexcept
92  {
93  return gammaNode1_;
94  }
95 
96  [[nodiscard]] rvsdg::GammaNode &
97  gammaNode2() const noexcept
98  {
99  return gammaNode2_;
100  }
101 
102  [[nodiscard]] const CorrelationData &
103  correlationData() const noexcept
104  {
105  return correlationData_;
106  }
107 
108  static std::unique_ptr<GammaGammaPredicateCorrelation>
113  {
114  return std::unique_ptr<GammaGammaPredicateCorrelation>(new GammaGammaPredicateCorrelation(
116  gammaNode1,
117  gammaNode2,
118  std::move(correlationData)));
119  }
120 
121 private:
126 };
127 
128 std::optional<std::unique_ptr<GammaGammaPredicateCorrelation>>
130 
136 {
137 public:
138  using ControlConstantCorrelationData = std::vector<uint64_t>;
139 
141  {
143  std::vector<uint64_t> alternatives{};
144  };
145 
147  {
149  };
150 
151  using CorrelationData = std::
152  variant<ControlConstantCorrelationData, MatchConstantCorrelationData, MatchCorrelationData>;
153 
154 private:
156  const CorrelationType type,
159  CorrelationData correlationData)
160  : type_(type),
163  data_(std::move(correlationData))
164  {}
165 
166 public:
167  [[nodiscard]] CorrelationType
168  type() const noexcept
169  {
170  return type_;
171  }
172 
173  [[nodiscard]] rvsdg::ThetaNode &
174  thetaNode() const noexcept
175  {
176  return thetaNode_;
177  }
178 
179  [[nodiscard]] rvsdg::GammaNode &
180  gammaNode() const noexcept
181  {
182  return gammaNode_;
183  }
184 
185  [[nodiscard]] const CorrelationData &
186  data() const noexcept
187  {
188  return data_;
189  }
190 
191  static std::unique_ptr<ThetaGammaPredicateCorrelation>
196  {
197  return std::unique_ptr<ThetaGammaPredicateCorrelation>(new ThetaGammaPredicateCorrelation(
199  thetaNode,
200  gammaNode,
201  std::move(data)));
202  }
203 
204  static std::unique_ptr<ThetaGammaPredicateCorrelation>
209  {
210  return std::unique_ptr<ThetaGammaPredicateCorrelation>(new ThetaGammaPredicateCorrelation(
212  thetaNode,
213  gammaNode,
214  std::move(data)));
215  }
216 
217  static std::unique_ptr<ThetaGammaPredicateCorrelation>
222  {
223  return std::unique_ptr<ThetaGammaPredicateCorrelation>(new ThetaGammaPredicateCorrelation(
225  thetaNode,
226  gammaNode,
227  std::move(data)));
228  }
229 
230 private:
235 };
236 
243 std::optional<std::unique_ptr<ThetaGammaPredicateCorrelation>>
245 
246 typedef struct
247 {
251 
259 std::optional<GammaSubregionRoles>
261 
271 {
272 public:
273  ~PredicateCorrelation() noexcept override;
274 
277  {}
278 
280 
282  operator=(const PredicateCorrelation &) = delete;
283 
284  void
285  Run(rvsdg::RvsdgModule & rvsdgModule, util::StatisticsCollector & statisticsCollector) override;
286 
287 private:
288  static void
290 
296  static void
298 
299  static bool
301 
302  static bool
304 };
305 
306 }
307 
308 #endif
rvsdg::GammaNode & gammaNode1() const noexcept
GammaGammaPredicateCorrelation(const CorrelationType type, rvsdg::GammaNode &gammaNode1, rvsdg::GammaNode &gammaNode2, CorrelationData correlationData)
rvsdg::GammaNode & gammaNode2() const noexcept
static std::unique_ptr< GammaGammaPredicateCorrelation > CreateMatchCorrelation(rvsdg::GammaNode &gammaNode1, rvsdg::GammaNode &gammaNode2, MatchCorrelationData correlationData)
const CorrelationData & correlationData() const noexcept
std::variant< MatchCorrelationData > CorrelationData
static bool handleMatchConstantCorrelation(const ThetaGammaPredicateCorrelation &correlation)
static void correlatePredicatesInRegion(rvsdg::Region &region)
PredicateCorrelation(const PredicateCorrelation &)=delete
PredicateCorrelation & operator=(const PredicateCorrelation &)=delete
void Run(rvsdg::RvsdgModule &rvsdgModule, util::StatisticsCollector &statisticsCollector) override
Perform RVSDG transformation.
static bool handleControlConstantCorrelation(const ThetaGammaPredicateCorrelation &correlation)
static void correlatePredicatesInTheta(rvsdg::ThetaNode &thetaNode)
~PredicateCorrelation() noexcept override
const CorrelationData & data() const noexcept
rvsdg::GammaNode & gammaNode() const noexcept
static std::unique_ptr< ThetaGammaPredicateCorrelation > CreateControlConstantCorrelation(rvsdg::ThetaNode &thetaNode, rvsdg::GammaNode &gammaNode, ControlConstantCorrelationData data)
rvsdg::ThetaNode & thetaNode() const noexcept
static std::unique_ptr< ThetaGammaPredicateCorrelation > CreateMatchConstantCorrelation(rvsdg::ThetaNode &thetaNode, rvsdg::GammaNode &gammaNode, MatchConstantCorrelationData data)
ThetaGammaPredicateCorrelation(const CorrelationType type, rvsdg::ThetaNode &thetaNode, rvsdg::GammaNode &gammaNode, CorrelationData correlationData)
std::variant< ControlConstantCorrelationData, MatchConstantCorrelationData, MatchCorrelationData > CorrelationData
static std::unique_ptr< ThetaGammaPredicateCorrelation > CreateMatchCorrelation(rvsdg::ThetaNode &thetaNode, rvsdg::GammaNode &gammaNode, MatchCorrelationData data)
Conditional operator / pattern matching.
Definition: gamma.hpp:99
Represent acyclic RVSDG subgraphs.
Definition: region.hpp:213
Represents an RVSDG transformation.
Transformation(std::string_view Name)
Global memory state passed between functions.
std::optional< std::unique_ptr< ThetaGammaPredicateCorrelation > > computeThetaGammaPredicateCorrelation(rvsdg::ThetaNode &thetaNode)
std::optional< std::unique_ptr< GammaGammaPredicateCorrelation > > computeGammaGammaPredicateCorrelation(rvsdg::GammaNode &gammaNode)
std::optional< GammaSubregionRoles > determineGammaSubregionRoles(const ThetaGammaPredicateCorrelation &correlation)