41 cl::desc(
"Deref attributes and metadata infer facts at definition only"));
47 assert(Ty &&
"Value defined with a null type: Error!");
49 "Cannot have values with typed pointer types");
54 : VTy(
checkType(ty)), UseList(nullptr), SubclassID(scid), HasValueHandle(0),
55 SubclassOptionalData(0), SubclassData(0), NumUserOperands(0),
57 static_assert(ConstantFirstVal == 0,
"!(SubclassID < ConstantFirstVal)");
62 if (SubclassID >= InstructionVal)
63 OpCode = SubclassID - InstructionVal;
64 if (OpCode == Instruction::Call || OpCode == Instruction::Invoke ||
65 OpCode == Instruction::CallBr)
67 "invalid CallBase type!");
68 else if (SubclassID != BasicBlockVal &&
69 ( SubclassID > ConstantLastVal))
71 "Cannot create non-first-class values except for constants!");
72 static_assert(
sizeof(
Value) == 2 *
sizeof(
void *) + 2 *
sizeof(
unsigned),
98 dbgs() <<
"While deleting: " << *VTy <<
" %" <<
getName() <<
"\n";
99 for (
auto *U :
users())
100 dbgs() <<
"Use still stuck around after Def is destroyed:" << *U <<
"\n";
112#define HANDLE_VALUE(Name) \
113 case Value::Name##Val: \
114 delete static_cast<Name *>(this); \
116#define HANDLE_MEMORY_VALUE(Name) \
117 case Value::Name##Val: \
118 static_cast<DerivedUser *>(this)->DeleteValue( \
119 static_cast<DerivedUser *>(this)); \
121#define HANDLE_CONSTANT(Name) \
122 case Value::Name##Val: \
123 llvm_unreachable("constants should be destroyed with destroyConstant"); \
125#define HANDLE_INSTRUCTION(Name)
126#include "llvm/IR/Value.def"
128#define HANDLE_INST(N, OPC, CLASS) \
129 case Value::InstructionVal + Instruction::OPC: \
130 delete static_cast<CLASS *>(this); \
132#define HANDLE_USER_INST(N, OPC, CLASS)
133#include "llvm/IR/Instruction.def"
140void Value::destroyValueName() {
144 Name->Destroy(Allocator);
168 Use *Result =
nullptr;
170 if (!U.getUser()->isDroppable()) {
180 User *Result =
nullptr;
181 for (
auto *U :
users()) {
182 if (!U->isDroppable()) {
183 if (Result && Result != U)
203 if (U.getUser()->isDroppable() && ShouldDrop(&U))
205 for (
Use *U : ToBeEdited)
212 if (UsrOp.get() ==
this)
219 if (
auto *Assume = dyn_cast<AssumeInst>(U.getUser())) {
220 unsigned OpNo = U.getOperandNo();
226 BOI.
Tag = Assume->getContext().pImpl->getOrInsertBundleTag(
"ignore");
243 for (; BI != BE && UI != UE; ++BI, ++UI) {
248 const auto *
User = dyn_cast<Instruction>(*UI);
249 if (
User &&
User->getParent() == BB)
264 ST = PP->getValueSymbolTable();
265 }
else if (
BasicBlock *BB = dyn_cast<BasicBlock>(V)) {
267 ST =
P->getValueSymbolTable();
268 }
else if (
GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
269 if (
Module *
P = GV->getParent())
270 ST = &
P->getValueSymbolTable();
271 }
else if (
Argument *
A = dyn_cast<Argument>(V)) {
273 ST =
P->getValueSymbolTable();
275 assert(isa<Constant>(V) &&
"Unknown value type!");
287 "No name entry found!");
296 "HasName bit out of sync!");
318void Value::setNameImpl(
const Twine &NewName) {
324 if (!NeedNewName && !
hasName())
333 assert(!NameRef.
contains(0) &&
"Null bytes are not allowed in names");
339 assert(!
getType()->isVoidTy() &&
"Cannot assign a name to void values!");
351 if (!NameRef.
empty()) {
378 setNameImpl(NewName);
379 if (
Function *
F = dyn_cast<Function>(
this))
380 F->updateAfterNameChange();
384 assert(V !=
this &&
"Illegal call to this->takeName(this)!");
392 if (V->hasName()) V->setName(
"");
405 if (!V->hasName())
return;
419 assert(!Failure &&
"V has a name, so it should have a ST!"); (void)Failure;
426 V->setValueName(
nullptr);
435 VST->removeValueName(V->getValueName());
437 V->setValueName(
nullptr);
441 ST->reinsertValue(
this);
458 const GlobalValue *GV = dyn_cast<GlobalValue>(
this);
464 assert(M->isMaterialized());
471 if (!Cache.
insert(Expr).second)
477 auto *CE = dyn_cast<ConstantExpr>(O);
490 auto *
C = dyn_cast<Constant>(V);
494 auto *CE = dyn_cast<ConstantExpr>(Expr);
503void Value::doRAUW(
Value *New, ReplaceMetadataUses ReplaceMetaUses) {
504 assert(New &&
"Value::replaceAllUsesWith(<null>) is invalid!");
506 "this->replaceAllUsesWith(expr(this)) is NOT valid!");
508 "replaceAllUses of value with new value of different type!");
520 if (
auto *
C = dyn_cast<Constant>(
U.getUser())) {
521 if (!isa<GlobalValue>(
C)) {
522 C->handleOperandChange(
this, New);
530 if (
BasicBlock *BB = dyn_cast<BasicBlock>(
this))
531 BB->replaceSuccessorsPhiUsesWith(cast<BasicBlock>(New));
535 doRAUW(New, ReplaceMetadataUses::Yes);
539 doRAUW(New, ReplaceMetadataUses::No);
544 assert(New &&
"Value::replaceUsesWithIf(<null>) is invalid!");
546 "replaceUses of value with new value of different type!");
552 if (!ShouldReplace(U))
556 if (
auto *
C = dyn_cast<Constant>(U.getUser())) {
557 if (!isa<GlobalValue>(
C)) {
566 while (!Consts.
empty()) {
579 for (
auto *DVI : DbgUsers) {
580 if (DVI->getParent() != BB)
581 DVI->replaceVariableLocationOp(V, New);
583 for (
auto *DPV : DPUsers) {
584 DPMarker *Marker = DPV->getMarker();
586 DPV->replaceVariableLocationOp(V, New);
593 assert(New &&
"Value::replaceUsesOutsideBlock(<null>, BB) is invalid!");
595 "this->replaceUsesOutsideBlock(expr(this), BB) is NOT valid!");
597 "replaceUses of value with new value of different type!");
598 assert(BB &&
"Basic block that may contain a use of 'New' must be defined\n");
602 auto *
I = dyn_cast<Instruction>(U.getUser());
604 return !
I ||
I->getParent() != BB;
610enum PointerStripKind {
612 PSK_ZeroIndicesAndAliases,
613 PSK_ZeroIndicesSameRepresentation,
614 PSK_ForAliasAnalysis,
615 PSK_InBoundsConstantIndices,
619template <Po
interStripKind StripKind>
static void NoopCallback(
const Value *) {}
621template <Po
interStripKind StripKind>
622static const Value *stripPointerCastsAndOffsets(
625 if (!
V->getType()->isPointerTy())
635 if (
auto *
GEP = dyn_cast<GEPOperator>(V)) {
637 case PSK_ZeroIndices:
638 case PSK_ZeroIndicesAndAliases:
639 case PSK_ZeroIndicesSameRepresentation:
640 case PSK_ForAliasAnalysis:
641 if (!
GEP->hasAllZeroIndices())
644 case PSK_InBoundsConstantIndices:
645 if (!
GEP->hasAllConstantIndices())
649 if (!
GEP->isInBounds())
653 V =
GEP->getPointerOperand();
655 V = cast<Operator>(V)->getOperand(0);
656 if (!
V->getType()->isPointerTy())
658 }
else if (StripKind != PSK_ZeroIndicesSameRepresentation &&
662 V = cast<Operator>(V)->getOperand(0);
663 }
else if (StripKind == PSK_ZeroIndicesAndAliases && isa<GlobalAlias>(V)) {
664 V = cast<GlobalAlias>(V)->getAliasee();
665 }
else if (StripKind == PSK_ForAliasAnalysis && isa<PHINode>(V) &&
666 cast<PHINode>(V)->getNumIncomingValues() == 1) {
667 V = cast<PHINode>(V)->getIncomingValue(0);
669 if (
const auto *Call = dyn_cast<CallBase>(V)) {
670 if (
const Value *RV =
Call->getReturnedArgOperand()) {
677 if (StripKind == PSK_ForAliasAnalysis &&
678 (
Call->getIntrinsicID() == Intrinsic::launder_invariant_group ||
679 Call->getIntrinsicID() == Intrinsic::strip_invariant_group)) {
680 V =
Call->getArgOperand(0);
686 assert(
V->getType()->isPointerTy() &&
"Unexpected operand type!");
687 }
while (Visited.
insert(V).second);
694 return stripPointerCastsAndOffsets<PSK_ZeroIndices>(
this);
698 return stripPointerCastsAndOffsets<PSK_ZeroIndicesAndAliases>(
this);
702 return stripPointerCastsAndOffsets<PSK_ZeroIndicesSameRepresentation>(
this);
706 return stripPointerCastsAndOffsets<PSK_InBoundsConstantIndices>(
this);
710 return stripPointerCastsAndOffsets<PSK_ForAliasAnalysis>(
this);
715 bool AllowInvariantGroup,
717 if (!
getType()->isPtrOrPtrVectorTy())
722 "The offset bit width does not match the DL specification.");
728 const Value *V =
this;
730 if (
auto *
GEP = dyn_cast<GEPOperator>(V)) {
732 if (!AllowNonInbounds && !
GEP->isInBounds())
741 APInt GEPOffset(
DL.getIndexTypeSizeInBits(V->getType()), 0);
742 if (!
GEP->accumulateConstantOffset(
DL, GEPOffset, ExternalAnalysis))
748 if (GEPOffset.getSignificantBits() >
BitWidth)
754 if (!ExternalAnalysis) {
757 bool Overflow =
false;
765 V =
GEP->getPointerOperand();
768 V = cast<Operator>(V)->getOperand(0);
769 }
else if (
auto *GA = dyn_cast<GlobalAlias>(V)) {
770 if (!GA->isInterposable())
771 V = GA->getAliasee();
772 }
else if (
const auto *Call = dyn_cast<CallBase>(V)) {
773 if (
const Value *RV =
Call->getReturnedArgOperand())
775 if (AllowInvariantGroup &&
Call->isLaunderOrStripInvariantGroup())
776 V =
Call->getArgOperand(0);
778 assert(
V->getType()->isPtrOrPtrVectorTy() &&
"Unexpected operand type!");
779 }
while (Visited.
insert(V).second);
786 return stripPointerCastsAndOffsets<PSK_InBounds>(
this, Func);
794 if (isa<Constant>(
this))
799 if (
auto *
A = dyn_cast<Argument>(
this)) {
800 if (
A->hasPointeeInMemoryValueAttr())
808 if (
F->doesNotFreeMemory() &&
F->hasNoSync())
813 if (
auto *
I = dyn_cast<Instruction>(
this))
814 F =
I->getFunction();
815 if (
auto *
A = dyn_cast<Argument>(
this))
830 const auto &GCName =
F->getGC();
831 if (GCName ==
"statepoint-example") {
832 auto *PT = cast<PointerType>(this->
getType());
833 if (PT->getAddressSpace() != 1)
843 for (
auto &Fn : *
F->getParent())
844 if (Fn.getIntrinsicID() == Intrinsic::experimental_gc_statepoint)
853 bool &CanBeFreed)
const {
859 if (
const Argument *
A = dyn_cast<Argument>(
this)) {
860 DerefBytes =
A->getDereferenceableBytes();
861 if (DerefBytes == 0) {
863 if (
Type *ArgMemTy =
A->getPointeeInMemoryValueType()) {
864 if (ArgMemTy->isSized()) {
866 DerefBytes =
DL.getTypeStoreSize(ArgMemTy).getKnownMinValue();
871 if (DerefBytes == 0) {
872 DerefBytes =
A->getDereferenceableOrNullBytes();
875 }
else if (
const auto *Call = dyn_cast<CallBase>(
this)) {
876 DerefBytes = Call->getRetDereferenceableBytes();
877 if (DerefBytes == 0) {
878 DerefBytes = Call->getRetDereferenceableOrNullBytes();
881 }
else if (
const LoadInst *LI = dyn_cast<LoadInst>(
this)) {
882 if (
MDNode *MD = LI->getMetadata(LLVMContext::MD_dereferenceable)) {
883 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
886 if (DerefBytes == 0) {
888 LI->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
889 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
894 }
else if (
auto *IP = dyn_cast<IntToPtrInst>(
this)) {
895 if (
MDNode *MD = IP->getMetadata(LLVMContext::MD_dereferenceable)) {
896 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
899 if (DerefBytes == 0) {
901 IP->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
902 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
907 }
else if (
auto *AI = dyn_cast<AllocaInst>(
this)) {
908 if (!AI->isArrayAllocation()) {
910 DL.getTypeStoreSize(AI->getAllocatedType()).getKnownMinValue();
914 }
else if (
auto *GV = dyn_cast<GlobalVariable>(
this)) {
915 if (GV->getValueType()->isSized() && !GV->hasExternalWeakLinkage()) {
918 DerefBytes =
DL.getTypeStoreSize(GV->getValueType()).getFixedValue();
928 if (
auto *GO = dyn_cast<GlobalObject>(
this)) {
929 if (isa<Function>(GO)) {
930 Align FunctionPtrAlign =
DL.getFunctionPtrAlign().valueOrOne();
931 switch (
DL.getFunctionPtrAlignType()) {
933 return FunctionPtrAlign;
935 return std::max(FunctionPtrAlign, GO->getAlign().valueOrOne());
941 if (
auto *GVar = dyn_cast<GlobalVariable>(GO)) {
942 Type *ObjectType = GVar->getValueType();
947 if (GVar->isStrongDefinitionForLinker())
948 return DL.getPreferredAlign(GVar);
950 return DL.getABITypeAlign(ObjectType);
955 }
else if (
const Argument *
A = dyn_cast<Argument>(
this)) {
957 if (!Alignment &&
A->hasStructRetAttr()) {
959 Type *EltTy =
A->getParamStructRetType();
961 return DL.getABITypeAlign(EltTy);
964 }
else if (
const AllocaInst *AI = dyn_cast<AllocaInst>(
this)) {
965 return AI->getAlign();
966 }
else if (
const auto *Call = dyn_cast<CallBase>(
this)) {
968 if (!Alignment && Call->getCalledFunction())
969 Alignment = Call->getCalledFunction()->getAttributes().getRetAlignment();
971 }
else if (
const LoadInst *LI = dyn_cast<LoadInst>(
this)) {
972 if (
MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) {
973 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
976 }
else if (
auto *CstPtr = dyn_cast<Constant>(
this)) {
979 CstPtr = CstPtr->stripPointerCasts();
983 size_t TrailingZeros = CstInt->getValue().countr_zero();
994static std::optional<int64_t>
998 for (
unsigned i = 1; i !=
Idx; ++i, ++GTI)
1003 for (
unsigned i =
Idx, e =
GEP->getNumOperands(); i != e; ++i, ++GTI) {
1006 return std::nullopt;
1019 if (
Size.isScalable())
1020 return std::nullopt;
1030 const Value *Ptr2 =
this;
1040 const GEPOperator *GEP1 = dyn_cast<GEPOperator>(Ptr1);
1041 const GEPOperator *GEP2 = dyn_cast<GEPOperator>(Ptr2);
1050 return std::nullopt;
1060 if (!IOffset1 || !IOffset2)
1061 return std::nullopt;
1062 return *IOffset2 - *IOffset1 + Offset2.
getSExtValue() -
1068 auto *PN = dyn_cast<PHINode>(
this);
1069 if (PN && PN->getParent() == CurBB)
1070 return PN->getIncomingValueForBlock(PredBB);
1077 if (!UseList || !UseList->Next)
1081 Use *Head = UseList;
1082 Use *Current = UseList->Next;
1083 Head->Next =
nullptr;
1085 Use *Next = Current->Next;
1086 Current->Next = Head;
1087 Head->Prev = &Current->Next;
1092 Head->Prev = &UseList;
1096 auto *Arg = dyn_cast<Argument>(
this);
1098 return Arg->hasSwiftErrorAttr();
1099 auto *Alloca = dyn_cast<AllocaInst>(
this);
1102 return Alloca->isSwiftError();
1117 Next->setPrevPtr(&Next);
1123 assert(
List &&
"Must insert after existing node");
1126 setPrevPtr(&
List->Next);
1129 Next->setPrevPtr(&Next);
1132void ValueHandleBase::AddToUseList() {
1141 assert(Entry &&
"Value doesn't have any handles?");
1142 AddToExistingUseList(&Entry);
1155 assert(!Entry &&
"Value really did already have handles?");
1156 AddToExistingUseList(&Entry);
1162 Handles.
size() == 1) {
1168 E = Handles.
end();
I !=
E; ++
I) {
1169 assert(
I->second &&
I->first ==
I->second->getValPtr() &&
1170 "List invariant broken!");
1171 I->second->setPrevPtr(&
I->second);
1177 "Pointer doesn't have a use list!");
1181 assert(*PrevPtr ==
this &&
"List invariant broken");
1185 assert(Next->getPrevPtr() == &Next &&
"List invariant broken");
1186 Next->setPrevPtr(PrevPtr);
1202 assert(V->HasValueHandle &&
"Should only be called if ValueHandles present");
1208 assert(Entry &&
"Value bit set but no entries exist");
1220 Iterator.RemoveFromUseList();
1221 Iterator.AddToExistingUseListAfter(Entry);
1222 assert(Entry->Next == &Iterator &&
"Loop invariant broken.");
1224 switch (Entry->getKind()) {
1231 Entry->operator=(
nullptr);
1241 if (V->HasValueHandle) {
1243 dbgs() <<
"While deleting: " << *V->getType() <<
" %" << V->getName()
1255 assert(Old->HasValueHandle &&
"Should only be called if ValueHandles present");
1256 assert(Old != New &&
"Changing value into itself!");
1258 "replaceAllUses of value with new value of different type!");
1265 assert(Entry &&
"Value bit set but no entries exist");
1272 Iterator.RemoveFromUseList();
1273 Iterator.AddToExistingUseListAfter(Entry);
1274 assert(Entry->Next == &Iterator &&
"Loop invariant broken.");
1276 switch (Entry->getKind()) {
1283 Entry->operator=(New);
1287 static_cast<CallbackVH*
>(Entry)->allUsesReplacedWith(New);
1295 if (Old->HasValueHandle)
1296 for (Entry = pImpl->
ValueHandles[Old]; Entry; Entry = Entry->Next)
1297 switch (Entry->getKind()) {
1299 dbgs() <<
"After RAUW from " << *Old->
getType() <<
" %"
1300 << Old->
getName() <<
" to " << *New->getType() <<
" %"
1301 << New->getName() <<
"\n";
1303 "A weak tracking value handle still pointed to the old value!\n");
1311void CallbackVH::anchor() {}
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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
This file defines the DenseMap class.
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallString class.
static std::optional< int64_t > getOffsetFromIndex(const GEPOperator *GEP, unsigned Idx, const DataLayout &DL)
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
static Type * checkType(Type *Ty)
static bool getSymTab(Value *V, ValueSymbolTable *&ST)
static void replaceDbgUsesOutsideBlock(Value *V, Value *New, BasicBlock *BB)
Replace llvm.dbg.
static bool isUnDroppableUser(const User *U)
static cl::opt< unsigned > UseDerefAtPointSemantics("use-dereferenceable-at-point-semantics", cl::Hidden, cl::init(false), cl::desc("Deref attributes and metadata infer facts at definition only"))
Class for arbitrary precision integers.
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
int64_t getSExtValue() const
Get sign extended value.
an instruction to allocate memory on the stack
This class represents an incoming formal argument to a Function.
LLVM Basic Block Representation.
iterator begin()
Instruction iterator methods.
InstListType::const_iterator const_iterator
Value handle with callbacks on RAUW and destruction.
A constant value that is initialized with an expression using other constant values.
static Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
This is the shared class of boolean and integer constants.
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
getLimitedValue - If the value is smaller than the specified limit, return it, otherwise return the l...
static ConstantInt * getTrue(LLVMContext &Context)
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
This is an important base class in LLVM.
Per-instruction record of debug-info.
const BasicBlock * getParent() const
A parsed version of the target data layout string in and methods for querying it.
@ MultipleOfFunctionAlign
The function pointer alignment is a multiple of the function alignment.
@ Independent
The function pointer alignment is independent of the function alignment.
bool erase(const KeyT &Val)
bool isPointerIntoBucketsArray(const void *Ptr) const
isPointerIntoBucketsArray - Return true if the specified pointer points somewhere into the DenseMap's...
const void * getPointerIntoBucketsArray() const
getPointerIntoBucketsArray() - Return an opaque pointer into the buckets array.
Type * getSourceElementType() const
Module * getParent()
Get the module that this global value is contained inside of...
DenseMap< const Value *, ValueName * > ValueNames
ValueHandlesTy ValueHandles
This is an important class for using LLVM in a threaded context.
bool shouldDiscardValueNames() const
Return true if the Context runtime configuration is set to discard all value names.
LLVMContextImpl *const pImpl
An instruction for reading from memory.
A Module instance is used to store all the information related to an LLVM module.
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
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.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
void setValue(const ValueTy &V)
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
static StringMapEntry * create(StringRef key, AllocatorTy &allocator, InitTy &&...initVals)
Create a StringMapEntry for the specified key construct the value using InitiVals.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
Class to represent struct types.
Value handle that tracks a Value across RAUW.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
bool isTriviallyEmpty() const
Check if this twine is trivially empty; a false return value does not necessarily mean the twine is e...
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
The instances of the Type class are immutable: once they are created, they are never changed.
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.
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
bool isVoidTy() const
Return true if this is 'void'.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
A Use represents the edge between a Value definition and its users.
Value * getOperand(unsigned i) const
unsigned getNumOperands() const
bool isDroppable() const
A droppable user is a user for which uses can be dropped without affecting correctness and should be ...
This is the common base class of value handles.
void RemoveFromUseList()
Remove this ValueHandle from its current use list.
Value * getValPtr() const
static void ValueIsDeleted(Value *V)
static void ValueIsRAUWd(Value *Old, Value *New)
This class provides a symbol table of name/value pairs.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
static constexpr uint64_t MaximumAlignment
user_iterator_impl< const User > const_user_iterator
user_iterator user_begin()
const Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB) const
Translate PHI node to its predecessor from the given basic block.
Value(Type *Ty, unsigned scid)
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.
void reverseUseList()
Reverse the use-list.
void assertModuleIsMaterializedImpl() const
bool hasNUndroppableUsesOrMore(unsigned N) const
Return true if this value has N uses or more.
bool hasOneUser() const
Return true if there is exactly one user of this value.
const Value * stripPointerCastsAndAliases() const
Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
void setName(const Twine &Name)
Change the name of the value.
const Value * stripInBoundsConstantOffsets() const
Strip off pointer casts and all-constant inbounds GEPs.
std::string getNameOrAsOperand() const
bool hasOneUse() const
Return true if there is exactly one use of this value.
~Value()
Value's destructor should be virtual by design, but that would require that Value and all of its subc...
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
const Value * stripInBoundsOffsets(function_ref< void(const Value *)> Func=[](const Value *) {}) const
Strip off pointer casts and inbounds GEPs.
iterator_range< user_iterator > users()
static void dropDroppableUse(Use &U)
Remove the droppable use U.
Align getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
unsigned getValueID() const
Return an ID for the concrete type of this object.
bool isUsedInBasicBlock(const BasicBlock *BB) const
Check if this value is used in the specified basic block.
bool materialized_use_empty() const
void printAsOperand(raw_ostream &O, bool PrintType=true, const Module *M=nullptr) const
Print the name of this Value out to the specified raw_ostream.
bool isUsedByMetadata() const
Return true if there is metadata referencing this value.
bool hasNUsesOrMore(unsigned N) const
Return true if this value has N uses or more.
void dropDroppableUsesIn(User &Usr)
Remove every use of this value in User that can safely be removed.
Use * getSingleUndroppableUse()
Return true if there is exactly one use of this value that cannot be dropped.
bool canBeFreed() const
Return true if the memory object referred to by V can by freed in the scope for which the SSA value d...
bool hasNUses(unsigned N) const
Return true if this Value has exactly N uses.
void replaceUsesWithIf(Value *New, llvm::function_ref< bool(Use &U)> ShouldReplace)
Go through the uses list for this definition and make each use point to "V" if the callback ShouldRep...
void setValueName(ValueName *VN)
User * getUniqueUndroppableUser()
Return true if there is exactly one unique user of this value that cannot be dropped (that user can h...
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
bool isSwiftError() const
Return true if this value is a swifterror value.
void deleteValue()
Delete a pointer to a generic Value.
ValueName * getValueName() const
const Value * stripPointerCastsSameRepresentation() const
Strip off pointer casts, all-zero GEPs and address space casts but ensures the representation of the ...
void dropDroppableUses(llvm::function_ref< bool(const Use *)> ShouldDrop=[](const Use *) { return true;})
Remove every uses that can safely be removed.
void replaceUsesOutsideBlock(Value *V, BasicBlock *BB)
replaceUsesOutsideBlock - Go through the uses list for this definition and make each use point to "V"...
LLVMContext & getContext() const
All values hold a context through their type.
static constexpr unsigned MaxAlignmentExponent
The maximum alignment for instructions.
unsigned getNumUses() const
This method computes the number of uses of this Value.
iterator_range< use_iterator > uses()
std::optional< int64_t > getPointerOffsetFrom(const Value *Other, const DataLayout &DL) const
If this ptr is provably equal to Other plus a constant offset, return that offset in bytes.
uint64_t getPointerDereferenceableBytes(const DataLayout &DL, bool &CanBeNull, bool &CanBeFreed) const
Returns the number of bytes known to be dereferenceable for the pointer value.
void clearMetadata()
Erase all metadata attached to this Value.
StringRef getName() const
Return a constant reference to the value's name.
void replaceNonMetadataUsesWith(Value *V)
Change non-metadata uses of this to point to a new Value.
void takeName(Value *V)
Transfer the name from V to this value.
bool hasNUndroppableUses(unsigned N) const
Return true if there this value.
const Value * stripPointerCastsForAliasAnalysis() const
Strip off pointer casts, all-zero GEPs, single-argument phi nodes and invariant group info.
An efficient, type-erasing, non-owning reference to a callable.
StructType * getStructTypeOrNull() const
Type * getIndexedType() const
A raw_ostream that writes to an std::string.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
initializer< Ty > init(const Ty &Val)
NodeAddr< FuncNode * > Func
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
bool hasNItemsOrMore(IterTy &&Begin, IterTy &&End, unsigned N, Pred &&ShouldBeCounted=[](const decltype(*std::declval< IterTy >()) &) { return true;}, std::enable_if_t< !std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< std::remove_reference_t< decltype(Begin)> >::iterator_category >::value, void > *=nullptr)
Return true if the sequence [Begin, End) has N or more items.
bool hasNItems(IterTy &&Begin, IterTy &&End, unsigned N, Pred &&ShouldBeCounted=[](const decltype(*std::declval< IterTy >()) &) { return true;}, std::enable_if_t< !std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< std::remove_reference_t< decltype(Begin)> >::iterator_category >::value, void > *=nullptr)
Return true if the sequence [Begin, End) has exactly N items.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void findDbgUsers(SmallVectorImpl< DbgVariableIntrinsic * > &DbgInsts, Value *V, SmallVectorImpl< DPValue * > *DPValues=nullptr)
Finds the debug info intrinsics describing a value.
constexpr unsigned BitWidth
gep_type_iterator gep_type_begin(const User *GEP)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Used to keep track of an operand bundle.
StringMapEntry< uint32_t > * Tag
The operand bundle tag, interned by LLVMContextImpl::getOrInsertBundleTag.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.