X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FTransforms%2FScalar%2FLoopUnrollPass.cpp;h=924be16beaaf641df180cd0857451188e08df469;hb=7520a90c75f339e03e3f37a20a9506dd7eb0061d;hp=ccc4a248476e3cea13fa309ac057360883f0566b;hpb=361ac0df6570558bd80b21e257a0a3e465cd20b4;p=oota-llvm.git diff --git a/lib/Transforms/Scalar/LoopUnrollPass.cpp b/lib/Transforms/Scalar/LoopUnrollPass.cpp index ccc4a248476..924be16beaa 100644 --- a/lib/Transforms/Scalar/LoopUnrollPass.cpp +++ b/lib/Transforms/Scalar/LoopUnrollPass.cpp @@ -42,7 +42,7 @@ UnrollThreshold("unroll-threshold", cl::init(150), cl::Hidden, cl::desc("The cut-off point for automatic loop unrolling")); static cl::opt UnrollMaxIterationsCountToAnalyze( - "unroll-max-iteration-count-to-analyze", cl::init(1000), cl::Hidden, + "unroll-max-iteration-count-to-analyze", cl::init(0), cl::Hidden, cl::desc("Don't allow loop unrolling to simulate more than this number of" "iterations when checking full unroll profitability")); @@ -213,9 +213,8 @@ namespace { PartialThreshold = UserThreshold ? CurrentThreshold : UP.PartialThreshold; if (!UserThreshold && - L->getHeader()->getParent()->getAttributes(). - hasAttribute(AttributeSet::FunctionIndex, - Attribute::OptimizeForSize)) { + L->getHeader()->getParent()->hasFnAttribute( + Attribute::OptimizeForSize)) { Threshold = UP.OptSizeThreshold; PartialThreshold = UP.PartialOptSizeThreshold; } @@ -453,10 +452,17 @@ public: // Given a list of loads that could be constant-folded (LoadBaseAddresses), // estimate number of optimized instructions after substituting the concrete - // values for the given Iteration. - // Fill in SimplifiedValues map for future use in DCE-estimation. - unsigned estimateNumberOfSimplifiedInstructions(unsigned Iteration) { - SmallVector Worklist; + // values for the given Iteration. Also track how many instructions become + // dead through this process. + unsigned estimateNumberOfOptimizedInstructions(unsigned Iteration) { + // We keep a set vector for the worklist so that we don't wast space in the + // worklist queuing up the same instruction repeatedly. This can happen due + // to multiple operands being the same instruction or due to the same + // instruction being an operand of lots of things that end up dead or + // simplified. + SmallSetVector Worklist; + + // Clear the simplified values and counts for this iteration. SimplifiedValues.clear(); CountedInstructions.clear(); NumberOfOptimizedInstructions = 0; @@ -468,14 +474,8 @@ public: if (CountedInstructions.insert(LI).second) NumberOfOptimizedInstructions += TTI.getUserCost(LI); - for (User *U : LI->users()) { - Instruction *UI = dyn_cast(U); - if (!UI) - continue; - if (!L->contains(UI)) - continue; - Worklist.push_back(UI); - } + for (User *U : LI->users()) + Worklist.insert(cast(U)); } // And then we try to simplify every user of every instruction from the @@ -483,31 +483,17 @@ public: // its users as well. while (!Worklist.empty()) { Instruction *I = Worklist.pop_back_val(); + if (!L->contains(I)) + continue; if (!visit(I)) continue; - for (User *U : I->users()) { - Instruction *UI = dyn_cast(U); - if (!UI) - continue; - if (!L->contains(UI)) - continue; - Worklist.push_back(UI); - } + for (User *U : I->users()) + Worklist.insert(cast(U)); } - return NumberOfOptimizedInstructions; - } - // Given a list of potentially simplifed instructions, estimate number of - // instructions that would become dead if we do perform the simplification. - unsigned estimateNumberOfDeadInstructions() { - NumberOfOptimizedInstructions = 0; - - // We keep a set vector for the worklist so that we don't wast space in the - // worklist queuing up the same instruction repeatedly. This can happen due - // to multiple operands being the same instruction or due to the same - // instruction being an operand of lots of things that end up dead or - // simplified. - SmallSetVector Worklist; + // Now that we know the potentially simplifed instructions, estimate number + // of instructions that would become dead if we do perform the + // simplification. // The dead instructions are held in a separate set. This is used to // prevent us from re-examining instructions and make sure we only count @@ -577,11 +563,10 @@ approximateNumberOfOptimizedInstructions(const Loop *L, ScalarEvolution &SE, unsigned IterationsNumberForEstimate = std::min(UnrollMaxIterationsCountToAnalyze, TripCount); unsigned NumberOfOptimizedInstructions = 0; - for (unsigned i = 0; i < IterationsNumberForEstimate; ++i) { + for (unsigned i = 0; i < IterationsNumberForEstimate; ++i) NumberOfOptimizedInstructions += - UA.estimateNumberOfSimplifiedInstructions(i); - NumberOfOptimizedInstructions += UA.estimateNumberOfDeadInstructions(); - } + UA.estimateNumberOfOptimizedInstructions(i); + NumberOfOptimizedInstructions *= TripCount / IterationsNumberForEstimate; return NumberOfOptimizedInstructions;