[PATCH] D111223: [GlobalISel] Pass RegBankSelect to applyMapping

Sebastian Neubauer via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 25 06:05:23 PDT 2021


sebastian-ne updated this revision to Diff 381962.
sebastian-ne added a comment.

I implemented it using an observer and it worked. Then I realized that I never registered the observer anywhere…
So, here’s a simpler implementation that seems to be enough to find all instructions.

The new patch for creating loops around call instructions does not use bundles anymore because they create more problems than they solve (e.g. the legalizer tries and fails to legalize instructions in a bundle). This simplifies the cases that need to be handled.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111223/new/

https://reviews.llvm.org/D111223

Files:
  llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp


Index: llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp
+++ llvm/lib/CodeGen/GlobalISel/RegBankSelect.cpp
@@ -699,11 +699,13 @@
     // Set a sensible insertion point so that subsequent calls to
     // MIRBuilder.
     MIRBuilder.setMBB(*MBB);
-    for (MachineBasicBlock::iterator MII = MBB->begin(), End = MBB->end();
-         MII != End;) {
-      // MI might be invalidated by the assignment, so move the
-      // iterator before hand.
-      MachineInstr &MI = *MII++;
+    SmallVector<MachineInstr *> WorkList;
+    for (MachineInstr &MI : reverse(MBB->instrs()))
+      WorkList.push_back(&MI);
+
+    while (!WorkList.empty()) {
+      MachineInstr &MI = *WorkList.back();
+      WorkList.pop_back();
 
       // Ignore target-specific post-isel instructions: they should use proper
       // regclasses.
@@ -728,18 +730,6 @@
                            "unable to map instruction", MI);
         return false;
       }
-
-      // It's possible the mapping changed control flow, and moved the following
-      // instruction to a new block, so figure out the new parent.
-      if (MII != End) {
-        MachineBasicBlock *NextInstBB = MII->getParent();
-        if (NextInstBB != MBB) {
-          LLVM_DEBUG(dbgs() << "Instruction mapping changed control flow\n");
-          MBB = NextInstBB;
-          MIRBuilder.setMBB(*MBB);
-          End = MBB->end();
-        }
-      }
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111223.381962.patch
Type: text/x-patch
Size: 1523 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211025/da1062b9/attachment.bin>


More information about the llvm-commits mailing list