15#ifndef LLVM_IR_INSTRUCTIONS_H
16#define LLVM_IR_INSTRUCTIONS_H
69 "Bitfields must be contiguous");
123 return Align(1ULL << getSubclassData<AlignmentField>());
127 setSubclassData<AlignmentField>(
Log2(
Align));
138 return getSubclassData<UsedWithInAllocaField>();
143 setSubclassData<UsedWithInAllocaField>(V);
147 bool isSwiftError()
const {
return getSubclassData<SwiftErrorField>(); }
153 return (
I->getOpcode() == Instruction::Alloca);
156 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
162 template <
typename Bitfield>
163 void setSubclassData(
typename Bitfield::Type
Value) {
164 Instruction::setSubclassData<Bitfield>(
Value);
179 Bitfield::areContiguous<VolatileField, AlignmentField, OrderingField>(),
180 "Bitfields must be contiguous");
203 bool isVolatile()
const {
return getSubclassData<VolatileField>(); }
210 return Align(1ULL << (getSubclassData<AlignmentField>()));
214 setSubclassData<AlignmentField>(
Log2(
Align));
219 return getSubclassData<OrderingField>();
224 setSubclassData<OrderingField>(Ordering);
265 return I->getOpcode() == Instruction::Load;
268 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
274 template <
typename Bitfield>
275 void setSubclassData(
typename Bitfield::Type
Value) {
276 Instruction::setSubclassData<Bitfield>(
Value);
295 Bitfield::areContiguous<VolatileField, AlignmentField, OrderingField>(),
296 "Bitfields must be contiguous");
317 void *
operator new(
size_t S) {
return User::operator
new(S, 2); }
318 void operator delete(
void *
Ptr) { User::operator
delete(
Ptr); }
321 bool isVolatile()
const {
return getSubclassData<VolatileField>(); }
330 return Align(1ULL << (getSubclassData<AlignmentField>()));
334 setSubclassData<AlignmentField>(
Log2(
Align));
339 return getSubclassData<OrderingField>();
345 setSubclassData<OrderingField>(Ordering);
389 return I->getOpcode() == Instruction::Store;
392 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
398 template <
typename Bitfield>
399 void setSubclassData(
typename Bitfield::Type
Value) {
400 Instruction::setSubclassData<Bitfield>(
Value);
439 void *
operator new(
size_t S) {
return User::operator
new(S, 0); }
440 void operator delete(
void *
Ptr) { User::operator
delete(
Ptr); }
444 return getSubclassData<OrderingField>();
450 setSubclassData<OrderingField>(Ordering);
465 return I->getOpcode() == Instruction::Fence;
468 return isa<Instruction>(V) && classof(cast<Instruction>(V));
474 template <
typename Bitfield>
475 void setSubclassData(
typename Bitfield::Type
Value) {
476 Instruction::setSubclassData<Bitfield>(
Value);
500 template <
unsigned Offset>
501 using AtomicOrderingBitfieldElement =
518 void *
operator new(
size_t S) {
return User::operator
new(S, 3); }
519 void operator delete(
void *
Ptr) { User::operator
delete(
Ptr); }
532 "Bitfields must be contiguous");
537 return Align(1ULL << getSubclassData<AlignmentField>());
541 setSubclassData<AlignmentField>(
Log2(
Align));
547 bool isVolatile()
const {
return getSubclassData<VolatileField>(); }
554 bool isWeak()
const {
return getSubclassData<WeakField>(); }
556 void setWeak(
bool IsWeak) { setSubclassData<WeakField>(IsWeak); }
575 return getSubclassData<SuccessOrderingField>();
581 "invalid CmpXchg success ordering");
582 setSubclassData<SuccessOrderingField>(Ordering);
587 return getSubclassData<FailureOrderingField>();
593 "invalid CmpXchg failure ordering");
594 setSubclassData<FailureOrderingField>(Ordering);
645 switch (SuccessOrdering) {
661 return I->getOpcode() == Instruction::AtomicCmpXchg;
664 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
670 template <
typename Bitfield>
671 void setSubclassData(
typename Bitfield::Type
Value) {
672 Instruction::setSubclassData<Bitfield>(
Value);
755 LAST_BINOP = UDecWrap,
760 template <
unsigned Offset>
761 using AtomicOrderingBitfieldElement =
765 template <
unsigned Offset>
766 using BinOpBitfieldElement =
775 void *
operator new(
size_t S) {
return User::operator
new(S, 2); }
776 void operator delete(
void *
Ptr) { User::operator
delete(
Ptr); }
785 "Bitfields must be contiguous");
804 setSubclassData<OperationField>(
Operation);
810 return Align(1ULL << getSubclassData<AlignmentField>());
814 setSubclassData<AlignmentField>(
Log2(
Align));
819 bool isVolatile()
const {
return getSubclassData<VolatileField>(); }
830 return getSubclassData<AtomicOrderingField>();
836 "atomicrmw instructions can only be atomic.");
838 "atomicrmw instructions cannot be unordered.");
839 setSubclassData<AtomicOrderingField>(Ordering);
865 return isFPOperation(getOperation());
870 return I->getOpcode() == Instruction::AtomicRMW;
873 return isa<Instruction>(V) && classof(cast<Instruction>(V));
882 template <
typename Bitfield>
883 void setSubclassData(
typename Bitfield::Type
Value) {
884 Instruction::setSubclassData<Bitfield>(
Value);
908 assert(Ty &&
"Invalid GetElementPtrInst indices for type!");
916 Type *SourceElementType;
917 Type *ResultElementType;
940 const Twine &NameStr =
"",
943 assert(PointeeType &&
"Must specify element type");
945 NameStr, InsertBefore);
950 const Twine &NameStr =
"",
953 Create(PointeeType,
Ptr, IdxList, NameStr, InsertBefore);
954 GEP->setNoWrapFlags(NW);
962 const Twine &NameStr =
"",
965 NameStr, InsertBefore);
977 return ResultElementType;
1047 if (
auto *IndexVTy = dyn_cast<VectorType>(
Index->getType())) {
1104 APInt &ConstantOffset)
const;
1107 return (
I->getOpcode() == Instruction::GetElementPtr);
1110 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
1119GetElementPtrInst::GetElementPtrInst(
Type *PointeeType,
Value *
Ptr,
1121 const Twine &NameStr,
1125 Values, InsertBefore),
1126 SourceElementType(PointeeType),
1127 ResultElementType(getIndexedType(PointeeType, IdxList)) {
1128 init(
Ptr, IdxList, NameStr);
1143 assert(isIntPredicate() &&
1144 "Invalid ICmp predicate value");
1146 "Both operands to ICmp instruction are not of the same type!");
1149 getOperand(0)->
getType()->isPtrOrPtrVectorTy()) &&
1150 "Invalid operand types for ICmp instruction");
1166 const Twine &NameStr =
""
1169 RHS, NameStr, InsertBefore) {
1180 const Twine &NameStr =
""
1193 return getSignedPredicate(getPredicate());
1198 static Predicate getSignedPredicate(Predicate
pred);
1205 return getUnsignedPredicate(getPredicate());
1210 static Predicate getUnsignedPredicate(Predicate
pred);
1215 return P == ICMP_EQ ||
P == ICMP_NE;
1221 return isEquality(getPredicate());
1231 return !isEquality();
1237 return !isEquality(
P);
1243 return P == ICMP_SGT ||
P == ICMP_UGT;
1249 return P == ICMP_SLT ||
P == ICMP_ULT;
1255 return P == ICMP_SGE ||
P == ICMP_UGE;
1261 return P == ICMP_SLE ||
P == ICMP_ULE;
1274 setPredicate(getSwappedPredicate());
1284 return I->getOpcode() == Instruction::ICmp;
1287 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1303 "Both operands to FCmp instruction are not of the same type!");
1306 "Invalid operand types for FCmp instruction");
1322 const Twine &NameStr =
""
1325 RHS, NameStr, InsertBefore) {
1333 const Twine &NameStr =
"",
1336 RHS, NameStr, nullptr, FlagsSource) {
1385 return I->getOpcode() == Instruction::FCmp;
1388 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
1408 :
CallInst(Ty, Func, Args, std::nullopt, NameStr, InsertBefore) {}
1418 static int ComputeNumOperands(
int NumArgs,
int NumBundleInputs = 0) {
1421 return 1 + NumArgs + NumBundleInputs;
1433 return new (ComputeNumOperands(0))
CallInst(Ty,
F, NameStr, InsertBefore);
1437 const Twine &NameStr,
1439 return new (ComputeNumOperands(Args.size()))
1440 CallInst(Ty, Func, Args, std::nullopt, NameStr, InsertBefore);
1445 const Twine &NameStr =
"",
1447 const int NumOperands =
1451 return new (NumOperands, DescriptorBytes)
1452 CallInst(Ty, Func, Args, Bundles, NameStr, InsertBefore);
1457 return Create(Func.getFunctionType(), Func.getCallee(), NameStr,
1463 const Twine &NameStr =
"",
1465 return Create(Func.getFunctionType(), Func.getCallee(), Args, Bundles,
1466 NameStr, InsertBefore);
1470 const Twine &NameStr,
1472 return Create(Func.getFunctionType(), Func.getCallee(), Args, NameStr,
1496 Bitfield::areContiguous<TailCallKindField, CallBase::CallingConvField>(),
1497 "Bitfields must be contiguous");
1500 return getSubclassData<TailCallKindField>();
1513 setSubclassData<TailCallKindField>(TCK);
1527 case Intrinsic::trap:
1528 case Intrinsic::ubsantrap:
1537 return I->getOpcode() == Instruction::Call;
1540 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
1549 template <
typename Bitfield>
1550 void setSubclassData(
typename Bitfield::Type
Value) {
1551 Instruction::setSubclassData<Bitfield>(
Value);
1555CallInst::CallInst(
FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1556 ArrayRef<OperandBundleDef> Bundles,
const Twine &NameStr,
1557 InsertPosition InsertBefore)
1558 : CallBase(Ty->getReturnType(), Instruction::
Call,
1559 OperandTraits<CallBase>::op_end(this) -
1560 (
Args.
size() + CountBundleInputs(Bundles) + 1),
1563 init(Ty, Func, Args, Bundles, NameStr);
1597 const Twine &NameStr =
"",
1634 return I->getOpcode() == Instruction::Select;
1637 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
1674 return I->getOpcode() == VAArg;
1677 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1700 const Twine &NameStr =
"",
1723 return I->getOpcode() == Instruction::ExtractElement;
1726 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
1746 const Twine &NameStr =
"",
1757 const Twine &NameStr =
"",
1764 static bool isValidOperands(
const Value *Vec,
const Value *NewElt,
1778 return I->getOpcode() == Instruction::InsertElement;
1781 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1824 const Twine &NameStr =
"",
1827 const Twine &NameStr =
"",
1830 void *
operator new(
size_t S) {
return User::operator
new(S, 2); }
1831 void operator delete(
void *
Ptr) {
return User::operator
delete(
Ptr); }
1839 static bool isValidOperands(
const Value *V1,
const Value *V2,
1841 static bool isValidOperands(
const Value *V1,
const Value *V2,
1859 static void getShuffleMask(
const Constant *Mask,
1865 Result.assign(ShuffleMask.
begin(), ShuffleMask.
end());
1886 unsigned NumSourceElts = cast<VectorType>(
Op<0>()->
getType())
1888 .getKnownMinValue();
1889 unsigned NumMaskElts = ShuffleMask.
size();
1890 return NumSourceElts != NumMaskElts;
1897 unsigned NumSourceElts = cast<VectorType>(
Op<0>()->
getType())
1899 .getKnownMinValue();
1900 unsigned NumMaskElts = ShuffleMask.
size();
1901 return NumSourceElts < NumMaskElts;
1909 static bool isSingleSourceMask(
ArrayRef<int> Mask,
int NumSrcElts);
1911 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
1913 getShuffleMask(Mask, MaskAsInts);
1914 return isSingleSourceMask(MaskAsInts, NumSrcElts);
1922 return !changesLength() &&
1923 isSingleSourceMask(ShuffleMask, ShuffleMask.
size());
1931 static bool isIdentityMask(
ArrayRef<int> Mask,
int NumSrcElts);
1933 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
1937 if (isa<ScalableVectorType>(Mask->getType()))
1941 getShuffleMask(Mask, MaskAsInts);
1942 return isIdentityMask(MaskAsInts, NumSrcElts);
1952 if (isa<ScalableVectorType>(
getType()))
1955 return !changesLength() && isIdentityMask(ShuffleMask, ShuffleMask.
size());
1960 bool isIdentityWithPadding()
const;
1964 bool isIdentityWithExtract()
const;
1969 bool isConcat()
const;
1979 static bool isSelectMask(
ArrayRef<int> Mask,
int NumSrcElts);
1981 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
1983 getShuffleMask(Mask, MaskAsInts);
1984 return isSelectMask(MaskAsInts, NumSrcElts);
1996 return !changesLength() && isSelectMask(ShuffleMask, ShuffleMask.
size());
2006 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2008 getShuffleMask(Mask, MaskAsInts);
2025 static bool isZeroEltSplatMask(
ArrayRef<int> Mask,
int NumSrcElts);
2027 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2029 getShuffleMask(Mask, MaskAsInts);
2030 return isZeroEltSplatMask(MaskAsInts, NumSrcElts);
2040 return !changesLength() &&
2041 isZeroEltSplatMask(ShuffleMask, ShuffleMask.
size());
2076 static bool isTransposeMask(
ArrayRef<int> Mask,
int NumSrcElts);
2078 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2080 getShuffleMask(Mask, MaskAsInts);
2081 return isTransposeMask(MaskAsInts, NumSrcElts);
2090 return !changesLength() && isTransposeMask(ShuffleMask, ShuffleMask.
size());
2101 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2103 getShuffleMask(Mask, MaskAsInts);
2104 return isSpliceMask(MaskAsInts, NumSrcElts,
Index);
2112 return !changesLength() &&
2113 isSpliceMask(ShuffleMask, ShuffleMask.
size(),
Index);
2119 static bool isExtractSubvectorMask(
ArrayRef<int> Mask,
int NumSrcElts,
2123 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2126 if (isa<ScalableVectorType>(Mask->getType()))
2129 getShuffleMask(Mask, MaskAsInts);
2130 return isExtractSubvectorMask(MaskAsInts, NumSrcElts,
Index);
2137 if (isa<ScalableVectorType>(
getType()))
2141 cast<FixedVectorType>(
Op<0>()->
getType())->getNumElements();
2142 return isExtractSubvectorMask(ShuffleMask, NumSrcElts,
Index);
2149 static bool isInsertSubvectorMask(
ArrayRef<int> Mask,
int NumSrcElts,
2150 int &NumSubElts,
int &
Index);
2152 int &NumSubElts,
int &
Index) {
2153 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2156 if (isa<ScalableVectorType>(Mask->getType()))
2159 getShuffleMask(Mask, MaskAsInts);
2160 return isInsertSubvectorMask(MaskAsInts, NumSrcElts, NumSubElts,
Index);
2167 if (isa<ScalableVectorType>(
getType()))
2171 cast<FixedVectorType>(
Op<0>()->
getType())->getNumElements();
2172 return isInsertSubvectorMask(ShuffleMask, NumSrcElts, NumSubElts,
Index);
2179 static bool isReplicationMask(
ArrayRef<int> Mask,
int &ReplicationFactor,
2183 assert(Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2186 if (isa<ScalableVectorType>(Mask->getType()))
2189 getShuffleMask(Mask, MaskAsInts);
2190 return isReplicationMask(MaskAsInts, ReplicationFactor, VF);
2194 bool isReplicationMask(
int &ReplicationFactor,
int &VF)
const;
2205 static bool isOneUseSingleSourceMask(
ArrayRef<int> Mask,
int VF);
2209 bool isOneUseSingleSourceMask(
int VF)
const;
2214 unsigned InVecNumElts) {
2215 for (
int &
Idx : Mask) {
2218 Idx =
Idx < (int)InVecNumElts ?
Idx + InVecNumElts :
Idx - InVecNumElts;
2220 "shufflevector mask index out of range");
2225 bool isInterleave(
unsigned Factor);
2246 static bool isInterleaveMask(
ArrayRef<int> Mask,
unsigned Factor,
2247 unsigned NumInputElts,
2250 unsigned NumInputElts) {
2252 return isInterleaveMask(Mask, Factor, NumInputElts, StartIndexes);
2258 static bool isDeInterleaveMaskOfFactor(
ArrayRef<int> Mask,
unsigned Factor,
2262 return isDeInterleaveMaskOfFactor(Mask, Factor, Unused);
2276 static bool isBitRotateMask(
ArrayRef<int> Mask,
unsigned EltSizeInBits,
2277 unsigned MinSubElts,
unsigned MaxSubElts,
2278 unsigned &NumSubElts,
unsigned &RotateAmt);
2282 return I->getOpcode() == Instruction::ShuffleVector;
2285 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2324 const Twine &NameStr =
"",
2345 return getOperand(0);
2348 return getOperand(0);
2359 return (
unsigned)Indices.
size();
2368 return I->getOpcode() == Instruction::ExtractValue;
2371 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2375ExtractValueInst::ExtractValueInst(Value *Agg, ArrayRef<unsigned> Idxs,
2376 const Twine &NameStr,
2377 InsertPosition InsertBefore)
2379 ExtractValue, Agg, InsertBefore) {
2380 init(Idxs, NameStr);
2405 const Twine &NameStr =
"",
2409 const Twine &NameStr);
2419 void *
operator new(
size_t S) {
return User::operator
new(S, 2); }
2420 void operator delete(
void *
Ptr) { User::operator
delete(
Ptr); }
2424 const Twine &NameStr =
"",
2465 return (
unsigned)Indices.
size();
2474 return I->getOpcode() == Instruction::InsertValue;
2477 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
2486InsertValueInst::InsertValueInst(
Value *Agg,
Value *Val,
2492 init(Agg, Val, Idxs, NameStr);
2508 unsigned ReservedSpace;
2512 explicit PHINode(
Type *Ty,
unsigned NumReservedValues,
2513 const Twine &NameStr =
"",
2515 :
Instruction(Ty, Instruction::PHI,
nullptr, 0, InsertBefore),
2516 ReservedSpace(NumReservedValues) {
2519 allocHungoffUses(ReservedSpace);
2539 const Twine &NameStr =
"",
2541 return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
2560 return block_begin() + getNumOperands();
2564 return make_range(block_begin(), block_end());
2578 return getOperand(i);
2581 assert(V &&
"PHI node got a null value!");
2583 "All operands to PHI node must be the same type as the PHI node!");
2598 return block_begin()[i];
2605 assert(
this == U.getUser() &&
"Iterator doesn't point to PHI's Uses?");
2606 return getIncomingBlock(
unsigned(&U - op_begin()));
2613 return getIncomingBlock(
I.getUse());
2629 assert(New && Old &&
"PHI node got a null basic block!");
2630 for (
unsigned Op = 0, NumOps = getNumOperands();
Op != NumOps; ++
Op)
2631 if (getIncomingBlock(
Op) == Old)
2632 setIncomingBlock(
Op, New);
2638 if (getNumOperands() == ReservedSpace)
2641 setNumHungOffUseOperands(getNumOperands() + 1);
2642 setIncomingValue(getNumOperands() - 1, V);
2643 setIncomingBlock(getNumOperands() - 1, BB);
2654 Value *removeIncomingValue(
unsigned Idx,
bool DeletePHIIfEmpty =
true);
2657 int Idx = getBasicBlockIndex(BB);
2658 assert(
Idx >= 0 &&
"Invalid basic block argument to remove!");
2659 return removeIncomingValue(
Idx, DeletePHIIfEmpty);
2664 void removeIncomingValueIf(
function_ref<
bool(
unsigned)> Predicate,
2665 bool DeletePHIIfEmpty =
true);
2671 for (
unsigned i = 0, e = getNumOperands(); i != e; ++i)
2672 if (block_begin()[i] == BB)
2678 int Idx = getBasicBlockIndex(BB);
2679 assert(
Idx >= 0 &&
"Invalid basic block argument!");
2680 return getIncomingValue(
Idx);
2685 assert(BB &&
"PHI node got a null basic block!");
2687 for (
unsigned Op = 0, NumOps = getNumOperands();
Op != NumOps; ++
Op)
2688 if (getIncomingBlock(
Op) == BB) {
2690 setIncomingValue(
Op, V);
2693 assert(Found &&
"Invalid basic block argument to set!");
2698 Value *hasConstantValue()
const;
2703 bool hasConstantOrUndefValue()
const;
2710 return getBasicBlockIndex(Pred) >= 0;
2716 return I->getOpcode() == Instruction::PHI;
2719 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2723 void growOperands();
2749 unsigned ReservedSpace;
2761 void *
operator new(
size_t S) {
return User::operator
new(S); }
2763 void growOperands(
unsigned Size);
2764 void init(
unsigned NumReservedValues,
const Twine &NameStr);
2773 void operator delete(
void *
Ptr) { User::operator
delete(
Ptr); }
2778 const Twine &NameStr =
"",
2787 bool isCleanup()
const {
return getSubclassData<CleanupField>(); }
2798 return cast<Constant>(getOperandList()[
Idx]);
2803 return !isa<ArrayType>(getOperandList()[
Idx]->
getType());
2808 return isa<ArrayType>(getOperandList()[
Idx]->
getType());
2820 return I->getOpcode() == Instruction::LandingPad;
2823 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2870 return new(!!retVal)
ReturnInst(
C, retVal, InsertBefore);
2874 return new (0)
ReturnInst(
C,
nullptr, InsertAtEnd);
2882 return getNumOperands() != 0 ? getOperand(0) :
nullptr;
2889 return (
I->getOpcode() == Instruction::Ret);
2892 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2896 BasicBlock *getSuccessor(
unsigned idx)
const {
2900 void setSuccessor(
unsigned idx, BasicBlock *
B) {
2953 std::random_access_iterator_tag, BasicBlock *,
2954 ptrdiff_t, BasicBlock *, BasicBlock *> {
2964 std::random_access_iterator_tag,
2965 const BasicBlock *, ptrdiff_t, const BasicBlock *,
2966 const BasicBlock *> {
2976 return new(1)
BranchInst(IfTrue, InsertBefore);
2992 assert(isConditional() &&
"Cannot get condition of an uncond branch!");
2997 assert(isConditional() &&
"Cannot set condition of unconditional branch!");
3004 assert(i < getNumSuccessors() &&
"Successor # out of range for Branch!");
3005 return cast_or_null<BasicBlock>((&
Op<-1>() - i)->
get());
3009 assert(idx < getNumSuccessors() &&
"Successor # out of range for Branch!");
3010 *(&
Op<-1>() - idx) = NewSucc;
3018 void swapSuccessors();
3028 std::next(value_op_begin(), isConditional() ? 1 : 0)),
3034 return (
I->getOpcode() == Instruction::Br);
3037 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3055 unsigned ReservedSpace;
3071 void *
operator new(
size_t S) {
return User::operator
new(S); }
3074 void growOperands();
3083 void operator delete(
void *
Ptr) { User::operator
delete(
Ptr); }
3086 static const unsigned DefaultPseudoIndex =
static_cast<unsigned>(~0L-1);
3095 template <
typename SwitchInstT,
typename ConstantIntT,
typename BasicBlockT>
3114 assert((
unsigned)Index < SI->getNumCases() &&
3115 "Index out the number of cases.");
3116 return reinterpret_cast<ConstantIntT *
>(
SI->getOperand(2 +
Index * 2));
3121 assert(((
unsigned)Index < SI->getNumCases() ||
3122 (
unsigned)
Index == DefaultPseudoIndex) &&
3123 "Index out the number of cases.");
3124 return SI->getSuccessor(getSuccessorIndex());
3133 (
unsigned)Index < SI->getNumCases()) &&
3134 "Index out the number of cases.");
3135 return (
unsigned)
Index != DefaultPseudoIndex ?
Index + 1 : 0;
3139 assert(
SI ==
RHS.SI &&
"Incompatible operators.");
3156 assert((
unsigned)Index < SI->getNumCases() &&
3157 "Index out the number of cases.");
3158 SI->setOperand(2 +
Index*2,
reinterpret_cast<Value*
>(V));
3163 SI->setSuccessor(getSuccessorIndex(), S);
3167 template <
typename CaseHandleT>
3170 std::random_access_iterator_tag,
3171 const CaseHandleT> {
3172 using SwitchInstT =
typename CaseHandleT::SwitchInstType;
3188 unsigned SuccessorIndex) {
3189 assert(SuccessorIndex < SI->getNumSuccessors() &&
3190 "Successor index # out of range!");
3205 (
unsigned)(Case.Index +
N) <= Case.SI->getNumCases() &&
3206 "Case.Index out the number of cases.");
3214 (
unsigned)(Case.Index -
N) <= Case.SI->getNumCases() &&
3215 "Case.Index out the number of cases.");
3220 assert(Case.SI ==
RHS.Case.SI &&
"Incompatible operators.");
3221 return Case.Index -
RHS.Case.Index;
3224 return Case ==
RHS.Case;
3227 assert(Case.SI ==
RHS.Case.SI &&
"Incompatible operators.");
3228 return Case.Index <
RHS.Case.Index;
3250 return cast<BasicBlock>(getOperand(1));
3256 return isa<UnreachableInst>(getDefaultDest()->getFirstNonPHIOrDbg());
3260 setOperand(1,
reinterpret_cast<Value*
>(DefaultCase));
3266 return getNumOperands()/2 - 1;
3284 return CaseIt(
this, getNumCases());
3309 return CaseIt(
this, DefaultPseudoIndex);
3322 const_cast<const SwitchInst *
>(
this)->findCaseValue(
C)->getCaseIndex());
3328 if (
I != case_end())
3331 return case_default();
3337 if (BB == getDefaultDest())
3341 for (
auto Case : cases()) {
3342 if (Case.getCaseSuccessor() != BB)
3348 CI = Case.getCaseValue();
3367 CaseIt removeCase(CaseIt
I);
3371 assert(idx < getNumSuccessors() &&
"Successor idx out of range for switch!");
3372 return cast<BasicBlock>(getOperand(idx*2+1));
3375 assert(idx < getNumSuccessors() &&
"Successor # out of range for switch!");
3376 setOperand(idx * 2 + 1, NewSucc);
3381 return I->getOpcode() == Instruction::Switch;
3384 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3392 std::optional<SmallVector<uint32_t, 8>> Weights;
3393 bool Changed =
false;
3445 unsigned ReservedSpace;
3459 void *
operator new(
size_t S) {
return User::operator
new(S); }
3462 void growOperands();
3471 void operator delete(
void *
Ptr) { User::operator
delete(
Ptr); }
3479 std::random_access_iterator_tag, BasicBlock *,
3480 ptrdiff_t, BasicBlock *, BasicBlock *> {
3490 std::random_access_iterator_tag,
3491 const BasicBlock *, ptrdiff_t, const BasicBlock *,
3492 const BasicBlock *> {
3527 void removeDestination(
unsigned i);
3531 return cast<BasicBlock>(getOperand(i+1));
3534 setOperand(i + 1, NewSucc);
3549 return I->getOpcode() == Instruction::IndirectBr;
3552 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3572 static constexpr int NumExtraOperands = 2;
3575 static constexpr int NormalDestOpEndIdx = -3;
3578 static constexpr int UnwindDestOpEndIdx = -2;
3595 static int ComputeNumOperands(
int NumArgs,
int NumBundleInputs = 0) {
3598 return 1 + NumExtraOperands + NumArgs + NumBundleInputs;
3610 const Twine &NameStr,
3612 int NumOperands = ComputeNumOperands(Args.size());
3613 return new (NumOperands)
3614 InvokeInst(Ty, Func, IfNormal, IfException, Args, std::nullopt,
3615 NumOperands, NameStr, InsertBefore);
3621 const Twine &NameStr =
"",
3624 ComputeNumOperands(Args.size(), CountBundleInputs(Bundles));
3627 return new (NumOperands, DescriptorBytes)
3628 InvokeInst(Ty, Func, IfNormal, IfException, Args, Bundles, NumOperands,
3629 NameStr, InsertBefore);
3634 const Twine &NameStr,
3636 return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
3637 IfException, Args, std::nullopt, NameStr, InsertBefore);
3643 const Twine &NameStr =
"",
3645 return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
3646 IfException, Args, Bundles, NameStr, InsertBefore);
3677 assert(i < 2 &&
"Successor # out of range for invoke!");
3678 return i == 0 ? getNormalDest() : getUnwindDest();
3682 assert(i < 2 &&
"Successor # out of range for invoke!");
3684 setNormalDest(NewSucc);
3686 setUnwindDest(NewSucc);
3696 return (
I->getOpcode() == Instruction::Invoke);
3699 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3705 template <
typename Bitfield>
3706 void setSubclassData(
typename Bitfield::Type
Value) {
3707 Instruction::setSubclassData<Bitfield>(
Value);
3711InvokeInst::InvokeInst(
FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3712 BasicBlock *IfException, ArrayRef<Value *> Args,
3713 ArrayRef<OperandBundleDef> Bundles,
int NumOperands,
3714 const Twine &NameStr, InsertPosition InsertBefore)
3715 : CallBase(Ty->getReturnType(), Instruction::Invoke,
3716 OperandTraits<CallBase>::op_end(this) - NumOperands, NumOperands,
3718 init(Ty, Func, IfNormal, IfException, Args, Bundles, NameStr);
3731 unsigned NumIndirectDests;
3741 int NumOperands,
const Twine &NameStr,
3749 static int ComputeNumOperands(
int NumArgs,
int NumIndirectDests,
3750 int NumBundleInputs = 0) {
3753 return 2 + NumIndirectDests + NumArgs + NumBundleInputs;
3768 int NumOperands = ComputeNumOperands(Args.size(), IndirectDests.
size());
3769 return new (NumOperands)
3770 CallBrInst(Ty, Func, DefaultDest, IndirectDests, Args, std::nullopt,
3771 NumOperands, NameStr, InsertBefore);
3779 int NumOperands = ComputeNumOperands(Args.size(), IndirectDests.
size(),
3783 return new (NumOperands, DescriptorBytes)
3784 CallBrInst(Ty, Func, DefaultDest, IndirectDests, Args, Bundles,
3785 NumOperands, NameStr, InsertBefore);
3792 return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
3793 IndirectDests, Args, NameStr, InsertBefore);
3800 const Twine &NameStr =
"",
3802 return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
3803 IndirectDests, Args, Bundles, NameStr, InsertBefore);
3842 return IndirectDests;
3853 "Successor # out of range for callbr!");
3859 "Successor # out of range for callbr!");
3867 return (
I->getOpcode() == Instruction::CallBr);
3870 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
3876 template <
typename Bitfield>
3877 void setSubclassData(
typename Bitfield::Type
Value) {
3878 Instruction::setSubclassData<Bitfield>(
Value);
3882CallBrInst::CallBrInst(
FunctionType *Ty, Value *Func, BasicBlock *DefaultDest,
3883 ArrayRef<BasicBlock *> IndirectDests,
3884 ArrayRef<Value *> Args,
3885 ArrayRef<OperandBundleDef> Bundles,
int NumOperands,
3886 const Twine &NameStr, InsertPosition InsertBefore)
3887 : CallBase(Ty->getReturnType(), Instruction::CallBr,
3888 OperandTraits<CallBase>::op_end(this) - NumOperands, NumOperands,
3890 init(Ty, Func, DefaultDest, IndirectDests, Args, Bundles, NameStr);
3926 return I->getOpcode() == Instruction::Resume;
3929 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
3933 BasicBlock *getSuccessor(
unsigned idx)
const {
3937 void setSuccessor(
unsigned idx,
BasicBlock *NewSucc) {
3957 unsigned ReservedSpace;
3969 unsigned NumHandlers,
const Twine &NameStr,
3973 void *
operator new(
size_t S) {
return User::operator
new(S); }
3975 void init(
Value *ParentPad,
BasicBlock *UnwindDest,
unsigned NumReserved);
3976 void growOperands(
unsigned Size);
3985 void operator delete(
void *
Ptr) {
return User::operator
delete(
Ptr); }
3988 unsigned NumHandlers,
3989 const Twine &NameStr =
"",
3991 return new CatchSwitchInst(ParentPad, UnwindDest, NumHandlers, NameStr,
4006 if (hasUnwindDest())
4007 return cast<BasicBlock>(getOperand(1));
4013 setOperand(1, UnwindDest);
4019 if (hasUnwindDest())
4020 return getNumOperands() - 2;
4021 return getNumOperands() - 1;
4025 static BasicBlock *handler_helper(
Value *V) {
return cast<BasicBlock>(V); }
4026 static const BasicBlock *handler_helper(
const Value *V) {
4027 return cast<BasicBlock>(V);
4042 if (hasUnwindDest())
4051 if (hasUnwindDest())
4070 return make_range(handler_begin(), handler_end());
4075 return make_range(handler_begin(), handler_end());
4084 void removeHandler(handler_iterator HI);
4089 "Successor # out of range for catchswitch!");
4090 return cast<BasicBlock>(getOperand(
Idx + 1));
4094 "Successor # out of range for catchswitch!");
4095 setOperand(
Idx + 1, NewSucc);
4100 return I->getOpcode() == Instruction::CatchSwitch;
4103 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4118 unsigned Values,
const Twine &NameStr,
4120 :
FuncletPadInst(Instruction::CleanupPad, ParentPad, Args, Values,
4121 NameStr, InsertBefore) {}
4126 const Twine &NameStr =
"",
4128 unsigned Values = 1 + Args.size();
4135 return I->getOpcode() == Instruction::CleanupPad;
4138 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4148 unsigned Values,
const Twine &NameStr,
4150 :
FuncletPadInst(Instruction::CatchPad, CatchSwitch, Args, Values,
4151 NameStr, InsertBefore) {}
4155 const Twine &NameStr =
"",
4157 unsigned Values = 1 + Args.size();
4159 CatchPadInst(CatchSwitch, Args, Values, NameStr, InsertBefore);
4164 return cast<CatchSwitchInst>(
Op<-1>());
4168 Op<-1>() = CatchSwitch;
4173 return I->getOpcode() == Instruction::CatchPad;
4176 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
4229 return (
I->getOpcode() == Instruction::CatchRet);
4232 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
4278 unsigned Values = 1;
4293 return cast<CleanupPadInst>(
Op<0>());
4297 Op<0>() = CleanupPad;
4303 return hasUnwindDest() ? cast<BasicBlock>(
Op<1>()) :
nullptr;
4313 return (
I->getOpcode() == Instruction::CleanupRet);
4316 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4322 return getUnwindDest();
4325 void setSuccessor(
unsigned Idx, BasicBlock *
B) {
4332 template <
typename Bitfield>
4333 void setSubclassData(
typename Bitfield::Type Value) {
4334 Instruction::setSubclassData<Bitfield>(Value);
4365 void *
operator new(
size_t S) {
return User::operator
new(S, 0); }
4366 void operator delete(
void *
Ptr) { User::operator
delete(
Ptr); }
4372 return I->getOpcode() == Instruction::Unreachable;
4375 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4379 BasicBlock *getSuccessor(
unsigned idx)
const {
4383 void setSuccessor(
unsigned idx, BasicBlock *
B) {
4407 const Twine &NameStr =
"",
4414 return I->getOpcode() == Trunc;
4417 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
4443 unsigned NoWrapKind = 0;
4471 const Twine &NameStr =
"",
4478 return I->getOpcode() == ZExt;
4481 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
4502 const Twine &NameStr =
"",
4509 return I->getOpcode() == SExt;
4512 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
4532 const Twine &NameStr =
"",