Skip to content

Commit 40bdfd3

Browse files
authored
[llvm-reduce][DebugInfo] Support reducing non-instruction debug-info (#78995)
LLVM will shortly be able to represent variable locations without encoding information into intrinsics -- they'll be stored as DPValue objects instead. We'll still need to be able to llvm-reduce these variable location assignments just like we can with intrinsics today, thus, here's an llvm-reduce pass that enumerates and reduces the DPValue objects. The test for this is paradoxically written with dbg.value intrinsics: this is because we're changing all the core parts of LLVM to support this first, with the textual IR format coming last. Until that arrives, testing the llvm-reduce'ing of DPValues needs the added test using intrinsics. We should be able to drop the variable assignment using %alsoloaded using this method. As with the other llvm-reduce tests, I've got one set of check lines for making the reduction happen as desired, and the other set to check the final output.
1 parent 30845e8 commit 40bdfd3

File tree

6 files changed

+140
-2
lines changed

6 files changed

+140
-2
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
; RUN: llvm-reduce --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t --try-experimental-debuginfo-iterators
2+
; RUN: FileCheck --check-prefixes=CHECK-FINAL --input-file=%t %s --implicit-check-not=dbg.value
3+
4+
; Test that we can, in RemoveDIs mode / DPValues mode (where variable location
5+
; information isn't an instruction), remove one variable location assignment
6+
; but not another.
7+
8+
; CHECK-INTERESTINGNESS: call void @llvm.dbg.value(metadata i32 %added,
9+
10+
; CHECK-FINAL: declare void @llvm.dbg.value(metadata,
11+
; CHECK-FINAL: %added = add
12+
; CHECK-FINAL-NEXT: call void @llvm.dbg.value(metadata i32 %added,
13+
14+
declare void @llvm.dbg.value(metadata, metadata, metadata)
15+
16+
define i32 @main() !dbg !7 {
17+
entry:
18+
%uninteresting1 = alloca i32, align 4
19+
%interesting = alloca i32, align 4
20+
%uninteresting2 = alloca i32, align 4
21+
store i32 0, ptr %uninteresting1, align 4
22+
store i32 0, ptr %interesting, align 4
23+
%0 = load i32, ptr %interesting, align 4
24+
%added = add nsw i32 %0, 1
25+
tail call void @llvm.dbg.value(metadata i32 %added, metadata !13, metadata !DIExpression()), !dbg !14
26+
store i32 %added, ptr %interesting, align 4
27+
%alsoloaded = load i32, ptr %interesting, align 4
28+
tail call void @llvm.dbg.value(metadata i32 %alsoloaded, metadata !13, metadata !DIExpression()), !dbg !14
29+
store i32 %alsoloaded, ptr %uninteresting2, align 4
30+
ret i32 0
31+
}
32+
33+
!llvm.dbg.cu = !{!0}
34+
!llvm.module.flags = !{!2, !3, !4, !5, !6}
35+
36+
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 14.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
37+
!1 = !DIFile(filename: "/tmp/a.c", directory: "/")
38+
!2 = !{i32 7, !"Dwarf Version", i32 4}
39+
!3 = !{i32 2, !"Debug Info Version", i32 3}
40+
!4 = !{i32 1, !"wchar_size", i32 4}
41+
!5 = !{i32 7, !"uwtable", i32 1}
42+
!6 = !{i32 7, !"frame-pointer", i32 2}
43+
!7 = distinct !DISubprogram(name: "main", scope: !8, file: !8, line: 1, type: !9, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !12)
44+
!8 = !DIFile(filename: "/tmp/a.c", directory: "")
45+
!9 = !DISubroutineType(types: !10)
46+
!10 = !{!11}
47+
!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
48+
!12 = !{}
49+
!13 = !DILocalVariable(name: "a", scope: !7, file: !8, line: 2, type: !11)
50+
!14 = !DILocation(line: 2, column: 7, scope: !7)
51+

llvm/tools/llvm-reduce/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ add_llvm_tool(llvm-reduce
3131
deltas/ReduceAttributes.cpp
3232
deltas/ReduceBasicBlocks.cpp
3333
deltas/ReduceDIMetadata.cpp
34+
deltas/ReduceDPValues.cpp
3435
deltas/ReduceFunctionBodies.cpp
3536
deltas/ReduceFunctions.cpp
3637
deltas/ReduceGlobalObjects.cpp

llvm/tools/llvm-reduce/DeltaManager.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "deltas/ReduceAttributes.h"
2121
#include "deltas/ReduceBasicBlocks.h"
2222
#include "deltas/ReduceDIMetadata.h"
23+
#include "deltas/ReduceDPValues.h"
2324
#include "deltas/ReduceFunctionBodies.h"
2425
#include "deltas/ReduceFunctions.h"
2526
#include "deltas/ReduceGlobalObjects.h"
@@ -78,9 +79,11 @@ static cl::list<std::string>
7879
DELTA_PASS("aliases", reduceAliasesDeltaPass) \
7980
DELTA_PASS("ifuncs", reduceIFuncsDeltaPass) \
8081
DELTA_PASS("simplify-conditionals-true", reduceConditionalsTrueDeltaPass) \
81-
DELTA_PASS("simplify-conditionals-false", reduceConditionalsFalseDeltaPass)\
82+
DELTA_PASS("simplify-conditionals-false", \
83+
reduceConditionalsFalseDeltaPass) \
8284
DELTA_PASS("invokes", reduceInvokesDeltaPass) \
83-
DELTA_PASS("unreachable-basic-blocks", reduceUnreachableBasicBlocksDeltaPass) \
85+
DELTA_PASS("unreachable-basic-blocks", \
86+
reduceUnreachableBasicBlocksDeltaPass) \
8487
DELTA_PASS("basic-blocks", reduceBasicBlocksDeltaPass) \
8588
DELTA_PASS("simplify-cfg", reduceUsingSimplifyCFGDeltaPass) \
8689
DELTA_PASS("function-data", reduceFunctionDataDeltaPass) \
@@ -89,6 +92,7 @@ static cl::list<std::string>
8992
DELTA_PASS("global-initializers", reduceGlobalsInitializersDeltaPass) \
9093
DELTA_PASS("global-variables", reduceGlobalsDeltaPass) \
9194
DELTA_PASS("di-metadata", reduceDIMetadataDeltaPass) \
95+
DELTA_PASS("dpvalues", reduceDPValuesDeltaPass) \
9296
DELTA_PASS("metadata", reduceMetadataDeltaPass) \
9397
DELTA_PASS("named-metadata", reduceNamedMetadataDeltaPass) \
9498
DELTA_PASS("arguments", reduceArgumentsDeltaPass) \
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//===- ReduceDPValues.cpp - Specialized Delta Pass ------------------------===//
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+
// This file implements a function which calls the Generic Delta pass in order
10+
// to reduce uninteresting DPValues from defined functions.
11+
//
12+
// DPValues store variable-location debug-info and are attached to instructions.
13+
// This information used to be represented by intrinsics such as dbg.value, and
14+
// would naturally get reduced by llvm-reduce like any other instruction. As
15+
// DPValues get stored elsewhere, they need to be enumerated and eliminated like
16+
// any other data structure in LLVM.
17+
//
18+
//===----------------------------------------------------------------------===//
19+
20+
#include "ReduceDPValues.h"
21+
#include "Utils.h"
22+
#include "llvm/ADT/STLExtras.h"
23+
24+
using namespace llvm;
25+
26+
static void extractDPValuesFromModule(Oracle &O, ReducerWorkItem &WorkItem) {
27+
Module &M = WorkItem.getModule();
28+
29+
for (auto &F : M)
30+
for (auto &BB : F)
31+
for (auto &I : BB)
32+
for (DPValue &DPV : llvm::make_early_inc_range(I.getDbgValueRange()))
33+
if (!O.shouldKeep())
34+
DPV.eraseFromParent();
35+
}
36+
37+
void llvm::reduceDPValuesDeltaPass(TestRunner &Test) {
38+
runDeltaPass(Test, extractDPValuesFromModule, "Reducing DPValues");
39+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===- ReduceDPValues.h -----------------------------------------*- C++ -*-===//
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+
// This file implements a function which calls the Generic Delta pass in order
10+
// to reduce uninteresting DPValues from defined functions.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEDPVALUES_H
15+
#define LLVM_TOOLS_LLVM_REDUCE_DELTAS_REDUCEDPVALUES_H
16+
17+
#include "Delta.h"
18+
#include "llvm/IR/BasicBlock.h"
19+
#include "llvm/IR/DebugProgramInstruction.h"
20+
21+
namespace llvm {
22+
void reduceDPValuesDeltaPass(TestRunner &Test);
23+
} // namespace llvm
24+
25+
#endif

llvm/tools/llvm-reduce/llvm-reduce.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ static cl::opt<int>
100100
"of delta passes (default=5)"),
101101
cl::init(5), cl::cat(LLVMReduceOptions));
102102

103+
static cl::opt<bool> TryUseNewDbgInfoFormat(
104+
"try-experimental-debuginfo-iterators",
105+
cl::desc("Enable debuginfo iterator positions, if they're built in"),
106+
cl::init(false));
107+
108+
extern cl::opt<bool> UseNewDbgInfoFormat;
109+
103110
static codegen::RegisterCodeGenFlags CGF;
104111

105112
/// Turn off crash debugging features
@@ -143,6 +150,17 @@ int main(int Argc, char **Argv) {
143150
cl::HideUnrelatedOptions({&LLVMReduceOptions, &getColorCategory()});
144151
cl::ParseCommandLineOptions(Argc, Argv, "LLVM automatic testcase reducer.\n");
145152

153+
// RemoveDIs debug-info transition: tests may request that we /try/ to use the
154+
// new debug-info format, if it's built in.
155+
#ifdef EXPERIMENTAL_DEBUGINFO_ITERATORS
156+
if (TryUseNewDbgInfoFormat) {
157+
// If LLVM was built with support for this, turn the new debug-info format
158+
// on.
159+
UseNewDbgInfoFormat = true;
160+
}
161+
#endif
162+
(void)TryUseNewDbgInfoFormat;
163+
146164
if (Argc == 1) {
147165
cl::PrintHelpMessage();
148166
return 0;

0 commit comments

Comments
 (0)