1 //===-- llvm/CodeGen/RenderMachineFunction.cpp - MF->HTML -----s-----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #define DEBUG_TYPE "rendermf"
12 #include "RenderMachineFunction.h"
14 #include "VirtRegMap.h"
16 #include "llvm/Function.h"
17 #include "llvm/Module.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/CodeGen/LiveIntervalAnalysis.h"
20 #include "llvm/CodeGen/MachineFunction.h"
21 #include "llvm/CodeGen/MachineInstr.h"
22 #include "llvm/CodeGen/MachineRegisterInfo.h"
23 #include "llvm/Support/CommandLine.h"
24 #include "llvm/Support/Debug.h"
25 #include "llvm/Support/raw_ostream.h"
26 #include "llvm/Target/TargetMachine.h"
32 char RenderMachineFunction::ID = 0;
33 static RegisterPass<RenderMachineFunction>
34 X("rendermf", "Render machine functions (and related info) to HTML pages");
36 static cl::opt<std::string>
37 outputFileSuffix("rmf-file-suffix",
38 cl::desc("Appended to function name to get output file name "
39 "(default: \".html\")"),
40 cl::init(".html"), cl::Hidden);
42 static cl::opt<std::string>
43 machineFuncsToRender("rmf-funcs",
44 cl::desc("Coma seperated list of functions to render"
46 cl::init(""), cl::Hidden);
48 static cl::opt<std::string>
49 pressureClasses("rmf-classes",
50 cl::desc("Register classes to render pressure for."),
51 cl::init(""), cl::Hidden);
53 static cl::opt<std::string>
54 showIntervals("rmf-intervals",
55 cl::desc("Live intervals to show alongside code."),
56 cl::init(""), cl::Hidden);
59 showEmptyIndexes("rmf-empty-indexes",
60 cl::desc("Render indexes not associated with instructions or "
62 cl::init(false), cl::Hidden);
65 useFancyVerticals("rmf-fancy-verts",
66 cl::desc("Use SVG for vertical text."),
67 cl::init(true), cl::Hidden);
70 prettyHTML("rmf-pretty-html",
71 cl::desc("Pretty print HTML. For debugging the renderer only.."),
72 cl::init(false), cl::Hidden);
77 bool MFRenderingOptions::renderingOptionsProcessed;
78 std::set<std::string> MFRenderingOptions::mfNamesToRender;
79 bool MFRenderingOptions::renderAllMFs = false;
81 std::set<std::string> MFRenderingOptions::classNamesToRender;
82 bool MFRenderingOptions::renderAllClasses = false;
84 std::set<std::pair<unsigned, unsigned> >
85 MFRenderingOptions::intervalNumsToRender;
86 unsigned MFRenderingOptions::intervalTypesToRender = ExplicitOnly;
88 template <typename OutputItr>
89 void MFRenderingOptions::splitComaSeperatedList(const std::string &s,
91 std::string::const_iterator curPos = s.begin();
92 std::string::const_iterator nextComa = std::find(curPos, s.end(), ',');
93 while (nextComa != s.end()) {
95 std::copy(curPos, nextComa, std::back_inserter(elem));
98 curPos = llvm::next(nextComa);
99 nextComa = std::find(curPos, s.end(), ',');
102 if (curPos != s.end()) {
104 std::copy(curPos, s.end(), std::back_inserter(elem));
110 void MFRenderingOptions::processOptions() {
111 if (!renderingOptionsProcessed) {
113 processRegClassNames();
114 processIntervalNumbers();
115 renderingOptionsProcessed = true;
119 void MFRenderingOptions::processFuncNames() {
120 if (machineFuncsToRender == "*") {
123 splitComaSeperatedList(machineFuncsToRender,
124 std::inserter(mfNamesToRender,
125 mfNamesToRender.begin()));
129 void MFRenderingOptions::processRegClassNames() {
130 if (pressureClasses == "*") {
131 renderAllClasses = true;
133 splitComaSeperatedList(pressureClasses,
134 std::inserter(classNamesToRender,
135 classNamesToRender.begin()));
139 void MFRenderingOptions::processIntervalNumbers() {
140 std::set<std::string> intervalRanges;
141 splitComaSeperatedList(showIntervals,
142 std::inserter(intervalRanges,
143 intervalRanges.begin()));
144 std::for_each(intervalRanges.begin(), intervalRanges.end(),
145 processIntervalRange);
148 void MFRenderingOptions::processIntervalRange(
149 const std::string &intervalRangeStr) {
150 if (intervalRangeStr == "*") {
151 intervalTypesToRender |= All;
152 } else if (intervalRangeStr == "virt*") {
153 intervalTypesToRender |= VirtPlusExplicit;
154 } else if (intervalRangeStr == "phys*") {
155 intervalTypesToRender |= PhysPlusExplicit;
157 std::istringstream iss(intervalRangeStr);
159 if ((iss >> reg1 >> std::ws)) {
161 intervalNumsToRender.insert(std::make_pair(reg1, reg1 + 1));
165 if (c == '-' && (iss >> reg2)) {
166 intervalNumsToRender.insert(std::make_pair(reg1, reg2 + 1));
168 dbgs() << "Warning: Invalid interval range \""
169 << intervalRangeStr << "\" in -rmf-intervals. Skipping.\n";
173 dbgs() << "Warning: Invalid interval number \""
174 << intervalRangeStr << "\" in -rmf-intervals. Skipping.\n";
179 void MFRenderingOptions::setup(MachineFunction *mf,
180 const TargetRegisterInfo *tri,
181 LiveIntervals *lis) {
189 void MFRenderingOptions::clear() {
190 regClassesTranslatedToCurrentFunction = false;
193 intervalsTranslatedToCurrentFunction = false;
197 void MFRenderingOptions::resetRenderSpecificOptions() {
199 intervalsTranslatedToCurrentFunction = false;
202 bool MFRenderingOptions::shouldRenderCurrentMachineFunction() const {
205 return (renderAllMFs ||
206 mfNamesToRender.find(mf->getFunction()->getName()) !=
207 mfNamesToRender.end());
210 const MFRenderingOptions::RegClassSet& MFRenderingOptions::regClasses() const{
211 translateRegClassNamesToCurrentFunction();
215 const MFRenderingOptions::IntervalSet& MFRenderingOptions::intervals() const {
216 translateIntervalNumbersToCurrentFunction();
220 bool MFRenderingOptions::renderEmptyIndexes() const {
221 return showEmptyIndexes;
224 bool MFRenderingOptions::fancyVerticals() const {
225 return useFancyVerticals;
228 void MFRenderingOptions::translateRegClassNamesToCurrentFunction() const {
229 if (!regClassesTranslatedToCurrentFunction) {
231 for (TargetRegisterInfo::regclass_iterator rcItr = tri->regclass_begin(),
232 rcEnd = tri->regclass_end();
233 rcItr != rcEnd; ++rcItr) {
234 const TargetRegisterClass *trc = *rcItr;
235 if (renderAllClasses ||
236 classNamesToRender.find(trc->getName()) !=
237 classNamesToRender.end()) {
238 regClassSet.insert(trc);
241 regClassesTranslatedToCurrentFunction = true;
245 void MFRenderingOptions::translateIntervalNumbersToCurrentFunction() const {
246 if (!intervalsTranslatedToCurrentFunction) {
249 // If we're not just doing explicit then do a copy over all matching
251 if (intervalTypesToRender != ExplicitOnly) {
252 for (LiveIntervals::iterator liItr = lis->begin(), liEnd = lis->end();
253 liItr != liEnd; ++liItr) {
255 if ((TargetRegisterInfo::isPhysicalRegister(liItr->first) &&
256 (intervalTypesToRender & PhysPlusExplicit)) ||
257 (TargetRegisterInfo::isVirtualRegister(liItr->first) &&
258 (intervalTypesToRender & VirtPlusExplicit))) {
259 intervalSet.insert(liItr->second);
264 // If we need to process the explicit list...
265 if (intervalTypesToRender != All) {
266 for (std::set<std::pair<unsigned, unsigned> >::const_iterator
267 regRangeItr = intervalNumsToRender.begin(),
268 regRangeEnd = intervalNumsToRender.end();
269 regRangeItr != regRangeEnd; ++regRangeItr) {
270 const std::pair<unsigned, unsigned> &range = *regRangeItr;
271 for (unsigned reg = range.first; reg != range.second; ++reg) {
272 if (lis->hasInterval(reg)) {
273 intervalSet.insert(&lis->getInterval(reg));
279 intervalsTranslatedToCurrentFunction = true;
283 // ---------- TargetRegisterExtraInformation implementation ----------
285 TargetRegisterExtraInfo::TargetRegisterExtraInfo()
286 : mapsPopulated(false) {
289 void TargetRegisterExtraInfo::setup(MachineFunction *mf,
290 MachineRegisterInfo *mri,
291 const TargetRegisterInfo *tri,
292 LiveIntervals *lis) {
299 void TargetRegisterExtraInfo::reset() {
300 if (!mapsPopulated) {
304 mapsPopulated = true;
307 resetPressureAndLiveStates();
310 void TargetRegisterExtraInfo::clear() {
315 //liveStatesMap.clear();
316 mapsPopulated = false;
319 void TargetRegisterExtraInfo::initWorst() {
320 assert(!mapsPopulated && prWorst.empty() && vrWorst.empty() &&
321 "Worst map already initialised?");
323 // Start with the physical registers.
324 for (unsigned preg = 1; preg < tri->getNumRegs(); ++preg) {
325 WorstMapLine &pregLine = prWorst[preg];
327 for (TargetRegisterInfo::regclass_iterator rcItr = tri->regclass_begin(),
328 rcEnd = tri->regclass_end();
329 rcItr != rcEnd; ++rcItr) {
330 const TargetRegisterClass *trc = *rcItr;
332 unsigned numOverlaps = 0;
333 for (TargetRegisterClass::iterator rItr = trc->begin(),
335 rItr != rEnd; ++rItr) {
336 unsigned trcPReg = *rItr;
337 if (tri->regsOverlap(preg, trcPReg))
341 pregLine[trc] = numOverlaps;
345 // Now the register classes.
346 for (TargetRegisterInfo::regclass_iterator rc1Itr = tri->regclass_begin(),
347 rcEnd = tri->regclass_end();
348 rc1Itr != rcEnd; ++rc1Itr) {
349 const TargetRegisterClass *trc1 = *rc1Itr;
350 WorstMapLine &classLine = vrWorst[trc1];
352 for (TargetRegisterInfo::regclass_iterator rc2Itr = tri->regclass_begin();
353 rc2Itr != rcEnd; ++rc2Itr) {
354 const TargetRegisterClass *trc2 = *rc2Itr;
358 for (TargetRegisterClass::iterator trc1Itr = trc1->begin(),
359 trc1End = trc1->end();
360 trc1Itr != trc1End; ++trc1Itr) {
361 unsigned trc1Reg = *trc1Itr;
362 unsigned trc1RegWorst = 0;
364 for (TargetRegisterClass::iterator trc2Itr = trc2->begin(),
365 trc2End = trc2->end();
366 trc2Itr != trc2End; ++trc2Itr) {
367 unsigned trc2Reg = *trc2Itr;
368 if (tri->regsOverlap(trc1Reg, trc2Reg))
371 if (trc1RegWorst > worst) {
372 worst = trc1RegWorst;
377 classLine[trc2] = worst;
383 unsigned TargetRegisterExtraInfo::getWorst(
385 const TargetRegisterClass *trc) const {
386 const WorstMapLine *wml = 0;
387 if (TargetRegisterInfo::isPhysicalRegister(reg)) {
388 PRWorstMap::const_iterator prwItr = prWorst.find(reg);
389 assert(prwItr != prWorst.end() && "Missing prWorst entry.");
390 wml = &prwItr->second;
392 const TargetRegisterClass *regTRC = mri->getRegClass(reg);
393 VRWorstMap::const_iterator vrwItr = vrWorst.find(regTRC);
394 assert(vrwItr != vrWorst.end() && "Missing vrWorst entry.");
395 wml = &vrwItr->second;
398 WorstMapLine::const_iterator wmlItr = wml->find(trc);
399 if (wmlItr == wml->end())
402 return wmlItr->second;
405 void TargetRegisterExtraInfo::initCapacity() {
406 assert(!mapsPopulated && capacityMap.empty() &&
407 "Capacity map already initialised?");
409 for (TargetRegisterInfo::regclass_iterator rcItr = tri->regclass_begin(),
410 rcEnd = tri->regclass_end();
411 rcItr != rcEnd; ++rcItr) {
412 const TargetRegisterClass *trc = *rcItr;
413 unsigned capacity = std::distance(trc->allocation_order_begin(*mf),
414 trc->allocation_order_end(*mf));
417 capacityMap[trc] = capacity;
421 unsigned TargetRegisterExtraInfo::getCapacity(
422 const TargetRegisterClass *trc) const {
423 CapacityMap::const_iterator cmItr = capacityMap.find(trc);
424 assert(cmItr != capacityMap.end() &&
425 "vreg with unallocable register class");
426 return cmItr->second;
429 void TargetRegisterExtraInfo::resetPressureAndLiveStates() {
431 //liveStatesMap.clear();
433 // Iterate over all slots.
436 // Iterate over all live intervals.
437 for (LiveIntervals::iterator liItr = lis->begin(),
439 liItr != liEnd; ++liItr) {
440 LiveInterval *li = liItr->second;
442 const TargetRegisterClass *liTRC;
444 if (TargetRegisterInfo::isPhysicalRegister(li->reg))
447 liTRC = mri->getRegClass(li->reg);
450 // For all ranges in the current interal.
451 for (LiveInterval::iterator lrItr = li->begin(),
453 lrItr != lrEnd; ++lrItr) {
454 LiveRange *lr = &*lrItr;
456 // For all slots in the current range.
457 for (SlotIndex i = lr->start; i != lr->end; i = i.getNextSlot()) {
459 // Record increased pressure at index for all overlapping classes.
460 for (TargetRegisterInfo::regclass_iterator
461 rcItr = tri->regclass_begin(),
462 rcEnd = tri->regclass_end();
463 rcItr != rcEnd; ++rcItr) {
464 const TargetRegisterClass *trc = *rcItr;
466 if (trc->allocation_order_begin(*mf) ==
467 trc->allocation_order_end(*mf))
470 unsigned worstAtI = getWorst(li->reg, trc);
473 pressureMap[i][trc] += worstAtI;
481 unsigned TargetRegisterExtraInfo::getPressureAtSlot(
482 const TargetRegisterClass *trc,
484 PressureMap::const_iterator pmItr = pressureMap.find(i);
485 if (pmItr == pressureMap.end())
487 const PressureMapLine &pmLine = pmItr->second;
488 PressureMapLine::const_iterator pmlItr = pmLine.find(trc);
489 if (pmlItr == pmLine.end())
491 return pmlItr->second;
494 bool TargetRegisterExtraInfo::classOverCapacityAtSlot(
495 const TargetRegisterClass *trc,
497 return (getPressureAtSlot(trc, i) > getCapacity(trc));
500 // ---------- MachineFunctionRenderer implementation ----------
502 template <typename OStream>
503 void RenderMachineFunction::Spacer::print(OStream &os) const {
506 for (unsigned i = 0; i < ns; ++i) {
511 RenderMachineFunction::Spacer RenderMachineFunction::s(unsigned ns) const {
515 template <typename OStream>
516 OStream& operator<<(OStream &os, const RenderMachineFunction::Spacer &s) {
521 template <typename Iterator>
522 std::string RenderMachineFunction::escapeChars(Iterator sBegin, Iterator sEnd) const {
525 for (Iterator sItr = sBegin; sItr != sEnd; ++sItr) {
529 case '<': r.append("<"); break;
530 case '>': r.append(">"); break;
531 case '&': r.append("&"); break;
532 case ' ': r.append(" "); break;
533 case '\"': r.append("""); break;
534 default: r.push_back(c); break;
541 RenderMachineFunction::LiveState
542 RenderMachineFunction::getLiveStateAt(const LiveInterval *li,
544 const MachineInstr *mi = sis->getInstructionFromIndex(i);
549 (vrm->getStackSlot(li->reg) == VirtRegMap::NO_STACK_SLOT)) {
555 if (i.getSlot() == SlotIndex::DEF &&
556 mi->definesRegister(li->reg, tri)) {
558 } else if (i.getSlot() == SlotIndex::USE &&
559 mi->readsRegister(li->reg)) {
563 (vrm->getStackSlot(li->reg) == VirtRegMap::NO_STACK_SLOT)) {
574 RenderMachineFunction::PressureState
575 RenderMachineFunction::getPressureStateAt(const TargetRegisterClass *trc,
577 if (trei.getPressureAtSlot(trc, i) == 0) {
579 } else if (trei.classOverCapacityAtSlot(trc, i)){
585 /// \brief Render a machine instruction.
586 template <typename OStream>
587 void RenderMachineFunction::renderMachineInstr(OStream &os,
588 const MachineInstr *mi) const {
590 raw_string_ostream oss(s);
593 os << escapeChars(oss.str());
596 template <typename OStream, typename T>
597 void RenderMachineFunction::renderVertical(const Spacer &indent,
600 if (ro.fancyVerticals()) {
601 os << indent << "<object\n"
602 << indent + s(2) << "class=\"obj\"\n"
603 << indent + s(2) << "type=\"image/svg+xml\"\n"
604 << indent + s(2) << "width=\"14px\"\n"
605 << indent + s(2) << "height=\"55px\"\n"
606 << indent + s(2) << "data=\"data:image/svg+xml,\n"
607 << indent + s(4) << "<svg xmlns='http://www.w3.org/2000/svg'>\n"
608 << indent + s(6) << "<text x='-55' y='10' "
609 "font-family='Courier' font-size='12' "
610 "transform='rotate(-90)' "
611 "text-rendering='optimizeSpeed' "
612 "fill='#000'>" << t << "</text>\n"
613 << indent + s(4) << "</svg>\">\n"
614 << indent << "</object>\n";
616 std::ostringstream oss;
618 std::string tStr(oss.str());
621 for (std::string::iterator tStrItr = tStr.begin(), tStrEnd = tStr.end();
622 tStrItr != tStrEnd; ++tStrItr) {
623 os << *tStrItr << "<br/>";
629 template <typename OStream>
630 void RenderMachineFunction::insertCSS(const Spacer &indent,
632 os << indent << "<style type=\"text/css\">\n"
633 << indent + s(2) << "body { font-color: black; }\n"
634 << indent + s(2) << "table.code td { font-family: monospace; "
635 "border-width: 0px; border-style: solid; "
636 "border-bottom: 1px solid #dddddd; white-space: nowrap; }\n"
637 << indent + s(2) << "table.code td.p-z { background-color: #000000; }\n"
638 << indent + s(2) << "table.code td.p-l { background-color: #00ff00; }\n"
639 << indent + s(2) << "table.code td.p-h { background-color: #ff0000; }\n"
640 << indent + s(2) << "table.code td.l-n { background-color: #ffffff; }\n"
641 << indent + s(2) << "table.code td.l-d { background-color: #ff0000; }\n"
642 << indent + s(2) << "table.code td.l-u { background-color: #ffff00; }\n"
643 << indent + s(2) << "table.code td.l-r { background-color: #000000; }\n"
644 << indent + s(2) << "table.code td.l-s { background-color: #770000; }\n"
645 << indent + s(2) << "table.code th { border-width: 0px; "
646 "border-style: solid; }\n"
647 << indent << "</style>\n";
650 template <typename OStream>
651 void RenderMachineFunction::renderFunctionSummary(
652 const Spacer &indent, OStream &os,
653 const char * const renderContextStr) const {
654 os << indent << "<h1>Function: " << mf->getFunction()->getName()
656 << indent << "<h2>Rendering context: " << renderContextStr << "</h2>\n";
660 template <typename OStream>
661 void RenderMachineFunction::renderPressureTableLegend(
662 const Spacer &indent,
664 os << indent << "<h2>Rendering Pressure Legend:</h2>\n"
665 << indent << "<table class=\"code\">\n"
666 << indent + s(2) << "<tr>\n"
667 << indent + s(4) << "<th>Pressure</th><th>Description</th>"
668 "<th>Appearance</th>\n"
669 << indent + s(2) << "</tr>\n"
670 << indent + s(2) << "<tr>\n"
671 << indent + s(4) << "<td>No Pressure</td>"
672 "<td>No physical registers of this class requested.</td>"
673 "<td class=\"p-z\"> </td>\n"
674 << indent + s(2) << "</tr>\n"
675 << indent + s(2) << "<tr>\n"
676 << indent + s(4) << "<td>Low Pressure</td>"
677 "<td>Sufficient physical registers to meet demand.</td>"
678 "<td class=\"p-l\"> </td>\n"
679 << indent + s(2) << "</tr>\n"
680 << indent + s(2) << "<tr>\n"
681 << indent + s(4) << "<td>High Pressure</td>"
682 "<td>Potentially insufficient physical registers to meet demand.</td>"
683 "<td class=\"p-h\"> </td>\n"
684 << indent + s(2) << "</tr>\n"
685 << indent << "</table>\n";
688 template <typename OStream, typename CellType>
689 void RenderMachineFunction::renderCellsWithRLE(
690 const Spacer &indent, OStream &os,
691 const std::pair<CellType, unsigned> &rleAccumulator,
692 const std::map<CellType, std::string> &cellTypeStrs) const {
694 if (rleAccumulator.second == 0)
697 typename std::map<CellType, std::string>::const_iterator ctsItr =
698 cellTypeStrs.find(rleAccumulator.first);
700 assert(ctsItr != cellTypeStrs.end() && "No string for given cell type.");
702 os << indent + s(4) << "<td class=\"" << ctsItr->second << "\"";
703 if (rleAccumulator.second > 1)
704 os << " colspan=" << rleAccumulator.second;
709 template <typename OStream>
710 void RenderMachineFunction::renderCodeTablePlusPI(const Spacer &indent,
713 std::map<LiveState, std::string> lsStrs;
714 lsStrs[Dead] = "l-n";
715 lsStrs[Defined] = "l-d";
716 lsStrs[Used] = "l-u";
717 lsStrs[AliveReg] = "l-r";
718 lsStrs[AliveStack] = "l-s";
720 std::map<PressureState, std::string> psStrs;
721 psStrs[Zero] = "p-z";
723 psStrs[High] = "p-h";
727 os << indent << "<table cellpadding=0 cellspacing=0 class=\"code\">\n"
728 << indent + s(2) << "<tr>\n";
730 // Render the header row...
732 os << indent + s(4) << "<th>index</th>\n"
733 << indent + s(4) << "<th>instr</th>\n";
735 // Render class names if necessary...
736 if (!ro.regClasses().empty()) {
737 for (MFRenderingOptions::RegClassSet::const_iterator
738 rcItr = ro.regClasses().begin(),
739 rcEnd = ro.regClasses().end();
740 rcItr != rcEnd; ++rcItr) {
741 const TargetRegisterClass *trc = *rcItr;
742 os << indent + s(4) << "<th>\n";
743 renderVertical(indent + s(6), os, trc->getName());
744 os << indent + s(4) << "</th>\n";
748 // FIXME: Is there a nicer way to insert space between columns in HTML?
749 if (!ro.regClasses().empty() && !ro.intervals().empty())
750 os << indent + s(4) << "<th> </th>\n";
752 // Render interval numbers if necessary...
753 if (!ro.intervals().empty()) {
754 for (MFRenderingOptions::IntervalSet::const_iterator
755 liItr = ro.intervals().begin(),
756 liEnd = ro.intervals().end();
757 liItr != liEnd; ++liItr) {
759 const LiveInterval *li = *liItr;
760 os << indent + s(4) << "<th>\n";
761 renderVertical(indent + s(6), os, li->reg);
762 os << indent + s(4) << "</th>\n";
766 os << indent + s(2) << "</tr>\n";
768 // End header row, start with the data rows...
770 MachineInstr *mi = 0;
773 for (SlotIndex i = sis->getZeroIndex(); i != sis->getLastIndex();
774 i = i.getNextSlot()) {
776 // Render the slot column.
777 os << indent + s(2) << "<tr height=6ex>\n";
779 // Render the code column.
780 if (i.getSlot() == SlotIndex::LOAD) {
781 MachineBasicBlock *mbb = sis->getMBBFromIndex(i);
782 mi = sis->getInstructionFromIndex(i);
784 if (i == sis->getMBBStartIdx(mbb) || mi != 0 ||
785 ro.renderEmptyIndexes()) {
786 os << indent + s(4) << "<td rowspan=4>" << i << " </td>\n"
787 << indent + s(4) << "<td rowspan=4>\n";
789 if (i == sis->getMBBStartIdx(mbb)) {
790 os << indent + s(6) << "BB#" << mbb->getNumber() << ": \n";
791 } else if (mi != 0) {
792 os << indent + s(6) << " ";
793 renderMachineInstr(os, mi);
795 // Empty interval - leave blank.
797 os << indent + s(4) << "</td>\n";
799 i = i.getStoreIndex(); // <- Will be incremented to the next index.
804 // Render the class columns.
805 if (!ro.regClasses().empty()) {
806 std::pair<PressureState, unsigned> psRLEAccumulator(Zero, 0);
807 for (MFRenderingOptions::RegClassSet::const_iterator
808 rcItr = ro.regClasses().begin(),
809 rcEnd = ro.regClasses().end();
810 rcItr != rcEnd; ++rcItr) {
811 const TargetRegisterClass *trc = *rcItr;
812 PressureState newPressure = getPressureStateAt(trc, i);
814 if (newPressure == psRLEAccumulator.first) {
815 ++psRLEAccumulator.second;
817 renderCellsWithRLE(indent + s(4), os, psRLEAccumulator, psStrs);
818 psRLEAccumulator.first = newPressure;
819 psRLEAccumulator.second = 1;
822 renderCellsWithRLE(indent + s(4), os, psRLEAccumulator, psStrs);
825 // FIXME: Is there a nicer way to insert space between columns in HTML?
826 if (!ro.regClasses().empty() && !ro.intervals().empty())
827 os << indent + s(4) << "<td width=2em></td>\n";
829 if (!ro.intervals().empty()) {
830 std::pair<LiveState, unsigned> lsRLEAccumulator(Dead, 0);
831 for (MFRenderingOptions::IntervalSet::const_iterator
832 liItr = ro.intervals().begin(),
833 liEnd = ro.intervals().end();
834 liItr != liEnd; ++liItr) {
835 const LiveInterval *li = *liItr;
836 LiveState newLiveness = getLiveStateAt(li, i);
838 if (newLiveness == lsRLEAccumulator.first) {
839 ++lsRLEAccumulator.second;
841 renderCellsWithRLE(indent + s(4), os, lsRLEAccumulator, lsStrs);
842 lsRLEAccumulator.first = newLiveness;
843 lsRLEAccumulator.second = 1;
846 renderCellsWithRLE(indent + s(4), os, lsRLEAccumulator, lsStrs);
848 os << indent + s(2) << "</tr>\n";
851 os << indent << "</table>\n";
853 if (!ro.regClasses().empty())
854 renderPressureTableLegend(indent, os);
857 template <typename OStream>
858 void RenderMachineFunction::renderWarnings(const Spacer &indent,
862 template <typename OStream>
863 void RenderMachineFunction::renderFunctionPage(
865 const char * const renderContextStr) const {
867 << s(2) << "<head>\n"
868 << s(4) << "<title>" << fqn << "</title>\n";
872 os << s(2) << "<head>\n"
873 << s(2) << "<body >\n";
875 renderFunctionSummary(s(4), os, renderContextStr);
877 os << s(4) << "<br/><br/><br/>\n";
879 //renderLiveIntervalInfoTable(" ", os);
881 os << s(4) << "<br/><br/><br/>\n";
883 renderCodeTablePlusPI(s(4), os);
885 os << s(2) << "</body>\n"
889 void RenderMachineFunction::getAnalysisUsage(AnalysisUsage &au) const {
890 au.addRequired<SlotIndexes>();
891 au.addRequired<LiveIntervals>();
892 au.setPreservesAll();
893 MachineFunctionPass::getAnalysisUsage(au);
896 bool RenderMachineFunction::runOnMachineFunction(MachineFunction &fn) {
898 mri = &mf->getRegInfo();
899 tri = mf->getTarget().getRegisterInfo();
900 lis = &getAnalysis<LiveIntervals>();
901 sis = &getAnalysis<SlotIndexes>();
903 trei.setup(mf, mri, tri, lis);
904 ro.setup(mf, tri, lis);
906 fqn = mf->getFunction()->getParent()->getModuleIdentifier() + "." +
907 mf->getFunction()->getName().str();
912 void RenderMachineFunction::releaseMemory() {
917 void RenderMachineFunction::renderMachineFunction(
918 const char *renderContextStr,
919 const VirtRegMap *vrm,
920 const char *renderSuffix) {
921 if (!ro.shouldRenderCurrentMachineFunction())
927 std::string rpFileName(mf->getFunction()->getName().str() +
928 (renderSuffix ? renderSuffix : "") +
932 raw_fd_ostream outFile(rpFileName.c_str(), errMsg, raw_fd_ostream::F_Binary);
934 renderFunctionPage(outFile, renderContextStr);
936 ro.resetRenderSpecificOptions();
939 std::string RenderMachineFunction::escapeChars(const std::string &s) const {
940 return escapeChars(s.begin(), s.end());