69 #define DEBUG_TYPE "loop-idiom"
71 STATISTIC(NumMemSet,
"Number of memset's formed from loop stores");
72 STATISTIC(NumMemCpy,
"Number of memcpy's formed from loop load+stores");
75 "use-lir-code-size-heurs",
76 cl::desc(
"Use loop idiom recognition code size heuristics when compiling"
82 class LoopIdiomRecognize {
91 bool ApplyCodeSizeHeuristics;
99 : CurLoop(nullptr), AA(AA), DT(DT), LI(LI), SE(SE), TLI(TLI), TTI(TTI),
102 bool runOnLoop(
Loop *
L);
107 StoreListMap StoreRefsForMemset;
108 StoreListMap StoreRefsForMemsetPattern;
109 StoreList StoreRefsForMemcpy;
111 bool HasMemsetPattern;
117 bool runOnCountableLoop();
122 bool isLegalStore(
StoreInst *SI,
bool &ForMemset,
bool &ForMemsetPattern,
128 bool processLoopStridedStore(
Value *DestPtr,
unsigned StoreSize,
129 unsigned StoreAlignment,
Value *StoredVal,
133 bool NegStride,
bool IsLoopMemset =
false);
134 bool processLoopStoreOfLoopLoad(
StoreInst *SI,
const SCEV *BECount);
135 bool avoidLIRForMultiBlockLoop(
bool IsMemset =
false,
136 bool IsLoopMemset =
false);
142 bool runOnNoncountableLoop();
144 bool recognizePopcount();
151 class LoopIdiomRecognizeLegacyPass :
public LoopPass {
154 explicit LoopIdiomRecognizeLegacyPass() :
LoopPass(
ID) {
163 AliasAnalysis *AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
164 DominatorTree *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
165 LoopInfo *LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
166 ScalarEvolution *SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
168 &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI();
170 &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(
174 LoopIdiomRecognize LIR(AA, DT, LI, SE, TLI, TTI, DL);
175 return LIR.runOnLoop(L);
192 const auto *DL = &L.
getHeader()->getModule()->getDataLayout();
194 LoopIdiomRecognize LIR(&AR.
AA, &AR.
DT, &AR.
LI, &AR.
SE, &AR.
TLI, &AR.
TTI, DL);
195 if (!LIR.runOnLoop(&L))
203 "Recognize loop idioms",
false,
false)
223 bool LoopIdiomRecognize::runOnLoop(
Loop *L) {
232 if (Name ==
"memset" || Name ==
"memcpy")
236 ApplyCodeSizeHeuristics =
239 HasMemset = TLI->
has(LibFunc::memset);
240 HasMemsetPattern = TLI->
has(LibFunc::memset_pattern16);
241 HasMemcpy = TLI->
has(LibFunc::memcpy);
243 if (HasMemset || HasMemsetPattern || HasMemcpy)
245 return runOnCountableLoop();
247 return runOnNoncountableLoop();
250 bool LoopIdiomRecognize::runOnCountableLoop() {
252 assert(!isa<SCEVCouldNotCompute>(BECount) &&
253 "runOnCountableLoop() called on a loop without a predictable"
254 "backedge-taken count");
258 if (
const SCEVConstant *BECst = dyn_cast<SCEVConstant>(BECount))
259 if (BECst->getAPInt() == 0)
263 CurLoop->getUniqueExitBlocks(ExitBlocks);
265 DEBUG(
dbgs() <<
"loop-idiom Scanning: F["
266 << CurLoop->getHeader()->getParent()->getName() <<
"] Loop %"
267 << CurLoop->getHeader()->getName() <<
"\n");
269 bool MadeChange =
false;
279 for (
auto *BB : CurLoop->getBlocks()) {
284 MadeChange |= runOnLoopBlock(BB, BECount, ExitBlocks);
291 assert(((SizeInBits & 7) || (SizeInBits >> 32) == 0) &&
292 "Don't overflow unsigned.");
293 return (
unsigned)SizeInBits >> 3;
317 if (Size == 0 || (Size & 7) || (Size & (Size - 1)))
337 unsigned ArraySize = 16 / Size;
342 bool LoopIdiomRecognize::isLegalStore(
StoreInst *SI,
bool &ForMemset,
343 bool &ForMemsetPattern,
bool &ForMemcpy) {
356 uint64_t SizeInBits = DL->getTypeSizeInBits(StoredVal->
getType());
357 if ((SizeInBits & 7) || (SizeInBits >> 32) != 0)
369 if (!isa<SCEVConstant>(StoreEv->
getOperand(1)))
383 if (HasMemset && SplatValue &&
386 CurLoop->isLoopInvariant(SplatValue)) {
390 }
else if (HasMemsetPattern &&
395 ForMemsetPattern =
true;
405 if (StoreSize != Stride && StoreSize != -Stride)
433 void LoopIdiomRecognize::collectStores(
BasicBlock *BB) {
434 StoreRefsForMemset.clear();
435 StoreRefsForMemsetPattern.clear();
436 StoreRefsForMemcpy.clear();
442 bool ForMemset =
false;
443 bool ForMemsetPattern =
false;
444 bool ForMemcpy =
false;
446 if (!isLegalStore(SI, ForMemset, ForMemsetPattern, ForMemcpy))
453 StoreRefsForMemset[
Ptr].push_back(SI);
454 }
else if (ForMemsetPattern) {
457 StoreRefsForMemsetPattern[
Ptr].push_back(SI);
458 }
else if (ForMemcpy)
459 StoreRefsForMemcpy.push_back(SI);
466 bool LoopIdiomRecognize::runOnLoopBlock(
472 for (
unsigned i = 0, e = ExitBlocks.
size();
i != e; ++
i)
476 bool MadeChange =
false;
483 for (
auto &SL : StoreRefsForMemset)
484 MadeChange |= processLoopStores(SL.second, BECount,
true);
486 for (
auto &SL : StoreRefsForMemsetPattern)
487 MadeChange |= processLoopStores(SL.second, BECount,
false);
490 for (
auto &SI : StoreRefsForMemcpy)
491 MadeChange |= processLoopStoreOfLoopLoad(SI, BECount);
496 if (
MemSetInst *MSI = dyn_cast<MemSetInst>(Inst)) {
498 if (!processLoopMemSet(MSI, BECount))
524 for (
unsigned i = 0, e = SL.
size(); i < e; ++
i) {
525 assert(SL[i]->
isSimple() &&
"Expected only non-volatile stores.");
527 Value *FirstStoredVal = SL[
i]->getValueOperand();
528 Value *FirstStorePtr = SL[
i]->getPointerOperand();
530 cast<SCEVAddRecExpr>(SE->
getSCEV(FirstStorePtr));
535 if (FirstStride == FirstStoreSize || -FirstStride == FirstStoreSize) {
540 Value *FirstSplatValue =
nullptr;
541 Constant *FirstPatternValue =
nullptr;
548 assert((FirstSplatValue || FirstPatternValue) &&
549 "Expected either splat value or pattern value.");
557 for (j = i + 1; j < e; ++j)
559 for (j = i; j > 0; --j)
562 for (
auto &k : IndexQueue) {
563 assert(SL[k]->
isSimple() &&
"Expected only non-volatile stores.");
564 Value *SecondStorePtr = SL[k]->getPointerOperand();
566 cast<SCEVAddRecExpr>(SE->
getSCEV(SecondStorePtr));
569 if (FirstStride != SecondStride)
572 Value *SecondStoredVal = SL[k]->getValueOperand();
573 Value *SecondSplatValue =
nullptr;
574 Constant *SecondPatternValue =
nullptr;
581 assert((SecondSplatValue || SecondPatternValue) &&
582 "Expected either splat value or pattern value.");
586 if (FirstSplatValue != SecondSplatValue)
589 if (FirstPatternValue != SecondPatternValue)
594 ConsecutiveChain[SL[
i]] = SL[k];
603 bool Changed =
false;
608 if (Tails.
count(*it))
617 unsigned StoreSize = 0;
621 if (TransformedStores.
count(I))
627 I = ConsecutiveChain[
I];
637 if (StoreSize != Stride && StoreSize != -Stride)
640 bool NegStride = StoreSize == -Stride;
642 if (processLoopStridedStore(StorePtr, StoreSize, HeadStore->
getAlignment(),
643 StoredVal, HeadStore, AdjacentStores, StoreEv,
644 BECount, NegStride)) {
645 TransformedStores.
insert(AdjacentStores.begin(), AdjacentStores.end());
654 bool LoopIdiomRecognize::processLoopMemSet(
MemSetInst *MSI,
655 const SCEV *BECount) {
674 uint64_t SizeInBytes = cast<ConstantInt>(MSI->
getLength())->getZExtValue();
675 if ((SizeInBytes >> 32) != 0)
685 if (SizeInBytes != Stride && SizeInBytes != -Stride)
691 if (!SplatValue || !CurLoop->isLoopInvariant(SplatValue))
696 bool NegStride = SizeInBytes == -Stride;
697 return processLoopStridedStore(Pointer, (
unsigned)SizeInBytes,
699 BECount, NegStride,
true);
707 const SCEV *BECount,
unsigned StoreSize,
717 if (
const SCEVConstant *BECst = dyn_cast<SCEVConstant>(BECount))
718 AccessSize = (BECst->getValue()->getZExtValue() + 1) * StoreSize;
729 if (IgnoredStores.
count(&I) == 0 &&
740 Type *IntPtr,
unsigned StoreSize,
751 bool LoopIdiomRecognize::processLoopStridedStore(
752 Value *DestPtr,
unsigned StoreSize,
unsigned StoreAlignment,
755 const SCEV *BECount,
bool NegStride,
bool IsLoopMemset) {
762 assert((SplatValue || PatternValue) &&
763 "Expected either splat value or pattern value.");
769 BasicBlock *Preheader = CurLoop->getLoopPreheader();
774 Type *IntPtr = Builder.getIntPtrTy(*DL, DestAS);
787 Expander.expandCodeFor(Start, DestInt8PtrTy, Preheader->
getTerminator());
796 if (avoidLIRForMultiBlockLoop(
true, IsLoopMemset))
805 const SCEV *NumBytesS =
807 if (StoreSize != 1) {
813 Expander.expandCodeFor(NumBytesS, IntPtr, Preheader->
getTerminator());
818 Builder.CreateMemSet(BasePtr, SplatValue, NumBytes, StoreAlignment);
821 Type *Int8PtrTy = DestInt8PtrTy;
826 Int8PtrTy, Int8PtrTy, IntPtr, (
void *)
nullptr);
833 PatternValue,
".memset_pattern");
835 GV->setAlignment(16);
837 NewCall = Builder.CreateCall(MSP, {BasePtr, PatternPtr, NumBytes});
840 DEBUG(
dbgs() <<
" Formed memset: " << *NewCall <<
"\n"
841 <<
" from store to: " << *Ev <<
" at: " << *TheStore <<
"\n");
846 for (
auto *I : Stores)
855 bool LoopIdiomRecognize::processLoopStoreOfLoopLoad(
StoreInst *SI,
856 const SCEV *BECount) {
863 bool NegStride = StoreSize == -Stride;
878 BasicBlock *Preheader = CurLoop->getLoopPreheader();
884 Type *IntPtrTy = Builder.getIntPtrTy(*DL, StrAS);
896 Value *StoreBasePtr = Expander.expandCodeFor(
897 StrStart, Builder.getInt8PtrTy(StrAS), Preheader->
getTerminator());
902 StoreSize, *AA, Stores)) {
909 const SCEV *LdStart = LoadEv->getStart();
918 Value *LoadBasePtr = Expander.expandCodeFor(
919 LdStart, Builder.getInt8PtrTy(LdAS), Preheader->
getTerminator());
930 if (avoidLIRForMultiBlockLoop())
939 const SCEV *NumBytesS =
946 Expander.expandCodeFor(NumBytesS, IntPtrTy, Preheader->
getTerminator());
949 Builder.CreateMemCpy(StoreBasePtr, LoadBasePtr, NumBytes,
953 DEBUG(
dbgs() <<
" Formed memcpy: " << *NewCall <<
"\n"
954 <<
" from load ptr=" << *LoadEv <<
" at: " << *LI <<
"\n"
955 <<
" from store ptr=" << *StoreEv <<
" at: " << *SI <<
"\n");
967 bool LoopIdiomRecognize::avoidLIRForMultiBlockLoop(
bool IsMemset,
969 if (ApplyCodeSizeHeuristics && CurLoop->getNumBlocks() > 1) {
970 if (!CurLoop->getParentLoop() && (!IsMemset || !IsLoopMemset)) {
971 DEBUG(
dbgs() <<
" " << CurLoop->getHeader()->getParent()->getName()
972 <<
" : LIR " << (IsMemset ?
"Memset" :
"Memcpy")
973 <<
" avoided: multi-block top-level loop\n");
981 bool LoopIdiomRecognize::runOnNoncountableLoop() {
982 return recognizePopcount();
999 if (!CmpZero || !CmpZero->
isZero())
1041 Value *VarX1, *VarX0;
1044 DefX2 = CountInst =
nullptr;
1045 VarX1 = VarX0 =
nullptr;
1046 PhiX = CountPhi =
nullptr;
1052 dyn_cast<BranchInst>(LoopEntry->
getTerminator()), LoopEntry))
1053 DefX2 = dyn_cast<Instruction>(
T);
1065 if ((SubOneOp = dyn_cast<BinaryOperator>(DefX2->
getOperand(0))))
1074 Instruction *SubInst = cast<Instruction>(SubOneOp);
1077 !((SubInst->
getOpcode() == Instruction::Sub && Dec->isOne()) ||
1079 Dec->isAllOnesValue()))) {
1095 CountInst =
nullptr;
1097 IterE = LoopEntry->
end();
1098 Iter != IterE; Iter++) {
1104 if (!Inc || !Inc->
isOne())
1108 if (!Phi || Phi->
getParent() != LoopEntry)
1112 bool LiveOutLoop =
false;
1114 if ((cast<Instruction>(U))->getParent() != LoopEntry) {
1139 CntInst = CountInst;
1151 bool LoopIdiomRecognize::recognizePopcount() {
1161 if (CurLoop->getNumBackEdges() != 1 || CurLoop->getNumBlocks() != 1)
1164 BasicBlock *LoopBody = *(CurLoop->block_begin());
1165 if (LoopBody->
size() >= 20) {
1171 BasicBlock *PH = CurLoop->getLoopPreheader();
1175 if (!EntryBI || EntryBI->isConditional())
1184 if (!PreCondBI || PreCondBI->isUnconditional())
1193 transformLoopToPopcount(PreCondBB, CntInst, CntPhi, Val);
1199 Value *Ops[] = {Val};
1210 void LoopIdiomRecognize::transformLoopToPopcount(
BasicBlock *PreCondBB,
1213 BasicBlock *PreHead = CurLoop->getLoopPreheader();
1223 Value *PopCnt, *PopCntZext, *NewCount, *TripCnt;
1226 NewCount = PopCntZext =
1227 Builder.CreateZExtOrTrunc(PopCnt, cast<IntegerType>(CntPhi->
getType()));
1229 if (NewCount != PopCnt)
1230 (cast<Instruction>(NewCount))->setDebugLoc(DL);
1238 if (!InitConst || !InitConst->
isZero()) {
1239 NewCount = Builder.CreateAdd(NewCount, CntInitVal);
1240 (cast<Instruction>(NewCount))->setDebugLoc(DL);
1249 ICmpInst *PreCond = cast<ICmpInst>(PreCondBr->getCondition());
1251 Value *Opnd0 = PopCntZext;
1256 ICmpInst *NewPreCond = cast<ICmpInst>(
1257 Builder.CreateICmp(PreCond->
getPredicate(), Opnd0, Opnd1));
1258 PreCondBr->setCondition(NewPreCond);
1283 BasicBlock *Body = *(CurLoop->block_begin());
1286 ICmpInst *LbCond = cast<ICmpInst>(LbBr->getCondition());
1291 Builder.SetInsertPoint(LbCond);
1294 "tcdec",
false,
true));
1301 LbCond->setPredicate(Pred);
1302 LbCond->setOperand(0, TcDec);
unsigned getAlignment() const
Pass interface - Implemented by all 'passes'.
Value * getValueOperand()
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void push_back(const T &Elt)
A parsed version of the target data layout string in and methods for querying it. ...
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
static CallInst * createPopcntIntrinsic(IRBuilder<> &IRBuilder, Value *Val, const DebugLoc &DL)
PreservedAnalyses getLoopPassPreservedAnalyses()
Returns the minimum set of Analyses that all loop passes must preserve.
const SCEV * getConstant(ConstantInt *V)
STATISTIC(NumFunctions,"Total number of functions")
Value * isBytewiseValue(Value *V)
If the specified value can be set by repeating the same byte in memory, return the i8 value that it i...
This header provides classes for managing a pipeline of passes over loops in LLVM IR...
This is the interface for a simple mod/ref and alias analysis over globals.
A Module instance is used to store all the information related to an LLVM module. ...
Value * getValue() const
Return the arguments to the instruction.
The main scalar evolution driver.
This class represents a function call, abstracting a target machine's calling convention.
size_type count(PtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Like Internal, but omit from symbol table.
This class wraps the llvm.memset intrinsic.
const Function * getParent() const
Return the enclosing method, or null if none.
const Instruction & front() const
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
An instruction for reading from memory.
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
iterator end()
Get an iterator to the end of the SetVector.
The access modifies the value stored in memory.
BlockT * getHeader() const
const SCEV * getStart() const
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
iterator begin()
Instruction iterator methods.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
This is the interface for a SCEV-based alias analysis.
bool has(LibFunc::Func F) const
Tests whether a library function is available.
INITIALIZE_PASS_BEGIN(LoopIdiomRecognizeLegacyPass,"loop-idiom","Recognize loop idioms", false, false) INITIALIZE_PASS_END(LoopIdiomRecognizeLegacyPass
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Instruction * getFirstNonPHI()
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
void computeLoopSafetyInfo(LoopSafetyInfo *, Loop *)
Computes safety information for a loop checks loop body & header for the possibility of may throw exc...
static bool isSimple(Instruction *I)
bool insert(const value_type &X)
Insert a new element into the SetVector.
This node represents a polynomial recurrence on the trip count of the specified loop.
static APInt getStoreStride(const SCEVAddRecExpr *StoreEv)
Value handle that is nullable, but tries to track the Value.
Class to represent array types.
BasicBlock * getSuccessor(unsigned i) const
iterator begin()
Get an iterator to the beginning of the SetVector.
Function * getDeclaration(Module *M, ID id, ArrayRef< Type * > Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
void initializeLoopIdiomRecognizeLegacyPassPass(PassRegistry &)
An instruction for storing to memory.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
static void deleteDeadInstruction(Instruction *I)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with etc Experimental Use value profile to guide fuzzing Number of simultaneous worker processes to run the jobs If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
bool isConsecutiveAccess(Value *A, Value *B, const DataLayout &DL, ScalarEvolution &SE, bool CheckType=true)
Returns true if the memory operations A and B are consecutive.
bool inferLibFuncAttributes(Function &F, const TargetLibraryInfo &TLI)
Analyze the name and prototype of the given function and set any applicable attributes.
initializer< Ty > init(const Ty &Val)
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)
unsigned getAlignment() const
Return the alignment of the access that is being performed.
bool isAffine() const
Return true if this represents an expression A + B*x where A and B are loop invariant values...
A set of analyses that are preserved following a run of a transformation pass.
const SCEV * getOne(Type *Ty)
Return a SCEV for the constant 1 of a specific type.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
BlockT * getLoopPreheader() const
If there is a preheader for this loop, return it.
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeSet AttributeList)
Look up the specified function in the module symbol table.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
Conditional or Unconditional Branch instruction.
This is an important base class in LLVM.
const SCEV * getOperand(unsigned i) const
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
Represent the analysis usage information of a pass.
static Value * matchCondition(BranchInst *BI, BasicBlock *LoopEntry)
Check if the given conditional branch is based on the comparison between a variable and zero...
This instruction compares its operands according to the predicate given to the constructor.
const SCEV * getMinusSCEV(const SCEV *LHS, const SCEV *RHS, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap)
Return LHS-RHS. Minus is represented in SCEV as A+B*-1.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE,"Assign register bank of generic virtual registers", false, false) RegBankSelect
Value * getOperand(unsigned i) const
Value * getPointerOperand()
self_iterator getIterator()
Predicate getPredicate() const
Return the predicate for this instruction.
const APInt & getAPInt() const
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr)
If the specified value is a trivially dead instruction, delete it.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
Value * GetUnderlyingObject(Value *V, const DataLayout &DL, unsigned MaxLookup=6)
This method strips off any GEP address adjustments and pointer casts from the specified value...
TargetTransformInfo & TTI
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...
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
bool isConditional() const
Representation for a specific memory location.
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
Iterator for intrusive lists based on ilist_node.
loop Recognize loop false
This is the shared class of boolean and integer constants.
Value * getDest() const
This is just like getRawDest, but it strips off any cast instructions that feed it, giving the original input.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
Provides information about what library functions are available for the current target.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
Value * getLength() const
BasicBlock * GetInsertBlock() const
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
static PHINode * Create(Type *Ty, unsigned NumReservedValues, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Constructors - NumReservedValues is a hint for the number of incoming edges that this phi node will h...
static Constant * getMemSetPatternValue(Value *V, const DataLayout *DL)
getMemSetPatternValue - If a strided store of the specified value is safe to turn into a memset_patte...
unsigned getPointerAddressSpace() const
Returns the address space of the pointer operand.
static bool detectPopcountIdiom(Loop *CurLoop, BasicBlock *PreCondBB, Instruction *&CntInst, PHINode *&CntPhi, Value *&Var)
Return true iff the idiom is detected in the loop.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
loop Recognize loop idioms
Class for arbitrary precision integers.
ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc)
getModRefInfo (for call sites) - Return information about whether a particular call site modifies or ...
Value * getIncomingValueForBlock(const BasicBlock *BB) const
iterator_range< user_iterator > users()
BasicBlock * getSinglePredecessor()
Return the predecessor of this block if it has a single predecessor block.
This class uses information about analyze scalars to rewrite expressions in canonical form...
const SCEV * getAddExpr(SmallVectorImpl< const SCEV * > &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap)
Get a canonical add expression, or something simpler if possible.
std::vector< BlockT * >::const_iterator block_iterator
Pass * createLoopIdiomPass()
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
block_iterator block_end() const
Value * getCondition() const
Captures loop safety information.
void forgetLoop(const Loop *L)
This method should be called by the client when it has changed a loop in a way that may effect Scalar...
size_type count(const key_type &key) const
Count the number of elements of a given key in the SetVector.
void setUnnamedAddr(UnnamedAddr Val)
This class represents an analyzed expression in the program.
Represents a single loop in the control flow graph.
unsigned getAlignment() const
Return the alignment of the access that is being performed.
The access both references and modifies the value stored in memory.
TerminatorInst * getTerminator()
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
CallInst * CreateCall(Value *Callee, ArrayRef< Value * > Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
void getLoopAnalysisUsage(AnalysisUsage &AU)
Helper to consistently add the set of standard passes to a loop pass's AnalysisUsage.
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
const Loop * getLoop() const
static const SCEV * getStartForNegStride(const SCEV *Start, const SCEV *BECount, Type *IntPtr, unsigned StoreSize, ScalarEvolution *SE)
const SCEV * getBackedgeTakenCount(const Loop *L)
If the specified loop has a predictable backedge-taken count, return it, otherwise return a SCEVCould...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
vector_type::const_iterator iterator
const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
unsigned getOpcode() const
Returns a member of one of the enums like Instruction::Add.
A vector that has set insertion semantics.
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
static unsigned getStoreSizeInBytes(StoreInst *SI, const DataLayout *DL)
block_iterator block_begin() const
StringRef - Represent a constant reference to a string, i.e.
This is the interface for LLVM's primary stateless and local alias analysis.
A container for analyses that lazily runs them and caches their results.
void replaceUsesOutsideBlock(Value *V, BasicBlock *BB)
replaceUsesOutsideBlock - Go through the uses list for this definition and make each use point to "V"...
const SCEV * getTruncateOrZeroExtend(const SCEV *V, Type *Ty)
Return a SCEV corresponding to a conversion of the input value to the specified type.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
const SCEV * getMulExpr(SmallVectorImpl< const SCEV * > &Ops, SCEV::NoWrapFlags Flags=SCEV::FlagAnyWrap)
Get a canonical multiply expression, or something simpler if possible.
bool hasLoopInvariantBackedgeTakenCount(const Loop *L)
Return true if the specified loop has an analyzable loop-invariant backedge-taken count...
Value * getPointerOperand()
const BasicBlock * getParent() const
bool isOne() const
This is just a convenience method to make client code smaller for a common case.
PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U)
This class represents a constant integer value.