1//===-- Constants.cpp - Implement Constant nodes --------------------------===// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7//===----------------------------------------------------------------------===// 9// This file implements the Constant* classes. 11//===----------------------------------------------------------------------===// 36using namespacePatternMatch;
38// As set of temporary options to help migrate how splats are represented. 41cl::desc(
"Use ConstantInt's native fixed-length vector splat support."));
44cl::desc(
"Use ConstantFP's native fixed-length vector splat support."));
47cl::desc(
"Use ConstantInt's native scalable vector splat support."));
50cl::desc(
"Use ConstantFP's native scalable vector splat support."));
52//===----------------------------------------------------------------------===// 54//===----------------------------------------------------------------------===// 57// Floating point values have an explicit -0.0 value. 58if (
constConstantFP *CFP = dyn_cast<ConstantFP>(
this))
59return CFP->isZero() && CFP->isNegative();
61// Equivalent for a vector of -0.0's. 63if (
constauto *SplatCFP = dyn_cast_or_null<ConstantFP>(
getSplatValue()))
64return SplatCFP->isNegativeZeroValue();
66// We've already handled true FP case; any other FP vectors can't represent -0.0. 67if (
getType()->isFPOrFPVectorTy())
70// Otherwise, just use +0.0. 74// Return true iff this constant is positive zero (floating point), negative 75// zero (floating point), or a null value. 77// Floating point values have an explicit -0.0 value. 78if (
constConstantFP *CFP = dyn_cast<ConstantFP>(
this))
81// Check for constant splat vectors of 1 values. 83if (
constauto *SplatCFP = dyn_cast_or_null<ConstantFP>(
getSplatValue()))
84return SplatCFP->isZero();
86// Otherwise, just use +0.0. 92if (
constConstantInt *CI = dyn_cast<ConstantInt>(
this))
96if (
constConstantFP *CFP = dyn_cast<ConstantFP>(
this))
97// ppc_fp128 determine isZero using high order double only 98// Should check the bitwise value to make sure all bits are zero. 99return CFP->isExactlyValue(+0.0);
101// constant zero is zero for aggregates, cpnull is null for pointers, none for 103return isa<ConstantAggregateZero>(
this) || isa<ConstantPointerNull>(
this) ||
104 isa<ConstantTokenNone>(
this) || isa<ConstantTargetNone>(
this);
108// Check for -1 integers 109if (
constConstantInt *CI = dyn_cast<ConstantInt>(
this))
110return CI->isMinusOne();
112// Check for FP which are bitcasted from -1 integers 113if (
constConstantFP *CFP = dyn_cast<ConstantFP>(
this))
114return CFP->getValueAPF().bitcastToAPInt().isAllOnes();
116// Check for constant splat vectors of 1 values. 119return SplatVal->isAllOnesValue();
125// Check for 1 integers 126if (
constConstantInt *CI = dyn_cast<ConstantInt>(
this))
129// Check for FP which are bitcasted from 1 integers 130if (
constConstantFP *CFP = dyn_cast<ConstantFP>(
this))
131return CFP->getValueAPF().bitcastToAPInt().isOne();
133// Check for constant splat vectors of 1 values. 136return SplatVal->isOneValue();
142// Check for 1 integers 143if (
constConstantInt *CI = dyn_cast<ConstantInt>(
this))
144return !CI->isOneValue();
146// Check for FP which are bitcasted from 1 integers 147if (
constConstantFP *CFP = dyn_cast<ConstantFP>(
this))
148return !CFP->getValueAPF().bitcastToAPInt().isOne();
150// Check that vectors don't contain 1 151if (
auto *VTy = dyn_cast<FixedVectorType>(
getType())) {
152for (
unsignedI = 0, E = VTy->getNumElements();
I != E; ++
I) {
160// Check for splats that don't contain 1 163return SplatVal->isNotOneValue();
165// It *may* contain 1, we can't tell. 170// Check for INT_MIN integers 171if (
constConstantInt *CI = dyn_cast<ConstantInt>(
this))
172return CI->isMinValue(
/*isSigned=*/true);
174// Check for FP which are bitcasted from INT_MIN integers 175if (
constConstantFP *CFP = dyn_cast<ConstantFP>(
this))
176return CFP->getValueAPF().bitcastToAPInt().isMinSignedValue();
178// Check for splats of INT_MIN values. 181return SplatVal->isMinSignedValue();
187// Check for INT_MIN integers 188if (
constConstantInt *CI = dyn_cast<ConstantInt>(
this))
189return !CI->isMinValue(
/*isSigned=*/true);
191// Check for FP which are bitcasted from INT_MIN integers 192if (
constConstantFP *CFP = dyn_cast<ConstantFP>(
this))
193return !CFP->getValueAPF().bitcastToAPInt().isMinSignedValue();
195// Check that vectors don't contain INT_MIN 196if (
auto *VTy = dyn_cast<FixedVectorType>(
getType())) {
197for (
unsignedI = 0, E = VTy->getNumElements();
I != E; ++
I) {
205// Check for splats that aren't INT_MIN 208return SplatVal->isNotMinSignedValue();
210// It *may* contain INT_MIN, we can't tell. 215if (
auto *CFP = dyn_cast<ConstantFP>(
this))
216return CFP->getValueAPF().isFiniteNonZero();
218if (
auto *VTy = dyn_cast<FixedVectorType>(
getType())) {
219for (
unsignedI = 0, E = VTy->getNumElements();
I != E; ++
I) {
221if (!CFP || !CFP->getValueAPF().isFiniteNonZero())
228if (
constauto *SplatCFP = dyn_cast_or_null<ConstantFP>(
getSplatValue()))
229return SplatCFP->isFiniteNonZeroFP();
231// It *may* contain finite non-zero, we can't tell. 236if (
auto *CFP = dyn_cast<ConstantFP>(
this))
237return CFP->getValueAPF().isNormal();
239if (
auto *VTy = dyn_cast<FixedVectorType>(
getType())) {
240for (
unsignedI = 0, E = VTy->getNumElements();
I != E; ++
I) {
242if (!CFP || !CFP->getValueAPF().isNormal())
249if (
constauto *SplatCFP = dyn_cast_or_null<ConstantFP>(
getSplatValue()))
250return SplatCFP->isNormalFP();
252// It *may* contain a normal fp value, we can't tell. 257if (
auto *CFP = dyn_cast<ConstantFP>(
this))
258return CFP->getValueAPF().getExactInverse(
nullptr);
260if (
auto *VTy = dyn_cast<FixedVectorType>(
getType())) {
261for (
unsignedI = 0, E = VTy->getNumElements();
I != E; ++
I) {
263if (!CFP || !CFP->getValueAPF().getExactInverse(
nullptr))
270if (
constauto *SplatCFP = dyn_cast_or_null<ConstantFP>(
getSplatValue()))
271return SplatCFP->hasExactInverseFP();
273// It *may* have an exact inverse fp value, we can't tell. 278if (
auto *CFP = dyn_cast<ConstantFP>(
this))
281if (
auto *VTy = dyn_cast<FixedVectorType>(
getType())) {
282for (
unsignedI = 0, E = VTy->getNumElements();
I != E; ++
I) {
284if (!CFP || !CFP->isNaN())
291if (
constauto *SplatCFP = dyn_cast_or_null<ConstantFP>(
getSplatValue()))
292return SplatCFP->isNaN();
294// It *may* be NaN, we can't tell. 299// Are they fully identical? 303// The input value must be a vector constant with the same type. 304auto *VTy = dyn_cast<VectorType>(
getType());
305if (!isa<Constant>(
Y) || !VTy || VTy !=
Y->getType())
308// TODO: Compare pointer constants? 309if (!(VTy->getElementType()->isIntegerTy() ||
310 VTy->getElementType()->isFloatingPointTy()))
313// They may still be identical element-wise (if they have `undef`s). 314// Bitcast to integer to allow exact bitwise comparison for all types. 319return CmpEq && (isa<PoisonValue>(CmpEq) ||
match(CmpEq,
m_One()));
325if (
auto *VTy = dyn_cast<VectorType>(
C->getType())) {
328if (isa<ConstantAggregateZero>(
C))
330if (isa<ScalableVectorType>(
C->getType()))
333for (
unsigned i = 0, e = cast<FixedVectorType>(VTy)->
getNumElements();
335if (
Constant *Elem =
C->getAggregateElement(i))
346this, [&](
constauto *
C) {
return isa<UndefValue>(
C); });
351this, [&](
constauto *
C) {
return isa<PoisonValue>(
C); });
356return isa<UndefValue>(
C) && !isa<PoisonValue>(
C);
361if (isa<ConstantInt>(
this) || isa<ConstantFP>(
this))
364if (
auto *VTy = dyn_cast<FixedVectorType>(
getType())) {
365for (
unsigned i = 0, e = VTy->getNumElements(); i != e; ++i)
372/// Constructor to create a '0' constant of arbitrary type. 376return ConstantInt::get(Ty, 0);
398// Function, Label, or Opaque type? 406// Create the base integer constant. 409// Convert an integer to a pointer, if necessary. 410if (
PointerType *PTy = dyn_cast<PointerType>(ScalarTy))
413// Broadcast a scalar to a vector, if necessary. 414if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
437"Must be an aggregate/vector constant");
439if (
constauto *
CC = dyn_cast<ConstantAggregate>(
this))
440return Elt <
CC->getNumOperands() ?
CC->getOperand(Elt) :
nullptr;
442if (
constauto *CAZ = dyn_cast<ConstantAggregateZero>(
this))
443return Elt < CAZ->getElementCount().getKnownMinValue()
444 ? CAZ->getElementValue(Elt)
447if (
constauto *CI = dyn_cast<ConstantInt>(
this))
448return Elt < cast<VectorType>(
getType())
451 ? ConstantInt::get(
getContext(), CI->getValue())
454if (
constauto *CFP = dyn_cast<ConstantFP>(
this))
455return Elt < cast<VectorType>(
getType())
458 ? ConstantFP::get(
getContext(), CFP->getValue())
461// FIXME: getNumElements() will fail for non-fixed vector types. 462if (isa<ScalableVectorType>(
getType()))
465if (
constauto *PV = dyn_cast<PoisonValue>(
this))
466return Elt < PV->getNumElements() ? PV->getElementValue(Elt) :
nullptr;
468if (
constauto *UV = dyn_cast<UndefValue>(
this))
469return Elt < UV->getNumElements() ? UV->getElementValue(Elt) :
nullptr;
471if (
constauto *CDS = dyn_cast<ConstantDataSequential>(
this))
472return Elt < CDS->getNumElements() ? CDS->getElementAsConstant(Elt)
479assert(isa<IntegerType>(Elt->
getType()) &&
"Index must be an integer");
481// Check if the constant fits into an uint64_t. 482if (CI->getValue().getActiveBits() > 64)
490 /// First call destroyConstantImpl on the subclass. This gives the subclass 491 /// a chance to remove the constant from any maps/pools it's contained in. 495#define HANDLE_CONSTANT(Name) \ 496 case Value::Name##Val: \ 497 cast<Name>(this)->destroyConstantImpl(); \ 499#include "llvm/IR/Value.def" 502// When a Constant is destroyed, there may be lingering 503// references to the constant by other constants in the constant pool. These 504// constants are implicitly dependent on the module that is being deleted, 505// but they don't know that. Because we only find out when the CPV is 506// deleted, we must now notify all of our users (that should only be 507// Constants) that they are, in fact, invalid now and should be deleted. 511#ifndef NDEBUG// Only in -g mode... 512if (!isa<Constant>(V)) {
513dbgs() <<
"While deleting: " << *
this 514 <<
"\n\nUse still stuck around after Def is destroyed: " << *V
518assert(isa<Constant>(V) &&
"References remain to Constant being destroyed");
519 cast<Constant>(V)->destroyConstant();
521// The constant should remove itself from our use list... 525// Value has no outstanding references it is safe to delete it now... 530switch (
C->getValueID()) {
531case Constant::ConstantIntVal:
534case Constant::ConstantFPVal:
537case Constant::ConstantAggregateZeroVal:
540case Constant::ConstantArrayVal:
543case Constant::ConstantStructVal:
546case Constant::ConstantVectorVal:
549case Constant::ConstantPointerNullVal:
552case Constant::ConstantDataArrayVal:
555case Constant::ConstantDataVectorVal:
558case Constant::ConstantTokenNoneVal:
561case Constant::BlockAddressVal:
564case Constant::DSOLocalEquivalentVal:
567case Constant::NoCFIValueVal:
570case Constant::ConstantPtrAuthVal:
573case Constant::UndefValueVal:
576case Constant::PoisonValueVal:
579case Constant::ConstantExprVal:
580if (isa<CastConstantExpr>(
C))
582elseif (isa<BinaryConstantExpr>(
C))
584elseif (isa<ExtractElementConstantExpr>(
C))
586elseif (isa<InsertElementConstantExpr>(
C))
588elseif (isa<ShuffleVectorConstantExpr>(
C))
590elseif (isa<GetElementPtrConstantExpr>(
C))
600/// Check if C contains a GlobalValue for which Predicate is true. 609while (!WorkList.
empty()) {
611if (
constauto *GV = dyn_cast<GlobalValue>(
WorkItem))
615constConstant *ConstOp = dyn_cast<Constant>(
Op);
618if (Visited.
insert(ConstOp).second)
626auto DLLImportPredicate = [](
constGlobalValue *GV) {
627return GV->isThreadLocal();
633auto DLLImportPredicate = [](
constGlobalValue *GV) {
634return GV->hasDLLImportStorageClass();
641constConstant *UC = dyn_cast<Constant>(U);
642if (!UC || isa<GlobalValue>(UC))
652return getRelocationInfo() == GlobalRelocation;
656return getRelocationInfo() != NoRelocation;
659Constant::PossibleRelocationsTy Constant::getRelocationInfo()
const{
660if (isa<GlobalValue>(
this))
661return GlobalRelocation;
// Global reference. 663if (
constBlockAddress *BA = dyn_cast<BlockAddress>(
this))
664return BA->getFunction()->getRelocationInfo();
666if (
constConstantExpr *CE = dyn_cast<ConstantExpr>(
this)) {
667if (CE->getOpcode() == Instruction::Sub) {
670if (LHS && RHS &&
LHS->getOpcode() == Instruction::PtrToInt &&
671RHS->getOpcode() == Instruction::PtrToInt) {
675// While raw uses of blockaddress need to be relocated, differences 676// between two of them don't when they are for labels in the same 677// function. This is a common idiom when creating a table for the 678// indirect goto extension, so we handle it efficiently here. 679if (isa<BlockAddress>(LHSOp0) && isa<BlockAddress>(RHSOp0) &&
684// Relative pointers do not need to be dynamically relocated. 688if (
auto *LHSGV = dyn_cast<GlobalValue>(LHS)) {
689if (LHSGV->isDSOLocal() && RHSGV->isDSOLocal())
690return LocalRelocation;
691 }
elseif (isa<DSOLocalEquivalent>(LHS)) {
692if (RHSGV->isDSOLocal())
693return LocalRelocation;
700 PossibleRelocationsTy
Result = NoRelocation;
702Result = std::max(cast<Constant>(
Op)->getRelocationInfo(), Result);
707/// Return true if the specified constantexpr is dead. This involves 708/// recursively traversing users of the constantexpr. 709/// If RemoveDeadUsers is true, also remove dead users at the same time. 711if (isa<GlobalValue>(
C))
returnfalse;
// Cannot remove this 716if (!
User)
returnfalse;
// Non-constant usage; 718returnfalse;
// Constant wasn't dead 720// Just removed User, so the iterator was invalidated. 721// Since we return immediately upon finding a live user, we can always 722// restart from user_begin(). 729if (RemoveDeadUsers) {
730// If C is only used by metadata, it should not be preserved but should 731// have its uses replaced. 733const_cast<Constant *
>(
C)->destroyConstant();
751// If the constant wasn't dead, remember that this was the last live use 752// and move on to the next constant. 758// If the constant was dead, then the iterator is invalidated. 759if (LastNonDeadUser == E)
762I = std::next(LastNonDeadUser);
770bool Constant::hasNLiveUses(
unsignedN)
const{
785assert(
C && Replacement &&
"Expected non-nullptr constant arguments");
786Type *Ty =
C->getType();
788assert(Ty == Replacement->
getType() &&
"Expected matching types");
792// Don't know how to deal with this constant. 793auto *VTy = dyn_cast<FixedVectorType>(Ty);
797unsigned NumElts = VTy->getNumElements();
799for (
unsigned i = 0; i != NumElts; ++i) {
800Constant *EltC =
C->getAggregateElement(i);
802"Expected matching types");
803 NewC[i] = EltC &&
match(EltC,
m_Undef()) ? Replacement : EltC;
809assert(
C &&
Other &&
"Expected non-nullptr constant arguments");
813Type *Ty =
C->getType();
817auto *VTy = dyn_cast<FixedVectorType>(Ty);
821Type *EltTy = VTy->getElementType();
822unsigned NumElts = VTy->getNumElements();
824 cast<FixedVectorType>(
Other->getType())->getNumElements() == NumElts &&
827bool FoundExtraUndef =
false;
829for (
unsignedI = 0;
I != NumElts; ++
I) {
830 NewC[
I] =
C->getAggregateElement(
I);
832assert(NewC[
I] && OtherEltC &&
"Unknown vector element");
835 FoundExtraUndef =
true;
844if (isa<ConstantData>(
this))
846if (isa<ConstantAggregate>(
this) || isa<ConstantExpr>(
this)) {
855//===----------------------------------------------------------------------===// 857//===----------------------------------------------------------------------===// 859ConstantInt::ConstantInt(
Type *Ty,
constAPInt &V)
863"Invalid constant for type");
887if (
auto *VTy = dyn_cast<VectorType>(Ty))
895if (
auto *VTy = dyn_cast<VectorType>(Ty))
904// Get a ConstantInt from an APInt. 906// get an existing value or the insertion position 908 std::unique_ptr<ConstantInt> &Slot =
913// Get the corresponding integer type for the bit width of the value. 921// Get a ConstantInt vector with each lane set to the same APInt. 924// Get an existing value or the insertion position. 925 std::unique_ptr<ConstantInt> &Slot =
936assert(Slot->getType() == VTy);
944// For vectors, broadcast the value. 945if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
952// TODO: Avoid implicit trunc? 953// See https://github.com/llvm/llvm-project/issues/112510. 961"ConstantInt type doesn't match the type implied by its value!");
963// For vectors, broadcast the value. 964if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
974/// Remove the constant from the constant table. 975void ConstantInt::destroyConstantImpl() {
979//===----------------------------------------------------------------------===// 981//===----------------------------------------------------------------------===// 992// For vectors, broadcast the value. 993if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1002"ConstantFP type doesn't match the type implied by its value!");
1004// For vectors, broadcast the value. 1005if (
auto *VTy = dyn_cast<VectorType>(Ty))
1017// For vectors, broadcast the value. 1018if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1029if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1040if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1051if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1062if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1069// ConstantFP accessors. 1073 std::unique_ptr<ConstantFP> &Slot = pImpl->
FPConstants[V];
1083// Get a ConstantFP vector with each lane set to the same APFloat. 1086// Get an existing value or the insertion position. 1087 std::unique_ptr<ConstantFP> &Slot =
1098assert(Slot->getType() == VTy);
1107if (
VectorType *VTy = dyn_cast<VectorType>(Ty))
1123/// Remove the constant from the constant table. 1124void ConstantFP::destroyConstantImpl() {
1128//===----------------------------------------------------------------------===// 1129// ConstantAggregateZero Implementation 1130//===----------------------------------------------------------------------===// 1133if (
auto *AT = dyn_cast<ArrayType>(
getType()))
1156if (
auto *AT = dyn_cast<ArrayType>(Ty))
1158if (
auto *VT = dyn_cast<VectorType>(Ty))
1159return VT->getElementCount();
1163//===----------------------------------------------------------------------===// 1164// UndefValue Implementation 1165//===----------------------------------------------------------------------===// 1191if (
auto *AT = dyn_cast<ArrayType>(Ty))
1192return AT->getNumElements();
1193if (
auto *VT = dyn_cast<VectorType>(Ty))
1194return cast<FixedVectorType>(VT)->getNumElements();
1198//===----------------------------------------------------------------------===// 1199// PoisonValue Implementation 1200//===----------------------------------------------------------------------===// 1224//===----------------------------------------------------------------------===// 1225// ConstantXXX Classes 1226//===----------------------------------------------------------------------===// 1228template <
typename ItTy,
typename EltTy>
1230for (; Start !=
End; ++Start)
1236template <
typename SequentialTy,
typename ElementTy>
1238assert(!V.empty() &&
"Cannot get empty int sequence.");
1242if (
auto *CI = dyn_cast<ConstantInt>(
C))
1246return SequentialTy::get(V[0]->getContext(), Elts);
1249template <
typename SequentialTy,
typename ElementTy>
1251assert(!V.empty() &&
"Cannot get empty FP sequence.");
1255if (
auto *CFP = dyn_cast<ConstantFP>(
C))
1256 Elts.
push_back(CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
1259return SequentialTy::getFP(V[0]->
getType(), Elts);
1262template <
typename SequenceTy>
1265// We speculatively build the elements here even if it turns out that there is 1266// a constantexpr or something else weird, since it is so uncommon for that to 1269if (CI->getType()->isIntegerTy(8))
1270return getIntSequenceIfElementsMatch<SequenceTy, uint8_t>(V);
1271elseif (CI->getType()->isIntegerTy(16))
1272return getIntSequenceIfElementsMatch<SequenceTy, uint16_t>(V);
1273elseif (CI->getType()->isIntegerTy(32))
1274return getIntSequenceIfElementsMatch<SequenceTy, uint32_t>(V);
1275elseif (CI->getType()->isIntegerTy(64))
1276return getIntSequenceIfElementsMatch<SequenceTy, uint64_t>(V);
1277 }
elseif (
ConstantFP *CFP = dyn_cast<ConstantFP>(
C)) {
1278if (CFP->getType()->isHalfTy() || CFP->getType()->isBFloatTy())
1279return getFPSequenceIfElementsMatch<SequenceTy, uint16_t>(V);
1280elseif (CFP->getType()->isFloatTy())
1281return getFPSequenceIfElementsMatch<SequenceTy, uint32_t>(V);
1282elseif (CFP->getType()->isDoubleTy())
1283return getFPSequenceIfElementsMatch<SequenceTy, uint64_t>(V);
1295// Check that types match, unless this is an opaque struct. 1296if (
auto *ST = dyn_cast<StructType>(
T)) {
1299for (
unsignedI = 0, E = V.size();
I != E; ++
I)
1301"Initializer for struct element doesn't match!");
1308assert(V.size() ==
T->getNumElements() &&
1309"Invalid initializer for constant array");
1319// Empty arrays are canonicalized to ConstantAggregateZero. 1325"Wrong type in array element initializer");
1329// If this is an all-zero array, return a ConstantAggregateZero object. If 1330// all undef, return an UndefValue, if "all simple", then return a 1331// ConstantDataArray. 1342// Check to see if all of the elements are ConstantFP or ConstantInt and if 1343// the element type is compatible with ConstantDataVector. If so, use it. 1345return getSequenceIfElementsMatch<ConstantDataArray>(
C, V);
1347// Otherwise, we really do want to create a ConstantArray. 1354unsigned VecSize = V.size();
1356for (
unsigned i = 0; i != VecSize; ++i)
1357 EltTypes[i] = V[i]->
getType();
1366"ConstantStruct::getTypeForElements cannot be called on empty list");
1373assert((
T->isOpaque() || V.size() ==
T->getNumElements()) &&
1374"Invalid initializer for constant struct");
1377// ConstantStruct accessors. 1379assert((ST->isOpaque() || ST->getNumElements() == V.size()) &&
1380"Incorrect # elements specified to ConstantStruct::get");
1382// Create a ConstantAggregateZero value if all elements are zeros. 1385bool isPoison =
false;
1388isUndef = isa<UndefValue>(V[0]);
1389 isPoison = isa<PoisonValue>(V[0]);
1390isZero = V[0]->isNullValue();
1391// PoisonValue inherits UndefValue, so its check is not necessary. 1394if (!
C->isNullValue())
1396if (!isa<PoisonValue>(
C))
1398if (isa<PoisonValue>(
C) || !isa<UndefValue>(
C))
1410return ST->getContext().pImpl->StructConstants.getOrCreate(ST, V);
1416assert(V.size() == cast<FixedVectorType>(
T)->getNumElements() &&
1417"Invalid initializer for constant vector");
1420// ConstantVector accessors. 1429assert(!V.empty() &&
"Vectors can't be empty");
1432// If this is an all-undef or all-zero vector, return a 1433// ConstantAggregateZero or UndefValue. 1437bool isPoison = isa<PoisonValue>(
C);
1442for (
unsigned i = 1, e = V.size(); i != e; ++i)
1456return ConstantFP::get(
C->getContext(),
T->getElementCount(),
1457 cast<ConstantFP>(
C)->getValue());
1459return ConstantInt::get(
C->getContext(),
T->getElementCount(),
1460 cast<ConstantInt>(
C)->getValue());
1462// Check to see if all of the elements are ConstantFP or ConstantInt and if 1463// the element type is compatible with ConstantDataVector. If so, use it. 1465return getSequenceIfElementsMatch<ConstantDataVector>(
C, V);
1467// Otherwise, the element type isn't compatible with ConstantDataVector, or 1468// the operand list contains a ConstantExpr or something else strange. 1473if (!EC.isScalable()) {
1474// Maintain special handling of zero. 1475if (!V->isNullValue()) {
1477return ConstantInt::get(V->getContext(), EC,
1478 cast<ConstantInt>(V)->getValue());
1480return ConstantFP::get(V->getContext(), EC,
1481 cast<ConstantFP>(V)->getValue());
1484// If this splat is compatible with ConstantDataVector, use it instead of 1486if ((isa<ConstantFP>(V) || isa<ConstantInt>(V)) &&
1494// Maintain special handling of zero. 1495if (!V->isNullValue()) {
1497return ConstantInt::get(V->getContext(), EC,
1498 cast<ConstantInt>(V)->getValue());
1500return ConstantFP::get(V->getContext(), EC,
1501 cast<ConstantFP>(V)->getValue());
1506if (V->isNullValue())
1508elseif (isa<UndefValue>(V))
1513// Move scalar into vector. 1516// Build shuffle mask to perform the splat. 1529/// Remove the constant from the constant table. 1530void ConstantTokenNone::destroyConstantImpl() {
1534// Utility function for determining if a ConstantExpr is a CastOp or not. This 1535// can't be inline because we don't want to #include Instruction.h into 1540return cast<ShuffleVectorConstantExpr>(
this)->ShuffleMask;
1544return cast<ShuffleVectorConstantExpr>(
this)->ShuffleMaskForBitcode;
1548bool OnlyIfReduced,
Type *SrcTy)
const{
1551// If no operands changed return self. 1555Type *OnlyIfReducedTy = OnlyIfReduced ? Ty :
nullptr;
1557case Instruction::Trunc:
1558case Instruction::ZExt:
1559case Instruction::SExt:
1560case Instruction::FPTrunc:
1561case Instruction::FPExt:
1562case Instruction::UIToFP:
1563case Instruction::SIToFP:
1564case Instruction::FPToUI:
1565case Instruction::FPToSI:
1566case Instruction::PtrToInt:
1567case Instruction::IntToPtr:
1568case Instruction::BitCast:
1569case Instruction::AddrSpaceCast:
1571case Instruction::InsertElement:
1574case Instruction::ExtractElement:
1576case Instruction::ShuffleVector:
1579case Instruction::GetElementPtr: {
1580auto *GEPO = cast<GEPOperator>(
this);
1583 SrcTy ? SrcTy : GEPO->getSourceElementType(), Ops[0], Ops.
slice(1),
1584 GEPO->getNoWrapFlags(), GEPO->getInRange(), OnlyIfReducedTy);
1594//===----------------------------------------------------------------------===// 1595// isValueValidForType implementations 1600return Val == 0 || Val == 1;
1607return Val == 0 || Val == 1 || Val == -1;
1608returnisIntN(NumBits, Val);
1612// convert modifies in place, so make a copy. 1617returnfalse;
// These can't be represented as floating point! 1619// FIXME rounding mode needs to be more flexible 1669//===----------------------------------------------------------------------===// 1670// Factory Function Implementation 1674"Cannot create an aggregate zero of non-aggregate type!");
1676 std::unique_ptr<ConstantAggregateZero> &Entry =
1684/// Remove the constant from the constant table. 1685void ConstantAggregateZero::destroyConstantImpl() {
1689/// Remove the constant from the constant table. 1690void ConstantArray::destroyConstantImpl() {
1695//---- ConstantStruct::get() implementation... 1698/// Remove the constant from the constant table. 1699void ConstantStruct::destroyConstantImpl() {
1703/// Remove the constant from the constant table. 1704void ConstantVector::destroyConstantImpl() {
1709assert(this->
getType()->isVectorTy() &&
"Only valid for vectors!");
1710if (isa<ConstantAggregateZero>(
this))
1712if (
auto *CI = dyn_cast<ConstantInt>(
this))
1713return ConstantInt::get(
getContext(), CI->getValue());
1714if (
auto *CFP = dyn_cast<ConstantFP>(
this))
1715return ConstantFP::get(
getContext(), CFP->getValue());
1717return CV->getSplatValue();
1719return CV->getSplatValue(AllowPoison);
1721// Check if this is a constant expression splat of the form returned by 1722// ConstantVector::getSplat() 1723constauto *Shuf = dyn_cast<ConstantExpr>(
this);
1724if (Shuf && Shuf->getOpcode() == Instruction::ShuffleVector &&
1725 isa<UndefValue>(Shuf->getOperand(1))) {
1727constauto *IElt = dyn_cast<ConstantExpr>(Shuf->getOperand(0));
1728if (IElt && IElt->getOpcode() == Instruction::InsertElement &&
1729 isa<UndefValue>(IElt->getOperand(0))) {
1733ConstantInt *Index = dyn_cast<ConstantInt>(IElt->getOperand(2));
1735if (Index && Index->getValue() == 0 &&
1745// Check out first element. 1747// Then make sure all remaining elements point to the same value. 1753// Strict mode: any mismatch is not a splat. 1757// Allow poison mode: ignore poison elements. 1758if (isa<PoisonValue>(OpC))
1761// If we do not have a defined element yet, use the current operand. 1762if (isa<PoisonValue>(Elt))
1772if (
constConstantInt *CI = dyn_cast<ConstantInt>(
this))
1773return CI->getValue();
1774// Scalable vectors can use a ConstantExpr to build a splat. 1775if (isa<ConstantExpr>(
this))
1777// For non-ConstantExpr we use getAggregateElement as a fast path to avoid 1778// calling getSplatValue in release builds. 1781assert(
C && isa<ConstantInt>(
C) &&
"Not a vector of numbers!");
1782return cast<ConstantInt>(
C)->getValue();
1786if (
auto *CI = dyn_cast<ConstantInt>(
this))
1791return ConstantRange::getFull(
BitWidth);
1793if (
auto *CI = dyn_cast_or_null<ConstantInt>(
1797if (
auto *CDV = dyn_cast<ConstantDataVector>(
this)) {
1799for (
unsignedI = 0, E = CDV->getNumElements();
I < E; ++
I)
1800 CR = CR.
unionWith(CDV->getElementAsAPInt(
I));
1804if (
auto *CV = dyn_cast<ConstantVector>(
this)) {
1806for (
unsignedI = 0, E = CV->getNumOperands();
I < E; ++
I) {
1809return ConstantRange::getFull(
BitWidth);
1810if (isa<PoisonValue>(Elem))
1812auto *CI = dyn_cast<ConstantInt>(Elem);
1814return ConstantRange::getFull(
BitWidth);
1820return ConstantRange::getFull(
BitWidth);
1823//---- ConstantPointerNull::get() implementation. 1827 std::unique_ptr<ConstantPointerNull> &Entry =
1835/// Remove the constant from the constant table. 1836void ConstantPointerNull::destroyConstantImpl() {
1840//---- ConstantTargetNone::get() implementation. 1845"Target extension type not allowed to have a zeroinitializer");
1846 std::unique_ptr<ConstantTargetNone> &Entry =
1854/// Remove the constant from the constant table. 1855void ConstantTargetNone::destroyConstantImpl() {
1867/// Remove the constant from the constant table. 1868void UndefValue::destroyConstantImpl() {
1869// Free the constant and any dangling references to it. 1886/// Remove the constant from the constant table. 1887void PoisonValue::destroyConstantImpl() {
1888// Free the constant and any dangling references to it. 1899F->getContext().pImpl->BlockAddresses[std::make_pair(
F, BB)];
1909Value::BlockAddressVal, AllocMarker) {
1912 BB->AdjustBlockAddressRefCount(1);
1920assert(
F &&
"Block must have a parent");
1922F->getContext().pImpl->BlockAddresses.lookup(std::make_pair(
F, BB));
1923assert(BA &&
"Refcount and block address map disagree!");
1927/// Remove the constant from the constant table. 1928void BlockAddress::destroyConstantImpl() {
1935// This could be replacing either the Basic Block or the Function. In either 1936// case, we have to remove the map entry. 1943assert(
From == NewBB &&
"From does not match any operand");
1944 NewBB = cast<BasicBlock>(To);
1947// See if the 'new' entry already exists, if not, just update this in place 1956// Remove the old entry, this can't cause the map to rehash (just a 1957// tombstone will get added). 1965// If we just want to keep the existing value, then return null. 1966// Callers know that this means we shouldn't delete this value. 1976"DSOLocalFunction does not match the expected global value");
1980DSOLocalEquivalent::DSOLocalEquivalent(
GlobalValue *GV)
1985/// Remove the constant from the constant table. 1986void DSOLocalEquivalent::destroyConstantImpl() {
1993assert(isa<Constant>(To) &&
"Can only replace the operands with a constant");
1995// The replacement is with another global value. 1996if (
constauto *ToObj = dyn_cast<GlobalValue>(To)) {
2003// If the argument is replaced with a null value, just replace this constant 2004// with a null value. 2008// The replacement could be a bitcast or an alias to another function. We can 2009// replace it with a bitcast to the dso_local_equivalent of that function. 2015// Replace this with the new one. 2021// It is ok to mutate the type here because this constant should always 2022// reflect the type of the function it's holding. 2033assert(
NC->getGlobalValue() == GV &&
2034"NoCFIValue does not match the expected global value");
2043/// Remove the constant from the constant table. 2044void NoCFIValue::destroyConstantImpl() {
2053assert(GV &&
"Can only replace the operands with a global value");
2069//---- ConstantPtrAuth::get() implementations. 2088assert(Key->getBitWidth() == 32);
2097/// Remove the constant from the constant table. 2098void ConstantPtrAuth::destroyConstantImpl() {
2103assert(isa<Constant>(ToV) &&
"Cannot make Constant refer to non-constant!");
2109unsigned NumUpdated = 0;
2112unsigned OperandNo = 0;
2114Constant *Val = cast<Constant>(
O->get());
2116 OperandNo = (
O - OperandList);
2124 Values,
this,
From, To, NumUpdated, OperandNo);
2129if (!CastV || CastV->getOpcode() != Instruction::IntToPtr)
2132constauto *IntVal = dyn_cast<ConstantInt>(CastV->getOperand(0));
2136return IntVal->getValue() ==
Value;
2140constValue *Discriminator,
2142// If the keys are different, there's no chance for this to be compatible. 2146// We can have 3 kinds of discriminators: 2147// - simple, integer-only: `i64 x, ptr null` vs. `i64 x` 2148// - address-only: `i64 0, ptr p` vs. `ptr p` 2149// - blended address/integer: `i64 x, ptr p` vs. `@llvm.ptrauth.blend(p, x)` 2151// If this constant has a simple discriminator (integer, no address), easy: 2152// it's compatible iff the provided full discriminator is also a simple 2153// discriminator, identical to our integer discriminator. 2157// Otherwise, we can isolate address and integer discriminator components. 2158constValue *AddrDiscriminator =
nullptr;
2160// This constant may or may not have an integer discriminator (instead of 0). 2162// If it does, there's an implicit blend. We need to have a matching blend 2163// intrinsic in the provided full discriminator. 2164if (!
match(Discriminator,
2165 m_Intrinsic<Intrinsic::ptrauth_blend>(
2169// Otherwise, interpret the provided full discriminator as address-only. 2170 AddrDiscriminator = Discriminator;
2173// Either way, we can now focus on comparing the address discriminators. 2175// Discriminators are i64, so the provided addr disc may be a ptrtoint. 2176if (
auto *Cast = dyn_cast<PtrToIntOperator>(AddrDiscriminator))
2177 AddrDiscriminator = Cast->getPointerOperand();
2179// Beyond that, we're only interested in compatible pointers. 2183// These are often the same constant GEP, making them trivially equivalent. 2187// Finally, they may be equivalent base+offset expressions. 2190DL, Off1,
/*AllowNonInbounds=*/true);
2192APInt Off2(
DL.getIndexTypeSizeInBits(AddrDiscriminator->
getType()), 0);
2194DL, Off2,
/*AllowNonInbounds=*/true);
2196return Base1 == Base2 && Off1 == Off2;
2199//---- ConstantExpr::get() implementations. 2202/// This is a utility function to handle folding of casts and lookup of the 2203/// cast in the ExprConstants map. It is used by the various get* methods below. 2205bool OnlyIfReduced =
false) {
2207// Fold a few common cases 2216// Look up the constant in the table first to ensure uniqueness. 2223bool OnlyIfReduced) {
2227"Cast opcode not supported as constant expression");
2228assert(
C && Ty &&
"Null arguments to getCast");
2234case Instruction::Trunc:
2236case Instruction::PtrToInt:
2238case Instruction::IntToPtr:
2240case Instruction::BitCast:
2242case Instruction::AddrSpaceCast:
2281bool fromVec = isa<VectorType>(
C->getType());
2282bool toVec = isa<VectorType>(Ty);
2284assert((fromVec == toVec) &&
"Cannot convert from scalar to/from vector");
2285assert(
C->getType()->isIntOrIntVectorTy() &&
"Trunc operand must be integer");
2288"SrcTy must be larger than DestTy for Trunc!");
2294bool OnlyIfReduced) {
2295assert(
C->getType()->isPtrOrPtrVectorTy() &&
2296"PtrToInt source must be pointer or pointer vector");
2298"PtrToInt destination must be integer or integer vector");
2299assert(isa<VectorType>(
C->getType()) == isa<VectorType>(DstTy));
2300if (isa<VectorType>(
C->getType()))
2301assert(cast<VectorType>(
C->getType())->getElementCount() ==
2302 cast<VectorType>(DstTy)->getElementCount() &&
2303"Invalid cast between a different number of vector elements");
2304returngetFoldedCast(Instruction::PtrToInt,
C, DstTy, OnlyIfReduced);
2308bool OnlyIfReduced) {
2309assert(
C->getType()->isIntOrIntVectorTy() &&
2310"IntToPtr source must be integer or integer vector");
2312"IntToPtr destination must be a pointer or pointer vector");
2313assert(isa<VectorType>(
C->getType()) == isa<VectorType>(DstTy));
2314if (isa<VectorType>(
C->getType()))
2315assert(cast<VectorType>(
C->getType())->getElementCount() ==
2316 cast<VectorType>(DstTy)->getElementCount() &&
2317"Invalid cast between a different number of vector elements");
2318returngetFoldedCast(Instruction::IntToPtr,
C, DstTy, OnlyIfReduced);
2322bool OnlyIfReduced) {
2324"Invalid constantexpr bitcast!");
2326// It is common to ask for a bitcast of a value to its own type, handle this 2328if (
C->getType() == DstTy)
returnC;
2330returngetFoldedCast(Instruction::BitCast,
C, DstTy, OnlyIfReduced);
2334bool OnlyIfReduced) {
2336"Invalid constantexpr addrspacecast!");
2337returngetFoldedCast(Instruction::AddrSpaceCast,
C, DstTy, OnlyIfReduced);
2341unsigned Flags,
Type *OnlyIfReducedTy) {
2342// Check the operands for consistency first. 2344"Invalid opcode in binary constant expression");
2346"Binop not supported as constant expression");
2348"Operand types in binary constant expression should match");
2352case Instruction::Add:
2353case Instruction::Sub:
2354case Instruction::Mul:
2356"Tried to create an integer operation on a non-integer type!");
2358case Instruction::And:
2359case Instruction::Or:
2360case Instruction::Xor:
2362"Tried to create a logical operation on a non-integral type!");
2372if (OnlyIfReducedTy == C1->
getType())
2384case Instruction::UDiv:
2385case Instruction::SDiv:
2386case Instruction::URem:
2387case Instruction::SRem:
2388case Instruction::FAdd:
2389case Instruction::FSub:
2390case Instruction::FMul:
2391case Instruction::FDiv:
2392case Instruction::FRem:
2393case Instruction::And:
2394case Instruction::Or:
2395case Instruction::LShr:
2396case Instruction::AShr:
2397case Instruction::Shl:
2399case Instruction::Add:
2400case Instruction::Sub:
2401case Instruction::Mul:
2402case Instruction::Xor:
2411case Instruction::UDiv:
2412case Instruction::SDiv:
2413case Instruction::URem:
2414case Instruction::SRem:
2415case Instruction::FAdd:
2416case Instruction::FSub:
2417case Instruction::FMul:
2418case Instruction::FDiv:
2419case Instruction::FRem:
2420case Instruction::And:
2421case Instruction::Or:
2422case Instruction::LShr:
2423case Instruction::AShr:
2424case Instruction::Shl:
2426case Instruction::Add:
2427case Instruction::Sub:
2428case Instruction::Mul:
2429case Instruction::Xor:
2438case Instruction::ZExt:
2439case Instruction::SExt:
2440case Instruction::FPTrunc:
2441case Instruction::FPExt:
2442case Instruction::UIToFP:
2443case Instruction::SIToFP:
2444case Instruction::FPToUI:
2445case Instruction::FPToSI:
2447case Instruction::Trunc:
2448case Instruction::PtrToInt:
2449case Instruction::IntToPtr:
2450case Instruction::BitCast:
2451case Instruction::AddrSpaceCast:
2460case Instruction::ZExt:
2461case Instruction::SExt:
2462case Instruction::FPTrunc:
2463case Instruction::FPExt:
2464case Instruction::UIToFP:
2465case Instruction::SIToFP:
2466case Instruction::FPToUI:
2467case Instruction::FPToSI:
2469case Instruction::Trunc:
2470case Instruction::PtrToInt:
2471case Instruction::IntToPtr:
2472case Instruction::BitCast:
2473case Instruction::AddrSpaceCast:
2481// sizeof is implemented as: (i64) gep (Ty*)null, 1 2482// Note that a non-inbounds gep is used, as null isn't within any object. 2492// alignof is implemented as: (i64) gep ({i1,Ty}*)null, 0, 1 2493// Note that a non-inbounds gep is used, as null isn't within any object. 2507 std::optional<ConstantRange>
InRange,
2508Type *OnlyIfReducedTy) {
2509assert(Ty &&
"Must specify element type");
2513return FC;
// Fold a few common cases. 2518// Get the result type of the getelementptr! 2520if (OnlyIfReducedTy == ReqTy)
2524if (
VectorType *VecTy = dyn_cast<VectorType>(ReqTy))
2525 EltCount = VecTy->getElementCount();
2527// Look up the constant in the table first to ensure uniqueness 2528 std::vector<Constant*> ArgVec;
2529 ArgVec.reserve(1 + Idxs.
size());
2530 ArgVec.push_back(
C);
2532for (; GTI != GTE; ++GTI) {
2533auto *
Idx = cast<Constant>(GTI.getOperand());
2535 (!isa<VectorType>(
Idx->getType()) ||
2536 cast<VectorType>(
Idx->getType())->getElementCount() == EltCount) &&
2537"getelementptr index type missmatch");
2539if (GTI.isStruct() &&
Idx->getType()->isVectorTy()) {
2540Idx =
Idx->getSplatValue();
2541 }
elseif (GTI.isSequential() && EltCount.isNonZero() &&
2542 !
Idx->getType()->isVectorTy()) {
2545 ArgVec.push_back(
Idx);
2556Type *OnlyIfReducedTy) {
2558"Tried to create extractelement operation on non-vector type!");
2560"Extractelement index must be an integer type!");
2563return FC;
// Fold a few common cases. 2565Type *ReqTy = cast<VectorType>(Val->
getType())->getElementType();
2566if (OnlyIfReducedTy == ReqTy)
2569// Look up the constant in the table first to ensure uniqueness 2580"Tried to create insertelement operation on non-vector type!");
2582"Insertelement types must match!");
2584"Insertelement index must be i32 type!");
2587return FC;
// Fold a few common cases. 2589if (OnlyIfReducedTy == Val->
getType())
2592// Look up the constant in the table first to ensure uniqueness 2602Type *OnlyIfReducedTy) {
2604"Invalid shuffle vector constant expr operands!");
2607return FC;
// Fold a few common cases. 2609unsigned NElts = Mask.size();
2610auto V1VTy = cast<VectorType>(V1->
getType());
2611Type *EltTy = V1VTy->getElementType();
2612bool TypeIsScalable = isa<ScalableVectorType>(V1VTy);
2615if (OnlyIfReducedTy == ShufTy)
2618// Look up the constant in the table first to ensure uniqueness 2627assert(
C->getType()->isIntOrIntVectorTy() &&
2628"Cannot NEG a nonintegral value!");
2629returngetSub(ConstantInt::get(
C->getType(), 0),
C,
/*HasNUW=*/false, HasNSW);
2633assert(
C->getType()->isIntOrIntVectorTy() &&
2634"Cannot NOT a nonintegral value!");
2639bool HasNUW,
bool HasNSW) {
2642returnget(Instruction::Add, C1, C2, Flags);
2646bool HasNUW,
bool HasNSW) {
2649returnget(Instruction::Sub, C1, C2, Flags);
2653bool HasNUW,
bool HasNSW) {
2656returnget(Instruction::Mul, C1, C2, Flags);
2660returnget(Instruction::Xor, C1, C2);
2664Type *Ty =
C->getType();
2667return ConstantInt::get(Ty, IVal->
logBase2());
2669// FIXME: We can extract pow of 2 of splat constant for scalable vectors. 2670auto *VecTy = dyn_cast<FixedVectorType>(Ty);
2675for (
unsignedI = 0, E = VecTy->getNumElements();
I != E; ++
I) {
2679// Note that log2(iN undef) is *NOT* iN undef, because log2(iN undef) u< N. 2680if (isa<UndefValue>(Elt)) {
2693bool AllowRHSConstant,
bool NSZ) {
2696// Commutative opcodes: it does not matter if AllowRHSConstant is set. 2699case Instruction::Add:
// X + 0 = X 2700case Instruction::Or:
// X | 0 = X 2701case Instruction::Xor:
// X ^ 0 = X 2703case Instruction::Mul:
// X * 1 = X 2704return ConstantInt::get(Ty, 1);
2705case Instruction::And:
// X & -1 = X 2707case Instruction::FAdd:
// X + -0.0 = X 2709case Instruction::FMul:
// X * 1.0 = X 2710return ConstantFP::get(Ty, 1.0);
2716// Non-commutative opcodes: AllowRHSConstant must be set. 2717if (!AllowRHSConstant)
2721case Instruction::Sub:
// X - 0 = X 2722case Instruction::Shl:
// X << 0 = X 2723case Instruction::LShr:
// X >>u 0 = X 2724case Instruction::AShr:
// X >> 0 = X 2725case Instruction::FSub:
// X - 0.0 = X 2727case Instruction::SDiv:
// X / 1 = X 2728case Instruction::UDiv:
// X /u 1 = X 2729return ConstantInt::get(Ty, 1);
2730case Instruction::FDiv:
// X / 1.0 = X 2731return ConstantFP::get(Ty, 1.0);
2739case Intrinsic::umax:
2741case Intrinsic::umin:
2743case Intrinsic::smax:
2746case Intrinsic::smin:
2755bool AllowRHSConstant,
bool NSZ) {
2764bool AllowLHSConstant) {
2769case Instruction::Or:
// -1 | X = -1 2772case Instruction::And:
// 0 & X = 0 2773case Instruction::Mul:
// 0 * X = 0 2777// AllowLHSConstant must be set. 2778if (!AllowLHSConstant)
2784case Instruction::Shl:
// 0 << X = 0 2785case Instruction::LShr:
// 0 >>l X = 0 2786case Instruction::AShr:
// 0 >>a X = 0 2787case Instruction::SDiv:
// 0 /s X = 0 2788case Instruction::UDiv:
// 0 /u X = 0 2789case Instruction::URem:
// 0 %u X = 0 2790case Instruction::SRem:
// 0 %s X = 0 2795/// Remove the constant from the constant table. 2796void ConstantExpr::destroyConstantImpl() {
2804GetElementPtrConstantExpr::GetElementPtrConstantExpr(
2808 SrcElementTy(SrcElementTy),
2813for (
unsigned i = 0, E = IdxList.
size(); i != E; ++i)
2814 OperandList[i+1] = IdxList[i];
2829//===----------------------------------------------------------------------===// 2830// ConstantData* implementations 2834return ATy->getElementType();
2835return cast<VectorType>(
getType())->getElementType();
2845if (
auto *
IT = dyn_cast<IntegerType>(Ty)) {
2846switch (
IT->getBitWidth()) {
2860return AT->getNumElements();
2861return cast<FixedVectorType>(
getType())->getNumElements();
2869/// Return the start of the specified element. 2870constchar *ConstantDataSequential::getElementPointer(
unsigned Elt)
const{
2876/// Return true if the array is empty or all zeros. 2884/// This is the underlying implementation of all of the 2885/// ConstantDataSequential::get methods. They all thunk down to here, providing 2886/// the correct element type. We take the bytes in as a StringRef because 2887/// we *want* an underlying "char*" to avoid TBAA type punning violations. 2890if (
ArrayType *ATy = dyn_cast<ArrayType>(Ty))
2895// If the elements are all zero or there are no elements, return a CAZ, which 2896// is more dense and canonical. 2900// Do a lookup to see if we have already formed one of these. 2906// The bucket can point to a linked list of different CDS's that have the same 2907// body but different types. For example, 0,0,0,1 could be a 4 element array 2908// of i8, or a 1-element array of i32. They'll both end up in the same 2909 /// StringMap bucket, linked up by their Next pointers. Walk the list. 2910 std::unique_ptr<ConstantDataSequential> *Entry = &Slot.second;
2911for (; *Entry; Entry = &(*Entry)->Next)
2912if ((*Entry)->getType() == Ty)
2915// Okay, we didn't get a hit. Create a node of the right class, link it in, 2917if (isa<ArrayType>(Ty)) {
2918// Use reset because std::make_unique can't access the constructor. 2923assert(isa<VectorType>(Ty));
2924// Use reset because std::make_unique can't access the constructor. 2929void ConstantDataSequential::destroyConstantImpl() {
2930// Remove the constant from the StringMap. 2936assert(Slot != CDSConstants.
end() &&
"CDS not found in uniquing table");
2938 std::unique_ptr<ConstantDataSequential> *Entry = &Slot->getValue();
2940// Remove the entry from the hash table. 2941if (!(*Entry)->Next) {
2942// If there is only one value in the bucket (common case) it must be this 2943// entry, and removing the entry should remove the bucket completely. 2944assert(Entry->get() ==
this &&
"Hash mismatch in ConstantDataSequential");
2949// Otherwise, there are multiple entries linked off the bucket, unlink the 2950// node we care about but keep the bucket around. 2952 std::unique_ptr<ConstantDataSequential> &
Node = *Entry;
2953assert(
Node &&
"Didn't find entry in its uniquing hash table!");
2954// If we found our entry, unlink it from the list and we're done. 2955if (
Node.get() ==
this) {
2964/// getFP() constructors - Return a constant of array type with a float 2965/// element type taken from argument `ElementType', and count taken from 2966/// argument `Elts'. The amount of bits of the contained type must match the 2967/// number of bits of the type contained in the passed in ArrayRef. 2968/// (i.e. half or bfloat for 16bits, float for 32bits, double for 64bits) Note 2969/// that this can return a ConstantAggregateZero object. 2971assert((ElementType->isHalfTy() || ElementType->isBFloatTy()) &&
2972"Element type is not a 16-bit float type");
2974constchar *
Data =
reinterpret_cast<constchar *
>(Elts.
data());
2978assert(ElementType->isFloatTy() &&
"Element type is not a 32-bit float type");
2980constchar *
Data =
reinterpret_cast<constchar *
>(Elts.
data());
2984assert(ElementType->isDoubleTy() &&
2985"Element type is not a 64-bit float type");
2987constchar *
Data =
reinterpret_cast<constchar *
>(Elts.
data());
2999 ElementVals.
append(Str.begin(), Str.end());
3001returnget(Context, ElementVals);
3004/// get() constructors - Return a constant with vector type with an element 3005/// count and element type matching the ArrayRef passed in. Note that this 3006/// can return a ConstantAggregateZero object. 3009constchar *
Data =
reinterpret_cast<constchar *
>(Elts.
data());
3014constchar *
Data =
reinterpret_cast<constchar *
>(Elts.
data());
3019constchar *
Data =
reinterpret_cast<constchar *
>(Elts.
data());
3024constchar *
Data =
reinterpret_cast<constchar *
>(Elts.
data());
3029constchar *
Data =
reinterpret_cast<constchar *
>(Elts.
data());
3034constchar *
Data =
reinterpret_cast<constchar *
>(Elts.
data());
3038/// getFP() constructors - Return a constant of vector type with a float 3039/// element type taken from argument `ElementType', and count taken from 3040/// argument `Elts'. The amount of bits of the contained type must match the 3041/// number of bits of the type contained in the passed in ArrayRef. 3042/// (i.e. half or bfloat for 16bits, float for 32bits, double for 64bits) Note 3043/// that this can return a ConstantAggregateZero object. 3046assert((ElementType->isHalfTy() || ElementType->isBFloatTy()) &&
3047"Element type is not a 16-bit float type");
3049constchar *
Data =
reinterpret_cast<constchar *
>(Elts.
data());
3054assert(ElementType->isFloatTy() &&
"Element type is not a 32-bit float type");
3056constchar *
Data =
reinterpret_cast<constchar *
>(Elts.
data());
3061assert(ElementType->isDoubleTy() &&
3062"Element type is not a 64-bit float type");
3064constchar *
Data =
reinterpret_cast<constchar *
>(Elts.
data());
3070"Element type not compatible with ConstantData");
3072if (CI->getType()->isIntegerTy(8)) {
3074returnget(V->getContext(), Elts);
3076if (CI->getType()->isIntegerTy(16)) {
3078returnget(V->getContext(), Elts);
3080if (CI->getType()->isIntegerTy(32)) {
3082returnget(V->getContext(), Elts);
3084assert(CI->getType()->isIntegerTy(64) &&
"Unsupported ConstantData type");
3086returnget(V->getContext(), Elts);
3089if (
ConstantFP *CFP = dyn_cast<ConstantFP>(V)) {
3090if (CFP->getType()->isHalfTy()) {
3092 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3093returngetFP(V->getType(), Elts);
3095if (CFP->getType()->isBFloatTy()) {
3097 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3098returngetFP(V->getType(), Elts);
3100if (CFP->getType()->isFloatTy()) {
3102 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3103returngetFP(V->getType(), Elts);
3105if (CFP->getType()->isDoubleTy()) {
3107 NumElts, CFP->getValueAPF().bitcastToAPInt().getLimitedValue());
3108returngetFP(V->getType(), Elts);
3117"Accessor can only be used when element is an integer");
3118constchar *EltPtr = getElementPointer(Elt);
3120// The data is stored in host byte order, make sure to cast back to the right 3121// type to load with the right endianness. 3125return *
reinterpret_cast<constuint8_t *
>(EltPtr);
3127return *
reinterpret_cast<constuint16_t *
>(EltPtr);
3129return *
reinterpret_cast<constuint32_t *
>(EltPtr);
3131return *
reinterpret_cast<constuint64_t *
>(EltPtr);
3137"Accessor can only be used when element is an integer");
3138constchar *EltPtr = getElementPointer(Elt);
3140// The data is stored in host byte order, make sure to cast back to the right 3141// type to load with the right endianness. 3145auto EltVal = *
reinterpret_cast<constuint8_t *
>(EltPtr);
3146returnAPInt(8, EltVal);
3149auto EltVal = *
reinterpret_cast<constuint16_t *
>(EltPtr);
3150returnAPInt(16, EltVal);
3153auto EltVal = *
reinterpret_cast<constuint32_t *
>(EltPtr);
3154returnAPInt(32, EltVal);
3157auto EltVal = *
reinterpret_cast<constuint64_t *
>(EltPtr);
3158returnAPInt(64, EltVal);
3164constchar *EltPtr = getElementPointer(Elt);
3168llvm_unreachable(
"Accessor can only be used when element is float/double!");
3170auto EltVal = *
reinterpret_cast<constuint16_t *
>(EltPtr);
3174auto EltVal = *
reinterpret_cast<constuint16_t *
>(EltPtr);
3178auto EltVal = *
reinterpret_cast<constuint32_t *
>(EltPtr);
3182auto EltVal = *
reinterpret_cast<constuint64_t *
>(EltPtr);
3190"Accessor can only be used when element is a 'float'");
3191return *
reinterpret_cast<constfloat *
>(getElementPointer(Elt));
3196"Accessor can only be used when element is a 'float'");
3197return *
reinterpret_cast<constdouble *
>(getElementPointer(Elt));
3218// The last value must be nul. 3219if (Str.back() != 0)
returnfalse;
3221// Other elements must be non-nul. 3222return !Str.drop_back().contains(0);
3225bool ConstantDataVector::isSplatData()
const{
3228// Compare elements 1+ to the 0'th element. 3240 IsSplat = isSplatData();
3246// If they're all the same, return the 0th one as a representative. 3250//===----------------------------------------------------------------------===// 3251// handleOperandChange implementations 3253/// Update this constant array to change uses of 3254/// 'From' to be uses of 'To'. This must update the uniquing data structures 3257/// Note that we intentionally replace all uses of From with To here. Consider 3258/// a large array that uses 'From' 1000 times. By handling this case all here, 3259/// ConstantArray::handleOperandChange is only invoked once, and that 3260/// single invocation handles all 1000 uses. Handling them one at a time would 3261/// work, but would be really slow because it would have to unique each updated 3265Value *Replacement =
nullptr;
3269#define HANDLE_CONSTANT(Name) \ 3270 case Value::Name##Val: \ 3271 Replacement = cast<Name>(this)->handleOperandChangeImpl(From, To); \ 3273#include "llvm/IR/Value.def" 3276// If handleOperandChangeImpl returned nullptr, then it handled 3277// replacing itself and we don't want to delete or replace anything else here. 3281// I do need to replace this with an existing value. 3282assert(Replacement !=
this &&
"I didn't contain From!");
3284// Everyone using this now uses the replacement. 3287// Delete the old constant! 3292assert(isa<Constant>(To) &&
"Cannot make Constant refer to non-constant!");
3298// Fill values with the modified operands of the constant array. Also, 3299// compute whether this turns into an all-zeros array. 3300unsigned NumUpdated = 0;
3302// Keep track of whether all the values in the array are "ToC". 3305unsigned OperandNo = 0;
3307Constant *Val = cast<Constant>(O->get());
3309 OperandNo = (O - OperandList);
3314 AllSame &= Val == ToC;
3320if (AllSame && isa<UndefValue>(ToC))
3323// Check for any other type of constant-folding. 3327// Update to the new value. 3329 Values,
this,
From, ToC, NumUpdated, OperandNo);
3333assert(isa<Constant>(To) &&
"Cannot make Constant refer to non-constant!");
3341// Fill values with the modified operands of the constant struct. Also, 3342// compute whether this turns into an all-zeros struct. 3343unsigned NumUpdated = 0;
3345unsigned OperandNo = 0;
3347Constant *Val = cast<Constant>(
O->get());
3349 OperandNo = (
O - OperandList);
3354 AllSame &= Val == ToC;
3360if (AllSame && isa<UndefValue>(ToC))
3363// Update to the new value. 3365 Values,
this,
From, ToC, NumUpdated, OperandNo);
3369assert(isa<Constant>(To) &&
"Cannot make Constant refer to non-constant!");
3374unsigned NumUpdated = 0;
3375unsigned OperandNo = 0;
3389// Update to the new value. 3391 Values,
this,
From, ToC, NumUpdated, OperandNo);
3395assert(isa<Constant>(ToV) &&
"Cannot make Constant refer to non-constant!");
3399unsigned NumUpdated = 0;
3400unsigned OperandNo = 0;
3410assert(NumUpdated &&
"I didn't contain From!");
3415// Update to the new value. 3417 NewOps,
this,
From, To, NumUpdated, OperandNo);
3425case Instruction::Trunc:
3426case Instruction::PtrToInt:
3427case Instruction::IntToPtr:
3428case Instruction::BitCast:
3429case Instruction::AddrSpaceCast:
3432case Instruction::InsertElement:
3434case Instruction::ExtractElement:
3436case Instruction::ShuffleVector:
3439case Instruction::GetElementPtr: {
3440constauto *GO = cast<GEPOperator>(
this);
3442 Ops.
slice(1), GO->getNoWrapFlags(),
"");
3448if (isa<OverflowingBinaryOperator>(BO)) {
3454if (isa<PossiblyExactOperator>(BO))
This file defines the StringMap class.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
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 bool isAllZeros(StringRef Arr)
Return true if the array is empty or all zeros.
static cl::opt< bool > UseConstantIntForScalableSplat("use-constant-int-for-scalable-splat", cl::init(false), cl::Hidden, cl::desc("Use ConstantInt's native scalable vector splat support."))
static cl::opt< bool > UseConstantIntForFixedLengthSplat("use-constant-int-for-fixed-length-splat", cl::init(false), cl::Hidden, cl::desc("Use ConstantInt's native fixed-length vector splat support."))
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 cl::opt< bool > UseConstantFPForScalableSplat("use-constant-fp-for-scalable-splat", cl::init(false), cl::Hidden, cl::desc("Use ConstantFP's native scalable vector splat support."))
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...
static cl::opt< bool > UseConstantFPForFixedLengthSplat("use-constant-fp-for-fixed-length-splat", cl::init(false), cl::Hidden, cl::desc("Use ConstantFP's native fixed-length vector splat support."))
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 isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
static bool isUndef(const MachineInstr &MI)
Merge contiguous icmps into a memcmp
static bool InRange(int64_t Value, unsigned short Shift, int LBound, int HBound)
static unsigned getAddressSpace(const Value *V, unsigned MaxLookup)
uint64_t IntrinsicInst * II
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml", "ocaml 3.10-compatible collector")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static unsigned getNumElements(Type *Ty)
This file contains some templates that are useful if you are working with the STL at all.
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.
static APInt getSignedMaxValue(unsigned numBits)
Gets maximum signed value of APInt for a specific bit width.
static APInt getSignedMinValue(unsigned numBits)
Gets minimum signed value of APInt for a specific bit width.
unsigned logBase2() const
bool isPowerOf2() const
Check if this APInt's value is a power of two greater than zero.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Class to represent array types.
static ArrayType * get(Type *ElementType, uint64_t NumElements)
This static method is the primary way to construct an ArrayType.
Type * getElementType() const
LLVM Basic Block Representation.
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches,...
const Function * getParent() const
Return the enclosing method, or null if none.
BinaryConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to impleme...
static BinaryOperator * Create(BinaryOps Op, Value *S1, Value *S2, const Twine &Name=Twine(), InsertPosition 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="", InsertPosition 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.
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, AllocInfo AllocInfo)
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 * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getExtractElement(Constant *Vec, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static Constant * getAlignOf(Type *Ty)
getAlignOf constant expr - computes the alignment of a type in a target independent way (Note: the re...
static Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
static Constant * getTruncOrBitCast(Constant *C, Type *Ty)
static Constant * getPointerBitCastOrAddrSpaceCast(Constant *C, Type *Ty)
Create a BitCast or AddrSpaceCast for a pointer type depending on the address space.
bool isCast() const
Return true if this is a convert constant expression.
static Constant * getIdentity(Instruction *I, Type *Ty, bool AllowRHSConstant=false, bool NSZ=false)
Return the identity constant for a binary or intrinsic Instruction.
static bool isDesirableCastOp(unsigned Opcode)
Whether creating a constant expression for this cast is desirable.
Constant * getShuffleMaskForBitcode() const
Assert that this is a shufflevector and return the mask.
static Constant * getBinOpAbsorber(unsigned Opcode, Type *Ty, bool AllowLHSConstant=false)
Return the absorbing element for the given binary operation, i.e.
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
static Constant * getSub(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static Constant * getNot(Constant *C)
const char * getOpcodeName() const
Return a string representation for an opcode.
static Constant * getInsertElement(Constant *Vec, Constant *Elt, Constant *Idx, Type *OnlyIfReducedTy=nullptr)
static Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getShuffleVector(Constant *V1, Constant *V2, ArrayRef< int > Mask, Type *OnlyIfReducedTy=nullptr)
static Constant * getSizeOf(Type *Ty)
getSizeOf constant expr - computes the (alloc) size of a type (in address-units, not bits) in a targe...
static bool isSupportedGetElementPtr(const Type *SrcElemTy)
Whether creating a constant expression for this getelementptr type is supported.
static Constant * getIntrinsicIdentity(Intrinsic::ID, Type *Ty)
static Constant * getXor(Constant *C1, Constant *C2)
static Constant * getMul(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static Constant * get(unsigned Opcode, Constant *C1, Constant *C2, unsigned Flags=0, Type *OnlyIfReducedTy=nullptr)
get - Return a binary or shift operator constant expression, folding if possible.
static bool isDesirableBinOp(unsigned Opcode)
Whether creating a constant expression for this binary operator is desirable.
ArrayRef< int > getShuffleMask() const
Assert that this is a shufflevector and return the mask.
static bool isSupportedBinOp(unsigned Opcode)
Whether creating a constant expression for this binary operator is supported.
static Constant * getAddrSpaceCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
unsigned getOpcode() const
Return the opcode at the root of this constant expression.
static Constant * getGetElementPtr(Type *Ty, Constant *C, ArrayRef< Constant * > IdxList, GEPNoWrapFlags NW=GEPNoWrapFlags::none(), std::optional< ConstantRange > InRange=std::nullopt, Type *OnlyIfReducedTy=nullptr)
Getelementptr form.
static Constant * getAdd(Constant *C1, Constant *C2, bool HasNUW=false, bool HasNSW=false)
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static Constant * getBinOpIdentity(unsigned Opcode, Type *Ty, bool AllowRHSConstant=false, bool NSZ=false)
Return the identity constant for a binary opcode.
static bool isSupportedCastOp(unsigned Opcode)
Whether creating a constant expression for this cast is supported.
static Constant * getNeg(Constant *C, bool HasNSW=false)
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.
Instruction * getAsInstruction() const
Returns an Instruction which implements the same operation as this ConstantExpr.
ConstantFP - Floating Point Values [float, double].
static Constant * getSNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
static Constant * getInfinity(Type *Ty, bool Negative=false)
static Constant * getZero(Type *Ty, bool Negative=false)
static Constant * getNaN(Type *Ty, bool Negative=false, uint64_t Payload=0)
bool isExactlyValue(const APFloat &V) const
We don't rely on operator== working on double values, as it returns true for things that are clearly ...
static bool isValueValidForType(Type *Ty, const APFloat &V)
Return true if Ty is big enough to represent V.
static Constant * getQNaN(Type *Ty, bool Negative=false, APInt *Payload=nullptr)
This is the shared class of boolean and integer constants.
static bool isValueValidForType(Type *Ty, uint64_t V)
This static method returns true if the type Ty is big enough to represent the value V.
static ConstantInt * getTrue(LLVMContext &Context)
static ConstantInt * getFalse(LLVMContext &Context)
unsigned getBitWidth() const
getBitWidth - Return the scalar bitwidth of this constant.
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 ...
A signed pointer, in the ptrauth sense.
Constant * getAddrDiscriminator() const
The address discriminator if any, or the null constant.
bool isKnownCompatibleWith(const Value *Key, const Value *Discriminator, const DataLayout &DL) const
Check whether an authentication operation with key Key and (possibly blended) discriminator Discrimin...
bool hasSpecialAddressDiscriminator(uint64_t Value) const
Whether the address uses a special address discriminator.
static ConstantPtrAuth * get(Constant *Ptr, ConstantInt *Key, ConstantInt *Disc, Constant *AddrDisc)
Return a pointer signed with the specified parameters.
ConstantPtrAuth * getWithSameSchema(Constant *Pointer) const
Produce a new ptrauth expression signing the given value using the same schema as is stored in one.
ConstantInt * getKey() const
The Key ID, an i32 constant.
bool hasAddressDiscriminator() const
Whether there is any non-null address discriminator.
ConstantInt * getDiscriminator() const
The integer discriminator, an i64 constant, or 0.
This class represents a range of values.
ConstantRange unionWith(const ConstantRange &CR, PreferredRangeType Type=Smallest) const
Return the range that results from the union of this range with another range.
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.
FixedVectorType * getType() const
Specialize the getType() method to always return a FixedVectorType, which reduces the amount of casti...
Constant * getSplatValue(bool AllowPoison=false) const
If all elements of the vector constant have the same value, return that value.
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.
Constant * getSplatValue(bool AllowPoison=false) const
If all elements of the vector constant have the same value, return that value.
bool containsUndefElement() const
Return true if this is a vector constant that includes any strictly undef (not poison) elements.
static Constant * mergeUndefsWith(Constant *C, Constant *Other)
Merges undefs of a Constant with another Constant, along with the undefs already present.
ConstantRange toConstantRange() const
Convert constant to an approximate constant range.
static Constant * getAllOnesValue(Type *Ty)
bool hasZeroLiveUses() const
Return true if the constant has no live uses.
bool isOneValue() const
Returns true if the value is one.
bool isManifestConstant() const
Return true if a constant is ConstantData or a ConstantAggregate or ConstantExpr that contain only Co...
bool isNegativeZeroValue() const
Return true if the value is what would be returned by getZeroValueForNegation.
bool isAllOnesValue() const
Return true if this is the value that would be returned by getAllOnesValue.
bool hasOneLiveUse() const
Return true if the constant has exactly one live use.
bool needsRelocation() const
This method classifies the entry according to whether or not it may generate a relocation entry (eith...
bool isDLLImportDependent() const
Return true if the value is dependent on a dllimport variable.
const APInt & getUniqueInteger() const
If C is a constant integer then return its value, otherwise C must be a vector of constant integers,...
bool containsConstantExpression() const
Return true if this is a fixed width vector constant that includes any constant expressions.
bool isFiniteNonZeroFP() const
Return true if this is a finite and non-zero floating-point scalar constant or a fixed width vector c...
void removeDeadConstantUsers() const
If there are any dead constant users dangling off of this constant, remove them.
bool isNormalFP() const
Return true if this is a normal (as opposed to denormal, infinity, nan, or zero) floating-point scala...
bool needsDynamicRelocation() const
static Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
bool isNaN() const
Return true if this is a floating-point NaN constant or a vector floating-point constant with all NaN...
bool isMinSignedValue() const
Return true if the value is the smallest signed value.
bool isConstantUsed() const
Return true if the constant has users other than constant expressions and other dangling things.
Constant * getAggregateElement(unsigned Elt) const
For aggregates (struct/array/vector) return the constant that corresponds to the specified element if...
bool isThreadDependent() const
Return true if the value can vary between threads.
bool isZeroValue() const
Return true if the value is negative zero or null value.
void destroyConstant()
Called if some element of this constant is no longer valid.
bool isNotMinSignedValue() const
Return true if the value is not the smallest signed value, or, for vectors, does not contain smallest...
bool isNullValue() const
Return true if this is the value that would be returned by getNullValue.
bool isNotOneValue() const
Return true if the value is not the one value, or, for vectors, does not contain one value elements.
bool isElementWiseEqual(Value *Y) const
Return true if this constant and a constant 'Y' are element-wise equal.
bool containsUndefOrPoisonElement() const
Return true if this is a vector constant that includes any undef or poison elements.
bool containsPoisonElement() const
Return true if this is a vector constant that includes any poison elements.
void handleOperandChange(Value *, Value *)
This method is a special form of User::replaceUsesOfWith (which does not work on constants) that does...
Wrapper for a function that represents a value that functionally represents the original function.
GlobalValue * getGlobalValue() const
static DSOLocalEquivalent * get(GlobalValue *GV)
Return a DSOLocalEquivalent for the specified global value.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
static constexpr ElementCount getFixed(ScalarTy MinVal)
ExtractElementConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to...
static ExtractElementInst * Create(Value *Vec, Value *Idx, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static FixedVectorType * get(Type *ElementType, unsigned NumElts)
Represents flags for the getelementptr instruction/expression.
GetElementPtrConstantExpr - This class is private to Constants.cpp, and is used behind the scenes to ...
std::optional< ConstantRange > getInRange() const
Type * getResultElementType() const
Type * getSourceElementType() const
an instruction for type-safe pointer arithmetic to access elements of arrays and structs
static Type * getGEPReturnType(Value *Ptr, ArrayRef< Value * > IdxList)
Returns the pointer type returned by the GEP instruction, which may be a vector of pointers.
static GetElementPtrInst * Create(Type *PointeeType, Value *Ptr, ArrayRef< Value * > IdxList, const Twine &NameStr="", InsertPosition InsertBefore=nullptr)
static Type * getIndexedType(Type *Ty, ArrayRef< Value * > IdxList)
Returns the result type of a getelementptr with the given source element type and indexes.
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="", InsertPosition InsertBefore=nullptr)
void setHasNoUnsignedWrap(bool b=true)
Set or clear the nuw flag on this instruction, which must be an operator which supports this flag.
void setHasNoSignedWrap(bool b=true)
Set or clear the nsw flag on this instruction, which must be an operator which supports this flag.
bool isCommutative() const LLVM_READONLY
Return true if the instruction is commutative:
const char * getOpcodeName() const
void setIsExact(bool b=true)
Set or clear the exact flag on this instruction, which must be an operator which supports this flag.
Class to represent integer types.
static IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
A wrapper class for inspecting calls to intrinsic functions.
DenseMap< unsigned, std::unique_ptr< ConstantInt > > IntOneConstants
DenseMap< unsigned, std::unique_ptr< ConstantInt > > IntZeroConstants
DenseMap< APFloat, std::unique_ptr< ConstantFP > > FPConstants
DenseMap< PointerType *, std::unique_ptr< ConstantPointerNull > > CPNConstants
DenseMap< Type *, std::unique_ptr< ConstantAggregateZero > > CAZConstants
ConstantInt * TheFalseVal
DenseMap< Type *, std::unique_ptr< PoisonValue > > PVConstants
DenseMap< std::pair< const Function *, const BasicBlock * >, BlockAddress * > BlockAddresses
DenseMap< APInt, std::unique_ptr< ConstantInt > > IntConstants
std::unique_ptr< ConstantTokenNone > TheNoneToken
VectorConstantsTy VectorConstants
DenseMap< const GlobalValue *, NoCFIValue * > NoCFIValues
DenseMap< Type *, std::unique_ptr< UndefValue > > UVConstants
StringMap< std::unique_ptr< ConstantDataSequential > > CDSConstants
StructConstantsTy StructConstants
ConstantUniqueMap< ConstantPtrAuth > ConstantPtrAuths
DenseMap< TargetExtType *, std::unique_ptr< ConstantTargetNone > > CTNConstants
ConstantUniqueMap< ConstantExpr > ExprConstants
DenseMap< std::pair< ElementCount, APInt >, std::unique_ptr< ConstantInt > > IntSplatConstants
ArrayConstantsTy ArrayConstants
DenseMap< const GlobalValue *, DSOLocalEquivalent * > DSOLocalEquivalents
DenseMap< std::pair< ElementCount, APFloat >, std::unique_ptr< ConstantFP > > FPSplatConstants
This is an important class for using LLVM in a threaded context.
LLVMContextImpl *const pImpl
Wrapper for a value that won't be replaced with a CFI jump table pointer in LowerTypeTestsModule.
static NoCFIValue * get(GlobalValue *GV)
Return a NoCFIValue for the specified function.
PointerType * getType() const
NoCFIValue is always a pointer.
GlobalValue * getGlobalValue() const
Class to represent pointers.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
In order to facilitate speculative execution, many instructions do not invoke immediate undefined beh...
static PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
PoisonValue * getStructElement(unsigned Elt) const
If this poison has struct type, return a poison with the right element type for the specified element...
PoisonValue * getSequentialElement() const
If this poison has array or vector type, return a poison with the right element type.
PoisonValue * getElementValue(Constant *C) const
Return an poison of the right value for the specified GEP index if we can, otherwise return null (e....
static void SalvageDebugInfo(const Constant &C)
Replace all uses of the constant with Undef in debug info metadata.
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.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Class to represent struct types.
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Class to represent target extensions types, which are generally unintrospectable from target-independ...
bool hasProperty(Property Prop) const
Returns true if the target extension type contains the given property.
@ HasZeroInit
zeroinitializer is valid for this target extension type.
The instances of the Type class are immutable: once they are created, they are never changed.
unsigned getIntegerBitWidth() const
static Type * getDoubleTy(LLVMContext &C)
const fltSemantics & getFltSemantics() const
bool isVectorTy() const
True if this is an instance of VectorType.
static Type * getFloatingPointTy(LLVMContext &C, const fltSemantics &S)
bool isArrayTy() const
True if this is an instance of ArrayType.
bool isIntOrIntVectorTy() const
Return true if this is an integer type or a vector of integer types.
bool isPointerTy() const
True if this is an instance of PointerType.
static IntegerType * getInt1Ty(LLVMContext &C)
bool isFloatTy() const
Return true if this is 'float', a 32-bit IEEE fp type.
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
unsigned getStructNumElements() const
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
@ HalfTyID
16-bit floating point type
@ TargetExtTyID
Target extension type.
@ ScalableVectorTyID
Scalable SIMD vector type.
@ FloatTyID
32-bit floating point type
@ IntegerTyID
Arbitrary bit width integers.
@ FixedVectorTyID
Fixed width SIMD vector type.
@ BFloatTyID
16-bit floating point type (7-bit significand)
@ DoubleTyID
64-bit floating point type
@ X86_FP80TyID
80-bit floating point type (X87)
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
@ FP128TyID
128-bit floating point type (112-bit significand)
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
bool isStructTy() const
True if this is an instance of StructType.
bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value.
static IntegerType * getInt16Ty(LLVMContext &C)
bool isHalfTy() const
Return true if this is 'half', a 16-bit IEEE fp type.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
static IntegerType * getInt8Ty(LLVMContext &C)
bool isDoubleTy() const
Return true if this is 'double', a 64-bit IEEE fp type.
bool isFloatingPointTy() const
Return true if this is one of the floating-point types.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
static IntegerType * getInt32Ty(LLVMContext &C)
static IntegerType * getInt64Ty(LLVMContext &C)
static Type * getFloatTy(LLVMContext &C)
bool isIntegerTy() const
True if this is an instance of IntegerType.
TypeID getTypeID() const
Return the type id for the type.
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
'undef' values are things that do not have specified contents.
UndefValue * getElementValue(Constant *C) const
Return an undef of the right value for the specified GEP index if we can, otherwise return null (e....
UndefValue * getStructElement(unsigned Elt) const
If this undef has struct type, return a undef with the right element type for the specified element.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
unsigned getNumElements() const
Return the number of elements in the array, vector, or struct.
UndefValue * getSequentialElement() const
If this Undef has array or vector type, return a undef with the right element type.
A Use represents the edge between a Value definition and its users.
const Use * getOperandList() const
void setOperand(unsigned i, Value *Val)
Value * getOperand(unsigned i) const
unsigned getNumOperands() const
iterator_range< value_op_iterator > operand_values()
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
user_iterator_impl< const User > const_user_iterator
user_iterator user_begin()
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
const Value * stripAndAccumulateConstantOffsets(const DataLayout &DL, APInt &Offset, bool AllowNonInbounds, bool AllowInvariantGroup=false, function_ref< bool(Value &Value, APInt &Offset)> ExternalAnalysis=nullptr) const
Accumulate the constant offset this value has compared to a base pointer.
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)
specificval_ty m_Specific(const Value *V)
Match if we have a specific specified value.
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.
class_match< Value > m_Value()
Match an arbitrary value and ignore it.
auto m_Undef()
Match an arbitrary undef constant.
initializer< Ty > init(const Ty &Val)
NodeAddr< FuncNode * > Func
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Constant * ConstantFoldCompareInstruction(CmpInst::Predicate Predicate, Constant *C1, Constant *C2)
gep_type_iterator gep_type_end(const User *GEP)
void deleteConstant(Constant *C)
Constant * ConstantFoldGetElementPtr(Type *Ty, Constant *C, std::optional< ConstantRange > InRange, ArrayRef< Value * > Idxs)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
Constant * ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt, Constant *Idx)
Attempt to constant fold an insertelement instruction with the specified operands and indices.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Constant * ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx)
Attempt to constant fold an extractelement instruction with the specified operands and indices.
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
OutputIt copy(R &&Range, OutputIt Out)
constexpr unsigned BitWidth
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
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)
Implement std::hash so that hash_code can be used in STL containers.
static const fltSemantics & IEEEsingle() LLVM_READNONE
static constexpr roundingMode rmNearestTiesToEven
static const fltSemantics & PPCDoubleDouble() LLVM_READNONE
static const fltSemantics & x87DoubleExtended() LLVM_READNONE
static const fltSemantics & IEEEquad() LLVM_READNONE
static const fltSemantics & IEEEdouble() LLVM_READNONE
static const fltSemantics & IEEEhalf() LLVM_READNONE
static const fltSemantics & BFloat() LLVM_READNONE
Summary of memprof metadata on allocations.
Information about how a User object was allocated, to be passed into the User constructor.