From f80f31eb9fd8ffa446310803e9d1da16e1c81c19 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Tue, 20 Jul 2010 10:18:54 +0000 Subject: [PATCH] Use run-length encoding to represent identical adjacent cells in the pressure and interval table. Reduces output HTML file sizes by ~80% in my test cases. Also fix access of private member type by << operator. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108823 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/RenderMachineFunction.cpp | 120 ++++++++++++++++++++++++---------- lib/CodeGen/RenderMachineFunction.h | 18 ++++- 2 files changed, 104 insertions(+), 34 deletions(-) diff --git a/lib/CodeGen/RenderMachineFunction.cpp b/lib/CodeGen/RenderMachineFunction.cpp index a5d81293016..708646c65c3 100644 --- a/lib/CodeGen/RenderMachineFunction.cpp +++ b/lib/CodeGen/RenderMachineFunction.cpp @@ -571,6 +571,17 @@ namespace llvm { return Dead; } + RenderMachineFunction::PressureState + RenderMachineFunction::getPressureStateAt(const TargetRegisterClass *trc, + SlotIndex i) const { + if (trei.getPressureAtSlot(trc, i) == 0) { + return Zero; + } else if (trei.classOverCapacityAtSlot(trc, i)){ + return High; + } + return Low; + } + /// \brief Render a machine instruction. template void RenderMachineFunction::renderMachineInstr(OStream &os, @@ -623,14 +634,14 @@ namespace llvm { << indent + s(2) << "table.code td { font-family: monospace; " "border-width: 0px; border-style: solid; " "border-bottom: 1px solid #dddddd; white-space: nowrap; }\n" - << indent + s(2) << "table.code td.s-zp { background-color: #000000; }\n" - << indent + s(2) << "table.code td.s-up { background-color: #00ff00; }\n" - << indent + s(2) << "table.code td.s-op { background-color: #ff0000; }\n" - << indent + s(2) << "table.code td.l-na { background-color: #ffffff; }\n" - << indent + s(2) << "table.code td.l-def { background-color: #ff0000; }\n" - << indent + s(2) << "table.code td.l-use { background-color: #ffff00; }\n" - << indent + s(2) << "table.code td.l-sar { background-color: #000000; }\n" - << indent + s(2) << "table.code td.l-sas { background-color: #770000; }\n" + << indent + s(2) << "table.code td.p-z { background-color: #000000; }\n" + << indent + s(2) << "table.code td.p-l { background-color: #00ff00; }\n" + << indent + s(2) << "table.code td.p-h { background-color: #ff0000; }\n" + << indent + s(2) << "table.code td.l-n { background-color: #ffffff; }\n" + << indent + s(2) << "table.code td.l-d { background-color: #ff0000; }\n" + << indent + s(2) << "table.code td.l-u { background-color: #ffff00; }\n" + << indent + s(2) << "table.code td.l-r { background-color: #000000; }\n" + << indent + s(2) << "table.code td.l-s { background-color: #770000; }\n" << indent + s(2) << "table.code th { border-width: 0px; " "border-style: solid; }\n" << indent << "\n"; @@ -674,17 +685,54 @@ namespace llvm { << indent << "\n"; } + template + void RenderMachineFunction::renderCellsWithRLE( + const Spacer &indent, OStream &os, + const std::pair &rleAccumulator, + const std::map &cellTypeStrs) const { + + if (rleAccumulator.second == 0) + return; + + typename std::map::const_iterator ctsItr = + cellTypeStrs.find(rleAccumulator.first); + + assert(ctsItr != cellTypeStrs.end() && "No string for given cell type."); + + os << indent + s(4) << "second << "\""; + if (rleAccumulator.second > 1) + os << " colspan=" << rleAccumulator.second; + os << ">\n"; + } + + template void RenderMachineFunction::renderCodeTablePlusPI(const Spacer &indent, OStream &os) const { + std::map lsStrs; + lsStrs[Dead] = "l-n"; + lsStrs[Defined] = "l-d"; + lsStrs[Used] = "l-u"; + lsStrs[AliveReg] = "l-r"; + lsStrs[AliveStack] = "l-s"; + + std::map psStrs; + psStrs[Zero] = "p-z"; + psStrs[Low] = "p-l"; + psStrs[High] = "p-h"; + + // Open the table... + os << indent << "\n" - << indent + s(2) << "\n" - << indent + s(4) << "\n" + << indent + s(2) << "\n"; + + // Render the header row... + + os << indent + s(4) << "\n" << indent + s(4) << "\n"; - // Header row: - + // Render class names if necessary... if (!ro.regClasses().empty()) { for (MFRenderingOptions::RegClassSet::const_iterator rcItr = ro.regClasses().begin(), @@ -701,6 +749,7 @@ namespace llvm { if (!ro.regClasses().empty() && !ro.intervals().empty()) os << indent + s(4) << "\n"; + // Render interval numbers if necessary... if (!ro.intervals().empty()) { for (MFRenderingOptions::IntervalSet::const_iterator liItr = ro.intervals().begin(), @@ -716,14 +765,18 @@ namespace llvm { os << indent + s(2) << "\n"; + // End header row, start with the data rows... + MachineInstr *mi = 0; // Data rows: for (SlotIndex i = sis->getZeroIndex(); i != sis->getLastIndex(); i = i.getNextSlot()) { + + // Render the slot column. + os << indent + s(2) << "\n"; - os << indent + s(2) << "\n"; - + // Render the code column. if (i.getSlot() == SlotIndex::LOAD) { MachineBasicBlock *mbb = sis->getMBBFromIndex(i); mi = sis->getInstructionFromIndex(i); @@ -739,7 +792,7 @@ namespace llvm { os << indent + s(6) << "  "; renderMachineInstr(os, mi); } else { - os << indent + s(6) << " \n"; + // Empty interval - leave blank. } os << indent + s(4) << "\n"; } else { @@ -748,25 +801,25 @@ namespace llvm { } } + // Render the class columns. if (!ro.regClasses().empty()) { + std::pair psRLEAccumulator(Zero, 0); for (MFRenderingOptions::RegClassSet::const_iterator rcItr = ro.regClasses().begin(), rcEnd = ro.regClasses().end(); rcItr != rcEnd; ++rcItr) { const TargetRegisterClass *trc = *rcItr; + PressureState newPressure = getPressureStateAt(trc, i); - os << indent + s(4) << "\n"; } + renderCellsWithRLE(indent + s(4), os, psRLEAccumulator, psStrs); } // FIXME: Is there a nicer way to insert space between columns in HTML? @@ -774,22 +827,23 @@ namespace llvm { os << indent + s(4) << "\n"; if (!ro.intervals().empty()) { + std::pair lsRLEAccumulator(Dead, 0); for (MFRenderingOptions::IntervalSet::const_iterator liItr = ro.intervals().begin(), liEnd = ro.intervals().end(); liItr != liEnd; ++liItr) { const LiveInterval *li = *liItr; - os << indent + s(4) << "\n"; } + renderCellsWithRLE(indent + s(4), os, lsRLEAccumulator, lsStrs); } os << indent + s(2) << "\n"; } diff --git a/lib/CodeGen/RenderMachineFunction.h b/lib/CodeGen/RenderMachineFunction.h index 1e604da1381..090b03ecd65 100644 --- a/lib/CodeGen/RenderMachineFunction.h +++ b/lib/CodeGen/RenderMachineFunction.h @@ -223,6 +223,11 @@ namespace llvm { const char *renderSuffix = 0); private: + class Spacer; + + template + friend OStream& operator<<(OStream &os, const Spacer &s); + std::string fqn; @@ -238,9 +243,12 @@ namespace llvm { // Utilities. typedef enum { Dead, Defined, Used, AliveReg, AliveStack } LiveState; - LiveState getLiveStateAt(const LiveInterval *li, SlotIndex i) const; + typedef enum { Zero, Low, High } PressureState; + PressureState getPressureStateAt(const TargetRegisterClass *trc, + SlotIndex i) const; + // ---------- Rendering methods ---------- /// For inserting spaces when pretty printing. @@ -286,6 +294,14 @@ namespace llvm { void renderPressureTableLegend(const Spacer &indent, OStream &os) const; + /// \brief Render a consecutive set of HTML cells of the same class using + /// the colspan attribute for run-length encoding. + template + void renderCellsWithRLE( + const Spacer &indent, OStream &os, + const std::pair &rleAccumulator, + const std::map &cellTypeStrs) const; + /// \brief Render code listing, potentially with register pressure /// and live intervals shown alongside. template -- 2.11.0
index
indexinstr