Remove dead variable.
[oota-llvm.git] / lib / CodeGen / RenderMachineFunction.cpp
index 708646c65c3f963ad2c910627505f54dcdd4348d..cbfd5a23d63d6635c81151417193d87cdadbd07d 100644 (file)
 using namespace llvm;
 
 char RenderMachineFunction::ID = 0;
-static RegisterPass<RenderMachineFunction>
-X("rendermf", "Render machine functions (and related info) to HTML pages");
+INITIALIZE_PASS_BEGIN(RenderMachineFunction, "rendermf",
+                "Render machine functions (and related info) to HTML pages",
+                false, false)
+INITIALIZE_PASS_DEPENDENCY(SlotIndexes)
+INITIALIZE_PASS_DEPENDENCY(LiveIntervals)
+INITIALIZE_PASS_END(RenderMachineFunction, "rendermf",
+                "Render machine functions (and related info) to HTML pages",
+                false, false)
 
 static cl::opt<std::string>
 outputFileSuffix("rmf-file-suffix",
@@ -55,6 +61,11 @@ showIntervals("rmf-intervals",
               cl::desc("Live intervals to show alongside code."),
               cl::init(""), cl::Hidden);
 
+static cl::opt<bool>
+filterEmpty("rmf-filter-empty-intervals",
+            cl::desc("Don't display empty intervals."),
+            cl::init(true), cl::Hidden);
+
 static cl::opt<bool>
 showEmptyIndexes("rmf-empty-indexes",
                  cl::desc("Render indexes not associated with instructions or "
@@ -149,10 +160,14 @@ namespace llvm {
                                           const std::string &intervalRangeStr) {
     if (intervalRangeStr == "*") {
       intervalTypesToRender |= All;
+    } else if (intervalRangeStr == "virt-nospills*") {
+      intervalTypesToRender |= VirtNoSpills;
+    } else if (intervalRangeStr == "spills*") {
+      intervalTypesToRender |= VirtSpills;
     } else if (intervalRangeStr == "virt*") {
-      intervalTypesToRender |= VirtPlusExplicit;
+      intervalTypesToRender |= AllVirt;
     } else if (intervalRangeStr == "phys*") {
-      intervalTypesToRender |= PhysPlusExplicit;
+      intervalTypesToRender |= AllPhys;
     } else {
       std::istringstream iss(intervalRangeStr);
       unsigned reg1, reg2;
@@ -178,10 +193,12 @@ namespace llvm {
 
   void MFRenderingOptions::setup(MachineFunction *mf,
                                  const TargetRegisterInfo *tri,
-                                 LiveIntervals *lis) {
+                                 LiveIntervals *lis,
+                                 const RenderMachineFunction *rmf) {
     this->mf = mf;
     this->tri = tri;
     this->lis = lis;
+    this->rmf = rmf;
 
     clear();
   }
@@ -251,12 +268,19 @@ namespace llvm {
       if (intervalTypesToRender != ExplicitOnly) {
         for (LiveIntervals::iterator liItr = lis->begin(), liEnd = lis->end();
              liItr != liEnd; ++liItr) {
-
-          if ((TargetRegisterInfo::isPhysicalRegister(liItr->first) &&
-               (intervalTypesToRender & PhysPlusExplicit)) ||
-              (TargetRegisterInfo::isVirtualRegister(liItr->first) &&
-               (intervalTypesToRender & VirtPlusExplicit))) {
-            intervalSet.insert(liItr->second);
+          LiveInterval *li = liItr->second;
+
+          if (filterEmpty && li->empty())
+            continue;
+
+          if ((TargetRegisterInfo::isPhysicalRegister(li->reg) &&
+               (intervalTypesToRender & AllPhys))) {
+            intervalSet.insert(li);
+          } else if (TargetRegisterInfo::isVirtualRegister(li->reg)) {
+            if (((intervalTypesToRender & VirtNoSpills) && !rmf->isSpill(li)) || 
+                ((intervalTypesToRender & VirtSpills) && rmf->isSpill(li))) {
+              intervalSet.insert(li);
+            }
           }
         }
       }
@@ -439,14 +463,9 @@ namespace llvm {
          liItr != liEnd; ++liItr) {
       LiveInterval *li = liItr->second;
 
-      const TargetRegisterClass *liTRC;
-
       if (TargetRegisterInfo::isPhysicalRegister(li->reg))
         continue;
       
-      liTRC = mri->getRegClass(li->reg);
-     
-
       // For all ranges in the current interal.
       for (LiveInterval::iterator lrItr = li->begin(),
              lrEnd = li->end();
@@ -499,8 +518,7 @@ namespace llvm {
 
   // ---------- MachineFunctionRenderer implementation ----------
 
-  template <typename OStream>
-  void RenderMachineFunction::Spacer::print(OStream &os) const {
+  void RenderMachineFunction::Spacer::print(raw_ostream &os) const {
     if (!prettyHTML)
       return;
     for (unsigned i = 0; i < ns; ++i) {
@@ -512,8 +530,7 @@ namespace llvm {
     return Spacer(ns);
   }
 
-  template <typename OStream>
-  OStream& operator<<(OStream &os, const RenderMachineFunction::Spacer &s) {
+  raw_ostream& operator<<(raw_ostream &os, const RenderMachineFunction::Spacer &s) {
     s.print(os);
     return os;
   }
@@ -543,7 +560,26 @@ namespace llvm {
                                         SlotIndex i) const {
     const MachineInstr *mi = sis->getInstructionFromIndex(i);
 
+    // For uses/defs recorded use/def indexes override current liveness and
+    // instruction operands (Only for the interval which records the indexes).
+    if (i.isUse() || i.isDef()) {
+      UseDefs::const_iterator udItr = useDefs.find(li);
+      if (udItr != useDefs.end()) {
+        const SlotSet &slotSet = udItr->second;
+        if (slotSet.count(i)) {
+          if (i.isUse()) {
+            return Used;
+          }
+          // else
+          return Defined;
+        }
+      }
+    }
+
+    // If the slot is a load/store, or there's no info in the use/def set then
+    // use liveness and instruction operand info.
     if (li->liveAt(i)) {
+
       if (mi == 0) {
         if (vrm == 0 || 
             (vrm->getStackSlot(li->reg) == VirtRegMap::NO_STACK_SLOT)) {
@@ -552,11 +588,9 @@ namespace llvm {
           return AliveStack;
         }
       } else {
-        if (i.getSlot() == SlotIndex::DEF &&
-            mi->definesRegister(li->reg, tri)) {
+        if (i.isDef() && mi->definesRegister(li->reg, tri)) {
           return Defined;
-        } else if (i.getSlot() == SlotIndex::USE &&
-                   mi->readsRegister(li->reg)) {
+        } else if (i.isUse() && mi->readsRegister(li->reg)) {
           return Used;
         } else {
           if (vrm == 0 || 
@@ -583,8 +617,7 @@ namespace llvm {
   }
 
   /// \brief Render a machine instruction.
-  template <typename OStream>
-  void RenderMachineFunction::renderMachineInstr(OStream &os,
+  void RenderMachineFunction::renderMachineInstr(raw_ostream &os,
                                                  const MachineInstr *mi) const {
     std::string s;
     raw_string_ostream oss(s);
@@ -593,9 +626,9 @@ namespace llvm {
     os << escapeChars(oss.str());
   }
 
-  template <typename OStream, typename T>
+  template <typename T>
   void RenderMachineFunction::renderVertical(const Spacer &indent,
-                                             OStream &os,
+                                             raw_ostream &os,
                                              const T &t) const {
     if (ro.fancyVerticals()) {
       os << indent << "<object\n"
@@ -626,9 +659,8 @@ namespace llvm {
     }
   }
 
-  template <typename OStream>
   void RenderMachineFunction::insertCSS(const Spacer &indent,
-                                        OStream &os) const {
+                                        raw_ostream &os) const {
     os << indent << "<style type=\"text/css\">\n"
        << indent + s(2) << "body { font-color: black; }\n"
        << indent + s(2) << "table.code td { font-family: monospace; "
@@ -647,9 +679,8 @@ namespace llvm {
        << indent << "</style>\n";
   }
 
-  template <typename OStream>
   void RenderMachineFunction::renderFunctionSummary(
-                                    const Spacer &indent, OStream &os,
+                                    const Spacer &indent, raw_ostream &os,
                                     const char * const renderContextStr) const {
     os << indent << "<h1>Function: " << mf->getFunction()->getName()
                  << "</h1>\n"
@@ -657,10 +688,9 @@ namespace llvm {
   }
 
 
-  template <typename OStream>
   void RenderMachineFunction::renderPressureTableLegend(
                                                       const Spacer &indent,
-                                                      OStream &os) const {
+                                                      raw_ostream &os) const {
     os << indent << "<h2>Rendering Pressure Legend:</h2>\n"
        << indent << "<table class=\"code\">\n"
        << indent + s(2) << "<tr>\n"
@@ -670,24 +700,24 @@ namespace llvm {
        << indent + s(2) << "<tr>\n"
        << indent + s(4) << "<td>No Pressure</td>"
                     "<td>No physical registers of this class requested.</td>"
-                    "<td class=\"s-zp\">&nbsp;&nbsp;</td>\n"
+                    "<td class=\"p-z\">&nbsp;&nbsp;</td>\n"
        << indent + s(2) << "</tr>\n"
        << indent + s(2) << "<tr>\n"
        << indent + s(4) << "<td>Low Pressure</td>"
                     "<td>Sufficient physical registers to meet demand.</td>"
-                    "<td class=\"s-up\">&nbsp;&nbsp;</td>\n"
+                    "<td class=\"p-l\">&nbsp;&nbsp;</td>\n"
        << indent + s(2) << "</tr>\n"
        << indent + s(2) << "<tr>\n"
        << indent + s(4) << "<td>High Pressure</td>"
                     "<td>Potentially insufficient physical registers to meet demand.</td>"
-                    "<td class=\"s-op\">&nbsp;&nbsp;</td>\n"
+                    "<td class=\"p-h\">&nbsp;&nbsp;</td>\n"
        << indent + s(2) << "</tr>\n"
        << indent << "</table>\n";
   }
 
-  template <typename OStream, typename CellType>
+  template <typename CellType>
   void RenderMachineFunction::renderCellsWithRLE(
-                   const Spacer &indent, OStream &os,
+                   const Spacer &indent, raw_ostream &os,
                    const std::pair<CellType, unsigned> &rleAccumulator,
                    const std::map<CellType, std::string> &cellTypeStrs) const {
 
@@ -706,9 +736,8 @@ namespace llvm {
   }
 
 
-  template <typename OStream>
   void RenderMachineFunction::renderCodeTablePlusPI(const Spacer &indent,
-                                                    OStream &os) const {
+                                                    raw_ostream &os) const {
 
     std::map<LiveState, std::string> lsStrs;
     lsStrs[Dead] = "l-n";
@@ -774,10 +803,10 @@ namespace llvm {
          i = i.getNextSlot()) {
      
       // Render the slot column. 
-      os << indent + s(2) << "<tr>\n";
+      os << indent + s(2) << "<tr height=6ex>\n";
       
       // Render the code column.
-      if (i.getSlot() == SlotIndex::LOAD) {
+      if (i.isLoad()) {
         MachineBasicBlock *mbb = sis->getMBBFromIndex(i);
         mi = sis->getInstructionFromIndex(i);
 
@@ -854,14 +883,8 @@ namespace llvm {
       renderPressureTableLegend(indent, os);
   }
 
-  template <typename OStream>
-  void RenderMachineFunction::renderWarnings(const Spacer &indent,
-                                             OStream &os) const {
-  }
-
-  template <typename OStream>
   void RenderMachineFunction::renderFunctionPage(
-                                    OStream &os,
+                                    raw_ostream &os,
                                     const char * const renderContextStr) const {
     os << "<html>\n"
        << s(2) << "<head>\n"
@@ -894,6 +917,7 @@ namespace llvm {
   }
 
   bool RenderMachineFunction::runOnMachineFunction(MachineFunction &fn) {
+
     mf = &fn;
     mri = &mf->getRegInfo();
     tri = mf->getTarget().getRegisterInfo();
@@ -901,7 +925,10 @@ namespace llvm {
     sis = &getAnalysis<SlotIndexes>();
 
     trei.setup(mf, mri, tri, lis);
-    ro.setup(mf, tri, lis);
+    ro.setup(mf, tri, lis, this);
+    spillIntervals.clear();
+    spillFor.clear();
+    useDefs.clear();
 
     fqn = mf->getFunction()->getParent()->getModuleIdentifier() + "." +
           mf->getFunction()->getName().str();
@@ -912,6 +939,50 @@ namespace llvm {
   void RenderMachineFunction::releaseMemory() {
     trei.clear();
     ro.clear();
+    spillIntervals.clear();
+    spillFor.clear();
+    useDefs.clear();
+  }
+
+  void RenderMachineFunction::rememberUseDefs(const LiveInterval *li) {
+
+    if (!ro.shouldRenderCurrentMachineFunction())
+      return; 
+
+    for (MachineRegisterInfo::reg_iterator rItr = mri->reg_begin(li->reg),
+                                           rEnd = mri->reg_end();
+         rItr != rEnd; ++rItr) {
+      const MachineInstr *mi = &*rItr;
+      if (mi->readsRegister(li->reg)) {
+        useDefs[li].insert(lis->getInstructionIndex(mi).getUseIndex());
+      }
+      if (mi->definesRegister(li->reg)) {
+        useDefs[li].insert(lis->getInstructionIndex(mi).getDefIndex());
+      }
+    }
+  }
+
+  void RenderMachineFunction::rememberSpills(
+                                     const LiveInterval *li,
+                                     const std::vector<LiveInterval*> &spills) {
+
+    if (!ro.shouldRenderCurrentMachineFunction())
+      return; 
+
+    for (std::vector<LiveInterval*>::const_iterator siItr = spills.begin(),
+                                                    siEnd = spills.end();
+         siItr != siEnd; ++siItr) {
+      const LiveInterval *spill = *siItr;
+      spillIntervals[li].insert(spill);
+      spillFor[spill] = li;
+    }
+  }
+
+  bool RenderMachineFunction::isSpill(const LiveInterval *li) const {
+    SpillForMap::const_iterator sfItr = spillFor.find(li);
+    if (sfItr == spillFor.end())
+      return false;
+    return true;
   }
 
   void RenderMachineFunction::renderMachineFunction(