56 "disable-i2p-p2i-opt",
cl::init(
false),
57 cl::desc(
"Disables inttoptr/ptrtoint roundtrip optimization"));
63std::optional<TypeSize>
70 assert(!
Size.isScalable() &&
"Array elements cannot have a scalable size");
80std::optional<TypeSize>
100 return "both values to select must have same type";
103 return "select values cannot have token type";
108 return "vector select condition element type must be i1";
111 return "selected values for vector select must be vectors";
113 return "vector select requires selected vectors to have "
114 "the same vector length as select condition";
116 return "select condition must be i1 or <n x i1>";
125PHINode::PHINode(
const PHINode &PN)
127 ReservedSpace(PN.getNumOperands()) {
149 Op<-1>().set(
nullptr);
162 bool DeletePHIIfEmpty) {
168 if (RemoveIndices.
empty())
173 return RemoveIndices.
contains(U.getOperandNo());
198void PHINode::growOperands() {
200 unsigned NumOps = e + e / 2;
201 if (NumOps < 2) NumOps = 2;
203 ReservedSpace = NumOps;
214 if (ConstantValue !=
this)
219 if (ConstantValue ==
this)
221 return ConstantValue;
230 Value *ConstantValue =
nullptr;
234 if (ConstantValue && ConstantValue !=
Incoming)
246LandingPadInst::LandingPadInst(
Type *
RetTy,
unsigned NumReservedValues,
247 const Twine &NameStr,
250 init(NumReservedValues, NameStr);
255 ReservedSpace(LP.getNumOperands()) {
260 for (
unsigned I = 0, E = ReservedSpace;
I != E; ++
I)
267 const Twine &NameStr,
272void LandingPadInst::init(
unsigned NumReservedValues,
const Twine &NameStr) {
273 ReservedSpace = NumReservedValues;
282void LandingPadInst::growOperands(
unsigned Size) {
284 if (ReservedSpace >= e +
Size)
return;
285 ReservedSpace = (std::max(e, 1U) +
Size / 2) * 2;
292 assert(OpNo < ReservedSpace &&
"Growing didn't work!");
304 case Instruction::Call:
306 case Instruction::Invoke:
308 case Instruction::CallBr:
320 if (ChildOB.getTagName() != OpB.
getTag())
331 return cast<CallBrInst>(
this)->getNumIndirectDests() + 1;
336 if (isa<Function>(V) || isa<Constant>(V))
344 if (
auto *CI = dyn_cast<CallInst>(
this))
345 return CI->isMustTailCall();
351 if (
auto *CI = dyn_cast<CallInst>(
this))
352 return CI->isTailCall();
358 return F->getIntrinsicID();
366 Mask |=
F->getAttributes().getRetNoFPClass();
374 Mask |=
F->getAttributes().getParamNoFPClass(i);
402 if (
F->getAttributes().hasAttrSomewhere(Kind, &Index))
419 if (!
F->getAttributes().hasParamAttr(ArgNo, Kind))
424 case Attribute::ReadNone:
426 case Attribute::ReadOnly:
428 case Attribute::WriteOnly:
437 return F->getAttributes().hasFnAttr(Kind);
442bool CallBase::hasFnAttrOnCalledFunction(
StringRef Kind)
const {
444 return F->getAttributes().hasFnAttr(Kind);
449template <
typename AK>
450Attribute CallBase::getFnAttrOnCalledFunction(AK Kind)
const {
451 if constexpr (std::is_same_v<AK, Attribute::AttrKind>) {
454 assert(Kind != Attribute::Memory &&
"Use getMemoryEffects() instead");
458 return F->getAttributes().getFnAttr(Kind);
467template <
typename AK>
468Attribute CallBase::getParamAttrOnCalledFunction(
unsigned ArgNo,
472 if (
auto *
F = dyn_cast<Function>(V))
473 return F->getAttributes().getParamAttr(ArgNo, Kind);
478CallBase::getParamAttrOnCalledFunction(
unsigned ArgNo,
480template Attribute CallBase::getParamAttrOnCalledFunction(
unsigned ArgNo,
491 const unsigned BeginIndex) {
493 for (
auto &
B : Bundles)
494 It = std::copy(
B.input_begin(),
B.input_end(), It);
497 auto BI = Bundles.
begin();
498 unsigned CurrentIndex = BeginIndex;
501 assert(BI != Bundles.
end() &&
"Incorrect allocation?");
503 BOI.Tag = ContextImpl->getOrInsertBundleTag(BI->getTag());
504 BOI.Begin = CurrentIndex;
505 BOI.End = CurrentIndex + BI->input_size();
506 CurrentIndex = BOI.End;
510 assert(BI == Bundles.
end() &&
"Incorrect allocation?");
521 if (BOI.Begin <= OpIdx && OpIdx < BOI.End)
527 assert(OpIdx >=
arg_size() &&
"the Idx is not in the operand bundles");
530 "The Idx isn't in the operand bundle");
534 constexpr unsigned NumberScaling = 1024;
540 while (Begin !=
End) {
541 unsigned ScaledOperandPerBundle =
542 NumberScaling * (std::prev(
End)->End - Begin->
Begin) / (
End - Begin);
543 Current = Begin + (((OpIdx - Begin->
Begin) * NumberScaling) /
544 ScaledOperandPerBundle);
546 Current = std::prev(
End);
547 assert(Current < End && Current >= Begin &&
548 "the operand bundle doesn't cover every value in the range");
549 if (OpIdx >= Current->
Begin && OpIdx < Current->
End)
551 if (OpIdx >= Current->
End)
558 "the operand bundle doesn't cover every value in the range");
571 return Create(CB, Bundles, InsertPt);
577 bool CreateNew =
false;
581 if (Bundle.getTagID() ==
ID) {
588 return CreateNew ?
Create(CB, Bundles, InsertPt) : CB;
686 "NumOperands not set up?");
691 "Calling a function with bad signature!");
693 for (
unsigned i = 0; i != Args.size(); ++i)
696 "Calling a function with a bad signature!");
731 "Wrong number of operands allocated");
746 Args, OpB, CI->
getName(), InsertPt);
760 LLVM_DEBUG(
dbgs() <<
"Attempting to update profile weights will result in "
761 "div by 0. Ignoring. Likely the function "
763 <<
" has 0 entry count, and contains call instructions "
764 "with non-zero prof info.");
777 const Twine &NameStr) {
782 "NumOperands not set up?");
787 "Invoking a function with bad signature");
789 for (
unsigned i = 0, e = Args.size(); i != e; i++)
792 "Invoking a function with a bad signature!");
812 "Wrong number of operands allocated");
815 std::copy(
II.bundle_op_info_begin(),
II.bundle_op_info_end(),
822 std::vector<Value *> Args(
II->arg_begin(),
II->arg_end());
825 II->getFunctionType(),
II->getCalledOperand(),
II->getNormalDest(),
826 II->getUnwindDest(), Args, OpB,
II->getName(), InsertPt);
827 NewII->setCallingConv(
II->getCallingConv());
828 NewII->SubclassOptionalData =
II->SubclassOptionalData;
829 NewII->setAttributes(
II->getAttributes());
830 NewII->setDebugLoc(
II->getDebugLoc());
835 return cast<LandingPadInst>(
getUnwindDest()->getFirstNonPHI());
840 LLVM_DEBUG(
dbgs() <<
"Attempting to update profile weights will result in "
841 "div by 0. Ignoring. Likely the function "
843 <<
" has 0 entry count, and contains call instructions "
844 "with non-zero prof info.");
858 const Twine &NameStr) {
862 IndirectDests.
size(),
864 "NumOperands not set up?");
869 "Calling a function with bad signature");
871 for (
unsigned i = 0, e = Args.size(); i != e; i++)
874 "Calling a function with a bad signature!");
879 std::copy(Args.begin(), Args.end(),
op_begin());
880 NumIndirectDests = IndirectDests.
size();
882 for (
unsigned i = 0; i != NumIndirectDests; ++i)
897 "Wrong number of operands allocated");
903 NumIndirectDests = CBI.NumIndirectDests;
917 NewCBI->NumIndirectDests = CBI->NumIndirectDests;
929 "Wrong number of operands allocated");
955 AllocMarker, InsertBefore) {
967 "Wrong number of operands allocated");
968 setSubclassData<Instruction::OpaqueField>(
977 setSubclassData<UnwindDestField>(
true);
979 Op<0>() = CleanupPad;
984CleanupReturnInst::CleanupReturnInst(
Value *CleanupPad,
BasicBlock *UnwindBB,
989 init(CleanupPad, UnwindBB);
1010 AllocMarker, InsertBefore) {
1018CatchSwitchInst::CatchSwitchInst(
Value *ParentPad,
BasicBlock *UnwindDest,
1019 unsigned NumReservedValues,
1020 const Twine &NameStr,
1025 ++NumReservedValues;
1026 init(ParentPad, UnwindDest, NumReservedValues + 1);
1037 for (
unsigned I = 1, E = ReservedSpace;
I != E; ++
I)
1042 unsigned NumReservedValues) {
1043 assert(ParentPad && NumReservedValues);
1045 ReservedSpace = NumReservedValues;
1049 Op<0>() = ParentPad;
1051 setSubclassData<UnwindDestField>(
true);
1058void CatchSwitchInst::growOperands(
unsigned Size) {
1060 assert(NumOperands >= 1);
1061 if (ReservedSpace >= NumOperands +
Size)
1063 ReservedSpace = (NumOperands +
Size / 2) * 2;
1070 assert(OpNo < ReservedSpace &&
"Growing didn't work!");
1078 for (
Use *CurDst = HI.getCurrent(); CurDst != EndDst; ++CurDst)
1079 *CurDst = *(CurDst + 1);
1090 const Twine &NameStr) {
1100 "Wrong number of operands allocated");
1107 const Twine &NameStr,
1110 init(ParentPad, Args, NameStr);
1120 AllocMarker, InsertBefore) {}
1126void BranchInst::AssertOK() {
1129 "May only branch on boolean predicates!");
1136 assert(IfTrue &&
"Branch destination may not be null!");
1157 "Wrong number of operands allocated");
1161 Op<-3>() = BI.
Op<-3>();
1162 Op<-2>() = BI.
Op<-2>();
1164 Op<-1>() = BI.
Op<-1>();
1170 "Cannot swap successors of an unconditional branch");
1186 assert(!isa<BasicBlock>(Amt) &&
1187 "Passed basic block into allocation size parameter! Use other ctor");
1189 "Allocation array size is not an integer!");
1196 "Insertion position cannot be null when alignment not provided!");
1199 "BB must be in a Function when alignment not provided!");
1201 return DL.getPrefTypeAlign(Ty);
1218 getAISize(Ty->getContext(), ArraySize), InsertBefore),
1227 return !CI->isOne();
1247void LoadInst::AssertOK() {
1249 "Ptr must have pointer type.");
1254 "Insertion position cannot be null when alignment not provided!");
1257 "BB must be in a Function when alignment not provided!");
1259 return DL.getABITypeAlign(Ty);
1274 SyncScope::System, InsertBef) {}
1291void StoreInst::AssertOK() {
1294 "Ptr must have pointer type!");
1309 SyncScope::System, InsertBefore) {}
1341 "All operands must be non-null!");
1343 "Ptr must have pointer type!");
1345 "Cmp type and NewVal type must be same!");
1356 AtomicCmpXchg, AllocMarker, InsertBefore) {
1357 Init(
Ptr, Cmp, NewVal, Alignment, SuccessOrdering, FailureOrdering, SSID);
1368 "atomicrmw instructions can only be atomic.");
1370 "atomicrmw instructions cannot be unordered.");
1380 "Ptr must have pointer type!");
1382 "AtomicRMW instructions must be atomic!");
1433 return "<invalid operation>";
1457 "NumOperands not initialized?");
1466 SourceElementType(GEPI.SourceElementType),
1467 ResultElementType(GEPI.ResultElementType) {
1469 "Wrong number of operands allocated");
1475 if (
auto *
Struct = dyn_cast<StructType>(Ty)) {
1480 if (!
Idx->getType()->isIntOrIntVectorTy())
1482 if (
auto *Array = dyn_cast<ArrayType>(Ty))
1483 return Array->getElementType();
1484 if (
auto *
Vector = dyn_cast<VectorType>(Ty))
1485 return Vector->getElementType();
1490 if (
auto *
Struct = dyn_cast<StructType>(Ty)) {
1495 if (
auto *Array = dyn_cast<ArrayType>(Ty))
1496 return Array->getElementType();
1497 if (
auto *
Vector = dyn_cast<VectorType>(Ty))
1498 return Vector->getElementType();
1502template <
typename IndexTy>
1504 if (IdxList.
empty())
1506 for (IndexTy V : IdxList.
slice(1)) {
1533 if (!CI->isZero())
return false;
1566 return cast<GEPOperator>(
this)->getNoWrapFlags();
1570 return cast<GEPOperator>(
this)->isInBounds();
1574 return cast<GEPOperator>(
this)->hasNoUnsignedSignedWrap();
1578 return cast<GEPOperator>(
this)->hasNoUnsignedWrap();
1584 return cast<GEPOperator>(
this)->accumulateConstantOffset(
DL,
Offset);
1590 APInt &ConstantOffset)
const {
1592 return cast<GEPOperator>(
this)->collectOffset(
DL,
BitWidth, VariableOffsets,
1600ExtractElementInst::ExtractElementInst(
Value *Val,
Value *Index,
1604 ExtractElement, AllocMarker, InsertBef) {
1605 assert(isValidOperands(Val, Index) &&
1606 "Invalid extractelement instruction operands!");
1622InsertElementInst::InsertElementInst(
Value *Vec,
Value *Elt,
Value *Index,
1627 "Invalid insertelement instruction operands!");
1635 const Value *Index) {
1639 if (Elt->
getType() != cast<VectorType>(Vec->
getType())->getElementType())
1642 if (!Index->getType()->isIntegerTy())
1652 assert(V &&
"Cannot create placeholder of nullptr V");
1673 ShuffleVector, AllocMarker, InsertBefore) {
1675 "Invalid shuffle vector instruction operands!");
1691 ShuffleVector, AllocMarker, InsertBefore) {
1693 "Invalid shuffle vector instruction operands!");
1701 int NumOpElts = cast<FixedVectorType>(
Op<0>()->
getType())->getNumElements();
1702 int NumMaskElts = ShuffleMask.
size();
1704 for (
int i = 0; i != NumMaskElts; ++i) {
1710 assert(MaskElt >= 0 && MaskElt < 2 * NumOpElts &&
"Out-of-range mask");
1711 MaskElt = (MaskElt < NumOpElts) ? MaskElt + NumOpElts : MaskElt - NumOpElts;
1712 NewMask[i] = MaskElt;
1721 if (!isa<VectorType>(V1->
getType()) || V1->
getType() != V2->getType())
1726 cast<VectorType>(V1->
getType())->getElementCount().getKnownMinValue();
1727 for (
int Elem : Mask)
1731 if (isa<ScalableVectorType>(V1->
getType()))
1739 const Value *Mask) {
1746 auto *MaskTy = dyn_cast<VectorType>(Mask->getType());
1747 if (!MaskTy || !MaskTy->getElementType()->isIntegerTy(32) ||
1748 isa<ScalableVectorType>(MaskTy) != isa<ScalableVectorType>(V1->
getType()))
1752 if (isa<UndefValue>(Mask) || isa<ConstantAggregateZero>(Mask))
1757 if (isa<ScalableVectorType>(MaskTy))
1760 unsigned V1Size = cast<FixedVectorType>(V1->
getType())->getNumElements();
1762 if (
const auto *CI = dyn_cast<ConstantInt>(Mask))
1763 return !CI->uge(V1Size * 2);
1765 if (
const auto *MV = dyn_cast<ConstantVector>(Mask)) {
1766 for (
Value *
Op : MV->operands()) {
1767 if (
auto *CI = dyn_cast<ConstantInt>(
Op)) {
1768 if (CI->uge(V1Size*2))
1770 }
else if (!isa<UndefValue>(
Op)) {
1777 if (
const auto *CDS = dyn_cast<ConstantDataSequential>(Mask)) {
1778 for (
unsigned i = 0, e = cast<FixedVectorType>(MaskTy)->
getNumElements();
1780 if (CDS->getElementAsInteger(i) >= V1Size*2)
1790 ElementCount EC = cast<VectorType>(Mask->getType())->getElementCount();
1792 if (isa<ConstantAggregateZero>(Mask)) {
1793 Result.resize(EC.getKnownMinValue(), 0);
1797 Result.reserve(EC.getKnownMinValue());
1799 if (EC.isScalable()) {
1800 assert((isa<ConstantAggregateZero>(Mask) || isa<UndefValue>(Mask)) &&
1801 "Scalable vector shuffle mask must be undef or zeroinitializer");
1802 int MaskVal = isa<UndefValue>(Mask) ? -1 : 0;
1803 for (
unsigned I = 0;
I < EC.getKnownMinValue(); ++
I)
1804 Result.emplace_back(MaskVal);
1808 unsigned NumElts = EC.getKnownMinValue();
1810 if (
auto *CDS = dyn_cast<ConstantDataSequential>(Mask)) {
1811 for (
unsigned i = 0; i != NumElts; ++i)
1812 Result.push_back(CDS->getElementAsInteger(i));
1815 for (
unsigned i = 0; i != NumElts; ++i) {
1816 Constant *
C = Mask->getAggregateElement(i);
1817 Result.push_back(isa<UndefValue>(
C) ? -1 :
1818 cast<ConstantInt>(
C)->getZExtValue());
1823 ShuffleMask.
assign(Mask.begin(), Mask.end());
1830 if (isa<ScalableVectorType>(ResultTy)) {
1838 for (
int Elem : Mask) {
1842 MaskConst.
push_back(ConstantInt::get(Int32Ty, Elem));
1848 assert(!Mask.empty() &&
"Shuffle mask must contain elements");
1849 bool UsesLHS =
false;
1850 bool UsesRHS =
false;
1851 for (
int I : Mask) {
1854 assert(
I >= 0 &&
I < (NumOpElts * 2) &&
1855 "Out-of-bounds shuffle mask element");
1856 UsesLHS |= (
I < NumOpElts);
1857 UsesRHS |= (
I >= NumOpElts);
1858 if (UsesLHS && UsesRHS)
1862 return UsesLHS || UsesRHS;
1874 for (
int i = 0, NumMaskElts = Mask.size(); i < NumMaskElts; ++i) {
1877 if (Mask[i] != i && Mask[i] != (NumOpElts + i))
1884 if (Mask.size() !=
static_cast<unsigned>(NumSrcElts))
1892 if (Mask.size() !=
static_cast<unsigned>(NumSrcElts))
1901 for (
int I = 0, E = Mask.size();
I < E; ++
I) {
1904 if (Mask[
I] != (NumSrcElts - 1 -
I) &&
1905 Mask[
I] != (NumSrcElts + NumSrcElts - 1 -
I))
1912 if (Mask.size() !=
static_cast<unsigned>(NumSrcElts))
1916 for (
int I = 0, E = Mask.size();
I < E; ++
I) {
1919 if (Mask[
I] != 0 && Mask[
I] != NumSrcElts)
1926 if (Mask.size() !=
static_cast<unsigned>(NumSrcElts))
1931 for (
int I = 0, E = Mask.size();
I < E; ++
I) {
1934 if (Mask[
I] !=
I && Mask[
I] != (NumSrcElts +
I))
1947 if (Mask.size() !=
static_cast<unsigned>(NumSrcElts))
1950 int Sz = Mask.size();
1955 if (Mask[0] != 0 && Mask[0] != 1)
1960 if ((Mask[1] - Mask[0]) != NumSrcElts)
1965 for (
int I = 2;
I < Sz; ++
I) {
1966 int MaskEltVal = Mask[
I];
1967 if (MaskEltVal == -1)
1969 int MaskEltPrevVal = Mask[
I - 2];
1970 if (MaskEltVal - MaskEltPrevVal != 2)
1978 if (Mask.size() !=
static_cast<unsigned>(NumSrcElts))
1981 int StartIndex = -1;
1982 for (
int I = 0, E = Mask.size();
I != E; ++
I) {
1983 int MaskEltVal = Mask[
I];
1984 if (MaskEltVal == -1)
1987 if (StartIndex == -1) {
1990 if (MaskEltVal <
I || NumSrcElts <= (MaskEltVal -
I))
1993 StartIndex = MaskEltVal -
I;
1998 if (MaskEltVal != (StartIndex +
I))
2002 if (StartIndex == -1)
2011 int NumSrcElts,
int &Index) {
2017 if (NumSrcElts <= (
int)Mask.size())
2022 for (
int i = 0, e = Mask.size(); i != e; ++i) {
2026 int Offset = (M % NumSrcElts) - i;
2027 if (0 <= SubIndex && SubIndex !=
Offset)
2032 if (0 <= SubIndex && SubIndex + (
int)Mask.size() <= NumSrcElts) {
2040 int NumSrcElts,
int &NumSubElts,
2042 int NumMaskElts = Mask.size();
2045 if (NumMaskElts < NumSrcElts)
2056 bool Src0Identity =
true;
2057 bool Src1Identity =
true;
2059 for (
int i = 0; i != NumMaskElts; ++i) {
2065 if (M < NumSrcElts) {
2067 Src0Identity &= (M == i);
2071 Src1Identity &= (M == (i + NumSrcElts));
2073 assert((Src0Elts | Src1Elts | UndefElts).isAllOnes() &&
2074 "unknown shuffle elements");
2076 "2-source shuffle not found");
2082 int Src0Hi = NumMaskElts - Src0Elts.
countl_zero();
2083 int Src1Hi = NumMaskElts - Src1Elts.
countl_zero();
2088 int NumSub1Elts = Src1Hi - Src1Lo;
2091 NumSubElts = NumSub1Elts;
2100 int NumSub0Elts = Src0Hi - Src0Lo;
2103 NumSubElts = NumSub0Elts;
2115 if (isa<ScalableVectorType>(
getType()))
2118 int NumOpElts = cast<FixedVectorType>(
Op<0>()->
getType())->getNumElements();
2119 int NumMaskElts = cast<FixedVectorType>(
getType())->getNumElements();
2120 if (NumMaskElts <= NumOpElts)
2129 for (
int i = NumOpElts; i < NumMaskElts; ++i)
2139 if (isa<ScalableVectorType>(
getType()))
2142 int NumOpElts = cast<FixedVectorType>(
Op<0>()->
getType())->getNumElements();
2143 int NumMaskElts = cast<FixedVectorType>(
getType())->getNumElements();
2144 if (NumMaskElts >= NumOpElts)
2152 if (isa<UndefValue>(
Op<0>()) || isa<UndefValue>(
Op<1>()))
2157 if (isa<ScalableVectorType>(
getType()))
2160 int NumOpElts = cast<FixedVectorType>(
Op<0>()->
getType())->getNumElements();
2161 int NumMaskElts = cast<FixedVectorType>(
getType())->getNumElements();
2162 if (NumMaskElts != NumOpElts * 2)
2173 int ReplicationFactor,
int VF) {
2174 assert(Mask.size() == (
unsigned)ReplicationFactor * VF &&
2175 "Unexpected mask size.");
2177 for (
int CurrElt :
seq(VF)) {
2178 ArrayRef<int> CurrSubMask = Mask.take_front(ReplicationFactor);
2179 assert(CurrSubMask.
size() == (
unsigned)ReplicationFactor &&
2180 "Run out of mask?");
2181 Mask = Mask.drop_front(ReplicationFactor);
2182 if (!
all_of(CurrSubMask, [CurrElt](
int MaskElt) {
2187 assert(Mask.empty() &&
"Did not consume the whole mask?");
2193 int &ReplicationFactor,
int &VF) {
2197 Mask.take_while([](
int MaskElt) {
return MaskElt == 0; }).
size();
2198 if (ReplicationFactor == 0 || Mask.size() % ReplicationFactor != 0)
2200 VF = Mask.size() / ReplicationFactor;
2212 for (
int MaskElt : Mask) {
2216 if (MaskElt < Largest)
2218 Largest = std::max(Largest, MaskElt);
2222 for (
int PossibleReplicationFactor :
2223 reverse(seq_inclusive<unsigned>(1, Mask.size()))) {
2224 if (Mask.size() % PossibleReplicationFactor != 0)
2226 int PossibleVF = Mask.size() / PossibleReplicationFactor;
2230 ReplicationFactor = PossibleReplicationFactor;
2242 if (isa<ScalableVectorType>(
getType()))
2245 VF = cast<FixedVectorType>(
Op<0>()->
getType())->getNumElements();
2246 if (ShuffleMask.
size() % VF != 0)
2248 ReplicationFactor = ShuffleMask.
size() / VF;
2254 if (VF <= 0 || Mask.size() <
static_cast<unsigned>(VF) ||
2255 Mask.size() % VF != 0)
2257 for (
unsigned K = 0, Sz = Mask.size(); K < Sz; K += VF) {
2262 for (
int Idx : SubMask) {
2276 if (isa<ScalableVectorType>(
getType()))
2298 unsigned NumElts = Mask.size();
2299 if (NumElts % Factor)
2302 unsigned LaneLen = NumElts / Factor;
2306 StartIndexes.
resize(Factor);
2312 for (;
I < Factor;
I++) {
2313 unsigned SavedLaneValue;
2314 unsigned SavedNoUndefs = 0;
2317 for (J = 0; J < LaneLen - 1; J++) {
2319 unsigned Lane = J * Factor +
I;
2320 unsigned NextLane = Lane + Factor;
2321 int LaneValue = Mask[Lane];
2322 int NextLaneValue = Mask[NextLane];
2325 if (LaneValue >= 0 && NextLaneValue >= 0 &&
2326 LaneValue + 1 != NextLaneValue)
2330 if (LaneValue >= 0 && NextLaneValue < 0) {
2331 SavedLaneValue = LaneValue;
2340 if (SavedNoUndefs > 0 && LaneValue < 0) {
2342 if (NextLaneValue >= 0 &&
2343 SavedLaneValue + SavedNoUndefs != (
unsigned)NextLaneValue)
2348 if (J < LaneLen - 1)
2354 StartMask = Mask[
I];
2355 }
else if (Mask[(LaneLen - 1) * Factor +
I] >= 0) {
2357 StartMask = Mask[(LaneLen - 1) * Factor +
I] - J;
2358 }
else if (SavedNoUndefs > 0) {
2360 StartMask = SavedLaneValue - (LaneLen - 1 - SavedNoUndefs);
2367 if (StartMask + LaneLen > NumInputElts)
2370 StartIndexes[
I] = StartMask;
2383 for (
unsigned Idx = 0;
Idx < Factor;
Idx++) {
2388 for (;
I < Mask.size();
I++)
2389 if (Mask[
I] >= 0 &&
static_cast<unsigned>(Mask[
I]) !=
Idx +
I * Factor)
2392 if (
I == Mask.size()) {
2406 int NumElts = Mask.size();
2407 assert((NumElts % NumSubElts) == 0 &&
"Illegal shuffle mask");
2410 for (
int i = 0; i != NumElts; i += NumSubElts) {
2411 for (
int j = 0; j != NumSubElts; ++j) {
2412 int M = Mask[i + j];
2415 if (M < i || M >= i + NumSubElts)
2417 int Offset = (NumSubElts - (M - (i + j))) % NumSubElts;
2418 if (0 <= RotateAmt &&
Offset != RotateAmt)
2427 ArrayRef<int> Mask,
unsigned EltSizeInBits,
unsigned MinSubElts,
2428 unsigned MaxSubElts,
unsigned &NumSubElts,
unsigned &RotateAmt) {
2429 for (NumSubElts = MinSubElts; NumSubElts <= MaxSubElts; NumSubElts *= 2) {
2431 if (EltRotateAmt < 0)
2433 RotateAmt = EltRotateAmt * EltSizeInBits;
2452 assert(!Idxs.
empty() &&
"InsertValueInst must have at least one index");
2455 Val->
getType() &&
"Inserted value must match indexed type!");
2465 Indices(IVI.Indices) {
2480 assert(!Idxs.
empty() &&
"ExtractValueInst must have at least one index");
2489 Indices(EVI.Indices) {
2501 for (
unsigned Index : Idxs) {
2508 if (
ArrayType *AT = dyn_cast<ArrayType>(Agg)) {
2509 if (Index >= AT->getNumElements())
2511 Agg = AT->getElementType();
2512 }
else if (
StructType *ST = dyn_cast<StructType>(Agg)) {
2513 if (Index >= ST->getNumElements())
2515 Agg = ST->getElementType(Index);
2521 return const_cast<Type*
>(Agg);
2541void UnaryOperator::AssertOK() {
2548 "Unary operation should return same type as operand!");
2550 "Tried to create a floating-point operation on a "
2551 "non-floating-point type!");
2564 :
Instruction(Ty, iType, AllocMarker, InsertBefore) {
2571void BinaryOperator::AssertOK() {
2573 (void)LHS; (void)RHS;
2575 "Binary operator operand types must match!");
2581 "Arithmetic operation should return same type as operands!");
2583 "Tried to create an integer operation on a non-integer type!");
2585 case FAdd:
case FSub:
2588 "Arithmetic operation should return same type as operands!");
2590 "Tried to create a floating-point operation on a "
2591 "non-floating-point type!");
2596 "Arithmetic operation should return same type as operands!");
2598 "Incorrect operand type (not integer) for S/UDIV");
2602 "Arithmetic operation should return same type as operands!");
2604 "Incorrect operand type (not floating point) for FDIV");
2609 "Arithmetic operation should return same type as operands!");
2611 "Incorrect operand type (not integer) for S/UREM");
2615 "Arithmetic operation should return same type as operands!");
2617 "Incorrect operand type (not floating point) for FREM");
2623 "Shift operation should return same type as operands!");
2625 "Tried to create a shift operation on a non-integral type!");
2630 "Logical operation should return same type as operands!");
2632 "Tried to create a logical operation on a non-integral type!");
2643 "Cannot create binary operator with two operands of differing type!");
2649 Value *Zero = ConstantInt::get(
Op->getType(), 0);
2656 Value *Zero = ConstantInt::get(
Op->getType(), 0);
2657 return BinaryOperator::CreateNSWSub(Zero,
Op,
Name, InsertBefore);
2664 Op->getType(),
Name, InsertBefore);
2684 cast<Instruction>(
this)->getMetadata(LLVMContext::MD_fpmath);
2698 default:
return false;
2699 case Instruction::ZExt:
2700 case Instruction::SExt:
2701 case Instruction::Trunc:
2703 case Instruction::BitCast:
2724 case Instruction::Trunc:
2725 case Instruction::ZExt:
2726 case Instruction::SExt:
2727 case Instruction::FPTrunc:
2728 case Instruction::FPExt:
2729 case Instruction::UIToFP:
2730 case Instruction::SIToFP:
2731 case Instruction::FPToUI:
2732 case Instruction::FPToSI:
2733 case Instruction::AddrSpaceCast:
2736 case Instruction::BitCast:
2738 case Instruction::PtrToInt:
2739 return DL.getIntPtrType(SrcTy)->getScalarSizeInBits() ==
2741 case Instruction::IntToPtr:
2742 return DL.getIntPtrType(DestTy)->getScalarSizeInBits() ==
2762 Type *DstIntPtrTy) {
2793 const unsigned numCastOps =
2794 Instruction::CastOpsEnd - Instruction::CastOpsBegin;
2795 static const uint8_t CastResults[numCastOps][numCastOps] = {
2801 { 1, 0, 0,99,99, 0, 0,99,99,99, 0, 3, 0},
2802 { 8, 1, 9,99,99, 2,17,99,99,99, 2, 3, 0},
2803 { 8, 0, 1,99,99, 0, 2,99,99,99, 0, 3, 0},
2804 { 0, 0, 0,99,99, 0, 0,99,99,99, 0, 3, 0},
2805 { 0, 0, 0,99,99, 0, 0,99,99,99, 0, 3, 0},
2806 { 99,99,99, 0, 0,99,99, 0, 0,99,99, 4, 0},
2807 { 99,99,99, 0, 0,99,99, 0, 0,99,99, 4, 0},
2808 { 99,99,99, 0, 0,99,99, 0, 0,99,99, 4, 0},
2809 { 99,99,99, 2, 2,99,99, 8, 2,99,99, 4, 0},
2810 { 1, 0, 0,99,99, 0, 0,99,99,99, 7, 3, 0},
2811 { 99,99,99,99,99,99,99,99,99,11,99,15, 0},
2812 { 5, 5, 5, 0, 0, 5, 5, 0, 0,16, 5, 1,14},
2813 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,13,12},
2820 bool IsFirstBitcast = (firstOp == Instruction::BitCast);
2821 bool IsSecondBitcast = (secondOp == Instruction::BitCast);
2822 bool AreBothBitcasts = IsFirstBitcast && IsSecondBitcast;
2825 if ((IsFirstBitcast && isa<VectorType>(SrcTy) != isa<VectorType>(MidTy)) ||
2826 (IsSecondBitcast && isa<VectorType>(MidTy) != isa<VectorType>(DstTy)))
2827 if (!AreBothBitcasts)
2830 int ElimCase = CastResults[firstOp-Instruction::CastOpsBegin]
2831 [secondOp-Instruction::CastOpsBegin];
2876 return Instruction::BitCast;
2879 if (!SrcIntPtrTy || DstIntPtrTy != SrcIntPtrTy)
2882 if (MidSize >= PtrSize)
2883 return Instruction::BitCast;
2893 return Instruction::BitCast;
2894 if (SrcSize < DstSize)
2896 if (SrcSize > DstSize)
2902 return Instruction::ZExt;
2910 if (SrcSize <= PtrSize && SrcSize == DstSize)
2911 return Instruction::BitCast;
2918 return Instruction::AddrSpaceCast;
2919 return Instruction::BitCast;
2930 "Illegal addrspacecast, bitcast sequence!");
2935 return Instruction::AddrSpaceCast;
2945 "Illegal inttoptr, bitcast sequence!");
2957 "Illegal bitcast, ptrtoint sequence!");
2962 return Instruction::UIToFP;
2977 case Trunc:
return new TruncInst (S, Ty,
Name, InsertBefore);
2978 case ZExt:
return new ZExtInst (S, Ty,
Name, InsertBefore);
2979 case SExt:
return new SExtInst (S, Ty,
Name, InsertBefore);
2981 case FPExt:
return new FPExtInst (S, Ty,
Name, InsertBefore);
3000 return Create(Instruction::BitCast, S, Ty,
Name, InsertBefore);
3001 return Create(Instruction::ZExt, S, Ty,
Name, InsertBefore);
3007 return Create(Instruction::BitCast, S, Ty,
Name, InsertBefore);
3008 return Create(Instruction::SExt, S, Ty,
Name, InsertBefore);
3014 return Create(Instruction::BitCast, S, Ty,
Name, InsertBefore);
3015 return Create(Instruction::Trunc, S, Ty,
Name, InsertBefore);
3026 cast<VectorType>(Ty)->getElementCount() ==
3027 cast<VectorType>(S->
getType())->getElementCount()) &&
3031 return Create(Instruction::PtrToInt, S, Ty,
Name, InsertBefore);
3042 return Create(Instruction::AddrSpaceCast, S, Ty,
Name, InsertBefore);
3044 return Create(Instruction::BitCast, S, Ty,
Name, InsertBefore);
3051 return Create(Instruction::PtrToInt, S, Ty,
Name, InsertBefore);
3053 return Create(Instruction::IntToPtr, S, Ty,
Name, InsertBefore);
3055 return Create(Instruction::BitCast, S, Ty,
Name, InsertBefore);
3062 "Invalid integer cast");
3063 unsigned SrcBits =
C->getType()->getScalarSizeInBits();
3066 (SrcBits == DstBits ? Instruction::BitCast :
3067 (SrcBits > DstBits ? Instruction::Trunc :
3068 (
isSigned ? Instruction::SExt : Instruction::ZExt)));
3076 unsigned SrcBits =
C->getType()->getScalarSizeInBits();
3078 assert((
C->getType() == Ty || SrcBits != DstBits) &&
"Invalid cast");
3080 (SrcBits == DstBits ? Instruction::BitCast :
3081 (SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt));
3089 if (SrcTy == DestTy)
3092 if (
VectorType *SrcVecTy = dyn_cast<VectorType>(SrcTy)) {
3093 if (
VectorType *DestVecTy = dyn_cast<VectorType>(DestTy)) {
3094 if (SrcVecTy->getElementCount() == DestVecTy->getElementCount()) {
3096 SrcTy = SrcVecTy->getElementType();
3097 DestTy = DestVecTy->getElementType();
3102 if (
PointerType *DestPtrTy = dyn_cast<PointerType>(DestTy)) {
3103 if (
PointerType *SrcPtrTy = dyn_cast<PointerType>(SrcTy)) {
3104 return SrcPtrTy->getAddressSpace() == DestPtrTy->getAddressSpace();
3116 if (SrcBits != DestBits)
3125 if (
auto *PtrTy = dyn_cast<PointerType>(SrcTy))
3126 if (
auto *IntTy = dyn_cast<IntegerType>(DestTy))
3127 return (IntTy->getBitWidth() ==
DL.getPointerTypeSizeInBits(PtrTy) &&
3128 !
DL.isNonIntegralPointerType(PtrTy));
3129 if (
auto *PtrTy = dyn_cast<PointerType>(DestTy))
3130 if (
auto *IntTy = dyn_cast<IntegerType>(SrcTy))
3131 return (IntTy->getBitWidth() ==
DL.getPointerTypeSizeInBits(PtrTy) &&
3132 !
DL.isNonIntegralPointerType(PtrTy));
3145 const Value *Src,
bool SrcIsSigned,
Type *DestTy,
bool DestIsSigned) {
3146 Type *SrcTy = Src->getType();
3149 "Only first class types are castable!");
3151 if (SrcTy == DestTy)
3155 if (
VectorType *SrcVecTy = dyn_cast<VectorType>(SrcTy))
3156 if (
VectorType *DestVecTy = dyn_cast<VectorType>(DestTy))
3157 if (SrcVecTy->getElementCount() == DestVecTy->getElementCount()) {
3160 SrcTy = SrcVecTy->getElementType();
3161 DestTy = DestVecTy->getElementType();
3171 if (DestBits < SrcBits)
3173 else if (DestBits > SrcBits) {
3187 assert(DestBits == SrcBits &&
3188 "Casting vector to integer of different width");
3192 "Casting from a value that is not first-class type");
3202 if (DestBits < SrcBits) {
3204 }
else if (DestBits > SrcBits) {
3210 assert(DestBits == SrcBits &&
3211 "Casting vector to floating point of different width");
3216 assert(DestBits == SrcBits &&
3217 "Illegal cast to vector (wrong type or size)");
3222 return AddrSpaceCast;
3248 bool SrcIsVec = isa<VectorType>(SrcTy);
3249 bool DstIsVec = isa<VectorType>(DstTy);
3256 ElementCount SrcEC = SrcIsVec ? cast<VectorType>(SrcTy)->getElementCount()
3258 ElementCount DstEC = DstIsVec ? cast<VectorType>(DstTy)->getElementCount()
3263 default:
return false;
3264 case Instruction::Trunc:
3266 SrcEC == DstEC && SrcScalarBitSize > DstScalarBitSize;
3267 case Instruction::ZExt:
3269 SrcEC == DstEC && SrcScalarBitSize < DstScalarBitSize;
3270 case Instruction::SExt:
3272 SrcEC == DstEC && SrcScalarBitSize < DstScalarBitSize;
3273 case Instruction::FPTrunc:
3275 SrcEC == DstEC && SrcScalarBitSize > DstScalarBitSize;
3276 case Instruction::FPExt:
3278 SrcEC == DstEC && SrcScalarBitSize < DstScalarBitSize;
3279 case Instruction::UIToFP:
3280 case Instruction::SIToFP:
3283 case Instruction::FPToUI:
3284 case Instruction::FPToSI:
3287 case Instruction::PtrToInt:
3291 case Instruction::IntToPtr:
3295 case Instruction::BitCast: {
3301 if (!SrcPtrTy != !DstPtrTy)
3314 if (SrcIsVec && DstIsVec)
3315 return SrcEC == DstEC;
3323 case Instruction::AddrSpaceCast: {
3335 return SrcEC == DstEC;
3436 if (
Op == Instruction::ICmp) {
3464 if (
ICmpInst *IC = dyn_cast<ICmpInst>(
this))
3467 cast<FCmpInst>(
this)->swapOperands();
3471 if (
const ICmpInst *IC = dyn_cast<ICmpInst>(
this))
3472 return IC->isCommutative();
3473 return cast<FCmpInst>(
this)->isCommutative();
3487 auto *
LHS = dyn_cast<Constant>(Cmp->getOperand(0));
3488 auto *
RHS = dyn_cast<Constant>(Cmp->getOperand(1));
3549 default:
return "unknown";
3730 switch (predicate) {
3731 default:
return false;
3738 switch (predicate) {
3739 default:
return false;
3856 switch (predicate) {
3857 default:
return false;
3865 switch (predicate) {
3866 default:
return false;
3875 default:
return false;
3885 default:
return false;
3924 if (
A.Pred ==
B.Pred)
3926 if (
A.HasSameSign &&
3929 if (
B.HasSameSign &&
3936 if (
auto *ICI = dyn_cast<ICmpInst>(Cmp))
3937 return ICI->getCmpPredicate();
3938 return Cmp->getPredicate();
3955 ReservedSpace = NumReserved;
3970 AllocMarker, InsertBefore) {
3976 init(
SI.getCondition(),
SI.getDefaultDest(),
SI.getNumOperands());
3977 setNumHungOffUseOperands(
SI.getNumOperands());
3978 Use *OL = getOperandList();
3979 const Use *InOL =
SI.getOperandList();
3980 for (
unsigned i = 2, E =
SI.getNumOperands(); i != E; i += 2) {
3982 OL[i+1] = InOL[i+1];
3984 SubclassOptionalData =
SI.SubclassOptionalData;
3992 if (OpNo+2 > ReservedSpace)
3995 assert(OpNo+1 < ReservedSpace &&
"Growing didn't work!");
4005 unsigned idx =
I->getCaseIndex();
4013 if (2 + (idx + 1) * 2 != NumOps) {
4014 OL[2 + idx * 2] = OL[NumOps - 2];
4015 OL[2 + idx * 2 + 1] = OL[NumOps - 1];
4019 OL[NumOps-2].
set(
nullptr);
4020 OL[NumOps-2+1].
set(
nullptr);
4023 return CaseIt(
this, idx);
4029void SwitchInst::growOperands() {
4031 unsigned NumOps = e*3;
4033 ReservedSpace = NumOps;
4038 assert(Changed &&
"called only if metadata has changed");
4043 assert(SI.getNumSuccessors() == Weights->size() &&
4044 "num of prof branch_weights must accord with num of successors");
4046 bool AllZeroes =
all_of(*Weights, [](
uint32_t W) {
return W == 0; });
4048 if (AllZeroes || Weights->size() < 2)
4061 "not correspond to number of succesors");
4067 this->Weights = std::move(Weights);
4073 assert(SI.getNumSuccessors() == Weights->size() &&
4074 "num of prof branch_weights must accord with num of successors");
4079 (*Weights)[
I->getCaseIndex() + 1] = Weights->back();
4080 Weights->pop_back();
4082 return SI.removeCase(
I);
4088 SI.addCase(OnVal, Dest);
4090 if (!Weights && W && *W) {
4093 (*Weights)[SI.getNumSuccessors() - 1] = *W;
4094 }
else if (Weights) {
4096 Weights->push_back(W.value_or(0));
4099 assert(SI.getNumSuccessors() == Weights->size() &&
4100 "num of prof branch_weights must accord with num of successors");
4109 return SI.eraseFromParent();
4115 return std::nullopt;
4116 return (*Weights)[idx];
4128 auto &OldW = (*Weights)[idx];
4140 if (ProfileData->getNumOperands() == SI.getNumSuccessors() + 1)
4141 return mdconst::extract<ConstantInt>(ProfileData->getOperand(idx + 1))
4145 return std::nullopt;
4152void IndirectBrInst::init(
Value *
Address,
unsigned NumDests) {
4154 "Address of indirectbr must be a pointer");
4155 ReservedSpace = 1+NumDests;
4166void IndirectBrInst::growOperands() {
4168 unsigned NumOps = e*2;
4170 ReservedSpace = NumOps;
4174IndirectBrInst::IndirectBrInst(
Value *
Address,
unsigned NumCases,
4177 Instruction::IndirectBr, AllocMarker, InsertBefore) {
4186 Use *OL = getOperandList();
4197 if (OpNo+1 > ReservedSpace)
4200 assert(OpNo < ReservedSpace &&
"Growing didn't work!");
4214 OL[idx+1] = OL[NumOps-1];
4217 OL[NumOps-1].
set(
nullptr);
4289 Result->setWeak(
isWeak());
4362 return new (AllocMarker)
CallInst(*
this, AllocMarker);
4365 return new (AllocMarker)
CallInst(*
this, AllocMarker);
4396 return new (AllocMarker)
ReturnInst(*
this, AllocMarker);
4401 return new (AllocMarker)
BranchInst(*
this, AllocMarker);
4415 return new (AllocMarker)
InvokeInst(*
this, AllocMarker);
4418 return new (AllocMarker)
InvokeInst(*
this, AllocMarker);
4426 return new (AllocMarker)
CallBrInst(*
this, AllocMarker);
4429 return new (AllocMarker)
CallBrInst(*
this, AllocMarker);
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Atomic ordering constants.
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains the declarations for the subclasses of Constant, which represent the different fla...