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;
127 template <
typename UseT>
128 class use_iterator_impl {
133 explicit use_iterator_impl(UseT *u) : U(u) {}
136 using iterator_category = std::forward_iterator_tag;
138 using difference_type = std::ptrdiff_t;
142 use_iterator_impl() : U() {}
144 bool operator==(
const use_iterator_impl &x)
const {
return U == x.U; }
145 bool operator!=(
const use_iterator_impl &x)
const {
return !
operator==(x); }
147 use_iterator_impl &operator++() {
148 assert(U &&
"Cannot increment end iterator!");
153 use_iterator_impl operator++(
int) {
159 UseT &operator*()
const {
160 assert(U &&
"Cannot dereference end iterator!");
164 UseT *operator->()
const {
return &operator*(); }
166 operator use_iterator_impl<const UseT>()
const {
167 return use_iterator_impl<const UseT>(U);
172 template <
typename UserTy>
173 class user_iterator_impl {
174 use_iterator_impl<Use> UI;
188 bool operator==(
const user_iterator_impl &x)
const {
return UI == x.UI; }
240 bool IsForDebug =
false)
const;
251 const Module *M =
nullptr)
const;
268 void destroyValueName();
269 enum class ReplaceMetadataUses {
No,
Yes };
270 void doRAUW(Value *New, ReplaceMetadataUses);
271 void setNameImpl(
const Twine &Name);
495 [](
const Use *) {
return true; });
527#define HANDLE_VALUE(Name) Name##Val,
528#include "llvm/IR/Value.def"
531#define HANDLE_CONSTANT_MARKER(Marker, Constant) Marker = Constant##Val,
532#include "llvm/IR/Value.def"
572 LLVM_ABI unsigned getMetadataIndex()
const;
573 LLVM_ABI unsigned &getMetadataIndex();
627 return const_cast<Value *
>(
628 static_cast<const Value *
>(
this)->stripPointerCasts());
637 return const_cast<Value *
>(
638 static_cast<const Value *
>(
this)->stripPointerCastsAndAliases());
648 return const_cast<Value *
>(
static_cast<const Value *
>(
this)
649 ->stripPointerCastsSameRepresentation());
660 return const_cast<Value *
>(
static_cast<const Value *
>(
this)
661 ->stripPointerCastsForAliasAnalysis());
670 return const_cast<Value *
>(
671 static_cast<const Value *
>(
this)->stripInBoundsConstantOffsets());
710 bool AllowInvariantGroup =
false,
713 bool LookThroughIntToPtr =
false)
const;
717 bool AllowInvariantGroup =
false,
720 bool LookThroughIntToPtr =
false) {
721 return const_cast<Value *
>(
722 static_cast<const Value *
>(
this)->stripAndAccumulateConstantOffsets(
723 DL,
Offset, AllowNonInbounds, AllowInvariantGroup, ExternalAnalysis,
724 LookThroughIntToPtr));
747 [](
const Value *) {}) {
748 return const_cast<Value *
>(
775 bool *CanBeFreed)
const;
790 const BasicBlock *PredBB)
const;
792 return const_cast<Value *
>(
793 static_cast<const Value *
>(
this)->DoPHITranslation(CurBB, PredBB));
817 template <
class Compare>
void sortUseList(Compare Cmp);
831 template <
class Compare>
832 static Use *mergeUseLists(
Use *L,
Use *R, Compare Cmp) {
903 const unsigned MaxSlots = 32;
904 Use *Slots[MaxSlots];
909 unsigned NumSlots = 1;
915 Next = Current->Next;
918 Current->Next =
nullptr;
922 for (
I = 0;
I < NumSlots; ++
I) {
930 Current = mergeUseLists(Slots[
I], Current, Cmp);
936 assert(NumSlots <= MaxSlots &&
"Use list bigger than 2^32");
945 assert(!
Next->Next &&
"Expected only one Use");
947 for (
unsigned I = 0;
I < NumSlots; ++
I)
965 static_assert(Value::ConstantFirstVal == 0,
966 "Val.getValueID() >= Value::ConstantFirstVal");
967 return Val.
getValueID() <= Value::ConstantLastVal;
973 static_assert(Value::ConstantDataFirstVal == 0,
974 "Val.getValueID() >= Value::ConstantDataFirstVal");
975 return Val.
getValueID() <= Value::ConstantDataLastVal;
981 return Val.
getValueID() >= Value::ConstantAggregateFirstVal &&
982 Val.
getValueID() <= Value::ConstantAggregateLastVal;
988 return Val.
getValueID() == Value::ArgumentVal;
994 return Val.
getValueID() == Value::InlineAsmVal;
1000 return Val.
getValueID() >= Value::InstructionVal;
1006 return Val.
getValueID() == Value::BasicBlockVal;
1012 return Val.
getValueID() == Value::FunctionVal;
1018 return Val.
getValueID() == Value::GlobalVariableVal;
1024 return Val.
getValueID() == Value::GlobalAliasVal;
1030 return Val.
getValueID() == Value::GlobalIFuncVal;
1052 return reinterpret_cast<Value**
>(Vals);
1062 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.
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)
std::ptrdiff_t difference_type
bool operator==(const user_iterator_impl &x) const
bool atEnd() const
Returns true if this iterator is equal to user_end() on the value.
UserTy * operator->() const
std::forward_iterator_tag iterator_category
UserTy * operator*() const
user_iterator_impl & operator++()
user_iterator_impl operator++(int)
user_iterator_impl()=default
bool operator!=(const user_iterator_impl &x) const
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 arbitary subclass data.
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.
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.
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 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.
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.
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.
This is an optimization pass for GlobalISel generic memory operations.
StringMapEntry< Value * > ValueName
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
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)
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVMAttributeRef wrap(Attribute Attr)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
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)