Skip to content

[NFC][mlir] Update DataFlowFramework.h to be compatible with clang c++23 #152040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

philass
Copy link
Contributor

@philass philass commented Aug 4, 2025

This change makes DataFlowFramework.h compatible with clang++ and --std=c++23.

Previously clang was checking the templated DataFlowSolver::eraseState body before being instantiated. This resulted in issues with incomplete types, and happened at least with clang++-19.

This is fixed by moving the definition of DataFlowSolver::eraseState after the AnalysisState's full class declaration.

For full context:

@llvmbot llvmbot added the mlir label Aug 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 4, 2025

@llvm/pr-subscribers-mlir

Author: Philip Lassen (philass)

Changes

This change makes it possible to compile DataFlowFramework.h with clang and --std=c++23.

For full context:

Thanks for the suggested fix @fabianmcg!


Full diff: https://github.com/llvm/llvm-project/pull/152040.diff

1 Files Affected:

  • (modified) mlir/include/mlir/Analysis/DataFlowFramework.h (+26-23)
diff --git a/mlir/include/mlir/Analysis/DataFlowFramework.h b/mlir/include/mlir/Analysis/DataFlowFramework.h
index 49862927caff2..470170c26e6cb 100644
--- a/mlir/include/mlir/Analysis/DataFlowFramework.h
+++ b/mlir/include/mlir/Analysis/DataFlowFramework.h
@@ -354,29 +354,7 @@ class DataFlowSolver {
 
   /// Erase any analysis state associated with the given lattice anchor.
   template <typename AnchorT>
-  void eraseState(AnchorT anchor) {
-    LatticeAnchor latticeAnchor(anchor);
-
-    // Update equivalentAnchorMap.
-    for (auto &&[TypeId, eqClass] : equivalentAnchorMap) {
-      if (!eqClass.contains(latticeAnchor)) {
-        continue;
-      }
-      llvm::EquivalenceClasses<LatticeAnchor>::member_iterator leaderIt =
-          eqClass.findLeader(latticeAnchor);
-
-      // Update analysis states with new leader if needed.
-      if (*leaderIt == latticeAnchor && ++leaderIt != eqClass.member_end()) {
-        analysisStates[*leaderIt][TypeId] =
-            std::move(analysisStates[latticeAnchor][TypeId]);
-      }
-
-      eqClass.erase(latticeAnchor);
-    }
-
-    // Update analysis states.
-    analysisStates.erase(latticeAnchor);
-  }
+  void eraseState(AnchorT anchor);
 
   /// Erase all analysis states.
   void eraseAllStates() {
@@ -560,6 +538,31 @@ class AnalysisState {
   friend class DataFlowSolver;
 };
 
+template <typename AnchorT>
+void DataFlowSolver::eraseState(AnchorT anchor) {
+  LatticeAnchor latticeAnchor(anchor);
+
+  // Update equivalentAnchorMap.
+  for (auto &&[TypeId, eqClass] : equivalentAnchorMap) {
+    if (!eqClass.contains(latticeAnchor)) {
+      continue;
+    }
+    llvm::EquivalenceClasses<LatticeAnchor>::member_iterator leaderIt =
+        eqClass.findLeader(latticeAnchor);
+
+    // Update analysis states with new leader if needed.
+    if (*leaderIt == latticeAnchor && ++leaderIt != eqClass.member_end()) {
+      analysisStates[*leaderIt][TypeId] =
+          std::move(analysisStates[latticeAnchor][TypeId]);
+    }
+
+    eqClass.erase(latticeAnchor);
+  }
+
+  // Update analysis states.
+  analysisStates.erase(latticeAnchor);
+}
+
 //===----------------------------------------------------------------------===//
 // DataFlowAnalysis
 //===----------------------------------------------------------------------===//

Copy link
Contributor

@fabianmcg fabianmcg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this! In general LGTM, I'll approve as soon as the comment is fixed.

@@ -560,6 +538,31 @@ class AnalysisState {
friend class DataFlowSolver;
};

template <typename AnchorT>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment around the lines:

Suggested change
template <typename AnchorT>
//===----------------------------------------------------------------------===//
// DataFlowSolver definition
//===----------------------------------------------------------------------===//
// This is method is defined outside `DataFlowSolver` and after `AnalysisState` to prevent issues around `AnalysisState` being used before it is defined.
template <typename AnchorT>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@fabianmcg fabianmcg changed the title [MLIR] Update DataFlowFramework.h to be compatible with clang c++23 [NFC][mlir] Update DataFlowFramework.h to be compatible with clang c++23 Aug 4, 2025
@fabianmcg
Copy link
Contributor

Also, please don't reference people in the commit message, see https://discourse.llvm.org/t/forbidding-username-in-commits/86997

@philass philass force-pushed the plassen/fix-dataflowframework-for-cpp23 branch 2 times, most recently from b2ba87f to 8cad488 Compare August 4, 2025 22:12
@fabianmcg
Copy link
Contributor

Also, please edit the commit message with a bigger description of the issue and solution to not force people to go to discourse. Thanks!

@philass
Copy link
Contributor Author

philass commented Aug 4, 2025

Thanks for pointing me to the commit message rules. I updated with a more detailed description of the problem and the fix. Would you like me to delete the reference to the discourse all together?

@philass
Copy link
Contributor Author

philass commented Aug 4, 2025

And if you do approve, could you also commit for me? I don't have llvm commit privileges.

//===----------------------------------------------------------------------===//
// DataFlowSolver definition
//===----------------------------------------------------------------------===//
// This is method is defined outside `DataFlowSolver` and after `AnalysisState`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// This is method is defined outside `DataFlowSolver` and after `AnalysisState`
// This method is defined outside `DataFlowSolver` and after `AnalysisState`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Done!

@philass philass force-pushed the plassen/fix-dataflowframework-for-cpp23 branch from 8cad488 to efc0f1f Compare August 4, 2025 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants