diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h --- a/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h +++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h @@ -256,7 +256,9 @@ /// best selected VPlan. void executePlan(InnerLoopVectorizer &LB, DominatorTree *DT); +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) void printPlans(raw_ostream &O); +#endif /// Look through the existing plans and return true if we have one with all /// the vectorization factors in question. diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -7813,6 +7813,7 @@ ILV.printDebugTracesAtEnd(); } +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) void LoopVectorizationPlanner::printPlans(raw_ostream &O) { for (const auto &Plan : VPlans) if (PrintVPlansInDotFormat) @@ -7820,6 +7821,7 @@ else Plan->print(O); } +#endif void LoopVectorizationPlanner::collectTriviallyDeadInstructions( SmallPtrSetImpl &DeadInstructions) { @@ -9017,6 +9019,7 @@ } } +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) void VPInterleaveRecipe::print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const { O << Indent << "INTERLEAVE-GROUP with factor " << IG->getFactor() << " at "; @@ -9032,6 +9035,7 @@ if (Instruction *I = IG->getMember(i)) O << "\n" << Indent << " " << VPlanIngredient(I) << " " << i; } +#endif void VPWidenCallRecipe::execute(VPTransformState &State) { State.ILV->widenCallInstruction(*cast(getUnderlyingInstr()), this, diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -573,10 +573,6 @@ /// Delete all blocks reachable from a given VPBlockBase, inclusive. static void deleteCFG(VPBlockBase *Entry); - void printAsOperand(raw_ostream &OS, bool PrintType) const { - OS << getName(); - } - /// Return true if it is legal to hoist instructions into this block. bool isLegalToHoistInto() { // There are currently no constraints that prevent an instruction to be @@ -588,6 +584,11 @@ /// replaces all uses of VPValues defined in the block with NewValue. virtual void dropAllReferences(VPValue *NewValue) = 0; +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) + void printAsOperand(raw_ostream &OS, bool PrintType) const { + OS << getName(); + } + /// Print plain-text dump of this VPBlockBase to \p O, prefixing all lines /// with \p Indent. \p SlotTracker is used to print unnamed VPValue's using /// consequtive numbers. @@ -604,7 +605,8 @@ } /// Dump this VPBlockBase to dbgs(). - void dump() const { print(dbgs()); } + LLVM_DUMP_METHOD void dump() const { print(dbgs()); } +#endif }; /// VPRecipeBase is a base class modeling a sequence of one or more output IR @@ -760,12 +762,14 @@ /// provided. void execute(VPTransformState &State) override; +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// Print the VPInstruction to \p O. void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override; /// Print the VPInstruction to dbgs() (for debugging). - void dump() const; + LLVM_DUMP_METHOD void dump() const; +#endif /// Return true if this instruction may modify memory. bool mayWriteToMemory() const { @@ -819,9 +823,11 @@ /// Produce widened copies of all Ingredients. void execute(VPTransformState &State) override; +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// Print the recipe. void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override; +#endif }; /// A recipe for widening Call instructions. @@ -843,9 +849,11 @@ /// Produce a widened version of the call instruction. void execute(VPTransformState &State) override; +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// Print the recipe. void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override; +#endif }; /// A recipe for widening select instructions. @@ -872,9 +880,11 @@ /// Produce a widened version of the select instruction. void execute(VPTransformState &State) override; +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// Print the recipe. void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override; +#endif }; /// A recipe for handling GEP instructions. @@ -910,9 +920,11 @@ /// Generate the gep nodes. void execute(VPTransformState &State) override; +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// Print the recipe. void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override; +#endif }; /// A recipe for handling phi nodes of integer and floating-point inductions, @@ -943,9 +955,11 @@ /// needed by their users. void execute(VPTransformState &State) override; +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// Print the recipe. void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override; +#endif /// Returns the start value of the induction. VPValue *getStartValue() { return getOperand(0); } @@ -1005,9 +1019,11 @@ /// Generate the phi/select nodes. void execute(VPTransformState &State) override; +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// Print the recipe. void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override; +#endif /// Returns the start value of the phi, if it is a reduction. VPValue *getStartValue() { @@ -1063,9 +1079,11 @@ /// Generate the phi/select nodes. void execute(VPTransformState &State) override; +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// Print the recipe. void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override; +#endif }; /// VPInterleaveRecipe is a recipe for transforming an interleave group of load @@ -1126,9 +1144,11 @@ /// Generate the wide load or store, and shuffles. void execute(VPTransformState &State) override; +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// Print the recipe. void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override; +#endif const InterleaveGroup *getInterleaveGroup() { return IG; } }; @@ -1166,9 +1186,11 @@ /// Generate the reduction in the loop void execute(VPTransformState &State) override; +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// Print the recipe. void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override; +#endif /// The VPValue of the scalar Chain being accumulated. VPValue *getChainOp() const { return getOperand(0); } @@ -1226,9 +1248,11 @@ void setAlsoPack(bool Pack) { AlsoPack = Pack; } +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// Print the recipe. void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override; +#endif bool isUniform() const { return IsUniform; } @@ -1255,6 +1279,7 @@ /// conditional branch. void execute(VPTransformState &State) override; +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// Print the recipe. void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override { @@ -1264,6 +1289,7 @@ else O << " All-One"; } +#endif /// Return the mask used by this recipe. Note that a full mask is represented /// by a nullptr. @@ -1296,9 +1322,11 @@ /// Generates phi nodes for live-outs as needed to retain SSA form. void execute(VPTransformState &State) override; +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// Print the recipe. void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override; +#endif }; /// A Recipe for widening load/store operations. @@ -1363,9 +1391,11 @@ /// Generate the wide load/store. void execute(VPTransformState &State) override; +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// Print the recipe. void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override; +#endif }; /// A Recipe for widening the canonical induction variable of the vector loop. @@ -1387,9 +1417,11 @@ /// step = . void execute(VPTransformState &State) override; +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// Print the recipe. void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override; +#endif }; /// VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph. It @@ -1474,6 +1506,7 @@ void dropAllReferences(VPValue *NewValue) override; +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// Print this VPBsicBlock to \p O, prefixing all lines with \p Indent. \p /// SlotTracker is used to print unnamed VPValue's using consequtive numbers. /// @@ -1482,6 +1515,7 @@ void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override; using VPBlockBase::print; // Get the print(raw_stream &O) version. +#endif private: /// Create an IR BasicBlock to hold the output instructions generated by this @@ -1575,6 +1609,7 @@ void dropAllReferences(VPValue *NewValue) override; +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// Print this VPRegionBlock to \p O (recursively), prefixing all lines with /// \p Indent. \p SlotTracker is used to print unnamed VPValue's using /// consequtive numbers. @@ -1584,6 +1619,7 @@ void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override; using VPBlockBase::print; // Get the print(raw_stream &O) version. +#endif }; //===----------------------------------------------------------------------===// @@ -1836,6 +1872,7 @@ VPLoopInfo &getVPLoopInfo() { return VPLInfo; } const VPLoopInfo &getVPLoopInfo() const { return VPLInfo; } +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// Print this VPlan to \p O. void print(raw_ostream &O) const; @@ -1843,7 +1880,8 @@ void printDOT(raw_ostream &O) const; /// Dump the plan to stderr (for debugging). - void dump() const; + LLVM_DUMP_METHOD void dump() const; +#endif /// Returns a range mapping the values the range \p Operands to their /// corresponding VPValues. @@ -1863,6 +1901,7 @@ BasicBlock *LoopExitBB); }; +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// VPlanPrinter prints a given VPlan to a given output stream. The printing is /// indented and follows the dot format. class VPlanPrinter { @@ -1909,7 +1948,7 @@ VPlanPrinter(raw_ostream &O, const VPlan &P) : OS(O), Plan(P), SlotTracker(&P) {} - void dump(); + LLVM_DUMP_METHOD void dump(); }; struct VPlanIngredient { @@ -1929,6 +1968,7 @@ Plan.print(OS); return OS; } +#endif //===----------------------------------------------------------------------===// // VPlan Utilities @@ -2144,8 +2184,10 @@ SmallPtrSetImpl &Candidates, VPInterleavedAccessInfo &IAI); +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// Print bundle \p Values to dbgs(). void dumpBundle(ArrayRef Values); +#endif public: VPlanSlp(VPInterleavedAccessInfo &IAI, VPBasicBlock &BB) : IAI(IAI), BB(BB) {} diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp --- a/llvm/lib/Transforms/Vectorize/VPlan.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp @@ -50,6 +50,7 @@ #define DEBUG_TYPE "vplan" +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) raw_ostream &llvm::operator<<(raw_ostream &OS, const VPValue &V) { const VPInstruction *Instr = dyn_cast(&V); VPSlotTracker SlotTracker( @@ -57,6 +58,7 @@ V.print(OS, SlotTracker); return OS; } +#endif Value *VPLane::getAsRuntimeExpr(IRBuilder<> &Builder, const ElementCount &VF) const { @@ -83,6 +85,7 @@ Def->removeDefinedValue(this); } +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) void VPValue::print(raw_ostream &OS, VPSlotTracker &SlotTracker) const { if (const VPRecipeBase *R = dyn_cast_or_null(Def)) R->print(OS, "", SlotTracker); @@ -105,6 +108,7 @@ print(dbgs(), "", SlotTracker); dbgs() << "\n"; } +#endif // 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 @@ -399,6 +403,7 @@ } } +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) void VPBasicBlock::print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const { O << Indent << getName() << ":\n"; @@ -434,6 +439,7 @@ O << '\n'; } } +#endif void VPRegionBlock::dropAllReferences(VPValue *NewValue) { for (VPBlockBase *Block : depth_first(Entry)) @@ -491,6 +497,7 @@ State->Instance.reset(); } +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) void VPRegionBlock::print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const { O << Indent << (isReplicator() ? " " : " ") << getName() << ": {"; @@ -501,6 +508,7 @@ } O << Indent << "}\n"; } +#endif void VPRecipeBase::insertBefore(VPRecipeBase *InsertPos) { assert(!Parent && "Recipe already in some VPBasicBlock"); @@ -601,6 +609,7 @@ generateInstruction(State, Part); } +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) void VPInstruction::dump() const { VPSlotTracker SlotTracker(getParent()->getPlan()); print(dbgs(), "", SlotTracker); @@ -641,6 +650,7 @@ Operand->printAsOperand(O, SlotTracker); } } +#endif /// Generate the code inside the body of the vectorized loop. Assumes a single /// LoopVectorBody basic-block was created for this. Introduce additional @@ -730,7 +740,7 @@ L->getExitBlock()); } -// TODO: Wrap those in #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)/#endif. +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) LLVM_DUMP_METHOD void VPlan::print(raw_ostream &O) const { VPSlotTracker SlotTracker(this); @@ -749,7 +759,6 @@ Printer.dump(); } -#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) LLVM_DUMP_METHOD void VPlan::dump() const { print(dbgs()); } #endif @@ -794,6 +803,7 @@ assert(DT->verify(DominatorTree::VerificationLevel::Fast)); } +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) const Twine VPlanPrinter::getUID(const VPBlockBase *Block) { return (isa(Block) ? "cluster_N" : "N") + Twine(getOrCreateBID(Block)); @@ -1072,6 +1082,7 @@ printOperands(O, SlotTracker); } +#endif void VPWidenCanonicalIVRecipe::execute(VPTransformState &State) { Value *CanonicalIV = State.CanonicalIV; @@ -1098,12 +1109,14 @@ } } +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) void VPWidenCanonicalIVRecipe::print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const { O << Indent << "EMIT "; getVPValue()->printAsOperand(O, SlotTracker); O << " = WIDEN-CANONICAL-INDUCTION"; } +#endif template void DomTreeBuilder::Calculate(VPDominatorTree &DT); @@ -1122,6 +1135,7 @@ } } +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) void VPValue::printAsOperand(raw_ostream &OS, VPSlotTracker &Tracker) const { if (const Value *UV = getUnderlyingValue()) { OS << "ir<"; @@ -1142,6 +1156,7 @@ Op->printAsOperand(O, SlotTracker); }); } +#endif void VPInterleavedAccessInfo::visitRegion(VPRegionBlock *Region, Old2NewTy &Old2New, diff --git a/llvm/lib/Transforms/Vectorize/VPlanSLP.cpp b/llvm/lib/Transforms/Vectorize/VPlanSLP.cpp --- a/llvm/lib/Transforms/Vectorize/VPlanSLP.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanSLP.cpp @@ -349,6 +349,7 @@ return FinalOrder; } +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) void VPlanSlp::dumpBundle(ArrayRef Values) { dbgs() << " Ops: "; for (auto Op : Values) { @@ -361,6 +362,7 @@ } dbgs() << "\n"; } +#endif VPInstruction *VPlanSlp::buildGraph(ArrayRef Values) { assert(!Values.empty() && "Need some operands!"); diff --git a/llvm/lib/Transforms/Vectorize/VPlanValue.h b/llvm/lib/Transforms/Vectorize/VPlanValue.h --- a/llvm/lib/Transforms/Vectorize/VPlanValue.h +++ b/llvm/lib/Transforms/Vectorize/VPlanValue.h @@ -116,11 +116,13 @@ /// for any other purpose, as the values may change as LLVM evolves. unsigned getVPValueID() const { return SubclassID; } +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 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; +#endif unsigned getNumUsers() const { return Users.size(); } void addUser(VPUser &User) { Users.push_back(&User); } @@ -192,8 +194,10 @@ SmallVector Operands; protected: +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// Print the operands to \p O. void printOperands(raw_ostream &O, VPSlotTracker &SlotTracker) const; +#endif public: VPUser() {} @@ -347,12 +351,14 @@ /// for any other purpose, as the values may change as LLVM evolves. unsigned getVPDefID() const { return SubclassID; } +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) /// Dump the VPDef to stderr (for debugging). void dump() const; /// Each concrete VPDef prints itself. virtual void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const = 0; +#endif }; class VPlan; diff --git a/llvm/unittests/Transforms/Vectorize/VPlanHCFGTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanHCFGTest.cpp --- a/llvm/unittests/Transforms/Vectorize/VPlanHCFGTest.cpp +++ b/llvm/unittests/Transforms/Vectorize/VPlanHCFGTest.cpp @@ -89,6 +89,7 @@ EXPECT_EQ(IndvarAdd, ICmp->getOperand(0)); EXPECT_EQ(VecBB->getCondBit(), ICmp); +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) // Add an external value to check we do not print the list of external values, // as this is not required with the new printing. Plan->addVPValue(&*F->arg_begin()); @@ -131,6 +132,7 @@ } )"; EXPECT_EQ(ExpectedStr, FullDump); +#endif LoopVectorizationLegality::InductionList Inductions; SmallPtrSet DeadInstructions; diff --git a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp --- a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp +++ b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp @@ -324,6 +324,7 @@ } } +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) TEST(VPBasicBlockTest, print) { VPInstruction *I1 = new VPInstruction(Instruction::Add, {}); VPInstruction *I2 = new VPInstruction(Instruction::Sub, {I1}); @@ -422,6 +423,7 @@ EXPECT_EQ("EMIT vp<%3> = mul vp<%1> vp<%0>", I4Dump); } } +#endif TEST(VPRecipeTest, CastVPInstructionToVPUser) { VPValue Op1; @@ -608,6 +610,7 @@ delete Load; } +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) TEST(VPRecipeTest, dump) { VPlan Plan; VPBasicBlock *VPBB1 = new VPBasicBlock(); @@ -663,6 +666,7 @@ delete AI; } +#endif TEST(VPRecipeTest, CastVPReductionRecipeToVPUser) { LLVMContext C; @@ -684,8 +688,10 @@ } void execute(struct VPTransformState &State) override{}; +#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) void print(raw_ostream &O, const Twine &Indent, VPSlotTracker &SlotTracker) const override {} +#endif }; TEST(VPDoubleValueDefTest, traverseUseLists) {