Skip to content

Commit 775c7af

Browse files
committed
[opt] Port the debugify passes to the new pass manager
llvm-svn: 325294
1 parent f884cd4 commit 775c7af

File tree

6 files changed

+60
-7
lines changed

6 files changed

+60
-7
lines changed

llvm/test/DebugInfo/debugify.ll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
; RUN: opt -debugify -S -o - < %s | FileCheck %s
2+
; RUN: opt -passes=debugify -S -o - < %s | FileCheck %s
23

34
; RUN: opt -debugify -debugify -S -o - < %s 2>&1 | \
45
; RUN: FileCheck %s -check-prefix=CHECK-REPEAT
6+
; RUN: opt -passes=debugify,debugify -S -o - < %s 2>&1 | \
7+
; RUN: FileCheck %s -check-prefix=CHECK-REPEAT
58

69
; RUN: opt -debugify -check-debugify -S -o - < %s | \
710
; RUN: FileCheck %s -implicit-check-not="CheckDebugify: FAIL"
11+
; RUN: opt -passes=debugify,check-debugify -S -o - < %s | \
12+
; RUN: FileCheck %s -implicit-check-not="CheckDebugify: FAIL"
13+
; RUN: opt -enable-debugify -passes=verify -S -o - < %s | \
14+
; RUN: FileCheck %s -implicit-check-not="CheckDebugify: FAIL"
815

916
; RUN: opt -debugify -strip -check-debugify -S -o - < %s | \
1017
; RUN: FileCheck %s -check-prefix=CHECK-FAIL

llvm/tools/opt/Debugify.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
///
1313
//===----------------------------------------------------------------------===//
1414

15+
#include "PassPrinters.h"
1516
#include "llvm/ADT/BitVector.h"
1617
#include "llvm/ADT/StringExtras.h"
1718
#include "llvm/IR/BasicBlock.h"
@@ -206,8 +207,19 @@ struct CheckDebugifyPass : public ModulePass {
206207

207208
ModulePass *createDebugifyPass() { return new DebugifyPass(); }
208209

210+
PreservedAnalyses NewPMDebugifyPass::run(Module &M, ModuleAnalysisManager &) {
211+
applyDebugifyMetadata(M);
212+
return PreservedAnalyses::all();
213+
}
214+
209215
ModulePass *createCheckDebugifyPass() { return new CheckDebugifyPass(); }
210216

217+
PreservedAnalyses NewPMCheckDebugifyPass::run(Module &M,
218+
ModuleAnalysisManager &) {
219+
checkDebugifyMetadata(M);
220+
return PreservedAnalyses::all();
221+
}
222+
211223
char DebugifyPass::ID = 0;
212224
static RegisterPass<DebugifyPass> X("debugify",
213225
"Attach debug info to everything");

llvm/tools/opt/NewPMDriver.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
//===----------------------------------------------------------------------===//
1515

1616
#include "NewPMDriver.h"
17+
#include "PassPrinters.h"
1718
#include "llvm/ADT/StringRef.h"
1819
#include "llvm/Analysis/AliasAnalysis.h"
1920
#include "llvm/Analysis/CGSCCPassManager.h"
@@ -185,7 +186,8 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
185186
VerifierKind VK,
186187
bool ShouldPreserveAssemblyUseListOrder,
187188
bool ShouldPreserveBitcodeUseListOrder,
188-
bool EmitSummaryIndex, bool EmitModuleHash) {
189+
bool EmitSummaryIndex, bool EmitModuleHash,
190+
bool EnableDebugify) {
189191
bool VerifyEachPass = VK == VK_VerifyEachPass;
190192

191193
Optional<PGOOptions> P;
@@ -208,6 +210,20 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
208210
PassBuilder PB(TM, P);
209211
registerEPCallbacks(PB, VerifyEachPass, DebugPM);
210212

213+
// Register a callback that creates the debugify passes as needed.
214+
PB.registerPipelineParsingCallback(
215+
[](StringRef Name, ModulePassManager &MPM,
216+
ArrayRef<PassBuilder::PipelineElement>) {
217+
if (Name == "debugify") {
218+
MPM.addPass(NewPMDebugifyPass());
219+
return true;
220+
} else if (Name == "check-debugify") {
221+
MPM.addPass(NewPMCheckDebugifyPass());
222+
return true;
223+
}
224+
return false;
225+
});
226+
211227
#ifdef LINK_POLLY_INTO_TOOLS
212228
polly::RegisterPollyPasses(PB);
213229
#endif
@@ -238,6 +254,8 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
238254
ModulePassManager MPM(DebugPM);
239255
if (VK > VK_NoVerifier)
240256
MPM.addPass(VerifierPass());
257+
if (EnableDebugify)
258+
MPM.addPass(NewPMDebugifyPass());
241259

242260
if (!PB.parsePassPipeline(MPM, PassPipeline, VerifyEachPass, DebugPM)) {
243261
errs() << Arg0 << ": unable to parse pass pipeline description.\n";
@@ -246,6 +264,8 @@ bool llvm::runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
246264

247265
if (VK > VK_NoVerifier)
248266
MPM.addPass(VerifierPass());
267+
if (EnableDebugify)
268+
MPM.addPass(NewPMCheckDebugifyPass());
249269

250270
// Add any relevant output pass at the end of the pipeline.
251271
switch (OK) {

llvm/tools/opt/NewPMDriver.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ bool runPassPipeline(StringRef Arg0, Module &M, TargetMachine *TM,
5757
opt_tool::OutputKind OK, opt_tool::VerifierKind VK,
5858
bool ShouldPreserveAssemblyUseListOrder,
5959
bool ShouldPreserveBitcodeUseListOrder,
60-
bool EmitSummaryIndex, bool EmitModuleHash);
61-
}
60+
bool EmitSummaryIndex, bool EmitModuleHash,
61+
bool EnableDebugify);
62+
} // namespace llvm
6263

6364
#endif

llvm/tools/opt/PassPrinters.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#ifndef LLVM_TOOLS_OPT_PASSPRINTERS_H
1616
#define LLVM_TOOLS_OPT_PASSPRINTERS_H
1717

18+
#include "llvm/IR/PassManager.h"
19+
1820
namespace llvm {
1921

2022
class BasicBlockPass;
@@ -25,6 +27,7 @@ class LoopPass;
2527
class PassInfo;
2628
class raw_ostream;
2729
class RegionPass;
30+
class Module;
2831

2932
FunctionPass *createFunctionPassPrinter(const PassInfo *PI, raw_ostream &out,
3033
bool Quiet);
@@ -46,4 +49,17 @@ BasicBlockPass *createBasicBlockPassPrinter(const PassInfo *PI,
4649

4750
} // end namespace llvm
4851

52+
llvm::ModulePass *createDebugifyPass();
53+
54+
struct NewPMDebugifyPass : public llvm::PassInfoMixin<NewPMDebugifyPass> {
55+
llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &AM);
56+
};
57+
58+
llvm::ModulePass *createCheckDebugifyPass();
59+
60+
struct NewPMCheckDebugifyPass
61+
: public llvm::PassInfoMixin<NewPMCheckDebugifyPass> {
62+
llvm::PreservedAnalyses run(llvm::Module &M, llvm::ModuleAnalysisManager &AM);
63+
};
64+
4965
#endif // LLVM_TOOLS_OPT_PASSPRINTERS_H

llvm/tools/opt/opt.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,6 @@ static cl::opt<std::string>
257257
cl::desc("YAML output filename for pass remarks"),
258258
cl::value_desc("filename"));
259259

260-
extern ModulePass *createDebugifyPass();
261-
extern ModulePass *createCheckDebugifyPass();
262-
263260
static inline void addPass(legacy::PassManagerBase &PM, Pass *P) {
264261
// Add the pass to the pass manager...
265262
PM.add(P);
@@ -555,7 +552,7 @@ int main(int argc, char **argv) {
555552
OptRemarkFile.get(), PassPipeline, OK, VK,
556553
PreserveAssemblyUseListOrder,
557554
PreserveBitcodeUseListOrder, EmitSummaryIndex,
558-
EmitModuleHash)
555+
EmitModuleHash, EnableDebugify)
559556
? 0
560557
: 1;
561558
}

0 commit comments

Comments
 (0)