[PATCH] D80045: [WebAssembly] iterate stack in DebugFixup from the top.

Wouter van Oortmerssen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 15 16:19:45 PDT 2020


aardappel created this revision.
aardappel added a reviewer: aheejin.
Herald added subscribers: llvm-commits, sunfish, hiraditya, jgravelle-google, sbc100, dschuff.
Herald added a project: LLVM.

This is more efficient in the typical case.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80045

Files:
  llvm/lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp


Index: llvm/lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyDebugFixup.cpp
@@ -86,9 +86,9 @@
           // Search for register rather than assume it is on top (which it
           // typically is if it appears right after the def), since
           // DBG_VALUE's may shift under some circumstances.
-          size_t Depth = 0;
-          for (auto &Elem : Stack) {
+          for (auto &Elem : reverse(Stack)) {
             if (MO.getReg() == Elem.Reg) {
+              auto Depth = static_cast<unsigned>(&Elem - &Stack[0]);
               LLVM_DEBUG(dbgs() << "Debug Value VReg " << MO.getReg()
                                 << " -> Stack Relative " << Depth << "\n");
               MO.ChangeToTargetIndex(WebAssembly::TI_OPERAND_STACK, Depth);
@@ -98,7 +98,6 @@
               Elem.DebugValue = &MI;
               break;
             }
-            Depth++;
           }
           // If the Reg was not found, we have a DBG_VALUE outside of its
           // def-use range, and we leave it unmodified as reg, which means


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80045.264377.patch
Type: text/x-patch
Size: 1202 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200515/eed04731/attachment.bin>


More information about the llvm-commits mailing list