From: Lang Hames Date: Tue, 20 Jul 2010 09:13:29 +0000 (+0000) Subject: Added support for turning HTML indentation on and off (indentation off by default). X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=245581b1aca7c4af512772fcef4bde5fb1ad7e84;p=oota-llvm.git Added support for turning HTML indentation on and off (indentation off by default). Reduces output file size ~20% on my test cases. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108822 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/RenderMachineFunction.cpp b/lib/CodeGen/RenderMachineFunction.cpp index 2095e2dbe9c..a5d81293016 100644 --- a/lib/CodeGen/RenderMachineFunction.cpp +++ b/lib/CodeGen/RenderMachineFunction.cpp @@ -66,6 +66,12 @@ useFancyVerticals("rmf-fancy-verts", cl::desc("Use SVG for vertical text."), cl::init(true), cl::Hidden); +static cl::opt +prettyHTML("rmf-pretty-html", + cl::desc("Pretty print HTML. For debugging the renderer only.."), + cl::init(false), cl::Hidden); + + namespace llvm { bool MFRenderingOptions::renderingOptionsProcessed; @@ -493,6 +499,25 @@ namespace llvm { // ---------- MachineFunctionRenderer implementation ---------- + template + void RenderMachineFunction::Spacer::print(OStream &os) const { + if (!prettyHTML) + return; + for (unsigned i = 0; i < ns; ++i) { + os << " "; + } + } + + RenderMachineFunction::Spacer RenderMachineFunction::s(unsigned ns) const { + return Spacer(ns); + } + + template + OStream& operator<<(OStream &os, const RenderMachineFunction::Spacer &s) { + s.print(os); + return os; + } + template std::string RenderMachineFunction::escapeChars(Iterator sBegin, Iterator sEnd) const { std::string r; @@ -558,22 +583,23 @@ namespace llvm { } template - void RenderMachineFunction::renderVertical(const std::string &indent, + void RenderMachineFunction::renderVertical(const Spacer &indent, OStream &os, const T &t) const { if (ro.fancyVerticals()) { os << indent << "\n" - << indent << " " << t << "\n" - << indent << " \">\n" + << indent + s(2) << "class=\"obj\"\n" + << indent + s(2) << "type=\"image/svg+xml\"\n" + << indent + s(2) << "width=\"14px\"\n" + << indent + s(2) << "height=\"55px\"\n" + << indent + s(2) << "data=\"data:image/svg+xml,\n" + << indent + s(4) << "\n" + << indent + s(6) << "" << t << "\n" + << indent + s(4) << "\">\n" << indent << "\n"; } else { std::ostringstream oss; @@ -583,36 +609,36 @@ namespace llvm { os << indent; for (std::string::iterator tStrItr = tStr.begin(), tStrEnd = tStr.end(); tStrItr != tStrEnd; ++tStrItr) { - os << *tStrItr << "
"; + os << *tStrItr << "
"; } os << "\n"; } } template - void RenderMachineFunction::insertCSS(const std::string &indent, + void RenderMachineFunction::insertCSS(const Spacer &indent, OStream &os) const { os << indent << "\n"; } template void RenderMachineFunction::renderFunctionSummary( - const std::string &indent, OStream &os, + const Spacer &indent, OStream &os, const char * const renderContextStr) const { os << indent << "

Function: " << mf->getFunction()->getName() << "

\n" @@ -622,40 +648,40 @@ namespace llvm { template void RenderMachineFunction::renderPressureTableLegend( - const std::string &indent, + const Spacer &indent, OStream &os) const { os << indent << "

Rendering Pressure Legend:

\n" << indent << "\n" - << indent << " \n" - << indent << " " + << indent + s(2) << "\n" + << indent + s(4) << "" "\n" - << indent << " \n" - << indent << " \n" - << indent << " " - " " - " \n" - << indent << " \n" - << indent << " \n" - << indent << " " - " " - " \n" - << indent << " \n" - << indent << " \n" - << indent << " " - " " - " \n" - << indent << " \n" + << indent + s(2) << "\n" + << indent + s(2) << "\n" + << indent + s(4) << "" + "" + "\n" + << indent + s(2) << "\n" + << indent + s(2) << "\n" + << indent + s(4) << "" + "" + "\n" + << indent + s(2) << "\n" + << indent + s(2) << "\n" + << indent + s(4) << "" + "" + "\n" + << indent + s(2) << "\n" << indent << "
PressureDescription
PressureDescriptionAppearance
No PressureNo physical registers of this class requested.  
Low PressureSufficient physical registers to meet demand.  
High PressurePotentially insufficient physical registers to meet demand.  
No PressureNo physical registers of this class requested.  
Low PressureSufficient physical registers to meet demand.  
High PressurePotentially insufficient physical registers to meet demand.  
\n"; } template - void RenderMachineFunction::renderCodeTablePlusPI(const std::string & indent, + void RenderMachineFunction::renderCodeTablePlusPI(const Spacer &indent, OStream &os) const { os << indent << "\n" - << indent << " \n" - << indent << " \n" - << indent << " \n"; + << indent + s(2) << "\n" + << indent + s(4) << "\n" + << indent + s(4) << "\n"; // Header row: @@ -665,15 +691,15 @@ namespace llvm { rcEnd = ro.regClasses().end(); rcItr != rcEnd; ++rcItr) { const TargetRegisterClass *trc = *rcItr; - os << indent << " \n"; + os << indent + s(4) << "\n"; } } // FIXME: Is there a nicer way to insert space between columns in HTML? if (!ro.regClasses().empty() && !ro.intervals().empty()) - os << indent << " \n"; + os << indent + s(4) << "\n"; if (!ro.intervals().empty()) { for (MFRenderingOptions::IntervalSet::const_iterator @@ -682,13 +708,13 @@ namespace llvm { liItr != liEnd; ++liItr) { const LiveInterval *li = *liItr; - os << indent << " \n"; + os << indent + s(4) << "\n"; } } - os << indent << " \n"; + os << indent + s(2) << "\n"; MachineInstr *mi = 0; @@ -696,7 +722,7 @@ namespace llvm { for (SlotIndex i = sis->getZeroIndex(); i != sis->getLastIndex(); i = i.getNextSlot()) { - os << indent << " \n"; + os << indent + s(2) << "\n"; if (i.getSlot() == SlotIndex::LOAD) { MachineBasicBlock *mbb = sis->getMBBFromIndex(i); @@ -704,19 +730,18 @@ namespace llvm { if (i == sis->getMBBStartIdx(mbb) || mi != 0 || ro.renderEmptyIndexes()) { - os << indent << " \n" - << indent << " \n" + << indent + s(4) << "\n"; + os << indent + s(4) << "\n"; } else { i = i.getStoreIndex(); // <- Will be incremented to the next index. continue; @@ -730,7 +755,7 @@ namespace llvm { rcItr != rcEnd; ++rcItr) { const TargetRegisterClass *trc = *rcItr; - os << indent << " \n"; + os << indent + s(4) << "\n"; if (!ro.intervals().empty()) { for (MFRenderingOptions::IntervalSet::const_iterator @@ -754,7 +779,7 @@ namespace llvm { liEnd = ro.intervals().end(); liItr != liEnd; ++liItr) { const LiveInterval *li = *liItr; - os << indent << " \n"; } } - os << indent << " \n"; + os << indent + s(2) << "\n"; } os << indent << "
indexinstr
indexinstr\n"; - renderVertical(indent + " ", os, trc->getName()); - os << indent << " \n"; + renderVertical(indent + s(6), os, trc->getName()); + os << indent + s(4) << "    \n"; - renderVertical(indent + " ", os, li->reg); - os << indent << " \n"; + renderVertical(indent + s(6), os, li->reg); + os << indent + s(4) << "
" << i << " \n"; + os << indent + s(4) << "" << i << " \n"; if (i == sis->getMBBStartIdx(mbb)) { - os << indent << " BB#" << mbb->getNumber() << ": \n"; + os << indent + s(6) << "BB#" << mbb->getNumber() << ": \n"; } else if (mi != 0) { - os << indent << "   "; + os << indent + s(6) << "  "; renderMachineInstr(os, mi); - os << "\n"; } else { - os << indent << "  \n"; + os << indent + s(6) << " \n"; } - os << indent << "
\n"; @@ -776,7 +801,7 @@ namespace llvm { } template - void RenderMachineFunction::renderWarnings(const std::string &indent, + void RenderMachineFunction::renderWarnings(const Spacer &indent, OStream &os) const { } @@ -785,25 +810,25 @@ namespace llvm { OStream &os, const char * const renderContextStr) const { os << "\n" - << " \n" - << " " << fqn << "\n"; + << s(2) << "\n" + << s(4) << "" << fqn << "\n"; - insertCSS(" ", os); + insertCSS(s(4), os); - os << " \n" - << " \n"; + os << s(2) << "\n" + << s(2) << "\n"; - renderFunctionSummary(" ", os, renderContextStr); + renderFunctionSummary(s(4), os, renderContextStr); - os << "


\n"; + os << s(4) << "


\n"; //renderLiveIntervalInfoTable(" ", os); - os << "


\n"; + os << s(4) << "


\n"; - renderCodeTablePlusPI(" ", os); + renderCodeTablePlusPI(s(4), os); - os << " \n" + os << s(2) << "\n" << "\n"; } diff --git a/lib/CodeGen/RenderMachineFunction.h b/lib/CodeGen/RenderMachineFunction.h index 743938d9edb..1e604da1381 100644 --- a/lib/CodeGen/RenderMachineFunction.h +++ b/lib/CodeGen/RenderMachineFunction.h @@ -243,6 +243,18 @@ namespace llvm { // ---------- Rendering methods ---------- + /// For inserting spaces when pretty printing. + class Spacer { + public: + explicit Spacer(unsigned numSpaces) : ns(numSpaces) {} + Spacer operator+(const Spacer &o) const { return Spacer(ns + o.ns); } + template void print(OStream &os) const; + private: + unsigned ns; + }; + + Spacer s(unsigned ns) const; + template std::string escapeChars(Iterator sBegin, Iterator sEnd) const; @@ -253,38 +265,38 @@ namespace llvm { /// \brief Render vertical text. template - void renderVertical(const std::string &indent, + void renderVertical(const Spacer &indent, OStream &os, const T &t) const; /// \brief Insert CSS layout info. template - void insertCSS(const std::string &indent, + void insertCSS(const Spacer &indent, OStream &os) const; /// \brief Render a brief summary of the function (including rendering /// context). template - void renderFunctionSummary(const std::string &indent, + void renderFunctionSummary(const Spacer &indent, OStream &os, const char * const renderContextStr) const; /// \brief Render a legend for the pressure table. template - void renderPressureTableLegend(const std::string &indent, + void renderPressureTableLegend(const Spacer &indent, OStream &os) const; /// \brief Render code listing, potentially with register pressure /// and live intervals shown alongside. template - void renderCodeTablePlusPI(const std::string &indent, + void renderCodeTablePlusPI(const Spacer &indent, OStream &os) const; /// \brief Render warnings about the machine function, or weird rendering /// parameter combinations (e.g. rendering specified live intervals /// over more than one machine function). template - void renderWarnings(const std::string &indent, + void renderWarnings(const Spacer &indent, OStream &os) const; /// \brief Render the HTML page representing the MachineFunction.