From f9dddec21ca6ae9acab02645f4540722ec542b39 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Wed, 5 Oct 2016 18:36:02 +0000 Subject: [PATCH] Improve DEBUG_VALUE assembly comments for spilled bitpieces Previously we would give up when we saw the bitpiece DWARF expression and print "[complex expression]" when actually we handled bitpiece expressions outside the loop. llvm-svn: 283355 --- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 14 ++-- llvm/test/DebugInfo/X86/pieces-4.ll | 84 ++++++++++++++++++++++ 2 files changed, 91 insertions(+), 7 deletions(-) create mode 100644 llvm/test/DebugInfo/X86/pieces-4.ll diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index e24aca754997..da5fca8e418e 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -711,21 +711,21 @@ static bool emitDebugValueComment(const MachineInstr *MI, AsmPrinter &AP) { int64_t Offset = Deref ? MI->getOperand(1).getImm() : 0; for (unsigned i = 0; i < Expr->getNumElements(); ++i) { - if (Deref) { + uint64_t Op = Expr->getElement(i); + if (Op == dwarf::DW_OP_bit_piece) { + // 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; - } - uint64_t Op = Expr->getElement(i); - if (Op == dwarf::DW_OP_deref) { + } else if (Op == dwarf::DW_OP_deref) { Deref = true; continue; - } else if (Op == dwarf::DW_OP_bit_piece) { - // There can't be any operands after this in a valid expression - break; } + uint64_t ExtraOffset = Expr->getElement(i++); if (Op == dwarf::DW_OP_plus) Offset += ExtraOffset; diff --git a/llvm/test/DebugInfo/X86/pieces-4.ll b/llvm/test/DebugInfo/X86/pieces-4.ll new file mode 100644 index 000000000000..7dfa88794f95 --- /dev/null +++ b/llvm/test/DebugInfo/X86/pieces-4.ll @@ -0,0 +1,84 @@ +; RUN: llc < %s | FileCheck %s + +; Compile the following with -O1: + +; struct IntPair { int x, y; }; +; int g(void); +; int bitpiece_spill() { +; struct IntPair o = {g(), 0}; +; // Force o.x to spill +; asm volatile("" : : : "rax", "rbx", "rcx", "rdx", "rsi", "rdi", "rbp", +; "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"); +; return o.x; +; } + +; 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 [bit_piece offset=32 size=32] <- 0 +; CHECK: #DEBUG_VALUE: bitpiece_spill:o [bit_piece offset=0 size=32] <- [%RSP+[[offs]]] +; CHECK: #APP +; CHECK: #NO_APP +; CHECK: movl [[offs]](%rsp), %eax # 4-byte Reload +; CHECK: retq + +; ModuleID = 't.c' +source_filename = "t.c" +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-windows-msvc19.0.24210" + +%struct.IntPair = type { i32, i32 } + +; Function Attrs: nounwind uwtable +define i32 @bitpiece_spill() local_unnamed_addr #0 !dbg !7 { +entry: + tail call void @llvm.dbg.declare(metadata %struct.IntPair* undef, metadata !12, metadata !17), !dbg !18 + %call = tail call i32 @g() #3, !dbg !19 + tail call void @llvm.dbg.value(metadata i32 %call, i64 0, metadata !12, metadata !20), !dbg !18 + tail call void @llvm.dbg.value(metadata i32 0, i64 0, metadata !12, metadata !21), !dbg !18 + tail call void asm sideeffect "", "~{rax},~{rbx},~{rcx},~{rdx},~{rsi},~{rdi},~{rbp},~{r8},~{r9},~{r10},~{r11},~{r12},~{r13},~{r14},~{r15},~{dirflag},~{fpsr},~{flags}"() #3, !dbg !22, !srcloc !23 + ret i32 %call, !dbg !24 +} + +; Function Attrs: nounwind readnone +declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 + +declare i32 @g() local_unnamed_addr #2 + +; Function Attrs: nounwind readnone +declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #1 + +attributes #0 = { nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { nounwind readnone } +attributes #2 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #3 = { nounwind } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5} +!llvm.ident = !{!6} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 4.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) +!1 = !DIFile(filename: "t.c", directory: "C:\5Csrc\5Cllvm\5Cbuild") +!2 = !{} +!3 = !{i32 2, !"Dwarf Version", i32 4} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"PIC Level", i32 2} +!6 = !{!"clang version 4.0.0 "} +!7 = distinct !DISubprogram(name: "bitpiece_spill", scope: !1, file: !1, line: 3, type: !8, isLocal: false, isDefinition: true, scopeLine: 3, isOptimized: true, unit: !0, variables: !11) +!8 = !DISubroutineType(types: !9) +!9 = !{!10} +!10 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) +!11 = !{!12} +!12 = !DILocalVariable(name: "o", scope: !7, file: !1, line: 4, type: !13) +!13 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "IntPair", file: !1, line: 1, size: 64, align: 32, elements: !14) +!14 = !{!15, !16} +!15 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !13, file: !1, line: 1, baseType: !10, size: 32, align: 32) +!16 = !DIDerivedType(tag: DW_TAG_member, name: "y", scope: !13, file: !1, line: 1, baseType: !10, size: 32, align: 32, offset: 32) +!17 = !DIExpression() +!18 = !DILocation(line: 4, column: 18, scope: !7) +!19 = !DILocation(line: 4, column: 23, scope: !7) +!20 = !DIExpression(DW_OP_bit_piece, 0, 32) +!21 = !DIExpression(DW_OP_bit_piece, 32, 32) +!22 = !DILocation(line: 6, column: 3, scope: !7) +!23 = !{i32 138} +!24 = !DILocation(line: 8, column: 3, scope: !7)