[llvm-commits] CVS: llvm/lib/CodeGen/LiveIntervalAnalysis.cpp

Chris Lattner lattner at cs.uiuc.edu
Sat Apr 9 09:18:07 PDT 2005



Changes in directory llvm/lib/CodeGen:

LiveIntervalAnalysis.cpp updated: 1.136 -> 1.137
---
Log message:

Adjust live intervals to support a livein set


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

 LiveIntervalAnalysis.cpp |   46 ++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 44 insertions(+), 2 deletions(-)


Index: llvm/lib/CodeGen/LiveIntervalAnalysis.cpp
diff -u llvm/lib/CodeGen/LiveIntervalAnalysis.cpp:1.136 llvm/lib/CodeGen/LiveIntervalAnalysis.cpp:1.137
--- llvm/lib/CodeGen/LiveIntervalAnalysis.cpp:1.136	Thu Mar 10 14:59:51 2005
+++ llvm/lib/CodeGen/LiveIntervalAnalysis.cpp	Sat Apr  9 11:17:50 2005
@@ -91,6 +91,28 @@
   allocatableRegs_ = mri_->getAllocatableSet(fn);
   r2rMap_.grow(mf_->getSSARegMap()->getLastVirtReg());
 
+  // If this function has any live ins, insert a dummy instruction at the
+  // beginning of the function that we will pretend "defines" the values.  This
+  // is to make the interval analysis simpler by providing a number.
+  if (fn.livein_begin() != fn.livein_end()) {
+    unsigned FirstLiveIn = *fn.livein_begin();
+
+    // Find a reg class that contains this live in.
+    const TargetRegisterClass *RC = 0;
+    for (MRegisterInfo::regclass_iterator RCI = mri_->regclass_begin(),
+           E = mri_->regclass_end(); RCI != E; ++RCI)
+      if ((*RCI)->contains(FirstLiveIn)) {
+        RC = *RCI;
+        break;
+      }
+
+    MachineInstr *OldFirstMI = fn.begin()->begin();
+    mri_->copyRegToReg(*fn.begin(), fn.begin()->begin(),
+                       FirstLiveIn, FirstLiveIn, RC);
+    assert(OldFirstMI != fn.begin()->begin() &&
+           "copyRetToReg didn't insert anything!");
+  }
+
   // number MachineInstrs
   unsigned miIndex = 0;
   for (MachineFunction::iterator mbb = mf_->begin(), mbbEnd = mf_->end();
@@ -103,6 +125,19 @@
       miIndex += InstrSlots::NUM;
     }
 
+  // Note intervals due to live-in values.
+  if (fn.livein_begin() != fn.livein_end()) {
+    MachineBasicBlock *Entry = fn.begin();
+    for (MachineFunction::liveinout_iterator I = fn.livein_begin(),
+           E = fn.livein_end(); I != E; ++I) {
+      handlePhysicalRegisterDef(Entry, Entry->begin(),
+                                getOrCreateInterval(*I), 0, 0);
+      for (const unsigned* AS = mri_->getAliasSet(*I); *AS; ++AS)
+        handlePhysicalRegisterDef(Entry, Entry->begin(),
+                                  getOrCreateInterval(*AS), 0, 0);
+    }
+  }
+
   computeIntervals();
 
   numIntervals += getNumIntervals();
@@ -164,6 +199,11 @@
     }
   }
 
+  // If we inserted a placeholder instruction at the entry of the block, remove
+  // it now.
+  if (fn.livein_begin() != fn.livein_end())
+    fn.begin()->erase(fn.begin()->begin());
+
   DEBUG(dump());
   return true;
 }
@@ -557,14 +597,16 @@
   DEBUG(std::cerr << "********** COMPUTING LIVE INTERVALS **********\n");
   DEBUG(std::cerr << "********** Function: "
         << ((Value*)mf_->getFunction())->getName() << '\n');
+  bool IgnoreFirstInstr = mf_->livein_begin() != mf_->livein_end();
 
   for (MachineFunction::iterator I = mf_->begin(), E = mf_->end();
        I != E; ++I) {
     MachineBasicBlock* mbb = I;
     DEBUG(std::cerr << ((Value*)mbb->getBasicBlock())->getName() << ":\n");
 
-    for (MachineBasicBlock::iterator mi = mbb->begin(), miEnd = mbb->end();
-         mi != miEnd; ++mi) {
+    MachineBasicBlock::iterator mi = mbb->begin(), miEnd = mbb->end();
+    if (IgnoreFirstInstr) { ++mi; IgnoreFirstInstr = false; }
+    for (; mi != miEnd; ++mi) {
       const TargetInstrDescriptor& tid =
         tm_->getInstrInfo()->get(mi->getOpcode());
       DEBUG(std::cerr << getInstructionIndex(mi) << "\t" << *mi);






More information about the llvm-commits mailing list