13 #ifndef LLVM_IR_VALUE_H 14 #define LLVM_IR_VALUE_H 34 class ConstantAggregate;
39 class GlobalIndirectSymbol;
47 class ModuleSlotTracker;
49 template<
typename ValueTy>
class StringMapEntry;
83 const unsigned char SubclassID;
84 unsigned char HasValueHandle : 1;
100 unsigned short SubclassData;
125 template <
typename UseT>
126 class use_iterator_impl
127 :
public std::iterator<std::forward_iterator_tag, UseT *> {
132 explicit use_iterator_impl(UseT *u) : U(u) {}
135 use_iterator_impl() : U() {}
137 bool operator==(
const use_iterator_impl &x)
const {
return U == x.U; }
140 use_iterator_impl &operator++() {
141 assert(U &&
"Cannot increment end iterator!");
146 use_iterator_impl operator++(
int) {
153 assert(U &&
"Cannot dereference end iterator!");
157 UseT *operator->()
const {
return &
operator*(); }
159 operator use_iterator_impl<const UseT>()
const {
160 return use_iterator_impl<const UseT>(U);
164 template <
typename UserTy>
165 class user_iterator_impl
166 :
public std::iterator<std::forward_iterator_tag, UserTy *> {
167 use_iterator_impl<Use> UI;
168 explicit user_iterator_impl(
Use *U) : UI(U) {}
172 user_iterator_impl() =
default;
174 bool operator==(
const user_iterator_impl &x)
const {
return UI == x.UI; }
178 bool atEnd()
const {
return *
this == user_iterator_impl(); }
180 user_iterator_impl &operator++() {
185 user_iterator_impl operator++(
int) {
193 return UI->getUser();
196 UserTy *operator->()
const {
return operator*(); }
198 operator user_iterator_impl<const UserTy>()
const {
199 return user_iterator_impl<const UserTy>(*UI);
202 Use &getUse()
const {
return *UI; }
229 bool IsForDebug =
false)
const;
240 const Module *M =
nullptr)
const;
257 void destroyValueName();
258 enum class ReplaceMetadataUses {
No,
Yes };
259 void doRAUW(
Value *New, ReplaceMetadataUses);
303 assert(New &&
"Value::replaceUsesWithIf(<null>) is invalid!");
305 "replaceUses of value with new value of different type!");
310 if (!ShouldReplace(U))
345 return UseList ==
nullptr;
349 return UseList ==
nullptr;
386 return UseList ==
nullptr;
435 if (I ==
E)
return false;
466 #define HANDLE_VALUE(Name) Name##Val, 467 #include "llvm/IR/Value.def" 470 #define HANDLE_CONSTANT_MARKER(Marker, Constant) Marker = Constant##Val, 471 #include "llvm/IR/Value.def" 523 return const_cast<Value *
>(
533 return const_cast<Value *
>(
544 return const_cast<Value *
>(
static_cast<const Value *
>(
this)
555 return const_cast<Value *
>(
static_cast<const Value *
>(
this)
565 return const_cast<Value *
>(
592 bool AllowNonInbounds)
const;
594 bool AllowNonInbounds) {
595 return const_cast<Value *
>(
597 DL, Offset, AllowNonInbounds));
603 APInt &Offset)
const {
619 return const_cast<Value *
>(
629 bool &CanBeNull)
const;
646 return const_cast<Value *
>(
685 template <
class Compare>
688 Use **Next = &Merged;
731 if (Val) removeFromList();
747 if (!UseList || !UseList->Next)
756 const unsigned MaxSlots = 32;
757 Use *Slots[MaxSlots];
760 Use *Next = UseList->Next;
761 UseList->Next =
nullptr;
762 unsigned NumSlots = 1;
768 Next = Current->Next;
771 Current->Next =
nullptr;
775 for (I = 0; I < NumSlots; ++
I) {
783 Current = mergeUseLists(Slots[I], Current, Cmp);
789 assert(NumSlots <= MaxSlots &&
"Use list bigger than 2^32");
797 assert(Next &&
"Expected one more Use");
798 assert(!Next->Next &&
"Expected only one Use");
800 for (
unsigned I = 0;
I < NumSlots; ++
I)
804 UseList = mergeUseLists(Slots[I], UseList, Cmp);
807 for (
Use *I = UseList, **Prev = &UseList;
I; I = I->Next) {
818 static_assert(Value::ConstantFirstVal == 0,
"Val.getValueID() >= Value::ConstantFirstVal");
819 return Val.
getValueID() <= Value::ConstantLastVal;
825 return Val.
getValueID() >= Value::ConstantDataFirstVal &&
826 Val.
getValueID() <= Value::ConstantDataLastVal;
832 return Val.
getValueID() >= Value::ConstantAggregateFirstVal &&
833 Val.
getValueID() <= Value::ConstantAggregateLastVal;
839 return Val.
getValueID() == Value::ArgumentVal;
845 return Val.
getValueID() == Value::InlineAsmVal;
851 return Val.
getValueID() >= Value::InstructionVal;
857 return Val.
getValueID() == Value::BasicBlockVal;
863 return Val.
getValueID() == Value::FunctionVal;
869 return Val.
getValueID() == Value::GlobalVariableVal;
875 return Val.
getValueID() == Value::GlobalAliasVal;
881 return Val.
getValueID() == Value::GlobalIFuncVal;
887 return isa<GlobalAlias>(Val) || isa<GlobalIFunc>(Val);
893 return isa<GlobalObject>(Val) || isa<GlobalIndirectSymbol>(Val);
899 return isa<GlobalVariable>(Val) || isa<Function>(Val);
908 return reinterpret_cast<Value**
>(Vals);
918 return reinterpret_cast<T**
>(Vals);
927 #endif // LLVM_IR_VALUE_H This is the common base class of value handles.
unsigned short getSubclassDataFromValue() const
void sortUseList(Compare Cmp)
Sort the use-list.
A parsed version of the target data layout string in and methods for querying it. ...
iterator_range< use_iterator > uses()
void operator()(Value *V)
This class represents an incoming formal argument to a Function.
unsigned getValueID() const
Return an ID for the concrete type of this object.
const Value * stripInBoundsOffsets() const
Strip off pointer casts and inbounds GEPs.
static bool doit(const Value &Val)
This class represents lattice values for constants.
void addUse(Use &U)
This method should only be used by the Use class.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
A Module instance is used to store all the information related to an LLVM module. ...
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
const Value * stripPointerCastsAndAliases() const
Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
use_iterator materialized_use_begin()
bool hasValueHandle() const
Return true if there is a value handle associated with this value.
An efficient, type-erasing, non-owning reference to a callable.
iterator_range< const_user_iterator > users() const
LLVMContext & getContext() const
All values hold a context through their type.
static bool doit(const Value &Val)
void deleteValue()
Delete a pointer to a generic Value.
Manage lifetime of a slot tracker for printing IR.
This defines the Use class.
use_iterator_impl< const Use > const_use_iterator
const Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB) const
Translate PHI node to its predecessor from the given basic block.
iterator_range< user_iterator > materialized_users()
void dump() const
Support for debugging, callable in GDB: V->dump()
const_user_iterator materialized_user_begin() const
iterator_range< const_user_iterator > materialized_users() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Attribute unwrap(LLVMAttributeRef Attr)
A Use represents the edge between a Value definition and its users.
void setName(const Twine &Name)
Change the name of the value.
void assertModuleIsMaterializedImpl() const
static bool doit(const Value &Val)
static const unsigned MaximumAlignment
#define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref)
APInt operator*(APInt a, uint64_t RHS)
static bool doit(const Value &Val)
Value * stripInBoundsOffsets()
Type * getType() const
All values are typed, get the type of this value.
iterator_range< const_use_iterator > materialized_uses() const
bool isSwiftError() const
Return true if this value is a swifterror value.
static bool doit(const Value &Val)
const_use_iterator use_end() const
const_use_iterator materialized_use_begin() const
const Value * stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL, APInt &Offset) const
This is a wrapper around stripAndAccumulateConstantOffsets with the in-bounds requirement set to fals...
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
void takeName(Value *V)
Transfer the name from V to this value.
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...
use_iterator_impl< Use > use_iterator
unsigned getRawSubclassOptionalData() const
Return the raw optional flags value contained in this value.
const_use_iterator use_begin() const
bool hasNUsesOrMore(unsigned N) const
Return true if this value has N users or more.
bool hasNUses(unsigned N) const
Return true if this Value has exactly N users.
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
void replaceNonMetadataUsesWith(Value *V)
Change non-metadata uses of this to point to a new Value.
MaybeAlign getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
iterator_range< use_iterator > materialized_uses()
bool isUsedInBasicBlock(const BasicBlock *BB) const
Check if this value is used in the specified basic block.
bool hasSameSubclassOptionalData(const Value *V) const
Check the optional flags for equality.
static bool doit(const Value &Val)
Value * stripPointerCastsAndInvariantGroups()
void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
Value * stripInBoundsConstantOffsets()
const Value * stripPointerCastsSameRepresentation() const
Strip off pointer casts, all-zero GEPs and address space casts but ensures the representation of the ...
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Value(Type *Ty, unsigned scid)
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.
Value * stripPointerCasts()
Value & operator=(const Value &)=delete
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
static const unsigned MaxAlignmentExponent
The maximum alignment for instructions.
bool materialized_use_empty() const
void assertModuleIsMaterialized() const
static bool doit(const Value &Val)
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
ValueName * getValueName() const
const User * user_back() const
std::unique_ptr< Value, ValueDeleter > unique_value
Use this instead of std::unique_ptr<Value> or std::unique_ptr<Instruction>.
uint64_t getPointerDereferenceableBytes(const DataLayout &DL, bool &CanBeNull) const
Returns the number of bytes known to be dereferenceable for the pointer value.
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
const Value * stripPointerCastsAndInvariantGroups() const
Strip off pointer casts, all-zero GEPs and invariant group info.
ValueTy
Concrete subclass of this.
void setValueSubclassData(unsigned short D)
bool isUsedByMetadata() const
Return true if there is metadata referencing this value.
A range adaptor for a pair of iterators.
Class for arbitrary precision integers.
const_user_iterator user_begin() const
iterator_range< user_iterator > users()
user_iterator_impl< const User > const_user_iterator
Value * stripPointerCastsAndAliases()
const Value * stripAndAccumulateConstantOffsets(const DataLayout &DL, APInt &Offset, bool AllowNonInbounds) const
Accumulate the constant offset this value has compared to a base pointer.
void reverseUseList()
Reverse the use-list.
iterator_range< const_use_iterator > uses() const
bool operator!=(uint64_t V1, const APInt &V2)
unsigned getNumUses() const
This method computes the number of uses of this Value.
LLVMAttributeRef wrap(Attribute Attr)
static bool doit(const Value &Val)
StringRef getName() const
Return a constant reference to the value's name.
user_iterator_impl< User > user_iterator
Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB)
static bool doit(const Value &Val)
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
void mutateType(Type *Ty)
Mutate the type of this Value to be of the specified type.
~Value()
Value's destructor should be virtual by design, but that would require that Value and all of its subc...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Value * stripPointerCastsSameRepresentation()
user_iterator user_begin()
Value * stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL, APInt &Offset)
Base class for aggregate constants (with operands).
LLVM Value Representation.
const_user_iterator user_end() const
void clearSubclassOptionalData()
Clear the optional flags contained in this value.
static bool doit(const Value &Val)
Value * stripAndAccumulateConstantOffsets(const DataLayout &DL, APInt &Offset, bool AllowNonInbounds)
This class implements an extremely fast bulk output stream that can only output to a stream...
user_iterator materialized_user_begin()
void setValueName(ValueName *VN)
static bool doit(const Value &Val)
bool hasOneUse() const
Return true if there is exactly one user of this value.
StringRef - Represent a constant reference to a string, i.e.
static bool doit(const Value &Val)
void replaceUsesOutsideBlock(Value *V, BasicBlock *BB)
replaceUsesOutsideBlock - Go through the uses list for this definition and make each use point to "V"...
bool operator==(uint64_t V1, const APInt &V2)
const Value * stripInBoundsConstantOffsets() const
Strip off pointer casts and all-constant inbounds GEPs.
Base class for constants with no operands.
Value * operator=(Value *RHS)
static bool doit(const Value &Val)
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
static bool doit(const Value &Val)