[PATCH] [WebAssembly] rewrite argument unscheduling loop

Eric Christopher via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 19 16:24:47 PST 2015


Hi Dan, JF,

I was getting a weird memory iterator error in this loop (in ToT with
Debug+Asserts), but while I was looking at it I realized we could simplify
the logic a bit if we split the loop apart into two - the part looking for
the new insert point and then the part to look for all of the argument
instructions.

It also solves the problem I was seeing with an invalid EntryBB.begin()
during the insert.

OK?

-eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151120/7b9d45a9/attachment.html>
-------------- next part --------------
diff --git a/lib/Target/WebAssembly/WebAssemblyRegColoring.cpp b/lib/Target/WebAssembly/WebAssemblyRegColoring.cpp
index 7f27e7c..4dde71e 100644
--- a/lib/Target/WebAssembly/WebAssemblyRegColoring.cpp
+++ b/lib/Target/WebAssembly/WebAssemblyRegColoring.cpp
@@ -98,20 +98,29 @@ bool WebAssemblyRegColoring::runOnMachineFunction(MachineFunction &MF) {
 
   // FIXME: If scheduling has moved an ARGUMENT virtual register, move it back,
   // and recompute liveness. This is a temporary hack.
-  bool SawNonArg = false;
   bool MovedArg = false;
   MachineBasicBlock &EntryMBB = MF.front();
-  for (auto MII = EntryMBB.begin(); MII != EntryMBB.end(); ) {
-    MachineInstr *MI = &*MII++;
+  MachineBasicBlock::iterator InsertPt;
+  // Look for the first NonArg instruction
+  for (auto MII = EntryMBB.begin(), MIE = EntryMBB.end(); MII != MIE; ++MII) {
+    MachineInstr *MI = MII;
+    if (MI->getOpcode() != WebAssembly::ARGUMENT_I32 &&
+        MI->getOpcode() != WebAssembly::ARGUMENT_I64 &&
+        MI->getOpcode() != WebAssembly::ARGUMENT_F32 &&
+        MI->getOpcode() != WebAssembly::ARGUMENT_F64) {
+      InsertPt = MII;
+      break;
+    }
+  }
+
+  for (auto I = InsertPt, E = EntryMBB.end(); I != E; ++I) {
+    MachineInstr *MI = I;
     if (MI->getOpcode() == WebAssembly::ARGUMENT_I32 ||
         MI->getOpcode() == WebAssembly::ARGUMENT_I64 ||
         MI->getOpcode() == WebAssembly::ARGUMENT_F32 ||
         MI->getOpcode() == WebAssembly::ARGUMENT_F64) {
-      EntryMBB.insert(EntryMBB.begin(), MI->removeFromParent());
-      if (SawNonArg)
-        MovedArg = true;
-    } else {
-      SawNonArg = true;
+      EntryMBB.insert(InsertPt, MI->removeFromParent());
+      MovedArg = true;
     }
   }
   if (MovedArg) {


More information about the llvm-commits mailing list