15 #ifndef LLVM_IR_INSTRUCTIONS_H
16 #define LLVM_IR_INSTRUCTIONS_H
66 "Bitfields must be contiguous");
122 return Align(1ULL << getSubclassData<AlignmentField>());
126 setSubclassData<AlignmentField>(
Log2(
Align));
137 return getSubclassData<UsedWithInAllocaField>();
142 setSubclassData<UsedWithInAllocaField>(V);
146 bool isSwiftError()
const {
return getSubclassData<SwiftErrorField>(); }
152 return (
I->getOpcode() == Instruction::Alloca);
155 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
161 template <
typename Bitfield>
163 Instruction::setSubclassData<Bitfield>(
Value);
178 Bitfield::areContiguous<VolatileField, AlignmentField, OrderingField>(),
179 "Bitfields must be contiguous");
210 bool isVolatile()
const {
return getSubclassData<VolatileField>(); }
217 return Align(1ULL << (getSubclassData<AlignmentField>()));
221 setSubclassData<AlignmentField>(
Log2(
Align));
226 return getSubclassData<OrderingField>();
231 setSubclassData<OrderingField>(Ordering);
275 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
281 template <
typename Bitfield>
283 Instruction::setSubclassData<Bitfield>(
Value);
302 Bitfield::areContiguous<VolatileField, AlignmentField, OrderingField>(),
303 "Bitfields must be contiguous");
329 void *
operator new(
size_t S) {
return User::operator
new(
S, 2); }
330 void operator delete(
void *Ptr) { User::operator
delete(Ptr); }
333 bool isVolatile()
const {
return getSubclassData<VolatileField>(); }
342 return Align(1ULL << (getSubclassData<AlignmentField>()));
346 setSubclassData<AlignmentField>(
Log2(
Align));
351 return getSubclassData<OrderingField>();
357 setSubclassData<OrderingField>(Ordering);
404 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
410 template <
typename Bitfield>
412 Instruction::setSubclassData<Bitfield>(
Value);
453 void *
operator new(
size_t S) {
return User::operator
new(
S, 0); }
454 void operator delete(
void *Ptr) { User::operator
delete(Ptr); }
458 return getSubclassData<OrderingField>();
464 setSubclassData<OrderingField>(Ordering);
479 return I->getOpcode() == Instruction::Fence;
482 return isa<Instruction>(V) && classof(cast<Instruction>(V));
488 template <
typename Bitfield>
490 Instruction::setSubclassData<Bitfield>(
Value);
514 template <
unsigned Offset>
515 using AtomicOrderingBitfieldElement =
536 void *
operator new(
size_t S) {
return User::operator
new(
S, 3); }
537 void operator delete(
void *Ptr) { User::operator
delete(Ptr); }
550 "Bitfields must be contiguous");
555 return Align(1ULL << getSubclassData<AlignmentField>());
559 setSubclassData<AlignmentField>(
Log2(
Align));
565 bool isVolatile()
const {
return getSubclassData<VolatileField>(); }
572 bool isWeak()
const {
return getSubclassData<WeakField>(); }
574 void setWeak(
bool IsWeak) { setSubclassData<WeakField>(IsWeak); }
593 return getSubclassData<SuccessOrderingField>();
599 "invalid CmpXchg success ordering");
600 setSubclassData<SuccessOrderingField>(Ordering);
605 return getSubclassData<FailureOrderingField>();
611 "invalid CmpXchg failure ordering");
612 setSubclassData<FailureOrderingField>(Ordering);
663 switch (SuccessOrdering) {
679 return I->getOpcode() == Instruction::AtomicCmpXchg;
682 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
688 template <
typename Bitfield>
690 Instruction::setSubclassData<Bitfield>(
Value);
762 template <
unsigned Offset>
763 using AtomicOrderingBitfieldElement =
767 template <
unsigned Offset>
768 using BinOpBitfieldElement =
780 void *
operator new(
size_t S) {
return User::operator
new(
S, 2); }
781 void operator delete(
void *Ptr) { User::operator
delete(Ptr); }
790 "Bitfields must be contiguous");
807 setSubclassData<OperationField>(
Operation);
813 return Align(1ULL << getSubclassData<AlignmentField>());
817 setSubclassData<AlignmentField>(
Log2(
Align));
822 bool isVolatile()
const {
return getSubclassData<VolatileField>(); }
833 return getSubclassData<AtomicOrderingField>();
839 "atomicrmw instructions can only be atomic.");
840 setSubclassData<AtomicOrderingField>(Ordering);
866 return isFPOperation(getOperation());
871 return I->getOpcode() == Instruction::AtomicRMW;
874 return isa<Instruction>(V) && classof(cast<Instruction>(V));
883 template <
typename Bitfield>
885 Instruction::setSubclassData<Bitfield>(
Value);
909 assert(Ty &&
"Invalid GetElementPtrInst indices for type!");
917 Type *SourceElementType;
918 Type *ResultElementType;
944 const Twine &NameStr =
"",
946 unsigned Values = 1 + unsigned(IdxList.
size());
947 assert(PointeeType &&
"Must specify element type");
949 ->isOpaqueOrPointeeTypeMatches(PointeeType));
951 NameStr, InsertBefore);
956 const Twine &NameStr,
958 unsigned Values = 1 + unsigned(IdxList.
size());
959 assert(PointeeType &&
"Must specify element type");
961 ->isOpaqueOrPointeeTypeMatches(PointeeType));
963 NameStr, InsertAtEnd);
970 const Twine &NameStr =
"",
973 Create(PointeeType, Ptr, IdxList, NameStr, InsertBefore);
974 GEP->setIsInBounds(
true);
980 const Twine &NameStr,
983 Create(PointeeType, Ptr, IdxList, NameStr, InsertAtEnd);
984 GEP->setIsInBounds(
true);
998 ->isOpaqueOrPointeeTypeMatches(ResultElementType));
999 return ResultElementType;
1071 if (
auto *PtrVTy = dyn_cast<VectorType>(Ptr->
getType())) {
1076 if (
auto *IndexVTy = dyn_cast<VectorType>(
Index->getType())) {
1120 APInt &ConstantOffset)
const;
1123 return (
I->getOpcode() == Instruction::GetElementPtr);
1126 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
1135 GetElementPtrInst::GetElementPtrInst(
Type *PointeeType,
Value *Ptr,
1137 const Twine &NameStr,
1139 :
Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr,
1141 Values, InsertBefore),
1142 SourceElementType(PointeeType),
1143 ResultElementType(getIndexedType(PointeeType, IdxList)) {
1145 ->isOpaqueOrPointeeTypeMatches(ResultElementType));
1146 init(Ptr, IdxList, NameStr);
1149 GetElementPtrInst::GetElementPtrInst(Type *PointeeType,
Value *Ptr,
1150 ArrayRef<Value *> IdxList,
unsigned Values,
1151 const Twine &NameStr,
1153 : Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr,
1154 OperandTraits<GetElementPtrInst>::op_end(
this) - Values,
1155 Values, InsertAtEnd),
1156 SourceElementType(PointeeType),
1157 ResultElementType(getIndexedType(PointeeType, IdxList)) {
1159 ->isOpaqueOrPointeeTypeMatches(ResultElementType));
1160 init(Ptr, IdxList, NameStr);
1175 assert(isIntPredicate() &&
1176 "Invalid ICmp predicate value");
1178 "Both operands to ICmp instruction are not of the same type!");
1181 getOperand(0)->
getType()->isPtrOrPtrVectorTy()) &&
1182 "Invalid operand types for ICmp instruction");
1199 const Twine &NameStr =
""
1214 const Twine &NameStr =
""
1228 const Twine &NameStr =
""
1263 return P == ICMP_EQ ||
P == ICMP_NE;
1279 return !isEquality();
1285 return !isEquality(
P);
1291 return P == ICMP_SGT ||
P == ICMP_UGT;
1297 return P == ICMP_SLT ||
P == ICMP_ULT;
1303 return P == ICMP_SGE ||
P == ICMP_UGE;
1309 return P == ICMP_SLE ||
P == ICMP_ULE;
1323 Op<0>().swap(Op<1>());
1332 return I->getOpcode() == Instruction::ICmp;
1335 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1351 "Both operands to FCmp instruction are not of the same type!");
1354 "Invalid operand types for FCmp instruction");
1371 const Twine &NameStr =
""
1384 const Twine &NameStr =
""
1396 const Twine &NameStr =
"",
1399 RHS, NameStr, nullptr, FlagsSource) {
1435 Op<0>().swap(Op<1>());
1448 return I->getOpcode() == Instruction::FCmp;
1451 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
1491 static int ComputeNumOperands(
int NumArgs,
int NumBundleInputs = 0) {
1494 return 1 + NumArgs + NumBundleInputs;
1506 return new (ComputeNumOperands(0))
CallInst(Ty,
F, NameStr, InsertBefore);
1510 const Twine &NameStr,
1512 return new (ComputeNumOperands(
Args.size()))
1518 const Twine &NameStr =
"",
1520 const int NumOperands =
1524 return new (NumOperands, DescriptorBytes)
1525 CallInst(Ty, Func,
Args, Bundles, NameStr, InsertBefore);
1530 return new (ComputeNumOperands(0))
CallInst(Ty,
F, NameStr, InsertAtEnd);
1535 return new (ComputeNumOperands(
Args.size()))
1542 const int NumOperands =
1546 return new (NumOperands, DescriptorBytes)
1547 CallInst(Ty, Func,
Args, Bundles, NameStr, InsertAtEnd);
1552 return Create(Func.getFunctionType(), Func.getCallee(), NameStr,
1558 const Twine &NameStr =
"",
1560 return Create(Func.getFunctionType(), Func.getCallee(),
Args, Bundles,
1561 NameStr, InsertBefore);
1565 const Twine &NameStr,
1567 return Create(Func.getFunctionType(), Func.getCallee(),
Args, NameStr,
1573 return Create(Func.getFunctionType(), Func.getCallee(), NameStr,
1579 return Create(Func.getFunctionType(), Func.getCallee(),
Args, NameStr,
1586 return Create(Func.getFunctionType(), Func.getCallee(),
Args, Bundles,
1587 NameStr, InsertAtEnd);
1607 Value *ArraySize =
nullptr,
1612 Value *ArraySize =
nullptr,
1617 Value *ArraySize =
nullptr,
1623 Value *ArraySize =
nullptr,
1648 Bitfield::areContiguous<TailCallKindField, CallBase::CallingConvField>(),
1649 "Bitfields must be contiguous");
1652 return getSubclassData<TailCallKindField>();
1665 setSubclassData<TailCallKindField>(TCK);
1681 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
1690 template <
typename Bitfield>
1692 Instruction::setSubclassData<Bitfield>(
Value);
1697 ArrayRef<OperandBundleDef> Bundles,
const Twine &NameStr,
1699 : CallBase(Ty->getReturnType(), Instruction::
Call,
1700 OperandTraits<CallBase>::op_end(
this) -
1701 (
Args.
size() + CountBundleInputs(Bundles) + 1),
1702 unsigned(
Args.
size() + CountBundleInputs(Bundles) + 1),
1704 init(Ty, Func,
Args, Bundles, NameStr);
1708 ArrayRef<OperandBundleDef> Bundles,
const Twine &NameStr,
1709 Instruction *InsertBefore)
1710 : CallBase(Ty->getReturnType(), Instruction::
Call,
1711 OperandTraits<CallBase>::op_end(
this) -
1712 (
Args.
size() + CountBundleInputs(Bundles) + 1),
1713 unsigned(
Args.
size() + CountBundleInputs(Bundles) + 1),
1715 init(Ty, Func,
Args, Bundles, NameStr);
1728 &Op<0>(), 3, InsertBefore) {
1736 &Op<0>(), 3, InsertAtEnd) {
1756 const Twine &NameStr =
"",
1766 const Twine &NameStr,
1768 return new(3)
SelectInst(
C, S1, S2, NameStr, InsertAtEnd);
1802 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
1845 return I->getOpcode() == VAArg;
1848 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1873 const Twine &NameStr =
"",
1879 const Twine &NameStr,
1902 return I->getOpcode() == Instruction::ExtractElement;
1905 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
1925 const Twine &NameStr =
"",
1938 const Twine &NameStr =
"",
1944 const Twine &NameStr,
1951 static bool isValidOperands(
const Value *Vec,
const Value *NewElt,
1965 return I->getOpcode() == Instruction::InsertElement;
1968 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2015 const Twine &NameStr =
"",
2020 const Twine &NameStr =
"",
2025 void *
operator new(
size_t S) {
return User::operator
new(
S, 2); }
2026 void operator delete(
void *Ptr) {
return User::operator
delete(Ptr); }
2034 static bool isValidOperands(
const Value *V1,
const Value *
V2,
2036 static bool isValidOperands(
const Value *V1,
const Value *
V2,
2060 Result.assign(ShuffleMask.begin(), ShuffleMask.end());
2081 unsigned NumSourceElts = cast<VectorType>(Op<0>()->
getType())
2083 .getKnownMinValue();
2084 unsigned NumMaskElts = ShuffleMask.size();
2085 return NumSourceElts != NumMaskElts;
2092 unsigned NumSourceElts = cast<VectorType>(Op<0>()->
getType())
2094 .getKnownMinValue();
2095 unsigned NumMaskElts = ShuffleMask.size();
2096 return NumSourceElts < NumMaskElts;
2105 assert(
Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2107 getShuffleMask(
Mask, MaskAsInts);
2108 return isSingleSourceMask(MaskAsInts);
2116 return !changesLength() && isSingleSourceMask(ShuffleMask);
2126 assert(
Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2130 if (isa<ScalableVectorType>(
Mask->getType()))
2134 getShuffleMask(
Mask, MaskAsInts);
2135 return isIdentityMask(MaskAsInts);
2145 if (isa<ScalableVectorType>(
getType()))
2148 return !changesLength() && isIdentityMask(ShuffleMask);
2153 bool isIdentityWithPadding()
const;
2157 bool isIdentityWithExtract()
const;
2162 bool isConcat()
const;
2174 assert(
Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2176 getShuffleMask(
Mask, MaskAsInts);
2177 return isSelectMask(MaskAsInts);
2189 return !changesLength() && isSelectMask(ShuffleMask);
2198 assert(
Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2200 getShuffleMask(
Mask, MaskAsInts);
2218 assert(
Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2220 getShuffleMask(
Mask, MaskAsInts);
2221 return isZeroEltSplatMask(MaskAsInts);
2231 return !changesLength() && isZeroEltSplatMask(ShuffleMask);
2268 assert(
Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2270 getShuffleMask(
Mask, MaskAsInts);
2271 return isTransposeMask(MaskAsInts);
2280 return !changesLength() && isTransposeMask(ShuffleMask);
2290 assert(
Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2293 if (isa<ScalableVectorType>(
Mask->getType()))
2296 getShuffleMask(
Mask, MaskAsInts);
2297 return isExtractSubvectorMask(MaskAsInts, NumSrcElts,
Index);
2304 if (isa<ScalableVectorType>(
getType()))
2308 cast<FixedVectorType>(Op<0>()->
getType())->getNumElements();
2309 return isExtractSubvectorMask(ShuffleMask, NumSrcElts,
Index);
2317 int &NumSubElts,
int &
Index);
2319 int &NumSubElts,
int &
Index) {
2320 assert(
Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2323 if (isa<ScalableVectorType>(
Mask->getType()))
2326 getShuffleMask(
Mask, MaskAsInts);
2327 return isInsertSubvectorMask(MaskAsInts, NumSrcElts, NumSubElts,
Index);
2334 if (isa<ScalableVectorType>(
getType()))
2338 cast<FixedVectorType>(Op<0>()->
getType())->getNumElements();
2339 return isInsertSubvectorMask(ShuffleMask, NumSrcElts, NumSubElts,
Index);
2350 assert(
Mask->getType()->isVectorTy() &&
"Shuffle needs vector constant.");
2353 if (isa<ScalableVectorType>(
Mask->getType()))
2356 getShuffleMask(
Mask, MaskAsInts);
2357 return isReplicationMask(MaskAsInts, ReplicationFactor, VF);
2361 bool isReplicationMask(
int &ReplicationFactor,
int &VF)
const;
2366 unsigned InVecNumElts) {
2367 for (
int &Idx :
Mask) {
2370 Idx = Idx < (
int)InVecNumElts ? Idx + InVecNumElts : Idx - InVecNumElts;
2371 assert(Idx >= 0 && Idx < (
int)InVecNumElts * 2 &&
2372 "shufflevector mask index out of range");
2378 return I->getOpcode() == Instruction::ShuffleVector;
2381 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2409 const Twine &NameStr,
2426 const Twine &NameStr =
"",
2434 const Twine &NameStr,
2454 return getOperand(0);
2457 return getOperand(0);
2468 return (
unsigned)Indices.size();
2477 return I->getOpcode() == Instruction::ExtractValue;
2480 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2484 ExtractValueInst::ExtractValueInst(
Value *Agg,
2485 ArrayRef<unsigned> Idxs,
2486 const Twine &NameStr,
2487 Instruction *InsertBefore)
2489 ExtractValue, Agg, InsertBefore) {
2490 init(Idxs, NameStr);
2493 ExtractValueInst::ExtractValueInst(
Value *Agg,
2494 ArrayRef<unsigned> Idxs,
2495 const Twine &NameStr,
2498 ExtractValue, Agg, InsertAtEnd) {
2499 init(Idxs, NameStr);
2520 const Twine &NameStr,
2529 const Twine &NameStr =
"",
2535 const Twine &NameStr);
2545 void *
operator new(
size_t S) {
return User::operator
new(
S, 2); }
2546 void operator delete(
void *Ptr) { User::operator
delete(Ptr); }
2550 const Twine &NameStr =
"",
2557 const Twine &NameStr,
2598 return (
unsigned)Indices.size();
2607 return I->getOpcode() == Instruction::InsertValue;
2610 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
2619 InsertValueInst::InsertValueInst(
Value *Agg,
2622 const Twine &NameStr,
2627 init(Agg, Val, Idxs, NameStr);
2630 InsertValueInst::InsertValueInst(
Value *Agg,
2632 ArrayRef<unsigned> Idxs,
2633 const Twine &NameStr,
2635 : Instruction(Agg->
getType(), InsertValue,
2636 OperandTraits<InsertValueInst>::op_begin(
this),
2638 init(Agg, Val, Idxs, NameStr);
2654 unsigned ReservedSpace;
2658 explicit PHINode(
Type *Ty,
unsigned NumReservedValues,
2659 const Twine &NameStr =
"",
2661 :
Instruction(Ty, Instruction::PHI,
nullptr, 0, InsertBefore),
2662 ReservedSpace(NumReservedValues) {
2665 allocHungoffUses(ReservedSpace);
2670 :
Instruction(Ty, Instruction::PHI,
nullptr, 0, InsertAtEnd),
2671 ReservedSpace(NumReservedValues) {
2674 allocHungoffUses(ReservedSpace);
2694 const Twine &NameStr =
"",
2696 return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
2701 return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
2714 return reinterpret_cast<block_iterator>(op_begin() + ReservedSpace);
2722 return block_begin() + getNumOperands();
2726 return block_begin() + getNumOperands();
2730 return make_range(block_begin(), block_end());
2734 return make_range(block_begin(), block_end());
2748 return getOperand(
i);
2751 assert(V &&
"PHI node got a null value!");
2753 "All operands to PHI node must be the same type as the PHI node!");
2768 return block_begin()[
i];
2775 assert(
this == U.
getUser() &&
"Iterator doesn't point to PHI's Uses?");
2776 return getIncomingBlock(
unsigned(&U - op_begin()));
2783 return getIncomingBlock(
I.getUse());
2787 assert(
BB &&
"PHI node got a null basic block!");
2788 block_begin()[
i] =
BB;
2793 assert(New && Old &&
"PHI node got a null basic block!");
2794 for (
unsigned Op = 0, NumOps = getNumOperands();
Op != NumOps; ++
Op)
2795 if (getIncomingBlock(
Op) == Old)
2796 setIncomingBlock(
Op, New);
2802 if (getNumOperands() == ReservedSpace)
2805 setNumHungOffUseOperands(getNumOperands() + 1);
2806 setIncomingValue(getNumOperands() - 1, V);
2807 setIncomingBlock(getNumOperands() - 1,
BB);
2818 Value *removeIncomingValue(
unsigned Idx,
bool DeletePHIIfEmpty =
true);
2821 int Idx = getBasicBlockIndex(
BB);
2822 assert(Idx >= 0 &&
"Invalid basic block argument to remove!");
2823 return removeIncomingValue(Idx, DeletePHIIfEmpty);
2830 for (
unsigned i = 0,
e = getNumOperands();
i !=
e; ++
i)
2831 if (block_begin()[
i] ==
BB)
2837 int Idx = getBasicBlockIndex(
BB);
2838 assert(Idx >= 0 &&
"Invalid basic block argument!");
2839 return getIncomingValue(Idx);
2844 assert(
BB &&
"PHI node got a null basic block!");
2846 for (
unsigned Op = 0, NumOps = getNumOperands();
Op != NumOps; ++
Op)
2847 if (getIncomingBlock(
Op) ==
BB) {
2849 setIncomingValue(
Op, V);
2852 assert(Found &&
"Invalid basic block argument to set!");
2857 Value *hasConstantValue()
const;
2862 bool hasConstantOrUndefValue()
const;
2869 return getBasicBlockIndex(Pred) >= 0;
2875 return I->getOpcode() == Instruction::PHI;
2878 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2882 void growOperands();
2908 unsigned ReservedSpace;
2922 void *
operator new(
size_t S) {
return User::operator
new(
S); }
2924 void growOperands(
unsigned Size);
2925 void init(
unsigned NumReservedValues,
const Twine &NameStr);
2934 void operator delete(
void *Ptr) { User::operator
delete(Ptr); }
2939 const Twine &NameStr =
"",
2950 bool isCleanup()
const {
return getSubclassData<CleanupField>(); }
2961 return cast<Constant>(getOperandList()[Idx]);
2966 return !isa<ArrayType>(getOperandList()[Idx]->
getType());
2971 return isa<ArrayType>(getOperandList()[Idx]->
getType());
2983 return I->getOpcode() == Instruction::LandingPad;
2986 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3033 return new(!!retVal)
ReturnInst(
C, retVal, InsertBefore);
3038 return new(!!retVal)
ReturnInst(
C, retVal, InsertAtEnd);
3050 return getNumOperands() != 0 ? getOperand(0) :
nullptr;
3060 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3064 BasicBlock *getSuccessor(
unsigned idx)
const {
3121 std::random_access_iterator_tag, BasicBlock *,
3122 ptrdiff_t, BasicBlock *, BasicBlock *> {
3132 std::random_access_iterator_tag,
3133 const BasicBlock *, ptrdiff_t, const BasicBlock *,
3134 const BasicBlock *> {
3144 return new(1)
BranchInst(IfTrue, InsertBefore);
3153 return new(1)
BranchInst(IfTrue, InsertAtEnd);
3168 assert(isConditional() &&
"Cannot get condition of an uncond branch!");
3173 assert(isConditional() &&
"Cannot set condition of unconditional branch!");
3180 assert(
i < getNumSuccessors() &&
"Successor # out of range for Branch!");
3181 return cast_or_null<BasicBlock>((&Op<-1>() -
i)->
get());
3185 assert(idx < getNumSuccessors() &&
"Successor # out of range for Branch!");
3186 *(&
Op<-1>() - idx) = NewSucc;
3194 void swapSuccessors();
3204 std::next(value_op_begin(), isConditional() ? 1 : 0)),
3210 return (
I->getOpcode() == Instruction::Br);
3213 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3231 unsigned ReservedSpace;
3254 void *
operator new(
size_t S) {
return User::operator
new(
S); }
3257 void growOperands();
3266 void operator delete(
void *Ptr) { User::operator
delete(Ptr); }
3269 static const unsigned DefaultPseudoIndex =
static_cast<unsigned>(~0L-1);
3278 template <
typename SwitchInstT,
typename ConstantIntT,
typename BasicBlockT>
3298 "Index out the number of cases.");
3299 return reinterpret_cast<ConstantIntT *
>(
SI->getOperand(2 +
Index * 2));
3305 (
unsigned)
Index == DefaultPseudoIndex) &&
3306 "Index out the number of cases.");
3307 return SI->getSuccessor(getSuccessorIndex());
3317 "Index out the number of cases.");
3318 return (
unsigned)
Index != DefaultPseudoIndex ?
Index + 1 : 0;
3322 assert(
SI ==
RHS.SI &&
"Incompatible operators.");
3327 using ConstCaseHandle =
3340 "Index out the number of cases.");
3341 SI->setOperand(2 +
Index*2,
reinterpret_cast<Value*
>(V));
3346 SI->setSuccessor(getSuccessorIndex(),
S);
3350 template <
typename CaseHandleT>
3351 class CaseIteratorImpl
3353 std::random_access_iterator_tag,
3354 const CaseHandleT> {
3355 using SwitchInstT =
typename CaseHandleT::SwitchInstType;
3362 CaseIteratorImpl() =
default;
3371 unsigned SuccessorIndex) {
3372 assert(SuccessorIndex < SI->getNumSuccessors() &&
3373 "Successor index # out of range!");
3388 (
unsigned)(Case.Index +
N) <= Case.SI->getNumCases() &&
3389 "Case.Index out the number of cases.");
3397 (
unsigned)(Case.Index -
N) <= Case.SI->getNumCases() &&
3398 "Case.Index out the number of cases.");
3403 assert(Case.SI ==
RHS.Case.SI &&
"Incompatible operators.");
3404 return Case.Index -
RHS.Case.Index;
3407 return Case ==
RHS.Case;
3410 assert(Case.SI ==
RHS.Case.SI &&
"Incompatible operators.");
3411 return Case.Index <
RHS.Case.Index;
3426 unsigned NumCases,
BasicBlock *InsertAtEnd) {
3438 return cast<BasicBlock>(getOperand(1));
3442 setOperand(1,
reinterpret_cast<Value*
>(DefaultCase));
3448 return getNumOperands()/2 - 1;
3466 return CaseIt(
this, getNumCases());
3491 return CaseIt(
this, DefaultPseudoIndex);
3504 const_cast<const SwitchInst *
>(
this)->findCaseValue(
C)->getCaseIndex());
3510 if (
I != case_end())
3513 return case_default();
3519 if (
BB == getDefaultDest())
3523 for (
auto Case :
cases()) {
3524 if (Case.getCaseSuccessor() !=
BB)
3530 CI = Case.getCaseValue();
3549 CaseIt removeCase(CaseIt
I);
3553 assert(idx < getNumSuccessors() &&
"Successor idx out of range for switch!");
3554 return cast<BasicBlock>(getOperand(idx*2+1));
3557 assert(idx < getNumSuccessors() &&
"Successor # out of range for switch!");
3558 setOperand(idx * 2 + 1, NewSucc);
3563 return I->getOpcode() == Instruction::Switch;
3566 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3575 bool Changed =
false;
3629 unsigned ReservedSpace;
3648 void *
operator new(
size_t S) {
return User::operator
new(
S); }
3650 void init(
Value *Address,
unsigned NumDests);
3651 void growOperands();
3660 void operator delete(
void *Ptr) { User::operator
delete(Ptr); }
3668 std::random_access_iterator_tag, BasicBlock *,
3669 ptrdiff_t, BasicBlock *, BasicBlock *> {
3679 std::random_access_iterator_tag,
3680 const BasicBlock *, ptrdiff_t, const BasicBlock *,
3681 const BasicBlock *> {
3721 void removeDestination(
unsigned i);
3725 return cast<BasicBlock>(getOperand(
i+1));
3728 setOperand(
i + 1, NewSucc);
3743 return I->getOpcode() == Instruction::IndirectBr;
3746 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3766 static constexpr
int NumExtraOperands = 2;
3769 static constexpr
int NormalDestOpEndIdx = -3;
3772 static constexpr
int UnwindDestOpEndIdx = -2;
3794 static int ComputeNumOperands(
int NumArgs,
int NumBundleInputs = 0) {
3797 return 1 + NumExtraOperands + NumArgs + NumBundleInputs;
3809 const Twine &NameStr,
3811 int NumOperands = ComputeNumOperands(
Args.size());
3812 return new (NumOperands)
3814 NameStr, InsertBefore);
3820 const Twine &NameStr =
"",
3823 ComputeNumOperands(
Args.size(), CountBundleInputs(Bundles));
3826 return new (NumOperands, DescriptorBytes)
3827 InvokeInst(Ty, Func, IfNormal, IfException,
Args, Bundles, NumOperands,
3828 NameStr, InsertBefore);
3834 int NumOperands = ComputeNumOperands(
Args.size());
3835 return new (NumOperands)
3837 NameStr, InsertAtEnd);
3845 ComputeNumOperands(
Args.size(), CountBundleInputs(Bundles));
3848 return new (NumOperands, DescriptorBytes)
3849 InvokeInst(Ty, Func, IfNormal, IfException,
Args, Bundles, NumOperands,
3850 NameStr, InsertAtEnd);
3855 const Twine &NameStr,
3857 return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
3858 IfException,
Args,
None, NameStr, InsertBefore);
3864 const Twine &NameStr =
"",
3866 return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
3867 IfException,
Args, Bundles, NameStr, InsertBefore);
3873 return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
3874 IfException,
Args, NameStr, InsertAtEnd);
3881 return Create(Func.getFunctionType(), Func.getCallee(), IfNormal,
3882 IfException,
Args, Bundles, NameStr, InsertAtEnd);
3896 return cast<BasicBlock>(Op<NormalDestOpEndIdx>());
3899 return cast<BasicBlock>(Op<UnwindDestOpEndIdx>());
3902 Op<NormalDestOpEndIdx>() =
reinterpret_cast<Value *
>(
B);
3905 Op<UnwindDestOpEndIdx>() =
reinterpret_cast<Value *
>(
B);
3913 assert(
i < 2 &&
"Successor # out of range for invoke!");
3914 return i == 0 ? getNormalDest() : getUnwindDest();
3918 assert(
i < 2 &&
"Successor # out of range for invoke!");
3920 setNormalDest(NewSucc);
3922 setUnwindDest(NewSucc);
3929 return (
I->getOpcode() == Instruction::Invoke);
3932 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3938 template <
typename Bitfield>
3940 Instruction::setSubclassData<Bitfield>(
Value);
3946 ArrayRef<OperandBundleDef> Bundles,
int NumOperands,
3947 const Twine &NameStr, Instruction *InsertBefore)
3948 : CallBase(Ty->getReturnType(), Instruction::Invoke,
3949 OperandTraits<CallBase>::op_end(
this) - NumOperands, NumOperands,
3951 init(Ty, Func, IfNormal, IfException,
Args, Bundles, NameStr);
3956 ArrayRef<OperandBundleDef> Bundles,
int NumOperands,
3957 const Twine &NameStr,
BasicBlock *InsertAtEnd)
3958 : CallBase(Ty->getReturnType(), Instruction::Invoke,
3959 OperandTraits<CallBase>::op_end(
this) - NumOperands, NumOperands,
3961 init(Ty, Func, IfNormal, IfException,
Args, Bundles, NameStr);
3974 unsigned NumIndirectDests;
3998 void updateArgBlockAddresses(
unsigned i,
BasicBlock *
B);
4001 static int ComputeNumOperands(
int NumArgs,
int NumIndirectDests,
4002 int NumBundleInputs = 0) {
4005 return 2 + NumIndirectDests + NumArgs + NumBundleInputs;
4020 int NumOperands = ComputeNumOperands(
Args.size(), IndirectDests.
size());
4021 return new (NumOperands)
4023 NumOperands, NameStr, InsertBefore);
4031 const Twine &NameStr =
"",
4033 int NumOperands = ComputeNumOperands(
Args.size(), IndirectDests.
size(),
4037 return new (NumOperands, DescriptorBytes)
4039 NumOperands, NameStr, InsertBefore);
4047 int NumOperands = ComputeNumOperands(
Args.size(), IndirectDests.
size());
4048 return new (NumOperands)
4050 NumOperands, NameStr, InsertAtEnd);
4059 int NumOperands = ComputeNumOperands(
Args.size(), IndirectDests.
size(),
4063 return new (NumOperands, DescriptorBytes)
4065 NumOperands, NameStr, InsertAtEnd);
4072 return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
4073 IndirectDests,
Args, NameStr, InsertBefore);
4080 const Twine &NameStr =
"",
4082 return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
4083 IndirectDests,
Args, Bundles, NameStr, InsertBefore);
4090 return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
4091 IndirectDests,
Args, NameStr, InsertAtEnd);
4100 return Create(Func.getFunctionType(), Func.getCallee(), DefaultDest,
4101 IndirectDests,
Args, Bundles, NameStr, InsertAtEnd);
4141 return IndirectDests;
4147 updateArgBlockAddresses(
i,
B);
4153 "Successor # out of range for callbr!");
4159 "Successor # out of range for callbr!");
4167 return (
I->getOpcode() == Instruction::CallBr);
4170 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
4176 template <
typename Bitfield>
4178 Instruction::setSubclassData<Bitfield>(
Value);
4183 ArrayRef<BasicBlock *> IndirectDests,
4184 ArrayRef<Value *>
Args,
4185 ArrayRef<OperandBundleDef> Bundles,
int NumOperands,
4186 const Twine &NameStr, Instruction *InsertBefore)
4187 : CallBase(Ty->getReturnType(), Instruction::CallBr,
4188 OperandTraits<CallBase>::op_end(
this) - NumOperands, NumOperands,
4190 init(Ty, Func, DefaultDest, IndirectDests,
Args, Bundles, NameStr);
4194 ArrayRef<BasicBlock *> IndirectDests,
4195 ArrayRef<Value *>
Args,
4196 ArrayRef<OperandBundleDef> Bundles,
int NumOperands,
4197 const Twine &NameStr,
BasicBlock *InsertAtEnd)
4198 : CallBase(Ty->getReturnType(), Instruction::CallBr,
4199 OperandTraits<CallBase>::op_end(
this) - NumOperands, NumOperands,
4201 init(Ty, Func, DefaultDest, IndirectDests,
Args, Bundles, NameStr);
4242 return I->getOpcode() == Instruction::Resume;
4245 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
4249 BasicBlock *getSuccessor(
unsigned idx)
const {
4253 void setSuccessor(
unsigned idx,
BasicBlock *NewSucc) {
4273 unsigned ReservedSpace;
4285 unsigned NumHandlers,
const Twine &NameStr,
4293 unsigned NumHandlers,
const Twine &NameStr,
4297 void *
operator new(
size_t S) {
return User::operator
new(
S); }
4300 void growOperands(
unsigned Size);
4309 void operator delete(
void *Ptr) {
return User::operator
delete(Ptr); }
4312 unsigned NumHandlers,
4313 const Twine &NameStr =
"",
4315 return new CatchSwitchInst(ParentPad, UnwindDest, NumHandlers, NameStr,
4320 unsigned NumHandlers,
const Twine &NameStr,
4322 return new CatchSwitchInst(ParentPad, UnwindDest, NumHandlers, NameStr,
4337 if (hasUnwindDest())
4338 return cast<BasicBlock>(getOperand(1));
4344 setOperand(1, UnwindDest);
4350 if (hasUnwindDest())
4351 return getNumOperands() - 2;
4352 return getNumOperands() - 1;
4356 static BasicBlock *handler_helper(
Value *V) {
return cast<BasicBlock>(V); }
4358 return cast<BasicBlock>(V);
4373 if (hasUnwindDest())
4382 if (hasUnwindDest())
4401 return make_range(handler_begin(), handler_end());
4406 return make_range(handler_begin(), handler_end());
4415 void removeHandler(handler_iterator
HI);
4419 assert(Idx < getNumSuccessors() &&
4420 "Successor # out of range for catchswitch!");
4421 return cast<BasicBlock>(getOperand(Idx + 1));
4424 assert(Idx < getNumSuccessors() &&
4425 "Successor # out of range for catchswitch!");
4426 setOperand(Idx + 1, NewSucc);
4431 return I->getOpcode() == Instruction::CatchSwitch;
4434 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4449 unsigned Values,
const Twine &NameStr,
4452 NameStr, InsertBefore) {}
4454 unsigned Values,
const Twine &NameStr,
4457 NameStr, InsertAtEnd) {}
4461 const Twine &NameStr =
"",
4463 unsigned Values = 1 +
Args.size();
4470 unsigned Values = 1 +
Args.size();
4477 return I->getOpcode() == Instruction::CleanupPad;
4480 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4490 unsigned Values,
const Twine &NameStr,
4493 NameStr, InsertBefore) {}
4495 unsigned Values,
const Twine &NameStr,
4498 NameStr, InsertAtEnd) {}
4502 const Twine &NameStr =
"",
4504 unsigned Values = 1 +
Args.size();
4511 unsigned Values = 1 +
Args.size();
4518 return cast<CatchSwitchInst>(Op<-1>());
4522 Op<-1>() = CatchSwitch;
4527 return I->getOpcode() == Instruction::CatchPad;
4530 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));
4591 return (
I->getOpcode() == Instruction::CatchRet);
4594 return isa<Instruction>(V) &&
classof(cast<Instruction>(V));