[llvm] dfca98d - [mir-strip-debug] Optionally preserve debug info that wasn't from debugify/mir-debugify
Daniel Sanders via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 10 15:24:27 PDT 2020
Author: Daniel Sanders
Date: 2020-04-10T15:24:14-07:00
New Revision: dfca98d6a83c725db38a20c06df92f1b2b9ce16b
URL: https://github.com/llvm/llvm-project/commit/dfca98d6a83c725db38a20c06df92f1b2b9ce16b
DIFF: https://github.com/llvm/llvm-project/commit/dfca98d6a83c725db38a20c06df92f1b2b9ce16b.diff
LOG: [mir-strip-debug] Optionally preserve debug info that wasn't from debugify/mir-debugify
Summary:
A few tests start out with debug info and expect it to reach
the output. For these tests we shouldn't strip the debug info
Reviewers: aprantl, vsk, bogner
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D77886
Added:
llvm/test/CodeGen/Generic/MIRStripDebug/dont-strip-real-debug-info.mir
Modified:
llvm/include/llvm/CodeGen/Passes.h
llvm/lib/CodeGen/MachineStripDebug.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/Passes.h b/llvm/include/llvm/CodeGen/Passes.h
index 2d76def4f2d4..7c9510ba3fae 100644
--- a/llvm/include/llvm/CodeGen/Passes.h
+++ b/llvm/include/llvm/CodeGen/Passes.h
@@ -477,7 +477,10 @@ namespace llvm {
ModulePass *createDebugifyMachineModulePass();
/// Creates MIR Strip Debug pass. \see MachineStripDebug.cpp
- ModulePass *createStripDebugMachineModulePass();
+ /// If OnlyDebugified is true then it will only strip debug info if it was
+ /// added by a Debugify pass. The module will be left unchanged if the debug
+ /// info was generated by another source such as clang.
+ ModulePass *createStripDebugMachineModulePass(bool OnlyDebugified);
/// The pass fixups statepoint machine instruction to replace usage of
/// caller saved registers with stack slots.
diff --git a/llvm/lib/CodeGen/MachineStripDebug.cpp b/llvm/lib/CodeGen/MachineStripDebug.cpp
index 012971874cb5..aeb2789c28c1 100644
--- a/llvm/lib/CodeGen/MachineStripDebug.cpp
+++ b/llvm/lib/CodeGen/MachineStripDebug.cpp
@@ -15,15 +15,30 @@
#include "llvm/CodeGen/Passes.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/InitializePasses.h"
+#include "llvm/Support/CommandLine.h"
#define DEBUG_TYPE "mir-strip-debug"
using namespace llvm;
namespace {
+cl::opt<bool>
+ OnlyDebugifiedDefault("mir-strip-debugify-only",
+ cl::desc("Should mir-strip-debug only strip debug "
+ "info from debugified modules by default"),
+ cl::init(true));
struct StripDebugMachineModule : public ModulePass {
bool runOnModule(Module &M) override {
+ if (OnlyDebugified) {
+ NamedMDNode *DebugifyMD = M.getNamedMetadata("llvm.debugify");
+ if (!DebugifyMD) {
+ LLVM_DEBUG(dbgs() << "Not stripping debug info"
+ " (debugify metadata not found)?\n");
+ return false;
+ }
+ }
+
MachineModuleInfo &MMI =
getAnalysis<MachineModuleInfoWrapperPass>().getMMI();
@@ -89,7 +104,9 @@ struct StripDebugMachineModule : public ModulePass {
return Changed;
}
- StripDebugMachineModule() : ModulePass(ID) {}
+ StripDebugMachineModule() : StripDebugMachineModule(OnlyDebugifiedDefault) {}
+ StripDebugMachineModule(bool OnlyDebugified)
+ : ModulePass(ID), OnlyDebugified(OnlyDebugified) {}
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.addRequired<MachineModuleInfoWrapperPass>();
@@ -97,6 +114,9 @@ struct StripDebugMachineModule : public ModulePass {
}
static char ID; // Pass identification.
+
+protected:
+ bool OnlyDebugified;
};
char StripDebugMachineModule::ID = 0;
@@ -107,6 +127,6 @@ INITIALIZE_PASS_BEGIN(StripDebugMachineModule, DEBUG_TYPE,
INITIALIZE_PASS_END(StripDebugMachineModule, DEBUG_TYPE,
"Machine Strip Debug Module", false, false)
-ModulePass *createStripDebugMachineModulePass() {
- return new StripDebugMachineModule();
+ModulePass *createStripDebugMachineModulePass(bool OnlyDebugified) {
+ return new StripDebugMachineModule(OnlyDebugified);
}
diff --git a/llvm/test/CodeGen/Generic/MIRStripDebug/dont-strip-real-debug-info.mir b/llvm/test/CodeGen/Generic/MIRStripDebug/dont-strip-real-debug-info.mir
new file mode 100644
index 000000000000..860cb9731ae8
--- /dev/null
+++ b/llvm/test/CodeGen/Generic/MIRStripDebug/dont-strip-real-debug-info.mir
@@ -0,0 +1,86 @@
+# RUN: llc -run-pass=mir-strip-debug -o - %s | FileCheck %s
+# RUN: llc -run-pass=mir-strip-debug,mir-debugify,mir-strip-debug -o - %s | FileCheck %s
+--- |
+ ; ModuleID = 'loc-only.ll'
+ source_filename = "loc-only.ll"
+
+ define i32 @test(i32 %a, i32 %b) !dbg !4 {
+ %add = add i32 %a, 2, !dbg !10
+ call void @llvm.dbg.value(metadata i32 %add, metadata !7, metadata !DIExpression()), !dbg !10
+ %sub = sub i32 %add, %b, !dbg !11
+ call void @llvm.dbg.value(metadata i32 %sub, metadata !9, metadata !DIExpression()), !dbg !11
+ ret i32 %sub, !dbg !12
+ }
+ ; CHECK-LABEL: define i32 @test(i32 %a, i32 %b) !dbg !4 {
+ ; CHECK-NEXT: %add = add i32 %a, 2, !dbg !10
+ ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %add, metadata !7, metadata !DIExpression()), !dbg !10
+ ; CHECK-NEXT: %sub = sub i32 %add, %b, !dbg !11
+ ; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %sub, metadata !9, metadata !DIExpression()), !dbg !11
+ ; CHECK-NEXT: ret i32 %sub, !dbg !12
+ ; CHECK-NEXT: }
+
+ ; Function Attrs: nounwind readnone speculatable willreturn
+ declare void @llvm.dbg.value(metadata, metadata, metadata) #0
+
+ ; Function Attrs: nounwind
+ declare void @llvm.stackprotector(i8*, i8**) #1
+
+ attributes #0 = { nounwind readnone speculatable willreturn }
+ attributes #1 = { nounwind }
+
+ !llvm.dbg.cu = !{!0}
+ ; CHECK: !llvm.dbg.cu = !{!0}
+ !llvm.module.flags = !{!3}
+ ; CHECK: !llvm.module.flags = !{!3}
+
+ !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+ !1 = !DIFile(filename: "<stdin>", directory: "/")
+ !2 = !{}
+ !3 = !{i32 2, !"Debug Info Version", i32 3}
+ !4 = distinct !DISubprogram(name: "test", linkageName: "test", scope: null, file: !1, line: 1, type: !5, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !6)
+ !5 = !DISubroutineType(types: !2)
+ !6 = !{!7, !9}
+ !7 = !DILocalVariable(name: "1", scope: !4, file: !1, line: 1, type: !8)
+ !8 = !DIBasicType(name: "ty32", size: 32, encoding: DW_ATE_unsigned)
+ !9 = !DILocalVariable(name: "2", scope: !4, file: !1, line: 2, type: !8)
+ !10 = !DILocation(line: 1, column: 1, scope: !4)
+ !11 = !DILocation(line: 2, column: 1, scope: !4)
+ !12 = !DILocation(line: 3, column: 1, scope: !4)
+
+ ; CHECK: !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+ ; CHECK: !1 = !DIFile(filename: "<stdin>", directory: "/")
+ ; CHECK: !2 = !{}
+ ; CHECK: !3 = !{i32 2, !"Debug Info Version", i32 3}
+ ; CHECK: !4 = distinct !DISubprogram(name: "test", linkageName: "test", scope: null, file: !1, line: 1, type: !5, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !6)
+ ; CHECK: !5 = !DISubroutineType(types: !2)
+ ; CHECK: !6 = !{!7, !9}
+ ; CHECK: !7 = !DILocalVariable(name: "1", scope: !4, file: !1, line: 1, type: !8)
+ ; CHECK: !8 = !DIBasicType(name: "ty32", size: 32, encoding: DW_ATE_unsigned)
+ ; CHECK: !9 = !DILocalVariable(name: "2", scope: !4, file: !1, line: 2, type: !8)
+ ; CHECK: !10 = !DILocation(line: 1, column: 1, scope: !4)
+ ; CHECK: !11 = !DILocation(line: 2, column: 1, scope: !4)
+ ; CHECK: !12 = !DILocation(line: 3, column: 1, scope: !4)
+
+...
+---
+name: test
+body: |
+ bb.1 (%ir-block.0):
+ %0:_(s32) = G_IMPLICIT_DEF
+ %1:_(s32) = G_IMPLICIT_DEF
+ %2:_(s32) = G_CONSTANT i32 2, debug-location !DILocation(line: 0, scope: !4)
+ %3:_(s32) = G_ADD %0, %2, debug-location !10
+ DBG_VALUE %3(s32), $noreg, !7, !DIExpression(), debug-location !10
+ %4:_(s32) = G_SUB %3, %1, debug-location !11
+ DBG_VALUE %4(s32), $noreg, !9, !DIExpression(), debug-location !11
+
+ ; CHECK-LABEL: body:
+ ; CHECK-NEXT: bb
+ ; CHECK-NEXT: %0:_(s32) = G_IMPLICIT_DEF{{$}}
+ ; CHECK-NEXT: %1:_(s32) = G_IMPLICIT_DEF{{$}}
+ ; CHECK-NEXT: %2:_(s32) = G_CONSTANT i32 2, debug-location !DILocation(line: 0, scope: !4)
+ ; CHECK-NEXT: %3:_(s32) = G_ADD %0, %2, debug-location !10
+ ; CHECK-NEXT: DBG_VALUE %3(s32), $noreg, !7, !DIExpression(), debug-location !10
+ ; CHECK-NEXT: %4:_(s32) = G_SUB %3, %1, debug-location !11
+ ; CHECK-NEXT: DBG_VALUE %4(s32), $noreg, !9, !DIExpression(), debug-location !11
+...
More information about the llvm-commits
mailing list