[llvm] r301099 - Revert "Use DW_OP_stack_value when reconstructing variable values with arithmetic."

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 22 17:44:41 PDT 2017


Author: adrian
Date: Sat Apr 22 19:44:40 2017
New Revision: 301099

URL: http://llvm.org/viewvc/llvm-project?rev=301099&view=rev
Log:
Revert "Use DW_OP_stack_value when reconstructing variable values with arithmetic."

This reverts commit r301093 while investigating stage2 bot breakage.

Modified:
    llvm/trunk/lib/Transforms/Utils/Local.cpp
    llvm/trunk/test/Transforms/InstCombine/debuginfo-dce.ll

Modified: llvm/trunk/lib/Transforms/Utils/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=301099&r1=301098&r2=301099&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/Local.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/Local.cpp Sat Apr 22 19:44:40 2017
@@ -1268,37 +1268,21 @@ static void appendOffset(SmallVectorImpl
   }
 }
 
-enum { WithStackValue = true };
-
-/// Prepend \p DIExpr with a deref and offset operation and optionally turn it
-/// into a stack value.
+/// Prepend \p DIExpr with a deref and offset operation.
 static DIExpression *prependDIExpr(DIBuilder &Builder, DIExpression *DIExpr,
-                                   bool Deref, int64_t Offset = 0,
-                                   bool StackValue = false) {
-  if (!Deref && !Offset && !StackValue)
+                                   bool Deref, int64_t Offset) {
+  if (!Deref && !Offset)
     return DIExpr;
-
-  SmallVector<uint64_t, 8> Ops;
-  appendOffset(Ops, Offset);
+  // Create a copy of the original DIDescriptor for user variable, prepending
+  // "deref" operation to a list of address elements, as new llvm.dbg.declare
+  // will take a value storing address of the memory for variable, not
+  // alloca itself.
+  SmallVector<uint64_t, 4> Ops;
   if (Deref)
     Ops.push_back(dwarf::DW_OP_deref);
+  appendOffset(Ops, Offset);
   if (DIExpr)
-    for (auto Op : DIExpr->expr_ops()) {
-      // A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment.
-      if (StackValue) {
-        if (Op.getOp() == dwarf::DW_OP_stack_value)
-          StackValue = false;
-        else if (Op.getOp() == dwarf::DW_OP_LLVM_fragment) {
-          Ops.push_back(dwarf::DW_OP_stack_value);
-          StackValue = false;
-        }
-      }
-      Ops.push_back(Op.getOp());
-      for (unsigned I = 0; I < Op.getNumArgs(); ++I)
-        Ops.push_back(Op.getArg(I));
-    }
-  if (StackValue)
-    Ops.push_back(dwarf::DW_OP_stack_value);
+    Ops.append(DIExpr->elements_begin(), DIExpr->elements_end());
   return Builder.createExpression(Ops);
 }
 
@@ -1390,15 +1374,12 @@ void llvm::salvageDebugInfo(Instruction
       unsigned BitWidth =
           M.getDataLayout().getPointerSizeInBits(GEP->getPointerAddressSpace());
       APInt Offset(BitWidth, 0);
-      // Rewrite a constant GEP into a DIExpression.  Since we are performing
-      // arithmetic to compute the variable's *value* in the DIExpression, we
-      // need to mark the expression with a DW_OP_stack_value.
+      // Rewrite a constant GEP into a DIExpression.
       if (GEP->accumulateConstantOffset(M.getDataLayout(), Offset)) {
         auto *DIExpr = DVI->getExpression();
         DIBuilder DIB(M, /*AllowUnresolved*/ false);
         // GEP offsets are i32 and thus always fit into an int64_t.
-        DIExpr = prependDIExpr(DIB, DIExpr, NoDeref, Offset.getSExtValue(),
-                               WithStackValue);
+        DIExpr = prependDIExpr(DIB, DIExpr, NoDeref, Offset.getSExtValue());
         DVI->setOperand(0, MDWrap(I.getOperand(0)));
         DVI->setOperand(3, MetadataAsValue::get(I.getContext(), DIExpr));
         DEBUG(dbgs() << "SALVAGE: " << *DVI << '\n');
@@ -1410,7 +1391,7 @@ void llvm::salvageDebugInfo(Instruction
       // Rewrite the load into DW_OP_deref.
       auto *DIExpr = DVI->getExpression();
       DIBuilder DIB(M, /*AllowUnresolved*/ false);
-      DIExpr = prependDIExpr(DIB, DIExpr, WithDeref);
+      DIExpr = prependDIExpr(DIB, DIExpr, WithDeref, 0);
       DVI->setOperand(0, MDWrap(I.getOperand(0)));
       DVI->setOperand(3, MetadataAsValue::get(I.getContext(), DIExpr));
       DEBUG(dbgs() << "SALVAGE:  " << *DVI << '\n');

Modified: llvm/trunk/test/Transforms/InstCombine/debuginfo-dce.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/debuginfo-dce.ll?rev=301099&r1=301098&r2=301099&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/debuginfo-dce.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/debuginfo-dce.ll Sat Apr 22 19:44:40 2017
@@ -23,6 +23,7 @@ target triple = "x86_64-apple-macosx10.1
 
 %struct.entry = type { %struct.entry* }
 
+; Function Attrs: nounwind ssp uwtable
 define void @salvage_load(%struct.entry** %queue) local_unnamed_addr #0 !dbg !14 {
 entry:
   %im_not_dead = alloca %struct.entry*
@@ -37,6 +38,7 @@ entry:
   ret void, !dbg !21
 }
 
+; Function Attrs: nounwind ssp uwtable
 define void @salvage_bitcast(%struct.entry* %queue) local_unnamed_addr #0 !dbg !14 {
 entry:
   %im_not_dead = alloca i8*
@@ -51,54 +53,24 @@ entry:
   ret void, !dbg !21
 }
 
-define void @salvage_gep0(%struct.entry* %queue, %struct.entry* %end) local_unnamed_addr #0 !dbg !14 {
+; Function Attrs: nounwind ssp uwtable
+define void @salvage_gep(%struct.entry* %queue, %struct.entry* %end) local_unnamed_addr #0 !dbg !14 {
 entry:
   %im_not_dead = alloca %struct.entry**
   %0 = getelementptr inbounds %struct.entry, %struct.entry* %queue, i32 -1, i32 0, !dbg !19
   %1 = getelementptr inbounds %struct.entry, %struct.entry* %queue, i32 -1, i32 0, !dbg !19
   call void @llvm.dbg.value(metadata %struct.entry** %1, i64 0, metadata !18, metadata !20), !dbg !19
-; CHECK: define void @salvage_gep0
+; CHECK: define void @salvage_gep
 ; CHECK-NEXT: entry:
 ; CHECK-NEXT: call void @llvm.dbg.value(metadata %struct.entry* %queue, i64 0,
-; CHECK-SAME:                           metadata ![[GEP0_EXPR:[0-9]+]])
-  store %struct.entry** %1, %struct.entry*** %im_not_dead, align 8
-  ret void, !dbg !21
-}
-
-define void @salvage_gep1(%struct.entry* %queue, %struct.entry* %end) local_unnamed_addr #0 !dbg !14 {
-entry:
-  %im_not_dead = alloca %struct.entry**
-  %0 = getelementptr inbounds %struct.entry, %struct.entry* %queue, i32 -1, i32 0, !dbg !19
-  %1 = getelementptr inbounds %struct.entry, %struct.entry* %queue, i32 -1, i32 0, !dbg !19
-  call void @llvm.dbg.value(metadata %struct.entry** %1, i64 0, metadata !18, metadata !DIExpression(DW_OP_LLVM_fragment, 0, 32)), !dbg !19
-; CHECK: define void @salvage_gep1
-; CHECK-NEXT: entry:
-; CHECK-NEXT: call void @llvm.dbg.value(metadata %struct.entry* %queue, i64 0,
-; CHECK-SAME:                           metadata ![[GEP1_EXPR:[0-9]+]])
-  store %struct.entry** %1, %struct.entry*** %im_not_dead, align 8
-  ret void, !dbg !21
-}
-
-define void @salvage_gep2(%struct.entry* %queue, %struct.entry* %end) local_unnamed_addr #0 !dbg !14 {
-entry:
-  %im_not_dead = alloca %struct.entry**
-  %0 = getelementptr inbounds %struct.entry, %struct.entry* %queue, i32 -1, i32 0, !dbg !19
-  %1 = getelementptr inbounds %struct.entry, %struct.entry* %queue, i32 -1, i32 0, !dbg !19
-  call void @llvm.dbg.value(metadata %struct.entry** %1, i64 0, metadata !18, metadata !DIExpression(DW_OP_stack_value)), !dbg !19
-; CHECK: define void @salvage_gep2
-; CHECK-NEXT: entry:
-; CHECK-NEXT: call void @llvm.dbg.value(metadata %struct.entry* %queue, i64 0,
-; CHECK-SAME:                           metadata ![[GEP2_EXPR:[0-9]+]])
+; CHECK-SAME:                           metadata ![[GEP_EXPR:[0-9]+]])
   store %struct.entry** %1, %struct.entry*** %im_not_dead, align 8
   ret void, !dbg !21
 }
 
 ; CHECK: ![[LOAD_EXPR]] = !DIExpression(DW_OP_deref, DW_OP_plus, 0)
 ; CHECK: ![[BITCAST_EXPR]] = !DIExpression(DW_OP_plus, 0)
-; CHECK: ![[GEP0_EXPR]] = !DIExpression(DW_OP_minus, 8, DW_OP_plus, 0, DW_OP_stack_value)
-; CHECK: ![[GEP1_EXPR]] = !DIExpression(DW_OP_minus, 8, DW_OP_stack_value,
-; CHECK-SAME:                           DW_OP_LLVM_fragment, 0, 32)
-; CHECK: ![[GEP2_EXPR]] = !DIExpression(DW_OP_minus, 8, DW_OP_stack_value)
+; CHECK: ![[GEP_EXPR]] = !DIExpression(DW_OP_minus, 8, DW_OP_plus, 0)
 
 ; Function Attrs: nounwind readnone
 declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1




More information about the llvm-commits mailing list