13#ifndef LLVM_IR_VALUE_H
14#define LLVM_IR_VALUE_H
35class ConstantAggregate;
48class ModuleSlotTracker;
50template<
typename ValueTy>
class StringMapEntry;
75 const unsigned char SubclassID;
76 unsigned char HasValueHandle : 1;
92 unsigned short SubclassData;
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; }
144 use_iterator_impl &operator++() {
145 assert(U &&
"Cannot increment end iterator!");
150 use_iterator_impl operator++(
int) {
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; }
187 bool atEnd()
const {
return *
this == user_iterator_impl(); }
189 user_iterator_impl &operator++() {
194 user_iterator_impl operator++(
int) {
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);
346 return UseList ==
nullptr;
350 return UseList ==
nullptr;
387 return UseList ==
nullptr;
487 [](
const Use *) {
return true; });
514#define HANDLE_VALUE(Name) Name##Val,
515#include "llvm/IR/Value.def"
518#define HANDLE_CONSTANT_MARKER(Marker, Constant) Marker = Constant##Val,
519#include "llvm/IR/Value.def"
645 return const_cast<Value *
>(
655 return const_cast<Value *
>(
666 return const_cast<Value *
>(
static_cast<const Value *
>(
this)
678 return const_cast<Value *
>(
static_cast<const Value *
>(
this)
688 return const_cast<Value *
>(
723 bool AllowInvariantGroup =
false,
727 bool AllowNonInbounds,
728 bool AllowInvariantGroup =
false) {
729 return const_cast<Value *
>(
731 DL,
Offset, AllowNonInbounds, AllowInvariantGroup));
752 [](
const Value *) {})
const;
754 [](
const Value *) {}) {
755 return const_cast<Value *
>(
762 const DataLayout &
DL)
const;
781 bool &CanBeFreed)
const;
796 const BasicBlock *PredBB)
const;
798 return const_cast<Value *
>(
823 template <
class Compare>
void sortUseList(Compare Cmp);
837 template <
class Compare>
838 static Use *mergeUseLists(
Use *L,
Use *R, Compare Cmp) {
840 Use **Next = &Merged;
883 if (Val) removeFromList();
885 if (V) V->addUse(*
this);
899 if (!UseList || !UseList->Next)
908 const unsigned MaxSlots = 32;
909 Use *Slots[MaxSlots];
912 Use *Next = UseList->Next;
913 UseList->Next =
nullptr;
914 unsigned NumSlots = 1;
920 Next = Current->Next;
923 Current->Next =
nullptr;
927 for (
I = 0;
I < NumSlots; ++
I) {
935 Current = mergeUseLists(Slots[
I], Current, Cmp);
941 assert(NumSlots <= MaxSlots &&
"Use list bigger than 2^32");
949 assert(Next &&
"Expected one more Use");
950 assert(!Next->Next &&
"Expected only one Use");
952 for (
unsigned I = 0;
I < NumSlots; ++
I)
956 UseList = mergeUseLists(Slots[
I], UseList, Cmp);
959 for (
Use *
I = UseList, **Prev = &UseList;
I;
I =
I->Next) {
970 static_assert(Value::ConstantFirstVal == 0,
"Val.getValueID() >= Value::ConstantFirstVal");
971 return Val.
getValueID() <= Value::ConstantLastVal;
977 return Val.
getValueID() >= Value::ConstantDataFirstVal &&
978 Val.
getValueID() <= Value::ConstantDataLastVal;
984 return Val.
getValueID() >= Value::ConstantAggregateFirstVal &&
985 Val.
getValueID() <= Value::ConstantAggregateLastVal;
991 return Val.
getValueID() == Value::ArgumentVal;
997 return Val.
getValueID() == Value::InlineAsmVal;
1003 return Val.
getValueID() >= Value::InstructionVal;
1009 return Val.
getValueID() == Value::BasicBlockVal;
1015 return Val.
getValueID() == Value::FunctionVal;
1021 return Val.
getValueID() == Value::GlobalVariableVal;
1027 return Val.
getValueID() == Value::GlobalAliasVal;
1033 return Val.
getValueID() == Value::GlobalIFuncVal;
1039 return isa<GlobalObject>(Val) || isa<GlobalAlias>(Val);
1045 return isa<GlobalVariable>(Val) || isa<Function>(Val) ||
1046 isa<GlobalIFunc>(Val);
1055 return reinterpret_cast<Value**
>(Vals);
1065 return reinterpret_cast<T**
>(Vals);
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
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.
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()
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)
iterator_range< use_iterator > materialized_uses()
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 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_use_iterator use_begin() const
iterator_range< const_user_iterator > materialized_users() const
void reverseUseList()
Reverse the use-list.
const User * getUniqueUndroppableUser() const
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 assertModuleIsMaterialized() const
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.
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.
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * > > &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
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.
void sortUseList(Compare Cmp)
Sort the use-list.
iterator_range< const_user_iterator > users() const
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()
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
MDNode * getMetadataImpl(unsigned KindID) const
Get metadata for the given kind, if any.
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_iterator materialized_use_begin()
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...
Value(const Value &)=delete
iterator_range< const_use_iterator > materialized_uses() const
use_iterator_impl< Use > use_iterator
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 ...
bool eraseMetadata(unsigned KindID)
Erase all metadata attachments with the given kind.
Value * stripAndAccumulateConstantOffsets(const DataLayout &DL, APInt &Offset, bool AllowNonInbounds, bool AllowInvariantGroup=false)
void addMetadata(unsigned KindID, MDNode &MD)
Add a metadata attachment.
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.
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)
void eraseMetadataIf(function_ref< bool(unsigned, MDNode *)> Pred)
Erase all metadata attachments matching the given predicate.
Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB)
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.
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()
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()
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.
Value * stripPointerCastsSameRepresentation()
const_user_iterator materialized_user_begin() const
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.
bool hasNUndroppableUses(unsigned N) const
Return true if there this value.
ValueTy
Concrete subclass of this.
const Value * stripPointerCastsForAliasAnalysis() const
Strip off pointer casts, all-zero GEPs, single-argument phi nodes and invariant group info.
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)