13#ifndef LLVM_IR_VALUE_H
14#define LLVM_IR_VALUE_H
36class ConstantAggregate;
49class ModuleSlotTracker;
51template<
typename ValueTy>
class StringMapEntry;
76 const unsigned char SubclassID;
77 unsigned char HasValueHandle : 1;
93 unsigned short SubclassData;
120 Use *UseList =
nullptr;
125 template <
typename UseT>
126 class use_iterator_impl {
131 explicit use_iterator_impl(UseT *u) : U(u) {}
134 using iterator_category = std::forward_iterator_tag;
135 using value_type = UseT;
136 using difference_type = std::ptrdiff_t;
137 using pointer = value_type *;
138 using reference = value_type &;
140 use_iterator_impl() : U() {}
142 bool operator==(
const use_iterator_impl &x)
const {
return U == x.U; }
145 use_iterator_impl &operator++() {
146 assert(U &&
"Cannot increment end iterator!");
151 use_iterator_impl operator++(
int) {
158 assert(U &&
"Cannot dereference end iterator!");
162 UseT *operator->()
const {
return &
operator*(); }
164 operator use_iterator_impl<const UseT>()
const {
165 return use_iterator_impl<const UseT>(U);
169 template <
typename UserTy>
170 class user_iterator_impl {
171 use_iterator_impl<Use> UI;
172 explicit user_iterator_impl(Use *U) : UI(
U) {}
176 using iterator_category = std::forward_iterator_tag;
177 using value_type = UserTy *;
178 using difference_type = std::ptrdiff_t;
179 using pointer = value_type *;
180 using reference = value_type &;
182 user_iterator_impl() =
default;
184 bool operator==(
const user_iterator_impl &x)
const {
return UI ==
x.UI; }
188 bool atEnd()
const {
return *
this == user_iterator_impl(); }
190 user_iterator_impl &operator++() {
195 user_iterator_impl operator++(
int) {
203 return UI->getUser();
206 UserTy *operator->()
const {
return operator*(); }
208 operator user_iterator_impl<const UserTy>()
const {
209 return user_iterator_impl<const UserTy>(*UI);
212 Use &getUse()
const {
return *UI; }
239 bool IsForDebug =
false)
const;
250 const Module *M =
nullptr)
const;
267 void destroyValueName();
268 enum class ReplaceMetadataUses {
No,
Yes };
269 void doRAUW(Value *New, ReplaceMetadataUses);
270 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"
658 return const_cast<Value *
>(
668 return const_cast<Value *
>(
679 return const_cast<Value *
>(
static_cast<const Value *
>(
this)
691 return const_cast<Value *
>(
static_cast<const Value *
>(
this)
701 return const_cast<Value *
>(
740 bool AllowInvariantGroup =
false,
743 bool LookThroughIntToPtr =
false)
const;
747 bool AllowInvariantGroup =
false,
750 bool LookThroughIntToPtr =
false) {
751 return const_cast<Value *
>(
753 DL,
Offset, AllowNonInbounds, AllowInvariantGroup, ExternalAnalysis,
754 LookThroughIntToPtr));
777 [](
const Value *) {}) {
778 return const_cast<Value *
>(
804 bool &CanBeFreed)
const;
819 const BasicBlock *PredBB)
const;
821 return const_cast<Value *
>(
846 template <
class Compare>
void sortUseList(Compare Cmp);
860 template <
class Compare>
861 static Use *mergeUseLists(
Use *L,
Use *R, Compare Cmp) {
863 Use **Next = &Merged;
923 if (!UseList || !UseList->Next)
932 const unsigned MaxSlots = 32;
933 Use *Slots[MaxSlots];
936 Use *Next = UseList->Next;
937 UseList->Next =
nullptr;
938 unsigned NumSlots = 1;
944 Next = Current->Next;
947 Current->Next =
nullptr;
951 for (
I = 0;
I < NumSlots; ++
I) {
959 Current = mergeUseLists(Slots[
I], Current, Cmp);
965 assert(NumSlots <= MaxSlots &&
"Use list bigger than 2^32");
973 assert(Next &&
"Expected one more Use");
974 assert(!Next->Next &&
"Expected only one Use");
976 for (
unsigned I = 0;
I < NumSlots; ++
I)
980 UseList = mergeUseLists(Slots[
I], UseList, Cmp);
983 for (
Use *
I = UseList, **Prev = &UseList;
I;
I =
I->Next) {
994 static_assert(Value::ConstantFirstVal == 0,
995 "Val.getValueID() >= Value::ConstantFirstVal");
996 return Val.
getValueID() <= Value::ConstantLastVal;
1002 static_assert(Value::ConstantDataFirstVal == 0,
1003 "Val.getValueID() >= Value::ConstantDataFirstVal");
1004 return Val.
getValueID() <= Value::ConstantDataLastVal;
1010 return Val.
getValueID() >= Value::ConstantAggregateFirstVal &&
1011 Val.
getValueID() <= Value::ConstantAggregateLastVal;
1017 return Val.
getValueID() == Value::ArgumentVal;
1023 return Val.
getValueID() == Value::InlineAsmVal;
1029 return Val.
getValueID() >= Value::InstructionVal;
1035 return Val.
getValueID() == Value::BasicBlockVal;
1041 return Val.
getValueID() == Value::FunctionVal;
1047 return Val.
getValueID() == Value::GlobalVariableVal;
1053 return Val.
getValueID() == Value::GlobalAliasVal;
1059 return Val.
getValueID() == Value::GlobalIFuncVal;
1065 return isa<GlobalObject>(Val) || isa<GlobalAlias>(Val);
1071 return isa<GlobalVariable>(Val) || isa<Function>(Val) ||
1072 isa<GlobalIFunc>(Val);
1081 return reinterpret_cast<Value**
>(Vals);
1091 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.
Machine Check Debug Module
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.
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)
This is the common base class of value handles.
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()
bool hasMetadata(StringRef Kind) const
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
bool hasMetadata() const
Return true if this value has any metadata attached to it.
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
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.
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
LLVM_ABI MDNode * getMetadataImpl(unsigned KindID) const
Get metadata for the given kind, if any.
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 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...
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 void eraseMetadataIf(function_ref< bool(unsigned, MDNode *)> Pred)
Erase all metadata attachments matching the given predicate.
Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB)
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
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.
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.
bool hasMetadata(unsigned KindID) const
Return true if this value has the given type of metadata attached.
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
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
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.
@ BasicBlock
Various leaf nodes.
@ User
could "use" a pointer
NodeAddr< UseNode * > Use
This is an optimization pass for GlobalISel generic memory operations.
std::unique_ptr< Value, ValueDeleter > unique_value
Use this instead of std::unique_ptr<Value> or std::unique_ptr<Instruction>.
APInt operator*(APInt a, uint64_t RHS)
bool operator!=(uint64_t V1, const APInt &V2)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
bool hasSingleElement(ContainerTy &&C)
Returns true if the given container only contains a single element.
Attribute unwrap(LLVMAttributeRef Attr)
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)