[PATCH] D77438: Add option to limit Debugify to locations (omitting variables)

Daniel Sanders via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 6 12:31:03 PDT 2020


dsanders updated this revision to Diff 255437.
dsanders added a comment.

+ test case


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77438/new/

https://reviews.llvm.org/D77438

Files:
  llvm/lib/Transforms/Utils/Debugify.cpp
  llvm/test/Transforms/Util/Debugify/loc-only.ll


Index: llvm/test/Transforms/Util/Debugify/loc-only.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/Util/Debugify/loc-only.ll
@@ -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:
Index: llvm/lib/Transforms/Utils/Debugify.cpp
===================================================================
--- llvm/lib/Transforms/Utils/Debugify.cpp
+++ llvm/lib/Transforms/Utils/Debugify.cpp
@@ -30,6 +30,17 @@
 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 @@
       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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77438.255437.patch
Type: text/x-patch
Size: 2327 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200406/1e2e6549/attachment.bin>


More information about the llvm-commits mailing list