13#ifndef LLVM_IR_VALUE_H
14#define LLVM_IR_VALUE_H
76 const unsigned char SubclassID;
77 unsigned char HasValueHandle : 1;
93 unsigned short SubclassData;
119 Use *UseList =
nullptr;
124 template <
typename UseT>
125 class use_iterator_impl {
130 explicit use_iterator_impl(UseT *u) : U(u) {}
133 using iterator_category = std::forward_iterator_tag;
134 using value_type = UseT;
135 using difference_type = std::ptrdiff_t;
136 using pointer = value_type *;
137 using reference = value_type &;
139 use_iterator_impl() : U() {}
141 bool operator==(
const use_iterator_impl &x)
const {
return U == x.U; }
142 bool operator!=(
const use_iterator_impl &x)
const {
return !
operator==(x); }
144 use_iterator_impl &operator++() {
145 assert(U &&
"Cannot increment end iterator!");
150 use_iterator_impl operator++(
int) {
156 UseT &operator*()
const {
157 assert(U &&
"Cannot dereference end iterator!");
161 UseT *operator->()
const {
return &operator*(); }
163 operator use_iterator_impl<const UseT>()
const {
164 return use_iterator_impl<const UseT>(U);
168 template <
typename UserTy>
169 class user_iterator_impl {
170 use_iterator_impl<Use> UI;
171 explicit user_iterator_impl(Use *U) : UI(
U) {}
175 using iterator_category = std::forward_iterator_tag;
176 using value_type = UserTy *;
177 using difference_type = std::ptrdiff_t;
178 using pointer = value_type *;
179 using reference = value_type &;
181 user_iterator_impl() =
default;
183 bool operator==(
const user_iterator_impl &x)
const {
return UI ==
x.UI; }
184 bool operator!=(
const user_iterator_impl &x)
const {
return !
operator==(x); }
187 bool atEnd()
const {
return *
this == user_iterator_impl(); }
189 user_iterator_impl &operator++() {
194 user_iterator_impl operator++(
int) {
201 UserTy *operator*()
const {
202 return UI->getUser();
205 UserTy *operator->()
const {
return operator*(); }
207 operator user_iterator_impl<const UserTy>()
const {
208 return user_iterator_impl<const UserTy>(*UI);
211 Use &getUse()
const {
return *UI; }
238 bool IsForDebug =
false)
const;
249 const Module *M =
nullptr)
const;
266 void destroyValueName();
267 enum class ReplaceMetadataUses {
No,
Yes };
268 void doRAUW(Value *New, ReplaceMetadataUses);
269 void setNameImpl(
const Twine &Name);
348 return UseList ==
nullptr;
493 [](
const Use *) {
return true; });
515 U.addToList(&UseList);
525#define HANDLE_VALUE(Name) Name##Val,
526#include "llvm/IR/Value.def"
529#define HANDLE_CONSTANT_MARKER(Marker, Constant) Marker = Constant##Val,
530#include "llvm/IR/Value.def"
580 LLVM_ABI unsigned getMetadataIndex()
const;
581 LLVM_ABI unsigned &getMetadataIndex();
635 return const_cast<Value *
>(
636 static_cast<const Value *
>(
this)->stripPointerCasts());
645 return const_cast<Value *
>(
646 static_cast<const Value *
>(
this)->stripPointerCastsAndAliases());
656 return const_cast<Value *
>(
static_cast<const Value *
>(
this)
657 ->stripPointerCastsSameRepresentation());
668 return const_cast<Value *
>(
static_cast<const Value *
>(
this)
669 ->stripPointerCastsForAliasAnalysis());
678 return const_cast<Value *
>(
679 static_cast<const Value *
>(
this)->stripInBoundsConstantOffsets());
718 bool AllowInvariantGroup =
false,
721 bool LookThroughIntToPtr =
false)
const;
725 bool AllowInvariantGroup =
false,
728 bool LookThroughIntToPtr =
false) {
729 return const_cast<Value *
>(
730 static_cast<const Value *
>(
this)->stripAndAccumulateConstantOffsets(
731 DL,
Offset, AllowNonInbounds, AllowInvariantGroup, ExternalAnalysis,
732 LookThroughIntToPtr));
755 [](
const Value *) {}) {
756 return const_cast<Value *
>(
782 bool &CanBeFreed)
const;
797 const BasicBlock *PredBB)
const;
799 return const_cast<Value *
>(
800 static_cast<const Value *
>(
this)->DoPHITranslation(CurBB, PredBB));
824 template <
class Compare>
void sortUseList(Compare Cmp);
838 template <
class Compare>
839 static Use *mergeUseLists(
Use *L,
Use *R, Compare Cmp) {
901 if (!UseList || !UseList->Next)
910 const unsigned MaxSlots = 32;
911 Use *Slots[MaxSlots];
915 UseList->Next =
nullptr;
916 unsigned NumSlots = 1;
922 Next = Current->Next;
925 Current->Next =
nullptr;
929 for (
I = 0;
I < NumSlots; ++
I) {
937 Current = mergeUseLists(Slots[
I], Current, Cmp);
943 assert(NumSlots <= MaxSlots &&
"Use list bigger than 2^32");
952 assert(!
Next->Next &&
"Expected only one Use");
954 for (
unsigned I = 0;
I < NumSlots; ++
I)
958 UseList = mergeUseLists(Slots[
I], UseList, Cmp);
961 for (
Use *
I = UseList, **Prev = &UseList;
I;
I =
I->Next) {
972 static_assert(Value::ConstantFirstVal == 0,
973 "Val.getValueID() >= Value::ConstantFirstVal");
974 return Val.
getValueID() <= Value::ConstantLastVal;
980 static_assert(Value::ConstantDataFirstVal == 0,
981 "Val.getValueID() >= Value::ConstantDataFirstVal");
982 return Val.
getValueID() <= Value::ConstantDataLastVal;
988 return Val.
getValueID() >= Value::ConstantAggregateFirstVal &&
989 Val.
getValueID() <= Value::ConstantAggregateLastVal;
995 return Val.
getValueID() == Value::ArgumentVal;
1001 return Val.
getValueID() == Value::InlineAsmVal;
1007 return Val.
getValueID() >= Value::InstructionVal;
1013 return Val.
getValueID() == Value::BasicBlockVal;
1019 return Val.
getValueID() == Value::FunctionVal;
1025 return Val.
getValueID() == Value::GlobalVariableVal;
1031 return Val.
getValueID() == Value::GlobalAliasVal;
1037 return Val.
getValueID() == Value::GlobalIFuncVal;
1059 return reinterpret_cast<Value**
>(Vals);
1069 return reinterpret_cast<T**
>(Vals);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref)
This defines the Use class.
bool operator==(const MergedFunctionsInfo &LHS, const MergedFunctionsInfo &RHS)
Class for arbitrary precision integers.
This class represents an incoming formal argument to a Function.
LLVM Basic Block Representation.
Base class for aggregate constants (with operands).
Base class for constants with no operands.
This is an important base class in LLVM.
A parsed version of the target data layout string in and methods for querying it.
This is an important class for using LLVM in a threaded context.
Manage lifetime of a slot tracker for printing IR.
A Module instance is used to store all the information related to an LLVM module.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
A Use represents the edge between a Value definition and its users.
LLVM_ABI void set(Value *Val)
LLVM_ABI Value * operator=(Value *RHS)
LLVM Value Representation.
iterator_range< user_iterator > materialized_users()
Type * getType() const
All values are typed, get the type of this value.
Value * stripInBoundsOffsets(function_ref< void(const Value *)> Func=[](const Value *) {})
unsigned short getSubclassDataFromValue() const
const_use_iterator materialized_use_begin() const
static constexpr uint64_t MaximumAlignment
Value * stripPointerCasts()
user_iterator_impl< const User > const_user_iterator
const Value * stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL, APInt &Offset) const
This is a wrapper around stripAndAccumulateConstantOffsets with the in-bounds requirement set to fals...
user_iterator user_begin()
LLVM_ABI const Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB) const
Translate PHI node to its predecessor from the given basic block.
LLVM_ABI Value(Type *Ty, unsigned scid)
iterator_range< use_iterator > materialized_uses()
LLVM_ABI void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
use_iterator_impl< const Use > const_use_iterator
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
iterator_range< const_use_iterator > uses() const
const_use_iterator use_begin() const
iterator_range< const_user_iterator > materialized_users() const
LLVM_ABI void reverseUseList()
Reverse the use-list.
const User * getUniqueUndroppableUser() const
LLVM_ABI void assertModuleIsMaterializedImpl() const
LLVM_ABI bool hasNUndroppableUsesOrMore(unsigned N) const
Return true if this value has N uses or more.
LLVM_ABI bool hasOneUser() const
Return true if there is exactly one user of this value.
LLVM_ABI const Value * stripPointerCastsAndAliases() const
Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
void assertModuleIsMaterialized() const
friend class ValueHandleBase
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set a particular kind of metadata attachment.
unsigned getRawSubclassOptionalData() const
Return the raw optional flags value contained in this value.
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
LLVM_ABI const Value * stripInBoundsConstantOffsets() const
Strip off pointer casts and all-constant inbounds GEPs.
LLVM_ABI std::string getNameOrAsOperand() const
bool hasOneUse() const
Return true if there is exactly one use of this value.
LLVM_ABI ~Value()
Value's destructor should be virtual by design, but that would require that Value and all of its subc...
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVMContext & getContext() const
All values hold a context through their type.
friend class ValueAsMetadata
LLVM_ABI void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
LLVM_ABI 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 LLVM_ABI void dropDroppableUse(Use &U)
Remove the droppable use U.
void sortUseList(Compare Cmp)
Sort the use-list.
iterator_range< const_user_iterator > users() const
LLVM_ABI Align getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
void clearSubclassOptionalData()
Clear the optional flags contained in this value.
unsigned getValueID() const
Return an ID for the concrete type of this object.
Value * stripPointerCastsAndAliases()
LLVM_ABI bool isUsedInBasicBlock(const BasicBlock *BB) const
Check if this value is used in the specified basic block.
Value * stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL, APInt &Offset)
const User * user_back() const
bool materialized_use_empty() const
LLVM_ABI 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 hasUseList() const
Check if this Value has a use-list.
Value * stripAndAccumulateConstantOffsets(const DataLayout &DL, APInt &Offset, bool AllowNonInbounds, bool AllowInvariantGroup=false, function_ref< bool(Value &Value, APInt &Offset)> ExternalAnalysis=nullptr, bool LookThroughIntToPtr=false)
bool isUsedByMetadata() const
Return true if there is metadata referencing this value.
LLVM_ABI bool hasNUsesOrMore(unsigned N) const
Return true if this value has N uses or more.
LLVM_ABI void dropDroppableUsesIn(User &Usr)
Remove every use of this value in User that can safely be removed.
use_iterator materialized_use_begin()
LLVM_ABI Use * getSingleUndroppableUse()
Return true if there is exactly one use of this value that cannot be dropped.
LLVM_ABI 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...
LLVM_ABI bool hasNUses(unsigned N) const
Return true if this Value has exactly N uses.
LLVM_ABI MDNode * getMetadataImpl(unsigned KindID) const LLVM_READONLY
Get metadata for the given kind, if any.
Value(const Value &)=delete
iterator_range< const_use_iterator > materialized_uses() const
use_iterator_impl< Use > use_iterator
LLVM_ABI void setValueName(ValueName *VN)
LLVM_ABI User * getUniqueUndroppableUser()
Return true if there is exactly one unique user of this value that cannot be dropped (that user can h...
LLVM_ABI const Value * stripAndAccumulateConstantOffsets(const DataLayout &DL, APInt &Offset, bool AllowNonInbounds, bool AllowInvariantGroup=false, function_ref< bool(Value &Value, APInt &Offset)> ExternalAnalysis=nullptr, bool LookThroughIntToPtr=false) const
Accumulate the constant offset this value has compared to a base pointer.
LLVM_ABI const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
LLVM_ABI bool isSwiftError() const
Return true if this value is a swifterror value.
LLVM_ABI void deleteValue()
Delete a pointer to a generic Value.
LLVM_ABI ValueName * getValueName() const
LLVM_ABI const Value * stripPointerCastsSameRepresentation() const
Strip off pointer casts, all-zero GEPs and address space casts but ensures the representation of the ...
LLVM_ABI bool eraseMetadata(unsigned KindID)
Erase all metadata attachments with the given kind.
LLVM_ABI void addMetadata(unsigned KindID, MDNode &MD)
Add a metadata attachment.
LLVM_ABI void dropDroppableUses(llvm::function_ref< bool(const Use *)> ShouldDrop=[](const Use *) { return true;})
Remove every uses that can safely be removed.
bool hasSameSubclassOptionalData(const Value *V) const
Check the optional flags for equality.
LLVM_ABI void replaceUsesOutsideBlock(Value *V, BasicBlock *BB)
replaceUsesOutsideBlock - Go through the uses list for this definition and make each use point to "V"...
void addUse(Use &U)
This method should only be used by the Use class.
void setValueSubclassData(unsigned short D)
LLVM_ABI MDNode * getMetadata(StringRef Kind) const LLVM_READONLY
Get the current metadata attachments for the given kind, if any.
LLVM_ABI void eraseMetadataIf(function_ref< bool(unsigned, MDNode *)> Pred)
Erase all metadata attachments matching the given predicate.
Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB)
static constexpr unsigned MaxAlignmentExponent
The maximum alignment for instructions.
bool hasValueHandle() const
Return true if there is a value handle associated with this value.
LLVM_ABI unsigned getNumUses() const
This method computes the number of uses of this Value.
LLVM_ABI bool 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...
Value & operator=(const Value &)=delete
iterator_range< use_iterator > uses()
void mutateType(Type *Ty)
Mutate the type of this Value to be of the specified type.
const_use_iterator use_end() const
Value * stripPointerCastsForAliasAnalysis()
LLVM_ABI 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.
Value * stripInBoundsConstantOffsets()
const Use * getSingleUndroppableUse() const
user_iterator_impl< User > user_iterator
user_iterator materialized_user_begin()
LLVM_ABI uint64_t getPointerDereferenceableBytes(const DataLayout &DL, bool &CanBeNull, bool &CanBeFreed) const
Returns the number of bytes known to be dereferenceable for the pointer value.
LLVM_ABI void clearMetadata()
Erase all metadata attached to this Value.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
LLVM_ABI void replaceNonMetadataUsesWith(Value *V)
Change non-metadata uses of this to point to a new Value.
Value * stripPointerCastsSameRepresentation()
const_user_iterator materialized_user_begin() const
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
const_user_iterator user_end() const
LLVM_ABI bool hasNUndroppableUses(unsigned N) const
Return true if there this value.
ValueTy
Concrete subclass of this.
LLVM_ABI const Value * stripPointerCastsForAliasAnalysis() const
Strip off pointer casts, all-zero GEPs, single-argument phi nodes and invariant group info.
LLVM_ABI void dump() const
Support for debugging, callable in GDB: V->dump()
const_user_iterator user_begin() const
An efficient, type-erasing, non-owning reference to a callable.
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
NodeAddr< UseNode * > Use
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
StringMapEntry< Value * > ValueName
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
bool hasSingleElement(ContainerTy &&C)
Returns true if the given container only contains a single element.
std::unique_ptr< Value, ValueDeleter > unique_value
Use this instead of std::unique_ptr<Value> or std::unique_ptr<Instruction>.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Attribute unwrap(LLVMAttributeRef Attr)
FunctionAddr VTableAddr Next
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
LLVMAttributeRef wrap(Attribute Attr)
void operator()(Value *V)
static bool doit(const Value &Val)
static bool doit(const Value &Val)
static bool doit(const Value &Val)
static bool doit(const Value &Val)
static bool doit(const Value &Val)
static bool doit(const Value &Val)
static bool doit(const Value &Val)
static bool doit(const Value &Val)
static bool doit(const Value &Val)
static bool doit(const Value &Val)
static bool doit(const Value &Val)
static bool doit(const Value &Val)
static bool doit(const Value &Val)