23 changes: 3 additions & 20 deletions llvm/lib/CodeGen/TargetPassConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,6 @@ static cl::opt<cl::boolOrDefault> DebugifyAndStripAll(
"Debugify MIR before and Strip debug after "
"each pass except those known to be unsafe when debug info is present"),
cl::ZeroOrMore);
static cl::opt<cl::boolOrDefault> DebugifyCheckAndStripAll(
"debugify-check-and-strip-all-safe", cl::Hidden,
cl::desc(
"Debugify MIR before, by checking and stripping the debug info after, "
"each pass except those known to be unsafe when debug info is present"),
cl::ZeroOrMore);
enum RunOutliner { AlwaysOutline, NeverOutline, TargetDefault };
// Enable or disable the MachineOutliner.
static cl::opt<RunOutliner> EnableMachineOutliner(
Expand Down Expand Up @@ -631,26 +625,15 @@ void TargetPassConfig::addStripDebugPass() {
PM->add(createStripDebugMachineModulePass(/*OnlyDebugified=*/true));
}

void TargetPassConfig::addCheckDebugPass() {
PM->add(createCheckDebugMachineModulePass());
}

void TargetPassConfig::addMachinePrePasses(bool AllowDebugify) {
if (AllowDebugify && DebugifyIsSafe &&
(DebugifyAndStripAll == cl::BOU_TRUE ||
DebugifyCheckAndStripAll == cl::BOU_TRUE))
if (AllowDebugify && DebugifyAndStripAll == cl::BOU_TRUE && DebugifyIsSafe)
addDebugifyPass();
}

void TargetPassConfig::addMachinePostPasses(const std::string &Banner,
bool AllowVerify, bool AllowStrip) {
if (DebugifyIsSafe) {
if (DebugifyCheckAndStripAll == cl::BOU_TRUE) {
addCheckDebugPass();
addStripDebugPass();
} else if (DebugifyAndStripAll == cl::BOU_TRUE)
addStripDebugPass();
}
if (DebugifyAndStripAll == cl::BOU_TRUE && DebugifyIsSafe)
addStripDebugPass();
if (AllowVerify)
addVerifyPass(Banner);
}
Expand Down
40 changes: 9 additions & 31 deletions llvm/lib/Transforms/Utils/Debugify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ bool llvm::applyDebugifyMetadata(

DIBuilder DIB(M);
LLVMContext &Ctx = M.getContext();
auto *Int32Ty = Type::getInt32Ty(Ctx);

// Get a DIType which corresponds to Ty.
DenseMap<uint64_t, DIType *> TypeCache;
Expand All @@ -101,7 +100,6 @@ bool llvm::applyDebugifyMetadata(
if (isFunctionSkipped(F))
continue;

bool InsertedDbgVal = false;
auto SPType = DIB.createSubroutineType(DIB.getOrCreateTypeArray(None));
DISubprogram::DISPFlags SPFlags =
DISubprogram::SPFlagDefinition | DISubprogram::SPFlagOptimized;
Expand All @@ -110,23 +108,6 @@ bool llvm::applyDebugifyMetadata(
auto SP = DIB.createFunction(CU, F.getName(), F.getName(), File, NextLine,
SPType, NextLine, DINode::FlagZero, SPFlags);
F.setSubprogram(SP);

// Helper that inserts a dbg.value before \p InsertBefore, copying the
// location (and possibly the type, if it's non-void) from \p TemplateInst.
auto insertDbgVal = [&](Instruction &TemplateInst,
Instruction *InsertBefore) {
std::string Name = utostr(NextVar++);
Value *V = &TemplateInst;
if (TemplateInst.getType()->isVoidTy())
V = ConstantInt::get(Int32Ty, 0);
const DILocation *Loc = TemplateInst.getDebugLoc().get();
auto LocalVar = DIB.createAutoVariable(SP, Name, File, Loc->getLine(),
getCachedDIType(V->getType()),
/*AlwaysPreserve=*/true);
DIB.insertDbgValueIntrinsic(V, LocalVar, DIB.createExpression(), Loc,
InsertBefore);
};

for (BasicBlock &BB : F) {
// Attach debug locations.
for (Instruction &I : BB)
Expand Down Expand Up @@ -161,19 +142,15 @@ bool llvm::applyDebugifyMetadata(
if (!isa<PHINode>(I) && !I->isEHPad())
InsertBefore = I->getNextNode();

insertDbgVal(*I, InsertBefore);
InsertedDbgVal = true;
std::string Name = utostr(NextVar++);
const DILocation *Loc = I->getDebugLoc().get();
auto LocalVar = DIB.createAutoVariable(SP, Name, File, Loc->getLine(),
getCachedDIType(I->getType()),
/*AlwaysPreserve=*/true);
DIB.insertDbgValueIntrinsic(I, LocalVar, DIB.createExpression(), Loc,
InsertBefore);
}
}
// Make sure we emit at least one dbg.value, otherwise MachineDebugify may
// not have anything to work with as it goes about inserting DBG_VALUEs.
// (It's common for MIR tests to be written containing skeletal IR with
// empty functions -- we're still interested in debugifying the MIR within
// those tests, and this helps with that.)
if (DebugifyLevel == Level::LocationsAndVariables && !InsertedDbgVal) {
auto *Term = findTerminatingInstruction(F.getEntryBlock());
insertDbgVal(*Term, Term);
}
if (ApplyToMF)
ApplyToMF(DIB, F);
DIB.finalizeSubprogram(SP);
Expand All @@ -182,9 +159,10 @@ bool llvm::applyDebugifyMetadata(

// Track the number of distinct lines and variables.
NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.debugify");
auto *IntTy = Type::getInt32Ty(Ctx);
auto addDebugifyOperand = [&](unsigned N) {
NMD->addOperand(MDNode::get(
Ctx, ValueAsMetadata::getConstant(ConstantInt::get(Int32Ty, N))));
Ctx, ValueAsMetadata::getConstant(ConstantInt::get(IntTy, N))));
};
addDebugifyOperand(NextLine - 1); // Original number of lines.
addDebugifyOperand(NextVar - 1); // Original number of variables.
Expand Down
33 changes: 0 additions & 33 deletions llvm/test/CodeGen/AArch64/GlobalISel/constant-mir-debugify.mir

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -debugify-and-strip-all-safe -O0 -mtriple=aarch64-unknown-unknown -verify-machineinstrs -run-pass=legalizer %s -o - | FileCheck %s
# RUN: llc -O0 -mtriple=aarch64-unknown-unknown -verify-machineinstrs -run-pass=legalizer %s -o - | FileCheck %s
--- |
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"

Expand Down
106 changes: 0 additions & 106 deletions llvm/test/CodeGen/AArch64/GlobalISel/phi-mir-debugify.mir

This file was deleted.

This file was deleted.

29 changes: 0 additions & 29 deletions llvm/test/CodeGen/Generic/MIRDebugify/check-line-and-variables.ll

This file was deleted.

69 changes: 0 additions & 69 deletions llvm/test/CodeGen/Generic/MIRDebugify/check-line-and-variables.mir

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
ret i32 %sub
}

; ALL: !llvm.dbg.cu = !{![[CU:[0-9]+]]}
; ALL: !llvm.debugify =
; ALL: !llvm.module.flags = !{![[VERSION:[0-9]+]]}
; ALL: ![[CU]] = distinct !DICompileUnit(
; ALL: ![[VERSION]] = !{i32 2, !"Debug Info Version", i32 3}
; VALUE: [[VAR1:![0-9]+]] = !DILocalVariable(name: "1"
; VALUE: [[VAR2:![0-9]+]] = !DILocalVariable(name: "2"
; CHECK: !llvm.dbg.cu = !{!0}
; CHECK: !llvm.debugify =
; CHECK: !llvm.module.flags = !{![[VERSION:[0-9]+]]}
; CHECK: !0 = distinct !DICompileUnit(
; CHECK: ![[VERSION]] = !{i32 2, !"Debug Info Version", i32 3}

...
---
Expand All @@ -39,13 +37,8 @@ body: |
; source file anyway. These first three coincide with IR-level information
; and therefore use metadata references.
; ALL: %0:_(s32) = IMPLICIT_DEF debug-location [[L1]]
; VALUE: DBG_VALUE %0(s32), $noreg, [[VAR1]], !DIExpression(), debug-location [[L1]]
; ALL: %1:_(s32) = IMPLICIT_DEF debug-location [[L2]]
; VALUE: DBG_VALUE %1(s32), $noreg, [[VAR2]], !DIExpression(), debug-location [[L2]]
; ALL: %2:_(s32) = G_CONSTANT i32 2, debug-location [[L3]]
; VALUE: DBG_VALUE %2(s32), $noreg, [[VAR1]], !DIExpression(), debug-location [[L3]]
; ALL: %3:_(s32) = G_ADD %0, %2, debug-location !DILocation(line: 4, column: 1, scope: [[SP:![0-9]+]])
; VALUE: DBG_VALUE %3(s32), $noreg, [[VAR1]], !DIExpression(), debug-location !DILocation(line: 4
; ALL: %4:_(s32) = G_SUB %3, %1, debug-location !DILocation(line: 5, column: 1, scope: [[SP]])
; VALUE: DBG_VALUE %4(s32), $noreg, [[VAR1]], !DIExpression(), debug-location !DILocation(line: 5
; ALL: %3:_(s32) = G_ADD %0, %2, debug-location !DILocation(line: 4, column: 1, scope: !6)
; ALL: %4:_(s32) = G_SUB %3, %1, debug-location !DILocation(line: 5, column: 1, scope: !6)
...
6 changes: 2 additions & 4 deletions llvm/test/DebugInfo/debugify.ll
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,11 @@ define i32 @boom() {

; --- DILocalVariables
; CHECK-DAG: ![[TY32:.*]] = !DIBasicType(name: "ty32", size: 32, encoding: DW_ATE_unsigned)
; CHECK-DAG: !DILocalVariable(name: "1", scope: {{.*}}, file: {{.*}}, line: 1, type: ![[TY32]])
; CHECK-DAG: !DILocalVariable(name: "2", scope: {{.*}}, file: {{.*}}, line: 3, type: ![[TY32]])
; CHECK-DAG: !DILocalVariable(name: "3", scope: {{.*}}, file: {{.*}}, line: 5, type: ![[TY32]])
; CHECK-DAG: !DILocalVariable(name: "1", scope: {{.*}}, file: {{.*}}, line: 3, type: ![[TY32]])

; --- Metadata counts
; CHECK-DAG: ![[NUM_INSTS]] = !{i32 6}
; CHECK-DAG: ![[NUM_VARS]] = !{i32 3}
; CHECK-DAG: ![[NUM_VARS]] = !{i32 1}

; --- Repeat case
; CHECK-REPEAT: ModuleDebugify: Skipping module with debug info
Expand Down
1 change: 0 additions & 1 deletion llvm/utils/gn/secondary/llvm/lib/CodeGen/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ static_library("CodeGen") {
"MachineBlockPlacement.cpp",
"MachineBranchProbabilityInfo.cpp",
"MachineCSE.cpp",
"MachineCheckDebugify.cpp",
"MachineCombiner.cpp",
"MachineCopyPropagation.cpp",
"MachineDebugify.cpp",
Expand Down