24#define DEBUG_TYPE "lower-mem-intrinsics"
35 Value *OpSize,
unsigned OpSizeVal) {
38 return B.CreateAnd(Len, OpSizeVal - 1);
39 return B.CreateURem(Len, OpSize);
48 Value *RTLoopRemainder =
nullptr) {
51 return B.CreateSub(Len, RTLoopRemainder);
56struct LoopExpansionInfo {
61 Value *MainLoopIndex =
nullptr;
69 Value *ResidualLoopIndex =
nullptr;
72std::optional<uint64_t> getAverageMemOpLoopTripCount(
const MemIntrinsic &
I) {
75 if (std::optional<Function::ProfileCount> EC =
76 I.getFunction()->getEntryCount();
77 !EC || !
EC->getCount())
79 if (
const auto Len =
I.getLengthInBytes())
80 return Len->getZExtValue();
84 std::numeric_limits<uint32_t>::max(),
Total);
88 for (
const auto &
P : ProfData)
89 TripCount +=
P.Count *
P.Value;
90 return std::round(1.0 * TripCount /
Total);
127static LoopExpansionInfo
129 unsigned MainLoopStep,
unsigned ResidualLoopStep,
131 std::optional<uint64_t> AverageTripCount) {
132 assert((ResidualLoopStep == 0 || MainLoopStep % ResidualLoopStep == 0) &&
133 "ResidualLoopStep must divide MainLoopStep if specified");
134 assert(ResidualLoopStep <= MainLoopStep &&
135 "ResidualLoopStep cannot be larger than MainLoopStep");
136 assert(MainLoopStep > 0 &&
"MainLoopStep must be non-zero");
137 LoopExpansionInfo LEI;
140 InsertBefore, BBNamePrefix +
"-post-expansion");
147 Type *LenType = Len->getType();
149 ConstantInt *CIMainLoopStep = ConstantInt::get(ILenType, MainLoopStep);
151 Value *LoopUnits = Len;
152 Value *ResidualUnits =
nullptr;
155 bool MustTakeMainLoop =
false;
156 if (MainLoopStep != 1) {
158 uint64_t TotalUnits = CLen->getZExtValue();
160 uint64_t ResidualCount = TotalUnits - LoopEndCount;
161 LoopUnits = ConstantInt::get(LenType, LoopEndCount);
162 ResidualUnits = ConstantInt::get(LenType, ResidualCount);
163 MustTakeMainLoop = LoopEndCount > 0;
171 CIMainLoopStep, MainLoopStep);
173 MainLoopStep, ResidualUnits);
176 MustTakeMainLoop = CLen->getZExtValue() > 0;
180 Ctx, BBNamePrefix +
"-expansion-main-body", ParentFunc, PostLoopBB);
184 LEI.MainLoopIndex = LoopIndex;
185 LoopIndex->
addIncoming(ConstantInt::get(LenType, 0U), PreLoopBB);
188 LoopBuilder.
CreateAdd(LoopIndex, ConstantInt::get(LenType, MainLoopStep));
195 if (ResidualLoopStep > 0 && ResidualLoopStep < MainLoopStep) {
206 ConstantInt *Zero = ConstantInt::get(ILenType, 0U);
207 if (MustTakeMainLoop)
208 PreLoopBuilder.
CreateBr(MainLoopBB);
211 PreLoopBuilder.
CreateICmpNE(LoopUnits, Zero), MainLoopBB,
213 if (AverageTripCount.has_value()) {
216 {AverageTripCount.value() % MainLoopStep, 1},
227 MainLoopBB, ResidualCondBB);
232 ResLoopBB, PostLoopBB);
236 ResBuilder.
CreatePHI(LenType, 2,
"residual-loop-index");
241 Value *FullOffset = ResBuilder.
CreateAdd(LoopUnits, ResidualIndex);
242 LEI.ResidualLoopIndex = FullOffset;
245 ResidualIndex, ConstantInt::get(LenType, ResidualLoopStep));
246 ResidualIndex->
addIncoming(ResNewIndex, ResLoopBB);
254 ResBuilder.
CreateICmpULT(ResNewIndex, ResidualUnits), ResLoopBB,
262 if (MustTakeMainLoop) {
263 PreLoopBuilder.
CreateBr(MainLoopBB);
265 ConstantInt *Zero = ConstantInt::get(ILenType, 0U);
268 MainLoopBB, PostLoopBB,
269 B.createLikelyBranchWeights());
274 LoopBuilder.
CreateICmpULT(NewIndex, LoopUnits), MainLoopBB, PostLoopBB);
275 if (AverageTripCount.has_value())
287 bool SrcIsVolatile,
bool DstIsVolatile,
290 std::optional<uint32_t> AtomicElementSize,
291 std::optional<uint64_t> AverageTripCount) {
309 Type *LoopOpType =
TTI.getMemcpyLoopLoweringType(
310 Ctx, CopyLen, SrcAS, DstAS, SrcAlign, DstAlign, AtomicElementSize);
312 "Atomic memcpy lowering is not supported for vector operand type");
315 unsigned LoopOpSize =
DL.getTypeStoreSize(LoopOpType);
316 assert((!AtomicElementSize || LoopOpSize % *AtomicElementSize == 0) &&
317 "Atomic memcpy lowering is not supported for selected operand size");
322 if (LoopEndCount != 0) {
323 LoopExpansionInfo LEI =
325 "static-memcpy", AverageTripCount);
339 LoopOpType, SrcGEP, PartSrcAlign, SrcIsVolatile);
342 Load->setMetadata(LLVMContext::MD_alias_scope,
348 Load, DstGEP, PartDstAlign, DstIsVolatile);
351 Store->setMetadata(LLVMContext::MD_noalias,
MDNode::get(Ctx, NewScope));
353 if (AtomicElementSize) {
357 assert(!LEI.ResidualLoopIP && !LEI.ResidualLoopIndex &&
358 "No residual loop was requested");
362 uint64_t BytesCopied = LoopEndCount;
364 if (RemainingBytes == 0)
369 TTI.getMemcpyLoopResidualLoweringType(RemainingOps, Ctx, RemainingBytes,
370 SrcAS, DstAS, SrcAlign, DstAlign,
373 for (
auto *OpTy : RemainingOps) {
377 unsigned OperandSize =
DL.getTypeStoreSize(OpTy);
378 assert((!AtomicElementSize || OperandSize % *AtomicElementSize == 0) &&
379 "Atomic memcpy lowering is not supported for selected operand size");
382 Int8Type, SrcAddr, ConstantInt::get(TypeOfCopyLen, BytesCopied));
387 Load->setMetadata(LLVMContext::MD_alias_scope,
391 Int8Type, DstAddr, ConstantInt::get(TypeOfCopyLen, BytesCopied));
396 Store->setMetadata(LLVMContext::MD_noalias,
MDNode::get(Ctx, NewScope));
398 if (AtomicElementSize) {
402 BytesCopied += OperandSize;
405 "Bytes copied should match size in the call!");
410 Align SrcAlign,
Align DstAlign,
bool SrcIsVolatile,
bool DstIsVolatile,
412 std::optional<uint32_t> AtomicElementSize,
413 std::optional<uint64_t> AverageTripCount) {
419 MDNode *NewDomain = MDB.createAnonymousAliasScopeDomain(
"MemCopyDomain");
421 MDNode *NewScope = MDB.createAnonymousAliasScope(NewDomain, Name);
426 Type *LoopOpType =
TTI.getMemcpyLoopLoweringType(
427 Ctx, CopyLen, SrcAS, DstAS, SrcAlign, DstAlign, AtomicElementSize);
429 "Atomic memcpy lowering is not supported for vector operand type");
430 unsigned LoopOpSize =
DL.getTypeStoreSize(LoopOpType);
431 assert((!AtomicElementSize || LoopOpSize % *AtomicElementSize == 0) &&
432 "Atomic memcpy lowering is not supported for selected operand size");
436 Type *ResidualLoopOpType = AtomicElementSize
439 unsigned ResidualLoopOpSize =
DL.getTypeStoreSize(ResidualLoopOpType);
440 assert(ResidualLoopOpSize == (AtomicElementSize ? *AtomicElementSize : 1) &&
441 "Store size is expected to match type size");
443 LoopExpansionInfo LEI =
445 "dynamic-memcpy", AverageTripCount);
457 MainLoopBuilder.CreateInBoundsGEP(Int8Type, SrcAddr, LEI.MainLoopIndex);
458 LoadInst *Load = MainLoopBuilder.CreateAlignedLoad(
459 LoopOpType, SrcGEP, PartSrcAlign, SrcIsVolatile);
462 Load->setMetadata(LLVMContext::MD_alias_scope,
MDNode::get(Ctx, NewScope));
465 MainLoopBuilder.CreateInBoundsGEP(Int8Type, DstAddr, LEI.MainLoopIndex);
467 Load, DstGEP, PartDstAlign, DstIsVolatile);
472 if (AtomicElementSize) {
478 if (!LEI.ResidualLoopIP)
485 Value *ResSrcGEP = ResLoopBuilder.CreateInBoundsGEP(Int8Type, SrcAddr,
486 LEI.ResidualLoopIndex);
487 LoadInst *ResLoad = ResLoopBuilder.CreateAlignedLoad(
488 ResidualLoopOpType, ResSrcGEP, ResSrcAlign, SrcIsVolatile);
494 Value *ResDstGEP = ResLoopBuilder.CreateInBoundsGEP(Int8Type, DstAddr,
495 LEI.ResidualLoopIndex);
496 StoreInst *ResStore = ResLoopBuilder.CreateAlignedStore(
497 ResLoad, ResDstGEP, ResDstAlign, DstIsVolatile);
502 if (AtomicElementSize) {
512static std::pair<Value *, Value *>
515 Value *ResAddr1 = Addr1;
516 Value *ResAddr2 = Addr2;
521 if (
TTI.isValidAddrSpaceCast(AS2, AS1))
522 ResAddr2 =
B.CreateAddrSpaceCast(Addr2, Addr1->
getType());
523 else if (
TTI.isValidAddrSpaceCast(AS1, AS2))
524 ResAddr1 =
B.CreateAddrSpaceCast(Addr1, Addr2->
getType());
527 "support addrspacecast");
529 return {ResAddr1, ResAddr2};
561 Align DstAlign,
bool SrcIsVolatile,
572 Type *LoopOpType =
TTI.getMemcpyLoopLoweringType(Ctx, CopyLen, SrcAS, DstAS,
574 unsigned LoopOpSize =
DL.getTypeStoreSize(LoopOpType);
576 bool LoopOpIsInt8 = LoopOpType == Int8Type;
580 bool RequiresResidual = !LoopOpIsInt8;
582 Type *ResidualLoopOpType = Int8Type;
583 unsigned ResidualLoopOpSize =
DL.getTypeStoreSize(ResidualLoopOpType);
587 ConstantInt *CILoopOpSize = ConstantInt::get(ILengthType, LoopOpSize);
589 ConstantInt::get(ILengthType, ResidualLoopOpSize);
590 ConstantInt *Zero = ConstantInt::get(ILengthType, 0);
594 Value *RuntimeLoopBytes = CopyLen;
595 Value *RuntimeLoopRemainder =
nullptr;
596 Value *SkipResidualCondition =
nullptr;
597 if (RequiresResidual) {
598 RuntimeLoopRemainder =
601 LoopOpSize, RuntimeLoopRemainder);
602 SkipResidualCondition =
603 PLBuilder.
CreateICmpEQ(RuntimeLoopRemainder, Zero,
"skip_residual");
605 Value *SkipMainCondition =
606 PLBuilder.
CreateICmpEQ(RuntimeLoopBytes, Zero,
"skip_main");
617 auto [CmpSrcAddr, CmpDstAddr] =
620 PLBuilder.
CreateICmpULT(CmpSrcAddr, CmpDstAddr,
"compare_src_dst");
623 &ThenTerm, &ElseTerm);
650 CopyBackwardsBB->
setName(
"memmove_copy_backwards");
652 CopyForwardBB->
setName(
"memmove_copy_forward");
654 ExitBB->
setName(
"memmove_done");
667 F->getContext(),
"memmove_bwd_main_loop",
F, CopyForwardBB);
673 if (RequiresResidual) {
676 F->getContext(),
"memmove_bwd_residual_loop",
F, MainLoopBB);
680 ResidualLoopPhi, CIResidualLoopOpSize,
"bwd_residual_index");
688 ResidualLoopOpType, LoadGEP, ResidualSrcAlign, SrcIsVolatile,
693 ResidualDstAlign, DstIsVolatile);
697 F->getContext(),
"memmove_bwd_middle",
F, MainLoopBB);
702 ResidualLoopBuilder.
CreateICmpEQ(ResidualIndex, RuntimeLoopBytes),
703 IntermediateBB, ResidualLoopBB);
705 ResidualLoopPhi->
addIncoming(ResidualIndex, ResidualLoopBB);
706 ResidualLoopPhi->
addIncoming(CopyLen, CopyBackwardsBB);
713 PredBB = IntermediateBB;
720 MainLoopBuilder.
CreateSub(MainLoopPhi, CILoopOpSize,
"bwd_main_index");
724 LoopOpType, LoadGEP, PartSrcAlign, SrcIsVolatile,
"element");
732 MainLoopPhi->
addIncoming(RuntimeLoopBytes, PredBB);
748 MainLoopBuilder.
CreatePHI(ILengthType, 0,
"fwd_main_index");
752 LoopOpType, LoadGEP, PartSrcAlign, SrcIsVolatile,
"element");
757 Value *MainIndex = MainLoopBuilder.
CreateAdd(MainLoopPhi, CILoopOpSize);
763 if (RequiresResidual)
769 MainLoopBuilder.
CreateICmpEQ(MainIndex, RuntimeLoopBytes), SuccessorBB,
777 if (RequiresResidual) {
781 F->getContext(),
"memmove_fwd_residual_loop",
F, ExitBB);
782 IntermediateBuilder.
CreateCondBr(SkipResidualCondition, ExitBB,
788 ResidualLoopBuilder.
CreatePHI(ILengthType, 0,
"fwd_residual_index");
792 ResidualLoopOpType, LoadGEP, ResidualSrcAlign, SrcIsVolatile,
797 ResidualDstAlign, DstIsVolatile);
798 Value *ResidualIndex =
799 ResidualLoopBuilder.
CreateAdd(ResidualLoopPhi, CIResidualLoopOpSize);
801 ResidualLoopBuilder.
CreateICmpEQ(ResidualIndex, CopyLen), ExitBB,
803 ResidualLoopPhi->
addIncoming(ResidualIndex, ResidualLoopBB);
804 ResidualLoopPhi->
addIncoming(RuntimeLoopBytes, IntermediateBB);
815 Align DstAlign,
bool SrcIsVolatile,
830 Type *LoopOpType =
TTI.getMemcpyLoopLoweringType(Ctx, CopyLen, SrcAS, DstAS,
832 unsigned LoopOpSize =
DL.getTypeStoreSize(LoopOpType);
840 ConstantInt *Zero = ConstantInt::get(ILengthType, 0);
841 ConstantInt *LoopBound = ConstantInt::get(ILengthType, BytesCopiedInLoop);
842 ConstantInt *CILoopOpSize = ConstantInt::get(ILengthType, LoopOpSize);
846 auto [CmpSrcAddr, CmpDstAddr] =
849 PLBuilder.
CreateICmpULT(CmpSrcAddr, CmpDstAddr,
"compare_src_dst");
852 &ThenTerm, &ElseTerm);
857 ExitBB->
setName(
"memmove_done");
869 unsigned OperandSize =
DL.getTypeStoreSize(OpTy);
875 Value *SrcGEP = Builder.CreateInBoundsGEP(
876 Int8Type, SrcAddr, ConstantInt::get(TypeOfCopyLen, BytesCopied));
878 Builder.CreateAlignedLoad(OpTy, SrcGEP, ResSrcAlign, SrcIsVolatile);
879 Value *DstGEP = Builder.CreateInBoundsGEP(
880 Int8Type, DstAddr, ConstantInt::get(TypeOfCopyLen, BytesCopied));
881 Builder.CreateAlignedStore(Load, DstGEP, ResDstAlign, DstIsVolatile);
882 BytesCopied += OperandSize;
886 if (RemainingBytes != 0) {
887 CopyBackwardsBB->
setName(
"memmove_bwd_residual");
888 uint64_t BytesCopied = BytesCopiedInLoop;
898 TTI.getMemcpyLoopResidualLoweringType(RemainingOps, Ctx, RemainingBytes,
899 SrcAS, DstAS, PartSrcAlign,
901 for (
auto *OpTy : RemainingOps) {
905 GenerateResidualLdStPair(OpTy, BwdResBuilder, BytesCopied);
908 if (BytesCopiedInLoop != 0) {
911 if (RemainingBytes != 0) {
915 PredBB = CopyBackwardsBB;
917 CopyBackwardsBB->
setName(
"memmove_bwd_loop");
921 Value *Index = LoopBuilder.
CreateSub(LoopPhi, CILoopOpSize,
"bwd_index");
924 LoopOpType, LoadGEP, PartSrcAlign, SrcIsVolatile,
"element");
942 if (BytesCopiedInLoop != 0) {
943 CopyForwardBB->
setName(
"memmove_fwd_loop");
946 if (RemainingBytes != 0) {
949 "memmove_fwd_residual");
950 FwdResidualBB = SuccBB;
956 LoopOpType, LoadGEP, PartSrcAlign, SrcIsVolatile,
"element");
971 if (RemainingBytes != 0) {
972 uint64_t BytesCopied = BytesCopiedInLoop;
978 TTI.getMemcpyLoopResidualLoweringType(RemainingOps, Ctx, RemainingBytes,
979 SrcAS, DstAS, PartSrcAlign,
981 for (
auto *OpTy : RemainingOps)
982 GenerateResidualLdStPair(OpTy, FwdResBuilder, BytesCopied);
988 std::optional<uint64_t> AverageTripCount,
1001 auto *ToLoopBR = Builder.CreateCondBr(
1002 Builder.CreateICmpEQ(ConstantInt::get(TypeOfCopyLen, 0), CopyLen), NewBB,
1005 if (AverageTripCount.has_value())
1006 ToLoopBR->setMetadata(LLVMContext::MD_prof,
1013 unsigned PartSize =
DL.getTypeStoreSize(
SetValue->getType());
1018 LoopIndex->
addIncoming(ConstantInt::get(TypeOfCopyLen, 0), OrigBB);
1023 PartAlign, IsVolatile);
1026 LoopBuilder.
CreateAdd(LoopIndex, ConstantInt::get(TypeOfCopyLen, 1));
1030 LoopBuilder.
CreateICmpULT(NewIndex, CopyLen), LoopBB, NewBB);
1031 if (AverageTripCount.has_value())
1038template <
typename T>
1042 const SCEV *DestSCEV = SE->
getSCEV(Memcpy->getRawDest());
1053 auto TripCount = getAverageMemOpLoopTripCount(*Memcpy);
1093 bool DstIsVolatile = SrcIsVolatile;
1098 if (SrcAS != DstAS) {
1099 if (!
TTI.addrspacesMayAlias(SrcAS, DstAS)) {
1102 auto AverageTripCount = getAverageMemOpLoopTripCount(*Memmove);
1105 Memmove, SrcAddr, DstAddr, CI, SrcAlign, DstAlign,
1106 SrcIsVolatile, DstIsVolatile,
1107 false,
TTI, std::nullopt, AverageTripCount);
1110 Memmove, SrcAddr, DstAddr, CopyLen, SrcAlign,
1111 DstAlign, SrcIsVolatile, DstIsVolatile,
1112 false,
TTI, std::nullopt, AverageTripCount);
1118 if (!(
TTI.isValidAddrSpaceCast(DstAS, SrcAS) ||
1119 TTI.isValidAddrSpaceCast(SrcAS, DstAS))) {
1124 dbgs() <<
"Do not know how to expand memmove between different "
1125 "address spaces\n");
1132 Memmove, SrcAddr, DstAddr, CI, SrcAlign, DstAlign,
1133 SrcIsVolatile, DstIsVolatile,
TTI);
1136 Memmove, SrcAddr, DstAddr, CopyLen, SrcAlign, DstAlign,
1137 SrcIsVolatile, DstIsVolatile,
TTI);
1148 getAverageMemOpLoopTripCount(*Memset),
1158 getAverageMemOpLoopTripCount(*Memset),
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static void SetValue(Value *V, GenericValue Val, ExecutionContext &SF)
static std::pair< Value *, Value * > tryInsertCastToCommonAddrSpace(IRBuilderBase &B, Value *Addr1, Value *Addr2, const TargetTransformInfo &TTI)
static bool canOverlap(MemTransferBase< T > *Memcpy, ScalarEvolution *SE)
static LoopExpansionInfo insertLoopExpansion(Instruction *InsertBefore, Value *Len, unsigned MainLoopStep, unsigned ResidualLoopStep, StringRef BBNamePrefix, std::optional< uint64_t > AverageTripCount)
Insert the control flow and loop counters for a memcpy/memset loop expansion.
static void createMemMoveLoopKnownSize(Instruction *InsertBefore, Value *SrcAddr, Value *DstAddr, ConstantInt *CopyLen, Align SrcAlign, Align DstAlign, bool SrcIsVolatile, bool DstIsVolatile, const TargetTransformInfo &TTI)
static Value * getRuntimeLoopRemainder(IRBuilderBase &B, Value *Len, Value *OpSize, unsigned OpSizeVal)
static Value * getRuntimeLoopUnits(IRBuilderBase &B, Value *Len, Value *OpSize, unsigned OpSizeVal, Value *RTLoopRemainder=nullptr)
static void createMemMoveLoopUnknownSize(Instruction *InsertBefore, Value *SrcAddr, Value *DstAddr, Value *CopyLen, Align SrcAlign, Align DstAlign, bool SrcIsVolatile, bool DstIsVolatile, const TargetTransformInfo &TTI)
static void createMemSetLoop(Instruction *InsertBefore, Value *DstAddr, Value *CopyLen, Value *SetValue, Align DstAlign, std::optional< uint64_t > AverageTripCount, bool IsVolatile)
This file contains the declarations for profiling metadata utility functions.
This class represents any memcpy intrinsic i.e.
uint32_t getElementSizeInBytes() const
LLVM Basic Block Representation.
const Function * getParent() const
Return the enclosing method, or null if none.
LLVM_ABI InstListType::const_iterator getFirstNonPHIIt() const
Returns an iterator to the first instruction in this block that is not a PHINode instruction.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
LLVM_ABI BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="", bool Before=false)
Split the basic block into two basic blocks at the specified instruction.
LLVM_ABI LLVMContext & getContext() const
Get the context in which this basic block lives.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
static BranchInst * Create(BasicBlock *IfTrue, InsertPosition InsertBefore=nullptr)
This is the shared class of boolean and integer constants.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
A parsed version of the target data layout string in and methods for querying it.
const DataLayout & getDataLayout() const
Get the data layout of the module this function belongs to.
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Common base class shared among various IRBuilders.
Value * CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name="")
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, const char *Name)
UnreachableInst * CreateUnreachable()
Value * CreateInBoundsGEP(Type *Ty, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &Name="")
Value * CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name="")
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
BranchInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, MDNode *BranchWeights=nullptr, MDNode *Unpredictable=nullptr)
Create a conditional 'br Cond, TrueDest, FalseDest' instruction.
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
BranchInst * CreateBr(BasicBlock *Dest)
Create an unconditional 'br label X' instruction.
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
StoreInst * CreateAlignedStore(Value *Val, Value *Ptr, MaybeAlign Align, bool isVolatile=false)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
Class to represent integer types.
This is an important class for using LLVM in a threaded context.
An instruction for reading from memory.
void setAtomic(AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System)
Sets the ordering constraint and the synchronization scope ID of this load instruction.
MDNode * createAnonymousAliasScope(MDNode *Domain, StringRef Name=StringRef())
Return metadata appropriate for an alias scope root node.
LLVM_ABI MDNode * createLikelyBranchWeights()
Return metadata containing two branch weights, with significant bias towards true destination.
MDNode * createAnonymousAliasScopeDomain(StringRef Name=StringRef())
Return metadata appropriate for an alias scope domain node.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
This class wraps the llvm.memcpy intrinsic.
Value * getLength() const
Value * getRawDest() const
MaybeAlign getDestAlign() const
This is the common base class for memset/memcpy/memmove.
This class wraps the llvm.memmove intrinsic.
This class wraps the llvm.memset and llvm.memset.inline intrinsics.
This class wraps the llvm.experimental.memset.pattern intrinsic.
Common base class for all memory transfer intrinsics.
Value * getRawSource() const
Return the arguments to the instruction.
MaybeAlign getSourceAlign() const
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
This class represents an analyzed expression in the program.
The main scalar evolution driver.
LLVM_ABI const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
LLVM_ABI bool isKnownPredicateAt(CmpPredicate Pred, const SCEV *LHS, const SCEV *RHS, const Instruction *CtxI)
Test if the given expression is known to satisfy the condition described by Pred, LHS,...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
void setAtomic(AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System)
Sets the ordering constraint and the synchronization scope ID of this store instruction.
StringRef - Represent a constant reference to a string, i.e.
The instances of the Type class are immutable: once they are created, they are never changed.
bool isVectorTy() const
True if this is an instance of VectorType.
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
static LLVM_ABI IntegerType * getIntNTy(LLVMContext &C, unsigned N)
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
const ParentTy * getParent() const
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void createMemCpyLoopKnownSize(Instruction *InsertBefore, Value *SrcAddr, Value *DstAddr, ConstantInt *CopyLen, Align SrcAlign, Align DestAlign, bool SrcIsVolatile, bool DstIsVolatile, bool CanOverlap, const TargetTransformInfo &TTI, std::optional< uint32_t > AtomicCpySize=std::nullopt, std::optional< uint64_t > AverageTripCount=std::nullopt)
Emit a loop implementing the semantics of an llvm.memcpy whose size is a compile time constant.
FunctionAddr VTableAddr Value
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.
LLVM_ABI void expandMemSetPatternAsLoop(MemSetPatternInst *MemSet)
Expand MemSetPattern as a loop. MemSet is not deleted.
LLVM_ABI bool expandMemMoveAsLoop(MemMoveInst *MemMove, const TargetTransformInfo &TTI)
Expand MemMove as a loop.
constexpr T alignDown(U Value, V Align, W Skew=0)
Returns the largest unsigned integer less than or equal to Value and is Skew mod Align.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
LLVM_ABI void SplitBlockAndInsertIfThenElse(Value *Cond, BasicBlock::iterator SplitBefore, Instruction **ThenTerm, Instruction **ElseTerm, MDNode *BranchWeights=nullptr, DomTreeUpdater *DTU=nullptr, LoopInfo *LI=nullptr)
SplitBlockAndInsertIfThenElse is similar to SplitBlockAndInsertIfThen, but also creates the ElseBlock...
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI SmallVector< InstrProfValueData, 4 > getValueProfDataFromInst(const Instruction &Inst, InstrProfValueKind ValueKind, uint32_t MaxNumValueData, uint64_t &TotalC, bool GetNoICPValue=false)
Extract the value profile data from Inst and returns them if Inst is annotated with value profile dat...
LLVM_ABI void expandAtomicMemCpyAsLoop(AnyMemCpyInst *AtomicMemCpy, const TargetTransformInfo &TTI, ScalarEvolution *SE)
Expand AtomicMemCpy as a loop. AtomicMemCpy is not deleted.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Align commonAlignment(Align A, uint64_t Offset)
Returns the alignment that satisfies both alignments.
LLVM_ABI void expandMemCpyAsLoop(MemCpyInst *MemCpy, const TargetTransformInfo &TTI, ScalarEvolution *SE=nullptr)
Expand MemCpy as a loop. MemCpy is not deleted.
cl::opt< bool > ProfcheckDisableMetadataFixes("profcheck-disable-metadata-fixes", cl::Hidden, cl::init(false), cl::desc("Disable metadata propagation fixes discovered through Issue #147390"))
LLVM_ABI void setFittedBranchWeights(Instruction &I, ArrayRef< uint64_t > Weights, bool IsExpected, bool ElideAllZero=false)
Variant of setBranchWeights where the Weights will be fit first to uint32_t by shifting right.
LLVM_ABI void createMemCpyLoopUnknownSize(Instruction *InsertBefore, Value *SrcAddr, Value *DstAddr, Value *CopyLen, Align SrcAlign, Align DestAlign, bool SrcIsVolatile, bool DstIsVolatile, bool CanOverlap, const TargetTransformInfo &TTI, std::optional< unsigned > AtomicSize=std::nullopt, std::optional< uint64_t > AverageTripCount=std::nullopt)
Emit a loop implementing the semantics of llvm.memcpy where the size is not a compile-time constant.
LLVM_ABI void expandMemSetAsLoop(MemSetInst *MemSet)
Expand MemSet as a loop. MemSet is not deleted.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.