[llvm] r317003 - [LoopVectorize] Replace manual VPlan memory management with unique_ptr.

Benjamin Kramer via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 31 07:58:23 PDT 2017


Author: d0k
Date: Tue Oct 31 07:58:22 2017
New Revision: 317003

URL: http://llvm.org/viewvc/llvm-project?rev=317003&view=rev
Log:
[LoopVectorize] Replace manual VPlan memory management with unique_ptr.

No functionality change intended.

Modified:
    llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp

Modified: llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp?rev=317003&r1=317002&r2=317003&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp (original)
+++ llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp Tue Oct 31 07:58:22 2017
@@ -2228,7 +2228,7 @@ class LoopVectorizationPlanner {
   /// The profitablity analysis.
   LoopVectorizationCostModel &CM;
 
-  SmallVector<VPlan *, 4> VPlans;
+  SmallVector<std::unique_ptr<VPlan>, 4> VPlans;
 
   unsigned BestVF = 0;
   unsigned BestUF = 0;
@@ -2240,14 +2240,6 @@ public:
                            LoopVectorizationCostModel &CM)
       : OrigLoop(L), LI(LI), TLI(TLI), TTI(TTI), Legal(Legal), CM(CM) {}
 
-  ~LoopVectorizationPlanner() {
-    while (!VPlans.empty()) {
-      VPlan *Plan = VPlans.back();
-      VPlans.pop_back();
-      delete Plan;
-    }
-  }
-
   /// Plan how to best vectorize, return the best VF and its cost.
   LoopVectorizationCostModel::VectorizationFactor plan(bool OptForSize,
                                                        unsigned UserVF);
@@ -2260,7 +2252,7 @@ public:
   void executePlan(InnerLoopVectorizer &LB, DominatorTree *DT);
 
   void printPlans(raw_ostream &O) {
-    for (VPlan *Plan : VPlans)
+    for (const auto &Plan : VPlans)
       O << *Plan;
   }
 
@@ -2336,7 +2328,7 @@ private:
   /// Build a VPlan according to the information gathered by Legal. \return a
   /// VPlan for vectorization factors \p Range.Start and up to \p Range.End
   /// exclusive, possibly decreasing \p Range.End.
-  VPlan *buildVPlan(VFRange &Range);
+  std::unique_ptr<VPlan> buildVPlan(VFRange &Range);
 };
 
 } // end namespace llvm
@@ -7616,15 +7608,9 @@ void LoopVectorizationPlanner::setBestPl
   BestVF = VF;
   BestUF = UF;
 
-  for (auto *VPlanIter = VPlans.begin(); VPlanIter != VPlans.end();) {
-    VPlan *Plan = *VPlanIter;
-    if (Plan->hasVF(VF))
-      ++VPlanIter;
-    else {
-      VPlanIter = VPlans.erase(VPlanIter);
-      delete Plan;
-    }
-  }
+  erase_if(VPlans, [VF](const std::unique_ptr<VPlan> &Plan) {
+    return !Plan->hasVF(VF);
+  });
   assert(VPlans.size() == 1 && "Best VF has not a single VPlan.");
 }
 
@@ -7647,8 +7633,7 @@ void LoopVectorizationPlanner::executePl
 
   // 2. Copy and widen instructions from the old loop into the new loop.
   assert(VPlans.size() == 1 && "Not a single VPlan to execute.");
-  VPlan *Plan = *VPlans.begin();
-  Plan->execute(&State);
+  VPlans.front()->execute(&State);
 
   // 3. Fix the vectorized code: take care of header phi's, live-outs,
   //    predication, updating analyses.
@@ -8009,8 +7994,7 @@ bool LoopVectorizationPlanner::getDecisi
 void LoopVectorizationPlanner::buildVPlans(unsigned MinVF, unsigned MaxVF) {
   for (unsigned VF = MinVF; VF < MaxVF + 1;) {
     VFRange SubRange = {VF, MaxVF + 1};
-    VPlan *Plan = buildVPlan(SubRange);
-    VPlans.push_back(Plan);
+    VPlans.push_back(buildVPlan(SubRange));
     VF = SubRange.End;
   }
 }
@@ -8238,7 +8222,7 @@ LoopVectorizationPlanner::createReplicat
   return Region;
 }
 
-VPlan *LoopVectorizationPlanner::buildVPlan(VFRange &Range) {
+std::unique_ptr<VPlan> LoopVectorizationPlanner::buildVPlan(VFRange &Range) {
   DenseMap<Instruction *, Instruction *> &SinkAfter = Legal->getSinkAfter();
   DenseMap<Instruction *, Instruction *> SinkAfterInverse;
 
@@ -8258,7 +8242,7 @@ VPlan *LoopVectorizationPlanner::buildVP
 
   // Create a dummy pre-entry VPBasicBlock to start building the VPlan.
   VPBasicBlock *VPBB = new VPBasicBlock("Pre-Entry");
-  VPlan *Plan = new VPlan(VPBB);
+  auto Plan = llvm::make_unique<VPlan>(VPBB);
 
   // Scan the body of the loop in a topological order to visit each basic block
   // after having visited its predecessor basic blocks.




More information about the llvm-commits mailing list