[llvm-commits] CVS: llvm/lib/CodeGen/RegAllocLocal.cpp LiveVariables.cpp LiveIntervals.cpp

Alkis Evlogimenos alkis at cs.uiuc.edu
Tue Jan 13 00:25:01 PST 2004


Changes in directory llvm/lib/CodeGen:

RegAllocLocal.cpp updated: 1.36 -> 1.37
LiveVariables.cpp updated: 1.13 -> 1.14
LiveIntervals.cpp updated: 1.19 -> 1.20

---
Log message:

Correctly compute live variable information for physical registers
when an implicitely defined register is later used by an alias. For example:

         call foo
         %reg1024 = mov %AL

The call implicitely defines EAX but only AL is used. Before this fix
no information was available on AL. Now EAX and all its aliases except
AL get defined and die at the call instruction whereas AL lives to be
killed by the assignment.


---
Diffs of the changes:  (+30 -33)

Index: llvm/lib/CodeGen/RegAllocLocal.cpp
diff -u llvm/lib/CodeGen/RegAllocLocal.cpp:1.36 llvm/lib/CodeGen/RegAllocLocal.cpp:1.37
--- llvm/lib/CodeGen/RegAllocLocal.cpp:1.36	Thu Dec 18 16:40:23 2003
+++ llvm/lib/CodeGen/RegAllocLocal.cpp	Tue Jan 13 00:24:30 2004
@@ -232,9 +232,8 @@
 
   std::vector<unsigned>::iterator It =
     std::find(PhysRegsUseOrder.begin(), PhysRegsUseOrder.end(), PhysReg);
-  assert(It != PhysRegsUseOrder.end() &&
-         "Spilled a physical register, but it was not in use list!");
-  PhysRegsUseOrder.erase(It);
+  if (It != PhysRegsUseOrder.end())
+    PhysRegsUseOrder.erase(It);
 }
 
 
@@ -550,6 +549,11 @@
         spillPhysReg(MBB, I, Reg, true);  // Spill any existing value in the reg
         PhysRegsUsed[Reg] = 0;            // It is free and reserved now
         PhysRegsUseOrder.push_back(Reg);
+        for (const unsigned *AliasSet = RegInfo->getAliasSet(Reg);
+             *AliasSet; ++AliasSet) {
+            PhysRegsUseOrder.push_back(*AliasSet);
+            PhysRegsUsed[*AliasSet] = 0;  // It is free and reserved now
+        }
       }
 
     // Loop over the implicit defs, spilling them as well.
@@ -559,6 +563,11 @@
       spillPhysReg(MBB, I, Reg);
       PhysRegsUseOrder.push_back(Reg);
       PhysRegsUsed[Reg] = 0;            // It is free and reserved now
+      for (const unsigned *AliasSet = RegInfo->getAliasSet(Reg);
+           *AliasSet; ++AliasSet) {
+          PhysRegsUseOrder.push_back(*AliasSet);
+          PhysRegsUsed[*AliasSet] = 0;  // It is free and reserved now
+      }
     }
 
     // Okay, we have allocated all of the source operands and spilled any values


Index: llvm/lib/CodeGen/LiveVariables.cpp
diff -u llvm/lib/CodeGen/LiveVariables.cpp:1.13 llvm/lib/CodeGen/LiveVariables.cpp:1.14
--- llvm/lib/CodeGen/LiveVariables.cpp:1.13	Sun Dec 14 07:24:17 2003
+++ llvm/lib/CodeGen/LiveVariables.cpp	Tue Jan 13 00:24:30 2004
@@ -117,14 +117,6 @@
   if (PhysRegInfo[Reg]) {
     PhysRegInfo[Reg] = MI;
     PhysRegUsed[Reg] = true;
-  } else {
-    for (const unsigned *AliasSet = RegInfo->getAliasSet(Reg);
-         *AliasSet; ++AliasSet) {
-      if (MachineInstr *LastUse = PhysRegInfo[*AliasSet]) {
-	PhysRegInfo[*AliasSet] = MI;
-	PhysRegUsed[*AliasSet] = true;
-      }
-    }
   }
 }
 
@@ -135,20 +127,21 @@
       RegistersKilled.insert(std::make_pair(LastUse, Reg));
     else
       RegistersDead.insert(std::make_pair(LastUse, Reg));
-  } else {
-    for (const unsigned *AliasSet = RegInfo->getAliasSet(Reg);
-         *AliasSet; ++AliasSet) {
-      if (MachineInstr *LastUse = PhysRegInfo[*AliasSet]) {
-	if (PhysRegUsed[*AliasSet])
-	  RegistersKilled.insert(std::make_pair(LastUse, *AliasSet));
-	else
-	  RegistersDead.insert(std::make_pair(LastUse, *AliasSet));
-	PhysRegInfo[*AliasSet] = 0;  // Kill the aliased register
-      }
-    }
   }
   PhysRegInfo[Reg] = MI;
   PhysRegUsed[Reg] = false;
+
+  for (const unsigned *AliasSet = RegInfo->getAliasSet(Reg);
+       *AliasSet; ++AliasSet) {
+    if (MachineInstr *LastUse = PhysRegInfo[*AliasSet]) {
+      if (PhysRegUsed[*AliasSet])
+	RegistersKilled.insert(std::make_pair(LastUse, *AliasSet));
+      else
+	RegistersDead.insert(std::make_pair(LastUse, *AliasSet));
+    }
+    PhysRegInfo[*AliasSet] = MI;
+    PhysRegUsed[*AliasSet] = false;
+  }
 }
 
 bool LiveVariables::runOnMachineFunction(MachineFunction &MF) {


Index: llvm/lib/CodeGen/LiveIntervals.cpp
diff -u llvm/lib/CodeGen/LiveIntervals.cpp:1.19 llvm/lib/CodeGen/LiveIntervals.cpp:1.20
--- llvm/lib/CodeGen/LiveIntervals.cpp:1.19	Tue Jan  6 19:45:58 2004
+++ llvm/lib/CodeGen/LiveIntervals.cpp	Tue Jan 13 00:24:30 2004
@@ -261,6 +261,8 @@
     if (reg < MRegisterInfo::FirstVirtualRegister) {
         if (allocatableRegisters_[reg]) {
             handlePhysicalRegisterDef(mbb, mi, reg);
+            for (const unsigned* as = mri_->getAliasSet(reg); *as; ++as)
+                handlePhysicalRegisterDef(mbb, mi, *as);
         }
     }
     else {
@@ -300,10 +302,8 @@
                   instr->print(std::cerr, *tm_););
 
             // handle implicit defs
-            for (const unsigned* id = tid.ImplicitDefs; *id; ++id) {
-                unsigned physReg = *id;
-                handlePhysicalRegisterDef(mbb, mi, physReg);
-            }
+            for (const unsigned* id = tid.ImplicitDefs; *id; ++id)
+                handleRegisterDef(mbb, mi, *id);
 
             // handle explicit defs
             for (int i = instr->getNumOperands() - 1; i >= 0; --i) {
@@ -312,14 +312,9 @@
                 if (!mop.isRegister())
                     continue;
 
-                unsigned reg = mop.getAllocatedRegNum();
                 // handle defs - build intervals
-                if (mop.isDef()) {
-                    if (reg < MRegisterInfo::FirstVirtualRegister)
-                        handlePhysicalRegisterDef(mbb, mi, reg);
-                    else
-                        handleVirtualRegisterDef(mbb, mi, reg);
-                }
+                if (mop.isDef())
+                    handleRegisterDef(mbb, mi, mop.getAllocatedRegNum());
             }
         }
     }





More information about the llvm-commits mailing list