From: Florian Hahn Date: Thu, 11 Oct 2018 09:46:25 +0000 (+0000) Subject: [LV] Use SmallVector instead of DenseMap in calculateRegisterUsage (NFC). X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=18e07bb822959b5bf3fbbeae02eb76d219d4d5a5;p=platform%2Fupstream%2Fllvm.git [LV] Use SmallVector instead of DenseMap in calculateRegisterUsage (NFC). We assign indices sequentially for seen instructions, so we can just use a vector and push back the seen instructions. No need for using a DenseMap. Reviewers: hsaito, rengolin, nadav, dcaballe Reviewed By: rengolin Differential Revision: https://reviews.llvm.org/D53089 llvm-svn: 344233 --- diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index cad1711b..7ebe8d1 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -4882,7 +4882,7 @@ LoopVectorizationCostModel::calculateRegisterUsage(ArrayRef VFs) { using IntervalMap = DenseMap; // Maps instruction to its index. - DenseMap IdxToInstr; + SmallVector IdxToInstr; // Marks the end of each interval. IntervalMap EndPoint; // Saves the list of instruction indices that are used in the loop. @@ -4891,10 +4891,9 @@ LoopVectorizationCostModel::calculateRegisterUsage(ArrayRef VFs) { // defined outside the loop, such as arguments and constants. SmallPtrSet LoopInvariants; - unsigned Index = 0; for (BasicBlock *BB : make_range(DFS.beginRPO(), DFS.endRPO())) { for (Instruction &I : BB->instructionsWithoutDebug()) { - IdxToInstr[Index++] = &I; + IdxToInstr.push_back(&I); // Save the end location of each USE. for (Value *U : I.operands()) { @@ -4911,7 +4910,7 @@ LoopVectorizationCostModel::calculateRegisterUsage(ArrayRef VFs) { } // Overwrite previous end points. - EndPoint[Instr] = Index; + EndPoint[Instr] = IdxToInstr.size(); Ends.insert(Instr); } } @@ -4948,7 +4947,7 @@ LoopVectorizationCostModel::calculateRegisterUsage(ArrayRef VFs) { return std::max(1, VF * TypeSize / WidestRegister); }; - for (unsigned int i = 0; i < Index; ++i) { + for (unsigned int i = 0, s = IdxToInstr.size(); i < s; ++i) { Instruction *I = IdxToInstr[i]; // Remove all of the instructions that end at this location.