[llvm] [MachineInstr] add insert method for variadic instructions (PR #67699)

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 30 10:04:58 PDT 2023


================
@@ -2475,3 +2475,45 @@ MachineInstr::getFirst5RegLLTs() const {
       Reg2, getRegInfo()->getType(Reg2), Reg3, getRegInfo()->getType(Reg3),
       Reg4, getRegInfo()->getType(Reg4));
 }
+
+void MachineInstr::insert(mop_iterator It, ArrayRef<MachineOperand> Ops) {
+  if (!It || Ops.empty())
+    return;
+
+  // Do one pass to untie operands.
+  DenseMap<unsigned, unsigned> TiedOpIndices;
+  for (const MachineOperand &MO : operands()) {
+    if (MO.isReg() && MO.isTied()) {
+      unsigned OpNo = getOperandNo(&MO);
+      unsigned TiedTo = findTiedOperandIdx(OpNo);
+      TiedOpIndices[OpNo] = TiedTo;
+      untieRegOperand(OpNo);
+    }
+  }
+
+  assert(It->getParent() == this && "iterator points to operand of other inst");
+  const unsigned OpIdx = getOperandNo(It);
+  const unsigned NumOperands = getNumOperands();
+  const unsigned OpsToMove = NumOperands - OpIdx;
+
+  SmallVector<MachineOperand> MovingOps;
+  MovingOps.reserve(OpsToMove);
+
+  for (unsigned I = 0; I < OpsToMove; ++I) {
+    MovingOps.emplace_back(getOperand(OpIdx));
+    removeOperand(OpIdx);
----------------
MatzeB wrote:

make sense. I haven't looked at the code as deeply as you have; just wanted to ask the questions to make sure :)

https://github.com/llvm/llvm-project/pull/67699


More information about the llvm-commits mailing list