Skip to content

Commit

Permalink
[VPlan] Add dump function to VPlan class.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
fhahn committed Dec 3, 2019
1 parent aa189ed commit e9c6842
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
10 changes: 7 additions & 3 deletions llvm/lib/Transforms/Vectorize/VPlan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,11 @@ void VPlan::execute(VPTransformState *State) {
updateDominatorTree(State->DT, VectorPreHeaderBB, VectorLatchBB);
}

#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
LLVM_DUMP_METHOD
void VPlan::dump() const { dbgs() << *this << '\n'; }
#endif

void VPlan::updateDominatorTree(DominatorTree *DT, BasicBlock *LoopPreHeaderBB,
BasicBlock *LoopLatchBB) {
BasicBlock *LoopHeaderBB = LoopPreHeaderBB->getSingleSuccessor();
Expand Down Expand Up @@ -527,8 +532,7 @@ void VPlanPrinter::dump() {
if (!Plan.Value2VPValue.empty() || Plan.BackedgeTakenCount) {
OS << ", where:";
if (Plan.BackedgeTakenCount)
OS << "\\n"
<< *Plan.getOrCreateBackedgeTakenCount() << " := BackedgeTakenCount";
OS << "\\n" << *Plan.BackedgeTakenCount << " := BackedgeTakenCount";
for (auto Entry : Plan.Value2VPValue) {
OS << "\\n" << *Entry.second;
OS << DOT::EscapeString(" := ");
Expand All @@ -540,7 +544,7 @@ void VPlanPrinter::dump() {
OS << "edge [fontname=Courier, fontsize=30]\n";
OS << "compound=true\n";

for (VPBlockBase *Block : depth_first(Plan.getEntry()))
for (const VPBlockBase *Block : depth_first(Plan.getEntry()))
dumpBlock(Block);

OS << "}\n";
Expand Down
12 changes: 7 additions & 5 deletions llvm/lib/Transforms/Vectorize/VPlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,9 @@ class VPlan {
VPLoopInfo &getVPLoopInfo() { return VPLInfo; }
const VPLoopInfo &getVPLoopInfo() const { return VPLInfo; }

/// Dump the plan to stderr (for debugging).
void dump() const;

private:
/// Add to the given dominator tree the header block and every new basic block
/// that was created between it and the latch block, inclusive.
Expand All @@ -1398,20 +1401,20 @@ class VPlan {
/// VPlanPrinter prints a given VPlan to a given output stream. The printing is
/// indented and follows the dot format.
class VPlanPrinter {
friend inline raw_ostream &operator<<(raw_ostream &OS, VPlan &Plan);
friend inline raw_ostream &operator<<(raw_ostream &OS, const VPlan &Plan);
friend inline raw_ostream &operator<<(raw_ostream &OS,
const struct VPlanIngredient &I);

private:
raw_ostream &OS;
VPlan &Plan;
const VPlan &Plan;
unsigned Depth = 0;
unsigned TabWidth = 2;
std::string Indent;
unsigned BID = 0;
SmallDenseMap<const VPBlockBase *, unsigned> BlockID;

VPlanPrinter(raw_ostream &O, VPlan &P) : OS(O), Plan(P) {}
VPlanPrinter(raw_ostream &O, const VPlan &P) : OS(O), Plan(P) {}

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

inline raw_ostream &operator<<(raw_ostream &OS, VPlan &Plan) {
inline raw_ostream &operator<<(raw_ostream &OS, const VPlan &Plan) {
VPlanPrinter Printer(OS, Plan);
Printer.dump();
return OS;
}


//===----------------------------------------------------------------------===//
// VPlan Utilities
//===----------------------------------------------------------------------===//
Expand Down

0 comments on commit e9c6842

Please sign in to comment.