[llvm-branch-commits] [clang] [SSAF][WPA] Add PointerFlowReachableAnalysis (PR #193097)

Jan Korous via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Apr 24 16:54:24 PDT 2026


================
@@ -102,14 +109,127 @@ class PointerFlowAnalysis final
                   const PointerFlowEntitySummary &Summary) override {
     auto EdgesOfEntity = getEdges(Summary);
 
-    getResult().Edges[Id] = EdgeSet(EdgesOfEntity.begin(), EdgesOfEntity.end());
+    this->getResult().Edges[Id] =
+        EdgeSet(EdgesOfEntity.begin(), EdgesOfEntity.end());
     return llvm::Error::success();
   }
 };
 
 AnalysisRegistry::Add<PointerFlowAnalysis>
     RegisterPointerFlowAnalysis("Whole-program pointer flow analysis");
 
+//===----------------------------------------------------------------------===//
+// PointerFlowReachableAnalysis---computes reachable node
+//===----------------------------------------------------------------------===//
+
+json::Object serializePointerFlowReachableAnalysisResult(
+    const PointerFlowReachableAnalysisResult &R,
+    JSONFormat::EntityIdToJSONFn IdToJSON) {
+  json::Object Result;
+
+  Result[PointerFlowReachableAnalysisResultName] =
+      entityPointerLevelMapToJSON(R.Reachables, IdToJSON);
+  return Result;
+}
+
+Expected<std::unique_ptr<AnalysisResult>>
+deserializePointerFlowReachableAnalysisResult(
+    const json::Object &Obj, JSONFormat::EntityIdFromJSONFn IdFromJSON) {
+  const json::Array *Content =
+      Obj.getArray(PointerFlowReachableAnalysisResultName);
+
+  if (!Content)
+    return makeSawButExpectedError(
+        Obj, "an object with a key %s",
+        PointerFlowReachableAnalysisResultName.data());
+
+  auto Reachables = entityPointerLevelMapFromJSON(*Content, IdFromJSON);
+
+  if (!Reachables)
+    return Reachables.takeError();
+
+  auto Ret = std::make_unique<PointerFlowReachableAnalysisResult>();
+
+  Ret->Reachables = std::move(*Reachables);
+  return Ret;
+}
+
+JSONFormat::AnalysisResultRegistry::Add<PointerFlowReachableAnalysisResult>
+    RegisterPointerFlowReachableResultForJSON(
+        serializePointerFlowReachableAnalysisResult,
+        deserializePointerFlowReachableAnalysisResult);
+
+// For any AnalysisResult that is a set of pointers, it can be the starting set
+// for reachable analysis.
+template <typename AnalysisResultInPointerSet>
----------------
jkorous-apple wrote:

Before we try to generalize, can we develop a particular analysis first?

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


More information about the llvm-branch-commits mailing list