36using namespace PatternMatch;
41 cl::desc(
"Use ConstantInt's native fixed-length vector splat support."));
44 cl::desc(
"Use ConstantFP's native fixed-length vector splat support."));
47 cl::desc(
"Use ConstantInt's native scalable vector splat support."));
50 cl::desc(
"Use ConstantFP's native scalable vector splat support."));
58 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
59 return CFP->isZero() && CFP->isNegative();
63 if (
const auto *SplatCFP = dyn_cast_or_null<ConstantFP>(
getSplatValue()))
64 return SplatCFP->isNegativeZeroValue();
67 if (
getType()->isFPOrFPVectorTy())
78 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
83 if (
const auto *SplatCFP = dyn_cast_or_null<ConstantFP>(
getSplatValue()))
84 return SplatCFP->isZero();
92 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
96 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
99 return CFP->isExactlyValue(+0.0);
103 return isa<ConstantAggregateZero>(
this) || isa<ConstantPointerNull>(
this) ||
104 isa<ConstantTokenNone>(
this) || isa<ConstantTargetNone>(
this);
109 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
110 return CI->isMinusOne();
113 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
114 return CFP->getValueAPF().bitcastToAPInt().isAllOnes();
119 return SplatVal->isAllOnesValue();
126 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
130 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
131 return CFP->getValueAPF().bitcastToAPInt().isOne();
136 return SplatVal->isOneValue();
143 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
144 return !CI->isOneValue();
147 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
148 return !CFP->getValueAPF().bitcastToAPInt().isOne();
151 if (
auto *VTy = dyn_cast<FixedVectorType>(
getType())) {
152 for (
unsigned I = 0, E = VTy->getNumElements();
I != E; ++
I) {
163 return SplatVal->isNotOneValue();
171 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
172 return CI->isMinValue(
true);
175 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
176 return CFP->getValueAPF().bitcastToAPInt().isMinSignedValue();
181 return SplatVal->isMinSignedValue();
188 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
189 return !CI->isMinValue(
true);
192 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
193 return !CFP->getValueAPF().bitcastToAPInt().isMinSignedValue();
196 if (
auto *VTy = dyn_cast<FixedVectorType>(
getType())) {
197 for (
unsigned I = 0, E = VTy->getNumElements();
I != E; ++
I) {
208 return SplatVal->isNotMinSignedValue();
215 if (
auto *CFP = dyn_cast<ConstantFP>(
this))
216 return CFP->getValueAPF().isFiniteNonZero();
218 if (
auto *VTy = dyn_cast<FixedVectorType>(
getType())) {
219 for (
unsigned I = 0, E = VTy->getNumElements();
I != E; ++
I) {
221 if (!CFP || !CFP->getValueAPF().isFiniteNonZero())
228 if (
const auto *SplatCFP = dyn_cast_or_null<ConstantFP>(
getSplatValue()))
229 return SplatCFP->isFiniteNonZeroFP();
236 if (
auto *CFP = dyn_cast<ConstantFP>(
this))
237 return CFP->getValueAPF().isNormal();
239 if (
auto *VTy = dyn_cast<FixedVectorType>(
getType())) {
240 for (
unsigned I = 0, E = VTy->getNumElements();
I != E; ++
I) {
242 if (!CFP || !CFP->getValueAPF().isNormal())
249 if (
const auto *SplatCFP = dyn_cast_or_null<ConstantFP>(
getSplatValue()))
250 return SplatCFP->isNormalFP();
257 if (
auto *CFP = dyn_cast<ConstantFP>(
this))
258 return CFP->getValueAPF().getExactInverse(
nullptr);
260 if (
auto *VTy = dyn_cast<FixedVectorType>(
getType())) {
261 for (
unsigned I = 0, E = VTy->getNumElements();
I != E; ++
I) {
263 if (!CFP || !CFP->getValueAPF().getExactInverse(
nullptr))
270 if (
const auto *SplatCFP = dyn_cast_or_null<ConstantFP>(
getSplatValue()))
271 return SplatCFP->hasExactInverseFP();
278 if (
auto *CFP = dyn_cast<ConstantFP>(
this))
281 if (
auto *VTy = dyn_cast<FixedVectorType>(
getType())) {
282 for (
unsigned I = 0, E = VTy->getNumElements();
I != E; ++
I) {
284 if (!CFP || !CFP->isNaN())
291 if (
const auto *SplatCFP = dyn_cast_or_null<ConstantFP>(
getSplatValue()))
292 return SplatCFP->isNaN();
304 auto *VTy = dyn_cast<VectorType>(
getType());
305 if (!isa<Constant>(
Y) || !VTy || VTy !=
Y->getType())
309 if (!(VTy->getElementType()->isIntegerTy() ||
310 VTy->getElementType()->isFloatingPointTy()))
319 return CmpEq && (isa<PoisonValue>(CmpEq) ||
match(CmpEq,
m_One()));
325 if (
auto *VTy = dyn_cast<VectorType>(
C->getType())) {
328 if (isa<ConstantAggregateZero>(
C))
330 if (isa<ScalableVectorType>(
C->getType()))
333 for (
unsigned i = 0, e = cast<FixedVectorType>(VTy)->
getNumElements();
335 if (
Constant *Elem =
C->getAggregateElement(i))
346 this, [&](
const auto *
C) {
return isa<UndefValue>(
C); });
351 this, [&](
const auto *
C) {
return isa<PoisonValue>(
C); });
356 return isa<UndefValue>(
C) && !isa<PoisonValue>(
C);
361 if (isa<ConstantInt>(
this) || isa<ConstantFP>(
this))
364 if (
auto *VTy = dyn_cast<FixedVectorType>(
getType())) {
365 for (
unsigned i = 0, e = VTy->getNumElements(); i != e; ++i)
376 return ConstantInt::get(Ty, 0);
410 if (
PointerType *PTy = dyn_cast<PointerType>(ScalarTy))
414 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
437 "Must be an aggregate/vector constant");
439 if (
const auto *CC = dyn_cast<ConstantAggregate>(
this))
440 return Elt < CC->getNumOperands() ? CC->getOperand(Elt) :
nullptr;
442 if (
const auto *CAZ = dyn_cast<ConstantAggregateZero>(
this))
443 return Elt < CAZ->getElementCount().getKnownMinValue()
444 ? CAZ->getElementValue(Elt)
447 if (
const auto *CI = dyn_cast<ConstantInt>(
this))
448 return Elt < cast<VectorType>(
getType())
451 ? ConstantInt::get(
getContext(), CI->getValue())
454 if (
const auto *CFP = dyn_cast<ConstantFP>(
this))
455 return Elt < cast<VectorType>(
getType())
458 ? ConstantFP::get(
getContext(), CFP->getValue())
462 if (isa<ScalableVectorType>(
getType()))
465 if (
const auto *PV = dyn_cast<PoisonValue>(
this))
466 return Elt < PV->getNumElements() ? PV->getElementValue(Elt) :
nullptr;
468 if (
const auto *UV = dyn_cast<UndefValue>(
this))
469 return Elt < UV->getNumElements() ? UV->getElementValue(Elt) :
nullptr;
471 if (
const auto *CDS = dyn_cast<ConstantDataSequential>(
this))
472 return Elt < CDS->getNumElements() ? CDS->getElementAsConstant(Elt)
479 assert(isa<IntegerType>(Elt->
getType()) &&
"Index must be an integer");
480 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Elt)) {
482 if (CI->getValue().getActiveBits() > 64)
495#define HANDLE_CONSTANT(Name) \
496 case Value::Name##Val: \
497 cast<Name>(this)->destroyConstantImpl(); \
499#include "llvm/IR/Value.def"
512 if (!isa<Constant>(V)) {
513 dbgs() <<
"While deleting: " << *
this
514 <<
"\n\nUse still stuck around after Def is destroyed: " << *V
518 assert(isa<Constant>(V) &&
"References remain to Constant being destroyed");
519 cast<Constant>(V)->destroyConstant();
530 switch (
C->getValueID()) {
531 case Constant::ConstantIntVal:
534 case Constant::ConstantFPVal:
537 case Constant::ConstantAggregateZeroVal:
540 case Constant::ConstantArrayVal:
543 case Constant::ConstantStructVal:
546 case Constant::ConstantVectorVal:
549 case Constant::ConstantPointerNullVal:
552 case Constant::ConstantDataArrayVal:
555 case Constant::ConstantDataVectorVal:
558 case Constant::ConstantTokenNoneVal:
561 case Constant::BlockAddressVal:
564 case Constant::DSOLocalEquivalentVal:
567 case Constant::NoCFIValueVal:
570 case Constant::ConstantPtrAuthVal:
573 case Constant::UndefValueVal:
576 case Constant::PoisonValueVal:
579 case Constant::ConstantExprVal:
580 if (isa<CastConstantExpr>(
C))
582 else if (isa<BinaryConstantExpr>(
C))
584 else if (isa<ExtractElementConstantExpr>(
C))
586 else if (isa<InsertElementConstantExpr>(
C))
588 else if (isa<ShuffleVectorConstantExpr>(
C))
590 else if (isa<GetElementPtrConstantExpr>(
C))
609 while (!WorkList.
empty()) {
611 if (
const auto *GV = dyn_cast<GlobalValue>(
WorkItem))
615 const Constant *ConstOp = dyn_cast<Constant>(
Op);
618 if (Visited.
insert(ConstOp).second)
626 auto DLLImportPredicate = [](
const GlobalValue *GV) {
627 return GV->isThreadLocal();
633 auto DLLImportPredicate = [](
const GlobalValue *GV) {
634 return GV->hasDLLImportStorageClass();
641 const Constant *UC = dyn_cast<Constant>(U);
642 if (!UC || isa<GlobalValue>(UC))
652 return getRelocationInfo() == GlobalRelocation;
656 return getRelocationInfo() != NoRelocation;
659Constant::PossibleRelocationsTy Constant::getRelocationInfo()
const {
660 if (isa<GlobalValue>(
this))
661 return GlobalRelocation;
663 if (
const BlockAddress *BA = dyn_cast<BlockAddress>(
this))
664 return BA->getFunction()->getRelocationInfo();
666 if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(
this)) {
667 if (CE->getOpcode() == Instruction::Sub) {
670 if (LHS && RHS &&
LHS->getOpcode() == Instruction::PtrToInt &&
671 RHS->getOpcode() == Instruction::PtrToInt) {
679 if (isa<BlockAddress>(LHSOp0) && isa<BlockAddress>(RHSOp0) &&
688 if (
auto *LHSGV = dyn_cast<GlobalValue>(LHS)) {
689 if (LHSGV->isDSOLocal() && RHSGV->isDSOLocal())
690 return LocalRelocation;
691 }
else if (isa<DSOLocalEquivalent>(LHS)) {
692 if (RHSGV->isDSOLocal())
693 return LocalRelocation;
700 PossibleRelocationsTy
Result = NoRelocation;
702 Result = std::max(cast<Constant>(
Op)->getRelocationInfo(), Result);
711 if (isa<GlobalValue>(
C))
return false;
716 if (!
User)
return false;
729 if (RemoveDeadUsers) {
733 const_cast<Constant *
>(
C)->destroyConstant();
759 if (LastNonDeadUser == E)
762 I = std::next(LastNonDeadUser);
770bool Constant::hasNLiveUses(
unsigned N)
const {
771 unsigned NumUses = 0;
785 assert(
C && Replacement &&
"Expected non-nullptr constant arguments");
786 Type *Ty =
C->getType();
788 assert(Ty == Replacement->
getType() &&
"Expected matching types");
793 auto *VTy = dyn_cast<FixedVectorType>(Ty);
797 unsigned NumElts = VTy->getNumElements();
799 for (
unsigned i = 0; i != NumElts; ++i) {
800 Constant *EltC =
C->getAggregateElement(i);
802 "Expected matching types");
803 NewC[i] = EltC &&
match(EltC,
m_Undef()) ? Replacement : EltC;
809 assert(
C &&
Other &&
"Expected non-nullptr constant arguments");
813 Type *Ty =
C->getType();
817 auto *VTy = dyn_cast<FixedVectorType>(Ty);
821 Type *EltTy = VTy->getElementType();
822 unsigned NumElts = VTy->getNumElements();
824 cast<FixedVectorType>(
Other->getType())->getNumElements() == NumElts &&
827 bool FoundExtraUndef =
false;
829 for (
unsigned I = 0;
I != NumElts; ++
I) {
830 NewC[
I] =
C->getAggregateElement(
I);
832 assert(NewC[
I] && OtherEltC &&
"Unknown vector element");
835 FoundExtraUndef =
true;
844 if (isa<UndefValue>(
this))
846 if (isa<ConstantData>(
this))
848 if (isa<ConstantAggregate>(
this) || isa<ConstantExpr>(
this)) {
861ConstantInt::ConstantInt(
Type *Ty,
const APInt &V)
865 "Invalid constant for type");
889 if (
auto *VTy = dyn_cast<VectorType>(Ty))
897 if (
auto *VTy = dyn_cast<VectorType>(Ty))
910 std::unique_ptr<ConstantInt> &Slot =
927 std::unique_ptr<ConstantInt> &Slot =
928 Context.pImpl->IntSplatConstants[std::make_pair(EC, V)];
938 assert(Slot->getType() == VTy);
947 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
963 "ConstantInt type doesn't match the type implied by its value!");
966 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
977void ConstantInt::destroyConstantImpl() {
995 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1004 "ConstantFP type doesn't match the type implied by its value!");
1007 if (
auto *VTy = dyn_cast<VectorType>(Ty))
1020 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1031 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1042 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1053 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1064 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1075 std::unique_ptr<ConstantFP> &Slot = pImpl->
FPConstants[V];
1089 std::unique_ptr<ConstantFP> &Slot =
1090 Context.pImpl->FPSplatConstants[std::make_pair(EC, V)];
1100 assert(Slot->getType() == VTy);
1109 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1118 "FP type Mismatch");
1126void ConstantFP::destroyConstantImpl() {
1135 if (
auto *AT = dyn_cast<ArrayType>(
getType()))
1158 if (
auto *AT = dyn_cast<ArrayType>(Ty))
1160 if (
auto *VT = dyn_cast<VectorType>(Ty))
1161 return VT->getElementCount();
1193 if (
auto *AT = dyn_cast<ArrayType>(Ty))
1194 return AT->getNumElements();
1195 if (
auto *VT = dyn_cast<VectorType>(Ty))
1196 return cast<FixedVectorType>(VT)->getNumElements();
1230template <
typename ItTy,
typename EltTy>
1232 for (; Start !=
End; ++Start)
1238template <
typename SequentialTy,
typename ElementTy>
1240 assert(!V.empty() &&
"Cannot get empty int sequence.");
1244 if (
auto *CI = dyn_cast<ConstantInt>(
C))
1248 return SequentialTy::get(V[0]->getContext(), Elts);
1251template <
typename SequentialTy,
typename ElementTy>
1253 assert(!V.empty() &&
"Cannot get empty FP sequence.");
1257 if (
auto *CFP = dyn_cast<ConstantFP>(
C))
1258 Elts.
push_back(CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
1261 return SequentialTy::getFP(V[0]->
getType(), Elts);
1264template <
typename SequenceTy>
1271 if (CI->getType()->isIntegerTy(8))
1272 return getIntSequenceIfElementsMatch<SequenceTy, uint8_t>(V);
1273 else if (CI->getType()->isIntegerTy(16))
1274 return getIntSequenceIfElementsMatch<SequenceTy, uint16_t>(V);
1275 else if (CI->getType()->isIntegerTy(32))
1276 return getIntSequenceIfElementsMatch<SequenceTy, uint32_t>(V);
1277 else if (CI->getType()->isIntegerTy(64))
1278 return getIntSequenceIfElementsMatch<SequenceTy, uint64_t>(V);
1279 }
else if (
ConstantFP *CFP = dyn_cast<ConstantFP>(
C)) {
1280 if (CFP->getType()->isHalfTy() || CFP->getType()->isBFloatTy())
1281 return getFPSequenceIfElementsMatch<SequenceTy, uint16_t>(V);
1282 else if (CFP->getType()->isFloatTy())
1283 return getFPSequenceIfElementsMatch<SequenceTy, uint32_t>(V);
1284 else if (CFP->getType()->isDoubleTy())
1285 return getFPSequenceIfElementsMatch<SequenceTy, uint64_t>(V);
1298 if (
auto *ST = dyn_cast<StructType>(
T)) {
1301 for (
unsigned I = 0, E = V.size();
I != E; ++
I)
1303 "Initializer for struct element doesn't match!");
1310 assert(V.size() ==
T->getNumElements() &&
1311 "Invalid initializer for constant array");
1327 "Wrong type in array element initializer");
1347 return getSequenceIfElementsMatch<ConstantDataArray>(
C, V);
1356 unsigned VecSize = V.size();
1358 for (
unsigned i = 0; i != VecSize; ++i)
1359 EltTypes[i] = V[i]->
getType();
1368 "ConstantStruct::getTypeForElements cannot be called on empty list");
1375 assert((
T->isOpaque() || V.size() ==
T->getNumElements()) &&
1376 "Invalid initializer for constant struct");
1381 assert((ST->isOpaque() || ST->getNumElements() == V.size()) &&
1382 "Incorrect # elements specified to ConstantStruct::get");
1387 bool isPoison =
false;
1390 isUndef = isa<UndefValue>(V[0]);
1391 isPoison = isa<PoisonValue>(V[0]);
1392 isZero = V[0]->isNullValue();
1396 if (!
C->isNullValue())
1398 if (!isa<PoisonValue>(
C))
1400 if (isa<PoisonValue>(
C) || !isa<UndefValue>(
C))
1412 return ST->getContext().pImpl->StructConstants.getOrCreate(ST, V);
1418 assert(V.size() == cast<FixedVectorType>(
T)->getNumElements() &&
1419 "Invalid initializer for constant vector");
1431 assert(!V.empty() &&
"Vectors can't be empty");
1437 bool isZero =
C->isNullValue();
1439 bool isPoison = isa<PoisonValue>(
C);
1444 for (
unsigned i = 1, e = V.size(); i != e; ++i)
1446 isZero =
isUndef = isPoison = isSplatFP = isSplatInt =
false;
1458 return ConstantFP::get(
C->getContext(),
T->getElementCount(),
1459 cast<ConstantFP>(
C)->getValue());
1461 return ConstantInt::get(
C->getContext(),
T->getElementCount(),
1462 cast<ConstantInt>(
C)->getValue());
1467 return getSequenceIfElementsMatch<ConstantDataVector>(
C, V);
1475 if (!EC.isScalable()) {
1477 if (!V->isNullValue()) {
1479 return ConstantInt::get(V->getContext(), EC,
1480 cast<ConstantInt>(V)->getValue());
1482 return ConstantFP::get(V->getContext(), EC,
1483 cast<ConstantFP>(V)->getValue());
1488 if ((isa<ConstantFP>(V) || isa<ConstantInt>(V)) &&
1497 if (!V->isNullValue()) {
1499 return ConstantInt::get(V->getContext(), EC,
1500 cast<ConstantInt>(V)->getValue());
1502 return ConstantFP::get(V->getContext(), EC,
1503 cast<ConstantFP>(V)->getValue());
1508 if (V->isNullValue())
1510 if (isa<PoisonValue>(V))
1512 if (isa<UndefValue>(V))
1534void ConstantTokenNone::destroyConstantImpl() {
1544 return cast<ShuffleVectorConstantExpr>(
this)->ShuffleMask;
1548 return cast<ShuffleVectorConstantExpr>(
this)->ShuffleMaskForBitcode;
1552 bool OnlyIfReduced,
Type *SrcTy)
const {
1559 Type *OnlyIfReducedTy = OnlyIfReduced ? Ty :
nullptr;
1561 case Instruction::Trunc:
1562 case Instruction::ZExt:
1563 case Instruction::SExt:
1564 case Instruction::FPTrunc:
1565 case Instruction::FPExt:
1566 case Instruction::UIToFP:
1567 case Instruction::SIToFP:
1568 case Instruction::FPToUI:
1569 case Instruction::FPToSI:
1570 case Instruction::PtrToAddr:
1571 case Instruction::PtrToInt:
1572 case Instruction::IntToPtr:
1573 case Instruction::BitCast:
1574 case Instruction::AddrSpaceCast:
1576 case Instruction::InsertElement:
1579 case Instruction::ExtractElement:
1581 case Instruction::ShuffleVector:
1584 case Instruction::GetElementPtr: {
1585 auto *GEPO = cast<GEPOperator>(
this);
1588 SrcTy ? SrcTy : GEPO->getSourceElementType(), Ops[0], Ops.
slice(1),
1589 GEPO->getNoWrapFlags(), GEPO->getInRange(), OnlyIfReducedTy);
1605 return Val == 0 || Val == 1;
1612 return Val == 0 || Val == 1 || Val == -1;
1613 return isIntN(NumBits, Val);
1679 "Cannot create an aggregate zero of non-aggregate type!");
1681 std::unique_ptr<ConstantAggregateZero> &Entry =
1690void ConstantAggregateZero::destroyConstantImpl() {
1695void ConstantArray::destroyConstantImpl() {
1704void ConstantStruct::destroyConstantImpl() {
1709void ConstantVector::destroyConstantImpl() {
1714 assert(this->
getType()->isVectorTy() &&
"Only valid for vectors!");
1715 if (isa<PoisonValue>(
this))
1717 if (isa<ConstantAggregateZero>(
this))
1719 if (
auto *CI = dyn_cast<ConstantInt>(
this))
1720 return ConstantInt::get(
getContext(), CI->getValue());
1721 if (
auto *CFP = dyn_cast<ConstantFP>(
this))
1722 return ConstantFP::get(
getContext(), CFP->getValue());
1724 return CV->getSplatValue();
1726 return CV->getSplatValue(AllowPoison);
1730 const auto *Shuf = dyn_cast<ConstantExpr>(
this);
1731 if (Shuf && Shuf->getOpcode() == Instruction::ShuffleVector &&
1732 isa<UndefValue>(Shuf->getOperand(1))) {
1734 const auto *IElt = dyn_cast<ConstantExpr>(Shuf->getOperand(0));
1735 if (IElt && IElt->getOpcode() == Instruction::InsertElement &&
1736 isa<UndefValue>(IElt->getOperand(0))) {
1740 ConstantInt *Index = dyn_cast<ConstantInt>(IElt->getOperand(2));
1742 if (Index && Index->getValue() == 0 &&
1765 if (isa<PoisonValue>(OpC))
1769 if (isa<PoisonValue>(Elt))
1779 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
1780 return CI->getValue();
1782 if (isa<ConstantExpr>(
this))
1783 return cast<ConstantInt>(this->
getSplatValue())->getValue();
1788 assert(
C && isa<ConstantInt>(
C) &&
"Not a vector of numbers!");
1789 return cast<ConstantInt>(
C)->getValue();
1793 if (
auto *CI = dyn_cast<ConstantInt>(
this))
1798 return ConstantRange::getFull(
BitWidth);
1800 if (
auto *CI = dyn_cast_or_null<ConstantInt>(
1804 if (
auto *CDV = dyn_cast<ConstantDataVector>(
this)) {
1806 for (
unsigned I = 0, E = CDV->getNumElements();
I < E; ++
I)
1807 CR = CR.
unionWith(CDV->getElementAsAPInt(
I));
1811 if (
auto *CV = dyn_cast<ConstantVector>(
this)) {
1813 for (
unsigned I = 0, E = CV->getNumOperands();
I < E; ++
I) {
1816 return ConstantRange::getFull(
BitWidth);
1817 if (isa<PoisonValue>(Elem))
1819 auto *CI = dyn_cast<ConstantInt>(Elem);
1821 return ConstantRange::getFull(
BitWidth);
1827 return ConstantRange::getFull(
BitWidth);
1834 std::unique_ptr<ConstantPointerNull> &Entry =
1843void ConstantPointerNull::destroyConstantImpl() {
1852 "Target extension type not allowed to have a zeroinitializer");
1853 std::unique_ptr<ConstantTargetNone> &Entry =
1862void ConstantTargetNone::destroyConstantImpl() {
1875void UndefValue::destroyConstantImpl() {
1894void PoisonValue::destroyConstantImpl() {
1919 BB->setHasAddressTaken(
true);
1927 assert(BA &&
"Refcount and block address map disagree!");
1932void BlockAddress::destroyConstantImpl() {
1967 "DSOLocalFunction does not match the expected global value");
1971DSOLocalEquivalent::DSOLocalEquivalent(
GlobalValue *GV)
1977void DSOLocalEquivalent::destroyConstantImpl() {
1984 assert(isa<Constant>(To) &&
"Can only replace the operands with a constant");
1987 if (
const auto *ToObj = dyn_cast<GlobalValue>(To)) {
2024 assert(
NC->getGlobalValue() == GV &&
2025 "NoCFIValue does not match the expected global value");
2035void NoCFIValue::destroyConstantImpl() {
2044 assert(GV &&
"Can only replace the operands with a global value");
2079 assert(Key->getBitWidth() == 32);
2089void ConstantPtrAuth::destroyConstantImpl() {
2094 assert(isa<Constant>(ToV) &&
"Cannot make Constant refer to non-constant!");
2095 Constant *To = cast<Constant>(ToV);
2100 unsigned NumUpdated = 0;
2103 unsigned OperandNo = 0;
2105 Constant *Val = cast<Constant>(
O->get());
2107 OperandNo = (
O - OperandList);
2115 Values,
this,
From, To, NumUpdated, OperandNo);
2120 if (!CastV || CastV->getOpcode() != Instruction::IntToPtr)
2123 const auto *IntVal = dyn_cast<ConstantInt>(CastV->getOperand(0));
2127 return IntVal->getValue() ==
Value;
2131 const Value *Discriminator,
2149 const Value *AddrDiscriminator =
nullptr;
2155 if (!
match(Discriminator,
2156 m_Intrinsic<Intrinsic::ptrauth_blend>(
2161 AddrDiscriminator = Discriminator;
2167 if (
auto *Cast = dyn_cast<PtrToIntOperator>(AddrDiscriminator))
2168 AddrDiscriminator = Cast->getPointerOperand();
2183 APInt Off2(
DL.getIndexTypeSizeInBits(AddrDiscriminator->
getType()), 0);
2187 return Base1 == Base2 && Off1 == Off2;
2196 bool OnlyIfReduced =
false) {
2214 bool OnlyIfReduced) {
2218 "Cast opcode not supported as constant expression");
2219 assert(
C && Ty &&
"Null arguments to getCast");
2225 case Instruction::Trunc:
2227 case Instruction::PtrToAddr:
2229 case Instruction::PtrToInt:
2231 case Instruction::IntToPtr:
2233 case Instruction::BitCast:
2235 case Instruction::AddrSpaceCast:
2274 bool fromVec = isa<VectorType>(
C->getType());
2275 bool toVec = isa<VectorType>(Ty);
2277 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2278 assert(
C->getType()->isIntOrIntVectorTy() &&
"Trunc operand must be integer");
2281 "SrcTy must be larger than DestTy for Trunc!");
2287 bool OnlyIfReduced) {
2288 assert(
C->getType()->isPtrOrPtrVectorTy() &&
2289 "PtrToAddr source must be pointer or pointer vector");
2291 "PtrToAddr destination must be integer or integer vector");
2292 assert(isa<VectorType>(
C->getType()) == isa<VectorType>(DstTy));
2293 if (isa<VectorType>(
C->getType()))
2294 assert(cast<VectorType>(
C->getType())->getElementCount() ==
2295 cast<VectorType>(DstTy)->getElementCount() &&
2296 "Invalid cast between a different number of vector elements");
2297 return getFoldedCast(Instruction::PtrToAddr,
C, DstTy, OnlyIfReduced);
2301 bool OnlyIfReduced) {
2302 assert(
C->getType()->isPtrOrPtrVectorTy() &&
2303 "PtrToInt source must be pointer or pointer vector");
2305 "PtrToInt destination must be integer or integer vector");
2306 assert(isa<VectorType>(
C->getType()) == isa<VectorType>(DstTy));
2307 if (isa<VectorType>(
C->getType()))
2308 assert(cast<VectorType>(
C->getType())->getElementCount() ==
2309 cast<VectorType>(DstTy)->getElementCount() &&
2310 "Invalid cast between a different number of vector elements");
2311 return getFoldedCast(Instruction::PtrToInt,
C, DstTy, OnlyIfReduced);
2315 bool OnlyIfReduced) {
2316 assert(
C->getType()->isIntOrIntVectorTy() &&
2317 "IntToPtr source must be integer or integer vector");
2319 "IntToPtr destination must be a pointer or pointer vector");
2320 assert(isa<VectorType>(
C->getType()) == isa<VectorType>(DstTy));
2321 if (isa<VectorType>(
C->getType()))
2322 assert(cast<VectorType>(
C->getType())->getElementCount() ==
2323 cast<VectorType>(DstTy)->getElementCount() &&
2324 "Invalid cast between a different number of vector elements");
2325 return getFoldedCast(Instruction::IntToPtr,
C, DstTy, OnlyIfReduced);
2329 bool OnlyIfReduced) {
2331 "Invalid constantexpr bitcast!");
2335 if (
C->getType() == DstTy)
return C;
2337 return getFoldedCast(Instruction::BitCast,
C, DstTy, OnlyIfReduced);
2341 bool OnlyIfReduced) {
2343 "Invalid constantexpr addrspacecast!");
2344 return getFoldedCast(Instruction::AddrSpaceCast,
C, DstTy, OnlyIfReduced);
2348 unsigned Flags,
Type *OnlyIfReducedTy) {
2351 "Invalid opcode in binary constant expression");
2353 "Binop not supported as constant expression");
2355 "Operand types in binary constant expression should match");
2359 case Instruction::Add:
2360 case Instruction::Sub:
2361 case Instruction::Mul:
2363 "Tried to create an integer operation on a non-integer type!");
2365 case Instruction::And:
2366 case Instruction::Or:
2367 case Instruction::Xor:
2369 "Tried to create a logical operation on a non-integral type!");
2379 if (OnlyIfReducedTy == C1->
getType())
2391 case Instruction::UDiv:
2392 case Instruction::SDiv:
2393 case Instruction::URem:
2394 case Instruction::SRem:
2395 case Instruction::FAdd:
2396 case Instruction::FSub:
2397 case Instruction::FMul:
2398 case Instruction::FDiv:
2399 case Instruction::FRem:
2400 case Instruction::And:
2401 case Instruction::Or:
2402 case Instruction::LShr:
2403 case Instruction::AShr:
2404 case Instruction::Shl:
2405 case Instruction::Mul:
2407 case Instruction::Add:
2408 case Instruction::Sub:
2409 case Instruction::Xor:
2418 case Instruction::UDiv:
2419 case Instruction::SDiv:
2420 case Instruction::URem:
2421 case Instruction::SRem:
2422 case Instruction::FAdd:
2423 case Instruction::FSub:
2424 case Instruction::FMul:
2425 case Instruction::FDiv:
2426 case Instruction::FRem:
2427 case Instruction::And:
2428 case Instruction::Or:
2429 case Instruction::LShr:
2430 case Instruction::AShr:
2431 case Instruction::Shl:
2432 case Instruction::Mul:
2434 case Instruction::Add:
2435 case Instruction::Sub:
2436 case Instruction::Xor:
2445 case Instruction::ZExt:
2446 case Instruction::SExt:
2447 case Instruction::FPTrunc:
2448 case Instruction::FPExt:
2449 case Instruction::UIToFP:
2450 case Instruction::SIToFP:
2451 case Instruction::FPToUI:
2452 case Instruction::FPToSI:
2454 case Instruction::Trunc:
2455 case Instruction::PtrToAddr:
2456 case Instruction::PtrToInt:
2457 case Instruction::IntToPtr:
2458 case Instruction::BitCast:
2459 case Instruction::AddrSpaceCast:
2468 case Instruction::ZExt:
2469 case Instruction::SExt:
2470 case Instruction::FPTrunc:
2471 case Instruction::FPExt:
2472 case Instruction::UIToFP:
2473 case Instruction::SIToFP:
2474 case Instruction::FPToUI:
2475 case Instruction::FPToSI:
2477 case Instruction::Trunc:
2478 case Instruction::PtrToAddr:
2479 case Instruction::PtrToInt:
2480 case Instruction::IntToPtr:
2481 case Instruction::BitCast:
2482 case Instruction::AddrSpaceCast:
2508 Constant *Indices[2] = {Zero, One};
2516 std::optional<ConstantRange>
InRange,
2517 Type *OnlyIfReducedTy) {
2518 assert(Ty &&
"Must specify element type");
2529 if (OnlyIfReducedTy == ReqTy)
2533 if (
VectorType *VecTy = dyn_cast<VectorType>(ReqTy))
2534 EltCount = VecTy->getElementCount();
2537 std::vector<Constant*> ArgVec;
2538 ArgVec.reserve(1 + Idxs.
size());
2539 ArgVec.push_back(
C);
2541 for (; GTI != GTE; ++GTI) {
2542 auto *
Idx = cast<Constant>(GTI.getOperand());
2544 (!isa<VectorType>(
Idx->getType()) ||
2545 cast<VectorType>(
Idx->getType())->getElementCount() == EltCount) &&
2546 "getelementptr index type missmatch");
2548 if (GTI.isStruct() &&
Idx->getType()->isVectorTy()) {
2549 Idx =
Idx->getSplatValue();
2550 }
else if (GTI.isSequential() && EltCount.isNonZero() &&
2551 !
Idx->getType()->isVectorTy()) {
2554 ArgVec.push_back(
Idx);
2565 Type *OnlyIfReducedTy) {
2567 "Tried to create extractelement operation on non-vector type!");
2569 "Extractelement index must be an integer type!");
2574 Type *ReqTy = cast<VectorType>(Val->
getType())->getElementType();
2575 if (OnlyIfReducedTy == ReqTy)
2589 "Tried to create insertelement operation on non-vector type!");
2591 "Insertelement types must match!");
2593 "Insertelement index must be i32 type!");
2598 if (OnlyIfReducedTy == Val->
getType())
2611 Type *OnlyIfReducedTy) {
2613 "Invalid shuffle vector constant expr operands!");
2618 unsigned NElts = Mask.size();
2619 auto V1VTy = cast<VectorType>(V1->
getType());
2620 Type *EltTy = V1VTy->getElementType();
2621 bool TypeIsScalable = isa<ScalableVectorType>(V1VTy);
2624 if (OnlyIfReducedTy == ShufTy)
2636 assert(
C->getType()->isIntOrIntVectorTy() &&
2637 "Cannot NEG a nonintegral value!");
2638 return getSub(ConstantInt::get(
C->getType(), 0),
C,
false, HasNSW);
2642 assert(
C->getType()->isIntOrIntVectorTy() &&
2643 "Cannot NOT a nonintegral value!");
2648 bool HasNUW,
bool HasNSW) {
2651 return get(Instruction::Add, C1, C2, Flags);
2655 bool HasNUW,
bool HasNSW) {
2658 return get(Instruction::Sub, C1, C2, Flags);
2662 return get(Instruction::Xor, C1, C2);
2666 Type *Ty =
C->getType();
2669 return ConstantInt::get(Ty, IVal->
logBase2());
2672 auto *VecTy = dyn_cast<FixedVectorType>(Ty);
2677 for (
unsigned I = 0, E = VecTy->getNumElements();
I != E; ++
I) {
2682 if (isa<UndefValue>(Elt)) {
2695 bool AllowRHSConstant,
bool NSZ) {
2701 case Instruction::Add:
2702 case Instruction::Or:
2703 case Instruction::Xor:
2705 case Instruction::Mul:
2706 return ConstantInt::get(Ty, 1);
2707 case Instruction::And:
2709 case Instruction::FAdd:
2711 case Instruction::FMul:
2712 return ConstantFP::get(Ty, 1.0);
2719 if (!AllowRHSConstant)
2723 case Instruction::Sub:
2724 case Instruction::Shl:
2725 case Instruction::LShr:
2726 case Instruction::AShr:
2727 case Instruction::FSub:
2729 case Instruction::SDiv:
2730 case Instruction::UDiv:
2731 return ConstantInt::get(Ty, 1);
2732 case Instruction::FDiv:
2733 return ConstantFP::get(Ty, 1.0);
2741 case Intrinsic::umax:
2743 case Intrinsic::umin:
2745 case Intrinsic::smax:
2748 case Intrinsic::smin:
2757 bool AllowRHSConstant,
bool NSZ) {
2758 if (
I->isBinaryOp())
2766 bool AllowLHSConstant) {
2771 case Instruction::Or:
2774 case Instruction::And:
2775 case Instruction::Mul:
2780 if (!AllowLHSConstant)
2786 case Instruction::Shl:
2787 case Instruction::LShr:
2788 case Instruction::AShr:
2789 case Instruction::SDiv:
2790 case Instruction::UDiv:
2791 case Instruction::URem:
2792 case Instruction::SRem:
2798void ConstantExpr::destroyConstantImpl() {
2806GetElementPtrConstantExpr::GetElementPtrConstantExpr(
2810 SrcElementTy(SrcElementTy),
2815 for (
unsigned i = 0, E = IdxList.
size(); i != E; ++i)
2816 OperandList[i+1] = IdxList[i];
2820 return SrcElementTy;
2824 return ResElementTy;
2836 return ATy->getElementType();
2837 return cast<VectorType>(
getType())->getElementType();
2847 if (
auto *
IT = dyn_cast<IntegerType>(Ty)) {
2848 switch (
IT->getBitWidth()) {
2862 return AT->getNumElements();
2863 return cast<FixedVectorType>(
getType())->getNumElements();
2871const char *ConstantDataSequential::getElementPointer(
uint64_t Elt)
const {
2890 if (
ArrayType *ATy = dyn_cast<ArrayType>(Ty))
2908 std::unique_ptr<ConstantDataSequential> *Entry = &Slot.second;
2909 for (; *Entry; Entry = &(*Entry)->Next)
2910 if ((*Entry)->getType() == Ty)
2911 return Entry->get();
2915 if (isa<ArrayType>(Ty)) {
2918 return Entry->get();
2921 assert(isa<VectorType>(Ty));
2924 return Entry->get();
2927void ConstantDataSequential::destroyConstantImpl() {
2934 assert(Slot != CDSConstants.
end() &&
"CDS not found in uniquing table");
2936 std::unique_ptr<ConstantDataSequential> *Entry = &Slot->getValue();
2939 if (!(*Entry)->Next) {
2942 assert(Entry->get() ==
this &&
"Hash mismatch in ConstantDataSequential");
2950 std::unique_ptr<ConstantDataSequential> &
Node = *Entry;
2951 assert(
Node &&
"Didn't find entry in its uniquing hash table!");
2953 if (
Node.get() ==
this) {
2969 assert((ElementType->isHalfTy() || ElementType->isBFloatTy()) &&
2970 "Element type is not a 16-bit float type");
2972 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2976 assert(ElementType->isFloatTy() &&
"Element type is not a 32-bit float type");
2978 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2982 assert(ElementType->isDoubleTy() &&
2983 "Element type is not a 64-bit float type");
2985 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2997 ElementVals.
append(Str.begin(), Str.end());
3007 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3012 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3017 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3022 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3027 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3032 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3044 assert((ElementType->isHalfTy() || ElementType->isBFloatTy()) &&
3045 "Element type is not a 16-bit float type");
3047 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3052 assert(ElementType->isFloatTy() &&
"Element type is not a 32-bit float type");
3054 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3059 assert(ElementType->isDoubleTy() &&
3060 "Element type is not a 64-bit float type");
3062 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3068 "Element type not compatible with ConstantData");
3070 if (CI->getType()->isIntegerTy(8)) {
3072 return get(V->getContext(), Elts);
3074 if (CI->getType()->isIntegerTy(16)) {
3076 return get(V->getContext(), Elts);
3078 if (CI->getType()->isIntegerTy(32)) {
3080 return get(V->getContext(), Elts);
3082 assert(CI->getType()->isIntegerTy(64) &&
"Unsupported ConstantData type");
3084 return get(V->getContext(), Elts);
3087 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(V)) {
3088 if (CFP->getType()->isHalfTy()) {
3090 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3091 return getFP(V->getType(), Elts);
3093 if (CFP->getType()->isBFloatTy()) {
3095 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3096 return getFP(V->getType(), Elts);
3098 if (CFP->getType()->isFloatTy()) {
3100 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3101 return getFP(V->getType(), Elts);
3103 if (CFP->getType()->isDoubleTy()) {
3105 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3106 return getFP(V->getType(), Elts);
3114 "Accessor can only be used when element is an integer");
3115 const char *EltPtr = getElementPointer(Elt);
3122 return *
reinterpret_cast<const uint8_t *
>(EltPtr);
3124 return *
reinterpret_cast<const uint16_t *
>(EltPtr);
3126 return *
reinterpret_cast<const uint32_t *
>(EltPtr);
3128 return *
reinterpret_cast<const uint64_t *
>(EltPtr);
3134 "Accessor can only be used when element is an integer");
3135 const char *EltPtr = getElementPointer(Elt);
3142 auto EltVal = *
reinterpret_cast<const uint8_t *
>(EltPtr);
3143 return APInt(8, EltVal);
3146 auto EltVal = *
reinterpret_cast<const uint16_t *
>(EltPtr);
3147 return APInt(16, EltVal);
3150 auto EltVal = *
reinterpret_cast<const uint32_t *
>(EltPtr);
3151 return APInt(32, EltVal);
3154 auto EltVal = *
reinterpret_cast<const uint64_t *
>(EltPtr);
3155 return APInt(64, EltVal);
3161 const char *EltPtr = getElementPointer(Elt);
3165 llvm_unreachable(
"Accessor can only be used when element is float/double!");
3167 auto EltVal = *
reinterpret_cast<const uint16_t *
>(EltPtr);
3171 auto EltVal = *
reinterpret_cast<const uint16_t *
>(EltPtr);
3175 auto EltVal = *
reinterpret_cast<const uint32_t *
>(EltPtr);
3179 auto EltVal = *
reinterpret_cast<const uint64_t *
>(EltPtr);
3187 "Accessor can only be used when element is a 'float'");
3188 return *
reinterpret_cast<const float *
>(getElementPointer(Elt));
3193 "Accessor can only be used when element is a 'float'");
3194 return *
reinterpret_cast<const double *
>(getElementPointer(Elt));
3216 if (Str.back() != 0)
return false;
3219 return !Str.drop_back().contains(0);
3222bool ConstantDataVector::isSplatData()
const {
3237 IsSplat = isSplatData();
3262 Value *Replacement =
nullptr;
3266#define HANDLE_CONSTANT(Name) \
3267 case Value::Name##Val: \
3268 Replacement = cast<Name>(this)->handleOperandChangeImpl(From, To); \
3270#include "llvm/IR/Value.def"
3279 assert(Replacement !=
this &&
"I didn't contain From!");
3289 assert(isa<Constant>(To) &&
"Cannot make Constant refer to non-constant!");
3290 Constant *ToC = cast<Constant>(To);
3297 unsigned NumUpdated = 0;
3300 bool AllSame =
true;
3302 unsigned OperandNo = 0;
3304 Constant *Val = cast<Constant>(O->get());
3306 OperandNo = (O - OperandList);
3311 AllSame &= Val == ToC;
3317 if (AllSame && isa<UndefValue>(ToC))
3326 Values,
this,
From, ToC, NumUpdated, OperandNo);
3330 assert(isa<Constant>(To) &&
"Cannot make Constant refer to non-constant!");
3331 Constant *ToC = cast<Constant>(To);
3340 unsigned NumUpdated = 0;
3341 bool AllSame =
true;
3342 unsigned OperandNo = 0;
3344 Constant *Val = cast<Constant>(
O->get());
3346 OperandNo = (
O - OperandList);
3351 AllSame &= Val == ToC;
3357 if (AllSame && isa<UndefValue>(ToC))
3362 Values,
this,
From, ToC, NumUpdated, OperandNo);
3366 assert(isa<Constant>(To) &&
"Cannot make Constant refer to non-constant!");
3367 Constant *ToC = cast<Constant>(To);
3371 unsigned NumUpdated = 0;
3372 unsigned OperandNo = 0;
3388 Values,
this,
From, ToC, NumUpdated, OperandNo);
3392 assert(isa<Constant>(ToV) &&
"Cannot make Constant refer to non-constant!");
3393 Constant *To = cast<Constant>(ToV);
3396 unsigned NumUpdated = 0;
3397 unsigned OperandNo = 0;
3407 assert(NumUpdated &&
"I didn't contain From!");
3414 NewOps,
this,
From, To, NumUpdated, OperandNo);
3422 case Instruction::Trunc:
3423 case Instruction::PtrToAddr:
3424 case Instruction::PtrToInt:
3425 case Instruction::IntToPtr:
3426 case Instruction::BitCast:
3427 case Instruction::AddrSpaceCast:
3430 case Instruction::InsertElement:
3432 case Instruction::ExtractElement:
3434 case Instruction::ShuffleVector:
3437 case Instruction::GetElementPtr: {
3438 const auto *GO = cast<GEPOperator>(
this);
3440 Ops.
slice(1), GO->getNoWrapFlags(),
"");
3446 if (isa<OverflowingBinaryOperator>(BO)) {
3452 if (isa<PossiblyExactOperator>(BO))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate any type of IT block"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow complex IT blocks")))
BlockVerifier::State From
static bool isAllZeros(StringRef Arr)
Return true if the array is empty or all zeros.
static cl::opt< bool > UseConstantIntForScalableSplat("use-constant-int-for-scalable-splat", cl::init(false), cl::Hidden, cl::desc("Use ConstantInt's native scalable vector splat support."))
static cl::opt< bool > UseConstantIntForFixedLengthSplat("use-constant-int-for-fixed-length-splat", cl::init(false), cl::Hidden, cl::desc("Use ConstantInt's native fixed-length vector splat support."))
static Constant * getFPSequenceIfElementsMatch(ArrayRef< Constant * > V)
static bool rangeOnlyContains(ItTy Start, ItTy End, EltTy Elt)
static Constant * getIntSequenceIfElementsMatch(ArrayRef< Constant * > V)
static Constant * getSequenceIfElementsMatch(Constant *C, ArrayRef< Constant * > V)
static bool ConstHasGlobalValuePredicate(const Constant *C, bool(*Predicate)(const GlobalValue *))
Check if C contains a GlobalValue for which Predicate is true.
static cl::opt< bool > UseConstantFPForScalableSplat("use-constant-fp-for-scalable-splat", cl::init(false), cl::Hidden, cl::desc("Use ConstantFP's native scalable vector splat support."))
static bool constantIsDead(const Constant *C, bool RemoveDeadUsers)
Return true if the specified constantexpr is dead.
static bool containsUndefinedElement(const Constant *C, function_ref< bool(const Constant *)> HasFn)
static Constant * getFoldedCast(Instruction::CastOps opc, Constant *C, Type *Ty, bool OnlyIfReduced=false)
This is a utility function to handle folding of casts and lookup of the cast in the ExprConstants map...
static cl::opt< bool > UseConstantFPForFixedLengthSplat("use-constant-fp-for-fixed-length-splat", cl::init(false), cl::Hidden, cl::desc("Use ConstantFP's native fixed-length vector splat support."))
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Looks at all the uses of the given value Returns the Liveness deduced from the uses of this value Adds all uses that cause the result to be MaybeLive to MaybeLiveRetUses If the result is MaybeLiveUses might be modified but its content should be ignored(since it might not be complete). DeadArgumentEliminationPass
static bool isSigned(unsigned int Opcode)
static char getTypeID(Type *Ty)
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
static bool isUndef(const MachineInstr &MI)
Merge contiguous icmps into a memcmp
static bool InRange(int64_t Value, unsigned short Shift, int LBound, int HBound)
uint64_t IntrinsicInst * II
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
static unsigned getNumElements(Type *Ty)
This file defines the SmallVector class.
static SymbolRef::Type getType(const Symbol *Sym)
static Function * getFunction(FunctionType *Ty, const Twine &Name, Module *M)
static APFloat getQNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for QNaN values.
static APFloat getSNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for SNaN values.
LLVM_ABI opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
bool bitwiseIsEqual(const APFloat &RHS) const
static LLVM_ABI APFloat getAllOnesValue(const fltSemantics &Semantics)
Returns a float which is bitcasted from an all one value int.
const fltSemantics & getSemantics() const
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
static APFloat getNaN(const fltSemantics &Sem, bool Negative=false, uint64_t payload=0)
Factory for NaN values.
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Class for arbitrary precision integers.
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
unsigned logBase2() const
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Class to represent array types.
static LLVM_ABI ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
Type * getElementType() const
LLVM Basic Block Representation.
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches,...
const Function * getParent() const
Return the enclosing method, or null if none.
LLVM_ABI LLVMContext & getContext() const
Get the context in which this basic block lives.
BinaryConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to impleme...
static LLVM_ABI BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), InsertPosition InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
The address of a basic block.
static LLVM_ABI BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
BasicBlock * getBasicBlock() const
static LLVM_ABI BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
CastConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to implement...
static LLVM_ABI CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
static LLVM_ABI bool castIsValid(Instruction::CastOps op, Type *SrcTy, Type *DstTy)
This method can be used to determine if a cast from SrcTy to DstTy using Opcode op is valid or not.
All zero aggregate value.
LLVM_ABI ElementCount getElementCount() const
Return the number of elements in the array, vector, or struct.
LLVM_ABI Constant * getSequentialElement() const
If this CAZ has array or vector type, return a zero with the right element type.
LLVM_ABI Constant * getElementValue(Constant *C) const
Return a zero of the right value for the specified GEP index if we can, otherwise return null (e....
LLVM_ABI Constant * getStructElement(unsigned Elt) const
If this CAZ has struct type, return a zero with the right element type for the specified element.
static LLVM_ABI ConstantAggregateZero * get(Type *Ty)
Base class for aggregate constants (with operands).
LLVM_ABI ConstantAggregate(Type *T, ValueTy VT, ArrayRef< Constant * > V, AllocInfo AllocInfo)
ConstantArray - Constant Array Declarations.
static LLVM_ABI Constant * get(ArrayType *T, ArrayRef< Constant * > V)
ArrayType * getType() const
Specialize the getType() method to always return an ArrayType, which reduces the amount of casting ne...
An array constant whose element type is a simple 1/2/4/8-byte integer or float/double,...
static LLVM_ABI Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
static LLVM_ABI Constant * getFP(Type *ElementType, ArrayRef< uint16_t > Elts)
getFP() constructors - Return a constant of array type with a float element type taken from argument ...
LLVM_ABI APFloat getElementAsAPFloat(uint64_t i) const
If this is a sequential container of floating point type, return the specified element as an APFloat.
LLVM_ABI uint64_t getElementAsInteger(uint64_t i) const
If this is a sequential container of integers (of any size), return the specified element in the low ...
StringRef getAsString() const
If this array is isString(), then this method returns the array as a StringRef.
LLVM_ABI Constant * getElementAsConstant(uint64_t i) const
Return a Constant for a specified index's element.
LLVM_ABI uint64_t getElementByteSize() const
Return the size (in bytes) of each element in the array/vector.
LLVM_ABI float getElementAsFloat(uint64_t i) const
If this is an sequential container of floats, return the specified element as a float.
LLVM_ABI bool isString(unsigned CharSize=8) const
This method returns true if this is an array of CharSize integers.
LLVM_ABI uint64_t getNumElements() const
Return the number of elements in the array or vector.
LLVM_ABI APInt getElementAsAPInt(uint64_t i) const
If this is a sequential container of integers (of any size), return the specified element as an APInt...
static LLVM_ABI Constant * getImpl(StringRef Bytes, Type *Ty)
This is the underlying implementation of all of the ConstantDataSequential::get methods.
LLVM_ABI double getElementAsDouble(uint64_t i) const
If this is an sequential container of doubles, return the specified element as a double.
LLVM_ABI Type * getElementType() const
Return the element type of the array/vector.
LLVM_ABI bool isCString() const
This method returns true if the array "isString", ends with a null byte, and does not contains any ot...
LLVM_ABI StringRef getRawDataValues() const
Return the raw, underlying, bytes of this data.
static LLVM_ABI bool isElementTypeCompatible(Type *Ty)
Return true if a ConstantDataSequential can be formed with a vector or array of the specified element...
A vector constant whose element type is a simple 1/2/4/8-byte integer or float/double,...
LLVM_ABI Constant * getSplatValue() const
If this is a splat constant, meaning that all of the elements have the same value,...
static LLVM_ABI Constant * getSplat(unsigned NumElts, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
LLVM_ABI bool isSplat() const
Returns true if this is a splat constant, meaning that all elements have the same value.
static LLVM_ABI Constant * get(LLVMContext &Context, ArrayRef< uint8_t > Elts)
get() constructors - Return a constant with vector type with an element count and element type matchi...
static LLVM_ABI Constant * getFP(Type *ElementType, ArrayRef< uint16_t > Elts)
getFP() constructors - Return a constant of vector type with a float element type taken from argument...
Base class for constants with no operands.
A constant value that is initialized with an expression using other constant values.
static LLVM_ABI Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static LLVM_ABI Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static LLVM_ABI Constant * getAlignOf(Type *Ty)
getAlignOf constant expr - computes the alignment of a type in a target independent way (Note: the re...
static LLVM_ABI Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
static LLVM_ABI Constant * getTruncOrBitCast(Constant *C, Type *Ty)
static LLVM_ABI Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
LLVM_ABI bool isCast() const
Return true if this is a convert constant expression.
static LLVM_ABI Constant * getIdentity(Instruction *I, Type *Ty, bool AllowRHSConstant=false, bool NSZ=false)
Return the identity constant for a binary or intrinsic Instruction.
static LLVM_ABI bool isDesirableCastOp(unsigned Opcode)
Whether creating a constant expression for this cast is desirable.
LLVM_ABI Constant * getShuffleMaskForBitcode() const
Assert that this is a shufflevector and return the mask.
static LLVM_ABI Constant * getBinOpAbsorber(unsigned Opcode, Type *Ty, bool AllowLHSConstant=false)
Return the absorbing element for the given binary operation, i.e.
static LLVM_ABI Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
static LLVM_ABI Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static LLVM_ABI Constant * getNot(Constant *C)
LLVM_ABI const char * getOpcodeName() const
Return a string representation for an opcode.
static LLVM_ABI Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static LLVM_ABI Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static LLVM_ABI Constant * getPtrToAddr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static LLVM_ABI Constant * getShuffleVector(Constant *V1, Constant *V2, ArrayRef< int > Mask, Type *OnlyIfReducedTy=nullptr)
static LLVM_ABI Constant * getSizeOf(Type *Ty)
getSizeOf constant expr - computes the (alloc) size of a type (in address-units, not bits) in a targe...
static bool isSupportedGetElementPtr(const Type *SrcElemTy)
Whether creating a constant expression for this getelementptr type is supported.
static LLVM_ABI Constant * getIntrinsicIdentity(Intrinsic::ID, Type *Ty)
static LLVM_ABI Constant * getXor(Constant *C1, Constant *C2)
static LLVM_ABI Constant * get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a binary or shift operator constant expression, folding if possible.
static LLVM_ABI bool isDesirableBinOp(unsigned Opcode)
Whether creating a constant expression for this binary operator is desirable.
LLVM_ABI ArrayRef< int > getShuffleMask() const
Assert that this is a shufflevector and return the mask.
static LLVM_ABI bool isSupportedBinOp(unsigned Opcode)
Whether creating a constant expression for this binary operator is supported.
static LLVM_ABI Constant * getAddrSpaceCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, GEPNoWrapFlags NW=GEPNoWrapFlags::none(), std::optional< ConstantRange > InRange=std::nullopt, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
static LLVM_ABI Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static LLVM_ABI Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static LLVM_ABI Constant * getBinOpIdentity(unsigned Opcode, Type *Ty, bool AllowRHSConstant=false, bool NSZ=false)
Return the identity constant for a binary opcode.
static LLVM_ABI bool isSupportedCastOp(unsigned Opcode)
Whether creating a constant expression for this cast is supported.
static LLVM_ABI Constant * getNeg(Constant *C, bool HasNSW=false)
static LLVM_ABI Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static LLVM_ABI Constant * getExactLogBase2(Constant *C)
If C is a scalar/fixed width vector of known powers of 2, then this function returns a new scalar/fix...
Constant * getWithOperands(ArrayRef< Constant * > Ops) const
This returns the current constant expression with the operands replaced with the specified values.
LLVM_ABI Instruction * getAsInstruction() const
Returns an Instruction which implements the same operation as this ConstantExpr.
ConstantFP - Floating Point Values [float, double].
static LLVM_ABI Constant * getSNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
static LLVM_ABI Constant * getInfinity(Type *Ty, bool Negative=false)
static LLVM_ABI Constant * getZero(Type *Ty, bool Negative=false)
static LLVM_ABI Constant * getNaN(Type *Ty, bool Negative=false, uint64_t Payload=0)
LLVM_ABI bool isExactlyValue(const APFloat &V) const
We don't rely on operator== working on double values, as it returns true for things that are clearly ...
static LLVM_ABI bool isValueValidForType(Type *Ty, const APFloat &V)
Return true if Ty is big enough to represent V.
static LLVM_ABI Constant * getQNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
This is the shared class of boolean and integer constants.
static LLVM_ABI bool isValueValidForType(Type *Ty, uint64_t V)
This static method returns true if the type Ty is big enough to represent the value V.
static LLVM_ABI ConstantInt * getTrue(LLVMContext &Context)
static LLVM_ABI ConstantInt * getFalse(LLVMContext &Context)
unsigned getBitWidth() const
getBitWidth - Return the scalar bitwidth of this constant.
static LLVM_ABI ConstantInt * getBool(LLVMContext &Context, bool V)
A constant pointer value that points to null.
static LLVM_ABI ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
PointerType * getType() const
Specialize the getType() method to always return an PointerType, which reduces the amount of casting ...
A signed pointer, in the ptrauth sense.
Constant * getAddrDiscriminator() const
The address discriminator if any, or the null constant.
LLVM_ABI bool isKnownCompatibleWith(const Value *Key, const Value *Discriminator, const DataLayout &DL) const
Check whether an authentication operation with key Key and (possibly blended) discriminator Discrimin...
LLVM_ABI bool hasSpecialAddressDiscriminator(uint64_t Value) const
Whether the address uses a special address discriminator.
static LLVM_ABI ConstantPtrAuth * get(Constant *Ptr, ConstantInt *Key, ConstantInt *Disc, Constant *AddrDisc)
Return a pointer signed with the specified parameters.
LLVM_ABI ConstantPtrAuth * getWithSameSchema(Constant *Pointer) const
Produce a new ptrauth expression signing the given value using the same schema as is stored in one.
ConstantInt * getKey() const
The Key ID, an i32 constant.
bool hasAddressDiscriminator() const
Whether there is any non-null address discriminator.
ConstantInt * getDiscriminator() const
The integer discriminator, an i64 constant, or 0.
This class represents a range of values.
LLVM_ABI ConstantRange unionWith(const ConstantRange &CR, PreferredRangeType Type=Smallest) const
Return the range that results from the union of this range with another range.
static LLVM_ABI Constant * get(StructType *T, ArrayRef< Constant * > V)
static LLVM_ABI StructType * getTypeForElements(ArrayRef< Constant * > V, bool Packed=false)
Return an anonymous struct type to use for a constant with the specified set of elements.
StructType * getType() const
Specialization - reduce amount of casting.
A constant target extension type default initializer.
static LLVM_ABI ConstantTargetNone * get(TargetExtType *T)
Static factory methods - Return objects of the specified value.
TargetExtType * getType() const
Specialize the getType() method to always return an TargetExtType, which reduces the amount of castin...
A constant token which is empty.
static LLVM_ABI ConstantTokenNone * get(LLVMContext &Context)
Return the ConstantTokenNone.
ConstantClass * getOrCreate(TypeClass *Ty, ValType V)
Return the specified constant from the map, creating it if necessary.
void remove(ConstantClass *CP)
Remove this constant from the map.
ConstantClass * replaceOperandsInPlace(ArrayRef< Constant * > Operands, ConstantClass *CP, Value *From, Constant *To, unsigned NumUpdated=0, unsigned OperandNo=~0u)
Constant Vector Declarations.
FixedVectorType * getType() const
Specialize the getType() method to always return a FixedVectorType, which reduces the amount of casti...
LLVM_ABI Constant * getSplatValue(bool AllowPoison=false) const
If all elements of the vector constant have the same value, return that value.
static LLVM_ABI Constant * getSplat(ElementCount EC, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
static LLVM_ABI Constant * get(ArrayRef< Constant * > V)
This is an important base class in LLVM.
static LLVM_ABI Constant * getIntegerValue(Type *Ty, const APInt &V)
Return the value for an integer or pointer constant, or a vector thereof, with the given scalar value...
LLVM_ABI bool hasExactInverseFP() const
Return true if this scalar has an exact multiplicative inverse or this vector has an exact multiplica...
static LLVM_ABI Constant * replaceUndefsWith(Constant *C, Constant *Replacement)
Try to replace undefined constant C or undefined elements in C with Replacement.
LLVM_ABI Constant * getSplatValue(bool AllowPoison=false) const
If all elements of the vector constant have the same value, return that value.
LLVM_ABI bool containsUndefElement() const
Return true if this is a vector constant that includes any strictly undef (not poison) elements.
static LLVM_ABI Constant * mergeUndefsWith(Constant *C, Constant *Other)
Merges undefs of a Constant with another Constant, along with the undefs already present.
LLVM_ABI ConstantRange toConstantRange() const
Convert constant to an approximate constant range.
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
LLVM_ABI bool hasZeroLiveUses() const
Return true if the constant has no live uses.
LLVM_ABI bool isOneValue() const
Returns true if the value is one.
LLVM_ABI bool isManifestConstant() const
Return true if a constant is ConstantData or a ConstantAggregate or ConstantExpr that contain only Co...
LLVM_ABI bool isNegativeZeroValue() const
Return true if the value is what would be returned by getZeroValueForNegation.
LLVM_ABI bool isAllOnesValue() const
Return true if this is the value that would be returned by getAllOnesValue.
LLVM_ABI bool hasOneLiveUse() const
Return true if the constant has exactly one live use.
LLVM_ABI bool needsRelocation() const
This method classifies the entry according to whether or not it may generate a relocation entry (eith...
LLVM_ABI bool isDLLImportDependent() const
Return true if the value is dependent on a dllimport variable.
LLVM_ABI const APInt & getUniqueInteger() const
If C is a constant integer then return its value, otherwise C must be a vector of constant integers,...
LLVM_ABI bool containsConstantExpression() const
Return true if this is a fixed width vector constant that includes any constant expressions.
LLVM_ABI bool isFiniteNonZeroFP() const
Return true if this is a finite and non-zero floating-point scalar constant or a fixed width vector c...
LLVM_ABI void removeDeadConstantUsers() const
If there are any dead constant users dangling off of this constant, remove them.
LLVM_ABI bool isNormalFP() const
Return true if this is a normal (as opposed to denormal, infinity, nan, or zero) floating-point scala...
LLVM_ABI bool needsDynamicRelocation() const
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
LLVM_ABI bool isNaN() const
Return true if this is a floating-point NaN constant or a vector floating-point constant with all NaN...
LLVM_ABI bool isMinSignedValue() const
Return true if the value is the smallest signed value.
LLVM_ABI bool isConstantUsed() const
Return true if the constant has users other than constant expressions and other dangling things.
LLVM_ABI Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
LLVM_ABI bool isThreadDependent() const
Return true if the value can vary between threads.
LLVM_ABI bool isZeroValue() const
Return true if the value is negative zero or null value.
LLVM_ABI void destroyConstant()
Called if some element of this constant is no longer valid.
LLVM_ABI bool isNotMinSignedValue() const
Return true if the value is not the smallest signed value, or, for vectors, does not contain smallest...
LLVM_ABI bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
LLVM_ABI bool isNotOneValue() const
Return true if the value is not the one value, or, for vectors, does not contain one value elements.
LLVM_ABI bool isElementWiseEqual(Value *Y) const
Return true if this constant and a constant 'Y' are element-wise equal.
LLVM_ABI bool containsUndefOrPoisonElement() const
Return true if this is a vector constant that includes any undef or poison elements.
LLVM_ABI bool containsPoisonElement() const
Return true if this is a vector constant that includes any poison elements.
LLVM_ABI void handleOperandChange(Value *, Value *)
This method is a special form of User::replaceUsesOfWith (which does not work on constants) that does...
Wrapper for a function that represents a value that functionally represents the original function.
GlobalValue * getGlobalValue() const
static LLVM_ABI DSOLocalEquivalent * get(GlobalValue *GV)
Return a DSOLocalEquivalent for the specified global value.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
static constexpr ElementCount getFixed(ScalarTy MinVal)
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
Represents flags for the getelementptr instruction/expression.
GetElementPtrConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
std::optional< ConstantRange > getInRange() const
Type * getResultElementType() const
Type * getSourceElementType() const
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
static Type * getGEPReturnType(Value *Ptr, ArrayRef< Value * > IdxList)
Returns the pointer type returned by the GEP instruction, which may be a vector of pointers.
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static LLVM_ABI Type * getIndexedType(Type *Ty, ArrayRef< Value * > IdxList)
Returns the result type of a getelementptr with the given source element type and indexes.
PointerType * getType() const
Global values are always pointers.
InsertElementConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
LLVM_ABI void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
LLVM_ABI void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.
LLVM_ABI bool isCommutative() const LLVM_READONLY
Return true if the instruction is commutative:
const char * getOpcodeName() const
LLVM_ABI void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag.
Class to represent integer types.
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
A wrapper class for inspecting calls to intrinsic functions.
DenseMap< unsigned, std::unique_ptr< ConstantInt > > IntOneConstants
DenseMap< unsigned, std::unique_ptr< ConstantInt > > IntZeroConstants
DenseMap< APFloat, std::unique_ptr< ConstantFP > > FPConstants
DenseMap< PointerType *, std::unique_ptr< ConstantPointerNull > > CPNConstants
DenseMap< Type *, std::unique_ptr< ConstantAggregateZero > > CAZConstants
ConstantInt * TheFalseVal
DenseMap< Type *, std::unique_ptr< PoisonValue > > PVConstants
DenseMap< APInt, std::unique_ptr< ConstantInt > > IntConstants
std::unique_ptr< ConstantTokenNone > TheNoneToken
VectorConstantsTy VectorConstants
DenseMap< const GlobalValue *, NoCFIValue * > NoCFIValues
DenseMap< const BasicBlock *, BlockAddress * > BlockAddresses
DenseMap< Type *, std::unique_ptr< UndefValue > > UVConstants
StringMap< std::unique_ptr< ConstantDataSequential > > CDSConstants
StructConstantsTy StructConstants
ConstantUniqueMap< ConstantPtrAuth > ConstantPtrAuths
DenseMap< TargetExtType *, std::unique_ptr< ConstantTargetNone > > CTNConstants
ConstantUniqueMap< ConstantExpr > ExprConstants
ArrayConstantsTy ArrayConstants
DenseMap< const GlobalValue *, DSOLocalEquivalent * > DSOLocalEquivalents
This is an important class for using LLVM in a threaded context.
LLVMContextImpl *const pImpl
Wrapper for a value that won't be replaced with a CFI jump table pointer in LowerTypeTestsModule.
static LLVM_ABI NoCFIValue * get(GlobalValue *GV)
Return a NoCFIValue for the specified function.
PointerType * getType() const
NoCFIValue is always a pointer.
GlobalValue * getGlobalValue() const
Class to represent pointers.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
In order to facilitate speculative execution, many instructions do not invoke immediate undefined beh...
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
LLVM_ABI PoisonValue * getStructElement(unsigned Elt) const
If this poison has struct type, return a poison with the right element type for the specified element...
LLVM_ABI PoisonValue * getSequentialElement() const
If this poison has array or vector type, return a poison with the right element type.
LLVM_ABI PoisonValue * getElementValue(Constant *C) const
Return an poison of the right value for the specified GEP index if we can, otherwise return null (e....
ShuffleVectorConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
This instruction constructs a fixed permutation of two input vectors.
static LLVM_ABI bool isValidOperands(const Value *V1, const Value *V2, const Value *Mask)
Return true if a shufflevector instruction can be formed with the specified operands.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
iterator find(StringRef Key)
StringRef - Represent a constant reference to a string, i.e.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Class to represent struct types.
static LLVM_ABI StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Class to represent target extensions types, which are generally unintrospectable from target-independ...
LLVM_ABI bool hasProperty(Property Prop) const
Returns true if the target extension type contains the given property.
@ HasZeroInit
zeroinitializer is valid for this target extension type.
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
bool isVectorTy() const
True if this is an instance of VectorType.
static LLVM_ABI Type * getDoubleTy(LLVMContext &C)
bool isArrayTy() const
True if this is an instance of ArrayType.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
bool isPointerTy() const
True if this is an instance of PointerType.
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
LLVM_ABI bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value.
@ HalfTyID
16-bit floating point type
@ TargetExtTyID
Target extension type.
@ ScalableVectorTyID
Scalable SIMD vector type.
@ FloatTyID
32-bit floating point type
@ IntegerTyID
Arbitrary bit width integers.
@ FixedVectorTyID
Fixed width SIMD vector type.
@ BFloatTyID
16-bit floating point type (7-bit significand)
@ DoubleTyID
64-bit floating point type
@ X86_FP80TyID
80-bit floating point type (X87)
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
@ FP128TyID
128-bit floating point type (112-bit significand)
static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
bool isStructTy() const
True if this is an instance of StructType.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
static LLVM_ABI IntegerType * getInt16Ty(LLVMContext &C)
LLVM_ABI const fltSemantics & getFltSemantics() const
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
bool isIntegerTy() const
True if this is an instance of IntegerType.
TypeID getTypeID() const
Return the type id for the type.
static LLVM_ABI Type * getFloatingPointTy(LLVMContext &C, const fltSemantics &S)
LLVM_ABI unsigned getStructNumElements() const
LLVM_ABI unsigned getIntegerBitWidth() const
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
'undef' values are things that do not have specified contents.
LLVM_ABI UndefValue * getElementValue(Constant *C) const
Return an undef of the right value for the specified GEP index if we can, otherwise return null (e....
LLVM_ABI UndefValue * getStructElement(unsigned Elt) const
If this undef has struct type, return a undef with the right element type for the specified element.
static LLVM_ABI UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
LLVM_ABI unsigned getNumElements() const
Return the number of elements in the array, vector, or struct.
LLVM_ABI UndefValue * getSequentialElement() const
If this Undef has array or vector type, return a undef with the right element type.
A Use represents the edge between a Value definition and its users.
const Use * getOperandList() const
void setOperand(unsigned i, Value *Val)
Value * getOperand(unsigned i) const
unsigned getNumOperands() const
iterator_range< value_op_iterator > operand_values()
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
user_iterator_impl< const User > const_user_iterator
user_iterator user_begin()
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
LLVM_ABI const Value * stripPointerCastsAndAliases() const
Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
LLVM_ABI const Value * stripInBoundsConstantOffsets() const
Strip off pointer casts and all-constant inbounds GEPs.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
iterator_range< user_iterator > users()
unsigned getValueID() const
Return an ID for the concrete type of this object.
LLVM_ABI const Value * stripAndAccumulateConstantOffsets(const DataLayout &DL, APInt &Offset, bool AllowNonInbounds, bool AllowInvariantGroup=false, function_ref< bool(Value &Value, APInt &Offset)> ExternalAnalysis=nullptr, bool LookThroughIntToPtr=false) const
Accumulate the constant offset this value has compared to a base pointer.
LLVM_ABI const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
iterator_range< use_iterator > uses()
void mutateType(Type *Ty)
Mutate the type of this Value to be of the specified type.
ValueTy
Concrete subclass of this.
Base class of all SIMD vector types.
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
static VectorType * getInteger(VectorType *VTy)
This static method gets a VectorType with the same number of elements as the input type,...
static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
Type * getElementType() const
An efficient, type-erasing, non-owning reference to a callable.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
bool match(Val *V, const Pattern &P)
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
auto m_Undef()
Match an arbitrary undef constant.
initializer< Ty > init(const Ty &Val)
NodeAddr< FuncNode * > Func
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI Constant * ConstantFoldCompareInstruction(CmpInst::Predicate Predicate, Constant *C1, Constant *C2)
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
gep_type_iterator gep_type_end(const User *GEP)
void deleteConstant(Constant *C)
LLVM_ABI Constant * ConstantFoldGetElementPtr(Type *Ty, Constant *C, std::optional< ConstantRange > InRange, ArrayRef< Value * > Idxs)
LLVM_ABI Constant * ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt, Constant *Idx)
Attempt to constant fold an insertelement instruction with the specified operands and indices.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI Constant * ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx)
Attempt to constant fold an extractelement instruction with the specified operands and indices.
OutputIt copy(R &&Range, OutputIt Out)
constexpr unsigned BitWidth
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
gep_type_iterator gep_type_begin(const User *GEP)
constexpr bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
LLVM_ABI Constant * ConstantFoldCastInstruction(unsigned opcode, Constant *V, Type *DestTy)
LLVM_ABI Constant * ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2, ArrayRef< int > Mask)
Attempt to constant fold a shufflevector instruction with the specified operands and mask.
LLVM_ABI Constant * ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1, Constant *V2)
Implement std::hash so that hash_code can be used in STL containers.
static LLVM_ABI const fltSemantics & IEEEsingle() LLVM_READNONE
static constexpr roundingMode rmNearestTiesToEven
static LLVM_ABI const fltSemantics & PPCDoubleDouble() LLVM_READNONE
static LLVM_ABI const fltSemantics & x87DoubleExtended() LLVM_READNONE
static LLVM_ABI const fltSemantics & IEEEquad() LLVM_READNONE
static LLVM_ABI const fltSemantics & IEEEdouble() LLVM_READNONE
static LLVM_ABI const fltSemantics & IEEEhalf() LLVM_READNONE
static LLVM_ABI const fltSemantics & BFloat() LLVM_READNONE
Summary of memprof metadata on allocations.
Information about how a User object was allocated, to be passed into the User constructor.