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,12 @@ // 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.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 @@ -200,10 +200,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(); @@ -212,9 +231,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; } @@ -224,27 +243,13 @@ assert(isImplicitLocation() || isUnknownLocation()); APInt API = APF.bitcastToAPInt(); int NumBytes = API.getBitWidth() / 8; - if (NumBytes == 4 /*float*/ || 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"); + // FIXME: Add support for `long double`. + if (NumBytes <= 8 /*double*/) + addUnsignedConstant(API, AP); + else + LLVM_DEBUG( + dbgs() << "Skipped DwarfExpression creation for ConstantFP of size" + << API.getBitWidth() << " bits\n"); } bool DwarfExpression::addMachineRegExpression(const TargetRegisterInfo &TRI,