43 void Constant::anchor() { }
47 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
48 return CFP->isZero() && CFP->isNegative();
52 if (
ConstantFP *SplatCFP = dyn_cast_or_null<ConstantFP>(CV->getSplatValue()))
53 if (SplatCFP && SplatCFP->isZero() && SplatCFP->isNegative())
68 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
77 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
81 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
82 return CFP->isZero() && !CFP->isNegative();
85 return isa<ConstantAggregateZero>(
this) || isa<ConstantPointerNull>(
this);
90 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
91 return CI->isMinusOne();
94 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
95 return CFP->getValueAPF().bitcastToAPInt().isAllOnesValue();
100 return Splat->isAllOnesValue();
105 return Splat->isAllOnesValue();
112 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
116 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
117 return CFP->getValueAPF().bitcastToAPInt() == 1;
122 return Splat->isOneValue();
127 return Splat->isOneValue();
134 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
135 return CI->isMinValue(
true);
138 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
139 return CFP->getValueAPF().bitcastToAPInt().isMinSignedValue();
144 return Splat->isMinSignedValue();
149 return Splat->isMinSignedValue();
156 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
157 return !CI->isMinValue(
true);
160 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(
this))
161 return !CFP->getValueAPF().bitcastToAPInt().isMinSignedValue();
166 return Splat->isNotMinSignedValue();
171 return Splat->isNotMinSignedValue();
220 if (
PointerType *PTy = dyn_cast<PointerType>(ScalarTy))
224 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
252 return Elt <
CS->getNumOperands() ?
CS->getOperand(Elt) :
nullptr;
255 return Elt < CA->getNumOperands() ? CA->getOperand(Elt) :
nullptr;
258 return Elt < CV->getNumOperands() ? CV->getOperand(Elt) :
nullptr;
261 return Elt < CAZ->getNumElements() ? CAZ->getElementValue(Elt) :
nullptr;
263 if (
const UndefValue *UV = dyn_cast<UndefValue>(
this))
264 return Elt < UV->getNumElements() ? UV->getElementValue(Elt) :
nullptr;
267 return Elt < CDS->getNumElements() ? CDS->getElementAsConstant(Elt)
273 assert(isa<IntegerType>(Elt->
getType()) &&
"Index must be an integer");
285 #define HANDLE_CONSTANT(Name) \
286 case Value::Name##Val: \
287 cast<Name>(this)->destroyConstantImpl(); \
289 #include "llvm/IR/Value.def"
301 #ifndef NDEBUG // Only in -g mode...
302 if (!isa<Constant>(V)) {
303 dbgs() <<
"While deleting: " << *
this
304 <<
"\n\nUse still stuck around after Def is destroyed: " << *V
308 assert(isa<Constant>(V) &&
"References remain to Constant being destroyed");
329 if (
ConstantExpr *Op = dyn_cast<ConstantExpr>(CE->getOperand(i))) {
336 switch (CE->getOpcode()) {
339 case Instruction::UDiv:
340 case Instruction::SDiv:
341 case Instruction::FDiv:
342 case Instruction::URem:
343 case Instruction::SRem:
344 case Instruction::FRem:
346 if (!isa<ConstantInt>(CE->getOperand(1)) ||CE->getOperand(1)->isNullValue())
368 while (!WorkList.
empty()) {
370 if (
const auto *GV = dyn_cast<GlobalValue>(WorkItem))
377 if (Visited.
insert(ConstOp).second)
386 auto DLLImportPredicate = [](
const GlobalValue *GV) {
387 return GV->isThreadLocal();
393 auto DLLImportPredicate = [](
const GlobalValue *GV) {
394 return GV->hasDLLImportStorageClass();
404 if (!UC || isa<GlobalValue>(UC))
430 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(
this)) {
431 if (GV->hasLocalLinkage() || GV->hasHiddenVisibility())
436 if (
const BlockAddress *BA = dyn_cast<BlockAddress>(
this))
437 return BA->getFunction()->getRelocationInfo();
443 if (
const ConstantExpr *CE = dyn_cast<ConstantExpr>(
this))
444 if (CE->getOpcode() == Instruction::Sub) {
448 LHS->
getOpcode() == Instruction::PtrToInt &&
449 RHS->getOpcode() == Instruction::PtrToInt &&
451 isa<BlockAddress>(RHS->getOperand(0)) &&
452 cast<BlockAddress>(LHS->
getOperand(0))->getFunction() ==
453 cast<BlockAddress>(RHS->getOperand(0))->getFunction())
459 Result = std::max(Result,
469 if (isa<GlobalValue>(C))
return false;
473 if (!User)
return false;
478 const_cast<Constant*
>(C)->destroyConstant();
507 if (LastNonDeadUser == E) {
523 void ConstantInt::anchor() { }
526 :
Constant(Ty, ConstantIntVal, nullptr, 0), Val(V) {
547 assert(Ty->
isIntegerTy(1) &&
"True must be i1 or vector of i1.");
551 "True must be vector of i1 or i1.");
559 assert(Ty->
isIntegerTy(1) &&
"False must be i1 or vector of i1.");
563 "False must be vector of i1 or i1.");
586 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
598 return get(Ty, V,
true);
602 return get(Ty, V,
true);
608 "ConstantInt type doesn't match the type implied by its value!");
611 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
623 void ConstantInt::destroyConstantImpl() {
647 void ConstantFP::anchor() { }
662 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
676 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
687 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
698 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
733 "Unknown FP format");
746 if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
753 :
Constant(Ty, ConstantFPVal, nullptr, 0), Val(V) {
763 void ConstantFP::destroyConstantImpl() {
786 if (isa<SequentialType>(
getType()))
794 if (isa<SequentialType>(
getType()))
801 if (
const auto *AT = dyn_cast<ArrayType>(Ty))
802 return AT->getNumElements();
803 if (
const auto *VT = dyn_cast<VectorType>(Ty))
804 return VT->getNumElements();
827 if (isa<SequentialType>(
getType()))
835 if (isa<SequentialType>(
getType()))
842 if (
const auto *AT = dyn_cast<ArrayType>(Ty))
843 return AT->getNumElements();
844 if (
const auto *VT = dyn_cast<VectorType>(Ty))
845 return VT->getNumElements();
853 template <
typename ItTy,
typename EltTy>
855 for (; Start != End; ++Start)
866 "Invalid initializer vector for constant array");
867 for (
unsigned i = 0, e = V.
size(); i != e; ++i)
869 "Initializer for array element doesn't match array element type!");
883 for (
unsigned i = 0, e = V.
size(); i != e; ++i) {
885 "Wrong type in array element initializer");
905 if (CI->getType()->isIntegerTy(8)) {
907 for (
unsigned i = 0, e = V.
size(); i != e; ++i)
914 }
else if (CI->getType()->isIntegerTy(16)) {
916 for (
unsigned i = 0, e = V.
size(); i != e; ++i)
923 }
else if (CI->getType()->isIntegerTy(32)) {
925 for (
unsigned i = 0, e = V.
size(); i != e; ++i)
932 }
else if (CI->getType()->isIntegerTy(64)) {
934 for (
unsigned i = 0, e = V.
size(); i != e; ++i)
944 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {
945 if (CFP->getType()->isFloatTy()) {
947 for (
unsigned i = 0, e = V.
size(); i != e; ++i)
948 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(V[i]))
950 CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
955 }
else if (CFP->getType()->isDoubleTy()) {
957 for (
unsigned i = 0, e = V.
size(); i != e; ++i)
958 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(V[i]))
960 CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
978 unsigned VecSize = V.
size();
980 for (
unsigned i = 0; i != VecSize; ++i)
990 "ConstantStruct::getTypeForElements cannot be called on empty list");
1000 "Invalid initializer vector for constant structure");
1001 for (
unsigned i = 0, e = V.
size(); i != e; ++i)
1003 "Initializer for struct element doesn't match struct element type!");
1010 "Incorrect # elements specified to ConstantStruct::get");
1014 bool isUndef =
false;
1017 isUndef = isa<UndefValue>(V[0]);
1018 isZero = V[0]->isNullValue();
1019 if (isUndef || isZero) {
1020 for (
unsigned i = 0, e = V.
size(); i != e; ++i) {
1023 if (!isa<UndefValue>(V[i]))
1043 return get(
T, Values);
1050 for (
size_t i = 0, e = V.
size(); i != e; i++)
1052 "Initializer for vector element doesn't match vector element type!");
1064 assert(!V.
empty() &&
"Vectors can't be empty");
1070 bool isZero = C->isNullValue();
1071 bool isUndef = isa<UndefValue>(
C);
1073 if (isZero || isUndef) {
1074 for (
unsigned i = 1, e = V.
size(); i != e; ++i)
1076 isZero = isUndef =
false;
1093 if (CI->getType()->isIntegerTy(8)) {
1095 for (
unsigned i = 0, e = V.
size(); i != e; ++i)
1096 if (
ConstantInt *CI = dyn_cast<ConstantInt>(V[i]))
1102 }
else if (CI->getType()->isIntegerTy(16)) {
1104 for (
unsigned i = 0, e = V.
size(); i != e; ++i)
1105 if (
ConstantInt *CI = dyn_cast<ConstantInt>(V[i]))
1111 }
else if (CI->getType()->isIntegerTy(32)) {
1113 for (
unsigned i = 0, e = V.
size(); i != e; ++i)
1114 if (
ConstantInt *CI = dyn_cast<ConstantInt>(V[i]))
1120 }
else if (CI->getType()->isIntegerTy(64)) {
1122 for (
unsigned i = 0, e = V.
size(); i != e; ++i)
1123 if (
ConstantInt *CI = dyn_cast<ConstantInt>(V[i]))
1132 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(C)) {
1133 if (CFP->getType()->isFloatTy()) {
1135 for (
unsigned i = 0, e = V.
size(); i != e; ++i)
1136 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(V[i]))
1138 CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
1143 }
else if (CFP->getType()->isDoubleTy()) {
1145 for (
unsigned i = 0, e = V.
size(); i != e; ++i)
1146 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(V[i]))
1148 CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
1165 if ((isa<ConstantFP>(V) || isa<ConstantInt>(V)) &&
1186 if (
getOpcode() != Instruction::GetElementPtr)
return false;
1197 for (; GEPI != E; ++GEPI, ++OI) {
1199 if (!CI)
return false;
1200 if (
ArrayType *ATy = dyn_cast<ArrayType>(*GEPI))
1211 return getOpcode() == Instruction::ExtractValue ||
1212 getOpcode() == Instruction::InsertValue;
1217 dyn_cast<ExtractValueConstantExpr>(
this))
1218 return EVCE->Indices;
1220 return cast<InsertValueConstantExpr>(
this)->Indices;
1233 "Replacing operand with value of different type!");
1235 return const_cast<ConstantExpr*>(
this);
1248 bool OnlyIfReduced)
const {
1255 Type *OnlyIfReducedTy = OnlyIfReduced ? Ty :
nullptr;
1257 case Instruction::Trunc:
1258 case Instruction::ZExt:
1259 case Instruction::SExt:
1260 case Instruction::FPTrunc:
1261 case Instruction::FPExt:
1262 case Instruction::UIToFP:
1263 case Instruction::SIToFP:
1264 case Instruction::FPToUI:
1265 case Instruction::FPToSI:
1266 case Instruction::PtrToInt:
1267 case Instruction::IntToPtr:
1268 case Instruction::BitCast:
1269 case Instruction::AddrSpaceCast:
1273 case Instruction::InsertElement:
1278 case Instruction::InsertValue:
1281 case Instruction::ExtractValue:
1283 case Instruction::ShuffleVector:
1286 case Instruction::GetElementPtr:
1288 cast<GEPOperator>(
this)->isInBounds(),
1290 case Instruction::ICmp:
1291 case Instruction::FCmp:
1308 return Val == 0 || Val == 1;
1311 uint64_t
Max = (1ll << NumBits) - 1;
1318 return Val == 0 || Val == 1 || Val == -1;
1321 int64_t Min = -(1ll << (NumBits-1));
1322 int64_t
Max = (1ll << (NumBits-1)) - 1;
1323 return (Val >= Min && Val <= Max);
1379 "Cannot create an aggregate zero of non-aggregate type!");
1390 void ConstantAggregateZero::destroyConstantImpl() {
1396 void ConstantArray::destroyConstantImpl() {
1406 void ConstantStruct::destroyConstantImpl() {
1412 void ConstantVector::destroyConstantImpl() {
1419 assert(this->
getType()->isVectorTy() &&
"Only valid for vectors!");
1420 if (isa<ConstantAggregateZero>(
this))
1423 return CV->getSplatValue();
1425 return CV->getSplatValue();
1444 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(
this))
1445 return CI->getValue();
1446 assert(this->
getSplatValue() &&
"Doesn't contain a unique integer!");
1448 assert(C && isa<ConstantInt>(C) &&
"Not a vector of numbers!");
1449 return cast<ConstantInt>(
C)->getValue();
1465 void ConstantPointerNull::destroyConstantImpl() {
1483 void UndefValue::destroyConstantImpl() {
1492 assert(BB->
getParent() &&
"Block must have a parent");
1502 assert(BA->
getFunction() == F &&
"Basic block moved between functions");
1511 BB->AdjustBlockAddressRefCount(1);
1519 assert(F &&
"Block must have a parent");
1522 assert(BA &&
"Refcount and block address map disagree!");
1528 void BlockAddress::destroyConstantImpl() {
1543 NewBB = cast<BasicBlock>(To);
1574 bool OnlyIfReduced =
false) {
1592 bool OnlyIfReduced) {
1595 assert(C && Ty &&
"Null arguments to getCast");
1601 case Instruction::Trunc:
1602 return getTrunc(C, Ty, OnlyIfReduced);
1603 case Instruction::ZExt:
1604 return getZExt(C, Ty, OnlyIfReduced);
1605 case Instruction::SExt:
1606 return getSExt(C, Ty, OnlyIfReduced);
1607 case Instruction::FPTrunc:
1609 case Instruction::FPExt:
1611 case Instruction::UIToFP:
1613 case Instruction::SIToFP:
1615 case Instruction::FPToUI:
1617 case Instruction::FPToSI:
1619 case Instruction::PtrToInt:
1621 case Instruction::IntToPtr:
1623 case Instruction::BitCast:
1625 case Instruction::AddrSpaceCast:
1681 (SrcBits == DstBits ? Instruction::BitCast :
1682 (SrcBits > DstBits ? Instruction::Trunc :
1683 (isSigned ? Instruction::SExt : Instruction::ZExt)));
1684 return getCast(opcode, C, Ty);
1692 if (SrcBits == DstBits)
1695 (SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt);
1696 return getCast(opcode, C, Ty);
1704 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
1708 "SrcTy must be larger than DestTy for Trunc!");
1710 return getFoldedCast(Instruction::Trunc, C, Ty, OnlyIfReduced);
1718 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
1722 "SrcTy must be smaller than DestTy for SExt!");
1724 return getFoldedCast(Instruction::SExt, C, Ty, OnlyIfReduced);
1732 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
1736 "SrcTy must be smaller than DestTy for ZExt!");
1738 return getFoldedCast(Instruction::ZExt, C, Ty, OnlyIfReduced);
1746 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
1749 "This is an illegal floating point truncation!");
1750 return getFoldedCast(Instruction::FPTrunc, C, Ty, OnlyIfReduced);
1758 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
1761 "This is an illegal floating point extension!");
1762 return getFoldedCast(Instruction::FPExt, C, Ty, OnlyIfReduced);
1770 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
1772 "This is an illegal uint to floating point cast!");
1773 return getFoldedCast(Instruction::UIToFP, C, Ty, OnlyIfReduced);
1781 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
1783 "This is an illegal sint to floating point cast!");
1784 return getFoldedCast(Instruction::SIToFP, C, Ty, OnlyIfReduced);
1792 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
1794 "This is an illegal floating point to uint cast!");
1795 return getFoldedCast(Instruction::FPToUI, C, Ty, OnlyIfReduced);
1803 assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
1805 "This is an illegal floating point to sint cast!");
1806 return getFoldedCast(Instruction::FPToSI, C, Ty, OnlyIfReduced);
1810 bool OnlyIfReduced) {
1812 "PtrToInt source must be pointer or pointer vector");
1814 "PtrToInt destination must be integer or integer vector");
1815 assert(isa<VectorType>(C->
getType()) == isa<VectorType>(DstTy));
1816 if (isa<VectorType>(C->
getType()))
1818 "Invalid cast between a different number of vector elements");
1819 return getFoldedCast(Instruction::PtrToInt, C, DstTy, OnlyIfReduced);
1823 bool OnlyIfReduced) {
1825 "IntToPtr source must be integer or integer vector");
1827 "IntToPtr destination must be a pointer or pointer vector");
1828 assert(isa<VectorType>(C->
getType()) == isa<VectorType>(DstTy));
1829 if (isa<VectorType>(C->
getType()))
1831 "Invalid cast between a different number of vector elements");
1832 return getFoldedCast(Instruction::IntToPtr, C, DstTy, OnlyIfReduced);
1836 bool OnlyIfReduced) {
1838 "Invalid constantexpr bitcast!");
1842 if (C->
getType() == DstTy)
return C;
1844 return getFoldedCast(Instruction::BitCast, C, DstTy, OnlyIfReduced);
1848 bool OnlyIfReduced) {
1850 "Invalid constantexpr addrspacecast!");
1856 Type *DstElemTy = DstScalarTy->getElementType();
1859 if (
VectorType *VT = dyn_cast<VectorType>(DstTy)) {
1865 return getFoldedCast(Instruction::AddrSpaceCast, C, DstTy, OnlyIfReduced);
1869 unsigned Flags,
Type *OnlyIfReducedTy) {
1871 assert(Opcode >= Instruction::BinaryOpsBegin &&
1872 Opcode < Instruction::BinaryOpsEnd &&
1873 "Invalid opcode in binary constant expression");
1875 "Operand types in binary constant expression should match");
1879 case Instruction::Add:
1880 case Instruction::Sub:
1881 case Instruction::Mul:
1882 assert(C1->
getType() == C2->
getType() &&
"Op types should be identical!");
1884 "Tried to create an integer operation on a non-integer type!");
1886 case Instruction::FAdd:
1887 case Instruction::FSub:
1888 case Instruction::FMul:
1889 assert(C1->
getType() == C2->
getType() &&
"Op types should be identical!");
1891 "Tried to create a floating-point operation on a "
1892 "non-floating-point type!");
1894 case Instruction::UDiv:
1895 case Instruction::SDiv:
1896 assert(C1->
getType() == C2->
getType() &&
"Op types should be identical!");
1898 "Tried to create an arithmetic operation on a non-arithmetic type!");
1900 case Instruction::FDiv:
1901 assert(C1->
getType() == C2->
getType() &&
"Op types should be identical!");
1903 "Tried to create an arithmetic operation on a non-arithmetic type!");
1905 case Instruction::URem:
1906 case Instruction::SRem:
1907 assert(C1->
getType() == C2->
getType() &&
"Op types should be identical!");
1909 "Tried to create an arithmetic operation on a non-arithmetic type!");
1911 case Instruction::FRem:
1912 assert(C1->
getType() == C2->
getType() &&
"Op types should be identical!");
1914 "Tried to create an arithmetic operation on a non-arithmetic type!");
1919 assert(C1->
getType() == C2->
getType() &&
"Op types should be identical!");
1921 "Tried to create a logical operation on a non-integral type!");
1923 case Instruction::Shl:
1924 case Instruction::LShr:
1925 case Instruction::AShr:
1926 assert(C1->
getType() == C2->
getType() &&
"Op types should be identical!");
1928 "Tried to create a shift operation on a non-integer type!");
1938 if (OnlyIfReducedTy == C1->
getType())
1966 Constant *Indices[2] = { Zero, One };
1991 Constant *C2,
bool OnlyIfReduced) {
1992 assert(C1->
getType() == C2->
getType() &&
"Op types should be identical!");
1994 switch (Predicate) {
2002 return getFCmp(Predicate, C1, C2, OnlyIfReduced);
2008 return getICmp(Predicate, C1, C2, OnlyIfReduced);
2013 Type *OnlyIfReducedTy) {
2019 if (OnlyIfReducedTy == V1->
getType())
2031 Type *OnlyIfReducedTy) {
2044 assert(DestTy &&
"GEP indices invalid!");
2050 if (OnlyIfReducedTy == ReqTy)
2054 std::vector<Constant*> ArgVec;
2055 ArgVec.reserve(1 + Idxs.
size());
2056 ArgVec.push_back(C);
2057 for (
unsigned i = 0, e = Idxs.
size(); i != e; ++i) {
2059 "getelementptr index type missmatch");
2060 assert((!Idxs[i]->
getType()->isVectorTy() ||
2062 Idxs[i]->getType()->getVectorNumElements()) &&
2063 "getelementptr index type missmatch");
2064 ArgVec.push_back(cast<Constant>(Idxs[i]));
2067 InBounds ? GEPOperator::IsInBounds : 0,
None,
2075 Constant *RHS,
bool OnlyIfReduced) {
2100 Constant *RHS,
bool OnlyIfReduced) {
2124 Type *OnlyIfReducedTy) {
2126 "Tried to create extractelement operation on non-vector type!");
2128 "Extractelement index must be an integer type!");
2134 if (OnlyIfReducedTy == ReqTy)
2148 "Tried to create insertelement operation on non-vector type!");
2150 "Insertelement types must match!");
2152 "Insertelement index must be i32 type!");
2157 if (OnlyIfReducedTy == Val->
getType())
2161 Constant *ArgVec[] = { Val, Elt, Idx };
2171 "Invalid shuffle vector constant expr operands!");
2180 if (OnlyIfReducedTy == ShufTy)
2193 Type *OnlyIfReducedTy) {
2195 "Non-first-class type for constant insertvalue expression");
2199 "insertvalue indices invalid!");
2205 if (OnlyIfReducedTy == ReqTy)
2216 Type *OnlyIfReducedTy) {
2218 "Tried to create extractelement operation on non-first-class type!");
2222 assert(ReqTy &&
"extractvalue indices invalid!");
2225 "Non-first-class type for constant extractvalue expression");
2229 if (OnlyIfReducedTy == ReqTy)
2241 "Cannot NEG a nonintegral value!");
2248 "Cannot FNEG a non-floating-point value!");
2254 "Cannot NOT a nonintegral value!");
2259 bool HasNUW,
bool HasNSW) {
2262 return get(Instruction::Add, C1, C2,
Flags);
2266 return get(Instruction::FAdd, C1, C2);
2270 bool HasNUW,
bool HasNSW) {
2273 return get(Instruction::Sub, C1, C2,
Flags);
2277 return get(Instruction::FSub, C1, C2);
2281 bool HasNUW,
bool HasNSW) {
2284 return get(Instruction::Mul, C1, C2,
Flags);
2288 return get(Instruction::FMul, C1, C2);
2292 return get(Instruction::UDiv, C1, C2,
2297 return get(Instruction::SDiv, C1, C2,
2302 return get(Instruction::FDiv, C1, C2);
2306 return get(Instruction::URem, C1, C2);
2310 return get(Instruction::SRem, C1, C2);
2314 return get(Instruction::FRem, C1, C2);
2330 bool HasNUW,
bool HasNSW) {
2333 return get(Instruction::Shl, C1, C2,
Flags);
2337 return get(Instruction::LShr, C1, C2,
2342 return get(Instruction::AShr, C1, C2,
2355 case Instruction::Add:
2360 case Instruction::Mul:
2382 case Instruction::Mul:
2389 void ConstantExpr::destroyConstantImpl() {
2397 GetElementPtrConstantExpr::GetElementPtrConstantExpr(
2401 (IdxList.
size() + 1),
2402 IdxList.
size() + 1),
2403 SrcElementTy(SrcElementTy) {
2406 for (
unsigned i = 0, E = IdxList.
size(); i != E; ++i)
2407 OperandList[i+1] = IdxList[i];
2411 return SrcElementTy;
2417 void ConstantDataArray::anchor() {}
2418 void ConstantDataVector::anchor() {}
2436 switch (
IT->getBitWidth()) {
2451 return AT->getNumElements();
2462 const char *ConstantDataSequential::getElementPointer(
unsigned Elt)
const {
2499 Entry = &Node->Next, Node = *Entry)
2500 if (Node->getType() == Ty)
2505 if (isa<ArrayType>(Ty))
2508 assert(isa<VectorType>(Ty));
2512 void ConstantDataSequential::destroyConstantImpl() {
2520 assert(Slot != CDSConstants.
end() &&
"CDS not found in uniquing table");
2525 if (!(*Entry)->Next) {
2528 assert((*Entry) ==
this &&
"Hash mismatch in ConstantDataSequential");
2534 Entry = &Node->Next, Node = *Entry) {
2535 assert(Node &&
"Didn't find entry in its uniquing hash table!");
2538 *Entry = Node->Next;
2554 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2559 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2564 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2569 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2574 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2579 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2591 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2597 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2603 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2615 const uint8_t *
Data =
reinterpret_cast<const uint8_t *
>(Str.
data());
2616 return get(Context,
makeArrayRef(const_cast<uint8_t *>(Data),
2623 return get(Context, ElementVals);
2631 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2636 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2641 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2646 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2651 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2656 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2668 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2674 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2680 const char *
Data =
reinterpret_cast<const char *
>(Elts.
data());
2686 "Element type not compatible with ConstantData");
2688 if (CI->getType()->isIntegerTy(8)) {
2692 if (CI->getType()->isIntegerTy(16)) {
2696 if (CI->getType()->isIntegerTy(32)) {
2700 assert(CI->getType()->isIntegerTy(64) &&
"Unsupported ConstantData type");
2705 if (
ConstantFP *CFP = dyn_cast<ConstantFP>(V)) {
2706 if (CFP->getType()->isFloatTy()) {
2708 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
2711 if (CFP->getType()->isDoubleTy()) {
2713 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
2725 "Accessor can only be used when element is an integer");
2726 const char *EltPtr = getElementPointer(Elt);
2733 return *
const_cast<uint8_t *
>(
reinterpret_cast<const uint8_t *
>(EltPtr));
2735 return *
const_cast<uint16_t *
>(
reinterpret_cast<const uint16_t *
>(EltPtr));
2737 return *
const_cast<uint32_t *
>(
reinterpret_cast<const uint32_t *
>(EltPtr));
2739 return *
const_cast<uint64_t *
>(
reinterpret_cast<const uint64_t *
>(EltPtr));
2746 const char *EltPtr = getElementPointer(Elt);
2750 llvm_unreachable(
"Accessor can only be used when element is float/double!");
2752 auto EltVal = *
reinterpret_cast<const uint32_t *
>(EltPtr);
2756 auto EltVal = *
reinterpret_cast<const uint64_t *
>(EltPtr);
2766 "Accessor can only be used when element is a 'float'");
2767 const float *EltPtr =
reinterpret_cast<const float *
>(getElementPointer(Elt));
2768 return *
const_cast<float *
>(EltPtr);
2775 "Accessor can only be used when element is a 'float'");
2776 const double *EltPtr =
2777 reinterpret_cast<const double *
>(getElementPointer(Elt));
2778 return *
const_cast<double *
>(EltPtr);
2805 if (Str.
back() != 0)
return false;
2819 if (memcmp(Base, Base+i*EltSize, EltSize))
2841 Value *Replacement =
nullptr;
2845 #define HANDLE_CONSTANT(Name) \
2846 case Value::Name##Val: \
2847 Replacement = cast<Name>(this)->handleOperandChangeImpl(From, To, U); \
2849 #include "llvm/IR/Value.def"
2858 assert(Replacement !=
this &&
"I didn't contain From!");
2879 Value *ConstantPointerNull::handleOperandChangeImpl(
Value *From,
Value *To,
2884 Value *ConstantAggregateZero::handleOperandChangeImpl(
Value *From,
Value *To,
2889 Value *ConstantDataSequential::handleOperandChangeImpl(
Value *From,
Value *To,
2895 assert(isa<Constant>(To) &&
"Cannot make Constant refer to non-constant!");
2896 Constant *ToC = cast<Constant>(To);
2903 unsigned NumUpdated = 0;
2906 bool AllSame =
true;
2909 Constant *Val = cast<Constant>(O->get());
2914 Values.push_back(Val);
2915 AllSame &= Val == ToC;
2921 if (AllSame && isa<UndefValue>(ToC))
2930 Values,
this, From, ToC, NumUpdated, U - OperandList);
2934 assert(isa<Constant>(To) &&
"Cannot make Constant refer to non-constant!");
2935 Constant *ToC = cast<Constant>(To);
2938 unsigned OperandToUpdate = U-OperandList;
2939 assert(
getOperand(OperandToUpdate) == From &&
"ReplaceAllUsesWith broken!");
2947 bool isAllUndef =
false;
2951 Constant *Val = cast<Constant>(O->get());
2955 }
else if (isa<UndefValue>(ToC)) {
2958 Constant *Val = cast<Constant>(O->get());
2960 if (isAllUndef) isAllUndef = isa<UndefValue>(Val);
2964 Values.
push_back(cast<Constant>(O->get()));
2966 Values[OperandToUpdate] = ToC;
2976 Values,
this, From, ToC);
2980 assert(isa<Constant>(To) &&
"Cannot make Constant refer to non-constant!");
2981 Constant *ToC = cast<Constant>(To);
2985 unsigned NumUpdated = 0;
2992 Values.push_back(Val);
3001 Values,
this, From, ToC, NumUpdated, U - OperandList);
3005 assert(isa<Constant>(ToV) &&
"Cannot make Constant refer to non-constant!");
3006 Constant *To = cast<Constant>(ToV);
3009 unsigned NumUpdated = 0;
3016 NewOps.push_back(Op);
3018 assert(NumUpdated &&
"I didn't contain From!");
3026 NewOps,
this, From, To, NumUpdated, U - OperandList);
3034 case Instruction::Trunc:
3035 case Instruction::ZExt:
3036 case Instruction::SExt:
3037 case Instruction::FPTrunc:
3038 case Instruction::FPExt:
3039 case Instruction::UIToFP:
3040 case Instruction::SIToFP:
3041 case Instruction::FPToUI:
3042 case Instruction::FPToSI:
3043 case Instruction::PtrToInt:
3044 case Instruction::IntToPtr:
3045 case Instruction::BitCast:
3046 case Instruction::AddrSpaceCast:
3051 case Instruction::InsertElement:
3055 case Instruction::InsertValue:
3057 case Instruction::ExtractValue:
3059 case Instruction::ShuffleVector:
3062 case Instruction::GetElementPtr: {
3063 const auto *GO = cast<GEPOperator>(
this);
3064 if (GO->isInBounds())
3066 Ops[0], Ops.
slice(1));
3070 case Instruction::ICmp:
3071 case Instruction::FCmp:
3080 if (isa<OverflowingBinaryOperator>(BO)) {
3086 if (isa<PossiblyExactOperator>(BO))
static Constant * getFPTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
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...
ConstantDataVector - A vector constant whose element type is a simple 1/2/4/8-byte integer or float/d...
void push_back(const T &Elt)
static ConstantInt * getFalse(LLVMContext &Context)
IntegerType * getType() const
getType - Specialize the getType() method to always return an IntegerType, which reduces the amount o...
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag...
static Constant * getString(LLVMContext &Context, StringRef Initializer, bool AddNull=true)
getString - This method constructs a CDS and initializes it with a text string.
static bool rangeOnlyContains(ItTy Start, ItTy End, EltTy Elt)
static Type * getDoubleTy(LLVMContext &C)
static IntegerType * getInt1Ty(LLVMContext &C)
static Constant * getFAdd(Constant *C1, Constant *C2)
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
unsigned getStructNumElements() const
APFloat getElementAsAPFloat(unsigned i) const
getElementAsAPFloat - If this is a sequential container of floating point type, return the specified ...
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
Type * getSequentialElementType() const
size_t size() const
size - Get the string size.
bool isOpaque() const
isOpaque - Return true if this is a type with an identity that has no body specified yet...
static const fltSemantics IEEEdouble
static Constant * getNaN(Type *Ty, bool Negative=false, unsigned type=0)
DenseMap< std::pair< const Function *, const BasicBlock * >, BlockAddress * > BlockAddresses
static Constant * getInfinity(Type *Ty, bool Negative=false)
2: 32-bit floating point type
Constant * getSplatValue() const
getSplatValue - If this is a splat vector constant, meaning that all of the elements have the same va...
const T & front() const
front - Get the first element.
unsigned getNumOperands() const
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
static Constant * getAddrSpaceCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static ConstantAggregateZero * get(Type *Ty)
bool isOneValue() const
Returns true if the value is one.
Constant * ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx)
Attempt to constant fold an extractelement instruction with the specified operands and indices...
Constant * getElementAsConstant(unsigned i) const
getElementAsConstant - Return a Constant for a specified index's element.
static Constant * getBinOpIdentity(unsigned Opcode, Type *Ty)
getBinOpIdentity - Return the identity for the given binary operation, i.e.
Constant * getSplatValue() const
getSplatValue - If this is a splat constant, meaning that all of the elements have the same value...
static PointerType * get(Type *ElementType, unsigned AddressSpace)
PointerType::get - This constructs a pointer to an object of the specified type in a numbered address...
gep_type_iterator gep_type_end(const User *GEP)
Constant * ConstantFoldCastInstruction(unsigned opcode, Constant *V, Type *DestTy)
static Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, bool InBounds=false, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
0 1 0 0 True if ordered and less than
iterator find(StringRef Key)
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...
ShuffleVectorInst - This instruction constructs a fixed permutation of two input vectors.
bool isDoubleTy() const
isDoubleTy - Return true if this is 'double', a 64-bit IEEE fp type.
ConstantInt * TheFalseVal
1 1 1 0 True if unordered or not equal
bool isPtrOrPtrVectorTy() const
isPtrOrPtrVectorTy - Return true if this is a pointer type or a vector of pointer types...
const Function * getParent() const
Return the enclosing method, or null if none.
4: 80-bit floating point type (X87)
const APInt & getUniqueInteger() const
If C is a constant integer then return its value, otherwise C must be a vector of constant integers...
unsigned getAddressSpace() const
Return the address space of the Pointer type.
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
1: 16-bit floating point type
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
static IntegerType * getInt64Ty(LLVMContext &C)
static Constant * getCompare(unsigned short pred, Constant *C1, Constant *C2, bool OnlyIfReduced=false)
Return an ICmp or FCmp comparison operator constant expression.
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
StringRef drop_back(size_t N=1) const
Return a StringRef equal to 'this' but with the last N elements dropped.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
void reserve(size_type N)
static IntegerType * getInt16Ty(LLVMContext &C)
unsigned getOpcode() const
getOpcode - Return the opcode at the root of this constant expression
static Type * getX86_FP80Ty(LLVMContext &C)
bool bitwiseIsEqual(const APFloat &) const
Bitwise comparison for equality (QNaNs compare equal, 0!=-0).
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static Constant * getNullValue(Type *Ty)
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static Constant * getFMul(Constant *C1, Constant *C2)
bool isNegativeZeroValue() const
isNegativeZeroValue - Return true if the value is what would be returned by getZeroValueForNegation.
1 0 0 1 True if unordered or equal
BlockAddress - The address of a basic block.
static const fltSemantics x87DoubleExtended
static InsertElementInst * Create(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
1 0 0 0 True if unordered: isnan(X) | isnan(Y)
static Constant * getIntegerCast(Constant *C, Type *Ty, bool isSigned)
Create a ZExt, Bitcast or Trunc for integer -> integer casts.
static bool castIsValid(Instruction::CastOps op, Value *S, Type *DstTy)
This method can be used to determine if a cast from S to DstTy using Opcode op is valid or not...
static cl::opt< ITMode > IT(cl::desc("IT block support"), cl::Hidden, cl::init(DefaultIT), cl::ZeroOrMore, cl::values(clEnumValN(DefaultIT,"arm-default-it","Generate IT block based on arch"), clEnumValN(RestrictedIT,"arm-restrict-it","Disallow deprecated IT based on ARMv8"), clEnumValN(NoRestrictedIT,"arm-no-restrict-it","Allow IT blocks based on ARMv7"), clEnumValEnd))
static Type * getFloatTy(LLVMContext &C)
const APInt & getValue() const
Return the constant as an APInt value reference.
static Constant * getNegativeZero(Type *Ty)
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
UndefValue - 'undef' values are things that do not have specified contents.
Constant * getSequentialElement() const
getSequentialElement - If this CAZ has array or vector type, return a zero with the right element typ...
static Constant * get(LLVMContext &Context, ArrayRef< uint8_t > Elts)
get() constructors - Return a constant with array type with an element count and element type matchin...
T LLVM_ATTRIBUTE_UNUSED_RESULT pop_back_val()
StructType - Class to represent struct types.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
A Use represents the edge between a Value definition and its users.
static Constant * getLShr(Constant *C1, Constant *C2, bool isExact=false)
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag...
static Constant * get(ArrayRef< Constant * > V)
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches, switches, etc.
0 1 0 1 True if ordered and less than or equal
double getElementAsDouble(unsigned i) const
getElementAsDouble - If this is an sequential container of doubles, return the specified element as a...
static Constant * getSExt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static const fltSemantics IEEEquad
Instruction * getAsInstruction()
getAsInstruction - Returns an Instruction which implements the same operation as this ConstantExpr...
static ConstantInt * ExtractElement(Constant *V, Constant *Idx)
Type * getVectorElementType() const
void remove(ConstantClass *CP)
Remove this constant from the map.
static Type * getPPC_FP128Ty(LLVMContext &C)
ConstantAggregateZero - All zero aggregate value.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
void handleOperandChange(Value *, Value *, Use *)
This method is a special form of User::replaceUsesOfWith (which does not work on constants) that does...
static bool isValidOperands(const Value *V1, const Value *V2, const Value *Mask)
isValidOperands - Return true if a shufflevector instruction can be formed with the specified operand...
bool isDLLImportDependent() const
Return true if the value is dependent on a dllimport variable.
static Constant * getZExt(Constant *C, Type *Ty, bool OnlyIfReduced=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 * getSizeOf(Type *Ty)
getSizeOf constant expr - computes the (alloc) size of a type (in address-units, not bits) in a targe...
static StructType * getTypeForElements(ArrayRef< Constant * > V, bool Packed=false)
getTypeForElements - Return an anonymous struct type to use for a constant with the specified set of ...
ConstantExpr - a constant value that is initialized with an expression using other constant values...
static GetElementPtrInst * CreateInBounds(Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Create an "inbounds" getelementptr.
UndefValue * getElementValue(Constant *C) const
getElementValue - Return an undef of the right value for the specified GEP index. ...
static SelectInst * Create(Value *C, Value *S1, Value *S2, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
LLVMContext & getContext() const
getContext - Return the LLVMContext in which this type was uniqued.
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
static Constant * getFPCast(Constant *C, Type *Ty)
Create a FPExt, Bitcast or FPTrunc for fp -> fp casts.
ConstantDataSequential - A vector or array constant whose element type is a simple 1/2/4/8-byte integ...
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
bool isHalfTy() const
isHalfTy - Return true if this is 'half', a 16-bit IEEE fp type.
ArrayRef< T > slice(unsigned N) const
slice(n) - Chop off the first N elements of the array.
static Constant * getAShr(Constant *C1, Constant *C2, bool isExact=false)
ArrayType - Class to represent array types.
bool isConstantUsed() const
isConstantUsed - Return true if the constant has users other than constant exprs and other dangling t...
UndefValue * getStructElement(unsigned Elt) const
getStructElement - If this undef has struct type, return a undef with the right element type for the ...
static Constant * getSelect(Constant *C, Constant *V1, Constant *V2, Type *OnlyIfReducedTy=nullptr)
Select constant expr.
bool isFirstClassType() const
isFirstClassType - Return true if the type is "first class", meaning it is a valid type for a Value...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
unsigned getActiveBits() const
Compute the number of active bits in the value.
TypeID getTypeID() const
getTypeID - Return the type id for the type.
bool isFloatingPointTy() const
isFloatingPointTy - Return true if this is one of the six floating point types
ArrayConstantsTy ArrayConstants
DenseMap< PointerType *, ConstantPointerNull * > CPNConstants
SequentialType * getType() const
getType - Specialize the getType() method to always return a SequentialType, which reduces the amount...
Constant * ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs)
ConstantFoldInsertValueInstruction - Attempt to constant fold an insertvalue instruction with the spe...
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
bool isArrayTy() const
isArrayTy - True if this is an instance of ArrayType.
static Constant * getUDiv(Constant *C1, Constant *C2, bool isExact=false)
unsigned getNumElements() const
Return the number of elements in the Vector type.
Constant * getWithOperandReplaced(unsigned OpNo, Constant *Op) const
getWithOperandReplaced - Return a constant expression identical to this one, but with the specified o...
const char * getOpcodeName() const
bool isPPC_FP128Ty() const
isPPC_FP128Ty - Return true if this is powerpc long double.
Type * getElementType() const
size_t size() const
size - Get the array size.
static Constant * getFDiv(Constant *C1, Constant *C2)
static APFloat getInf(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Infinity.
PointerType - Class to represent pointers.
10: Arbitrary bit width integers
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static bool removeDeadUsersOfConstant(const Constant *C)
removeDeadUsersOfConstant - If the specified constantexpr is dead, remove it.
bool isNotMinSignedValue() const
Return true if the value is not the smallest signed value.
DenseMap< Type *, ConstantAggregateZero * > CAZConstants
A self-contained host- and target-independent arbitrary-precision floating-point software implementat...
static Constant * getInsertValue(Constant *Agg, Constant *Val, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
bool isIntOrIntVectorTy() const
isIntOrIntVectorTy - Return true if this is an integer type or a vector of integer types...
static bool ConstHasGlobalValuePredicate(const Constant *C, bool(*Predicate)(const GlobalValue *))
Check if C contains a GlobalValue for which Predicate is true.
Constant * ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2, Constant *Mask)
static Constant * getFNeg(Constant *C)
static Constant * getFRem(Constant *C1, Constant *C2)
static CmpInst * Create(OtherOps Op, unsigned short predicate, Value *S1, Value *S2, const Twine &Name="", Instruction *InsertBefore=nullptr)
Construct a compare instruction, given the opcode, the predicate and the two operands.
static Constant * getImpl(StringRef Bytes, Type *Ty)
getImpl - This is the underlying implementation of all of the ConstantDataSequential::get methods...
static ConstantPointerNull * get(PointerType *T)
get() - Static factory methods - Return objects of the specified value
ConstantDataArray - An array constant whose element type is a simple 1/2/4/8-byte integer or float/do...
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
bool canTrap() const
canTrap - Return true if evaluation of this constant could trap.
static Constant * getFP(LLVMContext &Context, ArrayRef< uint16_t > Elts)
getFP() constructors - Return a constant with array type with an element count and element type of fl...
bool isVectorTy() const
isVectorTy - True if this is an instance of VectorType.
static BlockAddress * get(Function *F, BasicBlock *BB)
get - Return a BlockAddress for the specified function and basic block.
Type * getElementType(unsigned N) const
This is an important base class in LLVM.
uint64_t getElementByteSize() const
getElementByteSize - Return the size (in bytes) of each element in the array/vector.
bool hasIndices() const
Return true if this is an insertvalue or extractvalue expression, and the getIndices() method may be ...
StringRef getAsString() const
getAsString - If this array is isString(), then this method returns the array as a StringRef...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
char back() const
back - Get the last character in the string.
StringRef getRawDataValues() const
getRawDataValues - Return the raw, underlying, bytes of this data.
static Constant * getFP(LLVMContext &Context, ArrayRef< uint16_t > Elts)
getFP() constructors - Return a constant with vector type with an element count and element type of f...
bool isFloatTy() const
isFloatTy - Return true if this is 'float', a 32-bit IEEE fp type.
static Constant * getAnd(Constant *C1, Constant *C2)
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
static Constant * get(ArrayType *T, ArrayRef< Constant * > V)
ConstantFP - Floating Point Values [float, double].
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
bool isZeroValue() const
Return true if the value is negative zero or null value.
static Constant * getSExtOrBitCast(Constant *C, Type *Ty)
static Constant * getShuffleVector(Constant *V1, Constant *V2, Constant *Mask, Type *OnlyIfReducedTy=nullptr)
UndefValue * getSequentialElement() const
getSequentialElement - If this Undef has array or vector type, return a undef with the right element ...
uint64_t getNumElements() const
static bool canTrapImpl(const Constant *C, SmallPtrSetImpl< const ConstantExpr * > &NonTrappingOps)
unsigned getBitWidth() const
Return the number of bits in the APInt.
unsigned getValueID() const
Return an ID for the concrete type of this object.
opStatus convert(const fltSemantics &, roundingMode, bool *)
APFloat::convert - convert a value of one floating point type to another.
6: 128-bit floating point type (two 64-bits, PowerPC)
Value * getOperand(unsigned i) const
0 1 1 1 True if ordered (no nans)
ConstantClass * replaceOperandsInPlace(ArrayRef< Constant * > Operands, ConstantClass *CP, Value *From, Constant *To, unsigned NumUpdated=0, unsigned OperandNo=~0u)
static bool isValueValidForType(Type *Ty, const APFloat &V)
isValueValidForType - return true if Ty is big enough to represent V.
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...
Class to represent integer types.
ConstantVector - Constant Vector Declarations.
static Constant * get(StructType *T, ArrayRef< Constant * > V)
static Constant * getSplat(unsigned NumElts, Constant *Elt)
getSplat - Return a ConstantVector with the specified constant in each element.
bool empty() const
empty - Check if the array is empty.
static Constant * getNot(Constant *C)
Constant * getAggregateElement(unsigned Elt) const
getAggregateElement - For aggregates (struct/array/vector) return the constant that corresponds to th...
static Constant * getAllOnesValue(Type *Ty)
Get the all ones value.
unsigned getPredicate() const
getPredicate - Return the ICMP or FCMP predicate value.
1 1 1 1 Always true (always folded)
ArrayRef< unsigned > getIndices() const
getIndices - Assert that this is an insertvalue or exactvalue expression and return the list of indic...
uint64_t getElementAsInteger(unsigned i) const
getElementAsInteger - If this is a sequential container of integers (of any size), return the specified element in the low bits of a uint64_t.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
static const fltSemantics * TypeToFloatSemantics(Type *Ty)
bool isFP128Ty() const
isFP128Ty - Return true if this is 'fp128'.
bool isPointerTy() const
isPointerTy - True if this is an instance of PointerType.
static UndefValue * get(Type *T)
get() - Static factory methods - Return an 'undef' object of the specified type.
LLVMContext & getContext() const
All values hold a context through their type.
bool isFPOrFPVectorTy() const
isFPOrFPVectorTy - Return true if this is a FP type or a vector of FP.
PointerType * getPointerTo(unsigned AddrSpace=0)
getPointerTo - Return a pointer to the current type.
Constant * ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1, Constant *V2)
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
1 1 0 1 True if unordered, less than, or equal
static const fltSemantics IEEEhalf
VectorConstantsTy VectorConstants
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
LLVMContextImpl *const pImpl
bool isCString() const
isCString - This method returns true if the array "isString", ends with a nul byte, and does not contains any other nul bytes.
static Type * getFP128Ty(LLVMContext &C)
Constant * ConstantFoldGetElementPtr(Constant *C, bool inBounds, ArrayRef< Constant * > Idxs)
static Constant * getIntegerValue(Type *Ty, const APInt &V)
getIntegerValue - Return the value for an integer or pointer constant, or a vector thereof...
void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag...
bool isCompare() const
Return true if this is a compare constant expression.
static Constant * getFCmp(unsigned short pred, Constant *LHS, Constant *RHS, bool OnlyIfReduced=false)
0 0 1 0 True if ordered and greater than
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
static Constant * getSIToFP(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Type * getHalfTy(LLVMContext &C)
static Constant * getSplat(unsigned NumElts, Constant *Elt)
getSplat - Return a ConstantVector with the specified constant in each element.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
static bool isAllZeros(StringRef Arr)
isAllZeros - return true if the array is empty or all zeros.
PossibleRelocationsTy getRelocationInfo() const
getRelocationInfo - This method classifies the entry according to whether or not it may generate a re...
static const fltSemantics PPCDoubleDouble
ArrayType * getType() const
getType - Specialize the getType() method to always return an ArrayType, which reduces the amount of ...
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
unsigned getIntegerBitWidth() const
static PointerType * getUnqual(Type *ElementType)
PointerType::getUnqual - This constructs a pointer to an object of the specified type in the generic ...
This is the shared class of boolean and integer constants.
15: SIMD 'packed' format, or other vector type
unsigned getVectorNumElements() const
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
StructType::get - This static method is the primary way to create a literal StructType.
static Constant * getSDiv(Constant *C1, Constant *C2, bool isExact=false)
unsigned getScalarSizeInBits() const LLVM_READONLY
getScalarSizeInBits - If this is a vector type, return the getPrimitiveSizeInBits value for the eleme...
1 1 0 0 True if unordered or less than
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
ConstantPointerNull - a constant pointer value that points to null.
const char * getOpcodeName() const
getOpcodeName - Return a string representation for an opcode.
CHAIN = SC CHAIN, Imm128 - System call.
static APFloat getAllOnesValue(unsigned BitWidth, bool isIEEE=false)
Returns a float which is bitcasted from an all one value int.
BasicBlock * getBasicBlock() const
Value * stripPointerCasts()
Strip off pointer casts, all-zero GEPs, and aliases.
static Constant * getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced=false)
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 * getSigned(IntegerType *Ty, int64_t V)
Return a ConstantInt with the specified value for the specified type.
static Constant * get(Type *Ty, double V)
get() - This returns a ConstantFP, or a vector containing a splat of a ConstantFP, for the specified value in the specified type.
bool isNullValue() const
isNullValue - Return true if this is the value that would be returned by getNullValue.
static ConstantInt * getTrue(LLVMContext &Context)
void setOperand(unsigned i, Value *Val)
static BlockAddress * lookup(const BasicBlock *BB)
Lookup an existing BlockAddress constant for the given BasicBlock.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isAllOnesValue() const
isAllOnesValue - Return true if this is the value that would be returned by getAllOnesValue.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
VectorType - Class to represent vector types.
ConstantArray - Constant Array Declarations.
Class for arbitrary precision integers.
bool isCast() const
Return true if this is a convert constant expression.
unsigned getNumElements() const
Return the number of elements in the array, vector, or struct.
bool isIntegerTy() const
isIntegerTy - True if this is an instance of IntegerType.
StructType * getType() const
getType() specialization - Reduce amount of casting...
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.
GetElementPtrConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
iterator_range< user_iterator > users()
static Constant * getFPToUI(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
static char getTypeID(Type *Ty)
static bool isElementTypeCompatible(const Type *Ty)
isElementTypeCompatible - Return true if a ConstantDataSequential can be formed with a vector or arra...
DenseMap< Type *, UndefValue * > UVConstants
static Constant * getZExtOrBitCast(Constant *C, Type *Ty)
const Type * getScalarType() const LLVM_READONLY
getScalarType - If this is a vector type, return the element type, otherwise return 'this'...
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
bool isStructTy() const
isStructTy - True if this is an instance of StructType.
static Constant * getFSub(Constant *C1, Constant *C2)
static Type * getIndexedType(Type *Ty, ArrayRef< Value * > IdxList)
getIndexedType - Returns the type of the element that would be loaded with a load instruction with th...
bool isGEPWithNoNotionalOverIndexing() const
Return true if this is a getelementptr expression and all the index operands are compile-time known i...
static Constant * getTruncOrBitCast(Constant *C, Type *Ty)
static Constant * getNeg(Constant *C, bool HasNUW=false, bool HasNSW=false)
Constant * ConstantFoldCompareInstruction(unsigned short predicate, Constant *C1, Constant *C2)
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 isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
static APFloat getNaN(const fltSemantics &Sem, bool Negative=false, unsigned type=0)
Factory for QNaN values.
Constant * getElementValue(Constant *C) const
getElementValue - Return a zero of the right value for the specified GEP index.
PointerType * getType() const
Global values are always pointers.
static const fltSemantics IEEEsingle
Constant * ConstantFoldSelectInstruction(Constant *Cond, Constant *V1, Constant *V2)
user_iterator_impl< const User > const_user_iterator
bool isX86_FP80Ty() const
isX86_FP80Ty - Return true if this is x86 long double.
static IntegerType * getInt32Ty(LLVMContext &C)
float getElementAsFloat(unsigned i) const
getElementAsFloat - If this is an sequential container of floats, return the specified element as a f...
static Constant * getOffsetOf(StructType *STy, unsigned FieldNo)
getOffsetOf constant expr - computes the offset of a struct field in a target independent way (Note: ...
unsigned greater or equal
static InsertValueInst * Create(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &NameStr="", Instruction *InsertBefore=nullptr)
Type * getSourceElementType() const
static Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getOr(Constant *C1, Constant *C2)
static Constant * getZeroValueForNegation(Type *Ty)
Floating point negation must be implemented with f(x) = -0.0 - x.
unsigned getNumElements() const
getNumElements - Return the number of elements in the array or vector.
unsigned getNumElements() const
Return the number of elements in the array, vector, or struct.
Constant * ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt, Constant *Idx)
0 1 1 0 True if ordered and operands are unequal
static ArrayType * get(Type *ElementType, uint64_t NumElements)
ArrayType::get - This static method is the primary way to construct an ArrayType. ...
Compile-time customization of User operands.
bool isString() const
isString - This method returns true if this is an array of i8.
static Constant * getShl(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
void destroyConstant()
Called if some element of this constant is no longer valid.
PointerType * getType() const
getType - Specialize the getType() method to always return an PointerType, which reduces the amount o...
ConstantUniqueMap< ConstantExpr > ExprConstants
1 0 1 0 True if unordered or greater than
VectorType * getType() const
getType - Specialize the getType() method to always return a VectorType, which reduces the amount of ...
bool isExactlyValue(const APFloat &V) const
isExactlyValue - We don't rely on operator== working on double values, as it returns true for things ...
Type * getElementType() const
getElementType - Return the element type of the array/vector.
3: 64-bit floating point type
Function * getFunction() const
user_iterator user_begin()
static Constant * getSRem(Constant *C1, Constant *C2)
void removeDeadConstantUsers() const
removeDeadConstantUsers - If there are any dead constant users dangling off of this constant...
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
getPrimitiveSizeInBits - Return the basic size of this type if it is a primitive type.
0 0 0 1 True if ordered and equal
StructConstantsTy StructConstants
LLVM Value Representation.
1 0 1 1 True if unordered, greater than, or equal
static Constant * getURem(Constant *C1, Constant *C2)
static VectorType * get(Type *ElementType, unsigned NumElements)
VectorType::get - This static method is the primary way to construct an VectorType.
static Constant * getUIToFP(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getFPToSI(Constant *C, Type *Ty, bool OnlyIfReduced=false)
Constant * getStructElement(unsigned Elt) const
getStructElement - If this CAZ has struct type, return a zero with the right element type for the spe...
ConstantClass * getOrCreate(TypeClass *Ty, ValType V)
Return the specified constant from the map, creating it if necessary.
static Constant * getExtractValue(Constant *Agg, ArrayRef< unsigned > Idxs, Type *OnlyIfReducedTy=nullptr)
StringRef - Represent a constant reference to a string, i.e.
Constant * ConstantFoldExtractValueInstruction(Constant *Agg, ArrayRef< unsigned > Idxs)
Attempt to constant fold an extractvalue instruction with the specified operands and indices...
static APInt getNullValue(unsigned numBits)
Get the '0' value.
static Constant * getAlignOf(Type *Ty)
getAlignOf constant expr - computes the alignment of a type in a target independent way (Note: the re...
static Constant * getMul(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
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...
unsigned getNumElements() const
Random access to the elements.
0 0 1 1 True if ordered and greater than or equal
static Constant * getFPExtend(Constant *C, Type *Ty, bool OnlyIfReduced=false)
StringMap< ConstantDataSequential * > CDSConstants
bool isThreadDependent() const
isThreadDependent - Return true if the value can vary between threads.
Constant * getWithOperands(ArrayRef< Constant * > Ops) const
getWithOperands - This returns the current constant expression with the operands replaced with the sp...
static Constant * getBinOpAbsorber(unsigned Opcode, Type *Ty)
getBinOpAbsorber - Return the absorbing element for the given binary operation, i.e.
static IntegerType * getInt8Ty(LLVMContext &C)
const fltSemantics & getSemantics() const
Constant * getSplatValue() const
getSplatValue - If this is a splat constant, meaning that all of the elements have the same value...
0 0 0 0 Always false (always folded)
bool isMinSignedValue() const
Return true if the value is the smallest signed value.
static Constant * getXor(Constant *C1, Constant *C2)
5: 128-bit floating point type (112-bit mantissa)
gep_type_iterator gep_type_begin(const User *GEP)
static const char * areInvalidOperands(Value *Cond, Value *True, Value *False)
areInvalidOperands - Return a string if the specified operands are invalid for a select operation...