[llvm] [CodeGen][NewPM] Port AssignmentTrackingAnalysis to new pass manager (PR #77550)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 9 19:30:55 PST 2024


https://github.com/paperchalice updated https://github.com/llvm/llvm-project/pull/77550

>From b5186c4240c6ae5fee8e622ebee7e947ff286cfd Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Wed, 10 Jan 2024 11:20:39 +0800
Subject: [PATCH] [CodeGen][NewPM] Port AssignmentTrackingAnalysis to new pass
 manager

---
 .../llvm/CodeGen/AssignmentTrackingAnalysis.h | 29 +++++++++++++++-
 .../include/llvm/CodeGen/CodeGenPassBuilder.h |  1 +
 .../CodeGen/AssignmentTrackingAnalysis.cpp    | 34 +++++++++++++++++++
 llvm/lib/Passes/PassBuilder.cpp               |  1 +
 llvm/lib/Passes/PassRegistry.def              |  2 ++
 5 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/llvm/include/llvm/CodeGen/AssignmentTrackingAnalysis.h b/llvm/include/llvm/CodeGen/AssignmentTrackingAnalysis.h
index b740ab567b12f4..fb0ecd828b68f6 100644
--- a/llvm/include/llvm/CodeGen/AssignmentTrackingAnalysis.h
+++ b/llvm/include/llvm/CodeGen/AssignmentTrackingAnalysis.h
@@ -1,13 +1,21 @@
+//===-- llvm/CodeGen/AssignmentTrackingAnalysis.h --------------*- C++ -*--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
 #ifndef LLVM_CODEGEN_ASSIGNMENTTRACKINGANALYSIS_H
 #define LLVM_CODEGEN_ASSIGNMENTTRACKINGANALYSIS_H
 
 #include "llvm/IR/DebugInfoMetadata.h"
 #include "llvm/IR/DebugLoc.h"
 #include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/PassManager.h"
 #include "llvm/Pass.h"
 
 namespace llvm {
-class Function;
 class Instruction;
 class raw_ostream;
 } // namespace llvm
@@ -94,6 +102,25 @@ class FunctionVarLocs {
   ///@}
 };
 
+class DebugAssignmentTrackingAnalysis
+    : public AnalysisInfoMixin<DebugAssignmentTrackingAnalysis> {
+  friend AnalysisInfoMixin<DebugAssignmentTrackingAnalysis>;
+  static AnalysisKey Key;
+
+public:
+  using Result = FunctionVarLocs;
+  Result run(Function &F, FunctionAnalysisManager &FAM);
+};
+
+class DebugAssignmentTrackingPrinterPass
+    : public PassInfoMixin<DebugAssignmentTrackingPrinterPass> {
+  raw_ostream &OS;
+
+public:
+  DebugAssignmentTrackingPrinterPass(raw_ostream &OS) : OS(OS) {}
+  PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM);
+};
+
 class AssignmentTrackingAnalysis : public FunctionPass {
   std::unique_ptr<FunctionVarLocs> Results;
 
diff --git a/llvm/include/llvm/CodeGen/CodeGenPassBuilder.h b/llvm/include/llvm/CodeGen/CodeGenPassBuilder.h
index fa81ff504ac65b..f540f3774c414a 100644
--- a/llvm/include/llvm/CodeGen/CodeGenPassBuilder.h
+++ b/llvm/include/llvm/CodeGen/CodeGenPassBuilder.h
@@ -23,6 +23,7 @@
 #include "llvm/Analysis/ScopedNoAliasAA.h"
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/Analysis/TypeBasedAliasAnalysis.h"
+#include "llvm/CodeGen/AssignmentTrackingAnalysis.h"
 #include "llvm/CodeGen/CallBrPrepare.h"
 #include "llvm/CodeGen/CodeGenPrepare.h"
 #include "llvm/CodeGen/DwarfEHPrepare.h"
diff --git a/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp b/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
index ad3ad992898785..eb372655e5f165 100644
--- a/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
+++ b/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
@@ -1,3 +1,11 @@
+//===-- AssignmentTrackingAnalysis.cpp ------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
 #include "llvm/CodeGen/AssignmentTrackingAnalysis.h"
 #include "LiveDebugValues/LiveDebugValues.h"
 #include "llvm/ADT/BitVector.h"
@@ -2553,6 +2561,32 @@ static void analyzeFunction(Function &Fn, const DataLayout &Layout,
   }
 }
 
+FunctionVarLocs
+DebugAssignmentTrackingAnalysis::run(Function &F,
+                                     FunctionAnalysisManager &FAM) {
+  if (!isAssignmentTrackingEnabled(*F.getParent()))
+    return FunctionVarLocs();
+
+  auto &DL = F.getParent()->getDataLayout();
+
+  FunctionVarLocsBuilder Builder;
+  analyzeFunction(F, DL, &Builder);
+
+  // Save these results.
+  FunctionVarLocs Results;
+  Results.init(Builder);
+  return Results;
+}
+
+AnalysisKey DebugAssignmentTrackingAnalysis::Key;
+
+PreservedAnalyses
+DebugAssignmentTrackingPrinterPass::run(Function &F,
+                                        FunctionAnalysisManager &FAM) {
+  FAM.getResult<DebugAssignmentTrackingAnalysis>(F).print(OS, F);
+  return PreservedAnalyses::all();
+}
+
 bool AssignmentTrackingAnalysis::runOnFunction(Function &F) {
   if (!isAssignmentTrackingEnabled(*F.getParent()))
     return false;
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 27bfe12127cc2c..bfc97d5464c046 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -72,6 +72,7 @@
 #include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/Analysis/TypeBasedAliasAnalysis.h"
 #include "llvm/Analysis/UniformityAnalysis.h"
+#include "llvm/CodeGen/AssignmentTrackingAnalysis.h"
 #include "llvm/CodeGen/BasicBlockSectionsProfileReader.h"
 #include "llvm/CodeGen/CallBrPrepare.h"
 #include "llvm/CodeGen/CodeGenPrepare.h"
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index bda36bd8c107c9..fbaca001d1fec5 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -235,6 +235,7 @@ FUNCTION_ANALYSIS("block-freq", BlockFrequencyAnalysis())
 FUNCTION_ANALYSIS("branch-prob", BranchProbabilityAnalysis())
 FUNCTION_ANALYSIS("cycles", CycleAnalysis())
 FUNCTION_ANALYSIS("da", DependenceAnalysis())
+FUNCTION_ANALYSIS("debug-ata", DebugAssignmentTrackingAnalysis())
 FUNCTION_ANALYSIS("demanded-bits", DemandedBitsAnalysis())
 FUNCTION_ANALYSIS("domfrontier", DominanceFrontierAnalysis())
 FUNCTION_ANALYSIS("domtree", DominatorTreeAnalysis())
@@ -384,6 +385,7 @@ FUNCTION_PASS("print<branch-prob>", BranchProbabilityPrinterPass(dbgs()))
 FUNCTION_PASS("print<cost-model>", CostModelPrinterPass(dbgs()))
 FUNCTION_PASS("print<cycles>", CycleInfoPrinterPass(dbgs()))
 FUNCTION_PASS("print<da>", DependenceAnalysisPrinterPass(dbgs()))
+FUNCTION_PASS("print<debug-ata>", DebugAssignmentTrackingPrinterPass(dbgs()))
 FUNCTION_PASS("print<delinearization>", DelinearizationPrinterPass(dbgs()))
 FUNCTION_PASS("print<demanded-bits>", DemandedBitsPrinterPass(dbgs()))
 FUNCTION_PASS("print<domfrontier>", DominanceFrontierPrinterPass(dbgs()))



More information about the llvm-commits mailing list