LLVM  3.7.0
Macros | Functions | Variables
LoopUnrollPass.cpp File Reference
#include "llvm/Transforms/Scalar.h"
#include "llvm/ADT/SetVector.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/CodeMetrics.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/ScalarEvolutionExpressions.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DiagnosticInfo.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/Utils/UnrollLoop.h"
#include <climits>
Include dependency graph for LoopUnrollPass.cpp:

Go to the source code of this file.

Macros

#define DEBUG_TYPE   "loop-unroll"
 

Functions

Optional< EstimatedUnrollCost > analyzeLoopUnrollCost (const Loop *L, unsigned TripCount, ScalarEvolution &SE, const TargetTransformInfo &TTI, unsigned MaxUnrolledLoopSize)
 Figure out if the loop is worth full unrolling. More...
 
static unsigned ApproximateLoopSize (const Loop *L, unsigned &NumCalls, bool &NotDuplicatable, const TargetTransformInfo &TTI, AssumptionCache *AC)
 ApproximateLoopSize - Approximate the size of the loop. More...
 
static MDNodeGetUnrollMetadataForLoop (const Loop *L, StringRef Name)
 
static bool HasUnrollFullPragma (const Loop *L)
 
static bool HasUnrollDisablePragma (const Loop *L)
 
static bool HasRuntimeUnrollDisablePragma (const Loop *L)
 
static unsigned UnrollCountPragmaValue (const Loop *L)
 
static void SetLoopAlreadyUnrolled (Loop *L)
 

Variables

static cl::opt< unsignedUnrollThreshold ("unroll-threshold", cl::init(150), cl::Hidden, cl::desc("The baseline cost threshold for loop unrolling"))
 
static cl::opt< unsignedUnrollPercentDynamicCostSavedThreshold ("unroll-percent-dynamic-cost-saved-threshold", cl::init(20), cl::Hidden, cl::desc("The percentage of estimated dynamic cost which must be saved by ""unrolling to allow unrolling up to the max threshold."))
 
static cl::opt< unsignedUnrollDynamicCostSavingsDiscount ("unroll-dynamic-cost-savings-discount", cl::init(2000), cl::Hidden, cl::desc("This is the amount discounted from the total unroll cost when ""the unrolled form has a high dynamic cost savings (triggered by ""the '-unroll-perecent-dynamic-cost-saved-threshold' flag)."))
 
static cl::opt< unsignedUnrollMaxIterationsCountToAnalyze ("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"))
 
static cl::opt< unsignedUnrollCount ("unroll-count", cl::init(0), cl::Hidden, cl::desc("Use this unroll count for all loops including those with ""unroll_count pragma values, for testing purposes"))
 
static cl::opt< boolUnrollAllowPartial ("unroll-allow-partial", cl::init(false), cl::Hidden, cl::desc("Allows loops to be partially unrolled until ""-unroll-threshold loop size is reached."))
 
static cl::opt< boolUnrollRuntime ("unroll-runtime", cl::ZeroOrMore, cl::init(false), cl::Hidden, cl::desc("Unroll loops with run-time trip counts"))
 
static cl::opt< unsignedPragmaUnrollThreshold ("pragma-unroll-threshold", cl::init(16 *1024), cl::Hidden, cl::desc("Unrolled size limit for loops with an unroll(full) or ""unroll_count pragma."))
 

Macro Definition Documentation

#define DEBUG_TYPE   "loop-unroll"

Definition at line 38 of file LoopUnrollPass.cpp.

Function Documentation

Optional<EstimatedUnrollCost> analyzeLoopUnrollCost ( const Loop L,
unsigned  TripCount,
ScalarEvolution SE,
const TargetTransformInfo TTI,
unsigned  MaxUnrolledLoopSize 
)

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).

Returns
Optional value, holding the RolledDynamicCost and UnrolledCost. If the analysis failed (no benefits expected from the unrolling, or the loop is too big to analyze), the returned value is None.

Definition at line 468 of file LoopUnrollPass.cpp.

References llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::clear(), llvm::SetVector< T, SmallVector< T, N >, SmallSet< T, N > >::clear(), llvm::LoopBase< N, M >::contains(), llvm::LoopBase< N, M >::getHeader(), llvm::TargetTransformInfo::getUserCost(), llvm::SetVector< T, SmallVector< T, N >, SmallSet< T, N > >::insert(), llvm::None, llvm::SetVector< T, SmallVector< T, N >, SmallSet< T, N > >::size(), llvm::successors(), and UnrollMaxIterationsCountToAnalyze.

static unsigned ApproximateLoopSize ( const Loop L,
unsigned NumCalls,
bool NotDuplicatable,
const TargetTransformInfo TTI,
AssumptionCache AC 
)
static
static MDNode* GetUnrollMetadataForLoop ( const Loop L,
StringRef  Name 
)
static
static bool HasRuntimeUnrollDisablePragma ( const Loop L)
static

Definition at line 592 of file LoopUnrollPass.cpp.

References GetUnrollMetadataForLoop().

static bool HasUnrollDisablePragma ( const Loop L)
static

Definition at line 587 of file LoopUnrollPass.cpp.

References GetUnrollMetadataForLoop().

static bool HasUnrollFullPragma ( const Loop L)
static

Definition at line 582 of file LoopUnrollPass.cpp.

References GetUnrollMetadataForLoop().

static void SetLoopAlreadyUnrolled ( Loop L)
static
static unsigned UnrollCountPragmaValue ( const Loop L)
static

Variable Documentation

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<bool> UnrollAllowPartial("unroll-allow-partial", cl::init(false), cl::Hidden, cl::desc("Allows loops to be partially unrolled until ""-unroll-threshold loop size is reached."))
static
cl::opt<unsigned> UnrollCount("unroll-count", cl::init(0), 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> UnrollDynamicCostSavingsDiscount("unroll-dynamic-cost-savings-discount", cl::init(2000), cl::Hidden, cl::desc("This is the amount discounted from the total unroll cost when ""the unrolled form has a high dynamic cost savings (triggered by ""the '-unroll-perecent-dynamic-cost-saved-threshold' flag)."))
static
cl::opt<unsigned> UnrollMaxIterationsCountToAnalyze("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"))
static

Referenced by analyzeLoopUnrollCost().

cl::opt<unsigned> UnrollPercentDynamicCostSavedThreshold("unroll-percent-dynamic-cost-saved-threshold", cl::init(20), cl::Hidden, cl::desc("The percentage of estimated dynamic cost which must be saved by ""unrolling to allow unrolling up to the max threshold."))
static
cl::opt<bool> UnrollRuntime("unroll-runtime", cl::ZeroOrMore, cl::init(false), cl::Hidden, cl::desc("Unroll loops with run-time trip counts"))
static
cl::opt<unsigned> UnrollThreshold("unroll-threshold", cl::init(150), cl::Hidden, cl::desc("The baseline cost threshold for loop unrolling"))
static