[llvm-commits] [llvm] r108815 - in /llvm/trunk/lib/CodeGen: RegAllocPBQP.cpp RenderMachineFunction.cpp RenderMachineFunction.h

Lang Hames lhames at gmail.com
Tue Jul 20 00:41:45 PDT 2010


Author: lhames
Date: Tue Jul 20 02:41:44 2010
New Revision: 108815

URL: http://llvm.org/viewvc/llvm-project?rev=108815&view=rev
Log:
Switched to rendering after allocation (but before rewriting) in PBQP.

Updated renderer to use allocation information from VirtRegMap (if
available) to render spilled intervals differently.

Modified:
    llvm/trunk/lib/CodeGen/RegAllocPBQP.cpp
    llvm/trunk/lib/CodeGen/RenderMachineFunction.cpp
    llvm/trunk/lib/CodeGen/RenderMachineFunction.h

Modified: llvm/trunk/lib/CodeGen/RegAllocPBQP.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/RegAllocPBQP.cpp?rev=108815&r1=108814&r2=108815&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/RegAllocPBQP.cpp (original)
+++ llvm/trunk/lib/CodeGen/RegAllocPBQP.cpp Tue Jul 20 02:41:44 2010
@@ -865,11 +865,10 @@
   lis = &getAnalysis<LiveIntervals>();
   lss = &getAnalysis<LiveStacks>();
   loopInfo = &getAnalysis<MachineLoopInfo>();
+  RenderMachineFunction *rmf = &getAnalysis<RenderMachineFunction>();
 
   vrm = &getAnalysis<VirtRegMap>();
 
-  RenderMachineFunction *rmf = &getAnalysis<RenderMachineFunction>();
-  rmf->renderMachineFunction("Prior to PBQP register allocation.");
 
   DEBUG(dbgs() << "PBQP Register Allocating for " << mf->getFunction()->getName() << "\n");
 
@@ -907,6 +906,8 @@
   // Finalise allocation, allocate empty ranges.
   finalizeAlloc();
 
+  rmf->renderMachineFunction("After PBQP register allocation.", vrm);
+
   vregIntervalsToAlloc.clear();
   emptyVRegIntervals.clear();
   li2Node.clear();

Modified: llvm/trunk/lib/CodeGen/RenderMachineFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/RenderMachineFunction.cpp?rev=108815&r1=108814&r2=108815&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/RenderMachineFunction.cpp (original)
+++ llvm/trunk/lib/CodeGen/RenderMachineFunction.cpp Tue Jul 20 02:41:44 2010
@@ -11,6 +11,8 @@
 
 #include "RenderMachineFunction.h"
 
+#include "VirtRegMap.h"
+
 #include "llvm/Function.h"
 #include "llvm/Module.h"
 #include "llvm/ADT/SmallVector.h"
@@ -511,6 +513,50 @@
     return r;
   }
 
+  RenderMachineFunction::LiveState
+  RenderMachineFunction::getLiveStateAt(const LiveInterval *li,
+                                        SlotIndex i) const {
+    const MachineInstr *mi = sis->getInstructionFromIndex(i);
+
+    if (li->liveAt(i)) {
+      if (mi == 0) {
+        if (vrm == 0 || 
+            (vrm->getStackSlot(li->reg) == VirtRegMap::NO_STACK_SLOT)) {
+          return AliveReg;
+        } else {
+          return AliveStack;
+        }
+      } else {
+        if (i.getSlot() == SlotIndex::DEF &&
+            mi->definesRegister(li->reg, tri)) {
+          return Defined;
+        } else if (i.getSlot() == SlotIndex::USE &&
+                   mi->readsRegister(li->reg)) {
+          return Used;
+        } else {
+          if (vrm == 0 || 
+              (vrm->getStackSlot(li->reg) == VirtRegMap::NO_STACK_SLOT)) {
+            return AliveReg;
+          } else {
+            return AliveStack;
+          }
+        }
+      }
+    }
+    return Dead;
+  }
+
+  /// \brief Render a machine instruction.
+  template <typename OStream>
+  void RenderMachineFunction::renderMachineInstr(OStream &os,
+                                                 const MachineInstr *mi) const {
+    std::string s;
+    raw_string_ostream oss(s);
+    oss << *mi;
+
+    os << escapeChars(oss.str());
+  }
+
   template <typename OStream, typename T>
   void RenderMachineFunction::renderVertical(const std::string &indent,
                                              OStream &os,
@@ -557,7 +603,8 @@
        << indent << "  table.code td.l-na { background-color: #ffffff; }\n"
        << indent << "  table.code td.l-def { background-color: #ff0000; }\n"
        << indent << "  table.code td.l-use { background-color: #ffff00; }\n"
-       << indent << "  table.code td.l-sa { background-color: #000000; }\n"
+       << indent << "  table.code td.l-sar { background-color: #000000; }\n"
+       << indent << "  table.code td.l-sas { background-color: #770000; }\n"
        << indent << "  table.code th { border-width: 0px; "
                     "border-style: solid; }\n"
        << indent << "</style>\n";
@@ -663,7 +710,9 @@
           if (i == sis->getMBBStartIdx(mbb)) {
             os << indent << "      BB#" << mbb->getNumber() << ": \n";
           } else if (mi != 0) {
-            os << indent << "        " << escapeChars(mi) << "\n";
+            os << indent << "        ";
+            renderMachineInstr(os, mi);
+            os << "\n";
           } else {
             os << indent << "       \n";
           }
@@ -706,22 +755,13 @@
              liItr != liEnd; ++liItr) {
           const LiveInterval *li = *liItr;
           os << indent << "    <td class=\"";
-          if (li->liveAt(i)) {
-            if (mi == 0) {
-              os << "l-sa";
-            } else {
-              if (i.getSlot() == SlotIndex::DEF &&
-                  mi->definesRegister(li->reg, tri)) {
-                os << "l-def";
-              } else if (i.getSlot() == SlotIndex::USE &&
-                         mi->readsRegister(li->reg)) {
-                os << "l-use";
-              } else {
-                os << "l-sa";
-              }
-            }
-          } else {
-            os << "l-na";
+          switch (getLiveStateAt(li, i)) {
+            case Dead: os << "l-na"; break;
+            case Defined: os << "l-def"; break;
+            case Used: os << "l-use"; break;
+            case AliveReg: os << "l-sar"; break;
+            case AliveStack: os << "l-sas"; break;
+            default: assert(false && "Unrecognised live state."); break;
           }
           os << "\"></td>\n";
         }
@@ -797,10 +837,12 @@
 
   void RenderMachineFunction::renderMachineFunction(
                                                    const char *renderContextStr,
+                                                   const VirtRegMap *vrm,
                                                    const char *renderSuffix) {
     if (!ro.shouldRenderCurrentMachineFunction())
       return; 
 
+    this->vrm = vrm;
     trei.reset();
 
     std::string rpFileName(mf->getFunction()->getName().str() +
@@ -815,20 +857,8 @@
     ro.resetRenderSpecificOptions();
   }
 
-  void RenderMachineFunction::setupRenderingOptions() {
-
-  }
-
   std::string RenderMachineFunction::escapeChars(const std::string &s) const {
     return escapeChars(s.begin(), s.end());
   }
 
-  std::string RenderMachineFunction::escapeChars(const MachineInstr *mi) const {
-    std::string s;
-    raw_string_ostream os(s);
-    os << *mi;
-    std::string s2 = os.str();
-    return escapeChars(s2);
-  }
-
 }

Modified: llvm/trunk/lib/CodeGen/RenderMachineFunction.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/RenderMachineFunction.h?rev=108815&r1=108814&r2=108815&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/RenderMachineFunction.h (original)
+++ llvm/trunk/lib/CodeGen/RenderMachineFunction.h Tue Jul 20 02:41:44 2010
@@ -30,7 +30,7 @@
   class MachineRegisterInfo;
   class TargetRegisterClass;
   class TargetRegisterInfo;
-
+  class VirtRegMap;
 
   /// \brief Provide extra information about the physical and virtual registers
   ///        in the function being compiled.
@@ -212,10 +212,14 @@
     ///                         codegen pipeline) this function was rendered
     ///                         from. Set it to something like
     ///                         "Pre-register-allocation".
+    /// @param vrm              If non-null the VRM will be queried to determine
+    ///                         whether a virtual register was allocated to a
+    ///                         physical register or spilled.
     /// @param renderFilePrefix This string will be appended to the function
     ///                         name (before the output file suffix) to enable
     ///                         multiple renderings from the same function.
     void renderMachineFunction(const char *renderContextStr,
+                               const VirtRegMap *vrm = 0,
                                const char *renderSuffix = 0);
 
   private:
@@ -227,19 +231,26 @@
     const TargetRegisterInfo *tri;
     LiveIntervals *lis;
     SlotIndexes *sis;
+    const VirtRegMap *vrm;
 
     TargetRegisterExtraInfo trei;
     MFRenderingOptions ro;
 
-    // ---------- Utility functions ----------
+    // Utilities.
+    typedef enum { Dead, Defined, Used, AliveReg, AliveStack } LiveState;
 
-    void setupRenderingOptions();
+    LiveState getLiveStateAt(const LiveInterval *li, SlotIndex i) const;
 
     // ---------- Rendering methods ----------
 
     template <typename Iterator>
     std::string escapeChars(Iterator sBegin, Iterator sEnd) const;
 
+    /// \brief Render a machine instruction.
+    template <typename OStream>
+    void renderMachineInstr(OStream &os,
+                            const MachineInstr *mi) const;
+
     /// \brief Render vertical text.
     template <typename OStream, typename T>
     void renderVertical(const std::string &indent,
@@ -282,9 +293,6 @@
                             const char * const renderContextStr) const;
 
     std::string escapeChars(const std::string &s) const;
-
-    std::string escapeChars(const MachineInstr *mi) const;
-
   };
 }
 





More information about the llvm-commits mailing list