[llvm-branch-commits] [llvm] 6ef7835 - [DebugInfo] Refactor code for emitting DWARF expressions for FP constants

Pavel Labath via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Nov 23 01:04:07 PST 2020


Author: Pavel Labath
Date: 2020-11-23T09:59:07+01:00
New Revision: 6ef7835afca246e623e9990dcd8c71204f5691e5

URL: https://github.com/llvm/llvm-project/commit/6ef7835afca246e623e9990dcd8c71204f5691e5
DIFF: https://github.com/llvm/llvm-project/commit/6ef7835afca246e623e9990dcd8c71204f5691e5.diff

LOG: [DebugInfo] Refactor code for emitting DWARF expressions for FP constants

This patch moves the selection of the style used to emit the numbers
(DW_OP_implicit_value vs. DW_OP_const+DW_OP_stack_value) into
DwarfExpression::addUnsignedConstant. This logic is not FP-specific, and
it will be needed for large integers too.

The refactor also makes DW_OP_implicit_value (DW_OP_stack_value worked
already) be used for floating point constants other than float and
double, so I've added a _Float16 test for it.

Split off from D90916.

Differential Revision: https://reviews.llvm.org/D91058

Added: 
    llvm/test/DebugInfo/ARM/implicit_value-_Float16.ll

Modified: 
    llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
    llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
    llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 5054ed81fcfc..eb20c9cfa487 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -2466,24 +2466,11 @@ void DwarfDebug::emitDebugLocValue(const AsmPrinter &AP, const DIBasicType *BT,
     // TODO TargetIndexLocation is a target-independent. Currently only the WebAssembly-specific
     // encoding is supported.
     DwarfExpr.addWasmLocation(Loc.Index, static_cast<uint64_t>(Loc.Offset));
-      DwarfExpr.addExpression(std::move(ExprCursor));
-      return;
+    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.addConstantFP(Value.getConstantFP()->getValueAPF(), AP);
+    return;
   }
   DwarfExpr.addExpression(std::move(ExprCursor));
 }

diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
index 59ad7646ce1c..21f7ad1b7b80 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
@@ -200,10 +200,29 @@ void DwarfExpression::addUnsignedConstant(uint64_t Value) {
   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 @@ void DwarfExpression::addUnsignedConstant(const APInt &Value) {
   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 @@ void DwarfExpression::addConstantFP(const APFloat &APF, const AsmPrinter &AP) {
   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,

diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h
index 8fca9f5a630b..796717b525a2 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.h
@@ -297,7 +297,7 @@ class DwarfExpression {
   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/test/DebugInfo/ARM/implicit_value-_Float16.ll b/llvm/test/DebugInfo/ARM/implicit_value-_Float16.ll
new file mode 100644
index 000000000000..60c9ce40c0af
--- /dev/null
+++ b/llvm/test/DebugInfo/ARM/implicit_value-_Float16.ll
@@ -0,0 +1,51 @@
+; 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 0x2 0xe0 0x51
+; SCE-NEXT:      {{.*}}: DW_OP_constu 0x51e0, DW_OP_stack_value
+; GDB-NEXT:      {{.*}}: DW_OP_implicit_value 0x2 0x40 0x51
+; SCE-NEXT:      {{.*}}: DW_OP_constu 0x5140, DW_OP_stack_value
+; BOTH-NEXT:  DW_AT_name    ("a")
+
+source_filename = "-"
+target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
+target triple = "armv7-unknown-unknown"
+
+define dso_local arm_aapcscc void @f() local_unnamed_addr !dbg !8 {
+entry:
+  call void @llvm.dbg.value(metadata half 0xH51E0, metadata !13, metadata !DIExpression()), !dbg !15
+  call arm_aapcscc void bitcast (void (...)* @g to void ()*)(), !dbg !15
+  call void @llvm.dbg.value(metadata half 0xH5140, metadata !13, metadata !DIExpression()), !dbg !15
+  call arm_aapcscc void bitcast (void (...)* @g to void ()*)(), !dbg !15
+  ret void, !dbg !15
+}
+
+declare dso_local arm_aapcscc 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, !6}
+!llvm.ident = !{!7}
+
+!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}
+!6 = !{i32 1, !"min_enum_size", i32 4}
+!7 = !{!"clang version 12.0.0"}
+!8 = distinct !DISubprogram(name: "f", scope: !1, file: !1, type: !10, unit: !0)
+!10 = !DISubroutineType(types: !11)
+!11 = !{null}
+!12 = !{!13}
+!13 = !DILocalVariable(name: "a", scope: !8, file: !1, type: !14)
+!14 = !DIBasicType(name: "_Float16", size: 16, encoding: DW_ATE_float)
+!15 = !DILocation(line: 0, scope: !8)


        


More information about the llvm-branch-commits mailing list