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))
1024 std::unique_ptr<ConstantFP> &Slot = pImpl->
FPConstants[V];
1038 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1047 "FP type Mismatch");
1055void ConstantFP::destroyConstantImpl() {
1064 if (
auto *AT = dyn_cast<ArrayType>(
getType()))
1087 if (
auto *AT = dyn_cast<ArrayType>(Ty))
1089 if (
auto *VT = dyn_cast<VectorType>(Ty))
1090 return VT->getElementCount();
1122 if (
auto *AT = dyn_cast<ArrayType>(Ty))
1123 return AT->getNumElements();
1124 if (
auto *VT = dyn_cast<VectorType>(Ty))
1125 return cast<FixedVectorType>(VT)->getNumElements();
1159template <
typename ItTy,
typename EltTy>
1161 for (; Start != End; ++Start)
1167template <
typename SequentialTy,
typename ElementTy>
1169 assert(!V.empty() &&
"Cannot get empty int sequence.");
1173 if (
auto *CI = dyn_cast<ConstantInt>(
C))
1177 return SequentialTy::get(V[0]->getContext(), Elts);
1180template <
typename SequentialTy,
typename ElementTy>
1182 assert(!V.empty() &&
"Cannot get empty FP sequence.");
1186 if (
auto *CFP = dyn_cast<ConstantFP>(
C))
1187 Elts.
push_back(CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
1190 return SequentialTy::getFP(V[0]->
getType(), Elts);
1193template <
typename SequenceTy>
1200 if (CI->getType()->isIntegerTy(8))
1201 return getIntSequenceIfElementsMatch<SequenceTy, uint8_t>(V);
1202 else if (CI->getType()->isIntegerTy(16))
1203 return getIntSequenceIfElementsMatch<SequenceTy, uint16_t>(V);
1204 else if (CI->getType()->isIntegerTy(32))
1205 return getIntSequenceIfElementsMatch<SequenceTy, uint32_t>(V);
1206 else if (CI->getType()->isIntegerTy(64))
1207 return getIntSequenceIfElementsMatch<SequenceTy, uint64_t>(V);
1208 }
else if (
ConstantFP *CFP = dyn_cast<ConstantFP>(
C)) {
1209 if (CFP->getType()->isHalfTy() || CFP->getType()->isBFloatTy())
1210 return getFPSequenceIfElementsMatch<SequenceTy, uint16_t>(V);
1211 else if (CFP->getType()->isFloatTy())
1212 return getFPSequenceIfElementsMatch<SequenceTy, uint32_t>(V);
1213 else if (CFP->getType()->isDoubleTy())
1214 return getFPSequenceIfElementsMatch<SequenceTy, uint64_t>(V);
1227 if (
auto *ST = dyn_cast<StructType>(
T)) {
1230 for (
unsigned I = 0,
E = V.size();
I !=
E; ++
I)
1232 "Initializer for struct element doesn't match!");
1238 assert(V.size() ==
T->getNumElements() &&
1239 "Invalid initializer for constant array");
1255 "Wrong type in array element initializer");
1275 return getSequenceIfElementsMatch<ConstantDataArray>(
C, V);
1284 unsigned VecSize = V.size();
1286 for (
unsigned i = 0; i != VecSize; ++i)
1287 EltTypes[i] = V[i]->
getType();
1296 "ConstantStruct::getTypeForElements cannot be called on empty list");
1302 assert((
T->isOpaque() || V.size() ==
T->getNumElements()) &&
1303 "Invalid initializer for constant struct");
1308 assert((ST->isOpaque() || ST->getNumElements() == V.size()) &&
1309 "Incorrect # elements specified to ConstantStruct::get");
1314 bool isPoison =
false;
1317 isUndef = isa<UndefValue>(V[0]);
1318 isPoison = isa<PoisonValue>(V[0]);
1319 isZero = V[0]->isNullValue();
1323 if (!
C->isNullValue())
1325 if (!isa<PoisonValue>(
C))
1327 if (isa<PoisonValue>(
C) || !isa<UndefValue>(
C))
1339 return ST->getContext().pImpl->StructConstants.getOrCreate(ST, V);
1344 assert(V.size() == cast<FixedVectorType>(
T)->getNumElements() &&
1345 "Invalid initializer for constant vector");
1357 assert(!V.empty() &&
"Vectors can't be empty");
1363 bool isZero =
C->isNullValue();
1365 bool isPoison = isa<PoisonValue>(
C);
1368 for (
unsigned i = 1, e = V.size(); i != e; ++i)
1385 return getSequenceIfElementsMatch<ConstantDataVector>(
C, V);
1393 if (!EC.isScalable()) {
1396 if ((isa<ConstantFP>(V) || isa<ConstantInt>(V)) &&
1406 if (V->isNullValue())
1408 else if (isa<UndefValue>(V))
1430void ConstantTokenNone::destroyConstantImpl() {
1446 return cast<CompareConstantExpr>(
this)->predicate;
1450 return cast<ShuffleVectorConstantExpr>(
this)->ShuffleMask;
1454 return cast<ShuffleVectorConstantExpr>(
this)->ShuffleMaskForBitcode;
1458 bool OnlyIfReduced,
Type *SrcTy)
const {
1465 Type *OnlyIfReducedTy = OnlyIfReduced ? Ty :
nullptr;
1467 case Instruction::Trunc:
1468 case Instruction::ZExt:
1469 case Instruction::SExt:
1470 case Instruction::FPTrunc:
1471 case Instruction::FPExt:
1472 case Instruction::UIToFP:
1473 case Instruction::SIToFP:
1474 case Instruction::FPToUI:
1475 case Instruction::FPToSI:
1476 case Instruction::PtrToInt:
1477 case Instruction::IntToPtr:
1478 case Instruction::BitCast:
1479 case Instruction::AddrSpaceCast:
1481 case Instruction::InsertElement:
1484 case Instruction::ExtractElement:
1486 case Instruction::ShuffleVector:
1489 case Instruction::GetElementPtr: {
1490 auto *GEPO = cast<GEPOperator>(
this);
1493 SrcTy ? SrcTy : GEPO->getSourceElementType(), Ops[0], Ops.
slice(1),
1494 GEPO->isInBounds(), GEPO->getInRangeIndex(), OnlyIfReducedTy);
1496 case Instruction::ICmp:
1497 case Instruction::FCmp:
1514 return Val == 0 || Val == 1;
1521 return Val == 0 || Val == 1 || Val == -1;
1522 return isIntN(NumBits, Val);
1588 "Cannot create an aggregate zero of non-aggregate type!");
1590 std::unique_ptr<ConstantAggregateZero> &Entry =
1599void ConstantAggregateZero::destroyConstantImpl() {
1604void ConstantArray::destroyConstantImpl() {
1613void ConstantStruct::destroyConstantImpl() {
1618void ConstantVector::destroyConstantImpl() {
1623 assert(this->
getType()->isVectorTy() &&
"Only valid for vectors!");
1624 if (isa<ConstantAggregateZero>(
this))
1627 return CV->getSplatValue();
1629 return CV->getSplatValue(AllowUndefs);
1633 const auto *Shuf = dyn_cast<ConstantExpr>(
this);
1634 if (Shuf && Shuf->getOpcode() == Instruction::ShuffleVector &&
1635 isa<UndefValue>(Shuf->getOperand(1))) {
1637 const auto *IElt = dyn_cast<ConstantExpr>(Shuf->getOperand(0));
1638 if (IElt && IElt->getOpcode() == Instruction::InsertElement &&
1639 isa<UndefValue>(IElt->getOperand(0))) {
1668 if (isa<UndefValue>(OpC))
1672 if (isa<UndefValue>(Elt))
1682 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
1683 return CI->getValue();
1685 if (isa<ConstantExpr>(
this))
1686 return cast<ConstantInt>(this->
getSplatValue())->getValue();
1691 assert(
C && isa<ConstantInt>(
C) &&
"Not a vector of numbers!");
1692 return cast<ConstantInt>(
C)->getValue();
1699 std::unique_ptr<ConstantPointerNull> &Entry =
1708void ConstantPointerNull::destroyConstantImpl() {
1717 "Target extension type not allowed to have a zeroinitializer");
1718 std::unique_ptr<ConstantTargetNone> &Entry =
1727void ConstantTargetNone::destroyConstantImpl() {
1740void UndefValue::destroyConstantImpl() {
1759void PoisonValue::destroyConstantImpl() {
1771 F->getContext().pImpl->BlockAddresses[std::make_pair(
F, BB)];
1780 :
Constant(
Type::getInt8PtrTy(
F->getContext(),
F->getAddressSpace()),
1781 Value::BlockAddressVal, &Op<0>(), 2) {
1784 BB->AdjustBlockAddressRefCount(1);
1792 assert(
F &&
"Block must have a parent");
1794 F->getContext().pImpl->BlockAddresses.lookup(std::make_pair(
F, BB));
1795 assert(BA &&
"Refcount and block address map disagree!");
1800void BlockAddress::destroyConstantImpl() {
1815 assert(
From == NewBB &&
"From does not match any operand");
1816 NewBB = cast<BasicBlock>(To);
1848 "DSOLocalFunction does not match the expected global value");
1852DSOLocalEquivalent::DSOLocalEquivalent(
GlobalValue *GV)
1858void DSOLocalEquivalent::destroyConstantImpl() {
1865 assert(isa<Constant>(To) &&
"Can only replace the operands with a constant");
1868 if (
const auto *ToObj = dyn_cast<GlobalValue>(To)) {
1905 assert(
NC->getGlobalValue() == GV &&
1906 "NoCFIValue does not match the expected global value");
1916void NoCFIValue::destroyConstantImpl() {
1925 assert(GV &&
"Can only replace the operands with a global value");
1947 bool OnlyIfReduced =
false) {
1965 bool OnlyIfReduced) {
1968 assert(
C && Ty &&
"Null arguments to getCast");
1974 case Instruction::Trunc:
1976 case Instruction::ZExt:
1977 return getZExt(
C, Ty, OnlyIfReduced);
1978 case Instruction::SExt:
1979 return getSExt(
C, Ty, OnlyIfReduced);
1980 case Instruction::FPTrunc:
1982 case Instruction::FPExt:
1984 case Instruction::UIToFP:
1986 case Instruction::SIToFP:
1988 case Instruction::FPToUI:
1990 case Instruction::FPToSI:
1992 case Instruction::PtrToInt:
1994 case Instruction::IntToPtr:
1996 case Instruction::BitCast:
1998 case Instruction::AddrSpaceCast:
2023 "Can only sign extend/truncate integers!");
2024 Type *CTy =
C->getType();
2059 assert(
C->getType()->isIntOrIntVectorTy() &&
2061 unsigned SrcBits =
C->getType()->getScalarSizeInBits();
2064 (SrcBits == DstBits ? Instruction::BitCast :
2065 (SrcBits > DstBits ? Instruction::Trunc :
2066 (
isSigned ? Instruction::SExt : Instruction::ZExt)));
2073 unsigned SrcBits =
C->getType()->getScalarSizeInBits();
2075 if (SrcBits == DstBits)
2078 (SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt);
2084 bool fromVec = isa<VectorType>(
C->getType());
2085 bool toVec = isa<VectorType>(Ty);
2087 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2088 assert(
C->getType()->isIntOrIntVectorTy() &&
"Trunc operand must be integer");
2091 "SrcTy must be larger than DestTy for Trunc!");
2098 bool fromVec = isa<VectorType>(
C->getType());
2099 bool toVec = isa<VectorType>(Ty);
2101 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2102 assert(
C->getType()->isIntOrIntVectorTy() &&
"SExt operand must be integral");
2105 "SrcTy must be smaller than DestTy for SExt!");
2112 bool fromVec = isa<VectorType>(
C->getType());
2113 bool toVec = isa<VectorType>(Ty);
2115 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2116 assert(
C->getType()->isIntOrIntVectorTy() &&
"ZEXt operand must be integral");
2119 "SrcTy must be smaller than DestTy for ZExt!");
2126 bool fromVec = isa<VectorType>(
C->getType());
2127 bool toVec = isa<VectorType>(Ty);
2129 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2132 "This is an illegal floating point truncation!");
2133 return getFoldedCast(Instruction::FPTrunc,
C, Ty, OnlyIfReduced);
2138 bool fromVec = isa<VectorType>(
C->getType());
2139 bool toVec = isa<VectorType>(Ty);
2141 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2144 "This is an illegal floating point extension!");
2150 bool fromVec = isa<VectorType>(
C->getType());
2151 bool toVec = isa<VectorType>(Ty);
2153 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2155 "This is an illegal uint to floating point cast!");
2161 bool fromVec = isa<VectorType>(
C->getType());
2162 bool toVec = isa<VectorType>(Ty);
2164 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2166 "This is an illegal sint to floating point cast!");
2172 bool fromVec = isa<VectorType>(
C->getType());
2173 bool toVec = isa<VectorType>(Ty);
2175 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2177 "This is an illegal floating point to uint cast!");
2183 bool fromVec = isa<VectorType>(
C->getType());
2184 bool toVec = isa<VectorType>(Ty);
2186 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2188 "This is an illegal floating point to sint cast!");
2193 bool OnlyIfReduced) {
2194 assert(
C->getType()->isPtrOrPtrVectorTy() &&
2195 "PtrToInt source must be pointer or pointer vector");
2197 "PtrToInt destination must be integer or integer vector");
2198 assert(isa<VectorType>(
C->getType()) == isa<VectorType>(DstTy));
2199 if (isa<VectorType>(
C->getType()))
2200 assert(cast<VectorType>(
C->getType())->getElementCount() ==
2201 cast<VectorType>(DstTy)->getElementCount() &&
2202 "Invalid cast between a different number of vector elements");
2203 return getFoldedCast(Instruction::PtrToInt,
C, DstTy, OnlyIfReduced);
2207 bool OnlyIfReduced) {
2208 assert(
C->getType()->isIntOrIntVectorTy() &&
2209 "IntToPtr source must be integer or integer vector");
2211 "IntToPtr destination must be a pointer or pointer vector");
2212 assert(isa<VectorType>(
C->getType()) == isa<VectorType>(DstTy));
2213 if (isa<VectorType>(
C->getType()))
2214 assert(cast<VectorType>(
C->getType())->getElementCount() ==
2215 cast<VectorType>(DstTy)->getElementCount() &&
2216 "Invalid cast between a different number of vector elements");
2217 return getFoldedCast(Instruction::IntToPtr,
C, DstTy, OnlyIfReduced);
2221 bool OnlyIfReduced) {
2223 "Invalid constantexpr bitcast!");
2227 if (
C->getType() == DstTy)
return C;
2229 return getFoldedCast(Instruction::BitCast,
C, DstTy, OnlyIfReduced);
2233 bool OnlyIfReduced) {
2235 "Invalid constantexpr addrspacecast!");
2239 PointerType *SrcScalarTy = cast<PointerType>(
C->getType()->getScalarType());
2244 if (
VectorType *VT = dyn_cast<VectorType>(DstTy)) {
2247 cast<FixedVectorType>(VT)->getNumElements());
2251 return getFoldedCast(Instruction::AddrSpaceCast,
C, DstTy, OnlyIfReduced);
2255 unsigned Flags,
Type *OnlyIfReducedTy) {
2258 "Invalid opcode in binary constant expression");
2260 "Binop not supported as constant expression");
2262 "Operand types in binary constant expression should match");
2266 case Instruction::Add:
2267 case Instruction::Sub:
2268 case Instruction::Mul:
2269 case Instruction::UDiv:
2270 case Instruction::SDiv:
2271 case Instruction::URem:
2272 case Instruction::SRem:
2274 "Tried to create an integer operation on a non-integer type!");
2276 case Instruction::FAdd:
2277 case Instruction::FSub:
2278 case Instruction::FMul:
2279 case Instruction::FDiv:
2280 case Instruction::FRem:
2282 "Tried to create a floating-point operation on a "
2283 "non-floating-point type!");
2285 case Instruction::And:
2286 case Instruction::Or:
2287 case Instruction::Xor:
2289 "Tried to create a logical operation on a non-integral type!");
2291 case Instruction::Shl:
2292 case Instruction::LShr:
2293 case Instruction::AShr:
2295 "Tried to create a shift operation on a non-integer type!");
2305 if (OnlyIfReducedTy == C1->
getType())
2317 case Instruction::UDiv:
2318 case Instruction::SDiv:
2319 case Instruction::URem:
2320 case Instruction::SRem:
2321 case Instruction::FAdd:
2322 case Instruction::FSub:
2323 case Instruction::FMul:
2324 case Instruction::FDiv:
2325 case Instruction::FRem:
2327 case Instruction::Add:
2328 case Instruction::Sub:
2329 case Instruction::Mul:
2330 case Instruction::Shl:
2331 case Instruction::LShr:
2332 case Instruction::AShr:
2333 case Instruction::And:
2334 case Instruction::Or:
2335 case Instruction::Xor:
2344 case Instruction::UDiv:
2345 case Instruction::SDiv:
2346 case Instruction::URem:
2347 case Instruction::SRem:
2348 case Instruction::FAdd:
2349 case Instruction::FSub:
2350 case Instruction::FMul:
2351 case Instruction::FDiv:
2352 case Instruction::FRem:
2354 case Instruction::Add:
2355 case Instruction::Sub:
2356 case Instruction::Mul:
2357 case Instruction::Shl:
2358 case Instruction::LShr:
2359 case Instruction::AShr:
2360 case Instruction::And:
2361 case Instruction::Or:
2362 case Instruction::Xor:
2386 Constant *Indices[2] = { Zero, One };
2393 Constant *C2,
bool OnlyIfReduced) {
2396 switch (Predicate) {
2404 return getFCmp(Predicate, C1, C2, OnlyIfReduced);
2410 return getICmp(Predicate, C1, C2, OnlyIfReduced);
2416 std::optional<unsigned> InRangeIndex,
2417 Type *OnlyIfReducedTy) {
2418 PointerType *OrigPtrTy = cast<PointerType>(
C->getType()->getScalarType());
2419 assert(Ty &&
"Must specify element type");
2429 assert(DestTy &&
"GEP indices invalid!");
2436 if (
VectorType *VecTy = dyn_cast<VectorType>(
C->getType()))
2437 EltCount = VecTy->getElementCount();
2439 for (
auto *
Idx : Idxs)
2440 if (
VectorType *VecTy = dyn_cast<VectorType>(
Idx->getType()))
2441 EltCount = VecTy->getElementCount();
2443 if (EltCount.isNonZero())
2446 if (OnlyIfReducedTy == ReqTy)
2450 std::vector<Constant*> ArgVec;
2451 ArgVec.reserve(1 + Idxs.
size());
2452 ArgVec.push_back(
C);
2454 for (; GTI != GTE; ++GTI) {
2455 auto *
Idx = cast<Constant>(GTI.getOperand());
2457 (!isa<VectorType>(
Idx->getType()) ||
2458 cast<VectorType>(
Idx->getType())->getElementCount() == EltCount) &&
2459 "getelementptr index type missmatch");
2461 if (GTI.isStruct() &&
Idx->getType()->isVectorTy()) {
2462 Idx =
Idx->getSplatValue();
2463 }
else if (GTI.isSequential() && EltCount.isNonZero() &&
2464 !
Idx->getType()->isVectorTy()) {
2467 ArgVec.push_back(
Idx);
2470 unsigned SubClassOptionalData = InBounds ? GEPOperator::IsInBounds : 0;
2471 if (InRangeIndex && *InRangeIndex < 63)
2472 SubClassOptionalData |= (*InRangeIndex + 1) << 1;
2474 SubClassOptionalData, std::nullopt, Ty);
2481 Constant *RHS,
bool OnlyIfReduced) {
2506 Constant *RHS,
bool OnlyIfReduced) {
2531 Type *OnlyIfReducedTy) {
2533 "Tried to create extractelement operation on non-vector type!");
2535 "Extractelement index must be an integer type!");
2540 Type *ReqTy = cast<VectorType>(Val->
getType())->getElementType();
2541 if (OnlyIfReducedTy == ReqTy)
2555 "Tried to create insertelement operation on non-vector type!");
2557 "Insertelement types must match!");
2559 "Insertelement index must be i32 type!");
2564 if (OnlyIfReducedTy == Val->
getType())
2577 Type *OnlyIfReducedTy) {
2579 "Invalid shuffle vector constant expr operands!");
2584 unsigned NElts = Mask.size();
2585 auto V1VTy = cast<VectorType>(V1->
getType());
2586 Type *EltTy = V1VTy->getElementType();
2587 bool TypeIsScalable = isa<ScalableVectorType>(V1VTy);
2590 if (OnlyIfReducedTy == ShufTy)
2602 assert(
C->getType()->isIntOrIntVectorTy() &&
2603 "Cannot NEG a nonintegral value!");
2609 assert(
C->getType()->isIntOrIntVectorTy() &&
2610 "Cannot NOT a nonintegral value!");
2615 bool HasNUW,
bool HasNSW) {
2618 return get(Instruction::Add, C1, C2,
Flags);
2622 bool HasNUW,
bool HasNSW) {
2625 return get(Instruction::Sub, C1, C2,
Flags);
2629 bool HasNUW,
bool HasNSW) {
2632 return get(Instruction::Mul, C1, C2,
Flags);
2636 return get(Instruction::And, C1, C2);
2640 return get(Instruction::Or, C1, C2);
2644 return get(Instruction::Xor, C1, C2);
2648 bool HasNUW,
bool HasNSW) {
2651 return get(Instruction::Shl, C1, C2,
Flags);
2655 return get(Instruction::LShr, C1, C2,
2660 return get(Instruction::AShr, C1, C2,
2665 Type *Ty =
C->getType();
2671 auto *VecTy = dyn_cast<FixedVectorType>(Ty);
2676 for (
unsigned I = 0,
E = VecTy->getNumElements();
I !=
E; ++
I) {
2681 if (isa<UndefValue>(Elt)) {
2694 bool AllowRHSConstant,
bool NSZ) {
2700 case Instruction::Add:
2701 case Instruction::Or:
2702 case Instruction::Xor:
2704 case Instruction::Mul:
2706 case Instruction::And:
2708 case Instruction::FAdd:
2710 case Instruction::FMul:
2718 if (!AllowRHSConstant)
2722 case Instruction::Sub:
2723 case Instruction::Shl:
2724 case Instruction::LShr:
2725 case Instruction::AShr:
2726 case Instruction::FSub:
2728 case Instruction::SDiv:
2729 case Instruction::UDiv:
2731 case Instruction::FDiv:
2744 case Instruction::Or:
2747 case Instruction::And:
2748 case Instruction::Mul:
2754void ConstantExpr::destroyConstantImpl() {
2762GetElementPtrConstantExpr::GetElementPtrConstantExpr(
2766 (IdxList.
size() + 1),
2767 IdxList.
size() + 1),
2768 SrcElementTy(SrcElementTy),
2772 for (
unsigned i = 0,
E = IdxList.
size(); i !=
E; ++i)
2773 OperandList[i+1] = IdxList[i];
2777 return SrcElementTy;
2781 return ResElementTy;
2789 return ATy->getElementType();
2790 return cast<VectorType>(
getType())->getElementType();
2800 if (
auto *
IT = dyn_cast<IntegerType>(Ty)) {
2801 switch (
IT->getBitWidth()) {
2815 return AT->getNumElements();
2816 return cast<FixedVectorType>(
getType())->getNumElements();
2825const char *ConstantDataSequential::getElementPointer(
unsigned Elt)
const {
2845 if (
ArrayType *ATy = dyn_cast<ArrayType>(Ty))
2865 std::unique_ptr<ConstantDataSequential> *Entry = &Slot.second;
2866 for (; *Entry; Entry = &(*Entry)->Next)
2867 if ((*Entry)->getType() == Ty)
2868 return Entry->get();
2872 if (isa<ArrayType>(Ty)) {
2875 return Entry->get();
2878 assert(isa<VectorType>(Ty));
2881 return Entry->get();
2884void ConstantDataSequential::destroyConstantImpl() {
2891 assert(Slot != CDSConstants.
end() &&
"CDS not found in uniquing table");
2893 std::unique_ptr<ConstantDataSequential> *Entry = &Slot->getValue();
2896 if (!(*Entry)->Next) {
2899 assert(Entry->get() ==
this &&
"Hash mismatch in ConstantDataSequential");
2907 std::unique_ptr<ConstantDataSequential> &
Node = *Entry;
2908 assert(
Node &&
"Didn't find entry in its uniquing hash table!");
2910 if (
Node.get() ==
this) {
2915 Entry = &
Node->Next;
2927 "Element type is not a 16-bit float type");
2929 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2933 assert(ElementType->
isFloatTy() &&
"Element type is not a 32-bit float type");
2935 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2940 "Element type is not a 64-bit float type");
2942 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2949 const uint8_t *
Data = Str.bytes_begin();
2954 ElementVals.
append(Str.begin(), Str.end());
2964 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2969 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2974 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2979 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2984 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2989 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3002 "Element type is not a 16-bit float type");
3004 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3009 assert(ElementType->
isFloatTy() &&
"Element type is not a 32-bit float type");
3011 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3017 "Element type is not a 64-bit float type");
3019 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
3025 "Element type not compatible with ConstantData");
3027 if (CI->getType()->isIntegerTy(8)) {
3029 return get(V->getContext(), Elts);
3031 if (CI->getType()->isIntegerTy(16)) {
3033 return get(V->getContext(), Elts);
3035 if (CI->getType()->isIntegerTy(32)) {
3037 return get(V->getContext(), Elts);
3039 assert(CI->getType()->isIntegerTy(64) &&
"Unsupported ConstantData type");
3041 return get(V->getContext(), Elts);
3044 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(V)) {
3045 if (CFP->getType()->isHalfTy()) {
3047 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3048 return getFP(V->getType(), Elts);
3050 if (CFP->getType()->isBFloatTy()) {
3052 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3053 return getFP(V->getType(), Elts);
3055 if (CFP->getType()->isFloatTy()) {
3057 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3058 return getFP(V->getType(), Elts);
3060 if (CFP->getType()->isDoubleTy()) {
3062 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3063 return getFP(V->getType(), Elts);
3072 "Accessor can only be used when element is an integer");
3073 const char *EltPtr = getElementPointer(Elt);
3080 return *
reinterpret_cast<const uint8_t *
>(EltPtr);
3082 return *
reinterpret_cast<const uint16_t *
>(EltPtr);
3084 return *
reinterpret_cast<const uint32_t *
>(EltPtr);
3086 return *
reinterpret_cast<const uint64_t *
>(EltPtr);
3092 "Accessor can only be used when element is an integer");
3093 const char *EltPtr = getElementPointer(Elt);
3100 auto EltVal = *
reinterpret_cast<const uint8_t *
>(EltPtr);
3101 return APInt(8, EltVal);
3104 auto EltVal = *
reinterpret_cast<const uint16_t *
>(EltPtr);
3105 return APInt(16, EltVal);
3108 auto EltVal = *
reinterpret_cast<const uint32_t *
>(EltPtr);
3109 return APInt(32, EltVal);
3112 auto EltVal = *
reinterpret_cast<const uint64_t *
>(EltPtr);
3113 return APInt(64, EltVal);
3119 const char *EltPtr = getElementPointer(Elt);
3123 llvm_unreachable(
"Accessor can only be used when element is float/double!");
3125 auto EltVal = *
reinterpret_cast<const uint16_t *
>(EltPtr);
3129 auto EltVal = *
reinterpret_cast<const uint16_t *
>(EltPtr);
3133 auto EltVal = *
reinterpret_cast<const uint32_t *
>(EltPtr);
3137 auto EltVal = *
reinterpret_cast<const uint64_t *
>(EltPtr);
3145 "Accessor can only be used when element is a 'float'");
3146 return *
reinterpret_cast<const float *
>(getElementPointer(Elt));
3151 "Accessor can only be used when element is a 'float'");
3152 return *
reinterpret_cast<const double *
>(getElementPointer(Elt));
3174 if (Str.back() != 0)
return false;
3177 return !Str.drop_back().contains(0);
3180bool ConstantDataVector::isSplatData()
const {
3195 IsSplat = isSplatData();
3220 Value *Replacement =
nullptr;
3224#define HANDLE_CONSTANT(Name) \
3225 case Value::Name##Val: \
3226 Replacement = cast<Name>(this)->handleOperandChangeImpl(From, To); \
3228#include "llvm/IR/Value.def"
3237 assert(Replacement !=
this &&
"I didn't contain From!");
3247 assert(isa<Constant>(To) &&
"Cannot make Constant refer to non-constant!");
3248 Constant *ToC = cast<Constant>(To);
3255 unsigned NumUpdated = 0;
3258 bool AllSame =
true;
3260 unsigned OperandNo = 0;
3262 Constant *Val = cast<Constant>(O->get());
3264 OperandNo = (O - OperandList);
3269 AllSame &= Val == ToC;
3275 if (AllSame && isa<UndefValue>(ToC))
3284 Values,
this,
From, ToC, NumUpdated, OperandNo);
3288 assert(isa<Constant>(To) &&
"Cannot make Constant refer to non-constant!");
3289 Constant *ToC = cast<Constant>(To);
3298 unsigned NumUpdated = 0;
3299 bool AllSame =
true;
3300 unsigned OperandNo = 0;
3302 Constant *Val = cast<Constant>(
O->get());
3304 OperandNo = (
O - OperandList);
3309 AllSame &= Val == ToC;
3315 if (AllSame && isa<UndefValue>(ToC))
3320 Values,
this,
From, ToC, NumUpdated, OperandNo);
3324 assert(isa<Constant>(To) &&
"Cannot make Constant refer to non-constant!");
3325 Constant *ToC = cast<Constant>(To);
3329 unsigned NumUpdated = 0;
3330 unsigned OperandNo = 0;
3346 Values,
this,
From, ToC, NumUpdated, OperandNo);
3350 assert(isa<Constant>(ToV) &&
"Cannot make Constant refer to non-constant!");
3351 Constant *To = cast<Constant>(ToV);
3354 unsigned NumUpdated = 0;
3355 unsigned OperandNo = 0;
3365 assert(NumUpdated &&
"I didn't contain From!");
3372 NewOps,
this,
From, To, NumUpdated, OperandNo);
3380 case Instruction::Trunc:
3381 case Instruction::ZExt:
3382 case Instruction::SExt:
3383 case Instruction::FPTrunc:
3384 case Instruction::FPExt:
3385 case Instruction::UIToFP:
3386 case Instruction::SIToFP:
3387 case Instruction::FPToUI:
3388 case Instruction::FPToSI:
3389 case Instruction::PtrToInt:
3390 case Instruction::IntToPtr:
3391 case Instruction::BitCast:
3392 case Instruction::AddrSpaceCast:
3395 case Instruction::InsertElement:
3397 case Instruction::ExtractElement:
3399 case Instruction::ShuffleVector:
3403 case Instruction::GetElementPtr: {
3404 const auto *GO = cast<GEPOperator>(
this);
3405 if (GO->isInBounds())
3407 GO->getSourceElementType(), Ops[0], Ops.
slice(1),
"", InsertBefore);
3409 Ops.
slice(1),
"", InsertBefore);
3411 case Instruction::ICmp:
3412 case Instruction::FCmp:
3420 if (isa<OverflowingBinaryOperator>(BO)) {
3426 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 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.
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 * 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 Constant * getSExtOrBitCast(Constant *C, Type *Ty)
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 * getAShr(Constant *C1, Constant *C2, bool isExact=false)
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 * getFPToUI(Constant *C, Type *Ty, bool OnlyIfReduced=false)
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 * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=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 * getFPTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getSIToFP(Constant *C, Type *Ty, bool OnlyIfReduced=false)
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 * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false, std::optional< unsigned > InRangeIndex=std::nullopt, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
static Constant * getIntegerCast(Constant *C, Type *Ty, bool IsSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
static Constant * getXor(Constant *C1, Constant *C2)
static Constant * getSExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
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 * getZExtOrBitCast(Constant *C, Type *Ty)
static Constant * getShl(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static Constant * getLShr(Constant *C1, Constant *C2, bool isExact=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 Constant * getFPExtend(Constant *C, Type *Ty, bool OnlyIfReduced=false)
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 * getUIToFP(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getFPToSI(Constant *C, Type *Ty, bool OnlyIfReduced=false)
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 * getOr(Constant *C1, Constant *C2)
static Constant * getAnd(Constant *C1, Constant *C2)
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 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 * getFPCast(Constant *C, Type *Ty)
Create a FPExt, Bitcast or FPTrunc for fp -> fp casts.
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 * getNegativeZero(Type *Ty)
static Constant * getNaN(Type *Ty, bool Negative=false, uint64_t Payload=0)
static Constant * getZeroValueForNegation(Type *Ty)
Floating point negation must be implemented with f(x) = -0.0 - x.
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.
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 * 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.
DenseMap< unsigned, std::unique_ptr< ConstantInt > > IntOneConstants
DenseMap< unsigned, std::unique_ptr< ConstantInt > > IntZeroConstants
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
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
DenseMap< APFloat, std::unique_ptr< ConstantFP >, DenseMapAPFloatKeyInfo > FPConstants
ArrayConstantsTy ArrayConstants
DenseMap< APInt, std::unique_ptr< ConstantInt >, DenseMapAPIntKeyInfo > IntConstants
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.
GlobalValue * getGlobalValue() const
Class to represent pointers.
bool isOpaqueOrPointeeTypeMatches(Type *Ty)
Return true if either this is an opaque pointer type or if this pointee type matches Ty.
bool hasSameElementTypeAs(PointerType *Other)
Return true if both pointer types have the same element type.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
unsigned getAddressSpace() const
Return the address space of the Pointer type.
static PointerType * getWithSamePointeeType(PointerType *PT, unsigned AddressSpace)
This constructs a pointer type with the same pointee type as input PointerType (or opaque pointer if ...
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)
PointerType * getPointerTo(unsigned AddrSpace=0) const
Return a pointer to the current type.
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.
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
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.
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)
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