LLVM
8.0.1
|
#include "llvm/Transforms/Scalar/LoopSink.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/AliasSetTracker.h"
#include "llvm/Analysis/BasicAliasAnalysis.h"
#include "llvm/Analysis/BlockFrequencyInfo.h"
#include "llvm/Analysis/Loads.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/LoopPass.h"
#include "llvm/Analysis/ScalarEvolution.h"
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Metadata.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Scalar/LoopPassManager.h"
#include "llvm/Transforms/Utils/LoopUtils.h"
Go to the source code of this file.
Macros | |
#define | DEBUG_TYPE "loopsink" |
Functions | |
STATISTIC (NumLoopSunk, "Number of instructions sunk into loop") | |
STATISTIC (NumLoopSunkCloned, "Number of cloned instructions sunk into loop") | |
static BlockFrequency | adjustedSumFreq (SmallPtrSetImpl< BasicBlock *> &BBs, BlockFrequencyInfo &BFI) |
Return adjusted total frequency of BBs . More... | |
static SmallPtrSet< BasicBlock *, 2 > | findBBsToSinkInto (const Loop &L, const SmallPtrSetImpl< BasicBlock *> &UseBBs, const SmallVectorImpl< BasicBlock *> &ColdLoopBBs, DominatorTree &DT, BlockFrequencyInfo &BFI) |
Return a set of basic blocks to insert sinked instructions. More... | |
static bool | sinkInstruction (Loop &L, Instruction &I, const SmallVectorImpl< BasicBlock *> &ColdLoopBBs, const SmallDenseMap< BasicBlock *, int, 16 > &LoopBlockNumber, LoopInfo &LI, DominatorTree &DT, BlockFrequencyInfo &BFI) |
static bool | sinkLoopInvariantInstructions (Loop &L, AAResults &AA, LoopInfo &LI, DominatorTree &DT, BlockFrequencyInfo &BFI, ScalarEvolution *SE) |
Sinks instructions from loop's preheader to the loop body if the sum frequency of inserted copy is smaller than preheader's frequency. More... | |
INITIALIZE_PASS_BEGIN (LegacyLoopSinkPass, "loop-sink", "Loop Sink", false, false) Pass *llvm | |
Variables | |
static cl::opt< unsigned > | SinkFrequencyPercentThreshold ("sink-freq-percent-threshold", cl::Hidden, cl::init(90), cl::desc("Do not sink instructions that require cloning unless they " "execute less than this percent of the time.")) |
static cl::opt< unsigned > | MaxNumberOfUseBBsForSinking ("max-uses-for-sinking", cl::Hidden, cl::init(30), cl::desc("Do not sink instructions that have too many uses.")) |
#define DEBUG_TYPE "loopsink" |
Definition at line 56 of file LoopSink.cpp.
|
static |
Return adjusted total frequency of BBs
.
Definition at line 83 of file LoopSink.cpp.
References B, llvm::BlockFrequencyInfo::getBlockFreq(), SinkFrequencyPercentThreshold, and T.
Referenced by findBBsToSinkInto().
|
static |
Return a set of basic blocks to insert sinked instructions.
The returned set of basic blocks (BBsToSinkInto) should satisfy:
L
UseBBs
, there is at least one BB in BBsToSinkInto that domintates the UseBBThe purpose of the function is to find the optimal sinking points to minimize execution cost, which is defined as "sum of frequency of BBsToSinkInto". As a result, the returned BBsToSinkInto needs to have minimum total frequency. Additionally, if the total frequency of BBsToSinkInto exceeds preheader frequency, the optimal solution is not sinking (return empty set).
ColdLoopBBs
is used to help find the optimal sinking locations. It stores a list of BBs that is:
L
The complexity of the function is O(UseBBs.size() * ColdLoopBBs.size()). To avoid expensive computation, we cap the maximum UseBBs.size() in its caller.
Definition at line 121 of file LoopSink.cpp.
References adjustedSumFreq(), llvm::SmallPtrSetImpl< PtrType >::begin(), llvm::SmallPtrSetImplBase::clear(), llvm::DominatorTree::dominates(), llvm::SmallPtrSetImpl< PtrType >::end(), llvm::BlockFrequencyInfo::getBlockFreq(), llvm::LoopBase< BlockT, LoopT >::getLoopPreheader(), llvm::SmallPtrSetImpl< PtrType >::insert(), and llvm::SmallPtrSetImplBase::size().
Referenced by sinkInstruction().
Definition at line 383 of file LoopSink.cpp.
|
static |
Definition at line 175 of file LoopSink.cpp.
References assert(), B, llvm::SmallVectorTemplateCommon< T >::begin(), llvm::SmallPtrSetImpl< PtrType >::begin(), llvm::Instruction::clone(), llvm::LoopBase< BlockT, LoopT >::contains(), llvm::DenseMapBase< SmallDenseMap< KeyT, ValueT, InlineBuckets, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::count(), llvm::dbgs(), llvm::SmallPtrSetImplBase::empty(), llvm::SmallPtrSetImpl< PtrType >::end(), llvm::DenseMapBase< SmallDenseMap< KeyT, ValueT, InlineBuckets, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::find(), findBBsToSinkInto(), llvm::LoopInfoBase< BlockT, LoopT >::getLoopFor(), llvm::Value::getName(), llvm::Instruction::getParent(), llvm::Use::getUser(), llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::SmallVectorImpl< T >::insert(), LLVM_DEBUG, llvm::makeArrayRef(), MaxNumberOfUseBBsForSinking, llvm::Instruction::moveBefore(), N, llvm::replaceDominatedUsesWith(), llvm::Use::set(), llvm::Value::setName(), llvm::SmallPtrSetImplBase::size(), llvm::sort(), llvm::Value::use_begin(), llvm::Value::use_end(), and llvm::Value::uses().
Referenced by sinkLoopInvariantInstructions().
|
static |
Sinks instructions from loop's preheader to the loop body if the sum frequency of inserted copy is smaller than preheader's frequency.
Definition at line 255 of file LoopSink.cpp.
References llvm::AliasSetTracker::add(), llvm::all_of(), assert(), B, llvm::SmallVectorTemplateCommon< T >::begin(), llvm::LoopBase< BlockT, LoopT >::blocks(), llvm::canSinkOrHoistInst(), E, llvm::SmallVectorTemplateCommon< T >::end(), llvm::ScalarEvolution::forgetLoopDispositions(), llvm::BlockFrequencyInfo::getBlockFreq(), llvm::LoopBase< BlockT, LoopT >::getLoopPreheader(), llvm::BasicBlock::getParent(), llvm::Loop::hasLoopInvariantOperands(), llvm::Function::hasProfileData(), I, llvm::SmallVectorTemplateBase< T >::push_back(), llvm::BasicBlock::rbegin(), llvm::BasicBlock::rend(), and sinkInstruction().
Referenced by llvm::LoopSinkPass::run().
STATISTIC | ( | NumLoopSunk | , |
"Number of instructions sunk into loop" | |||
) |
STATISTIC | ( | NumLoopSunkCloned | , |
"Number of cloned instructions sunk into loop" | |||
) |
|
static |
Referenced by sinkInstruction().
|
static |
Referenced by adjustedSumFreq().