From 4fba26a77ea344b8d2b49cc8e1afdc8fcda13e96 Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Thu, 2 Nov 2023 21:50:25 +0100 Subject: [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. --- src/analysis/visitor-transfer-function.h | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'src/analysis/visitor-transfer-function.h') 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& + 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 -- cgit v1.2.3