summaryrefslogtreecommitdiff
path: root/src/analysis/visitor-transfer-function.h
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2023-10-19 07:41:53 +0200
committerGitHub <noreply@github.com>2023-10-18 22:41:53 -0700
commitf79b5aa26b1fc722853e56b541cd35128786ef6b (patch)
tree0a8255cb2a3d2c4f1ee41dcb64cbcce4758f4341 /src/analysis/visitor-transfer-function.h
parentc170fe7893fc05147de455e36d0a36b356b3f3db (diff)
downloadbinaryen-f79b5aa26b1fc722853e56b541cd35128786ef6b.tar.gz
binaryen-f79b5aa26b1fc722853e56b541cd35128786ef6b.tar.bz2
binaryen-f79b5aa26b1fc722853e56b541cd35128786ef6b.zip
[analysis][NFC] Use C++20 concepts for Lattice (#6027)
Replace the static assertions ensuring that Lattice types have the necessary operations with a C++20 concept called `Lattice`. To avoid name conflicts with the new concept, rename existing type parameters named `Lattice` to `L`. When not building with C++20, `Lattice` is a macro that resolves to `typename` so the code continues compiling and has the same behavior, but without any eager checks of the requirements on lattices. Add a new C++20 builder to CI to ensure that future changes compile with both C++17 and C++20. Once we switch to C++20 by default, the new builder can be removed. Update the lint builder to use a recent clang-format that understands concepts.
Diffstat (limited to 'src/analysis/visitor-transfer-function.h')
-rw-r--r--src/analysis/visitor-transfer-function.h9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/analysis/visitor-transfer-function.h b/src/analysis/visitor-transfer-function.h
index 18ee35392..699840ff3 100644
--- a/src/analysis/visitor-transfer-function.h
+++ b/src/analysis/visitor-transfer-function.h
@@ -14,10 +14,10 @@ enum class AnalysisDirection { Forward, Backward };
// Utility for visitor-based transfer functions for forward and backward
// analysis. Forward analysis is chosen by default unless the template parameter
// Backward is true.
-template<typename SubType, typename Lattice, AnalysisDirection Direction>
+template<typename SubType, Lattice L, AnalysisDirection Direction>
struct VisitorTransferFunc : public Visitor<SubType> {
protected:
- typename Lattice::Element* currState = nullptr;
+ typename L::Element* currState = nullptr;
// There are two distinct phases in the execution of the analyzer. First,
// the worklist algorithm will be run to obtain a solution, calling
@@ -46,8 +46,7 @@ public:
// 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* cfgBlock,
- typename Lattice::Element& inputState) {
+ void transfer(const BasicBlock* cfgBlock, typename L::Element& inputState) {
// If the block is empty, we propagate the state by inputState =
// outputState.
@@ -87,7 +86,7 @@ public:
// This is for collecting results after solving an analysis. Implemented in
// the same way as transfer(), but we also set the collectingResults flag.
void collectResults(const BasicBlock* cfgBlock,
- typename Lattice::Element& inputState) {
+ typename L::Element& inputState) {
collectingResults = true;
currState = &inputState;
if constexpr (Direction == AnalysisDirection::Backward) {