Go to the documentation of this file.
36 using namespace PatternMatch;
44 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
45 return CFP->isZero() && CFP->isNegative();
49 if (
const auto *SplatCFP = dyn_cast_or_null<ConstantFP>(
getSplatValue()))
50 return SplatCFP->isNegativeZeroValue();
53 if (
getType()->isFPOrFPVectorTy())
64 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
69 if (
const auto *SplatCFP = dyn_cast_or_null<ConstantFP>(
getSplatValue()))
70 return SplatCFP->isZero();
78 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
82 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
85 return CFP->isExactlyValue(+0.0);
89 return isa<ConstantAggregateZero>(
this) || isa<ConstantPointerNull>(
this) ||
90 isa<ConstantTokenNone>(
this) || isa<ConstantTargetNone>(
this);
95 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
96 return CI->isMinusOne();
99 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
100 return CFP->getValueAPF().bitcastToAPInt().isAllOnes();
105 return SplatVal->isAllOnesValue();
112 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
116 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
117 return CFP->getValueAPF().bitcastToAPInt().isOne();
122 return SplatVal->isOneValue();
129 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
130 return !CI->isOneValue();
133 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
134 return !CFP->getValueAPF().bitcastToAPInt().isOne();
137 if (
auto *VTy = dyn_cast<FixedVectorType>(
getType())) {
138 for (
unsigned I = 0,
E = VTy->getNumElements();
I !=
E; ++
I) {
149 return SplatVal->isNotOneValue();
157 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
158 return CI->isMinValue(
true);
161 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
162 return CFP->getValueAPF().bitcastToAPInt().isMinSignedValue();
167 return SplatVal->isMinSignedValue();
174 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
175 return !CI->isMinValue(
true);
178 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
179 return !CFP->getValueAPF().bitcastToAPInt().isMinSignedValue();
182 if (
auto *VTy = dyn_cast<FixedVectorType>(
getType())) {
183 for (
unsigned I = 0,
E = VTy->getNumElements();
I !=
E; ++
I) {
194 return SplatVal->isNotMinSignedValue();
201 if (
auto *CFP = dyn_cast<ConstantFP>(
this))
202 return CFP->getValueAPF().isFiniteNonZero();
204 if (
auto *VTy = dyn_cast<FixedVectorType>(
getType())) {
205 for (
unsigned I = 0,
E = VTy->getNumElements();
I !=
E; ++
I) {
206 auto *CFP = dyn_cast_or_null<ConstantFP>(getAggregateElement(
I));
207 if (!CFP || !CFP->getValueAPF().isFiniteNonZero())
214 if (
const auto *SplatCFP = dyn_cast_or_null<ConstantFP>(
getSplatValue()))
215 return SplatCFP->isFiniteNonZeroFP();
222 if (
auto *CFP = dyn_cast<ConstantFP>(
this))
223 return CFP->getValueAPF().isNormal();
225 if (
auto *VTy = dyn_cast<FixedVectorType>(
getType())) {
226 for (
unsigned I = 0,
E = VTy->getNumElements();
I !=
E; ++
I) {
227 auto *CFP = dyn_cast_or_null<ConstantFP>(getAggregateElement(
I));
228 if (!CFP || !CFP->getValueAPF().isNormal())
235 if (
const auto *SplatCFP = dyn_cast_or_null<ConstantFP>(
getSplatValue()))
236 return SplatCFP->isNormalFP();
243 if (
auto *CFP = dyn_cast<ConstantFP>(
this))
244 return CFP->getValueAPF().getExactInverse(
nullptr);
246 if (
auto *VTy = dyn_cast<FixedVectorType>(
getType())) {
247 for (
unsigned I = 0,
E = VTy->getNumElements();
I !=
E; ++
I) {
248 auto *CFP = dyn_cast_or_null<ConstantFP>(getAggregateElement(
I));
249 if (!CFP || !CFP->getValueAPF().getExactInverse(
nullptr))
256 if (
const auto *SplatCFP = dyn_cast_or_null<ConstantFP>(
getSplatValue()))
257 return SplatCFP->hasExactInverseFP();
264 if (
auto *CFP = dyn_cast<ConstantFP>(
this))
267 if (
auto *VTy = dyn_cast<FixedVectorType>(
getType())) {
268 for (
unsigned I = 0,
E = VTy->getNumElements();
I !=
E; ++
I) {
269 auto *CFP = dyn_cast_or_null<ConstantFP>(getAggregateElement(
I));
270 if (!CFP || !CFP->isNaN())
277 if (
const auto *SplatCFP = dyn_cast_or_null<ConstantFP>(
getSplatValue()))
278 return SplatCFP->isNaN();
290 auto *VTy = dyn_cast<VectorType>(
getType());
291 if (!isa<Constant>(
Y) || !VTy || VTy !=
Y->getType())
295 if (!(VTy->getElementType()->isIntegerTy() ||
296 VTy->getElementType()->isFloatingPointTy()))
305 return isa<UndefValue>(CmpEq) ||
match(CmpEq,
m_One());
311 if (
auto *VTy = dyn_cast<VectorType>(
C->getType())) {
314 if (isa<ConstantAggregateZero>(
C))
316 if (isa<ScalableVectorType>(
C->getType()))
319 for (
unsigned i = 0,
e = cast<FixedVectorType>(VTy)->getNumElements();
332 this, [&](
const auto *
C) {
return isa<UndefValue>(
C); });
337 this, [&](
const auto *
C) {
return isa<PoisonValue>(
C); });
342 return isa<UndefValue>(
C) && !isa<PoisonValue>(
C);
347 if (
auto *VTy = dyn_cast<FixedVectorType>(
getType())) {
348 for (
unsigned i = 0,
e = VTy->getNumElements();
i !=
e; ++
i)
349 if (isa<ConstantExpr>(getAggregateElement(
i)))
393 if (
PointerType *PTy = dyn_cast<PointerType>(ScalarTy))
397 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
420 "Must be an aggregate/vector constant");
422 if (
const auto *
CC = dyn_cast<ConstantAggregate>(
this))
423 return Elt <
CC->getNumOperands() ?
CC->getOperand(Elt) :
nullptr;
425 if (
const auto *CAZ = dyn_cast<ConstantAggregateZero>(
this))
426 return Elt < CAZ->getElementCount().getKnownMinValue()
427 ? CAZ->getElementValue(Elt)
431 if (isa<ScalableVectorType>(
getType()))
434 if (
const auto *PV = dyn_cast<PoisonValue>(
this))
435 return Elt < PV->getNumElements() ? PV->getElementValue(Elt) :
nullptr;
437 if (
const auto *UV = dyn_cast<UndefValue>(
this))
438 return Elt < UV->getNumElements() ? UV->getElementValue(Elt) :
nullptr;
440 if (
const auto *CDS = dyn_cast<ConstantDataSequential>(
this))
441 return Elt < CDS->getNumElements() ? CDS->getElementAsConstant(Elt)
448 assert(isa<IntegerType>(Elt->
getType()) &&
"Index must be an integer");
449 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Elt)) {
451 if (CI->getValue().getActiveBits() > 64)
453 return getAggregateElement(CI->getZExtValue());
461 switch (getValueID()) {
464 #define HANDLE_CONSTANT(Name) \
465 case Value::Name##Val: \
466 cast<Name>(this)->destroyConstantImpl(); \
468 #include "llvm/IR/Value.def"
478 while (!use_empty()) {
479 Value *V = user_back();
480 #ifndef NDEBUG // Only in -g mode...
481 if (!isa<Constant>(V)) {
482 dbgs() <<
"While deleting: " << *
this
483 <<
"\n\nUse still stuck around after Def is destroyed: " << *V
487 assert(isa<Constant>(V) &&
"References remain to Constant being destroyed");
488 cast<Constant>(V)->destroyConstant();
491 assert((use_empty() || user_back() != V) &&
"Constant not removed!");
499 switch (
C->getValueID()) {
500 case Constant::ConstantIntVal:
503 case Constant::ConstantFPVal:
506 case Constant::ConstantAggregateZeroVal:
509 case Constant::ConstantArrayVal:
512 case Constant::ConstantStructVal:
515 case Constant::ConstantVectorVal:
518 case Constant::ConstantPointerNullVal:
521 case Constant::ConstantDataArrayVal:
524 case Constant::ConstantDataVectorVal:
527 case Constant::ConstantTokenNoneVal:
530 case Constant::BlockAddressVal:
533 case Constant::DSOLocalEquivalentVal:
536 case Constant::NoCFIValueVal:
539 case Constant::UndefValueVal:
542 case Constant::PoisonValueVal:
545 case Constant::ConstantExprVal:
546 if (isa<CastConstantExpr>(
C))
548 else if (isa<BinaryConstantExpr>(
C))
550 else if (isa<SelectConstantExpr>(
C))
552 else if (isa<ExtractElementConstantExpr>(
C))
554 else if (isa<InsertElementConstantExpr>(
C))
556 else if (isa<ShuffleVectorConstantExpr>(
C))
558 else if (isa<GetElementPtrConstantExpr>(
C))
560 else if (isa<CompareConstantExpr>(
C))
576 WorkList.push_back(
C);
579 while (!WorkList.empty()) {
581 if (
const auto *GV = dyn_cast<GlobalValue>(WorkItem))
585 const Constant *ConstOp = dyn_cast<Constant>(
Op);
588 if (Visited.
insert(ConstOp).second)
589 WorkList.push_back(ConstOp);
596 auto DLLImportPredicate = [](
const GlobalValue *GV) {
597 return GV->isThreadLocal();
603 auto DLLImportPredicate = [](
const GlobalValue *GV) {
604 return GV->hasDLLImportStorageClass();
611 const Constant *UC = dyn_cast<Constant>(U);
612 if (!UC || isa<GlobalValue>(UC))
622 return getRelocationInfo() == GlobalRelocation;
626 return getRelocationInfo() != NoRelocation;
629 Constant::PossibleRelocationsTy Constant::getRelocationInfo()
const {
630 if (isa<GlobalValue>(
this))
631 return GlobalRelocation;
633 if (
const BlockAddress *BA = dyn_cast<BlockAddress>(
this))
634 return BA->getFunction()->getRelocationInfo();
636 if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(
this)) {
637 if (CE->getOpcode() == Instruction::Sub) {
640 if (
LHS &&
RHS &&
LHS->getOpcode() == Instruction::PtrToInt &&
641 RHS->getOpcode() == Instruction::PtrToInt) {
649 if (isa<BlockAddress>(LHSOp0) && isa<BlockAddress>(RHSOp0) &&
658 if (
auto *LHSGV = dyn_cast<GlobalValue>(
LHS)) {
659 if (LHSGV->isDSOLocal() && RHSGV->isDSOLocal())
660 return LocalRelocation;
661 }
else if (isa<DSOLocalEquivalent>(
LHS)) {
662 if (RHSGV->isDSOLocal())
663 return LocalRelocation;
670 PossibleRelocationsTy
Result = NoRelocation;
671 for (
unsigned i = 0,
e = getNumOperands();
i !=
e; ++
i)
673 std::max(cast<Constant>(getOperand(
i))->getRelocationInfo(), Result);
682 if (isa<GlobalValue>(
C))
return false;
687 if (!
User)
return false;
700 if (RemoveDeadUsers) {
704 const_cast<Constant *
>(
C)->destroyConstant();
730 if (LastNonDeadUser ==
E)
733 I = std::next(LastNonDeadUser);
741 bool Constant::hasNLiveUses(
unsigned N)
const {
742 unsigned NumUses = 0;
756 assert(
C && Replacement &&
"Expected non-nullptr constant arguments");
757 Type *Ty =
C->getType();
759 assert(Ty == Replacement->
getType() &&
"Expected matching types");
764 auto *VTy = dyn_cast<FixedVectorType>(Ty);
768 unsigned NumElts = VTy->getNumElements();
770 for (
unsigned i = 0;
i != NumElts; ++
i) {
773 "Expected matching types");
774 NewC[
i] = EltC &&
match(EltC,
m_Undef()) ? Replacement : EltC;
780 assert(
C &&
Other &&
"Expected non-nullptr constant arguments");
784 Type *Ty =
C->getType();
788 auto *VTy = dyn_cast<FixedVectorType>(Ty);
792 Type *EltTy = VTy->getElementType();
793 unsigned NumElts = VTy->getNumElements();
795 cast<FixedVectorType>(
Other->getType())->getNumElements() == NumElts &&
798 bool FoundExtraUndef =
false;
800 for (
unsigned I = 0;
I != NumElts; ++
I) {
801 NewC[
I] =
C->getAggregateElement(
I);
803 assert(NewC[
I] && OtherEltC &&
"Unknown vector element");
806 FoundExtraUndef =
true;
815 if (isa<ConstantData>(
this))
817 if (isa<ConstantAggregate>(
this) || isa<ConstantExpr>(
this)) {
818 for (
const Value *
Op : operand_values())
819 if (!cast<Constant>(
Op)->isManifestConstant())
856 if (
auto *VTy = dyn_cast<VectorType>(Ty))
864 if (
auto *VTy = dyn_cast<VectorType>(Ty))
877 std::unique_ptr<ConstantInt> &Slot = pImpl->
IntConstants[V];
891 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
902 return get(Ty, V,
true);
906 return get(Ty, V,
true);
912 "ConstantInt type doesn't match the type implied by its value!");
915 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
926 void ConstantInt::destroyConstantImpl() {
944 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
953 "ConstantFP type doesn't match the type implied by its value!");
956 if (
auto *VTy = dyn_cast<VectorType>(Ty))
969 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
980 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
991 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1002 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1013 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1031 std::unique_ptr<ConstantFP> &Slot = pImpl->
FPConstants[V];
1045 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1051 ConstantFP::ConstantFP(
Type *Ty,
const APFloat &V)
1054 "FP type Mismatch");
1062 void ConstantFP::destroyConstantImpl() {
1071 if (
auto *AT = dyn_cast<ArrayType>(
getType()))
1094 if (
auto *AT = dyn_cast<ArrayType>(Ty))
1096 if (
auto *VT = dyn_cast<VectorType>(Ty))
1097 return VT->getElementCount();
1129 if (
auto *AT = dyn_cast<ArrayType>(Ty))
1130 return AT->getNumElements();
1131 if (
auto *VT = dyn_cast<VectorType>(Ty))
1132 return cast<FixedVectorType>(VT)->getNumElements();
1166 template <
typename ItTy,
typename EltTy>
1168 for (; Start != End; ++Start)
1174 template <
typename SequentialTy,
typename ElementTy>
1176 assert(!V.
empty() &&
"Cannot get empty int sequence.");
1180 if (
auto *CI = dyn_cast<ConstantInt>(
C))
1181 Elts.push_back(CI->getZExtValue());
1187 template <
typename SequentialTy,
typename ElementTy>
1189 assert(!V.
empty() &&
"Cannot get empty FP sequence.");
1193 if (
auto *CFP = dyn_cast<ConstantFP>(
C))
1194 Elts.push_back(CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
1197 return SequentialTy::getFP(V[0]->
getType(), Elts);
1200 template <
typename SequenceTy>
1207 if (CI->getType()->isIntegerTy(8))
1208 return getIntSequenceIfElementsMatch<SequenceTy, uint8_t>(V);
1209 else if (CI->getType()->isIntegerTy(16))
1210 return getIntSequenceIfElementsMatch<SequenceTy, uint16_t>(V);
1211 else if (CI->getType()->isIntegerTy(32))
1212 return getIntSequenceIfElementsMatch<SequenceTy, uint32_t>(V);
1213 else if (CI->getType()->isIntegerTy(64))
1214 return getIntSequenceIfElementsMatch<SequenceTy, uint64_t>(V);
1215 }
else if (
ConstantFP *CFP = dyn_cast<ConstantFP>(
C)) {
1216 if (CFP->getType()->isHalfTy() || CFP->getType()->isBFloatTy())
1217 return getFPSequenceIfElementsMatch<SequenceTy, uint16_t>(V);
1218 else if (CFP->getType()->isFloatTy())
1219 return getFPSequenceIfElementsMatch<SequenceTy, uint32_t>(V);
1220 else if (CFP->getType()->isDoubleTy())
1221 return getFPSequenceIfElementsMatch<SequenceTy, uint64_t>(V);
1234 if (
auto *
ST = dyn_cast<StructType>(
T)) {
1237 for (
unsigned I = 0,
E = V.
size();
I !=
E; ++
I)
1239 "Initializer for struct element doesn't match!");
1246 "Invalid initializer for constant array");
1262 "Wrong type in array element initializer");
1282 return getSequenceIfElementsMatch<ConstantDataArray>(
C, V);
1303 "ConstantStruct::getTypeForElements cannot be called on empty list");
1309 assert((
T->isOpaque() || V.
size() ==
T->getNumElements()) &&
1310 "Invalid initializer for constant struct");
1316 "Incorrect # elements specified to ConstantStruct::get");
1321 bool isPoison =
false;
1324 isUndef = isa<UndefValue>(V[0]);
1325 isPoison = isa<PoisonValue>(V[0]);
1326 isZero = V[0]->isNullValue();
1330 if (!
C->isNullValue())
1332 if (!isa<PoisonValue>(
C))
1334 if (isa<PoisonValue>(
C) || !isa<UndefValue>(
C))
1346 return ST->getContext().pImpl->StructConstants.getOrCreate(
ST, V);
1351 assert(V.
size() == cast<FixedVectorType>(
T)->getNumElements() &&
1352 "Invalid initializer for constant vector");
1370 bool isZero =
C->isNullValue();
1372 bool isPoison = isa<PoisonValue>(
C);
1375 for (
unsigned i = 1,
e = V.
size();
i !=
e; ++
i)
1392 return getSequenceIfElementsMatch<ConstantDataVector>(
C, V);
1400 if (!EC.isScalable()) {
1403 if ((isa<ConstantFP>(V) || isa<ConstantInt>(V)) &&
1415 else if (isa<UndefValue>(V))
1437 void ConstantTokenNone::destroyConstantImpl() {
1453 return cast<CompareConstantExpr>(
this)->predicate;
1457 return cast<ShuffleVectorConstantExpr>(
this)->ShuffleMask;
1461 return cast<ShuffleVectorConstantExpr>(
this)->ShuffleMaskForBitcode;
1465 bool OnlyIfReduced,
Type *SrcTy)
const {
1472 Type *OnlyIfReducedTy = OnlyIfReduced ? Ty :
nullptr;
1474 case Instruction::Trunc:
1475 case Instruction::ZExt:
1476 case Instruction::SExt:
1477 case Instruction::FPTrunc:
1478 case Instruction::FPExt:
1479 case Instruction::UIToFP:
1480 case Instruction::SIToFP:
1481 case Instruction::FPToUI:
1482 case Instruction::FPToSI:
1483 case Instruction::PtrToInt:
1484 case Instruction::IntToPtr:
1485 case Instruction::BitCast:
1486 case Instruction::AddrSpaceCast:
1490 case Instruction::InsertElement:
1493 case Instruction::ExtractElement:
1495 case Instruction::ShuffleVector:
1498 case Instruction::GetElementPtr: {
1499 auto *GEPO = cast<GEPOperator>(
this);
1502 SrcTy ? SrcTy : GEPO->getSourceElementType(), Ops[0], Ops.
slice(1),
1503 GEPO->isInBounds(), GEPO->getInRangeIndex(), OnlyIfReducedTy);
1505 case Instruction::ICmp:
1506 case Instruction::FCmp:
1523 return Val == 0 || Val == 1;
1530 return Val == 0 || Val == 1 || Val == -1;
1531 return isIntN(NumBits, Val);
1597 "Cannot create an aggregate zero of non-aggregate type!");
1599 std::unique_ptr<ConstantAggregateZero> &Entry =
1608 void ConstantAggregateZero::destroyConstantImpl() {
1613 void ConstantArray::destroyConstantImpl() {
1622 void ConstantStruct::destroyConstantImpl() {
1627 void ConstantVector::destroyConstantImpl() {
1632 assert(this->
getType()->isVectorTy() &&
"Only valid for vectors!");
1633 if (isa<ConstantAggregateZero>(
this))
1636 return CV->getSplatValue();
1638 return CV->getSplatValue(AllowUndefs);
1642 const auto *Shuf = dyn_cast<ConstantExpr>(
this);
1643 if (Shuf && Shuf->getOpcode() == Instruction::ShuffleVector &&
1644 isa<UndefValue>(Shuf->getOperand(1))) {
1646 const auto *IElt = dyn_cast<ConstantExpr>(Shuf->getOperand(0));
1647 if (IElt && IElt->getOpcode() == Instruction::InsertElement &&
1648 isa<UndefValue>(IElt->getOperand(0))) {
1677 if (isa<UndefValue>(OpC))
1681 if (isa<UndefValue>(Elt))
1691 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
1692 return CI->getValue();
1694 if (isa<ConstantExpr>(
this))
1695 return cast<ConstantInt>(this->
getSplatValue())->getValue();
1700 assert(
C && isa<ConstantInt>(
C) &&
"Not a vector of numbers!");
1701 return cast<ConstantInt>(
C)->getValue();
1708 std::unique_ptr<ConstantPointerNull> &Entry =
1717 void ConstantPointerNull::destroyConstantImpl() {
1726 "Target extension type not allowed to have a zeroinitializer");
1727 std::unique_ptr<ConstantTargetNone> &Entry =
1736 void ConstantTargetNone::destroyConstantImpl() {
1749 void UndefValue::destroyConstantImpl() {
1768 void PoisonValue::destroyConstantImpl() {
1774 assert(
BB->getParent() &&
"Block must have a parent");
1775 return get(
BB->getParent(),
BB);
1780 F->getContext().pImpl->BlockAddresses[std::make_pair(
F,
BB)];
1790 Value::BlockAddressVal, &
Op<0>(), 2) {
1793 BB->AdjustBlockAddressRefCount(1);
1797 if (!
BB->hasAddressTaken())
1801 assert(
F &&
"Block must have a parent");
1803 F->getContext().pImpl->BlockAddresses.lookup(std::make_pair(
F,
BB));
1804 assert(BA &&
"Refcount and block address map disagree!");
1809 void BlockAddress::destroyConstantImpl() {
1824 assert(
From == NewBB &&
"From does not match any operand");
1825 NewBB = cast<BasicBlock>(To);
1857 "DSOLocalFunction does not match the expected global value");
1861 DSOLocalEquivalent::DSOLocalEquivalent(
GlobalValue *GV)
1867 void DSOLocalEquivalent::destroyConstantImpl() {
1874 assert(isa<Constant>(To) &&
"Can only replace the operands with a constant");
1877 if (
const auto *ToObj = dyn_cast<GlobalValue>(To)) {
1914 assert(
NC->getGlobalValue() == GV &&
1915 "NoCFIValue does not match the expected global value");
1925 void NoCFIValue::destroyConstantImpl() {
1934 assert(GV &&
"Can only replace the operands with a global value");
1956 bool OnlyIfReduced =
false) {
1974 bool OnlyIfReduced) {
1977 assert(
C && Ty &&
"Null arguments to getCast");
1983 case Instruction::Trunc:
1985 case Instruction::ZExt:
1986 return getZExt(
C, Ty, OnlyIfReduced);
1987 case Instruction::SExt:
1988 return getSExt(
C, Ty, OnlyIfReduced);
1989 case Instruction::FPTrunc:
1991 case Instruction::FPExt:
1993 case Instruction::UIToFP:
1995 case Instruction::SIToFP:
1997 case Instruction::FPToUI:
1999 case Instruction::FPToSI:
2001 case Instruction::PtrToInt:
2003 case Instruction::IntToPtr:
2005 case Instruction::BitCast:
2007 case Instruction::AddrSpaceCast:
2032 "Can only sign extend/truncate integers!");
2033 Type *CTy =
C->getType();
2042 assert(
S->getType()->isPtrOrPtrVectorTy() &&
"Invalid cast");
2049 unsigned SrcAS =
S->getType()->getPointerAddressSpace();
2058 assert(
S->getType()->isPtrOrPtrVectorTy() &&
"Invalid cast");
2068 assert(
C->getType()->isIntOrIntVectorTy() &&
2070 unsigned SrcBits =
C->getType()->getScalarSizeInBits();
2073 (SrcBits == DstBits ? Instruction::BitCast :
2074 (SrcBits > DstBits ? Instruction::Trunc :
2075 (
isSigned ? Instruction::SExt : Instruction::ZExt)));
2082 unsigned SrcBits =
C->getType()->getScalarSizeInBits();
2084 if (SrcBits == DstBits)
2087 (SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt);
2093 bool fromVec = isa<VectorType>(
C->getType());
2094 bool toVec = isa<VectorType>(Ty);
2096 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2097 assert(
C->getType()->isIntOrIntVectorTy() &&
"Trunc operand must be integer");
2100 "SrcTy must be larger than DestTy for Trunc!");
2107 bool fromVec = isa<VectorType>(
C->getType());
2108 bool toVec = isa<VectorType>(Ty);
2110 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2111 assert(
C->getType()->isIntOrIntVectorTy() &&
"SExt operand must be integral");
2114 "SrcTy must be smaller than DestTy for SExt!");
2121 bool fromVec = isa<VectorType>(
C->getType());
2122 bool toVec = isa<VectorType>(Ty);
2124 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2125 assert(
C->getType()->isIntOrIntVectorTy() &&
"ZEXt operand must be integral");
2128 "SrcTy must be smaller than DestTy for ZExt!");
2135 bool fromVec = isa<VectorType>(
C->getType());
2136 bool toVec = isa<VectorType>(Ty);
2138 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2141 "This is an illegal floating point truncation!");
2142 return getFoldedCast(Instruction::FPTrunc,
C, Ty, OnlyIfReduced);
2147 bool fromVec = isa<VectorType>(
C->getType());
2148 bool toVec = isa<VectorType>(Ty);
2150 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2153 "This is an illegal floating point extension!");
2159 bool fromVec = isa<VectorType>(
C->getType());
2160 bool toVec = isa<VectorType>(Ty);
2162 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2164 "This is an illegal uint to floating point cast!");
2170 bool fromVec = isa<VectorType>(
C->getType());
2171 bool toVec = isa<VectorType>(Ty);
2173 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2175 "This is an illegal sint to floating point cast!");
2181 bool fromVec = isa<VectorType>(
C->getType());
2182 bool toVec = isa<VectorType>(Ty);
2184 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2186 "This is an illegal floating point to uint cast!");
2192 bool fromVec = isa<VectorType>(
C->getType());
2193 bool toVec = isa<VectorType>(Ty);
2195 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2197 "This is an illegal floating point to sint cast!");
2202 bool OnlyIfReduced) {
2203 assert(
C->getType()->isPtrOrPtrVectorTy() &&
2204 "PtrToInt source must be pointer or pointer vector");
2206 "PtrToInt destination must be integer or integer vector");
2207 assert(isa<VectorType>(
C->getType()) == isa<VectorType>(DstTy));
2208 if (isa<VectorType>(
C->getType()))
2209 assert(cast<VectorType>(
C->getType())->getElementCount() ==
2210 cast<VectorType>(DstTy)->getElementCount() &&
2211 "Invalid cast between a different number of vector elements");
2212 return getFoldedCast(Instruction::PtrToInt,
C, DstTy, OnlyIfReduced);
2216 bool OnlyIfReduced) {
2217 assert(
C->getType()->isIntOrIntVectorTy() &&
2218 "IntToPtr source must be integer or integer vector");
2220 "IntToPtr destination must be a pointer or pointer vector");
2221 assert(isa<VectorType>(
C->getType()) == isa<VectorType>(DstTy));
2222 if (isa<VectorType>(
C->getType()))
2223 assert(cast<VectorType>(
C->getType())->getElementCount() ==
2224 cast<VectorType>(DstTy)->getElementCount() &&
2225 "Invalid cast between a different number of vector elements");
2226 return getFoldedCast(Instruction::IntToPtr,
C, DstTy, OnlyIfReduced);
2230 bool OnlyIfReduced) {
2232 "Invalid constantexpr bitcast!");
2236 if (
C->getType() == DstTy)
return C;
2238 return getFoldedCast(Instruction::BitCast,
C, DstTy, OnlyIfReduced);
2242 bool OnlyIfReduced) {
2244 "Invalid constantexpr addrspacecast!");
2248 PointerType *SrcScalarTy = cast<PointerType>(
C->getType()->getScalarType());
2253 if (
VectorType *VT = dyn_cast<VectorType>(DstTy)) {
2256 cast<FixedVectorType>(VT)->getNumElements());
2260 return getFoldedCast(Instruction::AddrSpaceCast,
C, DstTy, OnlyIfReduced);
2264 unsigned Flags,
Type *OnlyIfReducedTy) {
2267 "Invalid opcode in binary constant expression");
2269 "Binop not supported as constant expression");
2271 "Operand types in binary constant expression should match");
2276 case Instruction::Sub:
2278 case Instruction::UDiv:
2279 case Instruction::SDiv:
2280 case Instruction::URem:
2281 case Instruction::SRem:
2282 assert(
C1->getType()->isIntOrIntVectorTy() &&
2283 "Tried to create an integer operation on a non-integer type!");
2285 case Instruction::FAdd:
2286 case Instruction::FSub:
2287 case Instruction::FMul:
2288 case Instruction::FDiv:
2289 case Instruction::FRem:
2290 assert(
C1->getType()->isFPOrFPVectorTy() &&
2291 "Tried to create a floating-point operation on a "
2292 "non-floating-point type!");
2294 case Instruction::And:
2295 case Instruction::Or:
2296 case Instruction::Xor:
2297 assert(
C1->getType()->isIntOrIntVectorTy() &&
2298 "Tried to create a logical operation on a non-integral type!");
2300 case Instruction::Shl:
2301 case Instruction::LShr:
2302 case Instruction::AShr:
2303 assert(
C1->getType()->isIntOrIntVectorTy() &&
2304 "Tried to create a shift operation on a non-integer type!");
2314 if (OnlyIfReducedTy ==
C1->getType())
2326 case Instruction::UDiv:
2327 case Instruction::SDiv:
2328 case Instruction::URem:
2329 case Instruction::SRem:
2330 case Instruction::FAdd:
2331 case Instruction::FSub:
2332 case Instruction::FMul:
2333 case Instruction::FDiv:
2334 case Instruction::FRem:
2337 case Instruction::Sub:
2339 case Instruction::Shl:
2340 case Instruction::LShr:
2341 case Instruction::AShr:
2342 case Instruction::And:
2343 case Instruction::Or:
2344 case Instruction::Xor:
2353 case Instruction::UDiv:
2354 case Instruction::SDiv:
2355 case Instruction::URem:
2356 case Instruction::SRem:
2357 case Instruction::FAdd:
2358 case Instruction::FSub:
2359 case Instruction::FMul:
2360 case Instruction::FDiv:
2361 case Instruction::FRem:
2364 case Instruction::Sub:
2366 case Instruction::Shl:
2367 case Instruction::LShr:
2368 case Instruction::AShr:
2369 case Instruction::And:
2370 case Instruction::Or:
2371 case Instruction::Xor:
2395 Constant *Indices[2] = { Zero, One };
2420 Constant *C2,
bool OnlyIfReduced) {
2421 assert(
C1->getType() == C2->
getType() &&
"Op types should be identical!");
2442 Type *OnlyIfReducedTy) {
2448 if (OnlyIfReducedTy == V1->
getType())
2460 std::optional<unsigned> InRangeIndex,
2461 Type *OnlyIfReducedTy) {
2462 PointerType *OrigPtrTy = cast<PointerType>(
C->getType()->getScalarType());
2463 assert(Ty &&
"Must specify element type");
2472 assert(DestTy &&
"GEP indices invalid!");
2479 if (
VectorType *VecTy = dyn_cast<VectorType>(
C->getType()))
2480 EltCount = VecTy->getElementCount();
2482 for (
auto *Idx : Idxs)
2483 if (
VectorType *VecTy = dyn_cast<VectorType>(Idx->getType()))
2484 EltCount = VecTy->getElementCount();
2486 if (EltCount.isNonZero())
2489 if (OnlyIfReducedTy == ReqTy)
2493 std::vector<Constant*> ArgVec;
2494 ArgVec.reserve(1 + Idxs.size());
2495 ArgVec.push_back(
C);
2497 for (; GTI != GTE; ++GTI) {
2498 auto *Idx = cast<Constant>(GTI.getOperand());
2500 (!isa<VectorType>(Idx->getType()) ||
2501 cast<VectorType>(Idx->getType())->getElementCount() == EltCount) &&
2502 "getelementptr index type missmatch");
2504 if (GTI.isStruct() && Idx->getType()->isVectorTy()) {
2505 Idx = Idx->getSplatValue();
2506 }
else if (GTI.isSequential() && EltCount.isNonZero() &&
2507 !Idx->getType()->isVectorTy()) {
2510 ArgVec.push_back(Idx);
2513 unsigned SubClassOptionalData = InBounds ? GEPOperator::IsInBounds : 0;
2514 if (InRangeIndex && *InRangeIndex < 63)
2515 SubClassOptionalData |= (*InRangeIndex + 1) << 1;
2517 SubClassOptionalData, std::nullopt, Ty);
2574 Type *OnlyIfReducedTy) {
2576 "Tried to create extractelement operation on non-vector type!");
2578 "Extractelement index must be an integer type!");
2583 Type *ReqTy = cast<VectorType>(Val->
getType())->getElementType();
2584 if (OnlyIfReducedTy == ReqTy)
2598 "Tried to create insertelement operation on non-vector type!");
2600 "Insertelement types must match!");
2602 "Insertelement index must be i32 type!");
2607 if (OnlyIfReducedTy == Val->
getType())
2611 Constant *ArgVec[] = { Val, Elt, Idx };
2620 Type *OnlyIfReducedTy) {
2622 "Invalid shuffle vector constant expr operands!");
2627 unsigned NElts =
Mask.size();
2628 auto V1VTy = cast<VectorType>(V1->
getType());
2629 Type *EltTy = V1VTy->getElementType();
2630 bool TypeIsScalable = isa<ScalableVectorType>(V1VTy);
2633 if (OnlyIfReducedTy == ShufTy)
2645 assert(
C->getType()->isIntOrIntVectorTy() &&
2646 "Cannot NEG a nonintegral value!");
2652 assert(
C->getType()->isIntOrIntVectorTy() &&
2653 "Cannot NOT a nonintegral value!");
2658 bool HasNUW,
bool HasNSW) {
2665 bool HasNUW,
bool HasNSW) {
2668 return get(Instruction::Sub,
C1, C2, Flags);
2672 bool HasNUW,
bool HasNSW) {
2679 return get(Instruction::And,
C1, C2);
2683 return get(Instruction::Or,
C1, C2);
2687 return get(Instruction::Xor,
C1, C2);
2696 bool HasNUW,
bool HasNSW) {
2699 return get(Instruction::Shl,
C1, C2, Flags);
2703 return get(Instruction::LShr,
C1, C2,
2708 return get(Instruction::AShr,
C1, C2,
2713 Type *Ty =
C->getType();
2719 auto *VecTy = dyn_cast<FixedVectorType>(Ty);
2724 for (
unsigned I = 0,
E = VecTy->getNumElements();
I !=
E; ++
I) {
2729 if (isa<UndefValue>(Elt)) {
2742 bool AllowRHSConstant,
bool NSZ) {
2749 case Instruction::Or:
2750 case Instruction::Xor:
2754 case Instruction::And:
2756 case Instruction::FAdd:
2758 case Instruction::FMul:
2766 if (!AllowRHSConstant)
2770 case Instruction::Sub:
2771 case Instruction::Shl:
2772 case Instruction::LShr:
2773 case Instruction::AShr:
2774 case Instruction::FSub:
2776 case Instruction::SDiv:
2777 case Instruction::UDiv:
2779 case Instruction::FDiv:
2792 case Instruction::Or:
2795 case Instruction::And:
2802 void ConstantExpr::destroyConstantImpl() {
2810 GetElementPtrConstantExpr::GetElementPtrConstantExpr(
2814 (IdxList.
size() + 1),
2815 IdxList.
size() + 1),
2816 SrcElementTy(SrcElementTy),
2820 for (
unsigned i = 0,
E = IdxList.
size();
i !=
E; ++
i)
2821 OperandList[
i+1] = IdxList[
i];
2825 return SrcElementTy;
2829 return ResElementTy;
2837 return ATy->getElementType();
2838 return cast<VectorType>(
getType())->getElementType();
2848 if (
auto *
IT = dyn_cast<IntegerType>(Ty)) {
2849 switch (
IT->getBitWidth()) {
2863 return AT->getNumElements();
2864 return cast<FixedVectorType>(
getType())->getNumElements();
2873 const char *ConstantDataSequential::getElementPointer(
unsigned Elt)
const {
2893 if (
ArrayType *ATy = dyn_cast<ArrayType>(Ty))
2913 std::unique_ptr<ConstantDataSequential> *Entry = &Slot.second;
2914 for (; *Entry; Entry = &(*Entry)->Next)
2915 if ((*Entry)->getType() == Ty)
2916 return Entry->get();
2920 if (isa<ArrayType>(Ty)) {
2923 return Entry->get();
2926 assert(isa<VectorType>(Ty));
2929 return Entry->get();
2932 void ConstantDataSequential::destroyConstantImpl() {
2939 assert(Slot != CDSConstants.
end() &&
"CDS not found in uniquing table");
2941 std::unique_ptr<ConstantDataSequential> *Entry = &Slot->getValue();
2944 if (!(*Entry)->Next) {
2947 assert(Entry->get() ==
this &&
"Hash mismatch in ConstantDataSequential");
2955 std::unique_ptr<ConstantDataSequential> &Node = *Entry;
2956 assert(Node &&
"Didn't find entry in its uniquing hash table!");
2958 if (Node.get() ==
this) {
2963 Entry = &Node->Next;
2975 "Element type is not a 16-bit float type");
2977 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2981 assert(ElementType->
isFloatTy() &&
"Element type is not a 32-bit float type");
2983 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2988 "Element type is not a 64-bit float type");
2990 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2997 const uint8_t *
Data = Str.bytes_begin();
3002 ElementVals.
append(Str.begin(), Str.end());
3003 ElementVals.push_back(0);
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());
3037 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3050 "Element type is not a 16-bit float type");
3052 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3057 assert(ElementType->
isFloatTy() &&
"Element type is not a 32-bit float type");
3059 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3065 "Element type is not a 64-bit float type");
3067 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3073 "Element type not compatible with ConstantData");
3075 if (CI->getType()->isIntegerTy(8)) {
3079 if (CI->getType()->isIntegerTy(16)) {
3083 if (CI->getType()->isIntegerTy(32)) {
3087 assert(CI->getType()->isIntegerTy(64) &&
"Unsupported ConstantData type");
3092 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(V)) {
3093 if (CFP->getType()->isHalfTy()) {
3095 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3098 if (CFP->getType()->isBFloatTy()) {
3100 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3103 if (CFP->getType()->isFloatTy()) {
3105 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3108 if (CFP->getType()->isDoubleTy()) {
3110 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3120 "Accessor can only be used when element is an integer");
3121 const char *EltPtr = getElementPointer(Elt);
3128 return *
reinterpret_cast<const uint8_t *
>(EltPtr);
3130 return *
reinterpret_cast<const uint16_t *
>(EltPtr);
3132 return *
reinterpret_cast<const uint32_t *
>(EltPtr);
3134 return *
reinterpret_cast<const uint64_t *
>(EltPtr);
3140 "Accessor can only be used when element is an integer");
3141 const char *EltPtr = getElementPointer(Elt);
3148 auto EltVal = *
reinterpret_cast<const uint8_t *
>(EltPtr);
3149 return APInt(8, EltVal);
3152 auto EltVal = *
reinterpret_cast<const uint16_t *
>(EltPtr);
3153 return APInt(16, EltVal);
3156 auto EltVal = *
reinterpret_cast<const uint32_t *
>(EltPtr);
3157 return APInt(32, EltVal);
3160 auto EltVal = *
reinterpret_cast<const uint64_t *
>(EltPtr);
3161 return APInt(64, EltVal);
3167 const char *EltPtr = getElementPointer(Elt);
3171 llvm_unreachable(
"Accessor can only be used when element is float/double!");
3173 auto EltVal = *
reinterpret_cast<const uint16_t *
>(EltPtr);
3177 auto EltVal = *
reinterpret_cast<const uint16_t *
>(EltPtr);
3181 auto EltVal = *
reinterpret_cast<const uint32_t *
>(EltPtr);
3185 auto EltVal = *
reinterpret_cast<const uint64_t *
>(EltPtr);
3193 "Accessor can only be used when element is a 'float'");
3194 return *
reinterpret_cast<const float *
>(getElementPointer(Elt));
3199 "Accessor can only be used when element is a 'float'");
3200 return *
reinterpret_cast<const double *
>(getElementPointer(Elt));
3222 if (Str.back() != 0)
return false;
3225 return !Str.drop_back().contains(0);
3228 bool ConstantDataVector::isSplatData()
const {
3234 if (
memcmp(Base, Base+
i*EltSize, EltSize))
3243 IsSplat = isSplatData();
3268 Value *Replacement =
nullptr;
3272 #define HANDLE_CONSTANT(Name) \
3273 case Value::Name##Val: \
3274 Replacement = cast<Name>(this)->handleOperandChangeImpl(From, To); \
3276 #include "llvm/IR/Value.def"
3285 assert(Replacement !=
this &&
"I didn't contain From!");
3295 assert(isa<Constant>(To) &&
"Cannot make Constant refer to non-constant!");
3296 Constant *ToC = cast<Constant>(To);
3303 unsigned NumUpdated = 0;
3306 bool AllSame =
true;
3308 unsigned OperandNo = 0;
3310 Constant *Val = cast<Constant>(
O->get());
3312 OperandNo = (
O - OperandList);
3316 Values.push_back(Val);
3317 AllSame &= Val == ToC;
3323 if (AllSame && isa<UndefValue>(ToC))
3332 Values,
this,
From, ToC, NumUpdated, OperandNo);
3336 assert(isa<Constant>(To) &&
"Cannot make Constant refer to non-constant!");
3337 Constant *ToC = cast<Constant>(To);
3346 unsigned NumUpdated = 0;
3347 bool AllSame =
true;
3348 unsigned OperandNo = 0;
3350 Constant *Val = cast<Constant>(
O->get());
3352 OperandNo = (
O - OperandList);
3356 Values.push_back(Val);
3357 AllSame &= Val == ToC;
3363 if (AllSame && isa<UndefValue>(ToC))
3368 Values,
this,
From, ToC, NumUpdated, OperandNo);
3372 assert(isa<Constant>(To) &&
"Cannot make Constant refer to non-constant!");
3373 Constant *ToC = cast<Constant>(To);
3377 unsigned NumUpdated = 0;
3378 unsigned OperandNo = 0;
3386 Values.push_back(Val);
3394 Values,
this,
From, ToC, NumUpdated, OperandNo);
3398 assert(isa<Constant>(ToV) &&
"Cannot make Constant refer to non-constant!");
3399 Constant *To = cast<Constant>(ToV);
3402 unsigned NumUpdated = 0;
3403 unsigned OperandNo = 0;
3411 NewOps.push_back(
Op);
3413 assert(NumUpdated &&
"I didn't contain From!");
3420 NewOps,
this,
From, To, NumUpdated, OperandNo);
3428 case Instruction::Trunc:
3429 case Instruction::ZExt:
3430 case Instruction::SExt:
3431 case Instruction::FPTrunc:
3432 case Instruction::FPExt:
3433 case Instruction::UIToFP:
3434 case Instruction::SIToFP:
3435 case Instruction::FPToUI:
3436 case Instruction::FPToSI:
3437 case Instruction::PtrToInt:
3438 case Instruction::IntToPtr:
3439 case Instruction::BitCast:
3440 case Instruction::AddrSpaceCast:
3445 case Instruction::InsertElement:
3447 case Instruction::ExtractElement:
3449 case Instruction::ShuffleVector:
3453 case Instruction::GetElementPtr: {
3454 const auto *GO = cast<GEPOperator>(
this);
3455 if (GO->isInBounds())
3457 GO->getSourceElementType(), Ops[0], Ops.
slice(1),
"", InsertBefore);
3459 Ops.
slice(1),
"", InsertBefore);
3461 case Instruction::ICmp:
3462 case Instruction::FCmp:
3470 if (isa<OverflowingBinaryOperator>(BO)) {
3476 if (isa<PossiblyExactOperator>(BO))
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
LLVMContextImpl *const pImpl
@ FloatTyID
32-bit floating point type
bool isAllOnesValue() const
Return true if this is the value that would be returned by getAllOnesValue.
user_iterator_impl< const User > const_user_iterator
const Value * stripPointerCastsAndAliases() const
Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
@ DoubleTyID
64-bit floating point type
bool isFiniteNonZeroFP() const
Return true if this is a finite and non-zero floating-point scalar constant or a fixed width vector c...
This is an optimization pass for GlobalISel generic memory operations.
uint64_t getElementByteSize() const
Return the size (in bytes) of each element in the array/vector.
bool isNormalFP() const
Return true if this is a normal (as opposed to denormal, infinity, nan, or zero) floating-point scala...
bool isNaN() const
Return true if this is a floating-point NaN constant or a vector floating-point constant with all NaN...
static IntegerType * getInt1Ty(LLVMContext &C)
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
void deleteConstant(Constant *C)
DenseMap< std::pair< const Function *, const BasicBlock * >, BlockAddress * > BlockAddresses
static Constant * getNot(Constant *C)
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
static bool isValueValidForType(Type *Ty, const APFloat &V)
Return true if Ty is big enough to represent V.
static Constant * getZExtOrBitCast(Constant *C, Type *Ty)
static Constant * getSIToFP(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
bool containsPoisonElement() const
Return true if this is a vector constant that includes any poison elements.
const char * getOpcodeName() const
Return a string representation for an opcode.
Constant * getSequentialElement() const
If this CAZ has array or vector type, return a zero with the right element type.
static bool isAllZeros(StringRef Arr)
Return true if the array is empty or all zeros.
static const fltSemantics & IEEEsingle() LLVM_READNONE
ConstantClass * replaceOperandsInPlace(ArrayRef< Constant * > Operands, ConstantClass *CP, Value *From, Constant *To, unsigned NumUpdated=0, unsigned OperandNo=~0u)
static Constant * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Function * getFunction(Constant *C)
static Constant * get(StructType *T, ArrayRef< Constant * > V)
DenseMap< Type *, std::unique_ptr< UndefValue > > UVConstants
Instruction * getAsInstruction(Instruction *InsertBefore=nullptr) const
Returns an Instruction which implements the same operation as this ConstantExpr.
static bool rangeOnlyContains(ItTy Start, ItTy End, EltTy Elt)
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
static Constant * getFPCast(Constant *C, Type *Ty)
Create a FPExt, Bitcast or FPTrunc for fp -> fp casts.
instcombine should handle this C2 when C1
Constant * ConstantFoldSelectInstruction(Constant *Cond, Constant *V1, Constant *V2)
Attempt to constant fold a select instruction with the specified operands.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
PoisonValue * getSequentialElement() const
If this poison has array or vector type, return a poison with the right element type.
static Constant * getSExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
This might compile to this xmm1 xorps xmm0 movss xmm0 ret Now consider if the code caused xmm1 to get spilled This might produce this xmm1 movaps xmm0 movaps xmm1 movss xmm0 ret since the reload is only used by these we could fold it into the uses
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
static Constant * getICmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
get* - Return some common constants without having to specify the full Instruction::OPCODE identifier...
PoisonValue * getElementValue(Constant *C) const
Return an poison of the right value for the specified GEP index if we can, otherwise return null (e....
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
const fltSemantics & getFltSemantics() const
uint64_t getElementAsInteger(unsigned i) const
If this is a sequential container of integers (of any size), return the specified element in the low ...
Value * getSplatValue(const Value *V)
Get splat value if the input is a splat vector or return nullptr.
unsigned getPredicate() const
Return the ICMP or FCMP predicate value.
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false, std::optional< unsigned > InRangeIndex=std::nullopt, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
static 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.
static CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", Instruction *InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Base class for aggregate constants (with operands).
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
ConstantUniqueMap< ConstantExpr > ExprConstants
BasicBlock * getBasicBlock() const
Merge contiguous icmps into a memcmp
static Constant * getInfinity(Type *Ty, bool Negative=false)
static Constant * getSelect(Constant *C, Constant *V1, Constant *V2, Type *OnlyIfReducedTy=nullptr)
Select constant expr.
TypeID getTypeID() const
Return the type id for the type.
static Constant * getSExtOrTrunc(Constant *C, Type *Ty)
Create either an sext, trunc or nothing, depending on whether Ty is wider, narrower or the same as C-...
static const fltSemantics & x87DoubleExtended() LLVM_READNONE
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
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")))
static Constant * get(LLVMContext &Context, ArrayRef< uint8_t > Elts)
get() constructors - Return a constant with vector type with an element count and element type matchi...
float getElementAsFloat(unsigned i) const
If this is an sequential container of floats, return the specified element as a float.
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
ElementCount getElementCount() const
Return the number of elements in the array, vector, or struct.
static Constant * getOffsetOf(StructType *STy, unsigned FieldNo)
getOffsetOf constant expr - computes the offset of a struct field in a target independent way (Note: ...
@ ICMP_SGT
signed greater than
GetElementPtrConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
The instances of the Type class are immutable: once they are created, they are never changed.
Wrapper for a value that won't be replaced with a CFI jump table pointer in LowerTypeTestsModule.
unsigned getBitWidth() const
Return the number of bits in the APInt.
static const fltSemantics & BFloat() LLVM_READNONE
static constexpr ElementCount getFixed(ScalarTy MinVal)
bool isNotOneValue() const
Return true if the value is not the one value, or, for vectors, does not contain one value elements.
static bool isElementTypeCompatible(Type *Ty)
Return true if a ConstantDataSequential can be formed with a vector or array of the specified element...
static Constant * getFPToSI(Constant *C, Type *Ty, bool OnlyIfReduced=false)
All zero aggregate value.
bool needsDynamicRelocation() const
OutputIt copy(R &&Range, OutputIt Out)
bool needsRelocation() const
This method classifies the entry according to whether or not it may generate a relocation entry (eith...
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
bool containsUndefElement() const
Return true if this is a vector constant that includes any strictly undef (not poison) elements.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
Type * getElementType() const
static bool isValidOperands(const Value *V1, const Value *V2, const Value *Mask)
Return true if a shufflevector instruction can be formed with the specified operands.
@ ICMP_SLE
signed less or equal
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
static 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...
static APFloat getSNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for SNaN values.
bool hasProperty(Property Prop) const
Returns true if the target extension type contains the given property.
Class to represent array types.
iterator find(StringRef Key)
gep_type_iterator gep_type_begin(const User *GEP)
static Constant * getNegativeZero(Type *Ty)
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
bool isOneValue() const
Returns true if the value is one.
void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag.
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
bool isString(unsigned CharSize=8) const
This method returns true if this is an array of CharSize integers.
const fltSemantics & getSemantics() const
DenseMap< const GlobalValue *, DSOLocalEquivalent * > DSOLocalEquivalents
static IntegerType * getInt8Ty(LLVMContext &C)
static IntegerType * getInt32Ty(LLVMContext &C)
bool isThreadDependent() const
Return true if the value can vary between threads.
bool empty() const
empty - Check if the array is empty.
static const char * areInvalidOperands(Value *Cond, Value *True, Value *False)
Return a string if the specified operands are invalid for a select operation, otherwise return null.
static bool isSupportedBinOp(unsigned Opcode)
Whether creating a constant expression for this binary operator is supported.
Constant * getWithOperands(ArrayRef< Constant * > Ops) const
This returns the current constant expression with the operands replaced with the specified values.
static Constant * getFPSequenceIfElementsMatch(ArrayRef< Constant * > V)
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
static ConstantTargetNone * get(TargetExtType *T)
Static factory methods - Return objects of the specified value.
std::unique_ptr< ConstantTokenNone > TheNoneToken
static const fltSemantics & IEEEquad() LLVM_READNONE
LLVM Basic Block Representation.
ArrayConstantsTy ArrayConstants
gep_type_iterator gep_type_end(const User *GEP)
static bool isUndef(ArrayRef< int > Mask)
@ FCMP_ULT
1 1 0 0 True if unordered or less than
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static 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.
APFloat getElementAsAPFloat(unsigned i) const
If this is a sequential container of floating point type, return the specified element as an APFloat.
Base class for constants with no operands.
AddressSpace getAddressSpace(T *V)
A constant pointer value that points to null.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
static Constant * getBinOpIdentity(unsigned Opcode, Type *Ty, bool AllowRHSConstant=false, bool NSZ=false)
Return the identity constant for a binary opcode.
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
bool isOpaqueOrPointeeTypeMatches(Type *Ty)
Return true if either this is an opaque pointer type or if this pointee type matches Ty.
This is the shared class of boolean and integer constants.
bool isArrayTy() const
True if this is an instance of ArrayType.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr, Instruction *MDFrom=nullptr)
ArrayRef< int > getShuffleMask() const
Assert that this is a shufflevector and return the mask.
Compile-time customization of User operands.
@ SC
CHAIN = SC CHAIN, Imm128 - System call.
bool containsConstantExpression() const
Return true if this is a fixed width vector constant that includes any constant expressions.
bool isFPPredicate() const
bool match(Val *V, const Pattern &P)
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static const fltSemantics & IEEEhalf() LLVM_READNONE
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.
UndefValue * getElementValue(Constant *C) const
Return an undef of the right value for the specified GEP index if we can, otherwise return null (e....
static Type * getDoubleTy(LLVMContext &C)
(vector float) vec_cmpeq(*A, *B) C
@ ICMP_ULE
unsigned less or equal
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
DenseMap< Type *, std::unique_ptr< ConstantAggregateZero > > CAZConstants
static VectorType * getInteger(VectorType *VTy)
This static method gets a VectorType with the same number of elements as the input type,...
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
static Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
bool isVectorTy() const
True if this is an instance of VectorType.
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
static Constant * getBinOpAbsorber(unsigned Opcode, Type *Ty)
Return the absorbing element for the given binary operation, i.e.
unsigned getValueID() const
Return an ID for the concrete type of this object.
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Class to represent integer types.
const char * getOpcodeName() const
ConstantArray - Constant Array Declarations.
static Constant * getAllOnesValue(Type *Ty)
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
static bool containsUndefinedElement(const Constant *C, function_ref< bool(const Constant *)> HasFn)
Constant * getSplatValue() const
If this is a splat constant, meaning that all of the elements have the same value,...
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
bool bitwiseIsEqual(const APFloat &RHS) const
ConstantFP - Floating Point Values [float, double].
static Constant * getSplat(ElementCount EC, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
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 ...
ShuffleVectorConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
static Constant * getXor(Constant *C1, Constant *C2)
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
DenseMap< TargetExtType *, std::unique_ptr< ConstantTargetNone > > CTNConstants
static Constant * getImpl(StringRef Bytes, Type *Ty)
This is the underlying implementation of all of the ConstantDataSequential::get methods.
@ FCMP_OLT
0 1 0 0 True if ordered and less than
PoisonValue * getStructElement(unsigned Elt) const
If this poison has struct type, return a poison with the right element type for the specified element...
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
StructType * getType() const
Specialization - reduce amount of casting.
ConstantAggregate(Type *T, ValueTy VT, ArrayRef< Constant * > V)
static FixedVectorType * get(Type *ElementType, unsigned NumElts)
static Constant * getSequenceIfElementsMatch(Constant *C, ArrayRef< Constant * > V)
@ BFloatTyID
16-bit floating point type (7-bit significand)
bool isMinSignedValue() const
Return true if the value is the smallest signed value.
StringMap< std::unique_ptr< ConstantDataSequential > > CDSConstants
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
SelectConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to impleme...
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.
unsigned getNumElements() const
Return the number of elements in the array, vector, or struct.
static Constant * getSNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
unsigned getIntegerBitWidth() const
bool isCompare() const
Return true if this is a compare constant expression.
Constant * getShuffleMaskForBitcode() const
Assert that this is a shufflevector and return the mask.
Constant * ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1, Constant *V2)
Constant * ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx)
Attempt to constant fold an extractelement instruction with the specified operands and indices.
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
bool isCommutative() const LLVM_READONLY
Return true if the instruction is commutative:
@ FCMP_FALSE
0 0 0 0 Always false (always folded)
static Constant * getAShr(Constant *C1, Constant *C2, bool isExact=false)
unsigned getStructNumElements() const
bool isCString() const
This method returns true if the array "isString", ends with a null byte, and does not contains any ot...
Constant * ConstantFoldCastInstruction(unsigned opcode, Constant *V, Type *DestTy)
bool isIntegerTy() const
True if this is an instance of IntegerType.
static APFloat getQNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for QNaN values.
An efficient, type-erasing, non-owning reference to a callable.
bool isCast() const
Return true if this is a convert constant expression.
static Constant * getShuffleVector(Constant *V1, Constant *V2, ArrayRef< int > Mask, Type *OnlyIfReducedTy=nullptr)
ArrayType * getType() const
Specialize the getType() method to always return an ArrayType, which reduces the amount of casting ne...
Base class of all SIMD vector types.
static Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
StringRef getRawDataValues() const
Return the raw, underlying, bytes of this data.
FixedVectorType * getType() const
Specialize the getType() method to always return a FixedVectorType, which reduces the amount of casti...
bool isDLLImportDependent() const
Return true if the value is dependent on a dllimport variable.
static Constant * getCompare(unsigned short pred, Constant *C1, Constant *C2, bool OnlyIfReduced=false)
Return an ICmp or FCmp comparison operator constant expression.
bool hasZeroLiveUses() const
Return true if the constant has no live uses.
static Constant * getQNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
Constant * ConstantFoldCompareInstruction(CmpInst::Predicate Predicate, Constant *C1, Constant *C2)
This is an important base class in LLVM.
void mutateType(Type *Ty)
Mutate the type of this Value to be of the specified type.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
DenseMap< PointerType *, std::unique_ptr< ConstantPointerNull > > CPNConstants
bool isElementWiseEqual(Value *Y) const
Return true if this constant and a constant 'Y' are element-wise equal.
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 Constant * replaceUndefsWith(Constant *C, Constant *Replacement)
Try to replace undefined constant C or undefined elements in C with Replacement.
static Constant * getFP(Type *ElementType, ArrayRef< uint16_t > Elts)
getFP() constructors - Return a constant of vector type with a float element type taken from argument...
static Constant * getZero(Type *Ty, bool Negative=false)
ConstantInt * TheFalseVal
static Constant * getAddrSpaceCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
unsigned logBase2() const
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
An array constant whose element type is a simple 1/2/4/8-byte integer or float/double,...
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
This is an important class for using LLVM in a threaded context.
GlobalValue * getGlobalValue() const
bool isSplat() const
Returns true if this is a splat constant, meaning that all elements have the same value.
Type * getSourceElementType() const
static Constant * getAlignOf(Type *Ty)
getAlignOf constant expr - computes the alignment of a type in a target independent way (Note: the re...
A vector constant whose element type is a simple 1/2/4/8-byte integer or float/double,...
'undef' values are things that do not have specified contents.
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
static Constant * getShl(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static Constant * getOr(Constant *C1, Constant *C2)
static Constant * getIntSequenceIfElementsMatch(ArrayRef< Constant * > V)
Class to represent pointers.
Type * getElementType() const
Return the element type of the array/vector.
ConstantClass * getOrCreate(TypeClass *Ty, ValType V)
Return the specified constant from the map, creating it if necessary.
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
static GetElementPtrInst * CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Create an "inbounds" getelementptr.
bool hasOneLiveUse() const
Return true if the constant has exactly one live use.
Constant Vector Declarations.
static const fltSemantics & PPCDoubleDouble() LLVM_READNONE
Constant * ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt, Constant *Idx)
Attempt to constant fold an insertelement instruction with the specified operands and indices.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Constant * getElementAsConstant(unsigned i) const
Return a Constant for a specified index's element.
bool isNegativeZeroValue() const
Return true if the value is what would be returned by getZeroValueForNegation.
bool isManifestConstant() const
Return true if a constant is ConstantData or a ConstantAggregate or ConstantExpr that contain only Co...
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
@ ICMP_UGE
unsigned greater or equal
static Constant * getZeroValueForNegation(Type *Ty)
Floating point negation must be implemented with f(x) = -0.0 - x.
Constant * getElementValue(Constant *C) const
Return a zero of the right value for the specified GEP index if we can, otherwise return null (e....
CastConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to implement...
Constant * getSplatValue(bool AllowUndefs=false) const
If all elements of the vector constant have the same value, return that value.
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
static Constant * getNaN(Type *Ty, bool Negative=false, uint64_t Payload=0)
void handleOperandChange(Value *, Value *)
This method is a special form of User::replaceUsesOfWith (which does not work on constants) that does...
static Constant * getTruncOrBitCast(Constant *C, Type *Ty)
static Constant * getSizeOf(Type *Ty)
getSizeOf constant expr - computes the (alloc) size of a type (in address-units, not bits) in a targe...
Class for arbitrary precision integers.
void setOperand(unsigned i, Value *Val)
static M68kRelType getType(unsigned Kind, MCSymbolRefExpr::VariantKind &Modifier, bool &IsPCRel)
@ ICMP_SLT
signed less than
bool isIntPredicate() const
@ FP128TyID
128-bit floating point type (112-bit significand)
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
ValueTy
Concrete subclass of this.
The address of a basic block.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
void removeDeadConstantUsers() const
If there are any dead constant users dangling off of this constant, remove them.
Class to represent struct types.
static const fltSemantics & IEEEdouble() LLVM_READNONE
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
StringRef - Represent a constant reference to a string, i.e.
Analysis the ScalarEvolution expression for r is this
const Use * getOperandList() const
auto m_Undef()
Match an arbitrary undef constant.
static Constant * getSExtOrBitCast(Constant *C, Type *Ty)
static Constant * getUMin(Constant *C1, Constant *C2)
@ ICMP_ULT
unsigned less than
APInt getElementAsAPInt(unsigned i) const
If this is a sequential container of integers (of any size), return the specified element as an APInt...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
Type * getType() const
All values are typed, get the type of this value.
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVMContext & getContext() const
All values hold a context through their type.
StructConstantsTy StructConstants
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
DenseMap< Type *, std::unique_ptr< PoisonValue > > PVConstants
static Constant * getIntegerCast(Constant *C, Type *Ty, bool IsSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
static Constant * get(ArrayRef< Constant * > V)
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
TargetExtType * getType() const
Specialize the getType() method to always return an TargetExtType, which reduces the amount of castin...
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
const T & front() const
front - Get the first element.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
static ConstantInt * getFalse(LLVMContext &Context)
static Constant * getFCmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
@ IntegerTyID
Arbitrary bit width integers.
static Constant * getFP(Type *ElementType, ArrayRef< uint16_t > Elts)
getFP() constructors - Return a constant of array type with a float element type taken from argument ...
Constant * getStructElement(unsigned Elt) const
If this CAZ has struct type, return a zero with the right element type for the specified element.
static NoCFIValue * get(GlobalValue *GV)
Return a NoCFIValue for the specified function.
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
Function * getFunction() const
Class to represent target extensions types, which are generally unintrospectable from target-independ...
UndefValue * getSequentialElement() const
If this Undef has array or vector type, return a undef with the right element type.
static IntegerType * getInt64Ty(LLVMContext &C)
A constant value that is initialized with an expression using other constant values.
static bool constantIsDead(const Constant *C, bool RemoveDeadUsers)
Return true if the specified constantexpr is dead.
static ConstantInt * getTrue(LLVMContext &Context)
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
bool hasSameElementTypeAs(PointerType *Other)
Return true if both pointer types have the same element type.
Constant * ConstantFoldGetElementPtr(Type *Ty, Constant *C, bool InBounds, std::optional< unsigned > InRangeIndex, ArrayRef< Value * > Idxs)
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
static Constant * getNeg(Constant *C, bool HasNUW=false, bool HasNSW=false)
Should compile to something r4 addze r3 instead we get
double getElementAsDouble(unsigned i) const
If this is an sequential container of doubles, return the specified element as a double.
static ConstantInt * getBool(LLVMContext &Context, bool V)
@ FixedVectorTyID
Fixed width SIMD vector type.
bool isZeroValue() const
Return true if the value is negative zero or null value.
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
static Constant * get(Type *Ty, double V)
This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in...
static ConstantTokenNone * get(LLVMContext &Context)
Return the ConstantTokenNone.
static ConstantInt * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
static char getTypeID(Type *Ty)
static Constant * getAnd(Constant *C1, Constant *C2)
Constant * ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2, ArrayRef< int > Mask)
Attempt to constant fold a shufflevector instruction with the specified operands and mask.
UndefValue * getStructElement(unsigned Elt) const
If this undef has struct type, return a undef with the right element type for the specified element.
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
static bool ConstHasGlobalValuePredicate(const Constant *C, bool(*Predicate)(const GlobalValue *))
Check if C contains a GlobalValue for which Predicate is true.
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
A constant target extension type default initializer.
static Type * getIndexedType(Type *Ty, ArrayRef< Value * > IdxList)
Returns the result type of a getelementptr with the given source element type and indexes.
static Constant * getLShr(Constant *C1, Constant *C2, bool isExact=false)
void remove(ConstantClass *CP)
Remove this constant from the map.
static Constant * getFPTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
@ ICMP_SGE
signed greater or equal
static Constant * getFPToUI(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static CmpInst * Create(OtherOps Op, Predicate predicate, Value *S1, Value *S2, const Twine &Name="", Instruction *InsertBefore=nullptr)
Construct a compare instruction, given the opcode, the predicate and the two operands.
static Constant * mergeUndefsWith(Constant *C, Constant *Other)
Merges undefs of a Constant with another Constant, along with the undefs already present.
static APFloat getAllOnesValue(const fltSemantics &Semantics)
Returns a float which is bitcasted from an all one value int.
static bool isDesirableBinOp(unsigned Opcode)
Whether creating a constant expression for this binary operator is desirable.
Type * getResultElementType() const
This instruction constructs a fixed permutation of two input vectors.
static bool isSigned(unsigned int Opcode)
static constexpr roundingMode rmNearestTiesToEven
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
static 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...
bool hasExactInverseFP() const
Return true if this scalar has an exact multiplicative inverse or this vector has an exact multiplica...
unsigned getNumOperands() const
bool isStructTy() const
True if this is an instance of StructType.
std::optional< std::vector< StOtherPiece > > Other
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
InsertElementConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
const APInt & getUniqueInteger() const
If C is a constant integer then return its value, otherwise C must be a vector of constant integers,...
static Constant * getFPExtend(Constant *C, Type *Ty, bool OnlyIfReduced=false)
const Value * stripInBoundsConstantOffsets() const
Strip off pointer casts and all-constant inbounds GEPs.
@ ICMP_UGT
unsigned greater than
static PointerType * getWithSamePointeeType(PointerType *PT, unsigned AddressSpace)
This constructs a pointer type with the same pointee type as input PointerType (or opaque pointer if ...
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
bool containsUndefOrPoisonElement() const
Return true if this is a vector constant that includes any undef or poison elements.
static Constant * getSplat(unsigned NumElts, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
BinaryConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to impleme...
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
size_t size() const
size - Get the array size.
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
static 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 Constant * getMul(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
@ HasZeroInit
zeroinitializer is valid for this target extension type.
static APFloat getNaN(const fltSemantics &Sem, bool Negative=false, uint64_t payload=0)
Factory for NaN values.
Constant * getSplatValue(bool AllowUndefs=false) const
If all elements of the vector constant have the same value, return that value.
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
VectorConstantsTy VectorConstants
static StructType * getTypeForElements(ArrayRef< Constant * > V, bool Packed=false)
Return an anonymous struct type to use for a constant with the specified set of elements.
GlobalValue * getGlobalValue() const
static IntegerType * getInt16Ty(LLVMContext &C)
@ ScalableVectorTyID
Scalable SIMD vector type.
PointerType * getType() const
Global values are always pointers.
ArrayRef(const T &OneElt) -> ArrayRef< T >
bool isNotMinSignedValue() const
Return true if the value is not the smallest signed value, or, for vectors, does not contain smallest...
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
static BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
BlockVerifier::State From
PointerType * getType() const
Specialize the getType() method to always return an PointerType, which reduces the amount of casting ...
bool isConstantUsed() const
Return true if the constant has users other than constant expressions and other dangling things.
Value * getOperand(unsigned i) const
StringRef getAsString() const
If this array is isString(), then this method returns the array as a StringRef.
DenseMap< const GlobalValue *, NoCFIValue * > NoCFIValues
static ConstantAggregateZero * get(Type *Ty)
void reserve(size_type N)
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), Instruction *InsertBefore=nullptr)
Construct a binary instruction, given the opcode and the two operands.
@ FCMP_TRUE
1 1 1 1 Always true (always folded)
@ TargetExtTyID
Target extension type.
A constant token which is empty.
static DSOLocalEquivalent * get(GlobalValue *GV)
Return a DSOLocalEquivalent for the specified global value.
LLVM Value Representation.
Wrapper for a function that represents a value that functionally represents the original function.
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
@ HalfTyID
16-bit floating point type
@ X86_FP80TyID
80-bit floating point type (X87)
static Type * getFloatTy(LLVMContext &C)
static Type * getFloatingPointTy(LLVMContext &C, const fltSemantics &S)
Type * getElementType() const
void destroyConstant()
Called if some element of this constant is no longer valid.
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value.
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
A Use represents the edge between a Value definition and its users.
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
static Constant * getUIToFP(Constant *C, Type *Ty, bool OnlyIfReduced=false)
In order to facilitate speculative execution, many instructions do not invoke immediate undefined beh...
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
unsigned getNumElements() const
Return the number of elements in the array or vector.