[llvm-commits] [llvm] r103449 - /llvm/trunk/lib/CodeGen/TwoAddressInstructionPass.cpp

Evan Cheng evan.cheng at apple.com
Mon May 10 17:04:31 PDT 2010


Author: evancheng
Date: Mon May 10 19:04:31 2010
New Revision: 103449

URL: http://llvm.org/viewvc/llvm-project?rev=103449&view=rev
Log:
Ensure REG_SEQUENCE source operands are unique.

Modified:
    llvm/trunk/lib/CodeGen/TwoAddressInstructionPass.cpp

Modified: llvm/trunk/lib/CodeGen/TwoAddressInstructionPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TwoAddressInstructionPass.cpp?rev=103449&r1=103448&r2=103449&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TwoAddressInstructionPass.cpp (original)
+++ llvm/trunk/lib/CodeGen/TwoAddressInstructionPass.cpp Mon May 10 19:04:31 2010
@@ -1164,6 +1164,8 @@
       DEBUG(dbgs() << "Illegal REG_SEQUENCE instruction:" << *MI);
       llvm_unreachable(0);
     }
+
+    SmallSet<unsigned, 4> Seen;
     for (unsigned i = 1, e = MI->getNumOperands(); i < e; i += 2) {
       unsigned SrcReg = MI->getOperand(i).getReg();
       if (MI->getOperand(i).getSubReg() ||
@@ -1171,6 +1173,23 @@
         DEBUG(dbgs() << "Illegal REG_SEQUENCE instruction:" << *MI);
         llvm_unreachable(0);
       }
+
+      if (!Seen.insert(SrcReg)) {
+        // REG_SEQUENCE cannot have duplicated operands. Add a copy.
+        const TargetRegisterClass *RC = MRI->getRegClass(SrcReg);
+        unsigned NewReg = MRI->createVirtualRegister(RC);
+        bool Emitted =
+          TII->copyRegToReg(*MI->getParent(), MI, NewReg, SrcReg, RC, RC,
+                            MI->getDebugLoc());
+        (void)Emitted;
+        assert(Emitted && "Unable to issue a copy instruction!\n");
+        MI->getOperand(i).setReg(NewReg);
+        MI->getOperand(i).setIsKill();
+      }
+    }
+
+    for (unsigned i = 1, e = MI->getNumOperands(); i < e; i += 2) {
+      unsigned SrcReg = MI->getOperand(i).getReg();
       unsigned SrcIdx = MI->getOperand(i+1).getImm();
       UpdateRegSequenceSrcs(SrcReg, DstReg, SrcIdx, MRI);
     }





More information about the llvm-commits mailing list