[llvm] 0fbb261 - [llvm-reduce] Attempt to strip debug info
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 21 09:14:46 PDT 2022
Author: Arthur Eubanks
Date: 2022-10-21T09:11:58-07:00
New Revision: 0fbb261536a479c38a7bc26528b3f6984bfd4d84
URL: https://github.com/llvm/llvm-project/commit/0fbb261536a479c38a7bc26528b3f6984bfd4d84
DIFF: https://github.com/llvm/llvm-project/commit/0fbb261536a479c38a7bc26528b3f6984bfd4d84.diff
LOG: [llvm-reduce] Attempt to strip debug info
I often run llvm-reduce on IR that contains debug info, this prevents an
extra step of `opt -passes=strip` I do every time and will result in a
lot less invalid reductions around debug metadata.
Reviewed By: dblaikie
Differential Revision: https://reviews.llvm.org/D136208
Added:
llvm/test/tools/llvm-reduce/strip-debug-info.ll
llvm/tools/llvm-reduce/deltas/StripDebugInfo.cpp
llvm/tools/llvm-reduce/deltas/StripDebugInfo.h
Modified:
llvm/tools/llvm-reduce/CMakeLists.txt
llvm/tools/llvm-reduce/DeltaManager.cpp
llvm/utils/gn/secondary/llvm/tools/llvm-reduce/BUILD.gn
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-reduce/strip-debug-info.ll b/llvm/test/tools/llvm-reduce/strip-debug-info.ll
new file mode 100644
index 0000000000000..df34f686b33a3
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/strip-debug-info.ll
@@ -0,0 +1,39 @@
+; RUN: llvm-reduce --abort-on-invalid-reduction --delta-passes=strip-debug-info --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
+; RUN: FileCheck --check-prefix=CHECK-FINAL %s --input-file=%t
+
+; CHECK-INTERESTINGNESS: define i32 @main
+; CHECK-FINAL: define i32 @main
+; CHECK-FINAL-NOT: !dbg
+; CHECK-FINAL-NOT: call {{.*}}llvm.dbg
+; CHECK-FINAL-NOT: !llvm.dbg
+; CHECK-FINAL-NOT: = !DI
+
+define i32 @main() !dbg !4 {
+entry:
+ %retval = alloca i32, align 4
+ %a = alloca i8, align 1
+ store i32 0, ptr %retval, align 4
+ call void @llvm.dbg.declare(metadata ptr %a, metadata !10, metadata !DIExpression()), !dbg !12
+ store i8 0, ptr %a, align 1, !dbg !12
+ ret i32 0, !dbg !13
+}
+
+declare void @llvm.dbg.declare(metadata, metadata, metadata)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 16.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "/tmp/a.c", directory: "/tmp", checksumkind: CSK_MD5, checksum: "2ed6e287521b82331926229153026511")
+!2 = !{i32 7, !"Dwarf Version", i32 5}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = distinct !DISubprogram(name: "main", scope: !5, file: !5, line: 4, type: !6, scopeLine: 4, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !9)
+!5 = !DIFile(filename: "/tmp/a.c", directory: "", checksumkind: CSK_MD5, checksum: "2ed6e287521b82331926229153026511")
+!6 = !DISubroutineType(types: !7)
+!7 = !{!8}
+!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!9 = !{}
+!10 = !DILocalVariable(name: "a", scope: !4, file: !5, line: 6, type: !11)
+!11 = !DIBasicType(name: "_Bool", size: 8, encoding: DW_ATE_boolean)
+!12 = !DILocation(line: 6, column: 8, scope: !4)
+!13 = !DILocation(line: 7, column: 2, scope: !4)
diff --git a/llvm/tools/llvm-reduce/CMakeLists.txt b/llvm/tools/llvm-reduce/CMakeLists.txt
index 6f70806eee0fd..f6b485deb1020 100644
--- a/llvm/tools/llvm-reduce/CMakeLists.txt
+++ b/llvm/tools/llvm-reduce/CMakeLists.txt
@@ -54,6 +54,7 @@ add_llvm_tool(llvm-reduce
deltas/ReduceUsingSimplifyCFG.cpp
deltas/RunIRPasses.cpp
deltas/SimplifyInstructions.cpp
+ deltas/StripDebugInfo.cpp
llvm-reduce.cpp
DEPENDS
diff --git a/llvm/tools/llvm-reduce/DeltaManager.cpp b/llvm/tools/llvm-reduce/DeltaManager.cpp
index e544d27878ae2..f6b309d87e4dc 100644
--- a/llvm/tools/llvm-reduce/DeltaManager.cpp
+++ b/llvm/tools/llvm-reduce/DeltaManager.cpp
@@ -45,6 +45,7 @@
#include "deltas/ReduceVirtualRegisters.h"
#include "deltas/RunIRPasses.h"
#include "deltas/SimplifyInstructions.h"
+#include "deltas/StripDebugInfo.h"
#include "llvm/Support/CommandLine.h"
using namespace llvm;
@@ -66,6 +67,7 @@ static cl::list<std::string>
#define DELTA_PASSES \
do { \
+ DELTA_PASS("strip-debug-info", stripDebugInfoDeltaPass) \
DELTA_PASS("functions", reduceFunctionsDeltaPass) \
DELTA_PASS("function-bodies", reduceFunctionBodiesDeltaPass) \
DELTA_PASS("special-globals", reduceSpecialGlobalsDeltaPass) \
diff --git a/llvm/tools/llvm-reduce/deltas/StripDebugInfo.cpp b/llvm/tools/llvm-reduce/deltas/StripDebugInfo.cpp
new file mode 100644
index 0000000000000..efb02332bee91
--- /dev/null
+++ b/llvm/tools/llvm-reduce/deltas/StripDebugInfo.cpp
@@ -0,0 +1,28 @@
+//===- StripDebugInfo.cpp -------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "StripDebugInfo.h"
+#include "Delta.h"
+#include "llvm/IR/DebugInfo.h"
+#include "llvm/IR/Metadata.h"
+
+using namespace llvm;
+
+/// Removes all aliases aren't inside any of the
+/// desired Chunks.
+static void stripDebugInfoImpl(Oracle &O, Module &Program) {
+ bool HasDebugInfo = any_of(Program.named_metadata(), [](NamedMDNode &NMD) {
+ return NMD.getName().startswith("llvm.dbg.");
+ });
+ if (HasDebugInfo && !O.shouldKeep())
+ StripDebugInfo(Program);
+}
+
+void llvm::stripDebugInfoDeltaPass(TestRunner &Test) {
+ runDeltaPass(Test, stripDebugInfoImpl, "Stripping Debug Info");
+}
diff --git a/llvm/tools/llvm-reduce/deltas/StripDebugInfo.h b/llvm/tools/llvm-reduce/deltas/StripDebugInfo.h
new file mode 100644
index 0000000000000..56be459546e94
--- /dev/null
+++ b/llvm/tools/llvm-reduce/deltas/StripDebugInfo.h
@@ -0,0 +1,18 @@
+//===- StripDebugInfo.h -----------------------------------------*- C++ -*-===//
+//
+// 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_TOOLS_LLVM_REDUCE_DELTAS_STRIPDEBUGINFO_H
+#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_STRIPDEBUGINFO_H
+
+#include "Delta.h"
+
+namespace llvm {
+void stripDebugInfoDeltaPass(TestRunner &Test);
+} // namespace llvm
+
+#endif
diff --git a/llvm/utils/gn/secondary/llvm/tools/llvm-reduce/BUILD.gn b/llvm/utils/gn/secondary/llvm/tools/llvm-reduce/BUILD.gn
index 3fb2b1d1cd3b8..ac89f21b931c2 100644
--- a/llvm/utils/gn/secondary/llvm/tools/llvm-reduce/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/tools/llvm-reduce/BUILD.gn
@@ -46,6 +46,7 @@ executable("llvm-reduce") {
"deltas/ReduceVirtualRegisters.cpp",
"deltas/RunIRPasses.cpp",
"deltas/SimplifyInstructions.cpp",
+ "deltas/StripDebugInfo.cpp",
"deltas/Utils.cpp",
"llvm-reduce.cpp",
]
More information about the llvm-commits
mailing list