37#define DEBUG_TYPE "expand-memcmp"
40STATISTIC(NumMemCmpNotConstant,
"Number of memcmp calls without constant size");
42 "Number of memcmp calls with size greater than max size");
43STATISTIC(NumMemCmpInlined,
"Number of inlined memcmp calls");
50static Align getMemCmpArgAlignment(
const CallInst *CI,
unsigned ArgNo,
54 A = std::max(
A, *ParamAlign);
60class MemCmpExpansion {
68 PHINode *PhiSrc1 =
nullptr;
69 PHINode *PhiSrc2 =
nullptr;
71 ResultBlock() =
default;
74 CallInst *
const CI =
nullptr;
77 unsigned MaxLoadSize = 0;
79 const unsigned MaxBytesPerBlock;
80 unsigned MaxBlockSize = 0;
81 std::vector<BasicBlock *> LoadCmpBlocks;
83 PHINode *PhiRes =
nullptr;
84 const bool IsUsedForZeroCmp;
86 const TargetTransformInfo &TTI;
88 const Align CommonAlign;
89 DomTreeUpdater *DTU =
nullptr;
95 LoadEntry(
unsigned LoadSize,
uint64_t Offset)
96 : LoadSize(LoadSize), Offset(Offset) {
104 using LoadEntryVector = SmallVector<LoadEntry, 8>;
105 LoadEntryVector LoadSequence;
107 void createLoadCmpBlocks();
108 void createResultBlock();
109 void setupResultBlockPHINodes();
110 void setupEndBlockPHINodes();
111 Value *getCompareLoadPairs(
unsigned BlockIndex,
unsigned &LoadIndex);
112 LoadPair getPackedLoadPair(
unsigned BlockIndex,
unsigned &LoadIndex);
113 void emitLoadCompareBlock(
unsigned BlockIndex,
unsigned &LoadIndex);
114 void emitLoadCompareBlockMultipleLoads(
unsigned BlockIndex,
115 unsigned &LoadIndex);
116 void emitLoadCompareByteBlock(
unsigned BlockIndex,
unsigned OffsetBytes);
117 void emitMemCmpResultBlock();
118 Value *getMemCmpExpansionZeroCase();
119 Value *getMemCmpEqZeroOneBlock();
120 Value *getMemCmpOneBlock();
121 Value *getMemCmpOneBlockMultipleLoads();
122 Value *getMemCmpResult(
const LoadPair &Loads);
123 LoadPair getLoadPair(
Type *LoadSizeType,
Type *BSwapSizeType,
124 Type *CmpSizeType,
unsigned OffsetBytes);
132 static LoadEntryVector
133 computeGreedyLoadSequence(
uint64_t Size, llvm::ArrayRef<unsigned> LoadSizes,
134 unsigned MaxNumLoads);
135 LoadEntryVector computeOverlappingLoadSequence(
uint64_t Size,
136 unsigned MaxLoadSize,
137 unsigned MaxNumLoads)
const;
139 void optimiseLoadSequence(
140 LoadEntryVector &LoadSequence,
141 const TargetTransformInfo::MemCmpExpansionOptions &
Options,
142 bool IsUsedForZeroCmp)
const;
145 MemCmpExpansion(CallInst *CI,
uint64_t Size,
146 const TargetTransformInfo::MemCmpExpansionOptions &
Options,
147 const bool IsUsedForZeroCmp,
const DataLayout &TheDataLayout,
148 DomTreeUpdater *DTU,
const TargetTransformInfo &TTI,
149 Align CommonAlign,
unsigned MaxBytesPerBlock);
151 unsigned getNumBlocks();
152 unsigned getNumLoadsInBlock(
unsigned LoadIndex)
const;
153 unsigned getNumBytesInBlock(
unsigned LoadIndex,
unsigned NumLoads)
const;
154 uint64_t getNumLoads()
const {
return LoadSequence.size(); }
156 Value *getMemCmpExpansion();
166 Align CommonAlign,
unsigned LoadSize,
174 if (AccessAlign.
value() >= LoadSize)
177 return TTI.allowsMisalignedMemoryAccesses(CI->
getContext(), LoadSize * 8, AS,
185bool MemCmpExpansion::isAccessAllowed(
unsigned LoadSize,
187 return ::isAccessAllowed(CI,
TTI, CommonAlign, LoadSize,
Offset);
190MemCmpExpansion::LoadEntryVector
191MemCmpExpansion::computeGreedyLoadSequence(
uint64_t Size,
192 llvm::ArrayRef<unsigned> LoadSizes,
193 const unsigned MaxNumLoads) {
194 LoadEntryVector LoadSequence;
197 const unsigned LoadSize = LoadSizes.
front();
199 if (LoadSequence.size() + NumLoadsForThisSize > MaxNumLoads) {
206 if (NumLoadsForThisSize > 0) {
207 for (
uint64_t I = 0;
I < NumLoadsForThisSize; ++
I) {
208 LoadSequence.push_back({LoadSize,
Offset});
218MemCmpExpansion::LoadEntryVector
219MemCmpExpansion::computeOverlappingLoadSequence(
221 const unsigned MaxNumLoads)
const {
223 if (
Size < 2 || MaxLoadSize < 2)
228 const uint64_t NumNonOverlappingLoads =
Size / MaxLoadSize;
229 assert(NumNonOverlappingLoads &&
"there must be at least one load");
232 Size =
Size - NumNonOverlappingLoads * MaxLoadSize;
239 if ((NumNonOverlappingLoads + 1) > MaxNumLoads)
243 LoadEntryVector LoadSequence;
245 for (
uint64_t I = 0;
I < NumNonOverlappingLoads; ++
I) {
246 LoadSequence.push_back({MaxLoadSize,
Offset});
254 if (!isAccessAllowed(MaxLoadSize, OverlapOffset))
257 LoadSequence.push_back({MaxLoadSize, OverlapOffset});
261void MemCmpExpansion::optimiseLoadSequence(
262 LoadEntryVector &LoadSequence,
263 const TargetTransformInfo::MemCmpExpansionOptions &
Options,
264 bool IsUsedForZeroCmp)
const {
269 if (IsUsedForZeroCmp ||
Options.AllowedTailExpansions.empty())
272 while (LoadSequence.size() >= 2) {
273 auto Last = LoadSequence[LoadSequence.size() - 1];
274 auto PreLast = LoadSequence[LoadSequence.size() - 2];
277 if (PreLast.Offset + PreLast.LoadSize !=
Last.Offset)
280 auto LoadSize =
Last.LoadSize + PreLast.LoadSize;
281 if (
find(
Options.AllowedTailExpansions, LoadSize) ==
282 Options.AllowedTailExpansions.end())
291 if (LoadSize > MaxLoadSize && LoadSequence.size() > 2)
295 LoadSequence.pop_back();
296 LoadSequence.pop_back();
297 LoadSequence.emplace_back(LoadSize, PreLast.Offset);
309MemCmpExpansion::MemCmpExpansion(
311 const TargetTransformInfo::MemCmpExpansionOptions &
Options,
312 const bool IsUsedForZeroCmp,
const DataLayout &TheDataLayout,
313 DomTreeUpdater *DTU,
const TargetTransformInfo &
TTI, Align CommonAlign,
314 unsigned MaxBytesPerBlock)
316 MaxBytesPerBlock(MaxBytesPerBlock), IsUsedForZeroCmp(IsUsedForZeroCmp),
317 DL(TheDataLayout),
TTI(
TTI), CommonAlign(CommonAlign), DTU(DTU),
320 assert(NumLoadsPerBlock > 0 &&
"zero loads per block");
326 assert(!LoadSizes.
empty() &&
"cannot load Size bytes");
327 MaxLoadSize = LoadSizes.
front();
330 computeGreedyLoadSequence(
Size, LoadSizes,
Options.MaxNumLoads);
331 assert(LoadSequence.size() <=
Options.MaxNumLoads &&
"broken invariant");
334 if (
Options.AllowOverlappingLoads &&
335 (LoadSequence.empty() || LoadSequence.size() > 2)) {
336 auto OverlappingLoads =
337 computeOverlappingLoadSequence(
Size, MaxLoadSize,
Options.MaxNumLoads);
338 if (!OverlappingLoads.empty() &&
339 (LoadSequence.empty() ||
340 OverlappingLoads.size() < LoadSequence.size())) {
341 LoadSequence = OverlappingLoads;
344 assert(LoadSequence.size() <=
Options.MaxNumLoads &&
"broken invariant");
345 optimiseLoadSequence(LoadSequence,
Options, IsUsedForZeroCmp);
347 unsigned LoadIndex = 0;
348 while (LoadIndex < getNumLoads()) {
349 unsigned NumLoads = getNumLoadsInBlock(LoadIndex);
351 std::max(MaxBlockSize, getNumBytesInBlock(LoadIndex, NumLoads));
352 LoadIndex += NumLoads;
358unsigned MemCmpExpansion::getNumLoadsInBlock(
unsigned LoadIndex)
const {
359 if (IsUsedForZeroCmp)
360 return std::min<uint64_t>(getNumLoads() - LoadIndex, NumLoadsPerBlock);
362 unsigned NumLoads = 0;
363 unsigned NumBytes = 0;
364 while (LoadIndex + NumLoads < getNumLoads() && NumLoads < NumLoadsPerBlock &&
365 NumBytes + LoadSequence[LoadIndex + NumLoads].LoadSize <=
367 NumBytes += LoadSequence[LoadIndex + NumLoads].LoadSize;
370 assert(NumLoads &&
"at least one load must fit in a block");
374unsigned MemCmpExpansion::getNumBytesInBlock(
unsigned LoadIndex,
375 unsigned NumLoads)
const {
376 unsigned NumBytes = 0;
377 for (
unsigned I = 0;
I != NumLoads; ++
I)
378 NumBytes += LoadSequence[LoadIndex +
I].LoadSize;
382unsigned MemCmpExpansion::getNumBlocks() {
383 unsigned NumBlocks = 0;
384 for (
unsigned LoadIndex = 0; LoadIndex < getNumLoads(); ++NumBlocks)
385 LoadIndex += getNumLoadsInBlock(LoadIndex);
389void MemCmpExpansion::createLoadCmpBlocks() {
390 for (
unsigned i = 0; i < getNumBlocks(); i++) {
393 LoadCmpBlocks.push_back(BB);
397void MemCmpExpansion::createResultBlock() {
402MemCmpExpansion::LoadPair MemCmpExpansion::getLoadPair(
Type *LoadSizeType,
405 unsigned OffsetBytes) {
409 Align LhsAlign = getMemCmpArgAlignment(CI, 0,
DL);
410 Align RhsAlign = getMemCmpArgAlignment(CI, 1,
DL);
411 if (OffsetBytes > 0) {
412 auto *ByteType = Type::getInt8Ty(CI->
getContext());
420 Value *Lhs =
nullptr;
426 Value *Rhs =
nullptr;
433 if (BSwapSizeType && LoadSizeType != BSwapSizeType) {
441 CI->
getModule(), Intrinsic::bswap, BSwapSizeType);
447 if (CmpSizeType !=
nullptr && CmpSizeType != Lhs->
getType()) {
458void MemCmpExpansion::emitLoadCompareByteBlock(
unsigned BlockIndex,
459 unsigned OffsetBytes) {
462 const LoadPair Loads =
463 getLoadPair(Type::getInt8Ty(CI->
getContext()),
nullptr,
464 Type::getInt32Ty(CI->
getContext()), OffsetBytes);
469 if (BlockIndex < (LoadCmpBlocks.size() - 1)) {
473 ConstantInt::get(Diff->
getType(), 0));
474 Builder.
CreateCondBr(Cmp, EndBlock, LoadCmpBlocks[BlockIndex + 1]);
477 {{DominatorTree::Insert, BB, EndBlock},
478 {DominatorTree::Insert, BB, LoadCmpBlocks[BlockIndex + 1]}});
483 DTU->
applyUpdates({{DominatorTree::Insert, BB, EndBlock}});
490Value *MemCmpExpansion::getCompareLoadPairs(
unsigned BlockIndex,
491 unsigned &LoadIndex) {
492 assert(LoadIndex < getNumLoads() &&
493 "getCompareLoadPairs() called with no remaining loads");
494 std::vector<Value *> XorList, OrList;
495 Value *Diff =
nullptr;
497 const unsigned NumLoads = getNumLoadsInBlock(LoadIndex);
500 if (LoadCmpBlocks.empty())
509 IntegerType *
const MaxLoadType =
510 NumLoads == 1 ? nullptr
513 for (
unsigned i = 0; i < NumLoads; ++i, ++LoadIndex) {
514 const LoadEntry &CurLoadEntry = LoadSequence[LoadIndex];
515 const LoadPair Loads = getLoadPair(
517 MaxLoadType, CurLoadEntry.Offset);
522 Diff = Builder.
CreateXor(Loads.Lhs, Loads.Rhs);
524 XorList.push_back(Diff);
531 auto pairWiseOr = [&](std::vector<Value *> &InList) -> std::vector<Value *> {
532 std::vector<Value *> OutList;
533 for (
unsigned i = 0; i < InList.size() - 1; i = i + 2) {
535 OutList.push_back(
Or);
537 if (InList.size() % 2 != 0)
538 OutList.push_back(InList.back());
544 OrList = pairWiseOr(XorList);
547 while (OrList.size() != 1) {
548 OrList = pairWiseOr(OrList);
551 assert(Diff &&
"Failed to find comparison diff");
558MemCmpExpansion::LoadPair
559MemCmpExpansion::getPackedLoadPair(
unsigned BlockIndex,
unsigned &LoadIndex) {
560 assert(LoadIndex < getNumLoads() &&
561 "getPackedLoadPair() called with no remaining loads");
562 if (LoadCmpBlocks.empty())
567 const unsigned NumLoads = getNumLoadsInBlock(LoadIndex);
568 const unsigned NumBytes = getNumBytesInBlock(LoadIndex, NumLoads);
573 Value *PackedLhs = ConstantInt::get(BlockType, 0);
574 Value *PackedRhs = ConstantInt::get(BlockType, 0);
575 unsigned RemainingBytes = NumBytes;
577 for (
unsigned I = 0;
I != NumLoads; ++
I, ++LoadIndex) {
578 const LoadEntry &
Entry = LoadSequence[LoadIndex];
580 auto *BSwapType =
DL.isLittleEndian() &&
Entry.LoadSize != 1
584 LoadPair Loads = getLoadPair(LoadType, BSwapType, BlockType,
Entry.Offset);
586 if (BSwapType && BSwapType->getIntegerBitWidth() !=
Entry.LoadSize * 8) {
587 unsigned Padding = BSwapType->getIntegerBitWidth() -
Entry.LoadSize * 8;
588 Loads.Lhs = Builder.
CreateLShr(Loads.Lhs, Padding);
589 Loads.Rhs = Builder.
CreateLShr(Loads.Rhs, Padding);
592 RemainingBytes -=
Entry.LoadSize;
593 unsigned Shift = RemainingBytes * 8;
600 return {PackedLhs, PackedRhs};
603void MemCmpExpansion::emitLoadCompareBlockMultipleLoads(
unsigned BlockIndex,
604 unsigned &LoadIndex) {
605 Value *
Cmp = getCompareLoadPairs(BlockIndex, LoadIndex);
607 BasicBlock *NextBB = (BlockIndex == (LoadCmpBlocks.size() - 1))
609 : LoadCmpBlocks[BlockIndex + 1];
613 CondBrInst *CmpBr = Builder.
CreateCondBr(Cmp, ResBlock.BB, NextBB);
617 DTU->
applyUpdates({{DominatorTree::Insert, BB, ResBlock.BB},
618 {DominatorTree::Insert, BB, NextBB}});
623 if (BlockIndex == LoadCmpBlocks.size() - 1) {
625 PhiRes->
addIncoming(Zero, LoadCmpBlocks[BlockIndex]);
638void MemCmpExpansion::emitLoadCompareBlock(
unsigned BlockIndex,
639 unsigned &LoadIndex) {
640 const unsigned NumLoads = getNumLoadsInBlock(LoadIndex);
641 if (NumLoads == 1 && LoadSequence[LoadIndex].LoadSize == 1) {
642 MemCmpExpansion::emitLoadCompareByteBlock(BlockIndex,
643 LoadSequence[LoadIndex].
Offset);
650 const LoadEntry &
Entry = LoadSequence[LoadIndex++];
652 auto *BSwapType =
DL.isLittleEndian()
658 Loads = getLoadPair(LoadType, BSwapType, CmpType,
Entry.Offset);
660 Loads = getPackedLoadPair(BlockIndex, LoadIndex);
665 if (!IsUsedForZeroCmp) {
666 ResBlock.PhiSrc1->addIncoming(Loads.Lhs, LoadCmpBlocks[BlockIndex]);
667 ResBlock.PhiSrc2->addIncoming(Loads.Rhs, LoadCmpBlocks[BlockIndex]);
671 BasicBlock *NextBB = (BlockIndex == (LoadCmpBlocks.size() - 1))
673 : LoadCmpBlocks[BlockIndex + 1];
677 CondBrInst *CmpBr = Builder.
CreateCondBr(Cmp, NextBB, ResBlock.BB);
682 {DominatorTree::Insert, BB, ResBlock.BB}});
687 if (BlockIndex == LoadCmpBlocks.size() - 1) {
689 PhiRes->
addIncoming(Zero, LoadCmpBlocks[BlockIndex]);
696void MemCmpExpansion::emitMemCmpResultBlock() {
699 if (IsUsedForZeroCmp) {
706 DTU->
applyUpdates({{DominatorTree::Insert, ResBlock.BB, EndBlock}});
724 DTU->
applyUpdates({{DominatorTree::Insert, ResBlock.BB, EndBlock}});
727void MemCmpExpansion::setupResultBlockPHINodes() {
730 ResBlock.PhiSrc1 = Builder.
CreatePHI(MaxLoadType, getNumBlocks(),
"phi.src1");
731 ResBlock.PhiSrc2 = Builder.
CreatePHI(MaxLoadType, getNumBlocks(),
"phi.src2");
734void MemCmpExpansion::setupEndBlockPHINodes() {
739Value *MemCmpExpansion::getMemCmpExpansionZeroCase() {
740 unsigned LoadIndex = 0;
743 for (
unsigned I = 0;
I < getNumBlocks(); ++
I) {
744 emitLoadCompareBlockMultipleLoads(
I, LoadIndex);
747 emitMemCmpResultBlock();
754Value *MemCmpExpansion::getMemCmpEqZeroOneBlock() {
755 unsigned LoadIndex = 0;
756 Value *
Cmp = getCompareLoadPairs(0, LoadIndex);
757 assert(LoadIndex == getNumLoads() &&
"some entries were not consumed");
766Value *MemCmpExpansion::getMemCmpOneBlock() {
767 bool NeedsBSwap =
DL.isLittleEndian() &&
Size != 1;
769 Type *BSwapSizeType =
779 const LoadPair Loads = getLoadPair(LoadSizeType, BSwapSizeType,
781 return Builder.
CreateSub(Loads.Lhs, Loads.Rhs);
784 const LoadPair Loads = getLoadPair(LoadSizeType, BSwapSizeType, MaxLoadType,
787 return getMemCmpResult(Loads);
790Value *MemCmpExpansion::getMemCmpOneBlockMultipleLoads() {
791 unsigned LoadIndex = 0;
792 LoadPair Loads = getPackedLoadPair(0, LoadIndex);
793 assert(LoadIndex == getNumLoads() &&
"some entries were not consumed");
794 return getMemCmpResult(Loads);
797Value *MemCmpExpansion::getMemCmpResult(
const LoadPair &Loads) {
803 CmpPredicate Pred = ICmpInst::Predicate::BAD_ICMP_PREDICATE;
804 bool NeedsZExt =
false;
813 Pred = ICmpInst::ICMP_SLT;
818 Pred = ICmpInst::ICMP_SGE;
822 Pred = ICmpInst::ICMP_SLE;
828 if (ICmpInst::isSigned(Pred)) {
830 Loads.Lhs, Loads.Rhs);
832 UI->replaceAllUsesWith(Result);
833 UI->eraseFromParent();
841 {Loads.Lhs, Loads.Rhs});
846Value *MemCmpExpansion::getMemCmpExpansion() {
848 if (getNumBlocks() != 1) {
850 EndBlock =
SplitBlock(StartBlock, CI, DTU,
nullptr,
851 nullptr,
"endblock");
852 setupEndBlockPHINodes();
859 if (!IsUsedForZeroCmp) setupResultBlockPHINodes();
862 createLoadCmpBlocks();
868 DTU->
applyUpdates({{DominatorTree::Insert, StartBlock, LoadCmpBlocks[0]},
869 {DominatorTree::Delete, StartBlock, EndBlock}});
874 if (IsUsedForZeroCmp)
875 return getNumBlocks() == 1 ? getMemCmpEqZeroOneBlock()
876 : getMemCmpExpansionZeroCase();
878 if (getNumBlocks() == 1)
879 return getNumLoads() == 1 ? getMemCmpOneBlock()
880 : getMemCmpOneBlockMultipleLoads();
882 unsigned LoadIndex = 0;
883 for (
unsigned I = 0;
I < getNumBlocks(); ++
I) {
884 emitLoadCompareBlock(
I, LoadIndex);
887 emitMemCmpResultBlock();
964static bool expandMemCmp(CallInst *CI,
const TargetTransformInfo *
TTI,
965 const DataLayout *
DL, ProfileSummaryInfo *PSI,
966 BlockFrequencyInfo *BFI, DomTreeUpdater *DTU,
968 const ScalarOptions &Opts = ScalarOptions::Global;
978 NumMemCmpNotConstant++;
988 const bool IsUsedForZeroCmp =
995 if (Opts.memcmp_num_loads_per_block)
998 if (OptForSize && Opts.max_loads_per_memcmp_opt_size)
999 Options.MaxNumLoads = *Opts.max_loads_per_memcmp_opt_size;
1001 if (!OptForSize && Opts.max_loads_per_memcmp)
1002 Options.MaxNumLoads = *Opts.max_loads_per_memcmp;
1013 const Align CommonAlign = std::min(getMemCmpArgAlignment(CI, 0, *
DL),
1014 getMemCmpArgAlignment(CI, 1, *
DL));
1018 const unsigned MaxBytesPerBlock =
Options.LoadSizes.front();
1020 return !isAccessAllowed(CI, *TTI, CommonAlign, LoadSize, 0);
1026 if (
Options.LoadSizes.empty())
1030 *
TTI, CommonAlign, MaxBytesPerBlock);
1034 NumMemCmpGreaterThanMax++;
1050 const TargetTransformInfo *
TTI,
1051 ProfileSummaryInfo *PSI,
1052 BlockFrequencyInfo *BFI, DominatorTree *DT) {
1053 std::optional<DomTreeUpdater> DTU;
1055 DTU.emplace(DT, DomTreeUpdater::UpdateStrategy::Lazy);
1057 const DataLayout&
DL =
F.getDataLayout();
1062 if (Func == LibFunc_memcmp || Func == LibFunc_bcmp)
1067 bool MadeChanges =
false;
1068 for (
const auto &[CI, Func] : MemCmpCalls) {
1069 if (expandMemCmp(CI,
TTI, &
DL, PSI, BFI, DTU ? &*DTU :
nullptr,
1070 Func == LibFunc_bcmp))
1075 for (BasicBlock &BB :
F)
1079 PreservedAnalyses PA;
1080 PA.
preserve<DominatorTreeAnalysis>();
1090 if (
F.hasFnAttribute(Attribute::SanitizeAddress) ||
1091 F.hasFnAttribute(Attribute::SanitizeMemory) ||
1092 F.hasFnAttribute(Attribute::SanitizeThread) ||
1093 F.hasFnAttribute(Attribute::SanitizeHWAddress))
1099 .getCachedResult<ProfileSummaryAnalysis>(*
F.getParent());
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Expand Atomic instructions
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static bool runImpl(MachineFunction &MF)
FunctionAnalysisManager FAM
This file contains the declarations for profiling metadata utility functions.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
const T & front() const
Get the first element.
bool empty() const
Check if the array is empty.
iterator begin()
Instruction iterator methods.
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.
InstListType::iterator iterator
Instruction iterators...
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
Analysis pass which computes BlockFrequencyInfo.
BlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate IR basic block frequen...
MaybeAlign getParamAlign(unsigned ArgNo) const
Extract the alignment for a call or parameter (0=unknown).
Value * getArgOperand(unsigned i) const
This class represents a function call, abstracting a target machine's calling convention.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
A parsed version of the target data layout string in and methods for querying it.
Analysis pass which computes a DominatorTree.
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
bool hasMinSize() const
Optimize this function for minimum size (-Oz).
void applyUpdates(ArrayRef< UpdateT > Updates)
Submit updates to all available trees.
Predicate getUnsignedPredicate() const
For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
Value * CreateConstGEP1_64(Type *Ty, Value *Ptr, uint64_t Idx0, const Twine &Name="")
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, const char *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 * 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.
BasicBlock * GetInsertBlock() const
Value * CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name="")
UncondBrInst * CreateBr(BasicBlock *Dest)
Create an unconditional 'br label X' instruction.
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="", bool IsNonNeg=false)
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.
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
Value * CreateXor(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="", bool IsDisjoint=false)
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_ABI const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
user_iterator user_begin()
LLVM_ABI void setSuccessor(unsigned Idx, BasicBlock *BB)
Update the specified successor to point at the provided block.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserve()
Mark an analysis as preserved.
void push_back(const T &Elt)
Analysis pass providing the TargetTransformInfo.
Analysis pass providing the TargetLibraryInfo.
LibFunc getLibFunc(StringRef funcName) const
Searches for a particular function name.
LLVM_ABI unsigned getIntegerBitWidth() const
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI bool hasOneUser() const
Return true if there is exactly one user of this value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVMContext & getContext() const
All values hold a context through their type.
LLVM_ABI Align getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
const ParentTy * getParent() const
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
@ BasicBlock
Various leaf nodes.
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > OverloadTys={})
Look up the Function declaration of the intrinsic id in the Module M.
AllOnesConstantMatch m_AllOnes()
specific_intval< false > m_SpecificInt(const APInt &V)
Match a specific integer value or vector with all elements equal to the value.
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_Value()
Match an arbitrary value and ignore it.
SpecificCmpClass_match< LHS, RHS, ICmpInst > m_SpecificICmp(CmpPredicate MatchPred, const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)
CmpClass_match< LHS, RHS, ICmpInst > m_ICmp(CmpPredicate &Pred, const LHS &L, const RHS &R)
is_zero m_Zero()
Match any null constant or a vector with all elements equal to 0.
BlockType
Used as immediate MachineOperands for block signatures.
NodeAddr< FuncNode * > Func
This is an optimization pass for GlobalISel generic memory operations.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI void setExplicitlyUnknownBranchWeightsIfProfiled(Instruction &I, StringRef PassName, const Function *F=nullptr)
Like setExplicitlyUnknownBranchWeights(...), but only sets unknown branch weights in the new instruct...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
OuterAnalysisManagerProxy< ModuleAnalysisManager, Function > ModuleAnalysisManagerFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
LLVM_ABI bool shouldOptimizeForSize(const MachineFunction *MF, ProfileSummaryInfo *PSI, const MachineBlockFrequencyInfo *BFI, PGSOQueryType QueryType=PGSOQueryType::Other)
Returns true if machine function MF is suggested to be size-optimized based on the profile.
LLVM_ABI bool SimplifyInstructionsInBlock(BasicBlock *BB, const TargetLibraryInfo *TLI=nullptr)
Scan the specified basic block and try to simplify any instructions in it and recursively delete dead...
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
uint64_t PowerOf2Ceil(uint64_t A)
Returns the power of two which is greater than or equal to the given value.
IRBuilder(LLVMContext &, FolderTy, InserterTy) -> IRBuilder< FolderTy, InserterTy >
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
@ Or
Bitwise or logical OR of integers.
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.
LLVM_ABI bool isOnlyUsedInZeroEqualityComparison(const Instruction *CtxI)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
LLVM_ABI Constant * ConstantFoldLoadFromConstPtr(Constant *C, Type *Ty, APInt Offset, const DataLayout &DL)
Return the value that a load from C with offset Offset would produce if it is constant and determinab...
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
This struct is a compact representation of a valid (non-zero power of two) alignment.
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.