LinearScanner hotspot.
[oota-llvm.git] / lib / CodeGen / RegAllocLocal.cpp
index 2b249b2f825c95681df627d70185f0fbdbb26779..e42603e62993a90ba6a4dab291430843ead9fdea 100644 (file)
@@ -580,6 +580,9 @@ void RA::AllocateBasicBlock(MachineBasicBlock &MBB) {
         unsigned &PhysRegSlot = getVirt2PhysRegMapSlot(VirtReg);
         PhysReg = PhysRegSlot;
         PhysRegSlot = 0;
+      } else if (PhysRegsUsed[PhysReg] == -2) {
+        // Unallocatable register dead, ignore.
+        continue;
       }
 
       if (PhysReg) {
@@ -596,6 +599,8 @@ void RA::AllocateBasicBlock(MachineBasicBlock &MBB) {
       if (MO.isRegister() && MO.isDef() && MO.getReg() &&
           MRegisterInfo::isPhysicalRegister(MO.getReg())) {
         unsigned Reg = MO.getReg();
+        if (PhysRegsUsed[Reg] == -2) continue;  // Something like ESP.
+            
         PhysRegsEverUsed[Reg] = true;
         spillPhysReg(MBB, MI, Reg, true); // Spill any existing value in the reg
         PhysRegsUsed[Reg] = 0;            // It is free and reserved now
@@ -616,18 +621,21 @@ void RA::AllocateBasicBlock(MachineBasicBlock &MBB) {
       for (const unsigned *ImplicitDefs = TID.ImplicitDefs;
            *ImplicitDefs; ++ImplicitDefs) {
         unsigned Reg = *ImplicitDefs;
-        if (PhysRegsUsed[Reg] == -2) continue;
-
-        spillPhysReg(MBB, MI, Reg, true);
-        PhysRegsUseOrder.push_back(Reg);
-        PhysRegsUsed[Reg] = 0;            // It is free and reserved now
+        bool IsNonAllocatable = PhysRegsUsed[Reg] == -2;
+        if (!IsNonAllocatable) {
+          spillPhysReg(MBB, MI, Reg, true);
+          PhysRegsUseOrder.push_back(Reg);
+          PhysRegsUsed[Reg] = 0;            // It is free and reserved now
+        }
         PhysRegsEverUsed[Reg] = true;
 
         for (const unsigned *AliasSet = RegInfo->getAliasSet(Reg);
              *AliasSet; ++AliasSet) {
           if (PhysRegsUsed[*AliasSet] != -2) {
-            PhysRegsUseOrder.push_back(*AliasSet);
-            PhysRegsUsed[*AliasSet] = 0;  // It is free and reserved now
+            if (!IsNonAllocatable) {
+              PhysRegsUseOrder.push_back(*AliasSet);
+              PhysRegsUsed[*AliasSet] = 0;  // It is free and reserved now
+            }
             PhysRegsEverUsed[*AliasSet] = true;
           }
         }
@@ -667,6 +675,9 @@ void RA::AllocateBasicBlock(MachineBasicBlock &MBB) {
         PhysReg = PhysRegSlot;
         assert(PhysReg != 0);
         PhysRegSlot = 0;
+      } else if (PhysRegsUsed[PhysReg] == -2) {
+        // Unallocatable register dead, ignore.
+        continue;
       }
 
       if (PhysReg) {