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);
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); });
341 if (
auto *VTy = dyn_cast<FixedVectorType>(
getType())) {
342 for (
unsigned i = 0,
e = VTy->getNumElements();
i !=
e; ++
i)
343 if (isa<ConstantExpr>(getAggregateElement(
i)))
385 if (
PointerType *PTy = dyn_cast<PointerType>(ScalarTy))
389 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
412 "Must be an aggregate/vector constant");
414 if (
const auto *CC = dyn_cast<ConstantAggregate>(
this))
415 return Elt < CC->getNumOperands() ? CC->getOperand(Elt) :
nullptr;
417 if (
const auto *CAZ = dyn_cast<ConstantAggregateZero>(
this))
418 return Elt < CAZ->getElementCount().getKnownMinValue()
419 ? CAZ->getElementValue(Elt)
423 if (isa<ScalableVectorType>(
getType()))
426 if (
const auto *PV = dyn_cast<PoisonValue>(
this))
427 return Elt < PV->getNumElements() ? PV->getElementValue(Elt) :
nullptr;
429 if (
const auto *UV = dyn_cast<UndefValue>(
this))
430 return Elt < UV->getNumElements() ? UV->getElementValue(Elt) :
nullptr;
432 if (
const auto *CDS = dyn_cast<ConstantDataSequential>(
this))
433 return Elt < CDS->getNumElements() ? CDS->getElementAsConstant(Elt)
440 assert(isa<IntegerType>(Elt->
getType()) &&
"Index must be an integer");
441 if (
ConstantInt *CI = dyn_cast<ConstantInt>(Elt)) {
443 if (CI->getValue().getActiveBits() > 64)
445 return getAggregateElement(CI->getZExtValue());
453 switch (getValueID()) {
456 #define HANDLE_CONSTANT(Name) \
457 case Value::Name##Val: \
458 cast<Name>(this)->destroyConstantImpl(); \
460 #include "llvm/IR/Value.def"
470 while (!use_empty()) {
471 Value *V = user_back();
472 #ifndef NDEBUG // Only in -g mode...
473 if (!isa<Constant>(V)) {
474 dbgs() <<
"While deleting: " << *
this
475 <<
"\n\nUse still stuck around after Def is destroyed: " << *V
479 assert(isa<Constant>(V) &&
"References remain to Constant being destroyed");
480 cast<Constant>(V)->destroyConstant();
483 assert((use_empty() || user_back() != V) &&
"Constant not removed!");
491 switch (
C->getValueID()) {
492 case Constant::ConstantIntVal:
495 case Constant::ConstantFPVal:
498 case Constant::ConstantAggregateZeroVal:
501 case Constant::ConstantArrayVal:
504 case Constant::ConstantStructVal:
507 case Constant::ConstantVectorVal:
510 case Constant::ConstantPointerNullVal:
513 case Constant::ConstantDataArrayVal:
516 case Constant::ConstantDataVectorVal:
519 case Constant::ConstantTokenNoneVal:
522 case Constant::BlockAddressVal:
525 case Constant::DSOLocalEquivalentVal:
528 case Constant::NoCFIValueVal:
531 case Constant::UndefValueVal:
534 case Constant::PoisonValueVal:
537 case Constant::ConstantExprVal:
538 if (isa<UnaryConstantExpr>(
C))
540 else if (isa<BinaryConstantExpr>(
C))
542 else if (isa<SelectConstantExpr>(
C))
544 else if (isa<ExtractElementConstantExpr>(
C))
546 else if (isa<InsertElementConstantExpr>(
C))
548 else if (isa<ShuffleVectorConstantExpr>(
C))
550 else if (isa<InsertValueConstantExpr>(
C))
552 else if (isa<GetElementPtrConstantExpr>(
C))
554 else if (isa<CompareConstantExpr>(
C))
566 assert(
C->getType()->isFirstClassType() &&
567 "Cannot evaluate non-first-class types!");
569 if (isa<ConstantExpr>(
C) || isa<ConstantAggregate>(
C)) {
570 for (
unsigned i = 0,
e =
C->getNumOperands();
i !=
e; ++
i) {
572 if (isa<ConstantExpr>(
Op) || isa<ConstantAggregate>(
Op)) {
585 switch (CE->getOpcode()) {
588 case Instruction::SDiv:
589 case Instruction::SRem:
591 if (!CE->getOperand(0)->isNotMinSignedValue() &&
592 (!isa<ConstantInt>(CE->getOperand(1)) ||
593 CE->getOperand(1)->isAllOnesValue()))
596 case Instruction::UDiv:
597 case Instruction::URem:
599 return !isa<ConstantInt>(CE->getOperand(1)) ||
600 CE->getOperand(1)->isNullValue();
615 WorkList.push_back(
C);
618 while (!WorkList.empty()) {
620 if (
const auto *GV = dyn_cast<GlobalValue>(WorkItem))
624 const Constant *ConstOp = dyn_cast<Constant>(
Op);
627 if (Visited.
insert(ConstOp).second)
628 WorkList.push_back(ConstOp);
635 auto DLLImportPredicate = [](
const GlobalValue *GV) {
636 return GV->isThreadLocal();
642 auto DLLImportPredicate = [](
const GlobalValue *GV) {
643 return GV->hasDLLImportStorageClass();
650 const Constant *UC = dyn_cast<Constant>(U);
651 if (!UC || isa<GlobalValue>(UC))
661 return getRelocationInfo() == GlobalRelocation;
665 return getRelocationInfo() != NoRelocation;
668 Constant::PossibleRelocationsTy Constant::getRelocationInfo()
const {
669 if (isa<GlobalValue>(
this))
670 return GlobalRelocation;
672 if (
const BlockAddress *BA = dyn_cast<BlockAddress>(
this))
673 return BA->getFunction()->getRelocationInfo();
675 if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(
this)) {
676 if (CE->getOpcode() == Instruction::Sub) {
679 if (
LHS &&
RHS &&
LHS->getOpcode() == Instruction::PtrToInt &&
680 RHS->getOpcode() == Instruction::PtrToInt) {
688 if (isa<BlockAddress>(LHSOp0) && isa<BlockAddress>(RHSOp0) &&
697 if (
auto *LHSGV = dyn_cast<GlobalValue>(
LHS)) {
698 if (LHSGV->isDSOLocal() && RHSGV->isDSOLocal())
699 return LocalRelocation;
700 }
else if (isa<DSOLocalEquivalent>(
LHS)) {
701 if (RHSGV->isDSOLocal())
702 return LocalRelocation;
709 PossibleRelocationsTy
Result = NoRelocation;
710 for (
unsigned i = 0,
e = getNumOperands();
i !=
e; ++
i)
712 std::max(cast<Constant>(getOperand(
i))->getRelocationInfo(), Result);
721 if (isa<GlobalValue>(
C))
return false;
726 if (!
User)
return false;
739 if (RemoveDeadUsers) {
743 const_cast<Constant *
>(
C)->destroyConstant();
769 if (LastNonDeadUser ==
E)
772 I = std::next(LastNonDeadUser);
780 bool Constant::hasNLiveUses(
unsigned N)
const {
781 unsigned NumUses = 0;
795 assert(
C && Replacement &&
"Expected non-nullptr constant arguments");
796 Type *Ty =
C->getType();
798 assert(Ty == Replacement->
getType() &&
"Expected matching types");
803 auto *VTy = dyn_cast<FixedVectorType>(Ty);
807 unsigned NumElts = VTy->getNumElements();
809 for (
unsigned i = 0;
i != NumElts; ++
i) {
812 "Expected matching types");
813 NewC[
i] = EltC &&
match(EltC,
m_Undef()) ? Replacement : EltC;
819 assert(
C &&
Other &&
"Expected non-nullptr constant arguments");
823 Type *Ty =
C->getType();
827 auto *VTy = dyn_cast<FixedVectorType>(Ty);
831 Type *EltTy = VTy->getElementType();
832 unsigned NumElts = VTy->getNumElements();
834 cast<FixedVectorType>(
Other->getType())->getNumElements() == NumElts &&
837 bool FoundExtraUndef =
false;
839 for (
unsigned I = 0;
I != NumElts; ++
I) {
840 NewC[
I] =
C->getAggregateElement(
I);
842 assert(NewC[
I] && OtherEltC &&
"Unknown vector element");
845 FoundExtraUndef =
true;
854 if (isa<ConstantData>(
this))
856 if (isa<ConstantAggregate>(
this) || isa<ConstantExpr>(
this)) {
857 for (
const Value *
Op : operand_values())
858 if (!cast<Constant>(
Op)->isManifestConstant())
895 if (
auto *VTy = dyn_cast<VectorType>(Ty))
903 if (
auto *VTy = dyn_cast<VectorType>(Ty))
916 std::unique_ptr<ConstantInt> &Slot = pImpl->
IntConstants[V];
930 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
941 return get(Ty, V,
true);
945 return get(Ty, V,
true);
951 "ConstantInt type doesn't match the type implied by its value!");
954 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
965 void ConstantInt::destroyConstantImpl() {
983 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
992 "ConstantFP type doesn't match the type implied by its value!");
995 if (
auto *VTy = dyn_cast<VectorType>(Ty))
1008 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1019 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1030 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1041 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1052 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1070 std::unique_ptr<ConstantFP> &Slot = pImpl->
FPConstants[V];
1084 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1090 ConstantFP::ConstantFP(
Type *Ty,
const APFloat &V)
1093 "FP type Mismatch");
1101 void ConstantFP::destroyConstantImpl() {
1110 if (
auto *AT = dyn_cast<ArrayType>(
getType()))
1133 if (
auto *AT = dyn_cast<ArrayType>(Ty))
1135 if (
auto *VT = dyn_cast<VectorType>(Ty))
1136 return VT->getElementCount();
1168 if (
auto *AT = dyn_cast<ArrayType>(Ty))
1169 return AT->getNumElements();
1170 if (
auto *VT = dyn_cast<VectorType>(Ty))
1171 return cast<FixedVectorType>(VT)->getNumElements();
1205 template <
typename ItTy,
typename EltTy>
1207 for (; Start != End; ++Start)
1213 template <
typename SequentialTy,
typename ElementTy>
1215 assert(!V.
empty() &&
"Cannot get empty int sequence.");
1219 if (
auto *CI = dyn_cast<ConstantInt>(
C))
1220 Elts.push_back(CI->getZExtValue());
1226 template <
typename SequentialTy,
typename ElementTy>
1228 assert(!V.
empty() &&
"Cannot get empty FP sequence.");
1232 if (
auto *CFP = dyn_cast<ConstantFP>(
C))
1233 Elts.push_back(CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
1236 return SequentialTy::getFP(V[0]->
getType(), Elts);
1239 template <
typename SequenceTy>
1246 if (CI->getType()->isIntegerTy(8))
1247 return getIntSequenceIfElementsMatch<SequenceTy, uint8_t>(V);
1248 else if (CI->getType()->isIntegerTy(16))
1249 return getIntSequenceIfElementsMatch<SequenceTy, uint16_t>(V);
1250 else if (CI->getType()->isIntegerTy(32))
1251 return getIntSequenceIfElementsMatch<SequenceTy, uint32_t>(V);
1252 else if (CI->getType()->isIntegerTy(64))
1253 return getIntSequenceIfElementsMatch<SequenceTy, uint64_t>(V);
1254 }
else if (
ConstantFP *CFP = dyn_cast<ConstantFP>(
C)) {
1255 if (CFP->getType()->isHalfTy() || CFP->getType()->isBFloatTy())
1256 return getFPSequenceIfElementsMatch<SequenceTy, uint16_t>(V);
1257 else if (CFP->getType()->isFloatTy())
1258 return getFPSequenceIfElementsMatch<SequenceTy, uint32_t>(V);
1259 else if (CFP->getType()->isDoubleTy())
1260 return getFPSequenceIfElementsMatch<SequenceTy, uint64_t>(V);
1273 if (
auto *
ST = dyn_cast<StructType>(
T)) {
1276 for (
unsigned I = 0,
E = V.
size();
I !=
E; ++
I)
1278 "Initializer for struct element doesn't match!");
1285 "Invalid initializer for constant array");
1301 "Wrong type in array element initializer");
1321 return getSequenceIfElementsMatch<ConstantDataArray>(
C, V);
1342 "ConstantStruct::getTypeForElements cannot be called on empty list");
1348 assert((
T->isOpaque() || V.
size() ==
T->getNumElements()) &&
1349 "Invalid initializer for constant struct");
1355 "Incorrect # elements specified to ConstantStruct::get");
1360 bool isPoison =
false;
1363 isUndef = isa<UndefValue>(V[0]);
1364 isPoison = isa<PoisonValue>(V[0]);
1365 isZero = V[0]->isNullValue();
1369 if (!
C->isNullValue())
1371 if (!isa<PoisonValue>(
C))
1373 if (isa<PoisonValue>(
C) || !isa<UndefValue>(
C))
1385 return ST->getContext().pImpl->StructConstants.getOrCreate(
ST, V);
1390 assert(V.
size() == cast<FixedVectorType>(
T)->getNumElements() &&
1391 "Invalid initializer for constant vector");
1409 bool isZero =
C->isNullValue();
1411 bool isPoison = isa<PoisonValue>(
C);
1414 for (
unsigned i = 1,
e = V.
size();
i !=
e; ++
i)
1431 return getSequenceIfElementsMatch<ConstantDataVector>(
C, V);
1439 if (!EC.isScalable()) {
1442 if ((isa<ConstantFP>(V) || isa<ConstantInt>(V)) &&
1454 else if (isa<UndefValue>(V))
1476 void ConstantTokenNone::destroyConstantImpl() {
1492 return getOpcode() == Instruction::InsertValue;
1496 return cast<InsertValueConstantExpr>(
this)->Indices;
1500 return cast<CompareConstantExpr>(
this)->predicate;
1504 return cast<ShuffleVectorConstantExpr>(
this)->ShuffleMask;
1508 return cast<ShuffleVectorConstantExpr>(
this)->ShuffleMaskForBitcode;
1512 bool OnlyIfReduced,
Type *SrcTy)
const {
1519 Type *OnlyIfReducedTy = OnlyIfReduced ? Ty :
nullptr;
1521 case Instruction::Trunc:
1522 case Instruction::ZExt:
1523 case Instruction::SExt:
1524 case Instruction::FPTrunc:
1525 case Instruction::FPExt:
1526 case Instruction::UIToFP:
1527 case Instruction::SIToFP:
1528 case Instruction::FPToUI:
1529 case Instruction::FPToSI:
1530 case Instruction::PtrToInt:
1531 case Instruction::IntToPtr:
1532 case Instruction::BitCast:
1533 case Instruction::AddrSpaceCast:
1537 case Instruction::InsertElement:
1540 case Instruction::ExtractElement:
1542 case Instruction::InsertValue:
1545 case Instruction::FNeg:
1547 case Instruction::ShuffleVector:
1550 case Instruction::GetElementPtr: {
1551 auto *GEPO = cast<GEPOperator>(
this);
1554 SrcTy ? SrcTy : GEPO->getSourceElementType(), Ops[0], Ops.
slice(1),
1555 GEPO->isInBounds(), GEPO->getInRangeIndex(), OnlyIfReducedTy);
1557 case Instruction::ICmp:
1558 case Instruction::FCmp:
1575 return Val == 0 || Val == 1;
1582 return Val == 0 || Val == 1 || Val == -1;
1583 return isIntN(NumBits, Val);
1649 "Cannot create an aggregate zero of non-aggregate type!");
1651 std::unique_ptr<ConstantAggregateZero> &Entry =
1660 void ConstantAggregateZero::destroyConstantImpl() {
1665 void ConstantArray::destroyConstantImpl() {
1674 void ConstantStruct::destroyConstantImpl() {
1679 void ConstantVector::destroyConstantImpl() {
1684 assert(this->
getType()->isVectorTy() &&
"Only valid for vectors!");
1685 if (isa<ConstantAggregateZero>(
this))
1688 return CV->getSplatValue();
1690 return CV->getSplatValue(AllowUndefs);
1694 const auto *Shuf = dyn_cast<ConstantExpr>(
this);
1695 if (Shuf && Shuf->getOpcode() == Instruction::ShuffleVector &&
1696 isa<UndefValue>(Shuf->getOperand(1))) {
1698 const auto *IElt = dyn_cast<ConstantExpr>(Shuf->getOperand(0));
1699 if (IElt && IElt->getOpcode() == Instruction::InsertElement &&
1700 isa<UndefValue>(IElt->getOperand(0))) {
1729 if (isa<UndefValue>(OpC))
1733 if (isa<UndefValue>(Elt))
1743 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
1744 return CI->getValue();
1747 assert(
C && isa<ConstantInt>(
C) &&
"Not a vector of numbers!");
1748 return cast<ConstantInt>(
C)->getValue();
1755 std::unique_ptr<ConstantPointerNull> &Entry =
1764 void ConstantPointerNull::destroyConstantImpl() {
1777 void UndefValue::destroyConstantImpl() {
1796 void PoisonValue::destroyConstantImpl() {
1802 assert(
BB->getParent() &&
"Block must have a parent");
1803 return get(
BB->getParent(),
BB);
1808 F->getContext().pImpl->BlockAddresses[std::make_pair(
F,
BB)];
1818 Value::BlockAddressVal, &
Op<0>(), 2) {
1821 BB->AdjustBlockAddressRefCount(1);
1825 if (!
BB->hasAddressTaken())
1829 assert(
F &&
"Block must have a parent");
1831 F->getContext().pImpl->BlockAddresses.lookup(std::make_pair(
F,
BB));
1832 assert(BA &&
"Refcount and block address map disagree!");
1837 void BlockAddress::destroyConstantImpl() {
1852 assert(
From == NewBB &&
"From does not match any operand");
1853 NewBB = cast<BasicBlock>(To);
1885 "DSOLocalFunction does not match the expected global value");
1889 DSOLocalEquivalent::DSOLocalEquivalent(
GlobalValue *GV)
1895 void DSOLocalEquivalent::destroyConstantImpl() {
1902 assert(isa<Constant>(To) &&
"Can only replace the operands with a constant");
1905 if (
const auto *ToObj = dyn_cast<GlobalValue>(To)) {
1942 assert(
NC->getGlobalValue() == GV &&
1943 "NoCFIValue does not match the expected global value");
1953 void NoCFIValue::destroyConstantImpl() {
1962 assert(GV &&
"Can only replace the operands with a global value");
1984 bool OnlyIfReduced =
false) {
2002 bool OnlyIfReduced) {
2005 assert(
C && Ty &&
"Null arguments to getCast");
2011 case Instruction::Trunc:
2013 case Instruction::ZExt:
2014 return getZExt(
C, Ty, OnlyIfReduced);
2015 case Instruction::SExt:
2016 return getSExt(
C, Ty, OnlyIfReduced);
2017 case Instruction::FPTrunc:
2019 case Instruction::FPExt:
2021 case Instruction::UIToFP:
2023 case Instruction::SIToFP:
2025 case Instruction::FPToUI:
2027 case Instruction::FPToSI:
2029 case Instruction::PtrToInt:
2031 case Instruction::IntToPtr:
2033 case Instruction::BitCast:
2035 case Instruction::AddrSpaceCast:
2060 "Can only sign extend/truncate integers!");
2061 Type *CTy =
C->getType();
2070 assert(
S->getType()->isPtrOrPtrVectorTy() &&
"Invalid cast");
2077 unsigned SrcAS =
S->getType()->getPointerAddressSpace();
2086 assert(
S->getType()->isPtrOrPtrVectorTy() &&
"Invalid cast");
2096 assert(
C->getType()->isIntOrIntVectorTy() &&
2098 unsigned SrcBits =
C->getType()->getScalarSizeInBits();
2101 (SrcBits == DstBits ? Instruction::BitCast :
2102 (SrcBits > DstBits ? Instruction::Trunc :
2103 (isSigned ? Instruction::SExt : Instruction::ZExt)));
2110 unsigned SrcBits =
C->getType()->getScalarSizeInBits();
2112 if (SrcBits == DstBits)
2115 (SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt);
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() &&
"Trunc operand must be integer");
2128 "SrcTy must be larger than DestTy for Trunc!");
2135 bool fromVec = isa<VectorType>(
C->getType());
2136 bool toVec = isa<VectorType>(Ty);
2138 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2139 assert(
C->getType()->isIntOrIntVectorTy() &&
"SExt operand must be integral");
2142 "SrcTy must be smaller than DestTy for SExt!");
2149 bool fromVec = isa<VectorType>(
C->getType());
2150 bool toVec = isa<VectorType>(Ty);
2152 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2153 assert(
C->getType()->isIntOrIntVectorTy() &&
"ZEXt operand must be integral");
2156 "SrcTy must be smaller than DestTy for ZExt!");
2163 bool fromVec = isa<VectorType>(
C->getType());
2164 bool toVec = isa<VectorType>(Ty);
2166 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2169 "This is an illegal floating point truncation!");
2170 return getFoldedCast(Instruction::FPTrunc,
C, Ty, OnlyIfReduced);
2175 bool fromVec = isa<VectorType>(
C->getType());
2176 bool toVec = isa<VectorType>(Ty);
2178 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2181 "This is an illegal floating point extension!");
2187 bool fromVec = isa<VectorType>(
C->getType());
2188 bool toVec = isa<VectorType>(Ty);
2190 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2192 "This is an illegal uint to floating point cast!");
2198 bool fromVec = isa<VectorType>(
C->getType());
2199 bool toVec = isa<VectorType>(Ty);
2201 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2203 "This is an illegal sint to floating point cast!");
2209 bool fromVec = isa<VectorType>(
C->getType());
2210 bool toVec = isa<VectorType>(Ty);
2212 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2214 "This is an illegal floating point to uint cast!");
2220 bool fromVec = isa<VectorType>(
C->getType());
2221 bool toVec = isa<VectorType>(Ty);
2223 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2225 "This is an illegal floating point to sint cast!");
2230 bool OnlyIfReduced) {
2231 assert(
C->getType()->isPtrOrPtrVectorTy() &&
2232 "PtrToInt source must be pointer or pointer vector");
2234 "PtrToInt destination must be integer or integer vector");
2235 assert(isa<VectorType>(
C->getType()) == isa<VectorType>(DstTy));
2236 if (isa<VectorType>(
C->getType()))
2237 assert(cast<VectorType>(
C->getType())->getElementCount() ==
2238 cast<VectorType>(DstTy)->getElementCount() &&
2239 "Invalid cast between a different number of vector elements");
2240 return getFoldedCast(Instruction::PtrToInt,
C, DstTy, OnlyIfReduced);
2244 bool OnlyIfReduced) {
2245 assert(
C->getType()->isIntOrIntVectorTy() &&
2246 "IntToPtr source must be integer or integer vector");
2248 "IntToPtr destination must be a pointer or pointer vector");
2249 assert(isa<VectorType>(
C->getType()) == isa<VectorType>(DstTy));
2250 if (isa<VectorType>(
C->getType()))
2251 assert(cast<VectorType>(
C->getType())->getElementCount() ==
2252 cast<VectorType>(DstTy)->getElementCount() &&
2253 "Invalid cast between a different number of vector elements");
2254 return getFoldedCast(Instruction::IntToPtr,
C, DstTy, OnlyIfReduced);
2258 bool OnlyIfReduced) {
2260 "Invalid constantexpr bitcast!");
2264 if (
C->getType() == DstTy)
return C;
2266 return getFoldedCast(Instruction::BitCast,
C, DstTy, OnlyIfReduced);
2270 bool OnlyIfReduced) {
2272 "Invalid constantexpr addrspacecast!");
2276 PointerType *SrcScalarTy = cast<PointerType>(
C->getType()->getScalarType());
2281 if (
VectorType *VT = dyn_cast<VectorType>(DstTy)) {
2284 cast<FixedVectorType>(VT)->getNumElements());
2288 return getFoldedCast(Instruction::AddrSpaceCast,
C, DstTy, OnlyIfReduced);
2292 Type *OnlyIfReducedTy) {
2295 "Invalid opcode in unary constant expression");
2299 case Instruction::FNeg:
2300 assert(
C->getType()->isFPOrFPVectorTy() &&
2301 "Tried to create a floating-point operation on a "
2302 "non-floating-point type!");
2312 if (OnlyIfReducedTy ==
C->getType())
2323 unsigned Flags,
Type *OnlyIfReducedTy) {
2326 "Invalid opcode in binary constant expression");
2328 "Operand types in binary constant expression should match");
2333 case Instruction::Sub:
2335 case Instruction::UDiv:
2336 case Instruction::SDiv:
2337 case Instruction::URem:
2338 case Instruction::SRem:
2339 assert(
C1->getType()->isIntOrIntVectorTy() &&
2340 "Tried to create an integer operation on a non-integer type!");
2342 case Instruction::FAdd:
2343 case Instruction::FSub:
2344 case Instruction::FMul:
2345 case Instruction::FDiv:
2346 case Instruction::FRem:
2347 assert(
C1->getType()->isFPOrFPVectorTy() &&
2348 "Tried to create a floating-point operation on a "
2349 "non-floating-point type!");
2351 case Instruction::And:
2352 case Instruction::Or:
2353 case Instruction::Xor:
2354 assert(
C1->getType()->isIntOrIntVectorTy() &&
2355 "Tried to create a logical operation on a non-integral type!");
2357 case Instruction::Shl:
2358 case Instruction::LShr:
2359 case Instruction::AShr:
2360 assert(
C1->getType()->isIntOrIntVectorTy() &&
2361 "Tried to create a shift operation on a non-integer type!");
2371 if (OnlyIfReducedTy ==
C1->getType())
2398 Constant *Indices[2] = { Zero, One };
2423 Constant *C2,
bool OnlyIfReduced) {
2424 assert(
C1->getType() == C2->
getType() &&
"Op types should be identical!");
2445 Type *OnlyIfReducedTy) {
2451 if (OnlyIfReducedTy == V1->
getType())
2464 Type *OnlyIfReducedTy) {
2465 PointerType *OrigPtrTy = cast<PointerType>(
C->getType()->getScalarType());
2466 assert(Ty &&
"Must specify element type");
2475 assert(DestTy &&
"GEP indices invalid!");
2482 if (
VectorType *VecTy = dyn_cast<VectorType>(
C->getType()))
2483 EltCount = VecTy->getElementCount();
2485 for (
auto Idx : Idxs)
2486 if (
VectorType *VecTy = dyn_cast<VectorType>(Idx->getType()))
2487 EltCount = VecTy->getElementCount();
2489 if (EltCount.isNonZero())
2492 if (OnlyIfReducedTy == ReqTy)
2496 std::vector<Constant*> ArgVec;
2497 ArgVec.reserve(1 + Idxs.size());
2498 ArgVec.push_back(
C);
2500 for (; GTI != GTE; ++GTI) {
2501 auto *Idx = cast<Constant>(GTI.getOperand());
2503 (!isa<VectorType>(Idx->getType()) ||
2504 cast<VectorType>(Idx->getType())->getElementCount() == EltCount) &&
2505 "getelementptr index type missmatch");
2507 if (GTI.isStruct() && Idx->getType()->isVectorTy()) {
2508 Idx = Idx->getSplatValue();
2509 }
else if (GTI.isSequential() && EltCount.isNonZero() &&
2510 !Idx->getType()->isVectorTy()) {
2513 ArgVec.push_back(Idx);
2516 unsigned SubClassOptionalData = InBounds ? GEPOperator::IsInBounds : 0;
2517 if (InRangeIndex && *InRangeIndex < 63)
2518 SubClassOptionalData |= (*InRangeIndex + 1) << 1;
2520 SubClassOptionalData,
None,
None, Ty);
2577 Type *OnlyIfReducedTy) {
2579 "Tried to create extractelement operation on non-vector type!");
2581 "Extractelement index must be an integer type!");
2586 Type *ReqTy = cast<VectorType>(Val->
getType())->getElementType();
2587 if (OnlyIfReducedTy == ReqTy)
2601 "Tried to create insertelement operation on non-vector type!");
2603 "Insertelement types must match!");
2605 "Insertelement index must be i32 type!");
2610 if (OnlyIfReducedTy == Val->
getType())
2614 Constant *ArgVec[] = { Val, Elt, Idx };
2623 Type *OnlyIfReducedTy) {
2625 "Invalid shuffle vector constant expr operands!");
2630 unsigned NElts =
Mask.size();
2631 auto V1VTy = cast<VectorType>(V1->
getType());
2632 Type *EltTy = V1VTy->getElementType();
2633 bool TypeIsScalable = isa<ScalableVectorType>(V1VTy);
2636 if (OnlyIfReducedTy == ShufTy)
2649 Type *OnlyIfReducedTy) {
2651 "Non-first-class type for constant insertvalue expression");
2655 "insertvalue indices invalid!");
2661 if (OnlyIfReducedTy == ReqTy)
2672 assert(
C->getType()->isIntOrIntVectorTy() &&
2673 "Cannot NEG a nonintegral value!");
2679 assert(
C->getType()->isFPOrFPVectorTy() &&
2680 "Cannot FNEG a non-floating-point value!");
2681 return get(Instruction::FNeg,
C);
2685 assert(
C->getType()->isIntOrIntVectorTy() &&
2686 "Cannot NOT a nonintegral value!");
2691 bool HasNUW,
bool HasNSW) {
2698 return get(Instruction::FAdd,
C1, C2);
2702 bool HasNUW,
bool HasNSW) {
2705 return get(Instruction::Sub,
C1, C2, Flags);
2709 return get(Instruction::FSub,
C1, C2);
2713 bool HasNUW,
bool HasNSW) {
2720 return get(Instruction::FMul,
C1, C2);
2724 return get(Instruction::UDiv,
C1, C2,
2729 return get(Instruction::SDiv,
C1, C2,
2734 return get(Instruction::FDiv,
C1, C2);
2738 return get(Instruction::URem,
C1, C2);
2742 return get(Instruction::SRem,
C1, C2);
2746 return get(Instruction::FRem,
C1, C2);
2750 return get(Instruction::And,
C1, C2);
2754 return get(Instruction::Or,
C1, C2);
2758 return get(Instruction::Xor,
C1, C2);
2767 bool HasNUW,
bool HasNSW) {
2770 return get(Instruction::Shl,
C1, C2, Flags);
2774 return get(Instruction::LShr,
C1, C2,
2779 return get(Instruction::AShr,
C1, C2,
2784 Type *Ty =
C->getType();
2790 auto *VecTy = dyn_cast<FixedVectorType>(Ty);
2795 for (
unsigned I = 0,
E = VecTy->getNumElements();
I !=
E; ++
I) {
2800 if (isa<UndefValue>(Elt)) {
2813 bool AllowRHSConstant,
bool NSZ) {
2820 case Instruction::Or:
2821 case Instruction::Xor:
2825 case Instruction::And:
2827 case Instruction::FAdd:
2829 case Instruction::FMul:
2837 if (!AllowRHSConstant)
2841 case Instruction::Sub:
2842 case Instruction::Shl:
2843 case Instruction::LShr:
2844 case Instruction::AShr:
2845 case Instruction::FSub:
2847 case Instruction::SDiv:
2848 case Instruction::UDiv:
2850 case Instruction::FDiv:
2863 case Instruction::Or:
2866 case Instruction::And:
2873 void ConstantExpr::destroyConstantImpl() {
2881 GetElementPtrConstantExpr::GetElementPtrConstantExpr(
2885 (IdxList.
size() + 1),
2886 IdxList.
size() + 1),
2887 SrcElementTy(SrcElementTy),
2891 for (
unsigned i = 0,
E = IdxList.
size();
i !=
E; ++
i)
2892 OperandList[
i+1] = IdxList[
i];
2896 return SrcElementTy;
2900 return ResElementTy;
2908 return ATy->getElementType();
2909 return cast<VectorType>(
getType())->getElementType();
2919 if (
auto *
IT = dyn_cast<IntegerType>(Ty)) {
2920 switch (
IT->getBitWidth()) {
2934 return AT->getNumElements();
2935 return cast<FixedVectorType>(
getType())->getNumElements();
2944 const char *ConstantDataSequential::getElementPointer(
unsigned Elt)
const {
2964 if (
ArrayType *ATy = dyn_cast<ArrayType>(Ty))
2984 std::unique_ptr<ConstantDataSequential> *Entry = &Slot.second;
2985 for (; *Entry; Entry = &(*Entry)->Next)
2986 if ((*Entry)->getType() == Ty)
2987 return Entry->get();
2991 if (isa<ArrayType>(Ty)) {
2994 return Entry->get();
2997 assert(isa<VectorType>(Ty));
3000 return Entry->get();
3003 void ConstantDataSequential::destroyConstantImpl() {
3010 assert(Slot != CDSConstants.
end() &&
"CDS not found in uniquing table");
3012 std::unique_ptr<ConstantDataSequential> *Entry = &Slot->getValue();
3015 if (!(*Entry)->Next) {
3018 assert(Entry->get() ==
this &&
"Hash mismatch in ConstantDataSequential");
3026 std::unique_ptr<ConstantDataSequential> &Node = *Entry;
3027 assert(Node &&
"Didn't find entry in its uniquing hash table!");
3029 if (Node.get() ==
this) {
3034 Entry = &Node->Next;
3046 "Element type is not a 16-bit float type");
3048 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 "Element type is not a 64-bit float type");
3061 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3068 const uint8_t *
Data = Str.bytes_begin();
3073 ElementVals.
append(Str.begin(), Str.end());
3074 ElementVals.push_back(0);
3083 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3088 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3093 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3098 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3103 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3108 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3121 "Element type is not a 16-bit float type");
3123 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3128 assert(ElementType->
isFloatTy() &&
"Element type is not a 32-bit float type");
3130 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3136 "Element type is not a 64-bit float type");
3138 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3144 "Element type not compatible with ConstantData");
3146 if (CI->getType()->isIntegerTy(8)) {
3150 if (CI->getType()->isIntegerTy(16)) {
3154 if (CI->getType()->isIntegerTy(32)) {
3158 assert(CI->getType()->isIntegerTy(64) &&
"Unsupported ConstantData type");
3163 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(V)) {
3164 if (CFP->getType()->isHalfTy()) {
3166 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3169 if (CFP->getType()->isBFloatTy()) {
3171 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3174 if (CFP->getType()->isFloatTy()) {
3176 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3179 if (CFP->getType()->isDoubleTy()) {
3181 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3191 "Accessor can only be used when element is an integer");
3192 const char *EltPtr = getElementPointer(Elt);
3199 return *
reinterpret_cast<const uint8_t *
>(EltPtr);
3201 return *
reinterpret_cast<const uint16_t *
>(EltPtr);
3203 return *
reinterpret_cast<const uint32_t *
>(EltPtr);
3205 return *
reinterpret_cast<const uint64_t *
>(EltPtr);
3211 "Accessor can only be used when element is an integer");
3212 const char *EltPtr = getElementPointer(Elt);
3219 auto EltVal = *
reinterpret_cast<const uint8_t *
>(EltPtr);
3220 return APInt(8, EltVal);
3223 auto EltVal = *
reinterpret_cast<const uint16_t *
>(EltPtr);
3224 return APInt(16, EltVal);
3227 auto EltVal = *
reinterpret_cast<const uint32_t *
>(EltPtr);
3228 return APInt(32, EltVal);
3231 auto EltVal = *
reinterpret_cast<const uint64_t *
>(EltPtr);
3232 return APInt(64, EltVal);
3238 const char *EltPtr = getElementPointer(Elt);
3242 llvm_unreachable(
"Accessor can only be used when element is float/double!");
3244 auto EltVal = *
reinterpret_cast<const uint16_t *
>(EltPtr);
3248 auto EltVal = *
reinterpret_cast<const uint16_t *
>(EltPtr);
3252 auto EltVal = *
reinterpret_cast<const uint32_t *
>(EltPtr);
3256 auto EltVal = *
reinterpret_cast<const uint64_t *
>(EltPtr);
3264 "Accessor can only be used when element is a 'float'");
3265 return *
reinterpret_cast<const float *
>(getElementPointer(Elt));
3270 "Accessor can only be used when element is a 'float'");
3271 return *
reinterpret_cast<const double *
>(getElementPointer(Elt));
3293 if (Str.back() != 0)
return false;
3296 return !Str.drop_back().contains(0);
3299 bool ConstantDataVector::isSplatData()
const {
3314 IsSplat = isSplatData();
3339 Value *Replacement =
nullptr;
3343 #define HANDLE_CONSTANT(Name) \
3344 case Value::Name##Val: \
3345 Replacement = cast<Name>(this)->handleOperandChangeImpl(From, To); \
3347 #include "llvm/IR/Value.def"
3356 assert(Replacement !=
this &&
"I didn't contain From!");
3366 assert(isa<Constant>(To) &&
"Cannot make Constant refer to non-constant!");
3367 Constant *ToC = cast<Constant>(To);
3374 unsigned NumUpdated = 0;
3377 bool AllSame =
true;
3379 unsigned OperandNo = 0;
3381 Constant *Val = cast<Constant>(
O->get());
3383 OperandNo = (
O - OperandList);
3387 Values.push_back(Val);
3388 AllSame &= Val == ToC;
3394 if (AllSame && isa<UndefValue>(ToC))
3403 Values,
this,
From, ToC, NumUpdated, OperandNo);
3407 assert(isa<Constant>(To) &&
"Cannot make Constant refer to non-constant!");
3408 Constant *ToC = cast<Constant>(To);
3417 unsigned NumUpdated = 0;
3418 bool AllSame =
true;
3419 unsigned OperandNo = 0;
3421 Constant *Val = cast<Constant>(
O->get());
3423 OperandNo = (
O - OperandList);
3427 Values.push_back(Val);
3428 AllSame &= Val == ToC;
3434 if (AllSame && isa<UndefValue>(ToC))
3439 Values,
this,
From, ToC, NumUpdated, OperandNo);
3443 assert(isa<Constant>(To) &&
"Cannot make Constant refer to non-constant!");
3444 Constant *ToC = cast<Constant>(To);
3448 unsigned NumUpdated = 0;
3449 unsigned OperandNo = 0;
3457 Values.push_back(Val);
3465 Values,
this,
From, ToC, NumUpdated, OperandNo);
3469 assert(isa<Constant>(ToV) &&
"Cannot make Constant refer to non-constant!");
3470 Constant *To = cast<Constant>(ToV);
3473 unsigned NumUpdated = 0;
3474 unsigned OperandNo = 0;
3482 NewOps.push_back(
Op);
3484 assert(NumUpdated &&
"I didn't contain From!");
3491 NewOps,
this,
From, To, NumUpdated, OperandNo);
3499 case Instruction::Trunc:
3500 case Instruction::ZExt:
3501 case Instruction::SExt:
3502 case Instruction::FPTrunc:
3503 case Instruction::FPExt:
3504 case Instruction::UIToFP:
3505 case Instruction::SIToFP:
3506 case Instruction::FPToUI:
3507 case Instruction::FPToSI:
3508 case Instruction::PtrToInt:
3509 case Instruction::IntToPtr:
3510 case Instruction::BitCast:
3511 case Instruction::AddrSpaceCast:
3516 case Instruction::InsertElement:
3518 case Instruction::ExtractElement:
3520 case Instruction::InsertValue:
3523 case Instruction::ShuffleVector:
3527 case Instruction::GetElementPtr: {
3528 const auto *GO = cast<GEPOperator>(
this);
3529 if (GO->isInBounds())
3531 GO->getSourceElementType(), Ops[0], Ops.
slice(1),
"", InsertBefore);
3533 Ops.
slice(1),
"", InsertBefore);
3535 case Instruction::ICmp:
3536 case Instruction::FCmp:
3540 case Instruction::FNeg:
3547 if (isa<OverflowingBinaryOperator>(BO)) {
3553 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 Constant * getFDiv(Constant *C1, Constant *C2)
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)
static Constant * getFRem(Constant *C1, Constant *C2)
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.
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 InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
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 * getInsertValue(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
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
bool isNotOneValue() const
Return true if the value is not the one value, or, for vectors, does not contain one value elements.
bool hasIndices() const
Return true if this is an insertvalue or extractvalue expression, and the getIndices() method may be ...
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.
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.
LLVM_NODISCARD T pop_back_val()
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 six 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.
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.
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)
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.
FunctionType * getType(LLVMContext &Context, ID id, ArrayRef< Type * > Tys=None)
Return the function type for an intrinsic.
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")
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
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
UnaryConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to implemen...
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")
static Constant * getUDiv(Constant *C1, Constant *C2, bool isExact=false)
@ 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
InsertValueConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to im...
Constant * ConstantFoldGetElementPtr(Type *Ty, Constant *C, bool InBounds, Optional< unsigned > InRangeIndex, ArrayRef< Value * > Idxs)
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 * getURem(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.
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
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...
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)
static ElementCount getFixed(ScalarTy MinVal)
unsigned getIntegerBitWidth() const
static Constant * getFNeg(Constant *C)
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...
Constant * ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs)
ConstantFoldInsertValueInstruction - Attempt to constant fold an insertvalue instruction with the spe...
static Constant * getZero(Type *Ty, bool Negative=false)
ArrayRef< unsigned > getIndices() const
Assert that this is an insertvalue or exactvalue expression and return the list of indices.
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 * get(unsigned Opcode, Constant *C1, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a unary operator constant expression, folding if possible.
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 * getFSub(Constant *C1, Constant *C2)
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....
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)
@ 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.
static Constant * getFMul(Constant *C1, Constant *C2)
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
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
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 Constant * getSDiv(Constant *C1, Constant *C2, bool isExact=false)
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.
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)
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false, Optional< unsigned > InRangeIndex=None, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
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.
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
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.
Type * getResultElementType() const
This instruction constructs a fixed permutation of two input vectors.
static constexpr roundingMode rmNearestTiesToEven
static UnaryOperator * Create(UnaryOps Op, Value *S, const Twine &Name=Twine(), Instruction *InsertBefore=nullptr)
Construct a unary instruction, given the opcode and an operand.
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.
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
static Constant * getSRem(Constant *C1, Constant *C2)
InsertElementConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
static bool canTrapImpl(const Constant *C, SmallPtrSetImpl< const Constant * > &NonTrappingOps)
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...
bool canTrap() const
Return true if evaluation of this constant could trap.
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)
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.
const LLVM_NODISCARD char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
@ 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.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
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.
Constant * ConstantFoldUnaryInstruction(unsigned Opcode, Constant *V)
static Constant * getFAdd(Constant *C1, Constant *C2)
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)
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)