[llvm] r301333 - Print complete DIExpressions in the assembler output DEBUG_VALUE comments.

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon May 1 09:11:39 PDT 2017


Nice!

On Tue, Apr 25, 2017 at 10:35 AM Adrian Prantl via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: adrian
> Date: Tue Apr 25 12:22:09 2017
> New Revision: 301333
>
> URL: http://llvm.org/viewvc/llvm-project?rev=301333&view=rev
> Log:
> Print complete DIExpressions in the assembler output DEBUG_VALUE comments.
>
> The previous code was complex, incorrect, and couldn't print everything.
>
> Modified:
>     llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
>     llvm/trunk/test/DebugInfo/COFF/pieces.ll
>     llvm/trunk/test/DebugInfo/X86/debug-loc-asan.ll
>     llvm/trunk/test/DebugInfo/X86/op_deref.ll
>     llvm/trunk/test/DebugInfo/X86/pieces-4.ll
>     llvm/trunk/test/DebugInfo/X86/this-stack_value.ll
>     llvm/trunk/test/DebugInfo/X86/vla.ll
>
> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=301333&r1=301332&r2=301333&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
> +++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Tue Apr 25 12:22:09
> 2017
> @@ -825,43 +825,25 @@ static bool emitDebugValueComment(const
>        OS << Name << ":";
>    }
>    OS << V->getName();
> -
> -  const DIExpression *Expr = MI->getDebugExpression();
> -  auto Fragment = Expr->getFragmentInfo();
> -  if (Fragment)
> -    OS << " [fragment offset=" << Fragment->OffsetInBits
> -       << " size=" << Fragment->SizeInBits << "]";
>    OS << " <- ";
>
>    // The second operand is only an offset if it's an immediate.
> -  bool Deref = false;
>    bool MemLoc = MI->getOperand(0).isReg() && MI->getOperand(1).isImm();
>    int64_t Offset = MemLoc ? MI->getOperand(1).getImm() : 0;
> -  for (unsigned i = 0; i < Expr->getNumElements(); ++i) {
> -    uint64_t Op = Expr->getElement(i);
> -    if (Op == dwarf::DW_OP_LLVM_fragment) {
> -      // There can't be any operands after this in a valid expression
> -      break;
> -    } else if (Deref) {
> -      // We currently don't support extra Offsets or derefs after the
> first
> -      // one. Bail out early instead of emitting an incorrect comment.
> -      OS << " [complex expression]";
> -      AP.OutStreamer->emitRawComment(OS.str());
> -      return true;
> -    } else if (Op == dwarf::DW_OP_deref) {
> -      Deref = true;
> -      continue;
> -    }
> -
> -    uint64_t ExtraOffset = Expr->getElement(i++);
> -    if (Op == dwarf::DW_OP_plus)
> -      Offset += ExtraOffset;
> -    else if (Op == dwarf::DW_OP_stack_value)
> -      OS << " [stack value]";
> -    else {
> -      assert(Op == dwarf::DW_OP_minus);
> -      Offset -= ExtraOffset;
> +  const DIExpression *Expr = MI->getDebugExpression();
> +  if (Expr->getNumElements()) {
> +    OS << '[';
> +    bool NeedSep = false;
> +    for (auto Op : Expr->expr_ops()) {
> +      if (NeedSep)
> +        OS << ", ";
> +      else
> +        NeedSep = true;
> +      OS << dwarf::OperationEncodingString(Op.getOp());
> +      for (unsigned I = 0; I < Op.getNumArgs(); ++I)
> +        OS << ' ' << Op.getArg(I);
>      }
> +    OS << "] ";
>    }
>
>    // Register or immediate value. Register 0 means undef.
> @@ -892,7 +874,7 @@ static bool emitDebugValueComment(const
>        const TargetFrameLowering *TFI =
> AP.MF->getSubtarget().getFrameLowering();
>        Offset += TFI->getFrameIndexReference(*AP.MF,
>                                              MI->getOperand(0).getIndex(),
> Reg);
> -      Deref = true;
> +      MemLoc = true;
>      }
>      if (Reg == 0) {
>        // Suppress offset, it is not meaningful here.
> @@ -901,12 +883,12 @@ static bool emitDebugValueComment(const
>        AP.OutStreamer->emitRawComment(OS.str());
>        return true;
>      }
> -    if (MemLoc || Deref)
> +    if (MemLoc)
>        OS << '[';
>      OS << PrintReg(Reg, AP.MF->getSubtarget().getRegisterInfo());
>    }
>
> -  if (MemLoc || Deref)
> +  if (MemLoc)
>      OS << '+' << Offset << ']';
>
>    // NOTE: Want this comment at start of line, don't emit with AddComment.
>
> Modified: llvm/trunk/test/DebugInfo/COFF/pieces.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/COFF/pieces.ll?rev=301333&r1=301332&r2=301333&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/DebugInfo/COFF/pieces.ll (original)
> +++ llvm/trunk/test/DebugInfo/COFF/pieces.ll Tue Apr 25 12:22:09 2017
> @@ -35,27 +35,27 @@
>  ; }
>
>  ; ASM-LABEL: loop_csr: # @loop_csr
> -; ASM:        #DEBUG_VALUE: loop_csr:o [fragment offset=0 size=32] <- 0
> -; ASM:        #DEBUG_VALUE: loop_csr:o [fragment offset=32 size=32] <- 0
> +; ASM:        #DEBUG_VALUE: loop_csr:o <- [DW_OP_LLVM_fragment 0 32] 0
> +; ASM:        #DEBUG_VALUE: loop_csr:o <- [DW_OP_LLVM_fragment 32 32] 0
>  ; ASM: # BB#2:                                 # %for.body.preheader
>  ; ASM:         xorl    %edi, %edi
>  ; ASM:         xorl    %esi, %esi
>  ; ASM:         .p2align        4, 0x90
>  ; ASM: .LBB0_3:                                # %for.body
>  ; ASM: [[ox_start:\.Ltmp[0-9]+]]:
> -; ASM:        #DEBUG_VALUE: loop_csr:o [fragment offset=0 size=32] <- %EDI
> +; ASM:        #DEBUG_VALUE: loop_csr:o <- [DW_OP_LLVM_fragment 0 32] %EDI
>  ; ASM:        .cv_loc 0 1 13 11               # t.c:13:11
>  ; ASM:        movl    %edi, %ecx
>  ; ASM:        callq   g
>  ; ASM:        movl    %eax, %edi
>  ; ASM: [[oy_start:\.Ltmp[0-9]+]]:
> -; ASM:         #DEBUG_VALUE: loop_csr:o [fragment offset=0 size=32] <-
> %EDI
> -; ASM:         #DEBUG_VALUE: loop_csr:o [fragment offset=32 size=32] <-
> %ESI
> +; ASM:         #DEBUG_VALUE: loop_csr:o <- [DW_OP_LLVM_fragment 0 32] %EDI
> +; ASM:         #DEBUG_VALUE: loop_csr:o <- [DW_OP_LLVM_fragment 32 32]
> %ESI
>  ; ASM:         .cv_loc 0 1 14 11               # t.c:14:11
>  ; ASM:         movl    %esi, %ecx
>  ; ASM:         callq   g
>  ; ASM:         movl    %eax, %esi
> -; ASM:         #DEBUG_VALUE: loop_csr:o [fragment offset=32 size=32] <-
> %ESI
> +; ASM:         #DEBUG_VALUE: loop_csr:o <- [DW_OP_LLVM_fragment 32 32]
> %ESI
>  ; ASM:         cmpl    n(%rip), %eax
>  ; ASM:         jl      .LBB0_3
>  ; ASM: [[oy_end:\.Ltmp[0-9]+]]:
> @@ -64,32 +64,32 @@
>
>
>  ; ASM-LABEL: pad_right: # @pad_right
> -; ASM:         #DEBUG_VALUE: pad_right:o [fragment offset=32 size=32] <-
> %ECX
> +; ASM:         #DEBUG_VALUE: pad_right:o <- [DW_OP_LLVM_fragment 32 32]
> %ECX
>  ; ASM:         movl    %ecx, %eax
>  ; ASM:         retq
>
>
>  ; ASM-LABEL: pad_left: # @pad_left
> -; ASM:         #DEBUG_VALUE: pad_left:o [fragment offset=0 size=32] <-
> %ECX
> +; ASM:         #DEBUG_VALUE: pad_left:o <- [DW_OP_LLVM_fragment 0 32] %ECX
>  ; ASM:         .cv_loc 2 1 24 3                # t.c:24:3
>  ; ASM:         movl    %ecx, %eax
>  ; ASM:         retq
>
>
>  ; ASM-LABEL: nested: # @nested
> -; ASM:         #DEBUG_VALUE: nested:o <- [%RCX+0]
> +; ASM:         #DEBUG_VALUE: nested:o <- [DW_OP_deref] [%RCX+0]
>  ; ASM:         movl    12(%rcx), %eax
>  ; ASM: [[p_start:\.Ltmp[0-9]+]]:
> -; ASM:         #DEBUG_VALUE: nested:p [fragment offset=32 size=32] <- %EAX
> +; ASM:         #DEBUG_VALUE: nested:p <- [DW_OP_LLVM_fragment 32 32] %EAX
>  ; ASM:         retq
>
>  ; ASM-LABEL: bitpiece_spill: # @bitpiece_spill
> -; ASM:         #DEBUG_VALUE: bitpiece_spill:o [fragment offset=0 size=32]
> <- 0
> +; ASM:         #DEBUG_VALUE: bitpiece_spill:o <- [DW_OP_LLVM_fragment 0
> 32] 0
>  ; ASM:         xorl    %ecx, %ecx
>  ; ASM:         callq   g
>  ; ASM:         movl    %eax, [[offset_o_x:[0-9]+]](%rsp)          #
> 4-byte Spill
>  ; ASM: [[spill_o_x_start:\.Ltmp[0-9]+]]:
> -; ASM:         #DEBUG_VALUE: bitpiece_spill:o [fragment offset=32
> size=32] <- [%RSP+[[offset_o_x]]]
> +; ASM:         #DEBUG_VALUE: bitpiece_spill:o <- [DW_OP_LLVM_fragment 32
> 32] [%RSP+[[offset_o_x]]]
>  ; ASM:         #APP
>  ; ASM:         #NO_APP
>  ; ASM:         movl    [[offset_o_x]](%rsp), %eax          # 4-byte Reload
>
> Modified: llvm/trunk/test/DebugInfo/X86/debug-loc-asan.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/debug-loc-asan.ll?rev=301333&r1=301332&r2=301333&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/DebugInfo/X86/debug-loc-asan.ll (original)
> +++ llvm/trunk/test/DebugInfo/X86/debug-loc-asan.ll Tue Apr 25 12:22:09
> 2017
> @@ -12,10 +12,10 @@
>  ; The address of the (potentially now malloc'ed) alloca ends up
>  ; in RDI, after which it is spilled to the stack. We record the
>  ; spill OFFSET on the stack for checking the debug info below.
> -; CHECK: #DEBUG_VALUE: bar:y <- [%RDI+0]
> +; CHECK: #DEBUG_VALUE: bar:y <- [DW_OP_deref] [%RDI+0]
>  ; CHECK: movq %rdi, [[OFFSET:[0-9]+]](%rsp)
>  ; CHECK-NEXT: [[START_LABEL:.Ltmp[0-9]+]]
> -; CHECK-NEXT: #DEBUG_VALUE: bar:y <- [complex expression]
> +; CHECK-NEXT: #DEBUG_VALUE: bar:y <- [DW_OP_deref, DW_OP_deref]
>  ; This location should be valid until the end of the function.
>
>  ; CHECK:        movq    %rbp, %rsp
>
> Modified: llvm/trunk/test/DebugInfo/X86/op_deref.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/op_deref.ll?rev=301333&r1=301332&r2=301333&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/DebugInfo/X86/op_deref.ll (original)
> +++ llvm/trunk/test/DebugInfo/X86/op_deref.ll Tue Apr 25 12:22:09 2017
> @@ -20,7 +20,7 @@
>  ; right now, so we check the asm output:
>  ; RUN: llc -O0 -mtriple=x86_64-apple-darwin %s -o - -filetype=asm |
> FileCheck %s -check-prefix=ASM-CHECK
>  ; vla should have a register-indirect address at one point.
> -; ASM-CHECK: DEBUG_VALUE: vla <- [%RCX+0]
> +; ASM-CHECK: DEBUG_VALUE: vla <- [DW_OP_deref] [%RCX+0]
>  ; ASM-CHECK: DW_OP_breg2
>
>  ; RUN: llvm-as %s -o - | llvm-dis - | FileCheck %s
> --check-prefix=PRETTY-PRINT
>
> Modified: llvm/trunk/test/DebugInfo/X86/pieces-4.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/pieces-4.ll?rev=301333&r1=301332&r2=301333&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/DebugInfo/X86/pieces-4.ll (original)
> +++ llvm/trunk/test/DebugInfo/X86/pieces-4.ll Tue Apr 25 12:22:09 2017
> @@ -15,8 +15,8 @@
>  ; CHECK-LABEL: bitpiece_spill:                         # @bitpiece_spill
>  ; CHECK:               callq   g
>  ; CHECK:               movl    %eax, [[offs:[0-9]+]](%rsp)          #
> 4-byte Spill
> -; CHECK:               #DEBUG_VALUE: bitpiece_spill:o [fragment offset=32
> size=32] <- 0
> -; CHECK:               #DEBUG_VALUE: bitpiece_spill:o [fragment offset=0
> size=32] <- [%RSP+[[offs]]]
> +; CHECK:               #DEBUG_VALUE: bitpiece_spill:o <-
> [DW_OP_LLVM_fragment 32 32] 0
> +; CHECK:               #DEBUG_VALUE: bitpiece_spill:o <-
> [DW_OP_LLVM_fragment 0 32] [%RSP+[[offs]]]
>  ; CHECK:               #APP
>  ; CHECK:               #NO_APP
>  ; CHECK:               movl    [[offs]](%rsp), %eax          # 4-byte
> Reload
>
> Modified: llvm/trunk/test/DebugInfo/X86/this-stack_value.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/this-stack_value.ll?rev=301333&r1=301332&r2=301333&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/DebugInfo/X86/this-stack_value.ll (original)
> +++ llvm/trunk/test/DebugInfo/X86/this-stack_value.ll Tue Apr 25 12:22:09
> 2017
> @@ -17,7 +17,7 @@
>  ; The inlined A::this pointer has the same location as B::this, but it
> may not be
>  ; modified by the debugger.
>  ;
> -; ASM: [stack value]
> +; ASM: [DW_OP_stack_value]
>  ; CHECK:  Location description: 70 00 9f
>  ;                               rax+0, stack-value
>  source_filename = "ab.cpp"
>
> Modified: llvm/trunk/test/DebugInfo/X86/vla.ll
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/vla.ll?rev=301333&r1=301332&r2=301333&view=diff
>
> ==============================================================================
> --- llvm/trunk/test/DebugInfo/X86/vla.ll (original)
> +++ llvm/trunk/test/DebugInfo/X86/vla.ll Tue Apr 25 12:22:09 2017
> @@ -1,6 +1,6 @@
>  ; RUN: llc -O0 -mtriple=x86_64-apple-darwin -filetype=asm %s -o - |
> FileCheck %s
>  ; Ensure that we generate an indirect location for the variable length
> array a.
> -; CHECK: ##DEBUG_VALUE: vla:a <- [%RCX+0]
> +; CHECK: ##DEBUG_VALUE: vla:a <- [DW_OP_deref] [%RCX+0]
>  ; CHECK: DW_OP_breg2
>  ; rdar://problem/13658587
>  ;
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170501/d248d1d6/attachment.html>


More information about the llvm-commits mailing list