|
LLVM
4.0.0
|
#include "llvm/Transforms/Scalar/LoopIdiomRecognize.h"#include "llvm/ADT/MapVector.h"#include "llvm/ADT/SetVector.h"#include "llvm/ADT/Statistic.h"#include "llvm/Analysis/AliasAnalysis.h"#include "llvm/Analysis/BasicAliasAnalysis.h"#include "llvm/Analysis/GlobalsModRef.h"#include "llvm/Analysis/LoopAccessAnalysis.h"#include "llvm/Analysis/LoopPass.h"#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"#include "llvm/Analysis/ScalarEvolutionExpander.h"#include "llvm/Analysis/ScalarEvolutionExpressions.h"#include "llvm/Analysis/TargetLibraryInfo.h"#include "llvm/Analysis/TargetTransformInfo.h"#include "llvm/Analysis/ValueTracking.h"#include "llvm/IR/DataLayout.h"#include "llvm/IR/Dominators.h"#include "llvm/IR/IRBuilder.h"#include "llvm/IR/IntrinsicInst.h"#include "llvm/IR/Module.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/BuildLibCalls.h"#include "llvm/Transforms/Utils/Local.h"#include "llvm/Transforms/Utils/LoopUtils.h"Go to the source code of this file.
Macros | |
| #define | DEBUG_TYPE "loop-idiom" |
Functions | |
| STATISTIC (NumMemSet,"Number of memset's formed from loop stores") | |
| STATISTIC (NumMemCpy,"Number of memcpy's formed from loop load+stores") | |
| INITIALIZE_PASS_BEGIN (LoopIdiomRecognizeLegacyPass,"loop-idiom","Recognize loop idioms", false, false) INITIALIZE_PASS_END(LoopIdiomRecognizeLegacyPass | |
| static void | deleteDeadInstruction (Instruction *I) |
| static unsigned | getStoreSizeInBytes (StoreInst *SI, const DataLayout *DL) |
| static APInt | getStoreStride (const SCEVAddRecExpr *StoreEv) |
| static Constant * | getMemSetPatternValue (Value *V, const DataLayout *DL) |
| getMemSetPatternValue - If a strided store of the specified value is safe to turn into a memset_pattern16, return a ConstantArray of 16 bytes that should be passed in. More... | |
| static bool | mayLoopAccessLocation (Value *Ptr, ModRefInfo Access, Loop *L, const SCEV *BECount, unsigned StoreSize, AliasAnalysis &AA, SmallPtrSetImpl< Instruction * > &IgnoredStores) |
| mayLoopAccessLocation - Return true if the specified loop might access the specified pointer location, which is a loop-strided access. More... | |
| static const SCEV * | getStartForNegStride (const SCEV *Start, const SCEV *BECount, Type *IntPtr, unsigned StoreSize, ScalarEvolution *SE) |
| static Value * | matchCondition (BranchInst *BI, BasicBlock *LoopEntry) |
| Check if the given conditional branch is based on the comparison between a variable and zero, and if the variable is non-zero, the control yields to the loop entry. More... | |
| static bool | detectPopcountIdiom (Loop *CurLoop, BasicBlock *PreCondBB, Instruction *&CntInst, PHINode *&CntPhi, Value *&Var) |
| Return true iff the idiom is detected in the loop. More... | |
| static CallInst * | createPopcntIntrinsic (IRBuilder<> &IRBuilder, Value *Val, const DebugLoc &DL) |
Variables | |
| static cl::opt< bool > | UseLIRCodeSizeHeurs ("use-lir-code-size-heurs", cl::desc("Use loop idiom recognition code size heuristics when compiling""with -Os/-Oz"), cl::init(true), cl::Hidden) |
| loop | idiom |
| loop Recognize loop | idioms |
| loop Recognize loop | false |
| #define DEBUG_TYPE "loop-idiom" |
Definition at line 69 of file LoopIdiomRecognize.cpp.
|
static |
Definition at line 1197 of file LoopIdiomRecognize.cpp.
References llvm::IRBuilder< T, Inserter >::CreateCall(), llvm::Intrinsic::getDeclaration(), llvm::IRBuilderBase::GetInsertBlock(), llvm::BasicBlock::getParent(), llvm::GlobalValue::getParent(), llvm::Value::getType(), and llvm::Instruction::setDebugLoc().
|
static |
Definition at line 212 of file LoopIdiomRecognize.cpp.
References llvm::Instruction::eraseFromParent(), llvm::UndefValue::get(), llvm::Value::getType(), and llvm::Value::replaceAllUsesWith().
|
static |
Return true iff the idiom is detected in the loop.
Additionally: 1) CntInst is set to the instruction counting the population bit. 2) CntPhi is set to the corresponding phi node. 3) Var is set to the value whose population bits are being counted.
The core idiom we are trying to detect is:
Definition at line 1034 of file LoopIdiomRecognize.cpp.
References llvm::MCID::Add, llvm::APIntOps::And(), llvm::LoopBase< N, M >::block_begin(), llvm::dyn_cast(), llvm::BasicBlock::end(), llvm::BasicBlock::getFirstNonPHI(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::LoopBase< N, M >::getLoopPreheader(), llvm::Instruction::getOpcode(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::BasicBlock::getTerminator(), llvm::ConstantInt::isOne(), matchCondition(), T, and llvm::Value::users().
|
static |
getMemSetPatternValue - If a strided store of the specified value is safe to turn into a memset_pattern16, return a ConstantArray of 16 bytes that should be passed in.
Otherwise, return null.
Note that we don't ever attempt to use memset_pattern8 or 4, because these just replicate their input array and then pass on to memset_pattern16.
Definition at line 307 of file LoopIdiomRecognize.cpp.
References C, llvm::dyn_cast(), llvm::ArrayType::get(), llvm::ConstantArray::get(), llvm::Value::getType(), llvm::DataLayout::getTypeSizeInBits(), and llvm::DataLayout::isBigEndian().
|
static |
Definition at line 739 of file LoopIdiomRecognize.cpp.
References llvm::SCEV::FlagNUW, llvm::ScalarEvolution::getConstant(), llvm::ScalarEvolution::getMinusSCEV(), llvm::ScalarEvolution::getMulExpr(), and llvm::ScalarEvolution::getTruncateOrZeroExtend().
|
static |
Definition at line 289 of file LoopIdiomRecognize.cpp.
References assert(), llvm::Value::getType(), llvm::DataLayout::getTypeSizeInBits(), and llvm::StoreInst::getValueOperand().
|
static |
Definition at line 296 of file LoopIdiomRecognize.cpp.
References llvm::SCEVConstant::getAPInt(), and llvm::SCEVNAryExpr::getOperand().
| INITIALIZE_PASS_BEGIN | ( | LoopIdiomRecognizeLegacyPass | , |
| "loop-idiom" | , | ||
| "Recognize loop idioms" | , | ||
| false | , | ||
| false | |||
| ) |
|
static |
Check if the given conditional branch is based on the comparison between a variable and zero, and if the variable is non-zero, the control yields to the loop entry.
If the branch matches the behavior, the variable involved in the comparison is returned. This function will be called to see if the precondition and postcondition of the loop are in desirable form.
Definition at line 990 of file LoopIdiomRecognize.cpp.
References llvm::dyn_cast(), llvm::BranchInst::getCondition(), llvm::User::getOperand(), llvm::CmpInst::getPredicate(), llvm::BranchInst::getSuccessor(), llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, llvm::BranchInst::isConditional(), and llvm::ConstantInt::isZero().
Referenced by detectPopcountIdiom().
|
static |
mayLoopAccessLocation - Return true if the specified loop might access the specified pointer location, which is a loop-strided access.
The 'Access' argument specifies what the verboten forms of access are (read or write).
Definition at line 706 of file LoopIdiomRecognize.cpp.
References llvm::LoopBase< N, M >::block_begin(), llvm::LoopBase< N, M >::block_end(), llvm::SmallPtrSetImpl< PtrType >::count(), E, llvm::AAResults::getModRefInfo(), and llvm::MemoryLocation::UnknownSize.
| STATISTIC | ( | NumMemSet | , |
| "Number of memset's formed from loop stores" | |||
| ) |
| STATISTIC | ( | NumMemCpy | , |
| "Number of memcpy's formed from loop load+stores" | |||
| ) |
| loop Recognize loop false |
Definition at line 207 of file LoopIdiomRecognize.cpp.
| loop idiom |
Definition at line 207 of file LoopIdiomRecognize.cpp.
| loop Recognize loop idioms |
Definition at line 207 of file LoopIdiomRecognize.cpp.
1.8.6