Split the argument unscheduling loop in the WebAssembly register
authorEric Christopher <echristo@gmail.com>
Fri, 20 Nov 2015 00:34:54 +0000 (00:34 +0000)
committerEric Christopher <echristo@gmail.com>
Fri, 20 Nov 2015 00:34:54 +0000 (00:34 +0000)
coloring pass. Turn the logic into "look for an insert point and
then move things past the insert point".

No functional change intended.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253626 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/WebAssembly/WebAssemblyRegColoring.cpp

index 7f27e7cede6ad12e9ece20e3bbcc91fa6e64e8ce..bf21024a731b0fd3103ad903d871938561b7fa5f 100644 (file)
@@ -98,20 +98,30 @@ 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.
 
   // 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();
   bool MovedArg = false;
   MachineBasicBlock &EntryMBB = MF.front();
-  for (auto MII = EntryMBB.begin(); MII != EntryMBB.end(); ) {
-    MachineInstr *MI = &*MII++;
+  MachineBasicBlock::iterator InsertPt = EntryMBB.end();
+  // 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;
+    }
+  }
+  // Now move any argument instructions later in the block
+  // to before our first NonArg instruction.
+  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) {
     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) {
     }
   }
   if (MovedArg) {