Skip to content

Commit

Permalink
[VPlan] Add dump() helper to VPValue & VPRecipeBase.
Browse files Browse the repository at this point in the history
This provides a convenient way to print VPValues and recipes in a
debugger. In particular it saves the user from instantiating
VPSlotTracker to print recipes or values.
  • Loading branch information
fhahn committed Sep 22, 2020
1 parent 534f6e1 commit c671e34
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
14 changes: 14 additions & 0 deletions llvm/lib/Transforms/Vectorize/VPlan.cpp
Expand Up @@ -63,6 +63,20 @@ void VPValue::print(raw_ostream &OS, VPSlotTracker &SlotTracker) const {
printAsOperand(OS, SlotTracker);
}

void VPValue::dump() const {
const VPInstruction *Instr = dyn_cast<VPInstruction>(this);
VPSlotTracker SlotTracker(
(Instr && Instr->getParent()) ? Instr->getParent()->getPlan() : nullptr);
print(dbgs(), SlotTracker);
dbgs() << "\n";
}

void VPRecipeBase::dump() const {
VPSlotTracker SlotTracker(nullptr);
print(dbgs(), "", SlotTracker);
dbgs() << "\n";
}

// Get the top-most entry block of \p Start. This is the entry block of the
// containing VPlan. This function is templated to support both const and non-const blocks
template <typename T> static T *getPlanEntry(T *Start) {
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Transforms/Vectorize/VPlan.h
Expand Up @@ -653,6 +653,9 @@ class VPRecipeBase : public ilist_node_with_parent<VPRecipeBase, VPBasicBlock> {
virtual void print(raw_ostream &O, const Twine &Indent,
VPSlotTracker &SlotTracker) const = 0;

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

/// Insert an unlinked recipe into a basic block immediately before
/// the specified recipe.
void insertBefore(VPRecipeBase *InsertPos);
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Transforms/Vectorize/VPlanValue.h
Expand Up @@ -90,6 +90,9 @@ class VPValue {
void printAsOperand(raw_ostream &OS, VPSlotTracker &Tracker) const;
void print(raw_ostream &OS, VPSlotTracker &Tracker) const;

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

unsigned getNumUsers() const { return Users.size(); }
void addUser(VPUser &User) { Users.push_back(&User); }

Expand Down

0 comments on commit c671e34

Please sign in to comment.