|
16 | 16 |
|
17 | 17 | #include <cstddef> |
18 | 18 | #include <cstdint> |
| 19 | +#include <functional> |
19 | 20 | #include <optional> |
20 | 21 | #include <ostream> |
| 22 | +#include <utility> |
21 | 23 | #include <vector> |
22 | 24 |
|
23 | 25 | #include "absl/container/flat_hash_map.h" |
|
27 | 29 | #include "xls/ir/node.h" |
28 | 30 | #include "xls/ir/nodes.h" |
29 | 31 | #include "xls/ir/topo_sort.h" |
| 32 | +#include "xls/passes/optimization_pass.h" |
30 | 33 | #include "xls/passes/predicate_state.h" |
31 | 34 |
|
32 | 35 | namespace xls { |
@@ -97,15 +100,16 @@ class AnalysisHelper { |
97 | 100 | .previous = kRootPredicateId, |
98 | 101 | .distance_to_root = 0}; |
99 | 102 |
|
100 | | - explicit AnalysisHelper(FunctionBase* func) : function_(func) {} |
| 103 | + AnalysisHelper(FunctionBase* func, OptimizationContext& context) |
| 104 | + : function_(func), context_(context) {} |
101 | 105 |
|
102 | 106 | absl::flat_hash_map<Node*, PredicateState> Analyze() { |
103 | 107 | CHECK(node_states_.empty()); |
104 | 108 | CHECK(predicate_stacks_.empty()); |
105 | 109 | node_states_.reserve(function_->node_count()); |
106 | 110 | predicate_stacks_.push_back(kRootPredicateStackNode); |
107 | 111 | // Run in reverse topo sort order. Handle users before the values they use. |
108 | | - for (Node* node : ReverseTopoSort(function_)) { |
| 112 | + for (Node* node : context_.ReverseTopoSort(function_)) { |
109 | 113 | HandleNode(node); |
110 | 114 | } |
111 | 115 |
|
@@ -259,15 +263,17 @@ class AnalysisHelper { |
259 | 263 |
|
260 | 264 | private: |
261 | 265 | FunctionBase* function_; |
| 266 | + OptimizationContext& context_; |
262 | 267 | // Map of node to the predicate list head they are guarded by. |
263 | 268 | absl::flat_hash_map<Node*, PredicateStackId> node_states_; |
264 | 269 | // Map from 'PredicateStackId' to the predicate node. |
265 | 270 | std::vector<PredicateStackNode> predicate_stacks_; |
266 | 271 | }; |
267 | 272 | } // namespace |
268 | 273 |
|
269 | | -PredicateDominatorAnalysis PredicateDominatorAnalysis::Run(FunctionBase* f) { |
270 | | - AnalysisHelper helper(f); |
| 274 | +PredicateDominatorAnalysis PredicateDominatorAnalysis::Run( |
| 275 | + FunctionBase* f, OptimizationContext& context) { |
| 276 | + AnalysisHelper helper(f, context); |
271 | 277 | return PredicateDominatorAnalysis(helper.Analyze()); |
272 | 278 | } |
273 | 279 |
|
|
0 commit comments