Skip to content

Commit ea693a1

Browse files
committed
[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
1 parent e056758 commit ea693a1

10 files changed

+84
-26
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===- ModuleDebugInfoPrinter.h - -----------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_ANALYSIS_MODULEDEBUGINFOPRINTER_H
10+
#define LLVM_ANALYSIS_MODULEDEBUGINFOPRINTER_H
11+
12+
#include "llvm/IR/DebugInfo.h"
13+
#include "llvm/IR/PassManager.h"
14+
#include "llvm/Support/raw_ostream.h"
15+
16+
namespace llvm {
17+
18+
class ModuleDebugInfoPrinterPass
19+
: public PassInfoMixin<ModuleDebugInfoPrinterPass> {
20+
DebugInfoFinder Finder;
21+
raw_ostream &OS;
22+
23+
public:
24+
explicit ModuleDebugInfoPrinterPass(raw_ostream &OS);
25+
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
26+
};
27+
} // end namespace llvm
28+
29+
#endif // LLVM_ANALYSIS_MODULEDEBUGINFOPRINTER_H

llvm/include/llvm/InitializePasses.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ void initializeMergeFunctionsLegacyPassPass(PassRegistry&);
306306
void initializeMergeICmpsLegacyPassPass(PassRegistry &);
307307
void initializeMergedLoadStoreMotionLegacyPassPass(PassRegistry&);
308308
void initializeMetaRenamerPass(PassRegistry&);
309-
void initializeModuleDebugInfoPrinterPass(PassRegistry&);
309+
void initializeModuleDebugInfoLegacyPrinterPass(PassRegistry &);
310310
void initializeModuleMemProfilerLegacyPassPass(PassRegistry &);
311311
void initializeModuleSummaryIndexWrapperPassPass(PassRegistry&);
312312
void initializeModuloScheduleTestPass(PassRegistry&);

llvm/lib/Analysis/Analysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void llvm::initializeAnalysis(PassRegistry &Registry) {
6363
initializeMemDepPrinterPass(Registry);
6464
initializeMemDerefPrinterPass(Registry);
6565
initializeMemoryDependenceWrapperPassPass(Registry);
66-
initializeModuleDebugInfoPrinterPass(Registry);
66+
initializeModuleDebugInfoLegacyPrinterPass(Registry);
6767
initializeModuleSummaryIndexWrapperPassPass(Registry);
6868
initializeMustExecutePrinterPass(Registry);
6969
initializeMustBeExecutedContextPrinterPass(Registry);

llvm/lib/Analysis/ModuleDebugInfoPrinter.cpp

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,46 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17+
#include "llvm/Analysis/ModuleDebugInfoPrinter.h"
1718
#include "llvm/ADT/Statistic.h"
1819
#include "llvm/Analysis/Passes.h"
1920
#include "llvm/IR/DebugInfo.h"
21+
#include "llvm/IR/PassManager.h"
2022
#include "llvm/InitializePasses.h"
2123
#include "llvm/Pass.h"
2224
#include "llvm/Support/ErrorHandling.h"
2325
#include "llvm/Support/raw_ostream.h"
2426
using namespace llvm;
2527

2628
namespace {
27-
class ModuleDebugInfoPrinter : public ModulePass {
28-
DebugInfoFinder Finder;
29-
public:
30-
static char ID; // Pass identification, replacement for typeid
31-
ModuleDebugInfoPrinter() : ModulePass(ID) {
32-
initializeModuleDebugInfoPrinterPass(*PassRegistry::getPassRegistry());
33-
}
29+
class ModuleDebugInfoLegacyPrinter : public ModulePass {
30+
DebugInfoFinder Finder;
3431

35-
bool runOnModule(Module &M) override;
32+
public:
33+
static char ID; // Pass identification, replacement for typeid
34+
ModuleDebugInfoLegacyPrinter() : ModulePass(ID) {
35+
initializeModuleDebugInfoLegacyPrinterPass(
36+
*PassRegistry::getPassRegistry());
37+
}
3638

37-
void getAnalysisUsage(AnalysisUsage &AU) const override {
38-
AU.setPreservesAll();
39-
}
40-
void print(raw_ostream &O, const Module *M) const override;
41-
};
39+
bool runOnModule(Module &M) override;
40+
41+
void getAnalysisUsage(AnalysisUsage &AU) const override {
42+
AU.setPreservesAll();
43+
}
44+
void print(raw_ostream &O, const Module *M) const override;
45+
};
4246
}
4347

44-
char ModuleDebugInfoPrinter::ID = 0;
45-
INITIALIZE_PASS(ModuleDebugInfoPrinter, "module-debuginfo",
48+
char ModuleDebugInfoLegacyPrinter::ID = 0;
49+
INITIALIZE_PASS(ModuleDebugInfoLegacyPrinter, "module-debuginfo",
4650
"Decodes module-level debug info", false, true)
4751

4852
ModulePass *llvm::createModuleDebugInfoPrinterPass() {
49-
return new ModuleDebugInfoPrinter();
53+
return new ModuleDebugInfoLegacyPrinter();
5054
}
5155

52-
bool ModuleDebugInfoPrinter::runOnModule(Module &M) {
56+
bool ModuleDebugInfoLegacyPrinter::runOnModule(Module &M) {
5357
Finder.processModule(M);
5458
return false;
5559
}
@@ -67,7 +71,8 @@ static void printFile(raw_ostream &O, StringRef Filename, StringRef Directory,
6771
O << ":" << Line;
6872
}
6973

70-
void ModuleDebugInfoPrinter::print(raw_ostream &O, const Module *M) const {
74+
static void printModuleDebugInfo(raw_ostream &O, const Module *M,
75+
const DebugInfoFinder &Finder) {
7176
// Printing the nodes directly isn't particularly helpful (since they
7277
// reference other nodes that won't be printed, particularly for the
7378
// filenames), so just print a few useful things.
@@ -126,3 +131,18 @@ void ModuleDebugInfoPrinter::print(raw_ostream &O, const Module *M) const {
126131
O << '\n';
127132
}
128133
}
134+
135+
void ModuleDebugInfoLegacyPrinter::print(raw_ostream &O,
136+
const Module *M) const {
137+
printModuleDebugInfo(O, M, Finder);
138+
}
139+
140+
ModuleDebugInfoPrinterPass::ModuleDebugInfoPrinterPass(raw_ostream &OS)
141+
: OS(OS) {}
142+
143+
PreservedAnalyses ModuleDebugInfoPrinterPass::run(Module &M,
144+
ModuleAnalysisManager &AM) {
145+
Finder.processModule(M);
146+
printModuleDebugInfo(OS, &M, Finder);
147+
return PreservedAnalyses::all();
148+
}

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "llvm/Analysis/LoopNestAnalysis.h"
5050
#include "llvm/Analysis/MemoryDependenceAnalysis.h"
5151
#include "llvm/Analysis/MemorySSA.h"
52+
#include "llvm/Analysis/ModuleDebugInfoPrinter.h"
5253
#include "llvm/Analysis/ModuleSummaryAnalysis.h"
5354
#include "llvm/Analysis/ObjCARCAliasAnalysis.h"
5455
#include "llvm/Analysis/OptimizationRemarkEmitter.h"

llvm/lib/Passes/PassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ MODULE_PASS("print", PrintModulePass(dbgs()))
8585
MODULE_PASS("print-lcg", LazyCallGraphPrinterPass(dbgs()))
8686
MODULE_PASS("print-lcg-dot", LazyCallGraphDOTPrinterPass(dbgs()))
8787
MODULE_PASS("print-stack-safety", StackSafetyGlobalPrinterPass(dbgs()))
88+
MODULE_PASS("print<module-debuginfo>", ModuleDebugInfoPrinterPass(dbgs()))
8889
MODULE_PASS("rewrite-statepoints-for-gc", RewriteStatepointsForGC())
8990
MODULE_PASS("rewrite-symbols", RewriteSymbolPass())
9091
MODULE_PASS("rpo-function-attrs", ReversePostOrderFunctionAttrsPass())

llvm/test/DebugInfo/Generic/debuginfofinder-forward-declaration.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
; RUN: opt -analyze -module-debuginfo < %s | FileCheck %s
1+
; RUN: opt -analyze -module-debuginfo -enable-new-pm=0 < %s | FileCheck %s
2+
; RUN: opt -passes='print<module-debuginfo>' -disable-output 2>&1 < %s \
3+
; RUN: | FileCheck %s
24

35
; This module is generated from the following c-code:
46
;

llvm/test/DebugInfo/Generic/debuginfofinder-imported-global-variable.ll

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
; RUN: opt -analyze -module-debuginfo < %s | FileCheck %s
1+
; RUN: opt -analyze -module-debuginfo -enable-new-pm=0 < %s | FileCheck %s
2+
; RUN: opt -passes='print<module-debuginfo>' -disable-output 2>&1 < %s \
3+
; RUN: | FileCheck %s
24

35
; This is to track DebugInfoFinder's ability to find the debug info metadata,
4-
; in particular, properly visit different kinds of DIImportedEntit'ies.
6+
; in particular, properly visit different kinds of DIImportedEntities.
57

68
; Derived from the following C++ snippet
79
;
@@ -13,7 +15,6 @@
1315
;
1416
; compiled with `clang -O1 -g3 -emit-llvm -S`
1517

16-
; CHECK: Printing analysis 'Decodes module-level debug info':
1718
; CHECK: Compile unit: DW_LANG_C_plus_plus from /somewhere/source.cpp
1819
; CHECK: Global variable: i from /somewhere/source.cpp:2 ('_ZN1s1iE')
1920
; CHECK: Type: int DW_ATE_signed

llvm/test/DebugInfo/Generic/debuginfofinder-inlined-cu.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
; RUN: opt -analyze -module-debuginfo < %s | FileCheck %s
1+
; RUN: opt -analyze -module-debuginfo -enable-new-pm=0 < %s | FileCheck %s
2+
; RUN: opt -passes='print<module-debuginfo>' -disable-output 2>&1 < %s \
3+
; RUN: | FileCheck %s
24

35
; Verify that both compile units, even though one compile units's functions
46
; were entirely inlined into the other.

llvm/test/DebugInfo/Generic/debuginfofinder-multiple-cu.ll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
; RUN: opt -analyze -module-debuginfo < %s | FileCheck %s
1+
; RUN: opt -analyze -module-debuginfo -enable-new-pm=0 < %s | FileCheck %s
2+
; RUN: opt -passes='print<module-debuginfo>' -disable-output 2>&1 < %s \
3+
; RUN: | FileCheck %s
24

35
; Produced from linking:
46
; /tmp/test1.c containing f()

0 commit comments

Comments
 (0)