Skip to content

Commit e9c6842

Browse files
committed
[VPlan] Add dump function to VPlan class.
This adds a dump() function to VPlan, which uses the existing operator<<. This method provides a convenient way to dump a VPlan while debugging, e.g. from lldb. Reviewers: hsaito, Ayal, gilr, rengolin Reviewed By: hsaito Differential Revision: https://reviews.llvm.org/D70920
1 parent aa189ed commit e9c6842

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,11 @@ void VPlan::execute(VPTransformState *State) {
468468
updateDominatorTree(State->DT, VectorPreHeaderBB, VectorLatchBB);
469469
}
470470

471+
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
472+
LLVM_DUMP_METHOD
473+
void VPlan::dump() const { dbgs() << *this << '\n'; }
474+
#endif
475+
471476
void VPlan::updateDominatorTree(DominatorTree *DT, BasicBlock *LoopPreHeaderBB,
472477
BasicBlock *LoopLatchBB) {
473478
BasicBlock *LoopHeaderBB = LoopPreHeaderBB->getSingleSuccessor();
@@ -527,8 +532,7 @@ void VPlanPrinter::dump() {
527532
if (!Plan.Value2VPValue.empty() || Plan.BackedgeTakenCount) {
528533
OS << ", where:";
529534
if (Plan.BackedgeTakenCount)
530-
OS << "\\n"
531-
<< *Plan.getOrCreateBackedgeTakenCount() << " := BackedgeTakenCount";
535+
OS << "\\n" << *Plan.BackedgeTakenCount << " := BackedgeTakenCount";
532536
for (auto Entry : Plan.Value2VPValue) {
533537
OS << "\\n" << *Entry.second;
534538
OS << DOT::EscapeString(" := ");
@@ -540,7 +544,7 @@ void VPlanPrinter::dump() {
540544
OS << "edge [fontname=Courier, fontsize=30]\n";
541545
OS << "compound=true\n";
542546

543-
for (VPBlockBase *Block : depth_first(Plan.getEntry()))
547+
for (const VPBlockBase *Block : depth_first(Plan.getEntry()))
544548
dumpBlock(Block);
545549

546550
OS << "}\n";

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,9 @@ class VPlan {
13871387
VPLoopInfo &getVPLoopInfo() { return VPLInfo; }
13881388
const VPLoopInfo &getVPLoopInfo() const { return VPLInfo; }
13891389

1390+
/// Dump the plan to stderr (for debugging).
1391+
void dump() const;
1392+
13901393
private:
13911394
/// Add to the given dominator tree the header block and every new basic block
13921395
/// that was created between it and the latch block, inclusive.
@@ -1398,20 +1401,20 @@ class VPlan {
13981401
/// VPlanPrinter prints a given VPlan to a given output stream. The printing is
13991402
/// indented and follows the dot format.
14001403
class VPlanPrinter {
1401-
friend inline raw_ostream &operator<<(raw_ostream &OS, VPlan &Plan);
1404+
friend inline raw_ostream &operator<<(raw_ostream &OS, const VPlan &Plan);
14021405
friend inline raw_ostream &operator<<(raw_ostream &OS,
14031406
const struct VPlanIngredient &I);
14041407

14051408
private:
14061409
raw_ostream &OS;
1407-
VPlan &Plan;
1410+
const VPlan &Plan;
14081411
unsigned Depth = 0;
14091412
unsigned TabWidth = 2;
14101413
std::string Indent;
14111414
unsigned BID = 0;
14121415
SmallDenseMap<const VPBlockBase *, unsigned> BlockID;
14131416

1414-
VPlanPrinter(raw_ostream &O, VPlan &P) : OS(O), Plan(P) {}
1417+
VPlanPrinter(raw_ostream &O, const VPlan &P) : OS(O), Plan(P) {}
14151418

14161419
/// Handle indentation.
14171420
void bumpIndent(int b) { Indent = std::string((Depth += b) * TabWidth, ' '); }
@@ -1458,13 +1461,12 @@ inline raw_ostream &operator<<(raw_ostream &OS, const VPlanIngredient &I) {
14581461
return OS;
14591462
}
14601463

1461-
inline raw_ostream &operator<<(raw_ostream &OS, VPlan &Plan) {
1464+
inline raw_ostream &operator<<(raw_ostream &OS, const VPlan &Plan) {
14621465
VPlanPrinter Printer(OS, Plan);
14631466
Printer.dump();
14641467
return OS;
14651468
}
14661469

1467-
14681470
//===----------------------------------------------------------------------===//
14691471
// VPlan Utilities
14701472
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)