Add option to limit Debugify to locations (omitting variables)
authorDaniel Sanders <daniel_l_sanders@apple.com>
Fri, 3 Apr 2020 22:50:11 +0000 (15:50 -0700)
committerDaniel Sanders <daniel_l_sanders@apple.com>
Mon, 6 Apr 2020 22:04:55 +0000 (15:04 -0700)
Summary:
It can be helpful to test behaviour w.r.t locations without having DEBUG_VALUE
around. In particular, because DEBUG_VALUE has the potential to change CodeGen
behaviour (e.g. hasOneUse() vs hasOneNonDbgUse()) while locations generally
don't.

Reviewers: aprantl, bogner

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D77438

llvm/lib/Transforms/Utils/Debugify.cpp
llvm/test/Transforms/Util/Debugify/loc-only.ll [new file with mode: 0644]

index b1274d9..a9cdf65 100644 (file)
@@ -30,6 +30,17 @@ namespace {
 cl::opt<bool> Quiet("debugify-quiet",
                     cl::desc("Suppress verbose debugify output"));
 
+enum class Level {
+  Locations,
+  LocationsAndVariables
+};
+cl::opt<Level> DebugifyLevel(
+    "debugify-level", cl::desc("Kind of debug info to add"),
+    cl::values(clEnumValN(Level::Locations, "locations", "Locations only"),
+               clEnumValN(Level::LocationsAndVariables, "location+variables",
+                          "Locations and Variables")),
+    cl::init(Level::LocationsAndVariables));
+
 raw_ostream &dbg() { return Quiet ? nulls() : errs(); }
 
 uint64_t getAllocSizeInBits(Module &M, Type *Ty) {
@@ -100,6 +111,9 @@ bool applyDebugifyMetadata(Module &M,
       for (Instruction &I : BB)
         I.setDebugLoc(DILocation::get(Ctx, NextLine++, 1, SP));
 
+      if (DebugifyLevel < Level::LocationsAndVariables)
+        continue;
+
       // Inserting debug values into EH pads can break IR invariants.
       if (BB.isEHPad())
         continue;
diff --git a/llvm/test/Transforms/Util/Debugify/loc-only.ll b/llvm/test/Transforms/Util/Debugify/loc-only.ll
new file mode 100644 (file)
index 0000000..250e72d
--- /dev/null
@@ -0,0 +1,21 @@
+; RUN: opt -debugify -S < %s | FileCheck --check-prefixes=ALL,VALUE %s
+; RUN: opt -debugify -debugify-level=locations -S < %s | FileCheck --check-prefixes=ALL --implicit-check-not=dbg.value %s
+
+; ALL-LABEL: @test
+define void @test() {
+  %add = add i32 1, 2
+; ALL-NEXT:  %add = add i32 1, 2, !dbg [[L1:![0-9]+]]
+; VALUE-NEXT: call void @llvm.dbg.value(metadata i32 %add, metadata [[add:![0-9]+]], metadata !DIExpression()), !dbg [[L1]]
+  %sub = sub i32 %add, 1
+; ALL-NEXT: %sub = sub i32 %add, 1, !dbg [[L2:![0-9]+]]
+; VALUE-NEXT: call void @llvm.dbg.value(metadata i32 %sub, metadata [[sub:![0-9]+]], metadata !DIExpression()), !dbg [[L2]]
+; ALL-NEXT: ret void, !dbg [[L3:![0-9]+]]
+  ret void
+}
+
+; VALUE: [[add]] = !DILocalVariable
+; VALUE: [[sub]] = !DILocalVariable
+
+; ALL: [[L1]] = !DILocation(line: 1, column: 1, scope:
+; ALL: [[L2]] = !DILocation(line: 2, column: 1, scope:
+; ALL: [[L3]] = !DILocation(line: 3, column: 1, scope: