Avoid adding duplicate function live-in's.
authorEvan Cheng <evan.cheng@apple.com>
Mon, 24 May 2010 21:33:37 +0000 (21:33 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Mon, 24 May 2010 21:33:37 +0000 (21:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@104560 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/MachineRegisterInfo.h
lib/CodeGen/MachineFunction.cpp
lib/CodeGen/MachineRegisterInfo.cpp

index dede05f85c0f27d20586726e4df78d8660d8e7d0..fa14fdc3f19f7973741ce34fc5b0a145626f73ae 100644 (file)
@@ -293,6 +293,10 @@ public:
   /// corresponding live-in physical register.
   unsigned getLiveInPhysReg(unsigned VReg) const;
 
+  /// getLiveInVirtReg - If PReg is a live-in physical register, return the
+  /// corresponding live-in physical register.
+  unsigned getLiveInVirtReg(unsigned PReg) const;
+
   /// EmitLiveInCopies - Emit copies to initialize livein virtual registers
   /// into the given entry block.
   void EmitLiveInCopies(MachineBasicBlock *EntryMBB,
index 3cf10b3ac65d5be698d5626e24796ed699a0f9b7..a38c881982e77f5a07114a1155091bd07b061130 100644 (file)
@@ -398,8 +398,14 @@ void MachineFunction::viewCFGOnly() const
 unsigned MachineFunction::addLiveIn(unsigned PReg,
                                     const TargetRegisterClass *RC) {
   assert(RC->contains(PReg) && "Not the correct regclass!");
-  unsigned VReg = getRegInfo().createVirtualRegister(RC);
-  getRegInfo().addLiveIn(PReg, VReg);
+  MachineRegisterInfo &MRI = getRegInfo();
+  unsigned VReg = MRI.getLiveInVirtReg(PReg);
+  if (VReg) {
+    assert(MRI.getRegClass(VReg) == RC && "Register class mismatch!");
+    return VReg;
+  }
+  VReg = MRI.createVirtualRegister(RC);
+  MRI.addLiveIn(PReg, VReg);
   return VReg;
 }
 
index 402be479eac305be81caeca43a6f921d4d7ec5c2..70bf7e5da5e829f1a1c4ba2b4009b880524b13a8 100644 (file)
@@ -165,6 +165,15 @@ unsigned MachineRegisterInfo::getLiveInPhysReg(unsigned VReg) const {
   return 0;
 }
 
+/// getLiveInVirtReg - If PReg is a live-in physical register, return the
+/// corresponding live-in physical register.
+unsigned MachineRegisterInfo::getLiveInVirtReg(unsigned PReg) const {
+  for (livein_iterator I = livein_begin(), E = livein_end(); I != E; ++I)
+    if (I->first == PReg)
+      return I->second;
+  return 0;
+}
+
 static cl::opt<bool>
 SchedLiveInCopies("schedule-livein-copies", cl::Hidden,
                   cl::desc("Schedule copies of livein registers"),