diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -2471,24 +2471,16 @@ // TODO TargetIndexLocation is a target-independent. Currently only the WebAssembly-specific // encoding is supported. DwarfExpr.addWasmLocation(Loc.Index, static_cast(Loc.Offset)); - DwarfExpr.addExpression(std::move(ExprCursor)); - return; - } else if (Value.isConstantFP()) { - if (AP.getDwarfVersion() >= 4 && !AP.getDwarfDebug()->tuneForSCE()) { - DwarfExpr.addConstantFP(Value.getConstantFP()->getValueAPF(), AP); - return; - } else if (Value.getConstantFP() - ->getValueAPF() - .bitcastToAPInt() - .getBitWidth() <= 64 /*bits*/) - DwarfExpr.addUnsignedConstant( - Value.getConstantFP()->getValueAPF().bitcastToAPInt()); - else - LLVM_DEBUG( - dbgs() - << "Skipped DwarfExpression creation for ConstantFP of size" - << Value.getConstantFP()->getValueAPF().bitcastToAPInt().getBitWidth() - << " bits\n"); + DwarfExpr.addExpression(std::move(ExprCursor)); + return; + } + if (Value.isConstantInt()) { + DwarfExpr.addUnsignedConstant(Value.getConstantInt()->getValue(), AP); + return; + } + if (Value.isConstantFP()) { + DwarfExpr.addConstantFP(Value.getConstantFP()->getValueAPF(), AP); + return; } DwarfExpr.addExpression(std::move(ExprCursor)); } diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h --- a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h @@ -297,7 +297,7 @@ void addUnsignedConstant(uint64_t Value); /// Emit an unsigned constant. - void addUnsignedConstant(const APInt &Value); + void addUnsignedConstant(APInt Value, const AsmPrinter &AP); /// Emit an floating point constant. void addConstantFP(const APFloat &Value, const AsmPrinter &AP); diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp @@ -199,10 +199,29 @@ emitConstu(Value); } -void DwarfExpression::addUnsignedConstant(const APInt &Value) { +void DwarfExpression::addUnsignedConstant(APInt Value, const AsmPrinter &AP) { assert(isImplicitLocation() || isUnknownLocation()); LocationKind = Implicit; + if (AP.getDwarfVersion() >= 4 && !AP.getDwarfDebug()->tuneForSCE()) { + int NumBytes = Value.getBitWidth() / 8; + emitOp(dwarf::DW_OP_implicit_value); + emitUnsigned(NumBytes /*Size of the block in bytes*/); + + // The loop below is emitting the value starting at least significant + // byte, so we need to perform a byte-swap to get the byte order correct + // in case of a big-endian target. + if (AP.getDataLayout().isBigEndian()) + Value = Value.byteSwap(); + + for (int i = 0; i < NumBytes; ++i) { + emitData1(Value.getRawData()[0] & 0xFF); + Value = Value.lshr(8); + } + + return; + } + unsigned Size = Value.getBitWidth(); const uint64_t *Data = Value.getRawData(); @@ -211,9 +230,9 @@ unsigned Offset = 0; while (Offset < Size) { addUnsignedConstant(*Data++); + addStackValue(); if (Offset == 0 && Size <= 64) break; - addStackValue(); addOpPiece(std::min(Size - Offset, 64u), Offset); Offset += 64; } @@ -223,27 +242,13 @@ assert(isImplicitLocation() || isUnknownLocation()); APInt API = APF.bitcastToAPInt(); int NumBytes = API.getBitWidth() / 8; - if (NumBytes == 4 /*float*/ || NumBytes == 8 /*double*/) { + if (NumBytes <= 8 /*double*/) { // FIXME: Add support for `long double`. - emitOp(dwarf::DW_OP_implicit_value); - emitUnsigned(NumBytes /*Size of the block in bytes*/); - - // The loop below is emitting the value starting at least significant byte, - // so we need to perform a byte-swap to get the byte order correct in case - // of a big-endian target. - if (AP.getDataLayout().isBigEndian()) - API = API.byteSwap(); - - for (int i = 0; i < NumBytes; ++i) { - emitData1(API.getZExtValue() & 0xFF); - API = API.lshr(8); - } - - return; - } - LLVM_DEBUG( - dbgs() << "Skipped DW_OP_implicit_value creation for ConstantFP of size: " - << API.getBitWidth() << " bits\n"); + addUnsignedConstant(API, AP); + } else + LLVM_DEBUG( + dbgs() << "Skipped DwarfExpression creation for ConstantFP of size" + << API.getBitWidth() << " bits\n"); } bool DwarfExpression::addMachineRegExpression(const TargetRegisterInfo &TRI, diff --git a/llvm/test/DebugInfo/X86/implicit_value-int128_t.ll b/llvm/test/DebugInfo/X86/implicit_value-int128_t.ll new file mode 100644 --- /dev/null +++ b/llvm/test/DebugInfo/X86/implicit_value-int128_t.ll @@ -0,0 +1,46 @@ +; RUN: llc -debugger-tune=gdb -filetype=obj %s -o - | llvm-dwarfdump - \ +; RUN: | FileCheck %s --check-prefixes=GDB,BOTH +; RUN: llc -debugger-tune=sce -filetype=obj %s -o - | llvm-dwarfdump - \ +; RUN: | FileCheck %s --check-prefixes=SCE,BOTH + +; BOTH: DW_TAG_variable +; BOTH-NEXT: DW_AT_location +; GDB-NEXT: {{.*}}: DW_OP_implicit_value 0x10 0x0f 0x0e 0x0d 0x0c 0x0b 0x0a 0x09 0x08 0x07 0x06 0x05 0x04 0x03 0x02 0x01 0x00 +; SCE-NEXT: {{.*}}: DW_OP_constu 0x8090a0b0c0d0e0f, DW_OP_stack_value, DW_OP_piece 0x8, DW_OP_constu 0x1020304050607, DW_OP_stack_value, DW_OP_bit_piece 0x40 0x40 +; GDB-NEXT: {{.*}}: DW_OP_implicit_value 0x10 0x00 0x10 0x20 0x30 0x40 0x50 0x60 0x70 0x80 0x90 0xa0 0xb0 0xc0 0xd0 0xe0 0xf0) +; SCE-NEXT: {{.*}}: DW_OP_constu 0x7060504030201000, DW_OP_stack_value, DW_OP_piece 0x8, DW_OP_constu 0xf0e0d0c0b0a09080, DW_OP_stack_value, DW_OP_bit_piece 0x40 0x40 +; BOTH-NEXT: DW_AT_name ("a") + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define dso_local void @f() local_unnamed_addr !dbg !7 { +entry: + call void @llvm.dbg.value(metadata i128 5233100606242806050955395731361295, metadata !12, metadata !DIExpression()), !dbg !15 + tail call void @g(), !dbg !15 + call void @llvm.dbg.value(metadata i128 320182027492359845421654932427609477120, metadata !12, metadata !DIExpression()), !dbg !15 + tail call void @g(), !dbg !15 + ret void, !dbg !15 +} + +declare dso_local void @g() local_unnamed_addr + +declare void @llvm.dbg.value(metadata, metadata, metadata) #2 + +attributes #2 = { nofree nosync nounwind readnone speculatable willreturn } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5} + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, emissionKind: FullDebug, enums: !2) +!1 = !DIFile(filename: "-", directory: "/") +!2 = !{} +!3 = !{i32 7, !"Dwarf Version", i32 4} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"wchar_size", i32 4} +!7 = distinct !DISubprogram(name: "f", scope: !1, file: !1, type: !9, unit: !0) +!9 = !DISubroutineType(types: !10) +!10 = !{null} +!12 = !DILocalVariable(name: "a", scope: !7, file: !1, type: !14) +!14 = !DIBasicType(name: "__int128", size: 128, encoding: DW_ATE_signed) +!15 = !DILocation(line: 0, scope: !7)