15#ifndef LLVM_IR_INSTRUCTIONS_H
16#define LLVM_IR_INSTRUCTIONS_H
66 "Bitfields must be contiguous");
126 return Align(1ULL << getSubclassData<AlignmentField>());
130 setSubclassData<AlignmentField>(
Log2(
Align));
141 return getSubclassData<UsedWithInAllocaField>();
146 setSubclassData<UsedWithInAllocaField>(V);
150 bool isSwiftError()
const {
return getSubclassData<SwiftErrorField>(); }
156 return (
I->getOpcode() == Instruction::Alloca);
159 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
165 template <
typename Bitfield>
166 void setSubclassData(
typename Bitfield::Type
Value) {
167 Instruction::setSubclassData<Bitfield>(
Value);
182 Bitfield::areContiguous<VolatileField, AlignmentField, OrderingField>(),
183 "Bitfields must be contiguous");
214 bool isVolatile()
const {
return getSubclassData<VolatileField>(); }
221 return Align(1ULL << (getSubclassData<AlignmentField>()));
225 setSubclassData<AlignmentField>(
Log2(
Align));
230 return getSubclassData<OrderingField>();
235 setSubclassData<OrderingField>(Ordering);
276 return I->getOpcode() == Instruction::Load;
279 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
285 template <
typename Bitfield>
286 void setSubclassData(
typename Bitfield::Type
Value) {
287 Instruction::setSubclassData<Bitfield>(
Value);
306 Bitfield::areContiguous<VolatileField, AlignmentField, OrderingField>(),
307 "Bitfields must be contiguous");
333 void *
operator new(
size_t S) {
return User::operator
new(S, 2); }
334 void operator delete(
void *
Ptr) { User::operator
delete(
Ptr); }
337 bool isVolatile()
const {
return getSubclassData<VolatileField>(); }
346 return Align(1ULL << (getSubclassData<AlignmentField>()));
350 setSubclassData<AlignmentField>(
Log2(
Align));
355 return getSubclassData<OrderingField>();
361 setSubclassData<OrderingField>(Ordering);
405 return I->getOpcode() == Instruction::Store;
408 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
414 template <
typename Bitfield>
415 void setSubclassData(
typename Bitfield::Type
Value) {
416 Instruction::setSubclassData<Bitfield>(
Value);
457 void *
operator new(
size_t S) {
return User::operator
new(S, 0); }
458 void operator delete(
void *
Ptr) { User::operator
delete(
Ptr); }
462 return getSubclassData<OrderingField>();
468 setSubclassData<OrderingField>(Ordering);
483 return I->getOpcode() == Instruction::Fence;
486 return isa<Instruction>(V) && classof(cast<Instruction>(V));
492 template <
typename Bitfield>
493 void setSubclassData(
typename Bitfield::Type
Value) {
494 Instruction::setSubclassData<Bitfield>(
Value);
518 template <
unsigned Offset>
519 using AtomicOrderingBitfieldElement =
540 void *
operator new(
size_t S) {
return User::operator
new(S, 3); }
541 void operator delete(
void *
Ptr) { User::operator
delete(
Ptr); }
554 "Bitfields must be contiguous");
559 return Align(1ULL << getSubclassData<AlignmentField>());
563 setSubclassData<AlignmentField>(
Log2(
Align));
569 bool isVolatile()
const {
return getSubclassData<VolatileField>(); }
576 bool isWeak()
const {
return getSubclassData<WeakField>(); }
578 void setWeak(
bool IsWeak) { setSubclassData<WeakField>(IsWeak); }
597 return getSubclassData<SuccessOrderingField>();
603 "invalid CmpXchg success ordering");
604 setSubclassData<SuccessOrderingField>(Ordering);
609 return getSubclassData<FailureOrderingField>();
615 "invalid CmpXchg failure ordering");
616 setSubclassData<FailureOrderingField>(Ordering);
667 switch (SuccessOrdering) {
683 return I->getOpcode() == Instruction::AtomicCmpXchg;
686 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
692 template <
typename Bitfield>
693 void setSubclassData(
typename Bitfield::Type
Value) {
694 Instruction::setSubclassData<Bitfield>(
Value);
777 LAST_BINOP = UDecWrap,
782 template <
unsigned Offset>
783 using AtomicOrderingBitfieldElement =
787 template <
unsigned Offset>
788 using BinOpBitfieldElement =
800 void *
operator new(
size_t S) {
return User::operator
new(S, 2); }
801 void operator delete(
void *
Ptr) { User::operator
delete(
Ptr); }
810 "Bitfields must be contiguous");
814 static StringRef getOperationName(BinOp Op);
829 setSubclassData<OperationField>(
Operation);
835 return Align(1ULL << getSubclassData<AlignmentField>());
839 setSubclassData<AlignmentField>(
Log2(
Align));
844 bool isVolatile()
const {
return getSubclassData<VolatileField>(); }
855 return getSubclassData<AtomicOrderingField>();
861 "atomicrmw instructions can only be atomic.");
863 "atomicrmw instructions cannot be unordered.");
864 setSubclassData<AtomicOrderingField>(Ordering);
890 return isFPOperation(getOperation());
895 return I->getOpcode() == Instruction::AtomicRMW;
898 return isa<Instruction>(V) && classof(cast<Instruction>(V));
907 template <
typename Bitfield>
908 void setSubclassData(
typename Bitfield::Type
Value) {
909 Instruction::setSubclassData<Bitfield>(
Value);
933 assert(Ty &&
"Invalid GetElementPtrInst indices for type!");
941 Type *SourceElementType;
942 Type *ResultElementType;
968 const Twine &NameStr =
"",
971 assert(PointeeType &&
"Must specify element type");
972 assert(cast<PointerType>(
Ptr->getType()->getScalarType())
973 ->isOpaqueOrPointeeTypeMatches(PointeeType));
975 NameStr, InsertBefore);
980 const Twine &NameStr,
983 assert(PointeeType &&
"Must specify element type");
984 assert(cast<PointerType>(
Ptr->getType()->getScalarType())
985 ->isOpaqueOrPointeeTypeMatches(PointeeType));
987 NameStr, InsertAtEnd);
994 const Twine &NameStr =
"",
997 Create(PointeeType,
Ptr, IdxList, NameStr, InsertBefore);
998 GEP->setIsInBounds(
true);
1004 const Twine &NameStr,
1007 Create(PointeeType,
Ptr, IdxList, NameStr, InsertAtEnd);
1008 GEP->setIsInBounds(
true);
1022 ->isOpaqueOrPointeeTypeMatches(ResultElementType));
1023 return ResultElementType;
1088 PointerType *OrigPtrTy = cast<PointerType>(
Ptr->getType()->getScalarType());
1095 if (
auto *PtrVTy = dyn_cast<VectorType>(
Ptr->getType())) {
1100 if (
auto *IndexVTy = dyn_cast<VectorType>(
Index->getType())) {
1144 APInt &ConstantOffset)
const;
1147 return (
I->getOpcode() == Instruction::GetElementPtr);
1150 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
1159GetElementPtrInst::GetElementPtrInst(
Type *PointeeType,
Value *
Ptr,
1161 const Twine &NameStr,
1163 :
Instruction(getGEPReturnType(PointeeType,
Ptr, IdxList), GetElementPtr,
1165 Values, InsertBefore),
1166 SourceElementType(PointeeType),
1167 ResultElementType(getIndexedType(PointeeType, IdxList)) {
1169 ->isOpaqueOrPointeeTypeMatches(ResultElementType));
1170 init(
Ptr, IdxList, NameStr);
1173GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *
Ptr,
1174 ArrayRef<Value *> IdxList,
unsigned Values,
1175 const Twine &NameStr,
1176 BasicBlock *InsertAtEnd)
1177 : Instruction(getGEPReturnType(PointeeType,
Ptr, IdxList), GetElementPtr,
1178 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
1179 Values, InsertAtEnd),
1180 SourceElementType(PointeeType),
1181 ResultElementType(getIndexedType(PointeeType, IdxList)) {
1183 ->isOpaqueOrPointeeTypeMatches(ResultElementType));
1184 init(
Ptr, IdxList, NameStr);
1199 assert(isIntPredicate() &&
1200 "Invalid ICmp predicate value");
1202 "Both operands to ICmp instruction are not of the same type!");
1205 getOperand(0)->
getType()->isPtrOrPtrVectorTy()) &&
1206 "Invalid operand types for ICmp instruction");
1223 const Twine &NameStr =
""
1238 const Twine &NameStr =
""
1252 const Twine &NameStr =
""
1265 return getSignedPredicate(getPredicate());
1270 static Predicate getSignedPredicate(Predicate
pred);
1277 return getUnsignedPredicate(getPredicate());
1282 static Predicate getUnsignedPredicate(Predicate
pred);
1287 return P == ICMP_EQ ||
P == ICMP_NE;
1293 return isEquality(getPredicate());
1303 return !isEquality();
1309 return !isEquality(
P);
1315 return P == ICMP_SGT ||
P == ICMP_UGT;
1321 return P == ICMP_SLT ||
P == ICMP_ULT;
1327 return P == ICMP_SGE ||
P == ICMP_UGE;
1333 return P == ICMP_SLE ||
P == ICMP_ULE;
1346 setPredicate(getSwappedPredicate());
1347 Op<0>().swap(Op<1>());
1356 return I->getOpcode() == Instruction::ICmp;
1359 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1375 "Both operands to FCmp instruction are not of the same type!");
1378 "Invalid operand types for FCmp instruction");
1395 const Twine &NameStr =
""
1408 const Twine &NameStr =
""
1420 const Twine &NameStr =
"",
1423 RHS, NameStr, nullptr, FlagsSource) {
1459 Op<0>().swap(Op<1>());
1472 return I->getOpcode() == Instruction::FCmp;
1475 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
1496 :
CallInst(Ty, Func, Args, std::nullopt, NameStr, InsertBefore) {}
1515 static int ComputeNumOperands(
int NumArgs,
int NumBundleInputs = 0) {
1518 return 1 + NumArgs + NumBundleInputs;
1530 return new (ComputeNumOperands(0))
CallInst(Ty,
F, NameStr, InsertBefore);
1534 const Twine &NameStr,
1536 return new (ComputeNumOperands(Args.size()))
1537 CallInst(Ty, Func, Args, std::nullopt, NameStr, InsertBefore);
1542 const Twine &NameStr =
"",
1544 const int NumOperands =
1548 return new (NumOperands, DescriptorBytes)
1549 CallInst(Ty, Func, Args, Bundles, NameStr, InsertBefore);
1554 return new (ComputeNumOperands(0))
CallInst(Ty,
F, NameStr, InsertAtEnd);
1559 return new (ComputeNumOperands(Args.size()))
1560 CallInst(Ty, Func, Args, std::nullopt, NameStr, InsertAtEnd);
1566 const int NumOperands =
1570 return new (NumOperands, DescriptorBytes)
1571 CallInst(Ty, Func, Args, Bundles, NameStr, InsertAtEnd);
1576 return Create(Func.getFunctionType(), Func.getCallee(), NameStr,
1582 const Twine &NameStr =
"",
1584 return Create(Func.getFunctionType(), Func.getCallee(), Args, Bundles,
1585 NameStr, InsertBefore);
1589 const Twine &NameStr,
1591 return Create(Func.getFunctionType(), Func.getCallee(), Args, NameStr,
1597 return Create(Func.getFunctionType(), Func.getCallee(), NameStr,
1603 return Create(Func.getFunctionType(), Func.getCallee(), Args, NameStr,
1610 return Create(Func.getFunctionType(), Func.getCallee(), Args, Bundles,
1611 NameStr, InsertAtEnd);
1631 Value *ArraySize =
nullptr,
1636 Value *ArraySize =
nullptr,
1641 Value *AllocSize,
Value *ArraySize =
nullptr,
1646 Value *AllocSize,
Value *ArraySize =
nullptr,
1670 Bitfield::areContiguous<TailCallKindField, CallBase::CallingConvField>(),
1671 "Bitfields must be contiguous");
1674 return getSubclassData<TailCallKindField>();
1687 setSubclassData<TailCallKindField>(TCK);
1700 return I->getOpcode() == Instruction::Call;
1703 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
1712 template <
typename Bitfield>
1713 void setSubclassData(
typename Bitfield::Type
Value) {
1714 Instruction::setSubclassData<Bitfield>(
Value);
1718CallInst::CallInst(
FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1719 ArrayRef<OperandBundleDef> Bundles,
const Twine &NameStr,
1720 BasicBlock *InsertAtEnd)
1721 : CallBase(Ty->getReturnType(), Instruction::
Call,
1722 OperandTraits<CallBase>::op_end(this) -
1723 (
Args.
size() + CountBundleInputs(Bundles) + 1),
1726 init(Ty, Func, Args, Bundles, NameStr);
1729CallInst::CallInst(
FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1730 ArrayRef<OperandBundleDef> Bundles,
const Twine &NameStr,
1731 Instruction *InsertBefore)
1732 : CallBase(Ty->getReturnType(), Instruction::
Call,
1733 OperandTraits<CallBase>::op_end(this) -
1734 (
Args.
size() + CountBundleInputs(Bundles) + 1),
1737 init(Ty, Func, Args, Bundles, NameStr);
1750 &Op<0>(), 3, InsertBefore) {
1758 &Op<0>(), 3, InsertAtEnd) {
1778 const Twine &NameStr =
"",
1788 const Twine &NameStr,
1790 return new(3)
SelectInst(
C, S1, S2, NameStr, InsertAtEnd);
1821 return I->getOpcode() == Instruction::Select;
1824 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
1867 return I->getOpcode() == VAArg;
1870 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1895 const Twine &NameStr =
"",
1901 const Twine &NameStr,
1924 return I->getOpcode() == Instruction::ExtractElement;
1927 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
1947 const Twine &NameStr =
"",
1960 const Twine &NameStr =
"",
1966 const Twine &NameStr,
1973 static bool isValidOperands(
const Value *Vec,
const Value *NewElt,
1987 return I->getOpcode() == Instruction::InsertElement;
1990 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2037 const Twine &NameStr =
"",
2042 const Twine &NameStr =
"",
2047 void *
operator new(
size_t S) {
return User::operator
new(S, 2); }
2048 void operator delete(
void *
Ptr) {
return User::operator
delete(
Ptr); }
2056 static bool isValidOperands(
const Value *V1,
const Value *V2,
2058 static bool isValidOperands(
const Value *V1,
const Value *V2,
2076 static void getShuffleMask(
const Constant *Mask,
2082 Result.assign(ShuffleMask.
begin(), ShuffleMask.
end());
2103 unsigned NumSourceElts = cast<VectorType>(Op<0>()->
getType())
2105 .getKnownMinValue();
2106 unsigned NumMaskElts = ShuffleMask.
size();
2107 return NumSourceElts != NumMaskElts;
2114 unsigned NumSourceElts = cast<VectorType>(Op<0>()->
getType())
2116 .getKnownMinValue();
2117 unsigned NumMaskElts = ShuffleMask.
size();
2118 return NumSourceElts < NumMaskElts;
2127 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2129 getShuffleMask(Mask, MaskAsInts);
2130 return isSingleSourceMask(MaskAsInts);
2138 return !changesLength() && isSingleSourceMask(ShuffleMask);
2148 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2152 if (isa<ScalableVectorType>(Mask->getType()))
2156 getShuffleMask(Mask, MaskAsInts);
2157 return isIdentityMask(MaskAsInts);
2167 if (isa<ScalableVectorType>(
getType()))
2170 return !changesLength() && isIdentityMask(ShuffleMask);
2175 bool isIdentityWithPadding()
const;
2179 bool isIdentityWithExtract()
const;
2184 bool isConcat()
const;
2196 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2198 getShuffleMask(Mask, MaskAsInts);
2199 return isSelectMask(MaskAsInts);
2211 return !changesLength() && isSelectMask(ShuffleMask);
2220 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2222 getShuffleMask(Mask, MaskAsInts);
2240 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2242 getShuffleMask(Mask, MaskAsInts);
2243 return isZeroEltSplatMask(MaskAsInts);
2253 return !changesLength() && isZeroEltSplatMask(ShuffleMask);
2290 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2292 getShuffleMask(Mask, MaskAsInts);
2293 return isTransposeMask(MaskAsInts);
2302 return !changesLength() && isTransposeMask(ShuffleMask);
2311 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2313 getShuffleMask(Mask, MaskAsInts);
2314 return isSpliceMask(MaskAsInts,
Index);
2322 return !changesLength() && isSpliceMask(ShuffleMask,
Index);
2328 static bool isExtractSubvectorMask(
ArrayRef<int> Mask,
int NumSrcElts,
2332 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2335 if (isa<ScalableVectorType>(Mask->getType()))
2338 getShuffleMask(Mask, MaskAsInts);
2339 return isExtractSubvectorMask(MaskAsInts, NumSrcElts,
Index);
2346 if (isa<ScalableVectorType>(
getType()))
2350 cast<FixedVectorType>(Op<0>()->
getType())->getNumElements();
2351 return isExtractSubvectorMask(ShuffleMask, NumSrcElts,
Index);
2358 static bool isInsertSubvectorMask(
ArrayRef<int> Mask,
int NumSrcElts,
2359 int &NumSubElts,
int &
Index);
2361 int &NumSubElts,
int &
Index) {
2362 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2365 if (isa<ScalableVectorType>(Mask->getType()))
2368 getShuffleMask(Mask, MaskAsInts);
2369 return isInsertSubvectorMask(MaskAsInts, NumSrcElts, NumSubElts,
Index);
2376 if (isa<ScalableVectorType>(
getType()))
2380 cast<FixedVectorType>(Op<0>()->
getType())->getNumElements();
2381 return isInsertSubvectorMask(ShuffleMask, NumSrcElts, NumSubElts,
Index);
2388 static bool isReplicationMask(
ArrayRef<int> Mask,
int &ReplicationFactor,
2392 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2395 if (isa<ScalableVectorType>(Mask->getType()))
2398 getShuffleMask(Mask, MaskAsInts);
2399 return isReplicationMask(MaskAsInts, ReplicationFactor, VF);
2403 bool isReplicationMask(
int &ReplicationFactor,
int &VF)
const;
2414 static bool isOneUseSingleSourceMask(
ArrayRef<int> Mask,
int VF);
2418 bool isOneUseSingleSourceMask(
int VF)
const;
2423 unsigned InVecNumElts) {
2424 for (
int &
Idx : Mask) {
2427 Idx =
Idx < (int)InVecNumElts ?
Idx + InVecNumElts :
Idx - InVecNumElts;
2429 "shufflevector mask index out of range");
2434 bool isInterleave(
unsigned Factor);
2455 static bool isInterleaveMask(
ArrayRef<int> Mask,
unsigned Factor,
2456 unsigned NumInputElts,
2459 unsigned NumInputElts) {
2461 return isInterleaveMask(Mask, Factor, NumInputElts, StartIndexes);
2466 return I->getOpcode() == Instruction::ShuffleVector;
2469 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2497 const Twine &NameStr,
2514 const Twine &NameStr =
"",
2522 const Twine &NameStr,
2542 return getOperand(0);
2545 return getOperand(0);
2556 return (
unsigned)Indices.
size();
2565 return I->getOpcode() == Instruction::ExtractValue;
2568 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2572ExtractValueInst::ExtractValueInst(Value *Agg,
2573 ArrayRef<unsigned> Idxs,
2574 const Twine &NameStr,
2575 Instruction *InsertBefore)
2577 ExtractValue, Agg, InsertBefore) {
2578 init(Idxs, NameStr);
2581ExtractValueInst::ExtractValueInst(Value *Agg,
2582 ArrayRef<unsigned> Idxs,
2583 const Twine &NameStr,
2584 BasicBlock *InsertAtEnd)
2586 ExtractValue, Agg, InsertAtEnd) {
2587 init(Idxs, NameStr);
2608 const Twine &NameStr,
2617 const Twine &NameStr =
"",
2623 const Twine &NameStr);
2633 void *
operator new(
size_t S) {
return User::operator
new(S, 2); }
2634 void operator delete(
void *
Ptr) { User::operator
delete(
Ptr); }
2638 const Twine &NameStr =
"",
2645 const Twine &NameStr,
2686 return (
unsigned)Indices.
size();
2695 return I->getOpcode() == Instruction::InsertValue;
2698 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
2707InsertValueInst::InsertValueInst(
Value *Agg,
2710 const Twine &NameStr,
2715 init(Agg, Val, Idxs, NameStr);
2718InsertValueInst::InsertValueInst(Value *Agg,
2720 ArrayRef<unsigned> Idxs,
2721 const Twine &NameStr,
2722 BasicBlock *InsertAtEnd)
2723 : Instruction(Agg->
getType(), InsertValue,
2724 OperandTraits<InsertValueInst>::op_begin(this),
2726 init(Agg, Val, Idxs, NameStr);
2742 unsigned ReservedSpace;
2746 explicit PHINode(
Type *Ty,
unsigned NumReservedValues,
2747 const Twine &NameStr =
"",
2749 :
Instruction(Ty, Instruction::PHI,
nullptr, 0, InsertBefore),
2750 ReservedSpace(NumReservedValues) {
2753 allocHungoffUses(ReservedSpace);
2758 :
Instruction(Ty, Instruction::PHI,
nullptr, 0, InsertAtEnd),
2759 ReservedSpace(NumReservedValues) {
2762 allocHungoffUses(ReservedSpace);
2782 const Twine &NameStr =
"",
2784 return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
2789 return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
2808 return block_begin() + getNumOperands();
2812 return make_range(block_begin(), block_end());
2826 return getOperand(i);
2829 assert(V &&
"PHI node got a null value!");
2831 "All operands to PHI node must be the same type as the PHI node!");
2846 return block_begin()[i];
2853 assert(
this == U.getUser() &&
"Iterator doesn't point to PHI's Uses?");
2854 return getIncomingBlock(
unsigned(&U - op_begin()));
2861 return getIncomingBlock(
I.getUse());
2877 assert(New && Old &&
"PHI node got a null basic block!");
2878 for (
unsigned Op = 0, NumOps = getNumOperands(); Op != NumOps; ++Op)
2879 if (getIncomingBlock(Op) == Old)
2880 setIncomingBlock(Op, New);
2886 if (getNumOperands() == ReservedSpace)
2889 setNumHungOffUseOperands(getNumOperands() + 1);
2890 setIncomingValue(getNumOperands() - 1, V);
2891 setIncomingBlock(getNumOperands() - 1, BB);
2902 Value *removeIncomingValue(
unsigned Idx,
bool DeletePHIIfEmpty =
true);
2905 int Idx = getBasicBlockIndex(BB);
2906 assert(
Idx >= 0 &&
"Invalid basic block argument to remove!");
2907 return removeIncomingValue(
Idx, DeletePHIIfEmpty);
2914 for (
unsigned i = 0, e = getNumOperands(); i != e; ++i)
2915 if (block_begin()[i] == BB)
2921 int Idx = getBasicBlockIndex(BB);
2922 assert(
Idx >= 0 &&
"Invalid basic block argument!");
2923 return getIncomingValue(
Idx);
2928 assert(BB &&
"PHI node got a null basic block!");
2930 for (
unsigned Op = 0, NumOps = getNumOperands(); Op != NumOps; ++Op)
2931 if (getIncomingBlock(Op) == BB) {
2933 setIncomingValue(Op, V);
2936 assert(Found &&
"Invalid basic block argument to set!");
2941 Value *hasConstantValue()
const;
2946 bool hasConstantOrUndefValue()
const;
2953 return getBasicBlockIndex(Pred) >= 0;
2959 return I->getOpcode() == Instruction::PHI;
2962 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2966 void growOperands();
2992 unsigned ReservedSpace;
3006 void *
operator new(
size_t S) {
return User::operator
new(S); }
3008 void growOperands(
unsigned Size);
3009 void init(
unsigned NumReservedValues,
const Twine &NameStr);
3018 void operator delete(
void *
Ptr) { User::operator
delete(
Ptr); }
3023 const Twine &NameStr =
"",
3034 bool isCleanup()
const {
return getSubclassData<CleanupField>(); }
3045 return cast<Constant>(getOperandList()[
Idx]);
3050 return !isa<ArrayType>(getOperandList()[
Idx]->
getType());
3055 return isa<ArrayType>(getOperandList()[
Idx]->
getType());
3067 return I->getOpcode() == Instruction::LandingPad;
3070 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3117 return new(!!retVal)
ReturnInst(
C, retVal, InsertBefore);
3122 return new(!!retVal)
ReturnInst(
C, retVal, InsertAtEnd);
3134 return getNumOperands() != 0 ? getOperand(0) :
nullptr;
3141 return (
I->getOpcode() == Instruction::Ret);
3144 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3148 BasicBlock *getSuccessor(
unsigned idx)
const {
3152 void setSuccessor(
unsigned idx, BasicBlock *
B) {
3205 std::random_access_iterator_tag, BasicBlock *,
3206 ptrdiff_t, BasicBlock *, BasicBlock *> {
3216 std::random_access_iterator_tag,
3217 const BasicBlock *, ptrdiff_t, const BasicBlock *,
3218 const BasicBlock *> {
3228 return new(1)
BranchInst(IfTrue, InsertBefore);
3237 return new(1)
BranchInst(IfTrue, InsertAtEnd);
3252 assert(isConditional() &&
"Cannot get condition of an uncond branch!");
3257 assert(isConditional() &&
"Cannot set condition of unconditional branch!");
3264 assert(i < getNumSuccessors() &&
"Successor # out of range for Branch!");
3265 return cast_or_null<BasicBlock>((&Op<-1>() - i)->
get());
3269 assert(idx < getNumSuccessors() &&
"Successor # out of range for Branch!");
3270 *(&Op<-1>() - idx) = NewSucc;
3278 void swapSuccessors();
3288 std::next(value_op_begin(), isConditional() ? 1 : 0)),
3294 return (
I->getOpcode() == Instruction::Br);
3297 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3315 unsigned ReservedSpace;
3338 void *
operator new(
size_t S) {
return User::operator
new(S); }
3341 void growOperands();
3350 void operator delete(
void *
Ptr) { User::operator
delete(
Ptr); }
3353 static const unsigned DefaultPseudoIndex =
static_cast<unsigned>(~0L-1);
3362 template <
typename SwitchInstT,
typename ConstantIntT,
typename BasicBlockT>
3381 assert((
unsigned)Index < SI->getNumCases() &&
3382 "Index out the number of cases.");
3383 return reinterpret_cast<ConstantIntT *
>(
SI->getOperand(2 +
Index * 2));
3388 assert(((
unsigned)Index < SI->getNumCases() ||
3389 (
unsigned)
Index == DefaultPseudoIndex) &&
3390 "Index out the number of cases.");
3391 return SI->getSuccessor(getSuccessorIndex());
3400 (
unsigned)Index < SI->getNumCases()) &&
3401 "Index out the number of cases.");
3402 return (
unsigned)
Index != DefaultPseudoIndex ?
Index + 1 : 0;
3406 assert(
SI ==
RHS.SI &&
"Incompatible operators.");
3423 assert((
unsigned)Index < SI->getNumCases() &&
3424 "Index out the number of cases.");
3425 SI->setOperand(2 +
Index*2,
reinterpret_cast<Value*
>(V));
3430 SI->setSuccessor(getSuccessorIndex(), S);
3434 template <
typename CaseHandleT>
3437 std::random_access_iterator_tag,
3438 const CaseHandleT> {
3439 using SwitchInstT =
typename CaseHandleT::SwitchInstType;
3455 unsigned SuccessorIndex) {
3456 assert(SuccessorIndex < SI->getNumSuccessors() &&
3457 "Successor index # out of range!");
3472 (
unsigned)(Case.Index +
N) <= Case.SI->getNumCases() &&
3473 "Case.Index out the number of cases.");
3481 (
unsigned)(Case.Index -
N) <= Case.SI->getNumCases() &&
3482 "Case.Index out the number of cases.");
3487 assert(Case.SI ==
RHS.Case.SI &&
"Incompatible operators.");
3488 return Case.Index -
RHS.Case.Index;
3491 return Case ==
RHS.Case;
3494 assert(Case.SI ==
RHS.Case.SI &&
"Incompatible operators.");
3495 return Case.Index <
RHS.Case.Index;
3510 unsigned NumCases,
BasicBlock *InsertAtEnd) {
3522 return cast<BasicBlock>(getOperand(1));
3526 setOperand(1,
reinterpret_cast<Value*
>(DefaultCase));
3532 return getNumOperands()/2 - 1;
3550 return CaseIt(
this, getNumCases());
3575 return CaseIt(
this, DefaultPseudoIndex);
3588 const_cast<const SwitchInst *
>(
this)->findCaseValue(
C)->getCaseIndex());
3594 if (
I != case_end())
3597 return case_default();
3603 if (BB == getDefaultDest())
3607 for (
auto Case : cases()) {
3608 if (Case.getCaseSuccessor() != BB)
3614 CI = Case.getCaseValue();
3633 CaseIt removeCase(CaseIt
I);
3637 assert(idx < getNumSuccessors() &&
"Successor idx out of range for switch!");
3638 return cast<BasicBlock>(getOperand(idx*2+1));
3641 assert(idx < getNumSuccessors() &&
"Successor # out of range for switch!");
3642 setOperand(idx * 2 + 1, NewSucc);
3647 return I->getOpcode() == Instruction::Switch;
3650 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3658 std::optional<SmallVector<uint32_t, 8>> Weights;
3659 bool Changed =
false;
3711 unsigned ReservedSpace;
3730 void *
operator new(
size_t S) {
return User::operator
new(S); }
3733 void growOperands();
3742 void operator delete(
void *
Ptr) { User::operator
delete(
Ptr); }
3750 std::random_access_iterator_tag, BasicBlock *,
3751 ptrdiff_t, BasicBlock *, BasicBlock *> {
3761 std::random_access_iterator_tag,
3762 const BasicBlock *, ptrdiff_t, const BasicBlock *,
3763 const BasicBlock *> {
3803 void removeDestination(
unsigned i);
3807 return cast<BasicBlock>(getOperand(i+1));
3810 setOperand(i + 1, NewSucc);
3825 return I->getOpcode() == Instruction::IndirectBr;
3828 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3848 static constexpr int NumExtraOperands = 2;
3851 static constexpr int NormalDestOpEndIdx = -3;
3854 static constexpr int UnwindDestOpEndIdx = -2;
3876 static int ComputeNumOperands(
int NumArgs,
int NumBundleInputs = 0) {
3879 return 1 + NumExtraOperands + NumArgs + NumBundleInputs;
3891 const Twine &NameStr,
3893 int NumOperands = ComputeNumOperands(Args.size());
3894 return new (NumOperands)
3895 InvokeInst(Ty, Func, IfNormal, IfException, Args, std::nullopt,
3896 NumOperands, NameStr, InsertBefore);
3902 const Twine &NameStr =
"",
3905 ComputeNumOperands(Args.size(), CountBundleInputs(Bundles));
3908 return new (NumOperands, DescriptorBytes)
3909 InvokeInst(Ty, Func, IfNormal, IfException, Args, Bundles, NumOperands,
3910 NameStr, InsertBefore);
3916 int NumOperands = ComputeNumOperands(Args.size());
3917 return new (NumOperands)
3918 InvokeInst(Ty, Func, IfNormal, IfException, Args, std::nullopt,
3919 NumOperands, NameStr, InsertAtEnd);
3927 ComputeNumOperands(Args.size(), CountBundleInputs(Bundles));
3930 return new (NumOperands, DescriptorBytes)
3931 InvokeInst(Ty, Func, IfNormal, IfException, Args, Bundles, NumOperands,
3932 NameStr, InsertAtEnd);
3937 const Twine &NameStr,
3939 return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
3940 IfException, Args, std::nullopt, NameStr, InsertBefore);
3946 const Twine &NameStr =
"",
3948 return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
3949 IfException, Args, Bundles, NameStr, InsertBefore);
3955 return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
3956 IfException, Args, NameStr, InsertAtEnd);
3963 return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
3964 IfException, Args, Bundles, NameStr, InsertAtEnd);
3978 return cast<BasicBlock>(Op<NormalDestOpEndIdx>());
3981 return cast<BasicBlock>(Op<UnwindDestOpEndIdx>());
3984 Op<NormalDestOpEndIdx>() =
reinterpret_cast<Value *
>(
B);
3987 Op<UnwindDestOpEndIdx>() =
reinterpret_cast<Value *
>(
B);
3995 assert(i < 2 &&
"Successor # out of range for invoke!");
3996 return i == 0 ? getNormalDest() : getUnwindDest();
4000 assert(i < 2 &&
"Successor # out of range for invoke!");
4002 setNormalDest(NewSucc);
4004 setUnwindDest(NewSucc);
4011 return (
I->getOpcode() == Instruction::Invoke);
4014 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4020 template <
typename Bitfield>
4021 void setSubclassData(
typename Bitfield::Type
Value) {
4022 Instruction::setSubclassData<Bitfield>(
Value);
4026InvokeInst::InvokeInst(
FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
4027 BasicBlock *IfException, ArrayRef<Value *> Args,
4028 ArrayRef<OperandBundleDef> Bundles,
int NumOperands,
4029 const Twine &NameStr, Instruction *InsertBefore)
4030 : CallBase(Ty->getReturnType(), Instruction::Invoke,
4031 OperandTraits<CallBase>::op_end(this) - NumOperands, NumOperands,
4033 init(Ty, Func, IfNormal, IfException, Args, Bundles, NameStr);
4036InvokeInst::InvokeInst(
FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
4037 BasicBlock *IfException, ArrayRef<Value *> Args,
4038 ArrayRef<OperandBundleDef> Bundles,
int NumOperands,
4039 const Twine &NameStr, BasicBlock *InsertAtEnd)
4040 : CallBase(Ty->getReturnType(), Instruction::Invoke,
4041 OperandTraits<CallBase>::op_end(this) - NumOperands, NumOperands,
4043 init(Ty, Func, IfNormal, IfException, Args, Bundles, NameStr);
4056 unsigned NumIndirectDests;
4080 static int ComputeNumOperands(
int NumArgs,
int NumIndirectDests,
4081 int NumBundleInputs = 0) {
4084 return 2 + NumIndirectDests + NumArgs + NumBundleInputs;
4099 int NumOperands = ComputeNumOperands(Args.size(), IndirectDests.
size());
4100 return new (NumOperands)
4101 CallBrInst(Ty, Func, DefaultDest, IndirectDests, Args, std::nullopt,
4102 NumOperands, NameStr, InsertBefore);
4110 int NumOperands = ComputeNumOperands(Args.size(), IndirectDests.
size(),
4114 return new (NumOperands, DescriptorBytes)
4115 CallBrInst(Ty, Func, DefaultDest, IndirectDests, Args, Bundles,
4116 NumOperands, NameStr, InsertBefore);
4124 int NumOperands = ComputeNumOperands(Args.size(), IndirectDests.
size());
4125 return new (NumOperands)
4126 CallBrInst(Ty, Func, DefaultDest, IndirectDests, Args, std::nullopt,
4127 NumOperands, NameStr, InsertAtEnd);
4136 int NumOperands = ComputeNumOperands(Args.size(), IndirectDests.
size(),
4140 return new (NumOperands, DescriptorBytes)
4141 CallBrInst(Ty, Func, DefaultDest, IndirectDests, Args, Bundles,
4142 NumOperands, NameStr, InsertAtEnd);
4149 return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
4150 IndirectDests, Args, NameStr, InsertBefore);
4157 const Twine &NameStr =
"",
4159 return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
4160 IndirectDests, Args, Bundles, NameStr, InsertBefore);
4167 return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
4168 IndirectDests, Args, NameStr, InsertAtEnd);
4177 return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
4178 IndirectDests, Args, Bundles, NameStr, InsertAtEnd);
4218 return IndirectDests;
4229 "Successor # out of range for callbr!");
4235 "Successor # out of range for callbr!");
4243 return (
I->getOpcode() == Instruction::CallBr);
4246 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
4252 template <
typename Bitfield>
4253 void setSubclassData(
typename Bitfield::Type
Value) {
4254 Instruction::setSubclassData<Bitfield>(
Value);
4258CallBrInst::CallBrInst(
FunctionType *Ty, Value *Func, BasicBlock *DefaultDest,
4259 ArrayRef<BasicBlock *> IndirectDests,
4260 ArrayRef<Value *> Args,
4261 ArrayRef<OperandBundleDef> Bundles,
int NumOperands,
4262 const Twine &NameStr, Instruction *InsertBefore)
4263 : CallBase(Ty->getReturnType(), Instruction::CallBr,
4264 OperandTraits<CallBase>::op_end(this) - NumOperands, NumOperands,
4266 init(Ty, Func, DefaultDest, IndirectDests, Args, Bundles, NameStr);
4269CallBrInst::CallBrInst(
FunctionType *Ty, Value *Func, BasicBlock *DefaultDest,
4270 ArrayRef<BasicBlock *> IndirectDests,
4271 ArrayRef<Value *> Args,
4272 ArrayRef<OperandBundleDef> Bundles,
int NumOperands,
4273 const Twine &NameStr, BasicBlock *InsertAtEnd)
4274 : CallBase(Ty->getReturnType(), Instruction::CallBr,
4275 OperandTraits<CallBase>::op_end(this) - NumOperands, NumOperands,
4277 init(Ty, Func, DefaultDest, IndirectDests, Args, Bundles, NameStr);
4318 return I->getOpcode() == Instruction::Resume;
4321 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
4325 BasicBlock *getSuccessor(
unsigned idx)
const {
4329 void setSuccessor(
unsigned idx,
BasicBlock *NewSucc) {
4349 unsigned ReservedSpace;
4361 unsigned NumHandlers,
const Twine &NameStr,
4369 unsigned NumHandlers,
const Twine &NameStr,
4373 void *
operator new(
size_t S) {
return User::operator
new(S); }
4375 void init(
Value *ParentPad,
BasicBlock *UnwindDest,
unsigned NumReserved);
4376 void growOperands(
unsigned Size);
4385 void operator delete(
void *
Ptr) {
return User::operator
delete(
Ptr); }
4388 unsigned NumHandlers,
4389 const Twine &NameStr =
"",
4391 return new CatchSwitchInst(ParentPad, UnwindDest, NumHandlers, NameStr,
4396 unsigned NumHandlers,
const Twine &NameStr,
4398 return new CatchSwitchInst(ParentPad, UnwindDest, NumHandlers, NameStr,
4413 if (hasUnwindDest())
4414 return cast<BasicBlock>(getOperand(1));
4420 setOperand(1, UnwindDest);
4426 if (hasUnwindDest())
4427 return getNumOperands() - 2;
4428 return getNumOperands() - 1;
4432 static BasicBlock *handler_helper(
Value *V) {
return cast<BasicBlock>(V); }
4433 static const BasicBlock *handler_helper(
const Value *V) {
4434 return cast<BasicBlock>(V);
4449 if (hasUnwindDest())
4458 if (hasUnwindDest())