]> granicus.if.org Git - llvm/commitdiff
RegBankSelect: Allow targets to introduce control flow for mapping
authorMatt Arsenault <Matthew.Arsenault@amd.com>
Thu, 21 Feb 2019 15:48:13 +0000 (15:48 +0000)
committerMatt Arsenault <Matthew.Arsenault@amd.com>
Thu, 21 Feb 2019 15:48:13 +0000 (15:48 +0000)
For AMDGPU, if an operand requires an SGPR but is only available as a
VGPR, a loop needs to be introduced to execute the instruction with
each unique combination of values across all lanes. The rest of the
instructions in the block will be moved to a new block following the
loop. Check if the next instruction's parent changed, and update the
iterators and insertion block if this happened.

Tests will be included in a future patch.

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

lib/CodeGen/GlobalISel/RegBankSelect.cpp

index 2c231709240126a30933665c6c17c3207061cb8c..bd0c141c29858d2dc1d793db5a1a7ba71cec5270 100644 (file)
@@ -692,8 +692,21 @@ bool RegBankSelect::runOnMachineFunction(MachineFunction &MF) {
                            "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();
+        }
+      }
     }
   }
+
   OptMode = SaveOptMode;
   return false;
 }