[clang] [clang][dataflow] Add support for serialization and deserialization. (PR #152487)

Yitzhak Mandelbaum via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 18 05:31:25 PDT 2025


================
@@ -208,6 +208,27 @@ bool DataflowAnalysisContext::equivalentFormulas(const Formula &Val1,
   return isUnsatisfiable(std::move(Constraints));
 }
 
+llvm::DenseSet<Atom> DataflowAnalysisContext::getTransitiveClosure(
+    const llvm::DenseSet<Atom> &Tokens) const {
+  llvm::DenseSet<Atom> VisitedTokens;
+  // Use a worklist algorithm, with `Remaining` holding the worklist.
+  std::vector<Atom> Remaining(Tokens.begin(), Tokens.end());
+
+  // For each token in `Remaining`, add its dependencies to the worklist.
+  while (!Remaining.empty()) {
+    auto Token = Remaining.back();
+    Remaining.pop_back();
+    if (!VisitedTokens.insert(Token).second)
+      continue;
+    if (auto DepsIt = FlowConditionDeps.find(Token);
+        DepsIt != FlowConditionDeps.end())
+      for (Atom A : DepsIt->second)
+        Remaining.push_back(A);
----------------
ymand wrote:

My concern is that I think you can end up pushing the same node into `Remaining` twice. E.g.
```
A
|   \
|   C
|  /
B
```
We start with `Remaining` containing `A`:
```
Current Remaining
A            BC
C            BB
```
That is, when we pop `C`, `B` is in `Remaining` yet not yet visited. So, we'll add `B` a second time.

https://github.com/llvm/llvm-project/pull/152487


More information about the cfe-commits mailing list