84#define DEBUG_TYPE "loop-idiom-vectorize"
87class LoopIdiomVectorize {
88 const VectorizeOptions &Opts;
90 unsigned ByteCompareVF;
91 Loop *CurLoop =
nullptr;
101 BasicBlock *VectorLoopPreheaderBlock =
nullptr;
103 BasicBlock *VectorLoopMismatchBlock =
nullptr;
111 : Opts(Opts), VectorizeStyle(S), ByteCompareVF(VF), DT(DT), LI(LI),
120 bool recognizeByteCompare();
140 bool recognizeFindFirstByte();
143 unsigned VF,
Type *CharTy,
Value *IndPhi,
148 void transformFindFirstByte(
PHINode *IndPhi,
unsigned VF,
Type *CharTy,
160 if (Opts.disable_loop_idiom_vectorize_all)
164 Opts.loop_idiom_vectorize_style.value_or(VectorizeStyle);
165 unsigned BCVF = Opts.loop_idiom_vectorize_bytecmp_vf.value_or(ByteCompareVF);
167 Function &
F = *L.getHeader()->getParent();
171 std::optional<OptimizationRemarkEmitter> ORELocal;
173 ORELocal.emplace(&
F);
177 LoopIdiomVectorize LIV(Opts, VecStyle, BCVF, &AR.
DT, &AR.
LI, &AR.
TTI, *ORE);
190bool LoopIdiomVectorize::run(
Loop *L) {
193 Function &
F = *L->getHeader()->getParent();
194 if (Opts.disable_loop_idiom_vectorize_all ||
F.hasOptSize())
199 if (!Hints.allowVectorization(L,
false)) {
201 <<
" due to vectorization hints\n");
205 if (
F.hasFnAttribute(Attribute::NoImplicitFloat)) {
207 <<
" due to its NoImplicitFloat attribute");
213 if (!
L->getLoopPreheader())
217 << CurLoop->getHeader()->getName() <<
"\n");
219 if (recognizeByteCompare())
222 if (recognizeFindFirstByte())
234 for (
Value *
Op : PN.incoming_values())
235 if (
Op == ScalarRes) {
243 PN.addIncoming(VectorRes, IncBB);
251 if (L->contains(BB)) {
252 PN.addIncoming(PN.getIncomingValueForBlock(BB), IncBB);
259bool LoopIdiomVectorize::recognizeByteCompare() {
266 if (!
TTI->supportsScalableVectors() || !
TTI->getMinPageSize().has_value() ||
267 Opts.disable_loop_idiom_vectorize_bytecmp)
274 if (CurLoop->getNumBackEdges() != 1 || CurLoop->getNumBlocks() != 2)
281 auto LoopBlocks = CurLoop->getBlocks();
290 if (LoopBlocks[0]->
size() > 4)
304 if (LoopBlocks[1]->
size() > 7)
308 Value *StartIdx =
nullptr;
319 if (!Index || !
Index->getType()->isIntegerTy(32) ||
328 if (&
I != PN && &
I != Index)
330 if (!CurLoop->contains(U))
336 if (!
match(Header->getTerminator(),
340 !CurLoop->contains(WhileBB))
347 Value *LoadA, *LoadB;
352 !CurLoop->contains(TrueBB))
374 if (!CurLoop->isLoopInvariant(PtrA) || !CurLoop->isLoopInvariant(PtrB) ||
413 if (FoundBB == EndBB) {
415 Value *WhileCondVal = EndPN.getIncomingValueForBlock(Header);
416 Value *WhileBodyVal = EndPN.getIncomingValueForBlock(WhileBB);
422 if (WhileCondVal != WhileBodyVal &&
423 ((WhileCondVal != Index && WhileCondVal != MaxLen) ||
424 (WhileBodyVal != Index)))
434 transformByteCompare(GEPA, GEPB, PN, MaxLen, Index, StartIdx,
true,
439Value *LoopIdiomVectorize::createMaskedFindMismatch(
452 Intrinsic::get_active_lane_mask, {PredVTy, I64Type}, {ExtStart, ExtEnd});
456 Builder.
CreateMul(VecLen, ConstantInt::get(I64Type, ByteCompareVF),
"",
462 Builder.
CreateBr(VectorLoopStartBlock);
465 VectorLoopStartBlock}});
470 PHINode *LoopPred = Builder.
CreatePHI(PredVTy, 2,
"mismatch_vec_loop_pred");
471 LoopPred->
addIncoming(InitialPred, VectorLoopPreheaderBlock);
472 PHINode *VectorIndexPhi = Builder.
CreatePHI(I64Type, 2,
"mismatch_vec_index");
473 VectorIndexPhi->
addIncoming(ExtStart, VectorLoopPreheaderBlock);
474 Type *VectorLoadType =
478 Value *VectorLhsGep =
481 Align(1), LoopPred, Passthru);
483 Value *VectorRhsGep =
486 Align(1), LoopPred, Passthru);
489 VectorMatchCmp = Builder.
CreateSelect(LoopPred, VectorMatchCmp, PFalse);
491 Builder.
CreateCondBr(VectorMatchHasActiveLanes, VectorLoopMismatchBlock,
502 Value *NewVectorIndexPhi =
503 Builder.
CreateAdd(VectorIndexPhi, VecLen,
"",
505 VectorIndexPhi->
addIncoming(NewVectorIndexPhi, VectorLoopIncBlock);
508 {PredVTy, I64Type}, {NewVectorIndexPhi, ExtEnd});
509 LoopPred->
addIncoming(NewPred, VectorLoopIncBlock);
511 Value *PredHasActiveLanes =
513 Builder.
CreateCondBr(PredHasActiveLanes, VectorLoopStartBlock, EndBlock);
522 PHINode *FoundPred = Builder.
CreatePHI(PredVTy, 1,
"mismatch_vec_found_pred");
523 FoundPred->
addIncoming(VectorMatchCmp, VectorLoopStartBlock);
525 Builder.
CreatePHI(PredVTy, 1,
"mismatch_vec_last_loop_pred");
526 LastLoopPred->
addIncoming(LoopPred, VectorLoopStartBlock);
528 Builder.
CreatePHI(I64Type, 1,
"mismatch_vec_found_index");
529 VectorFoundIndex->
addIncoming(VectorIndexPhi, VectorLoopStartBlock);
534 Value *VectorLoopRes64 = Builder.
CreateAdd(VectorFoundIndex, Ctz,
"",
536 return Builder.
CreateTrunc(VectorLoopRes64, ResType);
539Value *LoopIdiomVectorize::createPredicatedFindMismatch(
544 Type *ResType = I32Type;
550 Builder.
Insert(JumpToVectorLoop);
553 VectorLoopStartBlock}});
558 auto *VectorIndexPhi = Builder.
CreatePHI(I64Type, 2,
"mismatch_vector_index");
559 VectorIndexPhi->
addIncoming(ExtStart, VectorLoopPreheaderBlock);
562 Value *AVL = Builder.
CreateSub(ExtEnd, VectorIndexPhi,
"avl",
true,
566 auto *VF = ConstantInt::get(I32Type, ByteCompareVF);
569 {I64Type}, {AVL, VF, Builder.
getTrue()});
570 Value *GepOffset = VectorIndexPhi;
572 Value *VectorLhsGep =
578 Intrinsic::vp_load, {VectorLoadType, VectorLhsGep->
getType()},
579 {VectorLhsGep, AllTrueMask, VL},
nullptr,
"lhs.load");
581 Value *VectorRhsGep =
584 Intrinsic::vp_load, {VectorLoadType, VectorLhsGep->
getType()},
585 {VectorRhsGep, AllTrueMask, VL},
nullptr,
"rhs.load");
587 Value *VectorMatchCmp =
588 Builder.
CreateICmpNE(VectorLhsLoad, VectorRhsLoad,
"mismatch.cmp");
590 Intrinsic::vp_cttz_elts, {ResType, VectorMatchCmp->
getType()},
591 {VectorMatchCmp, Builder.
getInt1(
false), AllTrueMask,
595 MismatchFound, VectorLoopMismatchBlock, VectorLoopIncBlock);
596 Builder.
Insert(VectorEarlyExit);
607 Value *NewVectorIndexPhi =
608 Builder.
CreateAdd(VectorIndexPhi, VL64,
"",
610 VectorIndexPhi->
addIncoming(NewVectorIndexPhi, VectorLoopIncBlock);
612 auto *VectorLoopBranchBack =
614 Builder.
Insert(VectorLoopBranchBack);
626 CTZLCSSAPhi->
addIncoming(CTZ, VectorLoopStartBlock);
627 auto *VectorIndexLCSSAPhi =
629 VectorIndexLCSSAPhi->
addIncoming(VectorIndexPhi, VectorLoopStartBlock);
632 Value *VectorLoopRes64 = Builder.
CreateAdd(VectorIndexLCSSAPhi, CTZI64,
"",
634 return Builder.
CreateTrunc(VectorLoopRes64, ResType);
637Value *LoopIdiomVectorize::expandFindMismatch(
644 BasicBlock *Preheader = CurLoop->getLoopPreheader();
651 EndBlock =
SplitBlock(Preheader, PHBranch, DT, LI,
nullptr,
"mismatch_end");
667 Ctx,
"mismatch_min_it_check", EndBlock->getParent(), EndBlock);
673 Ctx,
"mismatch_mem_check", EndBlock->getParent(), EndBlock);
676 Ctx,
"mismatch_vec_loop_preheader", EndBlock->getParent(), EndBlock);
679 EndBlock->getParent(), EndBlock);
682 EndBlock->getParent(), EndBlock);
685 EndBlock->getParent(), EndBlock);
688 Ctx,
"mismatch_loop_pre", EndBlock->getParent(), EndBlock);
694 Ctx,
"mismatch_loop_inc", EndBlock->getParent(), EndBlock);
700 auto VectorLoop = LI->AllocateLoop();
701 auto ScalarLoop = LI->AllocateLoop();
703 if (CurLoop->getParentLoop()) {
704 CurLoop->getParentLoop()->addBasicBlockToLoop(MinItCheckBlock, *LI);
705 CurLoop->getParentLoop()->addBasicBlockToLoop(MemCheckBlock, *LI);
706 CurLoop->getParentLoop()->addBasicBlockToLoop(VectorLoopPreheaderBlock,
708 CurLoop->getParentLoop()->addChildLoop(VectorLoop);
709 CurLoop->getParentLoop()->addBasicBlockToLoop(VectorLoopMismatchBlock, *LI);
710 CurLoop->getParentLoop()->addBasicBlockToLoop(LoopPreHeaderBlock, *LI);
711 CurLoop->getParentLoop()->addChildLoop(ScalarLoop);
713 LI->addTopLevelLoop(VectorLoop);
714 LI->addTopLevelLoop(ScalarLoop);
718 VectorLoop->addBasicBlockToLoop(VectorLoopStartBlock, *LI);
719 VectorLoop->addBasicBlockToLoop(VectorLoopIncBlock, *LI);
721 ScalarLoop->addBasicBlockToLoop(LoopStartBlock, *LI);
722 ScalarLoop->addBasicBlockToLoop(LoopIncBlock, *LI);
737 LLVMContext::MD_prof,
739 Builder.
Insert(MinItCheckBr);
779 Value *CombinedPageCmp = Builder.
CreateOr(LhsPageCmp, RhsPageCmp);
781 CombinedPageCmp, LoopPreHeaderBlock, VectorLoopPreheaderBlock);
785 Builder.
Insert(CombinedPageCmpCmpBr);
801 Value *VectorLoopRes =
nullptr;
802 switch (VectorizeStyle) {
805 createMaskedFindMismatch(Builder, DTU, GEPA, GEPB, ExtStart, ExtEnd);
808 VectorLoopRes = createPredicatedFindMismatch(Builder, DTU, GEPA, GEPB,
850 Value *PhiInc = Builder.
CreateAdd(IndexPhi, ConstantInt::get(ResType, 1),
"",
851 Index->hasNoUnsignedWrap(),
852 Index->hasNoSignedWrap());
872 ResPhi->
addIncoming(VectorLoopRes, VectorLoopMismatchBlock);
876 if (Opts.loop_idiom_vectorize_verify) {
877 ScalarLoop->verifyLoop();
878 VectorLoop->verifyLoop();
879 if (!VectorLoop->isRecursivelyLCSSAForm(*DT, *LI))
881 if (!ScalarLoop->isRecursivelyLCSSAForm(*DT, *LI))
896 BasicBlock *Preheader = CurLoop->getLoopPreheader();
908 expandFindMismatch(Builder, DTU, GEPA, GEPB, Index, Start, MaxLen);
912 assert(IndPhi->
hasOneUse() &&
"Index phi node has more than one use!");
913 Index->replaceAllUsesWith(ByteCmpRes);
919 CmpBB->moveBefore(EndBB);
932 if (FoundBB != EndBB) {
945 if (EndBB != FoundBB)
950 if (!CurLoop->isOutermost())
951 CurLoop->getParentLoop()->addBasicBlockToLoop(CmpBB, *LI);
953 if (Opts.loop_idiom_vectorize_verify && CurLoop->getParentLoop()) {
954 CurLoop->getParentLoop()->verifyLoop();
955 if (!CurLoop->getParentLoop()->isRecursivelyLCSSAForm(*DT, *LI))
960bool LoopIdiomVectorize::recognizeFindFirstByte() {
965 if (!
TTI->supportsScalableVectors() || !
TTI->getMinPageSize().has_value() ||
966 Opts.disable_loop_idiom_vectorize_find_first_byte)
973 (std::numeric_limits<uint64_t>::max() / 2))
983 if (CurLoop->getNumBackEdges() != 1 || CurLoop->getNumBlocks() != 4 ||
984 CurLoop->getSubLoops().size() != 1)
987 auto *InnerLoop = CurLoop->getSubLoops().front();
992 if (!Hints.allowVectorization(InnerLoop,
false)) {
994 << InnerLoop->getName()
995 <<
" due to vectorization hints\n");
1004 auto LoopBlocks = CurLoop->getBlocks();
1005 if (LoopBlocks[0]->
size() > 3 || LoopBlocks[1]->
size() > 4 ||
1006 LoopBlocks[2]->
size() > 3 || LoopBlocks[3]->
size() > 3)
1014 if (!CurLoop->contains(U))
1026 !InnerLoop->contains(MatchBB))
1038 Value *LoadSearch, *LoadNeedle;
1048 if (!CurLoop->contains(U)) {
1086 if (InnerLoop->contains(PSearch))
1088 if (PSearch != &Header->front() || PNeedle != &MatchBB->
front())
1126 !CurLoop->contains(OuterBB))
1143 if (!CurLoop->isLoopInvariant(SearchStart) ||
1144 !CurLoop->isLoopInvariant(SearchEnd) ||
1145 !CurLoop->isLoopInvariant(NeedleStart) ||
1146 !CurLoop->isLoopInvariant(NeedleEnd))
1149 LLVM_DEBUG(
dbgs() <<
"Found idiom in loop: \n" << *CurLoop <<
"\n\n");
1151 transformFindFirstByte(IndPhi, VF, CharTy, ExitSucc, ExitFail, SearchStart,
1152 SearchEnd, NeedleStart, NeedleEnd);
1156Value *LoopIdiomVectorize::expandFindFirstByte(
1165 auto *ConstVF = ConstantInt::get(I64Ty, VF);
1168 BasicBlock *Preheader = CurLoop->getLoopPreheader();
1175 nullptr,
"scalar_preheader");
1210 auto OuterLoop = LI->AllocateLoop();
1211 auto InnerLoop = LI->AllocateLoop();
1213 if (
auto ParentLoop = CurLoop->getParentLoop()) {
1214 ParentLoop->addBasicBlockToLoop(BB0, *LI);
1215 ParentLoop->addChildLoop(OuterLoop);
1217 LI->addTopLevelLoop(OuterLoop);
1224 while (ExitLoop && !ExitLoop->
contains(ExitSucc))
1230 OuterLoop->addChildLoop(InnerLoop);
1233 OuterLoop->addBasicBlockToLoop(BB1, *LI);
1234 OuterLoop->addBasicBlockToLoop(BB3, *LI);
1235 OuterLoop->addBasicBlockToLoop(BB5, *LI);
1236 InnerLoop->addBasicBlockToLoop(BB2, *LI);
1247 Value *ISearchStart =
1252 Value *SearchTripCount =
1254 "search_trip_count"),
1256 Value *INeedleStart =
1261 Value *NeedleTripCount =
1263 "needle_trip_count"),
1266 Builder.
CreateIntrinsic(Intrinsic::get_active_lane_mask, {PredVTy, I64Ty},
1267 {ConstantInt::get(I64Ty, 0), ConstVF});
1271 Value *SearchStartPage =
1272 Builder.
CreateLShr(ISearchStart, AddrShiftAmt,
"search_start_page");
1273 Value *SearchEndPage =
1274 Builder.
CreateLShr(ISearchEnd, AddrShiftAmt,
"search_end_page");
1275 Value *NeedleStartPage =
1276 Builder.
CreateLShr(INeedleStart, AddrShiftAmt,
"needle_start_page");
1277 Value *NeedleEndPage =
1278 Builder.
CreateLShr(INeedleEnd, AddrShiftAmt,
"needle_end_page");
1279 Value *SearchPageCmp =
1280 Builder.
CreateICmpNE(SearchStartPage, SearchEndPage,
"search_page_cmp");
1281 Value *NeedlePageCmp =
1282 Builder.
CreateICmpNE(NeedleStartPage, NeedleEndPage,
"needle_page_cmp");
1284 Value *CombinedPageCmp =
1285 Builder.
CreateOr(SearchPageCmp, NeedlePageCmp,
"combined_page_cmp");
1296 Intrinsic::get_active_lane_mask, {PredVTy, I64Ty},
1297 {SearchIdx, SearchTripCount},
nullptr,
"search_pred");
1298 PredSearch = Builder.
CreateAnd(PredVF, PredSearch,
"search_masked");
1299 Value *Search = Builder.
CreateGEP(CharTy, SearchStart, SearchIdx,
"psearch");
1301 CharVTy, Search,
Align(1), PredSearch, Passthru,
"search_load_vec");
1313 Intrinsic::get_active_lane_mask, {PredVTy, I64Ty},
1314 {NeedleIdx, NeedleTripCount},
nullptr,
"needle_pred");
1315 PredNeedle = Builder.
CreateAnd(PredVF, PredNeedle,
"needle_masked");
1316 Value *Needle = Builder.
CreateGEP(CharTy, NeedleStart, NeedleIdx,
"pneedle");
1318 CharVTy, Needle,
Align(1), PredNeedle, Passthru,
"needle_load_vec");
1324 Needle0,
"needle0");
1325 LoadNeedle = Builder.
CreateSelect(PredNeedle, LoadNeedle, Needle0Splat,
1332 Intrinsic::experimental_vector_match, {CharVTy, LoadNeedle->
getType()},
1333 {LoadSearch, LoadNeedle, PredSearch},
nullptr,
"match_segment");
1334 Value *MatchAcc = Builder.
CreateOr(Match, MatchSeg,
"match_accumulator");
1335 Value *NextNeedleIdx =
1336 Builder.
CreateAdd(NeedleIdx, ConstVF,
"needle_idx_next");
1356 Intrinsic::experimental_cttz_elts, {I64Ty, PredVTy},
1357 {MatchPredLCSSA, Builder.
getInt1(
true)},
nullptr,
1360 Builder.
CreateGEP(CharTy, MatchLCSSA, MatchCnt,
"match_res");
1366 Value *NextSearchIdx =
1367 Builder.
CreateAdd(SearchIdx, ConstVF,
"search_idx_next");
1383 MatchPredLCSSA->
addIncoming(MatchPredAccLCSSA, BB3);
1388 if (ExitSucc != ExitFail)
1391 if (Opts.loop_idiom_vectorize_verify) {
1392 OuterLoop->verifyLoop();
1393 InnerLoop->verifyLoop();
1394 if (!OuterLoop->isRecursivelyLCSSAForm(*DT, *LI))
1401void LoopIdiomVectorize::transformFindFirstByte(
1406 BasicBlock *Preheader = CurLoop->getLoopPreheader();
1412 expandFindFirstByte(Builder, DTU, VF, CharTy, IndPhi, ExitSucc, ExitFail,
1413 SearchStart, SearchEnd, NeedleStart, NeedleEnd);
1415 if (Opts.loop_idiom_vectorize_verify && CurLoop->getParentLoop()) {
1416 CurLoop->getParentLoop()->verifyLoop();
1417 if (!CurLoop->getParentLoop()->isRecursivelyLCSSAForm(*DT, *LI))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static void fixSuccessorPhis(Loop *L, Value *ScalarRes, Value *VectorRes, BasicBlock *SuccBB, BasicBlock *IncBB)
This file defines the LoopVectorizationLegality class.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
LLVM Basic Block Representation.
iterator_range< const_phi_iterator > phis() const
Returns a range that iterates over the phis in the basic block.
const Function * getParent() const
Return the enclosing method, or null if none.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
const Instruction & front() const
LLVM_ABI LLVMContext & getContext() const
Get the context in which this basic block lives.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
An abstraction over a floating-point predicate, and a pack of an integer predicate with samesign info...
Conditional Branch instruction.
static CondBrInst * Create(Value *Cond, BasicBlock *IfTrue, BasicBlock *IfFalse, InsertPosition InsertBefore=nullptr)
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
static constexpr UpdateKind Delete
static constexpr UpdateKind Insert
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
static constexpr ElementCount getScalable(ScalarTy MinVal)
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
void applyUpdates(ArrayRef< UpdateT > Updates)
Submit updates to all available trees.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
LLVM_ABI bool isInBounds() const
Determine whether the GEP has the inbounds flag.
Value * getPointerOperand()
Type * getResultElementType() const
unsigned getNumIndices() const
ConstantInt * getInt1(bool V)
Get a constant value representing either true or false.
Value * CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name="")
IntegerType * getInt1Ty()
Fetch the type representing a single bit.
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
CondBrInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, MDNode *BranchWeights=nullptr, MDNode *Unpredictable=nullptr)
Create a conditional 'br Cond, TrueDest, FalseDest' instruction.
LLVM_ABI Value * CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name="")
Return a vector value that contains.
ConstantInt * getTrue()
Get the constant value for i1 true.
LLVM_ABI CallInst * CreateMaskedLoad(Type *Ty, Value *Ptr, Align Alignment, Value *Mask, Value *PassThru=nullptr, const Twine &Name="")
Create a call to Masked Load intrinsic.
LLVM_ABI Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
void SetCurrentDebugLocation(const DebugLoc &L)
Set location information used by debugging information.
Value * CreateLShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
Value * CreateExtractVector(Type *DstType, Value *SrcVec, Value *Idx, const Twine &Name="")
Create a call to the vector.extract intrinsic.
Value * CreateVScale(Type *Ty, const Twine &Name="")
Create a call to llvm.vscale.<Ty>().
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
LLVM_ABI Value * CreateGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="", GEPNoWrapFlags NW=GEPNoWrapFlags::none())
Value * CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name="")
UncondBrInst * CreateBr(BasicBlock *Dest)
Create an unconditional 'br label X' instruction.
LLVM_ABI Value * CreateOrReduce(Value *Src)
Create a vector int OR reduction intrinsic of the source vector.
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
InstTy * Insert(InstTy *I, const Twine &Name="") const
Insert and return the specified instruction.
Value * CreateCountTrailingZeroElems(Type *ResTy, Value *Mask, bool ZeroIsPoison=true, const Twine &Name="")
Create a call to llvm.experimental_cttz_elts.
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
LLVM_ABI Value * CreatePtrDiff(Value *LHS, Value *RHS, const Twine &Name="", bool IsNUW=false)
Return the difference between two pointer values.
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="", bool IsNonNeg=false)
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
LLVM_ABI Value * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > OverloadTypes, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="", ArrayRef< OperandBundleDef > OpBundles={}, function_ref< void(CallInst *)> SetFn=[](CallInst *) {})
Variant to create a possibly constant-folded intrinsic.
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="", bool IsNUW=false, bool IsNSW=false)
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
Value * CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="", bool IsDisjoint=false)
IntegerType * getInt8Ty()
Fetch the type representing an 8-bit integer.
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
iterator_range< user_iterator > users()
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
LLVM_ABI void setSuccessor(unsigned Idx, BasicBlock *BB)
Update the specified successor to point at the provided block.
This is an important class for using LLVM in a threaded context.
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
An instruction for reading from memory.
bool contains(const LoopT *L) const
Return true if the specified loop is contained within this loop.
void addBasicBlockToLoop(BlockT *NewBB, LoopInfoBase< BlockT, LoopT > &LI)
This method is used by other analyses to update loop information.
LoopT * getParentLoop() const
Return the parent loop if it exists or nullptr for top level loops.
LLVM_ABI PreservedAnalyses run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U)
Utility class for getting and setting loop vectorizer hints in the form of loop metadata.
Represents a single loop in the control flow graph.
LLVM_ABI MDNode * createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight, bool IsExpected=false)
Return metadata containing two branch weights.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Class to represent scalable SIMD vectors.
static LLVM_ABI ScalableVectorType * get(Type *ElementType, unsigned MinNumElts)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM_ABI unsigned getIntegerBitWidth() const
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
bool isIntegerTy() const
True if this is an instance of IntegerType.
Unconditional Branch instruction.
static UncondBrInst * Create(BasicBlock *Target, InsertPosition InsertBefore=nullptr)
Value * getOperand(unsigned i) const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
bool hasOneUse() const
Return true if there is exactly one use of this value.
LLVMContext & getContext() const
All values hold a context through their type.
Base class of all SIMD vector types.
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
const ParentTy * getParent() const
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
match_bind< PHINode > m_Phi(PHINode *&PN)
Match a PHI node, capturing it if we match.
br_match m_UnconditionalBr(BasicBlock *&Succ)
bool match(Val *V, const Pattern &P)
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
auto m_BasicBlock()
Match an arbitrary basic block value and ignore it.
auto m_Value()
Match an arbitrary value and ignore it.
auto m_GEP(const OperandTypes &...Ops)
Matches GetElementPtrInst.
SpecificCmpClass_match< LHS, RHS, ICmpInst > m_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R)
OneOps_match< OpTy, Instruction::Load > m_Load(const OpTy &Op)
Matches LoadInst.
CastInst_match< OpTy, ZExtInst > m_ZExt(const OpTy &Op)
Matches ZExt.
BinaryOp_match< LHS, RHS, Instruction::Add, true > m_c_Add(const LHS &L, const RHS &R)
Matches a Add with LHS and RHS in either order.
CmpClass_match< LHS, RHS, ICmpInst > m_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
brc_match< Cond_t, match_bind< BasicBlock >, match_bind< BasicBlock > > m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F)
bool isSimple(Instruction *I)
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
unsigned Log2_64(uint64_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
AnalysisManager< Loop, LoopStandardAnalysisResults & > LoopAnalysisManager
The loop analysis manager.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
OuterAnalysisManagerProxy< FunctionAnalysisManager, Loop, LoopStandardAnalysisResults & > FunctionAnalysisManagerLoopProxy
A proxy from a FunctionAnalysisManager to a Loop.
LLVM_ABI BasicBlock * SplitBlock(BasicBlock *Old, BasicBlock::iterator SplitPt, DominatorTree *DT, LoopInfo *LI=nullptr, MemorySSAUpdater *MSSAU=nullptr, const Twine &BBName="")
Split the specified block at the specified instruction.
DWARFExpression::Operation Op
const VectorizeOptions & getVectorizeOptions(const LLVMContext &C)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
This struct is a compact representation of a valid (non-zero power of two) alignment.
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
TargetTransformInfo & TTI