[PATCH] D94347: [WebAssembly] locals can now be indirect in DWARF

Wouter van Oortmerssen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 8 15:29:28 PST 2021


aardappel created this revision.
aardappel added reviewers: dschuff, yurydelendik.
Herald added subscribers: ecnelises, sunfish, hiraditya, jgravelle-google, sbc100.
aardappel requested review of this revision.
Herald added subscribers: llvm-commits, aheejin.
Herald added a project: LLVM.

This for example to indicate that byval args are represented by a pointer to a struct.
We could have used DW_OP_deref for this, but we needed to change TargetIndex
anyway to be able to pass on indirect-ness thru LLVM, so leaving it target specific
seemed cleaner.
Followup to https://reviews.llvm.org/D94140


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94347

Files:
  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


Index: llvm/test/MC/WebAssembly/debug-byval-struct.ll
===================================================================
--- llvm/test/MC/WebAssembly/debug-byval-struct.ll
+++ llvm/test/MC/WebAssembly/debug-byval-struct.ll
@@ -103,11 +103,11 @@
 ; 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 0x4 0x1, DW_OP_stack_value)
 ; 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 0x4 0x2, DW_OP_stack_value)
 ; CHECK-NEXT:     DW_AT_name    ("some_struct")
 
 ; CHECK-LABEL:  DW_TAG_formal_parameter
Index: llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyInstrInfo.cpp
@@ -242,6 +242,7 @@
       {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);
 }
Index: llvm/lib/Target/WebAssembly/WebAssemblyDebugValueManager.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/WebAssemblyDebugValueManager.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyDebugValueManager.cpp
@@ -59,7 +59,11 @@
 
 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);
   }
 }
Index: llvm/lib/Target/WebAssembly/WebAssembly.h
===================================================================
--- llvm/lib/Target/WebAssembly/WebAssembly.h
+++ llvm/lib/Target/WebAssembly/WebAssembly.h
@@ -87,10 +87,14 @@
   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) that needs to be dereferenced.
+  TI_LOCAL_INDIRECT
 };
 } // end namespace WebAssembly
 
Index: llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
===================================================================
--- llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
+++ llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
@@ -174,7 +174,7 @@
     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,7 +294,7 @@
     } else if (Size == Operation::WasmLocationArg) {
       assert(Operand == 1);
       switch (Operands[0]) {
-      case 0: case 1: case 2:
+      case 0: case 1: case 2: case 4:
       case 3: // global as uint32
         OS << format(" 0x%" PRIx64, Operands[Operand]);
         break;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94347.315534.patch
Type: text/x-patch
Size: 3958 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210108/3582147b/attachment.bin>


More information about the llvm-commits mailing list