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");
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");
973 NameStr, InsertBefore);
978 const Twine &NameStr,
981 assert(PointeeType &&
"Must specify element type");
983 NameStr, InsertAtEnd);
990 const Twine &NameStr =
"",
993 Create(PointeeType,
Ptr, IdxList, NameStr, InsertBefore);
994 GEP->setIsInBounds(
true);
1000 const Twine &NameStr,
1003 Create(PointeeType,
Ptr, IdxList, NameStr, InsertAtEnd);
1004 GEP->setIsInBounds(
true);
1017 return ResultElementType;
1087 if (
auto *IndexVTy = dyn_cast<VectorType>(
Index->getType())) {
1131 APInt &ConstantOffset)
const;
1134 return (
I->getOpcode() == Instruction::GetElementPtr);
1137 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
1146GetElementPtrInst::GetElementPtrInst(
Type *PointeeType,
Value *
Ptr,
1148 const Twine &NameStr,
1152 Values, InsertBefore),
1153 SourceElementType(PointeeType),
1154 ResultElementType(getIndexedType(PointeeType, IdxList)) {
1155 init(
Ptr, IdxList, NameStr);
1158GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *
Ptr,
1159 ArrayRef<Value *> IdxList,
unsigned Values,
1160 const Twine &NameStr,
1161 BasicBlock *InsertAtEnd)
1162 : Instruction(getGEPReturnType(
Ptr, IdxList), GetElementPtr,
1163 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
1164 Values, InsertAtEnd),
1165 SourceElementType(PointeeType),
1166 ResultElementType(getIndexedType(PointeeType, IdxList)) {
1167 init(
Ptr, IdxList, NameStr);
1182 assert(isIntPredicate() &&
1183 "Invalid ICmp predicate value");
1185 "Both operands to ICmp instruction are not of the same type!");
1188 getOperand(0)->
getType()->isPtrOrPtrVectorTy()) &&
1189 "Invalid operand types for ICmp instruction");
1206 const Twine &NameStr =
""
1221 const Twine &NameStr =
""
1235 const Twine &NameStr =
""
1248 return getSignedPredicate(getPredicate());
1253 static Predicate getSignedPredicate(Predicate
pred);
1260 return getUnsignedPredicate(getPredicate());
1265 static Predicate getUnsignedPredicate(Predicate
pred);
1270 return P == ICMP_EQ ||
P == ICMP_NE;
1276 return isEquality(getPredicate());
1286 return !isEquality();
1292 return !isEquality(
P);
1298 return P == ICMP_SGT ||
P == ICMP_UGT;
1304 return P == ICMP_SLT ||
P == ICMP_ULT;
1310 return P == ICMP_SGE ||
P == ICMP_UGE;
1316 return P == ICMP_SLE ||
P == ICMP_ULE;
1329 setPredicate(getSwappedPredicate());
1339 return I->getOpcode() == Instruction::ICmp;
1342 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1358 "Both operands to FCmp instruction are not of the same type!");
1361 "Invalid operand types for FCmp instruction");
1378 const Twine &NameStr =
""
1391 const Twine &NameStr =
""
1403 const Twine &NameStr =
"",
1406 RHS, NameStr, nullptr, FlagsSource) {
1455 return I->getOpcode() == Instruction::FCmp;
1458 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
1479 :
CallInst(Ty, Func, Args, std::nullopt, NameStr, InsertBefore) {}
1498 static int ComputeNumOperands(
int NumArgs,
int NumBundleInputs = 0) {
1501 return 1 + NumArgs + NumBundleInputs;
1513 return new (ComputeNumOperands(0))
CallInst(Ty,
F, NameStr, InsertBefore);
1517 const Twine &NameStr,
1519 return new (ComputeNumOperands(Args.size()))
1520 CallInst(Ty, Func, Args, std::nullopt, NameStr, InsertBefore);
1525 const Twine &NameStr =
"",
1527 const int NumOperands =
1531 return new (NumOperands, DescriptorBytes)
1532 CallInst(Ty, Func, Args, Bundles, NameStr, InsertBefore);
1537 return new (ComputeNumOperands(0))
CallInst(Ty,
F, NameStr, InsertAtEnd);
1542 return new (ComputeNumOperands(Args.size()))
1543 CallInst(Ty, Func, Args, std::nullopt, NameStr, InsertAtEnd);
1549 const int NumOperands =
1553 return new (NumOperands, DescriptorBytes)
1554 CallInst(Ty, Func, Args, Bundles, NameStr, InsertAtEnd);
1559 return Create(Func.getFunctionType(), Func.getCallee(), NameStr,
1565 const Twine &NameStr =
"",
1567 return Create(Func.getFunctionType(), Func.getCallee(), Args, Bundles,
1568 NameStr, InsertBefore);
1572 const Twine &NameStr,
1574 return Create(Func.getFunctionType(), Func.getCallee(), Args, NameStr,
1580 return Create(Func.getFunctionType(), Func.getCallee(), NameStr,
1586 return Create(Func.getFunctionType(), Func.getCallee(), Args, NameStr,
1593 return Create(Func.getFunctionType(), Func.getCallee(), Args, Bundles,
1594 NameStr, InsertAtEnd);
1617 Bitfield::areContiguous<TailCallKindField, CallBase::CallingConvField>(),
1618 "Bitfields must be contiguous");
1621 return getSubclassData<TailCallKindField>();
1634 setSubclassData<TailCallKindField>(TCK);
1647 return I->getOpcode() == Instruction::Call;
1650 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
1659 template <
typename Bitfield>
1660 void setSubclassData(
typename Bitfield::Type
Value) {
1661 Instruction::setSubclassData<Bitfield>(
Value);
1665CallInst::CallInst(
FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1666 ArrayRef<OperandBundleDef> Bundles,
const Twine &NameStr,
1667 BasicBlock *InsertAtEnd)
1668 : CallBase(Ty->getReturnType(), Instruction::
Call,
1669 OperandTraits<CallBase>::op_end(this) -
1670 (
Args.
size() + CountBundleInputs(Bundles) + 1),
1673 init(Ty, Func, Args, Bundles, NameStr);
1676CallInst::CallInst(
FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1677 ArrayRef<OperandBundleDef> Bundles,
const Twine &NameStr,
1678 Instruction *InsertBefore)
1679 : CallBase(Ty->getReturnType(), Instruction::
Call,
1680 OperandTraits<CallBase>::op_end(this) -
1681 (
Args.
size() + CountBundleInputs(Bundles) + 1),
1684 init(Ty, Func, Args, Bundles, NameStr);
1697 &
Op<0>(), 3, InsertBefore) {
1705 &
Op<0>(), 3, InsertAtEnd) {
1725 const Twine &NameStr =
"",
1735 const Twine &NameStr,
1737 return new(3)
SelectInst(
C, S1, S2, NameStr, InsertAtEnd);
1768 return I->getOpcode() == Instruction::Select;
1771 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
1814 return I->getOpcode() == VAArg;
1817 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1842 const Twine &NameStr =
"",
1848 const Twine &NameStr,
1871 return I->getOpcode() == Instruction::ExtractElement;
1874 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
1894 const Twine &NameStr =
"",
1907 const Twine &NameStr =
"",
1913 const Twine &NameStr,
1920 static bool isValidOperands(
const Value *Vec,
const Value *NewElt,
1934 return I->getOpcode() == Instruction::InsertElement;
1937 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1984 const Twine &NameStr =
"",
1989 const Twine &NameStr =
"",
1994 void *
operator new(
size_t S) {
return User::operator
new(S, 2); }
1995 void operator delete(
void *
Ptr) {
return User::operator
delete(
Ptr); }
2003 static bool isValidOperands(
const Value *V1,
const Value *V2,
2005 static bool isValidOperands(
const Value *V1,
const Value *V2,
2023 static void getShuffleMask(
const Constant *Mask,
2029 Result.assign(ShuffleMask.
begin(), ShuffleMask.
end());
2050 unsigned NumSourceElts = cast<VectorType>(
Op<0>()->
getType())
2052 .getKnownMinValue();
2053 unsigned NumMaskElts = ShuffleMask.
size();
2054 return NumSourceElts != NumMaskElts;
2061 unsigned NumSourceElts = cast<VectorType>(
Op<0>()->
getType())
2063 .getKnownMinValue();
2064 unsigned NumMaskElts = ShuffleMask.
size();
2065 return NumSourceElts < NumMaskElts;
2074 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2076 getShuffleMask(Mask, MaskAsInts);
2077 return isSingleSourceMask(MaskAsInts);
2085 return !changesLength() && isSingleSourceMask(ShuffleMask);
2095 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2099 if (isa<ScalableVectorType>(Mask->getType()))
2103 getShuffleMask(Mask, MaskAsInts);
2104 return isIdentityMask(MaskAsInts);
2114 if (isa<ScalableVectorType>(
getType()))
2117 return !changesLength() && isIdentityMask(ShuffleMask);
2122 bool isIdentityWithPadding()
const;
2126 bool isIdentityWithExtract()
const;
2131 bool isConcat()
const;
2143 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2145 getShuffleMask(Mask, MaskAsInts);
2146 return isSelectMask(MaskAsInts);
2158 return !changesLength() && isSelectMask(ShuffleMask);
2167 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2169 getShuffleMask(Mask, MaskAsInts);
2187 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2189 getShuffleMask(Mask, MaskAsInts);
2190 return isZeroEltSplatMask(MaskAsInts);
2200 return !changesLength() && isZeroEltSplatMask(ShuffleMask);
2237 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2239 getShuffleMask(Mask, MaskAsInts);
2240 return isTransposeMask(MaskAsInts);
2249 return !changesLength() && isTransposeMask(ShuffleMask);
2258 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2260 getShuffleMask(Mask, MaskAsInts);
2261 return isSpliceMask(MaskAsInts,
Index);
2269 return !changesLength() && isSpliceMask(ShuffleMask,
Index);
2275 static bool isExtractSubvectorMask(
ArrayRef<int> Mask,
int NumSrcElts,
2279 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2282 if (isa<ScalableVectorType>(Mask->getType()))
2285 getShuffleMask(Mask, MaskAsInts);
2286 return isExtractSubvectorMask(MaskAsInts, NumSrcElts,
Index);
2293 if (isa<ScalableVectorType>(
getType()))
2297 cast<FixedVectorType>(
Op<0>()->
getType())->getNumElements();
2298 return isExtractSubvectorMask(ShuffleMask, NumSrcElts,
Index);
2305 static bool isInsertSubvectorMask(
ArrayRef<int> Mask,
int NumSrcElts,
2306 int &NumSubElts,
int &
Index);
2308 int &NumSubElts,
int &
Index) {
2309 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2312 if (isa<ScalableVectorType>(Mask->getType()))
2315 getShuffleMask(Mask, MaskAsInts);
2316 return isInsertSubvectorMask(MaskAsInts, NumSrcElts, NumSubElts,
Index);
2323 if (isa<ScalableVectorType>(
getType()))
2327 cast<FixedVectorType>(
Op<0>()->
getType())->getNumElements();
2328 return isInsertSubvectorMask(ShuffleMask, NumSrcElts, NumSubElts,
Index);
2335 static bool isReplicationMask(
ArrayRef<int> Mask,
int &ReplicationFactor,
2339 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2342 if (isa<ScalableVectorType>(Mask->getType()))
2345 getShuffleMask(Mask, MaskAsInts);
2346 return isReplicationMask(MaskAsInts, ReplicationFactor, VF);
2350 bool isReplicationMask(
int &ReplicationFactor,
int &VF)
const;
2361 static bool isOneUseSingleSourceMask(
ArrayRef<int> Mask,
int VF);
2365 bool isOneUseSingleSourceMask(
int VF)
const;
2370 unsigned InVecNumElts) {
2371 for (
int &
Idx : Mask) {
2374 Idx =
Idx < (int)InVecNumElts ?
Idx + InVecNumElts :
Idx - InVecNumElts;
2376 "shufflevector mask index out of range");
2381 bool isInterleave(
unsigned Factor);
2402 static bool isInterleaveMask(
ArrayRef<int> Mask,
unsigned Factor,
2403 unsigned NumInputElts,
2406 unsigned NumInputElts) {
2408 return isInterleaveMask(Mask, Factor, NumInputElts, StartIndexes);
2422 static bool isBitRotateMask(
ArrayRef<int> Mask,
unsigned EltSizeInBits,
2423 unsigned MinSubElts,
unsigned MaxSubElts,
2424 unsigned &NumSubElts,
unsigned &RotateAmt);
2428 return I->getOpcode() == Instruction::ShuffleVector;
2431 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2459 const Twine &NameStr,
2476 const Twine &NameStr =
"",
2484 const Twine &NameStr,
2504 return getOperand(0);
2507 return getOperand(0);
2518 return (
unsigned)Indices.
size();
2527 return I->getOpcode() == Instruction::ExtractValue;
2530 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2534ExtractValueInst::ExtractValueInst(Value *Agg,
2535 ArrayRef<unsigned> Idxs,
2536 const Twine &NameStr,
2537 Instruction *InsertBefore)
2539 ExtractValue, Agg, InsertBefore) {
2540 init(Idxs, NameStr);
2543ExtractValueInst::ExtractValueInst(Value *Agg,
2544 ArrayRef<unsigned> Idxs,
2545 const Twine &NameStr,
2546 BasicBlock *InsertAtEnd)
2548 ExtractValue, Agg, InsertAtEnd) {
2549 init(Idxs, NameStr);
2570 const Twine &NameStr,
2579 const Twine &NameStr =
"",
2585 const Twine &NameStr);
2595 void *
operator new(
size_t S) {
return User::operator
new(S, 2); }
2596 void operator delete(
void *
Ptr) { User::operator
delete(
Ptr); }
2600 const Twine &NameStr =
"",
2607 const Twine &NameStr,
2648 return (
unsigned)Indices.
size();
2657 return I->getOpcode() == Instruction::InsertValue;
2660 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
2669InsertValueInst::InsertValueInst(
Value *Agg,
2672 const Twine &NameStr,
2677 init(Agg, Val, Idxs, NameStr);
2680InsertValueInst::InsertValueInst(Value *Agg,
2682 ArrayRef<unsigned> Idxs,
2683 const Twine &NameStr,
2684 BasicBlock *InsertAtEnd)
2685 : Instruction(Agg->
getType(), InsertValue,
2686 OperandTraits<InsertValueInst>::op_begin(this),
2688 init(Agg, Val, Idxs, NameStr);
2704 unsigned ReservedSpace;
2708 explicit PHINode(
Type *Ty,
unsigned NumReservedValues,
2709 const Twine &NameStr =
"",
2711 :
Instruction(Ty, Instruction::PHI,
nullptr, 0, InsertBefore),
2712 ReservedSpace(NumReservedValues) {
2715 allocHungoffUses(ReservedSpace);
2720 :
Instruction(Ty, Instruction::PHI,
nullptr, 0, InsertAtEnd),
2721 ReservedSpace(NumReservedValues) {
2724 allocHungoffUses(ReservedSpace);
2744 const Twine &NameStr =
"",
2746 return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
2751 return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
2770 return block_begin() + getNumOperands();
2774 return make_range(block_begin(), block_end());
2788 return getOperand(i);
2791 assert(V &&
"PHI node got a null value!");
2793 "All operands to PHI node must be the same type as the PHI node!");
2808 return block_begin()[i];
2815 assert(
this == U.getUser() &&
"Iterator doesn't point to PHI's Uses?");
2816 return getIncomingBlock(
unsigned(&U - op_begin()));
2823 return getIncomingBlock(
I.getUse());
2839 assert(New && Old &&
"PHI node got a null basic block!");
2840 for (
unsigned Op = 0, NumOps = getNumOperands();
Op != NumOps; ++
Op)
2841 if (getIncomingBlock(
Op) == Old)
2842 setIncomingBlock(
Op, New);
2848 if (getNumOperands() == ReservedSpace)
2851 setNumHungOffUseOperands(getNumOperands() + 1);
2852 setIncomingValue(getNumOperands() - 1, V);
2853 setIncomingBlock(getNumOperands() - 1, BB);
2864 Value *removeIncomingValue(
unsigned Idx,
bool DeletePHIIfEmpty =
true);
2867 int Idx = getBasicBlockIndex(BB);
2868 assert(
Idx >= 0 &&
"Invalid basic block argument to remove!");
2869 return removeIncomingValue(
Idx, DeletePHIIfEmpty);
2874 void removeIncomingValueIf(
function_ref<
bool(
unsigned)> Predicate,
2875 bool DeletePHIIfEmpty =
true);
2881 for (
unsigned i = 0, e = getNumOperands(); i != e; ++i)
2882 if (block_begin()[i] == BB)
2888 int Idx = getBasicBlockIndex(BB);
2889 assert(
Idx >= 0 &&
"Invalid basic block argument!");
2890 return getIncomingValue(
Idx);
2895 assert(BB &&
"PHI node got a null basic block!");
2897 for (
unsigned Op = 0, NumOps = getNumOperands();
Op != NumOps; ++
Op)
2898 if (getIncomingBlock(
Op) == BB) {
2900 setIncomingValue(
Op, V);
2903 assert(Found &&
"Invalid basic block argument to set!");
2908 Value *hasConstantValue()
const;
2913 bool hasConstantOrUndefValue()
const;
2920 return getBasicBlockIndex(Pred) >= 0;
2926 return I->getOpcode() == Instruction::PHI;
2929 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2933 void growOperands();
2959 unsigned ReservedSpace;
2973 void *
operator new(
size_t S) {
return User::operator
new(S); }
2975 void growOperands(
unsigned Size);
2976 void init(
unsigned NumReservedValues,
const Twine &NameStr);
2985 void operator delete(
void *
Ptr) { User::operator
delete(
Ptr); }
2990 const Twine &NameStr =
"",
3001 bool isCleanup()
const {
return getSubclassData<CleanupField>(); }
3012 return cast<Constant>(getOperandList()[
Idx]);
3017 return !isa<ArrayType>(getOperandList()[
Idx]->
getType());
3022 return isa<ArrayType>(getOperandList()[
Idx]->
getType());
3034 return I->getOpcode() == Instruction::LandingPad;
3037 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3084 return new(!!retVal)
ReturnInst(
C, retVal, InsertBefore);
3089 return new(!!retVal)
ReturnInst(
C, retVal, InsertAtEnd);
3101 return getNumOperands() != 0 ? getOperand(0) :
nullptr;
3108 return (
I->getOpcode() == Instruction::Ret);
3111 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3115 BasicBlock *getSuccessor(
unsigned idx)
const {
3119 void setSuccessor(
unsigned idx, BasicBlock *
B) {
3172 std::random_access_iterator_tag, BasicBlock *,
3173 ptrdiff_t, BasicBlock *, BasicBlock *> {
3183 std::random_access_iterator_tag,
3184 const BasicBlock *, ptrdiff_t, const BasicBlock *,
3185 const BasicBlock *> {
3195 return new(1)
BranchInst(IfTrue, InsertBefore);
3204 return new(1)
BranchInst(IfTrue, InsertAtEnd);
3219 assert(isConditional() &&
"Cannot get condition of an uncond branch!");
3224 assert(isConditional() &&
"Cannot set condition of unconditional branch!");
3231 assert(i < getNumSuccessors() &&
"Successor # out of range for Branch!");
3232 return cast_or_null<BasicBlock>((&
Op<-1>() - i)->
get());
3236 assert(idx < getNumSuccessors() &&
"Successor # out of range for Branch!");
3237 *(&
Op<-1>() - idx) = NewSucc;
3245 void swapSuccessors();
3255 std::next(value_op_begin(), isConditional() ? 1 : 0)),
3261 return (
I->getOpcode() == Instruction::Br);
3264 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3282 unsigned ReservedSpace;
3305 void *
operator new(
size_t S) {
return User::operator
new(S); }
3308 void growOperands();
3317 void operator delete(
void *
Ptr) { User::operator
delete(
Ptr); }
3320 static const unsigned DefaultPseudoIndex =
static_cast<unsigned>(~0L-1);
3329 template <
typename SwitchInstT,
typename ConstantIntT,
typename BasicBlockT>
3348 assert((
unsigned)Index < SI->getNumCases() &&
3349 "Index out the number of cases.");
3350 return reinterpret_cast<ConstantIntT *
>(
SI->getOperand(2 +
Index * 2));
3355 assert(((
unsigned)Index < SI->getNumCases() ||
3356 (
unsigned)
Index == DefaultPseudoIndex) &&
3357 "Index out the number of cases.");
3358 return SI->getSuccessor(getSuccessorIndex());
3367 (
unsigned)Index < SI->getNumCases()) &&
3368 "Index out the number of cases.");
3369 return (
unsigned)
Index != DefaultPseudoIndex ?
Index + 1 : 0;
3373 assert(
SI ==
RHS.SI &&
"Incompatible operators.");
3390 assert((
unsigned)Index < SI->getNumCases() &&
3391 "Index out the number of cases.");
3392 SI->setOperand(2 +
Index*2,
reinterpret_cast<Value*
>(V));
3397 SI->setSuccessor(getSuccessorIndex(), S);
3401 template <
typename CaseHandleT>
3404 std::random_access_iterator_tag,
3405 const CaseHandleT> {
3406 using SwitchInstT =
typename CaseHandleT::SwitchInstType;
3422 unsigned SuccessorIndex) {
3423 assert(SuccessorIndex < SI->getNumSuccessors() &&
3424 "Successor index # out of range!");
3439 (
unsigned)(Case.Index +
N) <= Case.SI->getNumCases() &&
3440 "Case.Index out the number of cases.");
3448 (
unsigned)(Case.Index -
N) <= Case.SI->getNumCases() &&
3449 "Case.Index out the number of cases.");
3454 assert(Case.SI ==
RHS.Case.SI &&
"Incompatible operators.");
3455 return Case.Index -
RHS.Case.Index;
3458 return Case ==
RHS.Case;
3461 assert(Case.SI ==
RHS.Case.SI &&
"Incompatible operators.");
3462 return Case.Index <
RHS.Case.Index;
3477 unsigned NumCases,
BasicBlock *InsertAtEnd) {
3489 return cast<BasicBlock>(getOperand(1));
3493 setOperand(1,
reinterpret_cast<Value*
>(DefaultCase));
3499 return getNumOperands()/2 - 1;
3517 return CaseIt(
this, getNumCases());
3542 return CaseIt(
this, DefaultPseudoIndex);
3555 const_cast<const SwitchInst *
>(
this)->findCaseValue(
C)->getCaseIndex());
3561 if (
I != case_end())
3564 return case_default();
3570 if (BB == getDefaultDest())
3574 for (
auto Case : cases()) {
3575 if (Case.getCaseSuccessor() != BB)
3581 CI = Case.getCaseValue();
3600 CaseIt removeCase(CaseIt
I);
3604 assert(idx < getNumSuccessors() &&
"Successor idx out of range for switch!");
3605 return cast<BasicBlock>(getOperand(idx*2+1));
3608 assert(idx < getNumSuccessors() &&
"Successor # out of range for switch!");
3609 setOperand(idx * 2 + 1, NewSucc);
3614 return I->getOpcode() == Instruction::Switch;
3617 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3625 std::optional<SmallVector<uint32_t, 8>> Weights;
3626 bool Changed =
false;
3678 unsigned ReservedSpace;
3697 void *
operator new(
size_t S) {
return User::operator
new(S); }
3700 void growOperands();
3709 void operator delete(
void *
Ptr) { User::operator
delete(
Ptr); }
3717 std::random_access_iterator_tag, BasicBlock *,
3718 ptrdiff_t, BasicBlock *, BasicBlock *> {
3728 std::random_access_iterator_tag,
3729 const BasicBlock *, ptrdiff_t, const BasicBlock *,
3730 const BasicBlock *> {
3770 void removeDestination(
unsigned i);
3774 return cast<BasicBlock>(getOperand(i+1));
3777 setOperand(i + 1, NewSucc);
3792 return I->getOpcode() == Instruction::IndirectBr;
3795 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3815 static constexpr int NumExtraOperands = 2;
3818 static constexpr int NormalDestOpEndIdx = -3;
3821 static constexpr int UnwindDestOpEndIdx = -2;
3843 static int ComputeNumOperands(
int NumArgs,
int NumBundleInputs = 0) {
3846 return 1 + NumExtraOperands + NumArgs + NumBundleInputs;
3858 const Twine &NameStr,
3860 int NumOperands = ComputeNumOperands(Args.size());
3861 return new (NumOperands)
3862 InvokeInst(Ty, Func, IfNormal, IfException, Args, std::nullopt,
3863 NumOperands, NameStr, InsertBefore);
3869 const Twine &NameStr =
"",
3872 ComputeNumOperands(Args.size(), CountBundleInputs(Bundles));
3875 return new (NumOperands, DescriptorBytes)
3876 InvokeInst(Ty, Func, IfNormal, IfException, Args, Bundles, NumOperands,
3877 NameStr, InsertBefore);
3883 int NumOperands = ComputeNumOperands(Args.size());
3884 return new (NumOperands)
3885 InvokeInst(Ty, Func, IfNormal, IfException, Args, std::nullopt,
3886 NumOperands, NameStr, InsertAtEnd);
3894 ComputeNumOperands(Args.size(), CountBundleInputs(Bundles));
3897 return new (NumOperands, DescriptorBytes)
3898 InvokeInst(Ty, Func, IfNormal, IfException, Args, Bundles, NumOperands,
3899 NameStr, InsertAtEnd);
3904 const Twine &NameStr,
3906 return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
3907 IfException, Args, std::nullopt, NameStr, InsertBefore);
3913 const Twine &NameStr =
"",
3915 return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
3916 IfException, Args, Bundles, NameStr, InsertBefore);
3922 return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
3923 IfException, Args, NameStr, InsertAtEnd);
3930 return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
3931 IfException, Args, Bundles, NameStr, InsertAtEnd);
3962 assert(i < 2 &&
"Successor # out of range for invoke!");
3963 return i == 0 ? getNormalDest() : getUnwindDest();
3967 assert(i < 2 &&
"Successor # out of range for invoke!");
3969 setNormalDest(NewSucc);
3971 setUnwindDest(NewSucc);
3978 return (
I->getOpcode() == Instruction::Invoke);
3981 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3987 template <
typename Bitfield>
3988 void setSubclassData(
typename Bitfield::Type
Value) {
3989 Instruction::setSubclassData<Bitfield>(
Value);
3993InvokeInst::InvokeInst(
FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3994 BasicBlock *IfException, ArrayRef<Value *> Args,
3995 ArrayRef<OperandBundleDef> Bundles,
int NumOperands,
3996 const Twine &NameStr, Instruction *InsertBefore)
3997 : CallBase(Ty->getReturnType(), Instruction::Invoke,
3998 OperandTraits<CallBase>::op_end(this) - NumOperands, NumOperands,
4000 init(Ty, Func, IfNormal, IfException, Args, Bundles, NameStr);
4003InvokeInst::InvokeInst(
FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
4004 BasicBlock *IfException, ArrayRef<Value *> Args,
4005 ArrayRef<OperandBundleDef> Bundles,
int NumOperands,
4006 const Twine &NameStr, BasicBlock *InsertAtEnd)
4007 : CallBase(Ty->getReturnType(), Instruction::Invoke,
4008 OperandTraits<CallBase>::op_end(this) - NumOperands, NumOperands,
4010 init(Ty, Func, IfNormal, IfException, Args, Bundles, NameStr);
4023 unsigned NumIndirectDests;
4047 static int ComputeNumOperands(
int NumArgs,
int NumIndirectDests,
4048 int NumBundleInputs = 0) {
4051 return 2 + NumIndirectDests + NumArgs + NumBundleInputs;
4066 int NumOperands = ComputeNumOperands(Args.size(), IndirectDests.
size());
4067 return new (NumOperands)
4068 CallBrInst(Ty, Func, DefaultDest, IndirectDests, Args, std::nullopt,
4069 NumOperands, NameStr, InsertBefore);
4077 int NumOperands = ComputeNumOperands(Args.size(), IndirectDests.
size(),
4081 return new (NumOperands, DescriptorBytes)
4082 CallBrInst(Ty, Func, DefaultDest, IndirectDests, Args, Bundles,
4083 NumOperands, NameStr, InsertBefore);
4091 int NumOperands = ComputeNumOperands(Args.size(), IndirectDests.
size());
4092 return new (NumOperands)
4093 CallBrInst(Ty, Func, DefaultDest, IndirectDests, Args, std::nullopt,
4094 NumOperands, NameStr, InsertAtEnd);
4103 int NumOperands = ComputeNumOperands(Args.size(), IndirectDests.
size(),
4107 return new (NumOperands, DescriptorBytes)
4108 CallBrInst(Ty, Func, DefaultDest, IndirectDests, Args, Bundles,
4109 NumOperands, NameStr, InsertAtEnd);
4116 return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
4117 IndirectDests, Args, NameStr, InsertBefore);
4124 const Twine &NameStr =
"",
4126 return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
4127 IndirectDests, Args, Bundles, NameStr, InsertBefore);
4134 return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
4135 IndirectDests, Args, NameStr, InsertAtEnd);
4144 return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
4145 IndirectDests, Args, Bundles, NameStr, InsertAtEnd);
4185 return IndirectDests;
4196 "Successor # out of range for callbr!");
4202 "Successor # out of range for callbr!");
4210 return (
I->getOpcode() == Instruction::CallBr);
4213 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
4219 template <
typename Bitfield>
4220 void setSubclassData(
typename Bitfield::Type
Value) {
4221 Instruction::setSubclassData<Bitfield>(
Value);
4225CallBrInst::CallBrInst(
FunctionType *Ty, Value *Func, BasicBlock *DefaultDest,
4226 ArrayRef<BasicBlock *> IndirectDests,
4227 ArrayRef<Value *> Args,
4228 ArrayRef<OperandBundleDef> Bundles,
int NumOperands,
4229 const Twine &NameStr, Instruction *InsertBefore)
4230 : CallBase(Ty->getReturnType(), Instruction::CallBr,
4231 OperandTraits<CallBase>::op_end(this) - NumOperands, NumOperands,
4233 init(Ty, Func, DefaultDest, IndirectDests, Args, Bundles, NameStr);
4236CallBrInst::CallBrInst(
FunctionType *Ty, Value *Func, BasicBlock *DefaultDest,
4237 ArrayRef<BasicBlock *> IndirectDests,
4238 ArrayRef<Value *> Args,
4239 ArrayRef<OperandBundleDef> Bundles,
int NumOperands,
4240 const Twine &NameStr, BasicBlock *InsertAtEnd)
4241 : CallBase(Ty->getReturnType(), Instruction::CallBr,
4242 OperandTraits<CallBase>::op_end(this) - NumOperands, NumOperands,
4244 init(Ty, Func, DefaultDest, IndirectDests, Args, Bundles, NameStr);
4285 return I->getOpcode() == Instruction::Resume;
4288 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
4292 BasicBlock *getSuccessor(
unsigned idx)
const {
4296 void setSuccessor(
unsigned idx,
BasicBlock *NewSucc) {
4316 unsigned ReservedSpace;
4328 unsigned NumHandlers,
const Twine &NameStr,
4336 unsigned NumHandlers,
const Twine &NameStr,
4340 void *
operator new(
size_t S) {
return User::operator
new(S); }
4342 void init(
Value *ParentPad,
BasicBlock *UnwindDest,
unsigned NumReserved);
4343 void growOperands(
unsigned Size);
4352 void operator delete(
void *
Ptr) {
return User::operator
delete(
Ptr); }
4355 unsigned NumHandlers,
4356 const Twine &NameStr =
"",
4358 return new CatchSwitchInst(ParentPad, UnwindDest, NumHandlers, NameStr,
4363 unsigned NumHandlers,
const Twine &NameStr,
4365 return new CatchSwitchInst(ParentPad, UnwindDest, NumHandlers, NameStr,
4380 if (hasUnwindDest())
4381 return cast<BasicBlock>(getOperand(1));
4387 setOperand(1, UnwindDest);
4393 if (hasUnwindDest())
4394 return getNumOperands() - 2;
4395 return getNumOperands() - 1;
4399 static BasicBlock *handler_helper(
Value *V) {
return cast<BasicBlock>(V); }
4400 static const BasicBlock *handler_helper(
const Value *V) {
4401 return cast<BasicBlock>(V);
4416 if (hasUnwindDest())
4425 if (hasUnwindDest())
4444 return make_range(handler_begin(), handler_end());
4449 return make_range(handler_begin(), handler_end());
4458 void removeHandler(handler_iterator HI);
4463 "Successor # out of range for catchswitch!");
4464 return cast<BasicBlock>(getOperand(
Idx + 1));
4468 "Successor # out of range for catchswitch!");
4469 setOperand(
Idx + 1, NewSucc);
4474 return I->getOpcode() == Instruction::CatchSwitch;