14 #ifndef LLVM_IR_VALUE_H
15 #define LLVM_IR_VALUE_H
32 class ConstantAggregate;
37 class GlobalIndirectSymbol;
45 class ModuleSlotTracker;
78 const unsigned char SubclassID;
79 unsigned char HasValueHandle : 1;
95 unsigned short SubclassData;
120 template <
typename UseT>
121 class use_iterator_impl
122 :
public std::iterator<std::forward_iterator_tag, UseT *> {
124 explicit use_iterator_impl(UseT *u) : U(u) {}
128 use_iterator_impl() : U() {}
130 bool operator==(
const use_iterator_impl &x)
const {
return U == x.U; }
133 use_iterator_impl &operator++() {
134 assert(U &&
"Cannot increment end iterator!");
139 use_iterator_impl operator++(
int) {
146 assert(U &&
"Cannot dereference end iterator!");
150 UseT *operator->()
const {
return &
operator*(); }
152 operator use_iterator_impl<const UseT>()
const {
153 return use_iterator_impl<const UseT>(U);
157 template <
typename UserTy>
158 class user_iterator_impl
159 :
public std::iterator<std::forward_iterator_tag, UserTy *> {
160 use_iterator_impl<Use> UI;
161 explicit user_iterator_impl(
Use *U) : UI(U) {}
165 user_iterator_impl() =
default;
167 bool operator==(
const user_iterator_impl &x)
const {
return UI == x.UI; }
171 bool atEnd()
const {
return *
this == user_iterator_impl(); }
173 user_iterator_impl &operator++() {
178 user_iterator_impl operator++(
int) {
186 return UI->getUser();
189 UserTy *operator->()
const {
return operator*(); }
191 operator user_iterator_impl<const UserTy>()
const {
192 return user_iterator_impl<const UserTy>(*UI);
195 Use &getUse()
const {
return *UI; }
211 void print(raw_ostream &O,
bool IsForDebug =
false)
const;
212 void print(raw_ostream &O, ModuleSlotTracker &MST,
213 bool IsForDebug =
false)
const;
224 const Module *M =
nullptr)
const;
226 ModuleSlotTracker &MST)
const;
241 void destroyValueName();
242 void doRAUW(
Value *New,
bool NoMetadata);
301 return UseList ==
nullptr;
337 return UseList ==
nullptr;
385 if (I ==
E)
return false;
416 #define HANDLE_VALUE(Name) Name##Val,
417 #include "llvm/IR/Value.def"
420 #define HANDLE_CONSTANT_MARKER(Marker, Constant) Marker = Constant##Val,
421 #include "llvm/IR/Value.def"
505 return const_cast<Value *
>(
this)
524 bool &CanBeNull)
const;
580 template <
class Compare>
583 Use **Next = &Merged;
611 template <
class Compare>
612 static void mergeUseListsImpl(Use *L, Use *R, Use **Next,
Compare Cmp);
625 if (Val) removeFromList();
641 if (!UseList || !UseList->Next)
650 const unsigned MaxSlots = 32;
651 Use *Slots[MaxSlots];
654 Use *Next = UseList->Next;
655 UseList->Next =
nullptr;
656 unsigned NumSlots = 1;
662 Next = Current->Next;
665 Current->Next =
nullptr;
669 for (I = 0; I < NumSlots; ++
I) {
677 Current = mergeUseLists(Slots[I], Current, Cmp);
683 assert(NumSlots <= MaxSlots &&
"Use list bigger than 2^32");
691 assert(Next &&
"Expected one more Use");
692 assert(!Next->Next &&
"Expected only one Use");
694 for (
unsigned I = 0;
I < NumSlots; ++
I)
698 UseList = mergeUseLists(Slots[I], UseList, Cmp);
701 for (
Use *I = UseList, **Prev = &UseList;
I; I = I->Next) {
712 return Val.
getValueID() >= Value::ConstantFirstVal &&
719 return Val.
getValueID() >= Value::ConstantDataFirstVal &&
720 Val.
getValueID() <= Value::ConstantDataLastVal;
726 return Val.
getValueID() >= Value::ConstantAggregateFirstVal &&
727 Val.
getValueID() <= Value::ConstantAggregateLastVal;
733 return Val.
getValueID() == Value::ArgumentVal;
739 return Val.
getValueID() == Value::InlineAsmVal;
745 return Val.
getValueID() >= Value::InstructionVal;
751 return Val.
getValueID() == Value::BasicBlockVal;
757 return Val.
getValueID() == Value::FunctionVal;
763 return Val.
getValueID() == Value::GlobalVariableVal;
769 return Val.
getValueID() == Value::GlobalAliasVal;
775 return Val.
getValueID() == Value::GlobalIFuncVal;
781 return isa<GlobalAlias>(Val) || isa<GlobalIFunc>(Val);
787 return isa<GlobalObject>(Val) || isa<GlobalIndirectSymbol>(Val);
793 return isa<GlobalVariable>(Val) || isa<Function>(Val);
812 return reinterpret_cast<T**
>(
Vals);
821 #endif // LLVM_IR_VALUE_H
This is the common base class of value handles.
void sortUseList(Compare Cmp)
Sort the use-list.
use_iterator_impl< Use > use_iterator
A parsed version of the target data layout string in and methods for querying it. ...
Value * stripInBoundsConstantOffsets()
Strip off pointer casts and all-constant inbounds GEPs.
iterator_range< use_iterator > uses()
LLVM Argument representation.
static bool doit(const Value &Val)
const Value * stripInBoundsConstantOffsets() const
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.
const Value * stripPointerCastsNoFollowAliases() const
bool hasNUses(unsigned N) const
Return true if this Value has exactly N users.
iterator_range< const_user_iterator > materialized_users() const
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
use_iterator materialized_use_begin()
static bool doit(const Value &Val)
const_user_iterator user_begin() const
This defines the Use class.
const_use_iterator use_begin() const
const Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB) const
iterator_range< user_iterator > materialized_users()
StringRef getName() const
Return a constant reference to the value's name.
unsigned getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Attribute unwrap(LLVMAttributeRef Attr)
void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
A Use represents the edge between a Value definition and its users.
const_use_iterator materialized_use_begin() const
static GCRegistry::Add< StatepointGC > D("statepoint-example","an example strategy for statepoint")
void setName(const Twine &Name)
Change the name of the value.
static bool doit(const Value &Val)
static const unsigned MaximumAlignment
Value * stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL, APInt &Offset)
Accumulate offsets from stripInBoundsConstantOffsets().
#define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref)
static bool doit(const Value &Val)
user_iterator_impl< User > user_iterator
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.
static bool doit(const Value &Val)
iterator_range< const_use_iterator > uses() const
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.
ValueName * getValueName() const
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
Value * stripPointerCastsNoFollowAliases()
Strip off pointer casts and all-zero GEPs.
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.
This is an important base class in LLVM.
void replaceNonMetadataUsesWith(Value *V)
Change non-metadata uses of this to point to a new Value.
Value * stripInBoundsOffsets()
Strip off pointer casts and inbounds GEPs.
iterator_range< use_iterator > materialized_uses()
bool isUsedByMetadata() const
Return true if there is metadata referencing this value.
static bool doit(const Value &Val)
unsigned getValueID() const
Return an ID for the concrete type of this object.
bool hasValueHandle() const
Return true if there is a value handle associated with this value.
BlockMass operator*(BlockMass L, BranchProbability R)
iterator_range< const_user_iterator > users() const
Value(Type *Ty, unsigned scid)
LLVMContext & getContext() const
All values hold a context through their type.
use_iterator_impl< const Use > const_use_iterator
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.
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
void operator=(const Value &)=delete
void dump() const
Support for debugging, callable in GDB: V->dump()
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
const User * user_back() const
static const unsigned MaxAlignmentExponent
The maximum alignment for instructions.
static bool doit(const Value &Val)
Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB)
Translate PHI node to its predecessor from the given basic block.
const_user_iterator materialized_user_begin() const
Type * getType() const
All values are typed, get the type of this value.
bool isSwiftError() const
Return true if this value is a swifterror value.
Value * stripPointerCasts()
Strip off pointer casts, all-zero GEPs, and aliases.
ValueTy
Concrete subclass of this.
void setValueSubclassData(unsigned short D)
const Value * stripInBoundsOffsets() const
A range adaptor for a pair of iterators.
Class for arbitrary precision integers.
iterator_range< user_iterator > users()
void reverseUseList()
Reverse the use-list.
const Value * stripPointerCasts() const
bool operator!=(uint64_t V1, const APInt &V2)
void assertModuleIsMaterialized() const
user_iterator_impl< const User > const_user_iterator
LLVMAttributeRef wrap(Attribute Attr)
unsigned short getSubclassDataFromValue() const
unsigned getPointerDereferenceableBytes(const DataLayout &DL, bool &CanBeNull) const
Returns the number of bytes known to be dereferenceable for the pointer value.
static bool doit(const Value &Val)
unsigned getRawSubclassOptionalData() const
Return the raw optional flags value contained in this value.
bool hasOneUse() const
Return true if there is exactly one user of this value.
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.
bool hasNUsesOrMore(unsigned N) const
Return true if this value has N users or more.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
user_iterator user_begin()
Base class for aggregate constants (with operands).
StringMapEntry< Value * > ValueName
iterator_range< const_use_iterator > materialized_uses() const
LLVM Value Representation.
void clearSubclassOptionalData()
Clear the optional flags contained in this value.
static bool doit(const Value &Val)
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)
StringRef - Represent a constant reference to a string, i.e.
const_use_iterator use_end() const
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)
unsigned getNumUses() const
This method computes the number of uses of this Value.
Base class for constants with no operands.
const_user_iterator user_end() const
Value * operator=(Value *RHS)
static bool doit(const Value &Val)
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
const Value * stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL, APInt &Offset) const
static bool doit(const Value &Val)