Jlm
reduction.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Nico Reißmann <nico.reissmann@gmail.com>
3  * See COPYING for terms of redistribution.
4  */
5 
6 #ifndef JLM_LLVM_OPT_REDUCTION_HPP
7 #define JLM_LLVM_OPT_REDUCTION_HPP
8 
11 #include <jlm/util/Statistics.hpp>
12 
13 #include <optional>
14 
15 namespace jlm::rvsdg
16 {
17 class Graph;
18 class Node;
19 class Region;
20 class Output;
21 class StructuralNode;
22 }
23 
24 namespace jlm::llvm
25 {
26 
27 class CallExitMemoryStateSplitOperation;
28 class LambdaEntryMemoryStateSplitOperation;
29 class LambdaExitMemoryStateMergeOperation;
30 class LoadNonVolatileOperation;
31 class MemoryStateJoinOperation;
32 class MemoryStateMergeOperation;
33 class MemoryStateSplitOperation;
34 class StoreNonVolatileOperation;
35 
42 {
43 public:
44  class Statistics;
45 
46  ~NodeReduction() noexcept override;
47 
48  NodeReduction();
49 
50  NodeReduction(const NodeReduction &) = delete;
51 
53 
55  operator=(const NodeReduction &) = delete;
56 
58  operator=(NodeReduction &&) = delete;
59 
60  void
61  Run(rvsdg::RvsdgModule & rvsdgModule, util::StatisticsCollector & statisticsCollector) override;
62 
63 private:
64  void
65  ReduceNodesInRegion(rvsdg::Region & region);
66 
76  [[nodiscard]] bool
77  ReduceStructuralNode(rvsdg::StructuralNode & structuralNode);
78 
79  [[nodiscard]] static bool
80  ReduceGammaNode(rvsdg::StructuralNode & gammaNode);
81 
82  [[nodiscard]] static bool
83  ReduceSimpleNode(rvsdg::SimpleNode & simpleNode);
84 
85  [[nodiscard]] static bool
86  ReduceLoadNode(rvsdg::SimpleNode & simpleNode);
87 
88  [[nodiscard]] static bool
89  ReduceStoreNode(rvsdg::SimpleNode & simpleNode);
90 
91  [[nodiscard]] static bool
92  ReduceMemoryStateMergeNode(rvsdg::SimpleNode & simpleNode);
93 
94  [[nodiscard]] static bool
95  ReduceMemoryStateSplitNode(rvsdg::SimpleNode & simpleNode);
96 
97  [[nodiscard]] static bool
98  ReduceLambdaExitMemoryStateMergeNode(rvsdg::SimpleNode & simpleNode);
99 
100  [[nodiscard]] static bool
101  ReduceBinaryNode(rvsdg::SimpleNode & simpleNode);
102 
103  static std::optional<std::vector<rvsdg::Output *>>
105  const LoadNonVolatileOperation & operation,
106  const std::vector<rvsdg::Output *> & operands);
107 
108  static std::optional<std::vector<rvsdg::Output *>>
110  const StoreNonVolatileOperation & operation,
111  const std::vector<rvsdg::Output *> & operands);
112 
113  static std::optional<std::vector<rvsdg::Output *>>
115  const MemoryStateMergeOperation & operation,
116  const std::vector<rvsdg::Output *> & operands);
117 
118  static std::optional<std::vector<rvsdg::Output *>>
120  const MemoryStateJoinOperation & operation,
121  const std::vector<rvsdg::Output *> & operands);
122 
123  static std::optional<std::vector<rvsdg::Output *>>
125  const MemoryStateSplitOperation & operation,
126  const std::vector<rvsdg::Output *> & operands);
127 
128  static std::optional<std::vector<rvsdg::Output *>>
130  const LambdaExitMemoryStateMergeOperation & operation,
131  const std::vector<rvsdg::Output *> & operands);
132 
133  std::unique_ptr<Statistics> Statistics_;
134 };
135 
139 class NodeReduction::Statistics final : public util::Statistics
140 {
141 public:
142  ~Statistics() noexcept override = default;
143 
144  explicit Statistics(const util::FilePath & sourceFile)
145  : util::Statistics(Id::ReduceNodes, sourceFile)
146  {}
147 
148  void
149  Start(const rvsdg::Graph & graph) noexcept;
150 
151  void
152  End(const rvsdg::Graph & graph) noexcept;
153 
154  bool
155  AddIteration(const rvsdg::Region & region, size_t numIterations);
156 
157  std::optional<size_t>
158  GetNumIterations(const rvsdg::Region & region) const noexcept;
159 
160  static std::unique_ptr<Statistics>
161  Create(const util::FilePath & sourceFile)
162  {
163  return std::make_unique<Statistics>(sourceFile);
164  }
165 
166 private:
167  std::unordered_map<const rvsdg::Region *, size_t> NumIterations_;
168 };
169 
170 }
171 
172 #endif
static jlm::util::StatisticsCollector statisticsCollector
static std::unique_ptr< Statistics > Create(const util::FilePath &sourceFile)
Definition: reduction.hpp:161
std::unordered_map< const rvsdg::Region *, size_t > NumIterations_
Definition: reduction.hpp:167
~Statistics() noexcept override=default
static bool ReduceLambdaExitMemoryStateMergeNode(rvsdg::SimpleNode &simpleNode)
Definition: reduction.cpp:233
static std::optional< std::vector< rvsdg::Output * > > NormalizeMemoryStateMergeNode(const MemoryStateMergeOperation &operation, const std::vector< rvsdg::Output * > &operands)
Definition: reduction.cpp:279
void ReduceNodesInRegion(rvsdg::Region &region)
Definition: reduction.cpp:79
static bool ReduceMemoryStateSplitNode(rvsdg::SimpleNode &simpleNode)
Definition: reduction.cpp:225
std::unique_ptr< Statistics > Statistics_
Definition: reduction.hpp:133
void Run(rvsdg::RvsdgModule &rvsdgModule, util::StatisticsCollector &statisticsCollector) override
Perform RVSDG transformation.
Definition: reduction.cpp:63
static std::optional< std::vector< rvsdg::Output * > > NormalizeLoadNode(const LoadNonVolatileOperation &operation, const std::vector< rvsdg::Output * > &operands)
Definition: reduction.cpp:242
static std::optional< std::vector< rvsdg::Output * > > NormalizeMemoryStateSplitNode(const MemoryStateSplitOperation &operation, const std::vector< rvsdg::Output * > &operands)
Definition: reduction.cpp:305
static std::optional< std::vector< rvsdg::Output * > > NormalizeStoreNode(const StoreNonVolatileOperation &operation, const std::vector< rvsdg::Output * > &operands)
Definition: reduction.cpp:260
bool ReduceStructuralNode(rvsdg::StructuralNode &structuralNode)
Definition: reduction.cpp:114
static std::optional< std::vector< rvsdg::Output * > > NormalizeMemoryStateJoinNode(const MemoryStateJoinOperation &operation, const std::vector< rvsdg::Output * > &operands)
Definition: reduction.cpp:293
static bool ReduceSimpleNode(rvsdg::SimpleNode &simpleNode)
Definition: reduction.cpp:152
static bool ReduceBinaryNode(rvsdg::SimpleNode &simpleNode)
Definition: reduction.cpp:209
static bool ReduceStoreNode(rvsdg::SimpleNode &simpleNode)
Definition: reduction.cpp:201
static bool ReduceMemoryStateMergeNode(rvsdg::SimpleNode &simpleNode)
Definition: reduction.cpp:217
~NodeReduction() noexcept override
static bool ReduceGammaNode(rvsdg::StructuralNode &gammaNode)
Definition: reduction.cpp:141
static bool ReduceLoadNode(rvsdg::SimpleNode &simpleNode)
Definition: reduction.cpp:193
static std::optional< std::vector< rvsdg::Output * > > NormalizeLambdaExitMemoryStateMergeNode(const LambdaExitMemoryStateMergeOperation &operation, const std::vector< rvsdg::Output * > &operands)
Definition: reduction.cpp:318
Represent acyclic RVSDG subgraphs.
Definition: region.hpp:213
Represents an RVSDG transformation.
Global memory state passed between functions.
static std::vector< jlm::rvsdg::Output * > operands(const Node *node)
Definition: node.hpp:1049