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

Alkis Evlogimenos alkis at cs.uiuc.edu
Wed Oct 8 00:21:16 PDT 2003


Changes in directory llvm/lib/CodeGen:

RegAllocSimple.cpp updated: 1.43 -> 1.44
RegAllocLocal.cpp updated: 1.27 -> 1.28
PrologEpilogInserter.cpp updated: 1.12 -> 1.13
LiveVariables.cpp updated: 1.8 -> 1.9

---
Log message:

Change MRegisterDesc::AliasSet, TargetInstrDescriptor::ImplicitDefs
and TargetInstrDescriptor::ImplicitUses to always point to a null
terminated array and never be null. So there is no need to check for
pointer validity when iterating over those sets. Code that looked
like:

if (const unsigned* AS = TID.ImplicitDefs) {
  for (int i = 0; AS[i]; ++i) {
    // use AS[i]
  }
}

was changed to:

for (const unsigned* AS = TID.ImplicitDefs; *AS; ++AS) {
  // use *AS
}


---
Diffs of the changes:  (+54 -44)

Index: llvm/lib/CodeGen/RegAllocSimple.cpp
diff -u llvm/lib/CodeGen/RegAllocSimple.cpp:1.43 llvm/lib/CodeGen/RegAllocSimple.cpp:1.44
--- llvm/lib/CodeGen/RegAllocSimple.cpp:1.43	Mon Aug 18 09:31:23 2003
+++ llvm/lib/CodeGen/RegAllocSimple.cpp	Wed Oct  8 00:20:08 2003
@@ -153,13 +153,13 @@
     // are used by the instruction (including implicit uses)
     unsigned Opcode = MI->getOpcode();
     const TargetInstrDescriptor &Desc = TM->getInstrInfo().get(Opcode);
-    if (const unsigned *Regs = Desc.ImplicitUses)
-      while (*Regs)
-	RegsUsed[*Regs++] = true;
+    const unsigned *Regs = Desc.ImplicitUses;
+    while (*Regs)
+      RegsUsed[*Regs++] = true;
     
-    if (const unsigned *Regs = Desc.ImplicitDefs)
-      while (*Regs)
-	RegsUsed[*Regs++] = true;
+    Regs = Desc.ImplicitDefs;
+    while (*Regs)
+      RegsUsed[*Regs++] = true;
     
     // Loop over uses, move from memory into registers
     for (int i = MI->getNumOperands() - 1; i >= 0; --i) {


Index: llvm/lib/CodeGen/RegAllocLocal.cpp
diff -u llvm/lib/CodeGen/RegAllocLocal.cpp:1.27 llvm/lib/CodeGen/RegAllocLocal.cpp:1.28
--- llvm/lib/CodeGen/RegAllocLocal.cpp:1.27	Sat Aug 23 18:49:42 2003
+++ llvm/lib/CodeGen/RegAllocLocal.cpp	Wed Oct  8 00:20:08 2003
@@ -120,9 +120,10 @@
     ///
     bool areRegsEqual(unsigned R1, unsigned R2) const {
       if (R1 == R2) return true;
-      if (const unsigned *AliasSet = RegInfo->getAliasSet(R2))
-        for (unsigned i = 0; AliasSet[i]; ++i)
-          if (AliasSet[i] == R1) return true;
+      for (const unsigned *AliasSet = RegInfo->getAliasSet(R2);
+           *AliasSet; ++AliasSet) {
+        if (*AliasSet == R1) return true;
+      }
       return false;
     }
 
@@ -271,14 +272,15 @@
   if (PI != PhysRegsUsed.end()) {             // Only spill it if it's used!
     if (PI->second || !OnlyVirtRegs)
       spillVirtReg(MBB, I, PI->second, PhysReg);
-  } else if (const unsigned *AliasSet = RegInfo->getAliasSet(PhysReg)) {
+  } else {
     // If the selected register aliases any other registers, we must make
     // sure that one of the aliases isn't alive...
-    for (unsigned i = 0; AliasSet[i]; ++i) {
-      PI = PhysRegsUsed.find(AliasSet[i]);
+    for (const unsigned *AliasSet = RegInfo->getAliasSet(PhysReg);
+         *AliasSet; ++AliasSet) {
+      PI = PhysRegsUsed.find(*AliasSet);
       if (PI != PhysRegsUsed.end())     // Spill aliased register...
         if (PI->second || !OnlyVirtRegs)
-          spillVirtReg(MBB, I, PI->second, AliasSet[i]);
+          spillVirtReg(MBB, I, PI->second, *AliasSet);
     }
   }
 }
@@ -308,10 +310,10 @@
 
   // If the selected register aliases any other allocated registers, it is
   // not free!
-  if (const unsigned *AliasSet = RegInfo->getAliasSet(PhysReg))
-    for (unsigned i = 0; AliasSet[i]; ++i)
-      if (PhysRegsUsed.count(AliasSet[i])) // Aliased register in use?
-        return false;                      // Can't use this reg then.
+  for (const unsigned *AliasSet = RegInfo->getAliasSet(PhysReg);
+       *AliasSet; ++AliasSet)
+    if (PhysRegsUsed.count(*AliasSet)) // Aliased register in use?
+      return false;                    // Can't use this reg then.
   return true;
 }
 
@@ -414,12 +416,13 @@
         } else {
           // If one of the registers aliased to the current register is
           // compatible, use it.
-          if (const unsigned *AliasSet = RegInfo->getAliasSet(R))
-            for (unsigned a = 0; AliasSet[a]; ++a)
-              if (RegInfo->getRegClass(AliasSet[a]) == RC) {
-                PhysReg = AliasSet[a];    // Take an aliased register
-                break;
-              }
+          for (const unsigned *AliasSet = RegInfo->getAliasSet(R);
+               *AliasSet; ++AliasSet) {
+            if (RegInfo->getRegClass(*AliasSet) == RC) {
+              PhysReg = *AliasSet;    // Take an aliased register
+              break;
+            }
+          }
         }
       }
     }
@@ -485,9 +488,9 @@
 
     // Loop over the implicit uses, making sure that they are at the head of the
     // use order list, so they don't get reallocated.
-    if (const unsigned *ImplicitUses = TID.ImplicitUses)
-      for (unsigned i = 0; ImplicitUses[i]; ++i)
-        MarkPhysRegRecentlyUsed(ImplicitUses[i]);
+    for (const unsigned *ImplicitUses = TID.ImplicitUses;
+         *ImplicitUses; ++ImplicitUses)
+        MarkPhysRegRecentlyUsed(*ImplicitUses);
 
     // Get the used operands into registers.  This has the potential to spill
     // incoming values if we are out of registers.  Note that we completely


Index: llvm/lib/CodeGen/PrologEpilogInserter.cpp
diff -u llvm/lib/CodeGen/PrologEpilogInserter.cpp:1.12 llvm/lib/CodeGen/PrologEpilogInserter.cpp:1.13
--- llvm/lib/CodeGen/PrologEpilogInserter.cpp:1.12	Wed Aug 13 13:18:12 2003
+++ llvm/lib/CodeGen/PrologEpilogInserter.cpp	Wed Oct  8 00:20:08 2003
@@ -127,12 +127,15 @@
     unsigned Reg = CSRegs[i];
     if (ModifiedRegs[Reg]) {
       RegsToSave.push_back(Reg);  // If modified register...
-    } else if (const unsigned *AliasSet = RegInfo->getAliasSet(Reg))
-      for (unsigned j = 0; AliasSet[j]; ++j)     // Check alias registers too...
-	if (ModifiedRegs[AliasSet[j]]) {
+    } else {
+      for (const unsigned *AliasSet = RegInfo->getAliasSet(Reg);
+           *AliasSet; ++AliasSet) {  // Check alias registers too...
+	if (ModifiedRegs[*AliasSet]) {
 	  RegsToSave.push_back(Reg);
 	  break;
 	}
+      }
+    }
   }
 
   if (RegsToSave.empty())


Index: llvm/lib/CodeGen/LiveVariables.cpp
diff -u llvm/lib/CodeGen/LiveVariables.cpp:1.8 llvm/lib/CodeGen/LiveVariables.cpp:1.9
--- llvm/lib/CodeGen/LiveVariables.cpp:1.8	Mon May 26 19:05:17 2003
+++ llvm/lib/CodeGen/LiveVariables.cpp	Wed Oct  8 00:20:08 2003
@@ -108,12 +108,14 @@
   if (PhysRegInfo[Reg]) {
     PhysRegInfo[Reg] = MI;
     PhysRegUsed[Reg] = true;
-  } else if (const unsigned *AliasSet = RegInfo->getAliasSet(Reg)) {
-    for (; unsigned NReg = AliasSet[0]; ++AliasSet)
-      if (MachineInstr *LastUse = PhysRegInfo[NReg]) {
-	PhysRegInfo[NReg] = MI;
-	PhysRegUsed[NReg] = true;
+  } else {
+    for (const unsigned *AliasSet = RegInfo->getAliasSet(Reg);
+         *AliasSet; ++AliasSet) {
+      if (MachineInstr *LastUse = PhysRegInfo[*AliasSet]) {
+	PhysRegInfo[*AliasSet] = MI;
+	PhysRegUsed[*AliasSet] = true;
       }
+    }
   }
 }
 
@@ -124,15 +126,17 @@
       RegistersKilled.insert(std::make_pair(LastUse, Reg));
     else
       RegistersDead.insert(std::make_pair(LastUse, Reg));
-  } else if (const unsigned *AliasSet = RegInfo->getAliasSet(Reg)) {
-    for (; unsigned NReg = AliasSet[0]; ++AliasSet)
-      if (MachineInstr *LastUse = PhysRegInfo[NReg]) {
-	if (PhysRegUsed[NReg])
-	  RegistersKilled.insert(std::make_pair(LastUse, NReg));
+  } 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, NReg));
-	PhysRegInfo[NReg] = 0;  // Kill the aliased register
+	  RegistersDead.insert(std::make_pair(LastUse, *AliasSet));
+	PhysRegInfo[*AliasSet] = 0;  // Kill the aliased register
       }
+    }
   }
   PhysRegInfo[Reg] = MI;
   PhysRegUsed[Reg] = false;
@@ -206,9 +210,9 @@
 	NumOperandsToProcess = 1;
 
       // Loop over implicit uses, using them.
-      if (const unsigned *ImplicitUses = MID.ImplicitUses)
-	for (unsigned i = 0; ImplicitUses[i]; ++i)
-	  HandlePhysRegUse(ImplicitUses[i], MI);
+      for (const unsigned *ImplicitUses = MID.ImplicitUses;
+           *ImplicitUses; ++ImplicitUses)
+	HandlePhysRegUse(*ImplicitUses, MI);
 
       // Process all explicit uses...
       for (unsigned i = 0; i != NumOperandsToProcess; ++i) {





More information about the llvm-commits mailing list