[llvm] ea693a1 - [NPM] Port module-debuginfo pass to the new pass manager
Amy Huang via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 19 14:31:52 PDT 2020
Author: Amy Huang
Date: 2020-10-19T14:31:17-07:00
New Revision: ea693a162786d933863ab079648d4261ac0ead47
URL: https://github.com/llvm/llvm-project/commit/ea693a162786d933863ab079648d4261ac0ead47
DIFF: https://github.com/llvm/llvm-project/commit/ea693a162786d933863ab079648d4261ac0ead47.diff
LOG: [NPM] Port module-debuginfo pass to the new pass manager
Port pass to NPM and update tests in DebugInfo/Generic.
Differential Revision: https://reviews.llvm.org/D89730
Added:
llvm/include/llvm/Analysis/ModuleDebugInfoPrinter.h
Modified:
llvm/include/llvm/InitializePasses.h
llvm/lib/Analysis/Analysis.cpp
llvm/lib/Analysis/ModuleDebugInfoPrinter.cpp
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Passes/PassRegistry.def
llvm/test/DebugInfo/Generic/debuginfofinder-forward-declaration.ll
llvm/test/DebugInfo/Generic/debuginfofinder-imported-global-variable.ll
llvm/test/DebugInfo/Generic/debuginfofinder-inlined-cu.ll
llvm/test/DebugInfo/Generic/debuginfofinder-multiple-cu.ll
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/ModuleDebugInfoPrinter.h b/llvm/include/llvm/Analysis/ModuleDebugInfoPrinter.h
new file mode 100644
index 000000000000..99aa315319b8
--- /dev/null
+++ b/llvm/include/llvm/Analysis/ModuleDebugInfoPrinter.h
@@ -0,0 +1,29 @@
+//===- ModuleDebugInfoPrinter.h - -----------------------------------------===//
+//
+// 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_ANALYSIS_MODULEDEBUGINFOPRINTER_H
+#define LLVM_ANALYSIS_MODULEDEBUGINFOPRINTER_H
+
+#include "llvm/IR/DebugInfo.h"
+#include "llvm/IR/PassManager.h"
+#include "llvm/Support/raw_ostream.h"
+
+namespace llvm {
+
+class ModuleDebugInfoPrinterPass
+ : public PassInfoMixin<ModuleDebugInfoPrinterPass> {
+ DebugInfoFinder Finder;
+ raw_ostream &OS;
+
+public:
+ explicit ModuleDebugInfoPrinterPass(raw_ostream &OS);
+ PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
+};
+} // end namespace llvm
+
+#endif // LLVM_ANALYSIS_MODULEDEBUGINFOPRINTER_H
diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h
index 55cb389a3cff..4f3beb176dab 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -306,7 +306,7 @@ void initializeMergeFunctionsLegacyPassPass(PassRegistry&);
void initializeMergeICmpsLegacyPassPass(PassRegistry &);
void initializeMergedLoadStoreMotionLegacyPassPass(PassRegistry&);
void initializeMetaRenamerPass(PassRegistry&);
-void initializeModuleDebugInfoPrinterPass(PassRegistry&);
+void initializeModuleDebugInfoLegacyPrinterPass(PassRegistry &);
void initializeModuleMemProfilerLegacyPassPass(PassRegistry &);
void initializeModuleSummaryIndexWrapperPassPass(PassRegistry&);
void initializeModuloScheduleTestPass(PassRegistry&);
diff --git a/llvm/lib/Analysis/Analysis.cpp b/llvm/lib/Analysis/Analysis.cpp
index fdd5c9fc4669..db5167061509 100644
--- a/llvm/lib/Analysis/Analysis.cpp
+++ b/llvm/lib/Analysis/Analysis.cpp
@@ -63,7 +63,7 @@ void llvm::initializeAnalysis(PassRegistry &Registry) {
initializeMemDepPrinterPass(Registry);
initializeMemDerefPrinterPass(Registry);
initializeMemoryDependenceWrapperPassPass(Registry);
- initializeModuleDebugInfoPrinterPass(Registry);
+ initializeModuleDebugInfoLegacyPrinterPass(Registry);
initializeModuleSummaryIndexWrapperPassPass(Registry);
initializeMustExecutePrinterPass(Registry);
initializeMustBeExecutedContextPrinterPass(Registry);
diff --git a/llvm/lib/Analysis/ModuleDebugInfoPrinter.cpp b/llvm/lib/Analysis/ModuleDebugInfoPrinter.cpp
index 52b884fb88e0..64fd5eb1acd4 100644
--- a/llvm/lib/Analysis/ModuleDebugInfoPrinter.cpp
+++ b/llvm/lib/Analysis/ModuleDebugInfoPrinter.cpp
@@ -14,9 +14,11 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/Analysis/ModuleDebugInfoPrinter.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/Passes.h"
#include "llvm/IR/DebugInfo.h"
+#include "llvm/IR/PassManager.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/ErrorHandling.h"
@@ -24,32 +26,34 @@
using namespace llvm;
namespace {
- class ModuleDebugInfoPrinter : public ModulePass {
- DebugInfoFinder Finder;
- public:
- static char ID; // Pass identification, replacement for typeid
- ModuleDebugInfoPrinter() : ModulePass(ID) {
- initializeModuleDebugInfoPrinterPass(*PassRegistry::getPassRegistry());
- }
+class ModuleDebugInfoLegacyPrinter : public ModulePass {
+ DebugInfoFinder Finder;
- bool runOnModule(Module &M) override;
+public:
+ static char ID; // Pass identification, replacement for typeid
+ ModuleDebugInfoLegacyPrinter() : ModulePass(ID) {
+ initializeModuleDebugInfoLegacyPrinterPass(
+ *PassRegistry::getPassRegistry());
+ }
- void getAnalysisUsage(AnalysisUsage &AU) const override {
- AU.setPreservesAll();
- }
- void print(raw_ostream &O, const Module *M) const override;
- };
+ bool runOnModule(Module &M) override;
+
+ void getAnalysisUsage(AnalysisUsage &AU) const override {
+ AU.setPreservesAll();
+ }
+ void print(raw_ostream &O, const Module *M) const override;
+};
}
-char ModuleDebugInfoPrinter::ID = 0;
-INITIALIZE_PASS(ModuleDebugInfoPrinter, "module-debuginfo",
+char ModuleDebugInfoLegacyPrinter::ID = 0;
+INITIALIZE_PASS(ModuleDebugInfoLegacyPrinter, "module-debuginfo",
"Decodes module-level debug info", false, true)
ModulePass *llvm::createModuleDebugInfoPrinterPass() {
- return new ModuleDebugInfoPrinter();
+ return new ModuleDebugInfoLegacyPrinter();
}
-bool ModuleDebugInfoPrinter::runOnModule(Module &M) {
+bool ModuleDebugInfoLegacyPrinter::runOnModule(Module &M) {
Finder.processModule(M);
return false;
}
@@ -67,7 +71,8 @@ static void printFile(raw_ostream &O, StringRef Filename, StringRef Directory,
O << ":" << Line;
}
-void ModuleDebugInfoPrinter::print(raw_ostream &O, const Module *M) const {
+static void printModuleDebugInfo(raw_ostream &O, const Module *M,
+ const DebugInfoFinder &Finder) {
// Printing the nodes directly isn't particularly helpful (since they
// reference other nodes that won't be printed, particularly for the
// filenames), so just print a few useful things.
@@ -126,3 +131,18 @@ void ModuleDebugInfoPrinter::print(raw_ostream &O, const Module *M) const {
O << '\n';
}
}
+
+void ModuleDebugInfoLegacyPrinter::print(raw_ostream &O,
+ const Module *M) const {
+ printModuleDebugInfo(O, M, Finder);
+}
+
+ModuleDebugInfoPrinterPass::ModuleDebugInfoPrinterPass(raw_ostream &OS)
+ : OS(OS) {}
+
+PreservedAnalyses ModuleDebugInfoPrinterPass::run(Module &M,
+ ModuleAnalysisManager &AM) {
+ Finder.processModule(M);
+ printModuleDebugInfo(OS, &M, Finder);
+ return PreservedAnalyses::all();
+}
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 18de4619ce69..6168a764bcf3 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -49,6 +49,7 @@
#include "llvm/Analysis/LoopNestAnalysis.h"
#include "llvm/Analysis/MemoryDependenceAnalysis.h"
#include "llvm/Analysis/MemorySSA.h"
+#include "llvm/Analysis/ModuleDebugInfoPrinter.h"
#include "llvm/Analysis/ModuleSummaryAnalysis.h"
#include "llvm/Analysis/ObjCARCAliasAnalysis.h"
#include "llvm/Analysis/OptimizationRemarkEmitter.h"
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index e6f75173476f..85dd9637014f 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -85,6 +85,7 @@ MODULE_PASS("print", PrintModulePass(dbgs()))
MODULE_PASS("print-lcg", LazyCallGraphPrinterPass(dbgs()))
MODULE_PASS("print-lcg-dot", LazyCallGraphDOTPrinterPass(dbgs()))
MODULE_PASS("print-stack-safety", StackSafetyGlobalPrinterPass(dbgs()))
+MODULE_PASS("print<module-debuginfo>", ModuleDebugInfoPrinterPass(dbgs()))
MODULE_PASS("rewrite-statepoints-for-gc", RewriteStatepointsForGC())
MODULE_PASS("rewrite-symbols", RewriteSymbolPass())
MODULE_PASS("rpo-function-attrs", ReversePostOrderFunctionAttrsPass())
diff --git a/llvm/test/DebugInfo/Generic/debuginfofinder-forward-declaration.ll b/llvm/test/DebugInfo/Generic/debuginfofinder-forward-declaration.ll
index 675230d21403..3e0a167b849b 100644
--- a/llvm/test/DebugInfo/Generic/debuginfofinder-forward-declaration.ll
+++ b/llvm/test/DebugInfo/Generic/debuginfofinder-forward-declaration.ll
@@ -1,4 +1,6 @@
-; RUN: opt -analyze -module-debuginfo < %s | FileCheck %s
+; RUN: opt -analyze -module-debuginfo -enable-new-pm=0 < %s | FileCheck %s
+; RUN: opt -passes='print<module-debuginfo>' -disable-output 2>&1 < %s \
+; RUN: | FileCheck %s
; This module is generated from the following c-code:
;
diff --git a/llvm/test/DebugInfo/Generic/debuginfofinder-imported-global-variable.ll b/llvm/test/DebugInfo/Generic/debuginfofinder-imported-global-variable.ll
index 270ab7ad47f8..bce4a218d2df 100644
--- a/llvm/test/DebugInfo/Generic/debuginfofinder-imported-global-variable.ll
+++ b/llvm/test/DebugInfo/Generic/debuginfofinder-imported-global-variable.ll
@@ -1,7 +1,9 @@
-; RUN: opt -analyze -module-debuginfo < %s | FileCheck %s
+; RUN: opt -analyze -module-debuginfo -enable-new-pm=0 < %s | FileCheck %s
+; RUN: opt -passes='print<module-debuginfo>' -disable-output 2>&1 < %s \
+; RUN: | FileCheck %s
; This is to track DebugInfoFinder's ability to find the debug info metadata,
-; in particular, properly visit
diff erent kinds of DIImportedEntit'ies.
+; in particular, properly visit
diff erent kinds of DIImportedEntities.
; Derived from the following C++ snippet
;
@@ -13,7 +15,6 @@
;
; compiled with `clang -O1 -g3 -emit-llvm -S`
-; CHECK: Printing analysis 'Decodes module-level debug info':
; CHECK: Compile unit: DW_LANG_C_plus_plus from /somewhere/source.cpp
; CHECK: Global variable: i from /somewhere/source.cpp:2 ('_ZN1s1iE')
; CHECK: Type: int DW_ATE_signed
diff --git a/llvm/test/DebugInfo/Generic/debuginfofinder-inlined-cu.ll b/llvm/test/DebugInfo/Generic/debuginfofinder-inlined-cu.ll
index 1ef9fa56beb9..e9f8179bd29d 100644
--- a/llvm/test/DebugInfo/Generic/debuginfofinder-inlined-cu.ll
+++ b/llvm/test/DebugInfo/Generic/debuginfofinder-inlined-cu.ll
@@ -1,4 +1,6 @@
-; RUN: opt -analyze -module-debuginfo < %s | FileCheck %s
+; RUN: opt -analyze -module-debuginfo -enable-new-pm=0 < %s | FileCheck %s
+; RUN: opt -passes='print<module-debuginfo>' -disable-output 2>&1 < %s \
+; RUN: | FileCheck %s
; Verify that both compile units, even though one compile units's functions
; were entirely inlined into the other.
diff --git a/llvm/test/DebugInfo/Generic/debuginfofinder-multiple-cu.ll b/llvm/test/DebugInfo/Generic/debuginfofinder-multiple-cu.ll
index 3832a967894f..0658a91d7101 100644
--- a/llvm/test/DebugInfo/Generic/debuginfofinder-multiple-cu.ll
+++ b/llvm/test/DebugInfo/Generic/debuginfofinder-multiple-cu.ll
@@ -1,4 +1,6 @@
-; RUN: opt -analyze -module-debuginfo < %s | FileCheck %s
+; RUN: opt -analyze -module-debuginfo -enable-new-pm=0 < %s | FileCheck %s
+; RUN: opt -passes='print<module-debuginfo>' -disable-output 2>&1 < %s \
+; RUN: | FileCheck %s
; Produced from linking:
; /tmp/test1.c containing f()
More information about the llvm-commits
mailing list