summaryrefslogtreecommitdiff
path: root/src/analysis/visitor-transfer-function.h
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2023-11-02 21:50:25 +0100
committerGitHub <noreply@github.com>2023-11-02 13:50:25 -0700
commit4fba26a77ea344b8d2b49cc8e1afdc8fcda13e96 (patch)
tree5409b665b4610bc8c07f2e7629d5883f4f3c0633 /src/analysis/visitor-transfer-function.h
parent2c3860b8f6e9ba3e0878ecadfdef409da0f471b7 (diff)
downloadbinaryen-4fba26a77ea344b8d2b49cc8e1afdc8fcda13e96.tar.gz
binaryen-4fba26a77ea344b8d2b49cc8e1afdc8fcda13e96.tar.bz2
binaryen-4fba26a77ea344b8d2b49cc8e1afdc8fcda13e96.zip
[analysis] Make it easier to implement a transfer function (#6077)
Combine the `transfer` and `getDependents` methods of a transfer function so that a transfer function only has to implement `transfer`, which now returns a range of basic blocks that may need to be re-analyzed. To make it easier to implement the returned basic block range, change the requirement so that it provides iterators to `const BasicBlock*` rather than `BasicBlock`. This allows us to entirely remove cfg-impl.h.
Diffstat (limited to 'src/analysis/visitor-transfer-function.h')
-rw-r--r--src/analysis/visitor-transfer-function.h21
1 files changed, 8 insertions, 13 deletions
diff --git a/src/analysis/visitor-transfer-function.h b/src/analysis/visitor-transfer-function.h
index d77fc9fcd..6e449baf9 100644
--- a/src/analysis/visitor-transfer-function.h
+++ b/src/analysis/visitor-transfer-function.h
@@ -34,22 +34,11 @@ protected:
bool collectingResults = false;
public:
- // Returns an iterable to all the BasicBlocks which depend on currBlock for
- // information.
- BasicBlock::BasicBlockIterable
- getDependents(const BasicBlock& currBlock) noexcept {
- if constexpr (Direction == AnalysisDirection::Backward) {
- return currBlock.preds();
- } else {
- return currBlock.succs();
- }
- }
-
// Executes the transfer function on all the expressions of the corresponding
// CFG node, starting with the node's input state, and changes the input state
// to the final output state of the node in place.
- void transfer(const BasicBlock& bb,
- typename L::Element& inputState) noexcept {
+ const std::vector<const BasicBlock*>&
+ transfer(const BasicBlock& bb, typename L::Element& inputState) noexcept {
// If the block is empty, we propagate the state by inputState =
// outputState.
@@ -64,6 +53,12 @@ public:
}
}
currState = nullptr;
+
+ if constexpr (Direction == AnalysisDirection::Backward) {
+ return bb.preds();
+ } else {
+ return bb.succs();
+ }
}
// This is for collecting results after solving an analysis. Implemented in