[llvm] e3c0b0f - [WebAssembly] locals can now be indirect in DWARF

Wouter van Oortmerssen via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 5 11:15:11 PST 2021


Author: Wouter van Oortmerssen
Date: 2021-02-05T11:14:42-08:00
New Revision: e3c0b0fe0958ef766aee01fc517f6476e712ff39

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

LOG: [WebAssembly] locals can now be indirect in DWARF

This for example to indicate that byval args are represented by a pointer to a struct.
Followup to https://reviews.llvm.org/D94140

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

Added: 
    

Modified: 
    llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
    llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
    llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
    llvm/lib/Target/WebAssembly/WebAssembly.h
    llvm/lib/Target/WebAssembly/WebAssemblyDebugValueManager.cpp
    llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp
    llvm/test/MC/WebAssembly/debug-byval-struct.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
index 69ff3baa8e34..f76d417a5e2b 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
@@ -2501,8 +2501,8 @@ void DwarfDebug::emitDebugLocValue(const AsmPrinter &AP, const DIBasicType *BT,
     // encoding is supported.
     assert(AP.TM.getTargetTriple().isWasm());
     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() &&
         !ExprCursor) {

diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
index 59ad7646ce1c..ae52c174d7c1 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
@@ -664,9 +664,14 @@ void DwarfExpression::emitLegacyZExt(unsigned FromBits) {
 }
 
 void DwarfExpression::addWasmLocation(unsigned Index, uint64_t Offset) {
-  assert(LocationKind == Implicit || LocationKind == Unknown);
-  LocationKind = Implicit;
   emitOp(dwarf::DW_OP_WASM_location);
-  emitUnsigned(Index);
+  emitUnsigned(Index == 4/*TI_LOCAL_INDIRECT*/ ? 0/*TI_LOCAL*/ : Index);
   emitUnsigned(Offset);
+  if (Index == 4 /*TI_LOCAL_INDIRECT*/) {
+    assert(LocationKind == Unknown);
+    LocationKind = Memory;
+  } else {
+    assert(LocationKind == Implicit || LocationKind == Unknown);
+    LocationKind = Implicit;
+  }
 }

diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
index 6618a7731e92..4293e52ea762 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
@@ -174,7 +174,10 @@ bool DWARFExpression::Operation::extract(DataExtractor Data,
     case Operation::WasmLocationArg:
       assert(Operand == 1);
       switch (Operands[0]) {
-      case 0: case 1: case 2:
+      case 0:
+      case 1:
+      case 2:
+      case 4:
         Operands[Operand] = Data.getULEB128(&Offset);
         break;
       case 3: // global as uint32
@@ -294,8 +297,11 @@ bool DWARFExpression::Operation::print(raw_ostream &OS, DIDumpOptions DumpOpts,
     } else if (Size == Operation::WasmLocationArg) {
       assert(Operand == 1);
       switch (Operands[0]) {
-      case 0: case 1: case 2:
+      case 0:
+      case 1:
+      case 2:
       case 3: // global as uint32
+      case 4:
         OS << format(" 0x%" PRIx64, Operands[Operand]);
         break;
       default: assert(false);

diff  --git a/llvm/lib/Target/WebAssembly/WebAssembly.h b/llvm/lib/Target/WebAssembly/WebAssembly.h
index 9ce02f7731e0..e812d0047961 100644
--- a/llvm/lib/Target/WebAssembly/WebAssembly.h
+++ b/llvm/lib/Target/WebAssembly/WebAssembly.h
@@ -87,10 +87,14 @@ enum TargetIndex {
   TI_LOCAL,
   // Followed by an absolute global index (ULEB). DEPRECATED.
   TI_GLOBAL_FIXED,
+  // Followed by the index from the bottom of the Wasm stack.
   TI_OPERAND_STACK,
   // Followed by a compilation unit relative global index (uint32_t)
   // that will have an associated relocation.
-  TI_GLOBAL_RELOC
+  TI_GLOBAL_RELOC,
+  // Like TI_LOCAL, but indicates an indirect value (e.g. byval arg
+  // passed by pointer).
+  TI_LOCAL_INDIRECT
 };
 } // end namespace WebAssembly
 

diff  --git a/llvm/lib/Target/WebAssembly/WebAssemblyDebugValueManager.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyDebugValueManager.cpp
index 78191ae758fe..c63656a3012b 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyDebugValueManager.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyDebugValueManager.cpp
@@ -59,7 +59,11 @@ void WebAssemblyDebugValueManager::clone(MachineInstr *Insert,
 
 void WebAssemblyDebugValueManager::replaceWithLocal(unsigned LocalId) {
   for (auto *DBI : DbgValues) {
-    MachineOperand &Op = DBI->getDebugOperand(0);
-    Op.ChangeToTargetIndex(llvm::WebAssembly::TI_LOCAL, LocalId);
+    MachineOperand &Op0 = DBI->getDebugOperand(0);
+    MachineOperand &Op1 = DBI->getOperand(1);
+    bool Indirect = Op1.isImm() && Op1.getImm() == 0;
+    Op0.ChangeToTargetIndex(Indirect ? llvm::WebAssembly::TI_LOCAL_INDIRECT
+                                     : llvm::WebAssembly::TI_LOCAL,
+                            LocalId);
   }
 }

diff  --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp
index db2ad05b4cdf..5dbe7a790824 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp
@@ -210,6 +210,7 @@ WebAssemblyInstrInfo::getSerializableTargetIndices() const {
       {WebAssembly::TI_LOCAL, "wasm-local"},
       {WebAssembly::TI_GLOBAL_FIXED, "wasm-global-fixed"},
       {WebAssembly::TI_OPERAND_STACK, "wasm-operand-stack"},
-      {WebAssembly::TI_GLOBAL_RELOC, "wasm-global-reloc"}};
+      {WebAssembly::TI_GLOBAL_RELOC, "wasm-global-reloc"},
+      {WebAssembly::TI_LOCAL_INDIRECT, "wasm-local-indirect"}};
   return makeArrayRef(TargetIndices);
 }

diff  --git a/llvm/test/MC/WebAssembly/debug-byval-struct.ll b/llvm/test/MC/WebAssembly/debug-byval-struct.ll
index 9d90764a3708..54074ee493b0 100644
--- a/llvm/test/MC/WebAssembly/debug-byval-struct.ll
+++ b/llvm/test/MC/WebAssembly/debug-byval-struct.ll
@@ -103,11 +103,11 @@ attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
 ; CHECK-NEXT:     DW_AT_name    ("x")
 
 ; CHECK-LABEL:  DW_TAG_formal_parameter
-; CHECK-NEXT:     DW_AT_location        (DW_OP_WASM_location 0x0 0x1, DW_OP_stack_value)
+; CHECK-NEXT:     DW_AT_location        (DW_OP_WASM_location 0x0 0x1)
 ; CHECK-NEXT:     DW_AT_name    ("some_union")
 
 ; CHECK-LABEL:  DW_TAG_formal_parameter
-; CHECK-NEXT:     DW_AT_location        (DW_OP_WASM_location 0x0 0x2, DW_OP_stack_value)
+; CHECK-NEXT:     DW_AT_location        (DW_OP_WASM_location 0x0 0x2)
 ; CHECK-NEXT:     DW_AT_name    ("some_struct")
 
 ; CHECK-LABEL:  DW_TAG_formal_parameter


        


More information about the llvm-commits mailing list