36using 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) {
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) {
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) {
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) {
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();
321 if (
Constant *Elem =
C->getAggregateElement(i))
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)
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)
464#define HANDLE_CONSTANT(Name) \
465 case Value::Name##Val: \
466 cast<Name>(this)->destroyConstantImpl(); \
468#include "llvm/IR/Value.def"
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();
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<ExtractElementConstantExpr>(
C))
552 else if (isa<InsertElementConstantExpr>(
C))
554 else if (isa<ShuffleVectorConstantExpr>(
C))
556 else if (isa<GetElementPtrConstantExpr>(
C))
558 else if (isa<CompareConstantExpr>(
C))
577 while (!WorkList.
empty()) {
579 if (
const auto *GV = dyn_cast<GlobalValue>(
WorkItem))
583 const Constant *ConstOp = dyn_cast<Constant>(
Op);
586 if (Visited.
insert(ConstOp).second)
594 auto DLLImportPredicate = [](
const GlobalValue *GV) {
595 return GV->isThreadLocal();
601 auto DLLImportPredicate = [](
const GlobalValue *GV) {
602 return GV->hasDLLImportStorageClass();
609 const Constant *UC = dyn_cast<Constant>(U);
610 if (!UC || isa<GlobalValue>(UC))
620 return getRelocationInfo() == GlobalRelocation;
624 return getRelocationInfo() != NoRelocation;
627Constant::PossibleRelocationsTy Constant::getRelocationInfo()
const {
628 if (isa<GlobalValue>(
this))
629 return GlobalRelocation;
631 if (
const BlockAddress *BA = dyn_cast<BlockAddress>(
this))
632 return BA->getFunction()->getRelocationInfo();
634 if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(
this)) {
635 if (CE->getOpcode() == Instruction::Sub) {
638 if (LHS && RHS &&
LHS->getOpcode() == Instruction::PtrToInt &&
639 RHS->getOpcode() == Instruction::PtrToInt) {
647 if (isa<BlockAddress>(LHSOp0) && isa<BlockAddress>(RHSOp0) &&
656 if (
auto *LHSGV = dyn_cast<GlobalValue>(LHS)) {
657 if (LHSGV->isDSOLocal() && RHSGV->isDSOLocal())
658 return LocalRelocation;
659 }
else if (isa<DSOLocalEquivalent>(LHS)) {
660 if (RHSGV->isDSOLocal())
661 return LocalRelocation;
668 PossibleRelocationsTy
Result = NoRelocation;
671 std::max(cast<Constant>(
getOperand(i))->getRelocationInfo(), Result);
680 if (isa<GlobalValue>(
C))
return false;
685 if (!
User)
return false;
698 if (RemoveDeadUsers) {
702 const_cast<Constant *
>(
C)->destroyConstant();
728 if (LastNonDeadUser ==
E)
731 I = std::next(LastNonDeadUser);
739bool Constant::hasNLiveUses(
unsigned N)
const {
740 unsigned NumUses = 0;
754 assert(
C && Replacement &&
"Expected non-nullptr constant arguments");
755 Type *Ty =
C->getType();
757 assert(Ty == Replacement->
getType() &&
"Expected matching types");
762 auto *VTy = dyn_cast<FixedVectorType>(Ty);
766 unsigned NumElts = VTy->getNumElements();
768 for (
unsigned i = 0; i != NumElts; ++i) {
769 Constant *EltC =
C->getAggregateElement(i);
771 "Expected matching types");
772 NewC[i] = EltC &&
match(EltC,
m_Undef()) ? Replacement : EltC;
778 assert(
C &&
Other &&
"Expected non-nullptr constant arguments");
782 Type *Ty =
C->getType();
786 auto *VTy = dyn_cast<FixedVectorType>(Ty);
790 Type *EltTy = VTy->getElementType();
791 unsigned NumElts = VTy->getNumElements();
793 cast<FixedVectorType>(
Other->getType())->getNumElements() == NumElts &&
796 bool FoundExtraUndef =
false;
798 for (
unsigned I = 0;
I != NumElts; ++
I) {
799 NewC[
I] =
C->getAggregateElement(
I);
801 assert(NewC[
I] && OtherEltC &&
"Unknown vector element");
804 FoundExtraUndef =
true;
813 if (isa<ConstantData>(
this))
815 if (isa<ConstantAggregate>(
this) || isa<ConstantExpr>(
this)) {
854 if (
auto *VTy = dyn_cast<VectorType>(Ty))
862 if (
auto *VTy = dyn_cast<VectorType>(Ty))
875 std::unique_ptr<ConstantInt> &Slot =
892 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
905 "ConstantInt type doesn't match the type implied by its value!");
908 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
919void ConstantInt::destroyConstantImpl() {
937 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
946 "ConstantFP type doesn't match the type implied by its value!");
949 if (
auto *VTy = dyn_cast<VectorType>(Ty))
962 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
973 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
984 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
995 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1006 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1017 std::unique_ptr<ConstantFP> &Slot = pImpl->
FPConstants[V];
1031 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1040 "FP type Mismatch");
1048void ConstantFP::destroyConstantImpl() {
1057 if (
auto *AT = dyn_cast<ArrayType>(
getType()))
1080 if (
auto *AT = dyn_cast<ArrayType>(Ty))
1082 if (
auto *VT = dyn_cast<VectorType>(Ty))
1083 return VT->getElementCount();
1115 if (
auto *AT = dyn_cast<ArrayType>(Ty))
1116 return AT->getNumElements();
1117 if (
auto *VT = dyn_cast<VectorType>(Ty))
1118 return cast<FixedVectorType>(VT)->getNumElements();
1152template <
typename ItTy,
typename EltTy>
1154 for (; Start !=
End; ++Start)
1160template <
typename SequentialTy,
typename ElementTy>
1162 assert(!V.empty() &&
"Cannot get empty int sequence.");
1166 if (
auto *CI = dyn_cast<ConstantInt>(
C))
1170 return SequentialTy::get(V[0]->getContext(), Elts);
1173template <
typename SequentialTy,
typename ElementTy>
1175 assert(!V.empty() &&
"Cannot get empty FP sequence.");
1179 if (
auto *CFP = dyn_cast<ConstantFP>(
C))
1180 Elts.
push_back(CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
1183 return SequentialTy::getFP(V[0]->
getType(), Elts);
1186template <
typename SequenceTy>
1193 if (CI->getType()->isIntegerTy(8))
1194 return getIntSequenceIfElementsMatch<SequenceTy, uint8_t>(V);
1195 else if (CI->getType()->isIntegerTy(16))
1196 return getIntSequenceIfElementsMatch<SequenceTy, uint16_t>(V);
1197 else if (CI->getType()->isIntegerTy(32))
1198 return getIntSequenceIfElementsMatch<SequenceTy, uint32_t>(V);
1199 else if (CI->getType()->isIntegerTy(64))
1200 return getIntSequenceIfElementsMatch<SequenceTy, uint64_t>(V);
1201 }
else if (
ConstantFP *CFP = dyn_cast<ConstantFP>(
C)) {
1202 if (CFP->getType()->isHalfTy() || CFP->getType()->isBFloatTy())
1203 return getFPSequenceIfElementsMatch<SequenceTy, uint16_t>(V);
1204 else if (CFP->getType()->isFloatTy())
1205 return getFPSequenceIfElementsMatch<SequenceTy, uint32_t>(V);
1206 else if (CFP->getType()->isDoubleTy())
1207 return getFPSequenceIfElementsMatch<SequenceTy, uint64_t>(V);
1220 if (
auto *ST = dyn_cast<StructType>(
T)) {
1223 for (
unsigned I = 0,
E = V.size();
I !=
E; ++
I)
1225 "Initializer for struct element doesn't match!");
1231 assert(V.size() ==
T->getNumElements() &&
1232 "Invalid initializer for constant array");
1248 "Wrong type in array element initializer");
1268 return getSequenceIfElementsMatch<ConstantDataArray>(
C, V);
1277 unsigned VecSize = V.size();
1279 for (
unsigned i = 0; i != VecSize; ++i)
1280 EltTypes[i] = V[i]->
getType();
1289 "ConstantStruct::getTypeForElements cannot be called on empty list");
1295 assert((
T->isOpaque() || V.size() ==
T->getNumElements()) &&
1296 "Invalid initializer for constant struct");
1301 assert((ST->isOpaque() || ST->getNumElements() == V.size()) &&
1302 "Incorrect # elements specified to ConstantStruct::get");
1307 bool isPoison =
false;
1310 isUndef = isa<UndefValue>(V[0]);
1311 isPoison = isa<PoisonValue>(V[0]);
1312 isZero = V[0]->isNullValue();
1316 if (!
C->isNullValue())
1318 if (!isa<PoisonValue>(
C))
1320 if (isa<PoisonValue>(
C) || !isa<UndefValue>(
C))
1332 return ST->getContext().pImpl->StructConstants.getOrCreate(ST, V);
1337 assert(V.size() == cast<FixedVectorType>(
T)->getNumElements() &&
1338 "Invalid initializer for constant vector");
1350 assert(!V.empty() &&
"Vectors can't be empty");
1356 bool isZero =
C->isNullValue();
1358 bool isPoison = isa<PoisonValue>(
C);
1361 for (
unsigned i = 1, e = V.size(); i != e; ++i)
1378 return getSequenceIfElementsMatch<ConstantDataVector>(
C, V);
1386 if (!EC.isScalable()) {
1389 if ((isa<ConstantFP>(V) || isa<ConstantInt>(V)) &&
1399 if (V->isNullValue())
1401 else if (isa<UndefValue>(V))
1423void ConstantTokenNone::destroyConstantImpl() {
1439 return cast<CompareConstantExpr>(
this)->predicate;
1443 return cast<ShuffleVectorConstantExpr>(
this)->ShuffleMask;
1447 return cast<ShuffleVectorConstantExpr>(
this)->ShuffleMaskForBitcode;
1451 bool OnlyIfReduced,
Type *SrcTy)
const {
1458 Type *OnlyIfReducedTy = OnlyIfReduced ? Ty :
nullptr;
1460 case Instruction::Trunc:
1461 case Instruction::ZExt:
1462 case Instruction::SExt:
1463 case Instruction::FPTrunc:
1464 case Instruction::FPExt:
1465 case Instruction::UIToFP:
1466 case Instruction::SIToFP:
1467 case Instruction::FPToUI:
1468 case Instruction::FPToSI:
1469 case Instruction::PtrToInt:
1470 case Instruction::IntToPtr:
1471 case Instruction::BitCast:
1472 case Instruction::AddrSpaceCast:
1474 case Instruction::InsertElement:
1477 case Instruction::ExtractElement:
1479 case Instruction::ShuffleVector:
1482 case Instruction::GetElementPtr: {
1483 auto *GEPO = cast<GEPOperator>(
this);
1486 SrcTy ? SrcTy : GEPO->getSourceElementType(), Ops[0], Ops.
slice(1),
1487 GEPO->isInBounds(), GEPO->getInRangeIndex(), OnlyIfReducedTy);
1489 case Instruction::ICmp:
1490 case Instruction::FCmp:
1507 return Val == 0 || Val == 1;
1514 return Val == 0 || Val == 1 || Val == -1;
1515 return isIntN(NumBits, Val);
1581 "Cannot create an aggregate zero of non-aggregate type!");
1583 std::unique_ptr<ConstantAggregateZero> &Entry =
1592void ConstantAggregateZero::destroyConstantImpl() {
1597void ConstantArray::destroyConstantImpl() {
1606void ConstantStruct::destroyConstantImpl() {
1611void ConstantVector::destroyConstantImpl() {
1616 assert(this->
getType()->isVectorTy() &&
"Only valid for vectors!");
1617 if (isa<ConstantAggregateZero>(
this))
1620 return CV->getSplatValue();
1622 return CV->getSplatValue(AllowUndefs);
1626 const auto *Shuf = dyn_cast<ConstantExpr>(
this);
1627 if (Shuf && Shuf->getOpcode() == Instruction::ShuffleVector &&
1628 isa<UndefValue>(Shuf->getOperand(1))) {
1630 const auto *IElt = dyn_cast<ConstantExpr>(Shuf->getOperand(0));
1631 if (IElt && IElt->getOpcode() == Instruction::InsertElement &&
1632 isa<UndefValue>(IElt->getOperand(0))) {
1661 if (isa<UndefValue>(OpC))
1665 if (isa<UndefValue>(Elt))
1675 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
1676 return CI->getValue();
1678 if (isa<ConstantExpr>(
this))
1679 return cast<ConstantInt>(this->
getSplatValue())->getValue();
1684 assert(
C && isa<ConstantInt>(
C) &&
"Not a vector of numbers!");
1685 return cast<ConstantInt>(
C)->getValue();
1692 std::unique_ptr<ConstantPointerNull> &Entry =
1701void ConstantPointerNull::destroyConstantImpl() {
1710 "Target extension type not allowed to have a zeroinitializer");
1711 std::unique_ptr<ConstantTargetNone> &Entry =
1720void ConstantTargetNone::destroyConstantImpl() {
1733void UndefValue::destroyConstantImpl() {
1752void PoisonValue::destroyConstantImpl() {
1764 F->getContext().pImpl->BlockAddresses[std::make_pair(
F, BB)];
1774 Value::BlockAddressVal, &
Op<0>(), 2) {
1777 BB->AdjustBlockAddressRefCount(1);
1785 assert(
F &&
"Block must have a parent");
1787 F->getContext().pImpl->BlockAddresses.lookup(std::make_pair(
F, BB));
1788 assert(BA &&
"Refcount and block address map disagree!");
1793void BlockAddress::destroyConstantImpl() {
1808 assert(
From == NewBB &&
"From does not match any operand");
1809 NewBB = cast<BasicBlock>(To);
1841 "DSOLocalFunction does not match the expected global value");
1845DSOLocalEquivalent::DSOLocalEquivalent(
GlobalValue *GV)
1851void DSOLocalEquivalent::destroyConstantImpl() {
1858 assert(isa<Constant>(To) &&
"Can only replace the operands with a constant");
1861 if (
const auto *ToObj = dyn_cast<GlobalValue>(To)) {
1898 assert(
NC->getGlobalValue() == GV &&
1899 "NoCFIValue does not match the expected global value");
1909void NoCFIValue::destroyConstantImpl() {
1918 assert(GV &&
"Can only replace the operands with a global value");
1940 bool OnlyIfReduced =
false) {
1958 bool OnlyIfReduced) {
1962 "Cast opcode not supported as constant expression");
1963 assert(
C && Ty &&
"Null arguments to getCast");
1969 case Instruction::Trunc:
1971 case Instruction::PtrToInt:
1973 case Instruction::IntToPtr:
1975 case Instruction::BitCast:
1977 case Instruction::AddrSpaceCast:
2016 bool fromVec = isa<VectorType>(
C->getType());
2017 bool toVec = isa<VectorType>(Ty);
2019 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2020 assert(
C->getType()->isIntOrIntVectorTy() &&
"Trunc operand must be integer");
2023 "SrcTy must be larger than DestTy for Trunc!");
2029 bool OnlyIfReduced) {
2030 assert(
C->getType()->isPtrOrPtrVectorTy() &&
2031 "PtrToInt source must be pointer or pointer vector");
2033 "PtrToInt destination must be integer or integer vector");
2034 assert(isa<VectorType>(
C->getType()) == isa<VectorType>(DstTy));
2035 if (isa<VectorType>(
C->getType()))
2036 assert(cast<VectorType>(
C->getType())->getElementCount() ==
2037 cast<VectorType>(DstTy)->getElementCount() &&
2038 "Invalid cast between a different number of vector elements");
2039 return getFoldedCast(Instruction::PtrToInt,
C, DstTy, OnlyIfReduced);
2043 bool OnlyIfReduced) {
2044 assert(
C->getType()->isIntOrIntVectorTy() &&
2045 "IntToPtr source must be integer or integer vector");
2047 "IntToPtr destination must be a pointer or pointer vector");
2048 assert(isa<VectorType>(
C->getType()) == isa<VectorType>(DstTy));
2049 if (isa<VectorType>(
C->getType()))
2050 assert(cast<VectorType>(
C->getType())->getElementCount() ==
2051 cast<VectorType>(DstTy)->getElementCount() &&
2052 "Invalid cast between a different number of vector elements");
2053 return getFoldedCast(Instruction::IntToPtr,
C, DstTy, OnlyIfReduced);
2057 bool OnlyIfReduced) {
2059 "Invalid constantexpr bitcast!");
2063 if (
C->getType() == DstTy)
return C;
2065 return getFoldedCast(Instruction::BitCast,
C, DstTy, OnlyIfReduced);
2069 bool OnlyIfReduced) {
2071 "Invalid constantexpr addrspacecast!");
2072 return getFoldedCast(Instruction::AddrSpaceCast,
C, DstTy, OnlyIfReduced);
2076 unsigned Flags,
Type *OnlyIfReducedTy) {
2079 "Invalid opcode in binary constant expression");
2081 "Binop not supported as constant expression");
2083 "Operand types in binary constant expression should match");
2087 case Instruction::Add:
2088 case Instruction::Sub:
2089 case Instruction::Mul:
2091 "Tried to create an integer operation on a non-integer type!");
2093 case Instruction::And:
2094 case Instruction::Or:
2095 case Instruction::Xor:
2097 "Tried to create a logical operation on a non-integral type!");
2099 case Instruction::Shl:
2100 case Instruction::LShr:
2101 case Instruction::AShr:
2103 "Tried to create a shift operation on a non-integer type!");
2113 if (OnlyIfReducedTy == C1->
getType())
2125 case Instruction::UDiv:
2126 case Instruction::SDiv:
2127 case Instruction::URem:
2128 case Instruction::SRem:
2129 case Instruction::FAdd:
2130 case Instruction::FSub:
2131 case Instruction::FMul:
2132 case Instruction::FDiv:
2133 case Instruction::FRem:
2134 case Instruction::And:
2135 case Instruction::Or:
2136 case Instruction::LShr:
2137 case Instruction::AShr:
2139 case Instruction::Add:
2140 case Instruction::Sub:
2141 case Instruction::Mul:
2142 case Instruction::Shl:
2143 case Instruction::Xor:
2152 case Instruction::UDiv:
2153 case Instruction::SDiv:
2154 case Instruction::URem:
2155 case Instruction::SRem:
2156 case Instruction::FAdd:
2157 case Instruction::FSub:
2158 case Instruction::FMul:
2159 case Instruction::FDiv:
2160 case Instruction::FRem:
2161 case Instruction::And:
2162 case Instruction::Or:
2163 case Instruction::LShr:
2164 case Instruction::AShr:
2166 case Instruction::Add:
2167 case Instruction::Sub:
2168 case Instruction::Mul:
2169 case Instruction::Shl:
2170 case Instruction::Xor:
2179 case Instruction::ZExt:
2180 case Instruction::SExt:
2181 case Instruction::FPTrunc:
2182 case Instruction::FPExt:
2183 case Instruction::UIToFP:
2184 case Instruction::SIToFP:
2185 case Instruction::FPToUI:
2186 case Instruction::FPToSI:
2188 case Instruction::Trunc:
2189 case Instruction::PtrToInt:
2190 case Instruction::IntToPtr:
2191 case Instruction::BitCast:
2192 case Instruction::AddrSpaceCast:
2201 case Instruction::ZExt:
2202 case Instruction::SExt:
2203 case Instruction::FPTrunc:
2204 case Instruction::FPExt:
2205 case Instruction::UIToFP:
2206 case Instruction::SIToFP:
2207 case Instruction::FPToUI:
2208 case Instruction::FPToSI:
2210 case Instruction::Trunc:
2211 case Instruction::PtrToInt:
2212 case Instruction::IntToPtr:
2213 case Instruction::BitCast:
2214 case Instruction::AddrSpaceCast:
2238 Constant *Indices[2] = { Zero, One };
2245 Constant *C2,
bool OnlyIfReduced) {
2248 switch (Predicate) {
2256 return getFCmp(Predicate, C1, C2, OnlyIfReduced);
2262 return getICmp(Predicate, C1, C2, OnlyIfReduced);
2268 std::optional<unsigned> InRangeIndex,
2269 Type *OnlyIfReducedTy) {
2270 assert(Ty &&
"Must specify element type");
2278 "GEP indices invalid!");;
2282 if (OnlyIfReducedTy == ReqTy)
2286 if (
VectorType *VecTy = dyn_cast<VectorType>(ReqTy))
2287 EltCount = VecTy->getElementCount();
2290 std::vector<Constant*> ArgVec;
2291 ArgVec.reserve(1 + Idxs.
size());
2292 ArgVec.push_back(
C);
2294 for (; GTI != GTE; ++GTI) {
2295 auto *
Idx = cast<Constant>(GTI.getOperand());
2297 (!isa<VectorType>(
Idx->getType()) ||
2298 cast<VectorType>(
Idx->getType())->getElementCount() == EltCount) &&
2299 "getelementptr index type missmatch");
2301 if (GTI.isStruct() &&
Idx->getType()->isVectorTy()) {
2302 Idx =
Idx->getSplatValue();
2303 }
else if (GTI.isSequential() && EltCount.isNonZero() &&
2304 !
Idx->getType()->isVectorTy()) {
2307 ArgVec.push_back(
Idx);
2310 unsigned SubClassOptionalData = InBounds ? GEPOperator::IsInBounds : 0;
2311 if (InRangeIndex && *InRangeIndex < 63)
2312 SubClassOptionalData |= (*InRangeIndex + 1) << 1;
2314 SubClassOptionalData, std::nullopt, Ty);
2321 Constant *RHS,
bool OnlyIfReduced) {
2346 Constant *RHS,
bool OnlyIfReduced) {
2371 Type *OnlyIfReducedTy) {
2373 "Tried to create extractelement operation on non-vector type!");
2375 "Extractelement index must be an integer type!");
2380 Type *ReqTy = cast<VectorType>(Val->
getType())->getElementType();
2381 if (OnlyIfReducedTy == ReqTy)
2395 "Tried to create insertelement operation on non-vector type!");
2397 "Insertelement types must match!");
2399 "Insertelement index must be i32 type!");
2404 if (OnlyIfReducedTy == Val->
getType())
2417 Type *OnlyIfReducedTy) {
2419 "Invalid shuffle vector constant expr operands!");
2424 unsigned NElts = Mask.size();
2425 auto V1VTy = cast<VectorType>(V1->
getType());
2426 Type *EltTy = V1VTy->getElementType();
2427 bool TypeIsScalable = isa<ScalableVectorType>(V1VTy);
2430 if (OnlyIfReducedTy == ShufTy)
2442 assert(
C->getType()->isIntOrIntVectorTy() &&
2443 "Cannot NEG a nonintegral value!");
2448 assert(
C->getType()->isIntOrIntVectorTy() &&
2449 "Cannot NOT a nonintegral value!");
2454 bool HasNUW,
bool HasNSW) {
2457 return get(Instruction::Add, C1, C2, Flags);
2461 bool HasNUW,
bool HasNSW) {
2464 return get(Instruction::Sub, C1, C2, Flags);
2468 bool HasNUW,
bool HasNSW) {
2471 return get(Instruction::Mul, C1, C2, Flags);
2475 return get(Instruction::Xor, C1, C2);
2479 bool HasNUW,
bool HasNSW) {
2482 return get(Instruction::Shl, C1, C2, Flags);
2486 Type *Ty =
C->getType();
2492 auto *VecTy = dyn_cast<FixedVectorType>(Ty);
2497 for (
unsigned I = 0,
E = VecTy->getNumElements();
I !=
E; ++
I) {
2502 if (isa<UndefValue>(Elt)) {
2515 bool AllowRHSConstant,
bool NSZ) {
2521 case Instruction::Add:
2522 case Instruction::Or:
2523 case Instruction::Xor:
2525 case Instruction::Mul:
2527 case Instruction::And:
2529 case Instruction::FAdd:
2531 case Instruction::FMul:
2539 if (!AllowRHSConstant)
2543 case Instruction::Sub:
2544 case Instruction::Shl:
2545 case Instruction::LShr:
2546 case Instruction::AShr:
2547 case Instruction::FSub:
2549 case Instruction::SDiv:
2550 case Instruction::UDiv:
2552 case Instruction::FDiv:
2561 case Intrinsic::umax:
2563 case Intrinsic::umin:
2565 case Intrinsic::smax:
2568 case Intrinsic::smin:
2577 bool AllowRHSConstant,
bool NSZ) {
2578 if (
I->isBinaryOp())
2591 case Instruction::Or:
2594 case Instruction::And:
2595 case Instruction::Mul:
2601void ConstantExpr::destroyConstantImpl() {
2609GetElementPtrConstantExpr::GetElementPtrConstantExpr(
2613 (IdxList.
size() + 1),
2614 IdxList.
size() + 1),
2615 SrcElementTy(SrcElementTy),
2619 for (
unsigned i = 0,
E = IdxList.
size(); i !=
E; ++i)
2620 OperandList[i+1] = IdxList[i];
2624 return SrcElementTy;
2628 return ResElementTy;
2636 return ATy->getElementType();
2637 return cast<VectorType>(
getType())->getElementType();
2647 if (
auto *
IT = dyn_cast<IntegerType>(Ty)) {
2648 switch (
IT->getBitWidth()) {
2662 return AT->getNumElements();
2663 return cast<FixedVectorType>(
getType())->getNumElements();
2672const char *ConstantDataSequential::getElementPointer(
unsigned Elt)
const {
2692 if (
ArrayType *ATy = dyn_cast<ArrayType>(Ty))
2712 std::unique_ptr<ConstantDataSequential> *Entry = &Slot.second;
2713 for (; *Entry; Entry = &(*Entry)->Next)
2714 if ((*Entry)->getType() == Ty)
2715 return Entry->get();
2719 if (isa<ArrayType>(Ty)) {
2722 return Entry->get();
2725 assert(isa<VectorType>(Ty));
2728 return Entry->get();
2731void ConstantDataSequential::destroyConstantImpl() {
2738 assert(Slot != CDSConstants.
end() &&
"CDS not found in uniquing table");
2740 std::unique_ptr<ConstantDataSequential> *Entry = &Slot->getValue();
2743 if (!(*Entry)->Next) {
2746 assert(Entry->get() ==
this &&
"Hash mismatch in ConstantDataSequential");
2754 std::unique_ptr<ConstantDataSequential> &
Node = *Entry;
2755 assert(
Node &&
"Didn't find entry in its uniquing hash table!");
2757 if (
Node.get() ==
this) {
2762 Entry = &
Node->Next;
2774 "Element type is not a 16-bit float type");
2776 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2780 assert(ElementType->
isFloatTy() &&
"Element type is not a 32-bit float type");
2782 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2787 "Element type is not a 64-bit float type");
2789 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2796 const uint8_t *
Data = Str.bytes_begin();
2801 ElementVals.
append(Str.begin(), Str.end());
2811 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2816 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2821 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2826 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2831 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2836 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2849 "Element type is not a 16-bit float type");
2851 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2856 assert(ElementType->
isFloatTy() &&
"Element type is not a 32-bit float type");
2858 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2864 "Element type is not a 64-bit float type");
2866 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2872 "Element type not compatible with ConstantData");
2874 if (CI->getType()->isIntegerTy(8)) {
2876 return get(V->getContext(), Elts);
2878 if (CI->getType()->isIntegerTy(16)) {
2880 return get(V->getContext(), Elts);
2882 if (CI->getType()->isIntegerTy(32)) {
2884 return get(V->getContext(), Elts);
2886 assert(CI->getType()->isIntegerTy(64) &&
"Unsupported ConstantData type");
2888 return get(V->getContext(), Elts);
2891 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(V)) {
2892 if (CFP->getType()->isHalfTy()) {
2894 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
2895 return getFP(V->getType(), Elts);
2897 if (CFP->getType()->isBFloatTy()) {
2899 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
2900 return getFP(V->getType(), Elts);
2902 if (CFP->getType()->isFloatTy()) {
2904 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
2905 return getFP(V->getType(), Elts);
2907 if (CFP->getType()->isDoubleTy()) {
2909 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
2910 return getFP(V->getType(), Elts);
2919 "Accessor can only be used when element is an integer");
2920 const char *EltPtr = getElementPointer(Elt);
2927 return *
reinterpret_cast<const uint8_t *
>(EltPtr);
2929 return *
reinterpret_cast<const uint16_t *
>(EltPtr);
2931 return *
reinterpret_cast<const uint32_t *
>(EltPtr);
2933 return *
reinterpret_cast<const uint64_t *
>(EltPtr);
2939 "Accessor can only be used when element is an integer");
2940 const char *EltPtr = getElementPointer(Elt);
2947 auto EltVal = *
reinterpret_cast<const uint8_t *
>(EltPtr);
2948 return APInt(8, EltVal);
2951 auto EltVal = *
reinterpret_cast<const uint16_t *
>(EltPtr);
2952 return APInt(16, EltVal);
2955 auto EltVal = *
reinterpret_cast<const uint32_t *
>(EltPtr);
2956 return APInt(32, EltVal);
2959 auto EltVal = *
reinterpret_cast<const uint64_t *
>(EltPtr);
2960 return APInt(64, EltVal);
2966 const char *EltPtr = getElementPointer(Elt);
2970 llvm_unreachable(
"Accessor can only be used when element is float/double!");
2972 auto EltVal = *
reinterpret_cast<const uint16_t *
>(EltPtr);
2976 auto EltVal = *
reinterpret_cast<const uint16_t *
>(EltPtr);
2980 auto EltVal = *
reinterpret_cast<const uint32_t *
>(EltPtr);
2984 auto EltVal = *
reinterpret_cast<const uint64_t *
>(EltPtr);
2992 "Accessor can only be used when element is a 'float'");
2993 return *
reinterpret_cast<const float *
>(getElementPointer(Elt));
2998 "Accessor can only be used when element is a 'float'");
2999 return *
reinterpret_cast<const double *
>(getElementPointer(Elt));
3021 if (Str.back() != 0)
return false;
3024 return !Str.drop_back().contains(0);
3027bool ConstantDataVector::isSplatData()
const {
3042 IsSplat = isSplatData();
3067 Value *Replacement =
nullptr;
3071#define HANDLE_CONSTANT(Name) \
3072 case Value::Name##Val: \
3073 Replacement = cast<Name>(this)->handleOperandChangeImpl(From, To); \
3075#include "llvm/IR/Value.def"
3084 assert(Replacement !=
this &&
"I didn't contain From!");
3094 assert(isa<Constant>(To) &&
"Cannot make Constant refer to non-constant!");
3095 Constant *ToC = cast<Constant>(To);
3102 unsigned NumUpdated = 0;
3105 bool AllSame =
true;
3107 unsigned OperandNo = 0;
3109 Constant *Val = cast<Constant>(O->get());
3111 OperandNo = (O - OperandList);
3116 AllSame &= Val == ToC;
3122 if (AllSame && isa<UndefValue>(ToC))
3131 Values,
this,
From, ToC, NumUpdated, OperandNo);
3135 assert(isa<Constant>(To) &&
"Cannot make Constant refer to non-constant!");
3136 Constant *ToC = cast<Constant>(To);
3145 unsigned NumUpdated = 0;
3146 bool AllSame =
true;
3147 unsigned OperandNo = 0;
3149 Constant *Val = cast<Constant>(
O->get());
3151 OperandNo = (
O - OperandList);
3156 AllSame &= Val == ToC;
3162 if (AllSame && isa<UndefValue>(ToC))
3167 Values,
this,
From, ToC, NumUpdated, OperandNo);
3171 assert(isa<Constant>(To) &&
"Cannot make Constant refer to non-constant!");
3172 Constant *ToC = cast<Constant>(To);
3176 unsigned NumUpdated = 0;
3177 unsigned OperandNo = 0;
3193 Values,
this,
From, ToC, NumUpdated, OperandNo);
3197 assert(isa<Constant>(ToV) &&
"Cannot make Constant refer to non-constant!");
3198 Constant *To = cast<Constant>(ToV);
3201 unsigned NumUpdated = 0;
3202 unsigned OperandNo = 0;
3212 assert(NumUpdated &&
"I didn't contain From!");
3219 NewOps,
this,
From, To, NumUpdated, OperandNo);
3227 case Instruction::Trunc:
3228 case Instruction::ZExt:
3229 case Instruction::SExt:
3230 case Instruction::FPTrunc:
3231 case Instruction::FPExt:
3232 case Instruction::UIToFP:
3233 case Instruction::SIToFP:
3234 case Instruction::FPToUI:
3235 case Instruction::FPToSI:
3236 case Instruction::PtrToInt:
3237 case Instruction::IntToPtr:
3238 case Instruction::BitCast:
3239 case Instruction::AddrSpaceCast:
3242 case Instruction::InsertElement:
3244 case Instruction::ExtractElement:
3246 case Instruction::ShuffleVector:
3250 case Instruction::GetElementPtr: {
3251 const auto *GO = cast<GEPOperator>(
this);
3252 if (GO->isInBounds())
3254 GO->getSourceElementType(), Ops[0], Ops.
slice(1),
"", InsertBefore);
3256 Ops.
slice(1),
"", InsertBefore);
3258 case Instruction::ICmp:
3259 case Instruction::FCmp:
3267 if (isa<OverflowingBinaryOperator>(BO)) {
3273 if (isa<PossiblyExactOperator>(BO))
This file defines the StringMap class.
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::values(clEnumValN(DefaultIT, "arm-default-it", "Generate any type of IT block"), clEnumValN(RestrictedIT, "arm-restrict-it", "Disallow complex IT blocks")))
BlockVerifier::State From
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static bool isAllZeros(StringRef Arr)
Return true if the array is empty or all zeros.
static Constant * getFPSequenceIfElementsMatch(ArrayRef< Constant * > V)
static bool rangeOnlyContains(ItTy Start, ItTy End, EltTy Elt)
static Constant * getIntSequenceIfElementsMatch(ArrayRef< Constant * > V)
static Constant * getSequenceIfElementsMatch(Constant *C, ArrayRef< Constant * > V)
static bool ConstHasGlobalValuePredicate(const Constant *C, bool(*Predicate)(const GlobalValue *))
Check if C contains a GlobalValue for which Predicate is true.
static bool constantIsDead(const Constant *C, bool RemoveDeadUsers)
Return true if the specified constantexpr is dead.
static bool containsUndefinedElement(const Constant *C, function_ref< bool(const Constant *)> HasFn)
static Constant * getFoldedCast(Instruction::CastOps opc, Constant *C, Type *Ty, bool OnlyIfReduced=false)
This is a utility function to handle folding of casts and lookup of the cast in the ExprConstants map...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
Looks at all the uses of the given value Returns the Liveness deduced from the uses of this value Adds all uses that cause the result to be MaybeLive to MaybeLiveRetUses If the result is MaybeLiveUses might be modified but its content should be ignored(since it might not be complete). DeadArgumentEliminationPass
static Function * getFunction(Constant *C)
static bool isSigned(unsigned int Opcode)
static char getTypeID(Type *Ty)
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
static bool isUndef(ArrayRef< int > Mask)
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
Merge contiguous icmps into a memcmp
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
static SymbolRef::Type getType(const Symbol *Sym)
static constexpr uint32_t Opcode
static APFloat getQNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for QNaN values.
static APFloat getSNaN(const fltSemantics &Sem, bool Negative=false, const APInt *payload=nullptr)
Factory for SNaN values.
opStatus convert(const fltSemantics &ToSemantics, roundingMode RM, bool *losesInfo)
bool bitwiseIsEqual(const APFloat &RHS) const
static APFloat getAllOnesValue(const fltSemantics &Semantics)
Returns a float which is bitcasted from an all one value int.
const fltSemantics & getSemantics() const
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
static APFloat getNaN(const fltSemantics &Sem, bool Negative=false, uint64_t payload=0)
Factory for NaN values.
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Class for arbitrary precision integers.
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
unsigned logBase2() const
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Class to represent array types.
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
Type * getElementType() const
LLVM Basic Block Representation.
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches,...
const Function * getParent() const
Return the enclosing method, or null if none.
BinaryConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to impleme...
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.
The address of a basic block.
static BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
Function * getFunction() const
BasicBlock * getBasicBlock() const
static BlockAddress * get(Function *F, BasicBlock *BB)
Return a BlockAddress for the specified function and basic block.
CastConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to implement...
static 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 ...
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.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
@ FCMP_OEQ
0 0 0 1 True if ordered and equal
@ FCMP_TRUE
1 1 1 1 Always true (always folded)
@ ICMP_SLT
signed less than
@ ICMP_SLE
signed less or equal
@ FCMP_OLT
0 1 0 0 True if ordered and less than
@ FCMP_ULE
1 1 0 1 True if unordered, less than, or equal
@ FCMP_OGT
0 0 1 0 True if ordered and greater than
@ FCMP_OGE
0 0 1 1 True if ordered and greater than or equal
@ ICMP_UGE
unsigned greater or equal
@ ICMP_UGT
unsigned greater than
@ ICMP_SGT
signed greater than
@ FCMP_ULT
1 1 0 0 True if unordered or less than
@ FCMP_ONE
0 1 1 0 True if ordered and operands are unequal
@ FCMP_UEQ
1 0 0 1 True if unordered or equal
@ ICMP_ULT
unsigned less than
@ FCMP_UGT
1 0 1 0 True if unordered or greater than
@ FCMP_OLE
0 1 0 1 True if ordered and less than or equal
@ FCMP_ORD
0 1 1 1 True if ordered (no nans)
@ ICMP_SGE
signed greater or equal
@ FCMP_UNE
1 1 1 0 True if unordered or not equal
@ ICMP_ULE
unsigned less or equal
@ FCMP_UGE
1 0 1 1 True if unordered, greater than, or equal
@ FCMP_FALSE
0 0 0 0 Always false (always folded)
@ FCMP_UNO
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
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.
bool isFPPredicate() const
bool isIntPredicate() const
All zero aggregate value.
ElementCount getElementCount() const
Return the number of elements in the array, vector, or struct.
Constant * getSequentialElement() const
If this CAZ has array or vector type, return a zero with the right element type.
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 * getStructElement(unsigned Elt) const
If this CAZ has struct type, return a zero with the right element type for the specified element.
static ConstantAggregateZero * get(Type *Ty)
Base class for aggregate constants (with operands).
ConstantAggregate(Type *T, ValueTy VT, ArrayRef< Constant * > V)
ConstantArray - Constant Array Declarations.
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
ArrayType * getType() const
Specialize the getType() method to always return an ArrayType, which reduces the amount of casting ne...
An array constant whose element type is a simple 1/2/4/8-byte integer or float/double,...
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
This method constructs a CDS and initializes it with a text string.
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
static Constant * getFP(Type *ElementType, ArrayRef< uint16_t > Elts)
getFP() constructors - Return a constant of array type with a float element type taken from argument ...
APInt getElementAsAPInt(unsigned i) const
If this is a sequential container of integers (of any size), return the specified element as an APInt...
double getElementAsDouble(unsigned i) const
If this is an sequential container of doubles, return the specified element as a double.
StringRef getAsString() const
If this array is isString(), then this method returns the array as a StringRef.
uint64_t getElementByteSize() const
Return the size (in bytes) of each element in the array/vector.
float getElementAsFloat(unsigned i) const
If this is an sequential container of floats, return the specified element as a float.
bool isString(unsigned CharSize=8) const
This method returns true if this is an array of CharSize integers.
uint64_t getElementAsInteger(unsigned i) const
If this is a sequential container of integers (of any size), return the specified element in the low ...
static Constant * getImpl(StringRef Bytes, Type *Ty)
This is the underlying implementation of all of the ConstantDataSequential::get methods.
unsigned getNumElements() const
Return the number of elements in the array or vector.
Constant * getElementAsConstant(unsigned i) const
Return a Constant for a specified index's element.
Type * getElementType() const
Return the element type of the array/vector.
bool isCString() const
This method returns true if the array "isString", ends with a null byte, and does not contains any ot...
APFloat getElementAsAPFloat(unsigned i) const
If this is a sequential container of floating point type, return the specified element as an APFloat.
StringRef getRawDataValues() const
Return the raw, underlying, bytes of this data.
static bool isElementTypeCompatible(Type *Ty)
Return true if a ConstantDataSequential can be formed with a vector or array of the specified element...
A vector constant whose element type is a simple 1/2/4/8-byte integer or float/double,...
Constant * getSplatValue() const
If this is a splat constant, meaning that all of the elements have the same value,...
static Constant * getSplat(unsigned NumElts, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
bool isSplat() const
Returns true if this is a splat constant, meaning that all elements have the same value.
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...
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...
Base class for constants with no operands.
A constant value that is initialized with an expression using other constant values.
static Constant * getFCmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static Constant * getAlignOf(Type *Ty)
getAlignOf constant expr - computes the alignment of a type in a target independent way (Note: the re...
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
static Constant * getTruncOrBitCast(Constant *C, Type *Ty)
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
bool isCast() const
Return true if this is a convert constant expression.
static Constant * getIdentity(Instruction *I, Type *Ty, bool AllowRHSConstant=false, bool NSZ=false)
Return the identity constant for a binary or intrinsic Instruction.
static bool isDesirableCastOp(unsigned Opcode)
Whether creating a constant expression for this cast is desirable.
Constant * getShuffleMaskForBitcode() const
Assert that this is a shufflevector and return the mask.
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static Constant * getNot(Constant *C)
const char * getOpcodeName() const
Return a string representation for an opcode.
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
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...
Instruction * getAsInstruction(Instruction *InsertBefore=nullptr) const
Returns an Instruction which implements the same operation as this ConstantExpr.
bool isCompare() const
Return true if this is a compare constant expression.
static Constant * getShuffleVector(Constant *V1, Constant *V2, ArrayRef< int > Mask, Type *OnlyIfReducedTy=nullptr)
static Constant * getSizeOf(Type *Ty)
getSizeOf constant expr - computes the (alloc) size of a type (in address-units, not bits) in a targe...
static bool isSupportedGetElementPtr(const Type *SrcElemTy)
Whether creating a constant expression for this getelementptr type is supported.
static Constant * getIntrinsicIdentity(Intrinsic::ID, Type *Ty)
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false, std::optional< unsigned > InRangeIndex=std::nullopt, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
static Constant * getXor(Constant *C1, Constant *C2)
static Constant * getBinOpAbsorber(unsigned Opcode, Type *Ty)
Return the absorbing element for the given binary operation, i.e.
static Constant * getMul(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static Constant * getShl(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.
static bool isDesirableBinOp(unsigned Opcode)
Whether creating a constant expression for this binary operator is desirable.
unsigned getPredicate() const
Return the ICMP or FCMP predicate value.
ArrayRef< int > getShuffleMask() const
Assert that this is a shufflevector and return the mask.
static bool isSupportedBinOp(unsigned Opcode)
Whether creating a constant expression for this binary operator is supported.
static Constant * getAddrSpaceCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getBinOpIdentity(unsigned Opcode, Type *Ty, bool AllowRHSConstant=false, bool NSZ=false)
Return the identity constant for a binary opcode.
static bool isSupportedCastOp(unsigned Opcode)
Whether creating a constant expression for this cast is supported.
static Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
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...
Constant * getWithOperands(ArrayRef< Constant * > Ops) const
This returns the current constant expression with the operands replaced with the specified values.
static Constant * getNeg(Constant *C, bool HasNUW=false, bool HasNSW=false)
static Constant * getCompare(unsigned short pred, Constant *C1, Constant *C2, bool OnlyIfReduced=false)
Return an ICmp or FCmp comparison operator constant expression.
ConstantFP - Floating Point Values [float, double].
static Constant * getSNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
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 Constant * getInfinity(Type *Ty, bool Negative=false)
static Constant * getZero(Type *Ty, bool Negative=false)
static Constant * getNaN(Type *Ty, bool Negative=false, uint64_t Payload=0)
bool isExactlyValue(const APFloat &V) const
We don't rely on operator== working on double values, as it returns true for things that are clearly ...
static bool isValueValidForType(Type *Ty, const APFloat &V)
Return true if Ty is big enough to represent V.
static Constant * getQNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
This is the shared class of boolean and integer constants.
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 ConstantInt * getTrue(LLVMContext &Context)
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.
static ConstantInt * getFalse(LLVMContext &Context)
static ConstantInt * getBool(LLVMContext &Context, bool V)
A constant pointer value that points to null.
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
PointerType * getType() const
Specialize the getType() method to always return an PointerType, which reduces the amount of casting ...
static Constant * get(StructType *T, ArrayRef< Constant * > V)
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.
StructType * getType() const
Specialization - reduce amount of casting.
A constant target extension type default initializer.
static ConstantTargetNone * get(TargetExtType *T)
Static factory methods - Return objects of the specified value.
TargetExtType * getType() const
Specialize the getType() method to always return an TargetExtType, which reduces the amount of castin...
A constant token which is empty.
static ConstantTokenNone * get(LLVMContext &Context)
Return the ConstantTokenNone.
ConstantClass * getOrCreate(TypeClass *Ty, ValType V)
Return the specified constant from the map, creating it if necessary.
void remove(ConstantClass *CP)
Remove this constant from the map.
ConstantClass * replaceOperandsInPlace(ArrayRef< Constant * > Operands, ConstantClass *CP, Value *From, Constant *To, unsigned NumUpdated=0, unsigned OperandNo=~0u)
Constant Vector Declarations.
Constant * getSplatValue(bool AllowUndefs=false) const
If all elements of the vector constant have the same value, return that value.
FixedVectorType * getType() const
Specialize the getType() method to always return a FixedVectorType, which reduces the amount of casti...
static Constant * getSplat(ElementCount EC, Constant *Elt)
Return a ConstantVector with the specified constant in each element.
static Constant * get(ArrayRef< Constant * > V)
This is an important base class in LLVM.
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...
static Constant * replaceUndefsWith(Constant *C, Constant *Replacement)
Try to replace undefined constant C or undefined elements in C with Replacement.
bool containsUndefElement() const
Return true if this is a vector constant that includes any strictly undef (not poison) elements.
Constant * getSplatValue(bool AllowUndefs=false) const
If all elements of the vector constant have the same value, return that value.
static Constant * mergeUndefsWith(Constant *C, Constant *Other)
Merges undefs of a Constant with another Constant, along with the undefs already present.
static Constant * getAllOnesValue(Type *Ty)
bool hasZeroLiveUses() const
Return true if the constant has no live uses.
bool isOneValue() const
Returns true if the value is one.
bool isManifestConstant() const
Return true if a constant is ConstantData or a ConstantAggregate or ConstantExpr that contain only Co...
bool isNegativeZeroValue() const
Return true if the value is what would be returned by getZeroValueForNegation.
bool isAllOnesValue() const
Return true if this is the value that would be returned by getAllOnesValue.
bool hasOneLiveUse() const
Return true if the constant has exactly one live use.
bool needsRelocation() const
This method classifies the entry according to whether or not it may generate a relocation entry (eith...
bool isDLLImportDependent() const
Return true if the value is dependent on a dllimport variable.
const APInt & getUniqueInteger() const
If C is a constant integer then return its value, otherwise C must be a vector of constant integers,...
bool containsConstantExpression() const
Return true if this is a fixed width vector constant that includes any constant expressions.
bool isFiniteNonZeroFP() const
Return true if this is a finite and non-zero floating-point scalar constant or a fixed width vector c...
void removeDeadConstantUsers() const
If there are any dead constant users dangling off of this constant, remove them.
bool isNormalFP() const
Return true if this is a normal (as opposed to denormal, infinity, nan, or zero) floating-point scala...
bool needsDynamicRelocation() const
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
bool isNaN() const
Return true if this is a floating-point NaN constant or a vector floating-point constant with all NaN...
bool isMinSignedValue() const
Return true if the value is the smallest signed value.
bool isConstantUsed() const
Return true if the constant has users other than constant expressions and other dangling things.
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
bool isThreadDependent() const
Return true if the value can vary between threads.
bool isZeroValue() const
Return true if the value is negative zero or null value.
void destroyConstant()
Called if some element of this constant is no longer valid.
bool isNotMinSignedValue() const
Return true if the value is not the smallest signed value, or, for vectors, does not contain smallest...
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
bool isNotOneValue() const
Return true if the value is not the one value, or, for vectors, does not contain one value elements.
bool isElementWiseEqual(Value *Y) const
Return true if this constant and a constant 'Y' are element-wise equal.
bool containsUndefOrPoisonElement() const
Return true if this is a vector constant that includes any undef or poison elements.
bool containsPoisonElement() const
Return true if this is a vector constant that includes any poison elements.
void handleOperandChange(Value *, Value *)
This method is a special form of User::replaceUsesOfWith (which does not work on constants) that does...
Wrapper for a function that represents a value that functionally represents the original function.
GlobalValue * getGlobalValue() const
static DSOLocalEquivalent * get(GlobalValue *GV)
Return a DSOLocalEquivalent for the specified global value.
This class represents an Operation in the Expression.
static constexpr ElementCount getFixed(ScalarTy MinVal)
static FixedVectorType * get(Type *ElementType, unsigned NumElts)
GetElementPtrConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
Type * getResultElementType() const
Type * getSourceElementType() const
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
static GetElementPtrInst * CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Create an "inbounds" getelementptr.
static Type * getGEPReturnType(Value *Ptr, ArrayRef< Value * > IdxList)
Returns the pointer type returned by the GEP instruction, which may be a vector of pointers.
static Type * getIndexedType(Type *Ty, ArrayRef< Value * > IdxList)
Returns the result type of a getelementptr with the given source element type and indexes.
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
PointerType * getType() const
Global values are always pointers.
InsertElementConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.
bool isCommutative() const LLVM_READONLY
Return true if the instruction is commutative:
const char * getOpcodeName() const
void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag.
Class to represent integer types.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
A wrapper class for inspecting calls to intrinsic functions.
DenseMap< unsigned, std::unique_ptr< ConstantInt > > IntOneConstants
DenseMap< unsigned, std::unique_ptr< ConstantInt > > IntZeroConstants
DenseMap< APFloat, std::unique_ptr< ConstantFP > > FPConstants
DenseMap< PointerType *, std::unique_ptr< ConstantPointerNull > > CPNConstants
DenseMap< Type *, std::unique_ptr< ConstantAggregateZero > > CAZConstants
ConstantInt * TheFalseVal
DenseMap< Type *, std::unique_ptr< PoisonValue > > PVConstants
DenseMap< std::pair< const Function *, const BasicBlock * >, BlockAddress * > BlockAddresses
DenseMap< APInt, std::unique_ptr< ConstantInt > > IntConstants
std::unique_ptr< ConstantTokenNone > TheNoneToken
VectorConstantsTy VectorConstants
DenseMap< const GlobalValue *, NoCFIValue * > NoCFIValues
DenseMap< Type *, std::unique_ptr< UndefValue > > UVConstants
StringMap< std::unique_ptr< ConstantDataSequential > > CDSConstants
StructConstantsTy StructConstants
DenseMap< TargetExtType *, std::unique_ptr< ConstantTargetNone > > CTNConstants
ConstantUniqueMap< ConstantExpr > ExprConstants
ArrayConstantsTy ArrayConstants
DenseMap< const GlobalValue *, DSOLocalEquivalent * > DSOLocalEquivalents
This is an important class for using LLVM in a threaded context.
LLVMContextImpl *const pImpl
Wrapper for a value that won't be replaced with a CFI jump table pointer in LowerTypeTestsModule.
static NoCFIValue * get(GlobalValue *GV)
Return a NoCFIValue for the specified function.
PointerType * getType() const
NoCFIValue is always a pointer.
GlobalValue * getGlobalValue() const
Class to represent pointers.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
In order to facilitate speculative execution, many instructions do not invoke immediate undefined beh...
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
PoisonValue * getStructElement(unsigned Elt) const
If this poison has struct type, return a poison with the right element type for the specified element...
PoisonValue * getSequentialElement() const
If this poison has array or vector type, return a poison with the right element type.
PoisonValue * getElementValue(Constant *C) const
Return an poison of the right value for the specified GEP index if we can, otherwise return null (e....
ShuffleVectorConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
This instruction constructs a fixed permutation of two input vectors.
static bool isValidOperands(const Value *V1, const Value *V2, const Value *Mask)
Return true if a shufflevector instruction can be formed with the specified operands.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void reserve(size_type N)
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
iterator find(StringRef Key)
StringRef - Represent a constant reference to a string, i.e.
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Class to represent struct types.
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Class to represent target extensions types, which are generally unintrospectable from target-independ...
bool hasProperty(Property Prop) const
Returns true if the target extension type contains the given property.
@ HasZeroInit
zeroinitializer is valid for this target extension type.
The instances of the Type class are immutable: once they are created, they are never changed.
unsigned getIntegerBitWidth() const
static Type * getDoubleTy(LLVMContext &C)
const fltSemantics & getFltSemantics() const
bool isVectorTy() const
True if this is an instance of VectorType.
static Type * getFloatingPointTy(LLVMContext &C, const fltSemantics &S)
bool isArrayTy() const
True if this is an instance of ArrayType.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
static IntegerType * getInt1Ty(LLVMContext &C)
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
unsigned getStructNumElements() const
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
@ HalfTyID
16-bit floating point type
@ TargetExtTyID
Target extension type.
@ ScalableVectorTyID
Scalable SIMD vector type.
@ FloatTyID
32-bit floating point type
@ IntegerTyID
Arbitrary bit width integers.
@ FixedVectorTyID
Fixed width SIMD vector type.
@ BFloatTyID
16-bit floating point type (7-bit significand)
@ DoubleTyID
64-bit floating point type
@ X86_FP80TyID
80-bit floating point type (X87)
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
@ FP128TyID
128-bit floating point type (112-bit significand)
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
bool isStructTy() const
True if this is an instance of StructType.
bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value.
static IntegerType * getInt16Ty(LLVMContext &C)
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
static IntegerType * getInt8Ty(LLVMContext &C)
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
static IntegerType * getInt32Ty(LLVMContext &C)
static IntegerType * getInt64Ty(LLVMContext &C)
static Type * getFloatTy(LLVMContext &C)
bool isIntegerTy() const
True if this is an instance of IntegerType.
TypeID getTypeID() const
Return the type id for the type.
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
'undef' values are things that do not have specified contents.
UndefValue * getElementValue(Constant *C) const
Return an undef of the right value for the specified GEP index if we can, otherwise return null (e....
UndefValue * getStructElement(unsigned Elt) const
If this undef has struct type, return a undef with the right element type for the specified element.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
unsigned getNumElements() const
Return the number of elements in the array, vector, or struct.
UndefValue * getSequentialElement() const
If this Undef has array or vector type, return a undef with the right element type.
A Use represents the edge between a Value definition and its users.
const Use * getOperandList() const
void setOperand(unsigned i, Value *Val)
Value * getOperand(unsigned i) const
unsigned getNumOperands() const
iterator_range< value_op_iterator > operand_values()
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
user_iterator_impl< const User > const_user_iterator
user_iterator user_begin()
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
const Value * stripPointerCastsAndAliases() const
Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
const Value * stripInBoundsConstantOffsets() const
Strip off pointer casts and all-constant inbounds GEPs.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
iterator_range< user_iterator > users()
unsigned getValueID() const
Return an ID for the concrete type of this object.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
LLVMContext & getContext() const
All values hold a context through their type.
iterator_range< use_iterator > uses()
void mutateType(Type *Ty)
Mutate the type of this Value to be of the specified type.
ValueTy
Concrete subclass of this.
Base class of all SIMD vector types.
ElementCount getElementCount() const
Return an ElementCount instance to represent the (possibly scalable) number of elements in the vector...
static VectorType * getInteger(VectorType *VTy)
This static method gets a VectorType with the same number of elements as the input type,...
static VectorType * get(Type *ElementType, ElementCount EC)
This static method is the primary way to construct an VectorType.
Type * getElementType() const
An efficient, type-erasing, non-owning reference to a callable.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
bool match(Val *V, const Pattern &P)
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
apint_match m_APInt(const APInt *&Res)
Match a ConstantInt or splatted ConstantVector, binding the specified pointer to the contained APInt.
auto m_Undef()
Match an arbitrary undef constant.
NodeAddr< FuncNode * > Func
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
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.
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Constant * ConstantFoldGetElementPtr(Type *Ty, Constant *C, bool InBounds, std::optional< unsigned > InRangeIndex, ArrayRef< Value * > Idxs)
Constant * ConstantFoldCompareInstruction(CmpInst::Predicate Predicate, Constant *C1, Constant *C2)
gep_type_iterator gep_type_end(const User *GEP)
void deleteConstant(Constant *C)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
Constant * ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt, Constant *Idx)
Attempt to constant fold an insertelement instruction with the specified operands and indices.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Constant * ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx)
Attempt to constant fold an extractelement instruction with the specified operands and indices.
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
OutputIt copy(R &&Range, OutputIt Out)
gep_type_iterator gep_type_begin(const User *GEP)
Constant * ConstantFoldCastInstruction(unsigned opcode, Constant *V, Type *DestTy)
Constant * ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2, ArrayRef< int > Mask)
Attempt to constant fold a shufflevector instruction with the specified operands and mask.
Constant * ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1, Constant *V2)
static const fltSemantics & IEEEsingle() LLVM_READNONE
static constexpr roundingMode rmNearestTiesToEven
static const fltSemantics & PPCDoubleDouble() LLVM_READNONE
static const fltSemantics & x87DoubleExtended() LLVM_READNONE
static const fltSemantics & IEEEquad() LLVM_READNONE
static const fltSemantics & IEEEdouble() LLVM_READNONE
static const fltSemantics & IEEEhalf() LLVM_READNONE
static const fltSemantics & BFloat() LLVM_READNONE
Compile-time customization of User operands.