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