|
LLVM
4.0.0
|
#include "llvm/Transforms/Scalar/LoopUnrollPass.h"#include "llvm/ADT/SetVector.h"#include "llvm/Analysis/AssumptionCache.h"#include "llvm/Analysis/CodeMetrics.h"#include "llvm/Analysis/GlobalsModRef.h"#include "llvm/Analysis/InstructionSimplify.h"#include "llvm/Analysis/LoopPass.h"#include "llvm/Analysis/LoopUnrollAnalyzer.h"#include "llvm/Analysis/OptimizationDiagnosticInfo.h"#include "llvm/Analysis/ScalarEvolution.h"#include "llvm/Analysis/ScalarEvolutionExpressions.h"#include "llvm/IR/DataLayout.h"#include "llvm/IR/Dominators.h"#include "llvm/IR/InstVisitor.h"#include "llvm/IR/IntrinsicInst.h"#include "llvm/IR/Metadata.h"#include "llvm/Support/CommandLine.h"#include "llvm/Support/Debug.h"#include "llvm/Support/raw_ostream.h"#include "llvm/Transforms/Scalar.h"#include "llvm/Transforms/Scalar/LoopPassManager.h"#include "llvm/Transforms/Utils/LoopUtils.h"#include "llvm/Transforms/Utils/UnrollLoop.h"#include <climits>#include <utility>Go to the source code of this file.
Macros | |
| #define | DEBUG_TYPE "loop-unroll" |
Variables | |
| static cl::opt< unsigned > | UnrollThreshold ("unroll-threshold", cl::Hidden, cl::desc("The baseline cost threshold for loop unrolling")) |
| static cl::opt< unsigned > | UnrollMaxPercentThresholdBoost ("unroll-max-percent-threshold-boost", cl::init(400), cl::Hidden, cl::desc("The maximum 'boost' (represented as a percentage >= 100) applied ""to the threshold when aggressively unrolling a loop due to the ""dynamic cost savings. If completely unrolling a loop will reduce ""the total runtime from X to Y, we boost the loop unroll ""threshold to DefaultThreshold*std::min(MaxPercentThresholdBoost, ""X/Y). This limit avoids excessive code bloat.")) |
| static cl::opt< unsigned > | UnrollMaxIterationsCountToAnalyze ("unroll-max-iteration-count-to-analyze", cl::init(10), cl::Hidden, cl::desc("Don't allow loop unrolling to simulate more than this number of""iterations when checking full unroll profitability")) |
| static cl::opt< unsigned > | UnrollCount ("unroll-count", cl::Hidden, cl::desc("Use this unroll count for all loops including those with ""unroll_count pragma values, for testing purposes")) |
| static cl::opt< unsigned > | UnrollMaxCount ("unroll-max-count", cl::Hidden, cl::desc("Set the max unroll count for partial and runtime unrolling, for""testing purposes")) |
| static cl::opt< unsigned > | UnrollFullMaxCount ("unroll-full-max-count", cl::Hidden, cl::desc("Set the max unroll count for full unrolling, for testing purposes")) |
| static cl::opt< bool > | UnrollAllowPartial ("unroll-allow-partial", cl::Hidden, cl::desc("Allows loops to be partially unrolled until ""-unroll-threshold loop size is reached.")) |
| static cl::opt< bool > | UnrollAllowRemainder ("unroll-allow-remainder", cl::Hidden, cl::desc("Allow generation of a loop remainder (extra iterations) ""when unrolling a loop.")) |
| static cl::opt< bool > | UnrollRuntime ("unroll-runtime", cl::ZeroOrMore, cl::Hidden, cl::desc("Unroll loops with run-time trip counts")) |
| static cl::opt< unsigned > | UnrollMaxUpperBound ("unroll-max-upperbound", cl::init(8), cl::Hidden, cl::desc("The max of trip count upper bound that is considered in unrolling")) |
| static cl::opt< unsigned > | PragmaUnrollThreshold ("pragma-unroll-threshold", cl::init(16 *1024), cl::Hidden, cl::desc("Unrolled size limit for loops with an unroll(full) or ""unroll_count pragma.")) |
| static cl::opt< unsigned > | FlatLoopTripCountThreshold ("flat-loop-tripcount-threshold", cl::init(5), cl::Hidden, cl::desc("If the runtime tripcount for the loop is lower than the ""threshold, the loop is considered as flat and will be less ""aggressively unrolled.")) |
| static cl::opt< bool > | UnrollAllowPeeling ("unroll-allow-peeling", cl::Hidden, cl::desc("Allows loops to be peeled when the dynamic ""trip count is known to be low.")) |
| static const unsigned | NoThreshold = UINT_MAX |
| A magic value for use with the Threshold parameter to indicate that the loop unroll should be performed regardless of how much code expansion would result. More... | |
| #define DEBUG_TYPE "loop-unroll" |
Definition at line 43 of file LoopUnrollPass.cpp.
Referenced by computeUnrollCount().
|
static |
Figure out if the loop is worth full unrolling.
Complete loop unrolling can make some loads constant, and we need to know if that would expose any further optimization opportunities. This routine estimates this optimization. It computes cost of unrolled loop (UnrolledCost) and dynamic cost of the original loop (RolledDynamicCost). By dynamic cost we mean that we won't count costs of blocks that are known not to be executed (i.e. if we have a branch in the loop and we know that at the given iteration its condition would be resolved to true, we won't add up the cost of the 'false'-block).
Definition at line 253 of file LoopUnrollPass.cpp.
References llvm::SmallVectorImpl< T >::append(), assert(), llvm::SmallVectorTemplateCommon< T >::begin(), C, llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::clear(), llvm::SetVector< T, SmallVector< T, N >, SmallDenseSet< T, N > >::clear(), llvm::SmallVectorImpl< T >::clear(), llvm::LoopBase< N, M >::contains(), llvm::dbgs(), DEBUG, llvm::Value::dump(), llvm::dyn_cast(), llvm::SmallVectorBase::empty(), llvm::SetVector< T, SmallVector< T, N >, SmallDenseSet< T, N > >::empty(), llvm::LoopBase< N, M >::empty(), llvm::SmallVectorTemplateCommon< T >::end(), llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, ValueInfoT, detail::DenseSetPair< ValueT > >, ValueInfoT >::end(), llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, ValueInfoT, detail::DenseSetPair< ValueT > >, ValueInfoT >::find(), llvm::LoopBase< N, M >::getHeader(), llvm::LoopBase< N, M >::getLoopLatch(), llvm::LoopBase< N, M >::getLoopPreheader(), llvm::TargetTransformInfo::getUserCost(), I, llvm::SetVector< T, SmallVector< T, N >, SmallDenseSet< T, N > >::insert(), llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, ValueInfoT, detail::DenseSetPair< ValueT > >, ValueInfoT >::insert(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::insert(), llvm::Loop::isLCSSAForm(), llvm::Loop::isLoopSimplifyForm(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::lookup(), llvm::None, llvm::User::operands(), llvm::SetVector< T, SmallVector< T, N >, SmallDenseSet< T, N > >::pop_back_val(), llvm::SmallVectorImpl< T >::pop_back_val(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), SI, llvm::SetVector< T, SmallVector< T, N >, SmallDenseSet< T, N > >::size(), llvm::successors(), UnrollMaxIterationsCountToAnalyze, and llvm::InstVisitor< SubClass, RetTy >::visit().
Referenced by computeUnrollCount().
|
static |
ApproximateLoopSize - Approximate the size of the loop.
Definition at line 550 of file LoopUnrollPass.cpp.
References llvm::CodeMetrics::analyzeBasicBlock(), llvm::LoopBase< N, M >::blocks(), llvm::CodeMetrics::collectEphemeralValues(), llvm::CodeMetrics::convergent, Metrics, llvm::CodeMetrics::notDuplicatable, llvm::CodeMetrics::NumInlineCandidates, and llvm::CodeMetrics::NumInsts.
Referenced by tryToUnrollLoop().
|
static |
Definition at line 686 of file LoopUnrollPass.cpp.
References llvm::TargetTransformInfo::UnrollingPreferences::AllowExpensiveTripCount, llvm::TargetTransformInfo::UnrollingPreferences::AllowRemainder, analyzeLoopUnrollCost(), assert(), llvm::TargetTransformInfo::UnrollingPreferences::BEInsns, llvm::computePeelCount(), llvm::TargetTransformInfo::UnrollingPreferences::Count, llvm::dbgs(), DEBUG, DEBUG_TYPE, llvm::TargetTransformInfo::UnrollingPreferences::DefaultUnrollRuntimeCount, llvm::OptimizationRemarkEmitter::emit(), FlatLoopTripCountThreshold, llvm::TargetTransformInfo::UnrollingPreferences::Force, llvm::TargetTransformInfo::UnrollingPreferences::FullUnrollMaxCount, getFullUnrollBoostingFactor(), llvm::LoopBase< N, M >::getHeader(), llvm::getLoopEstimatedTripCount(), llvm::Loop::getStartLoc(), getUnrolledLoopSize(), HasRuntimeUnrollDisablePragma(), HasUnrollEnablePragma(), HasUnrollFullPragma(), llvm::TargetTransformInfo::UnrollingPreferences::MaxCount, llvm::TargetTransformInfo::UnrollingPreferences::MaxPercentThresholdBoost, NoThreshold, llvm::TargetTransformInfo::UnrollingPreferences::Partial, llvm::TargetTransformInfo::UnrollingPreferences::PartialThreshold, llvm::TargetTransformInfo::UnrollingPreferences::PeelCount, PragmaUnrollThreshold, llvm::TargetTransformInfo::UnrollingPreferences::Runtime, llvm::TargetTransformInfo::UnrollingPreferences::Threshold, UnrollCount, UnrollCountPragmaValue(), and llvm::TargetTransformInfo::UnrollingPreferences::UpperBound.
Referenced by tryToUnrollLoop().
|
static |
Gather the various unrolling parameters based on the defaults, compiler flags, TTI overrides and user specified parameters.
Definition at line 120 of file LoopUnrollPass.cpp.
References llvm::TargetTransformInfo::UnrollingPreferences::AllowExpensiveTripCount, llvm::TargetTransformInfo::UnrollingPreferences::AllowPeeling, llvm::TargetTransformInfo::UnrollingPreferences::AllowRemainder, llvm::TargetTransformInfo::UnrollingPreferences::BEInsns, llvm::TargetTransformInfo::UnrollingPreferences::Count, llvm::TargetTransformInfo::UnrollingPreferences::DefaultUnrollRuntimeCount, llvm::TargetTransformInfo::UnrollingPreferences::Force, llvm::TargetTransformInfo::UnrollingPreferences::FullUnrollMaxCount, llvm::LoopBase< N, M >::getHeader(), llvm::TargetTransformInfo::getUnrollingPreferences(), llvm::Optional< T >::hasValue(), if(), llvm::TargetTransformInfo::UnrollingPreferences::MaxCount, llvm::TargetTransformInfo::UnrollingPreferences::MaxPercentThresholdBoost, llvm::TargetTransformInfo::UnrollingPreferences::OptSizeThreshold, llvm::TargetTransformInfo::UnrollingPreferences::Partial, llvm::TargetTransformInfo::UnrollingPreferences::PartialOptSizeThreshold, llvm::TargetTransformInfo::UnrollingPreferences::PartialThreshold, llvm::TargetTransformInfo::UnrollingPreferences::PeelCount, llvm::TargetTransformInfo::UnrollingPreferences::Runtime, llvm::TargetTransformInfo::UnrollingPreferences::Threshold, UnrollAllowPartial, UnrollAllowPeeling, UnrollAllowRemainder, UnrollFullMaxCount, UnrollMaxCount, UnrollMaxPercentThresholdBoost, UnrollMaxUpperBound, UnrollRuntime, UnrollThreshold, and llvm::TargetTransformInfo::UnrollingPreferences::UpperBound.
Referenced by tryToUnrollLoop().
|
static |
Definition at line 664 of file LoopUnrollPass.cpp.
References fuzzer::min().
Referenced by computeUnrollCount().
|
static |
Definition at line 677 of file LoopUnrollPass.cpp.
References assert(), llvm::TargetTransformInfo::UnrollingPreferences::BEInsns, and llvm::TargetTransformInfo::UnrollingPreferences::Count.
Referenced by computeUnrollCount().
Definition at line 580 of file LoopUnrollPass.cpp.
References llvm::Loop::getLoopID(), and llvm::GetUnrollMetadata().
Referenced by HasRuntimeUnrollDisablePragma(), HasUnrollDisablePragma(), HasUnrollEnablePragma(), HasUnrollFullPragma(), and UnrollCountPragmaValue().
Definition at line 603 of file LoopUnrollPass.cpp.
References GetUnrollMetadataForLoop().
Referenced by computeUnrollCount().
Definition at line 598 of file LoopUnrollPass.cpp.
References GetUnrollMetadataForLoop().
Referenced by tryToUnrollLoop().
Definition at line 593 of file LoopUnrollPass.cpp.
References GetUnrollMetadataForLoop().
Referenced by computeUnrollCount().
Definition at line 587 of file LoopUnrollPass.cpp.
References GetUnrollMetadataForLoop().
Referenced by computeUnrollCount().
|
static |
Definition at line 626 of file LoopUnrollPass.cpp.
References Context, llvm::dyn_cast(), llvm::MDString::get(), llvm::MDNode::get(), llvm::LoopBase< N, M >::getHeader(), llvm::Loop::getLoopID(), llvm::MDNode::getNumOperands(), llvm::MDNode::getOperand(), llvm::MDString::getString(), i, llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::MDNode::replaceOperandWith(), llvm::Loop::setLoopID(), and llvm::StringRef::startswith().
Referenced by tryToUnrollLoop().
|
static |
Definition at line 914 of file LoopUnrollPass.cpp.
References llvm::TargetTransformInfo::UnrollingPreferences::AllowExpensiveTripCount, llvm::TargetTransformInfo::UnrollingPreferences::AllowRemainder, ApproximateLoopSize(), llvm::TargetTransformInfo::UnrollingPreferences::BEInsns, computeUnrollCount(), llvm::MCID::Convergent, llvm::TargetTransformInfo::UnrollingPreferences::Count, llvm::dbgs(), DEBUG, llvm::TargetTransformInfo::UnrollingPreferences::Force, gatherUnrollingPreferences(), llvm::LoopBase< N, M >::getExitingBlock(), llvm::LoopBase< N, M >::getHeader(), llvm::LoopBase< N, M >::getLoopLatch(), llvm::ScalarEvolution::getSmallConstantMaxTripCount(), llvm::ScalarEvolution::getSmallConstantTripCount(), llvm::ScalarEvolution::getSmallConstantTripMultiple(), HasUnrollDisablePragma(), llvm::ScalarEvolution::isBackedgeTakenCountMaxOrZero(), llvm::LoopBase< N, M >::isLoopExiting(), llvm::Loop::isLoopSimplifyForm(), llvm::TargetTransformInfo::UnrollingPreferences::Partial, llvm::TargetTransformInfo::UnrollingPreferences::PartialThreshold, llvm::TargetTransformInfo::UnrollingPreferences::PeelCount, llvm::TargetTransformInfo::UnrollingPreferences::Runtime, SetLoopAlreadyUnrolled(), llvm::TargetTransformInfo::UnrollingPreferences::Threshold, llvm::UnrollLoop(), UnrollMaxUpperBound, and llvm::TargetTransformInfo::UnrollingPreferences::UpperBound.
Referenced by llvm::LoopUnrollPass::run().
Definition at line 609 of file LoopUnrollPass.cpp.
References assert(), llvm::MDNode::getNumOperands(), llvm::MDNode::getOperand(), and GetUnrollMetadataForLoop().
Referenced by computeUnrollCount().
|
static |
Referenced by computeUnrollCount().
A magic value for use with the Threshold parameter to indicate that the loop unroll should be performed regardless of how much code expansion would result.
Definition at line 116 of file LoopUnrollPass.cpp.
Referenced by computeUnrollCount().
|
static |
Referenced by computeUnrollCount().
|
static |
Referenced by gatherUnrollingPreferences().
|
static |
Referenced by gatherUnrollingPreferences().
|
static |
Referenced by gatherUnrollingPreferences().
|
static |
Referenced by computeUnrollCount().
|
static |
Referenced by gatherUnrollingPreferences().
|
static |
Referenced by gatherUnrollingPreferences().
|
static |
Referenced by analyzeLoopUnrollCost().
|
static |
Referenced by gatherUnrollingPreferences().
|
static |
Referenced by gatherUnrollingPreferences(), and tryToUnrollLoop().
|
static |
Referenced by gatherUnrollingPreferences().
|
static |
Referenced by gatherUnrollingPreferences().
1.8.6