More minor changes:
authorChris Lattner <sabre@nondot.org>
Fri, 23 Jul 2004 21:24:19 +0000 (21:24 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 23 Jul 2004 21:24:19 +0000 (21:24 +0000)
 * Inline some functions
 * Eliminate some comparisons from the release build

This is good for another .3 on gcc.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15144 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/LiveIntervalAnalysis.h
lib/CodeGen/LiveIntervalAnalysis.cpp
lib/CodeGen/LiveIntervalAnalysis.h

index bb324e3c796ae041f35a4a6cdad4cbda9cd933c5..b4228ce9b6c8cb45301138bf61548dbddef7b305 100644 (file)
@@ -101,11 +101,20 @@ namespace llvm {
         }
 
         /// getInstructionIndex - returns the base index of instr
-        unsigned getInstructionIndex(MachineInstr* instr) const;
+        unsigned getInstructionIndex(MachineInstr* instr) const {
+          Mi2IndexMap::const_iterator it = mi2iMap_.find(instr);
+          assert(it != mi2iMap_.end() && "Invalid instruction!");
+          return it->second;
+        }
 
         /// getInstructionFromIndex - given an index in any slot of an
         /// instruction return a pointer the instruction
-        MachineInstr* getInstructionFromIndex(unsigned index) const;
+        MachineInstr* getInstructionFromIndex(unsigned index) const {
+          index /= InstrSlots::NUM; // convert index to vector index
+          assert(index < i2miMap_.size() &&
+                 "index does not correspond to an instruction");
+          return i2miMap_[index];
+        }
 
         Intervals& getIntervals() { return intervals_; }
 
@@ -150,7 +159,12 @@ namespace llvm {
         LiveInterval& getOrCreateInterval(unsigned reg);
 
         /// rep - returns the representative of this register
-        unsigned rep(unsigned reg);
+        unsigned rep(unsigned reg) {
+          Reg2RegMap::iterator it = r2rMap_.find(reg);
+          if (it != r2rMap_.end())
+            return it->second = rep(it->second);
+          return reg;
+        }
 
         void printRegName(unsigned reg) const;
     };
index bce9d563a96f7c69dca33ebe43d6fa4bec053797..5d92700af0292e53b4cdf8ee5c7e8c39332816be 100644 (file)
@@ -374,7 +374,7 @@ void LiveIntervals::handleVirtualRegisterDef(MachineBasicBlock* mbb,
     DEBUG(std::cerr << '\n');
 }
 
-void LiveIntervals::handlePhysicalRegisterDef(MachineBasicBlock* mbb,
+void LiveIntervals::handlePhysicalRegisterDef(MachineBasicBlock *MBB,
                                               MachineBasicBlock::iterator mi,
                                               LiveInterval& interval)
 {
@@ -383,7 +383,6 @@ void LiveIntervals::handlePhysicalRegisterDef(MachineBasicBlock* mbb,
     DEBUG(std::cerr << "\t\tregister: "; printRegName(interval.reg));
     typedef LiveVariables::killed_iterator KillIter;
 
-    MachineBasicBlock::iterator e = mbb->end();
     unsigned baseIndex = getInstructionIndex(mi);
     unsigned start = getDefIndex(baseIndex);
     unsigned end = start;
@@ -403,8 +402,9 @@ void LiveIntervals::handlePhysicalRegisterDef(MachineBasicBlock* mbb,
     // If it is not dead on definition, it must be killed by a
     // subsequent instruction. Hence its interval is:
     // [defSlot(def), useSlot(kill)+1)
-    do {
+    while (1) {
         ++mi;
+        assert(mi != MBB->end() && "physreg was not killed in defining block!");
         baseIndex += InstrSlots::NUM;
         for (KillIter ki = lv_->killed_begin(mi), ke = lv_->killed_end(mi);
              ki != ke; ++ki) {
@@ -414,7 +414,7 @@ void LiveIntervals::handlePhysicalRegisterDef(MachineBasicBlock* mbb,
                 goto exit;
             }
         }
-    } while (mi != e);
+    }
 
 exit:
     assert(start < end && "did not find end of interval?");
@@ -422,35 +422,16 @@ exit:
     DEBUG(std::cerr << " +" << LiveRange(start, end) << '\n');
 }
 
-void LiveIntervals::handleRegisterDef(MachineBasicBlock* mbb,
-                                      MachineBasicBlock::iterator mi,
-                                      unsigned reg)
-{
-    if (MRegisterInfo::isPhysicalRegister(reg)) {
-        if (lv_->getAllocatablePhysicalRegisters()[reg]) {
-            handlePhysicalRegisterDef(mbb, mi, getOrCreateInterval(reg));
-            for (const unsigned* as = mri_->getAliasSet(reg); *as; ++as)
-                handlePhysicalRegisterDef(mbb, mi, getOrCreateInterval(*as));
-        }
-    }
-    else
-        handleVirtualRegisterDef(mbb, mi, getOrCreateInterval(reg));
-}
-
-unsigned LiveIntervals::getInstructionIndex(MachineInstr* instr) const
-{
-    Mi2IndexMap::const_iterator it = mi2iMap_.find(instr);
-    return (it == mi2iMap_.end() ?
-            std::numeric_limits<unsigned>::max() :
-            it->second);
-}
-
-MachineInstr* LiveIntervals::getInstructionFromIndex(unsigned index) const
-{
-    index /= InstrSlots::NUM; // convert index to vector index
-    assert(index < i2miMap_.size() &&
-           "index does not correspond to an instruction");
-    return i2miMap_[index];
+void LiveIntervals::handleRegisterDef(MachineBasicBlock *MBB,
+                                      MachineBasicBlock::iterator MI,
+                                      unsigned reg) {
+  if (MRegisterInfo::isVirtualRegister(reg))
+    handleVirtualRegisterDef(MBB, MI, getOrCreateInterval(reg));
+  else if (lv_->getAllocatablePhysicalRegisters()[reg]) {
+    handlePhysicalRegisterDef(MBB, MI, getOrCreateInterval(reg));
+    for (const unsigned* AS = mri_->getAliasSet(reg); *AS; ++AS)
+      handlePhysicalRegisterDef(MBB, MI, getOrCreateInterval(*AS));
+  }
 }
 
 /// computeIntervals - computes the live intervals for virtual
@@ -490,14 +471,6 @@ void LiveIntervals::computeIntervals()
     }
 }
 
-unsigned LiveIntervals::rep(unsigned reg)
-{
-    Reg2RegMap::iterator it = r2rMap_.find(reg);
-    if (it != r2rMap_.end())
-        return it->second = rep(it->second);
-    return reg;
-}
-
 void LiveIntervals::joinIntervalsInMachineBB(MachineBasicBlock *MBB) {
     DEBUG(std::cerr << ((Value*)MBB->getBasicBlock())->getName() << ":\n");
     const TargetInstrInfo& tii = *tm_->getInstrInfo();
index bb324e3c796ae041f35a4a6cdad4cbda9cd933c5..b4228ce9b6c8cb45301138bf61548dbddef7b305 100644 (file)
@@ -101,11 +101,20 @@ namespace llvm {
         }
 
         /// getInstructionIndex - returns the base index of instr
-        unsigned getInstructionIndex(MachineInstr* instr) const;
+        unsigned getInstructionIndex(MachineInstr* instr) const {
+          Mi2IndexMap::const_iterator it = mi2iMap_.find(instr);
+          assert(it != mi2iMap_.end() && "Invalid instruction!");
+          return it->second;
+        }
 
         /// getInstructionFromIndex - given an index in any slot of an
         /// instruction return a pointer the instruction
-        MachineInstr* getInstructionFromIndex(unsigned index) const;
+        MachineInstr* getInstructionFromIndex(unsigned index) const {
+          index /= InstrSlots::NUM; // convert index to vector index
+          assert(index < i2miMap_.size() &&
+                 "index does not correspond to an instruction");
+          return i2miMap_[index];
+        }
 
         Intervals& getIntervals() { return intervals_; }
 
@@ -150,7 +159,12 @@ namespace llvm {
         LiveInterval& getOrCreateInterval(unsigned reg);
 
         /// rep - returns the representative of this register
-        unsigned rep(unsigned reg);
+        unsigned rep(unsigned reg) {
+          Reg2RegMap::iterator it = r2rMap_.find(reg);
+          if (it != r2rMap_.end())
+            return it->second = rep(it->second);
+          return reg;
+        }
 
         void printRegName(unsigned reg) const;
     };