14 #ifndef LLVM_IR_VALUE_H
15 #define LLVM_IR_VALUE_H
33 class ConstantAggregate;
38 class GlobalIndirectSymbol;
46 class ModuleSlotTracker;
48 template<
typename ValueTy>
class StringMapEntry;
82 const unsigned char SubclassID;
83 unsigned char HasValueHandle : 1;
99 unsigned short SubclassData;
124 template <
typename UseT>
125 class use_iterator_impl
126 :
public std::iterator<std::forward_iterator_tag, UseT *> {
131 explicit use_iterator_impl(UseT *u) : U(u) {}
134 use_iterator_impl() : U() {}
136 bool operator==(
const use_iterator_impl &x)
const {
return U == x.U; }
139 use_iterator_impl &operator++() {
140 assert(U &&
"Cannot increment end iterator!");
145 use_iterator_impl operator++(
int) {
152 assert(U &&
"Cannot dereference end iterator!");
156 UseT *operator->()
const {
return &
operator*(); }
158 operator use_iterator_impl<const UseT>()
const {
159 return use_iterator_impl<const UseT>(U);
163 template <
typename UserTy>
164 class user_iterator_impl
165 :
public std::iterator<std::forward_iterator_tag, UserTy *> {
166 use_iterator_impl<Use> UI;
167 explicit user_iterator_impl(
Use *U) : UI(U) {}
171 user_iterator_impl() =
default;
173 bool operator==(
const user_iterator_impl &x)
const {
return UI == x.UI; }
177 bool atEnd()
const {
return *
this == user_iterator_impl(); }
179 user_iterator_impl &operator++() {
184 user_iterator_impl operator++(
int) {
192 return UI->getUser();
195 UserTy *operator->()
const {
return operator*(); }
197 operator user_iterator_impl<const UserTy>()
const {
198 return user_iterator_impl<const UserTy>(*UI);
201 Use &getUse()
const {
return *UI; }
226 void print(raw_ostream &O,
bool IsForDebug =
false)
const;
227 void print(raw_ostream &O, ModuleSlotTracker &MST,
228 bool IsForDebug =
false)
const;
239 const Module *M =
nullptr)
const;
241 ModuleSlotTracker &MST)
const;
256 void destroyValueName();
257 void doRAUW(
Value *New,
bool NoMetadata);
324 return UseList ==
nullptr;
361 return UseList ==
nullptr;
410 if (I ==
E)
return false;
441 #define HANDLE_VALUE(Name) Name##Val,
442 #include "llvm/IR/Value.def"
445 #define HANDLE_CONSTANT_MARKER(Marker, Constant) Marker = Constant##Val,
446 #include "llvm/IR/Value.def"
498 return const_cast<Value *
>(
509 return const_cast<Value *
>(
519 return const_cast<Value *
>(
529 return const_cast<Value *
>(
544 return const_cast<Value *
>(
static_cast<const Value *
>(
this)
554 return const_cast<Value *
>(
564 bool &CanBeNull)
const;
581 return const_cast<Value *
>(
620 template <
class Compare>
623 Use **Next = &Merged;
651 template <
class Compare>
652 static void mergeUseListsImpl(Use *L, Use *R, Use **Next,
Compare Cmp);
672 if (Val) removeFromList();
688 if (!UseList || !UseList->Next)
697 const unsigned MaxSlots = 32;
698 Use *Slots[MaxSlots];
701 Use *Next = UseList->Next;
702 UseList->Next =
nullptr;
703 unsigned NumSlots = 1;
709 Next = Current->Next;
712 Current->Next =
nullptr;
716 for (I = 0; I < NumSlots; ++
I) {
724 Current = mergeUseLists(Slots[I], Current, Cmp);
730 assert(NumSlots <= MaxSlots &&
"Use list bigger than 2^32");
738 assert(Next &&
"Expected one more Use");
739 assert(!Next->Next &&
"Expected only one Use");
741 for (
unsigned I = 0;
I < NumSlots; ++
I)
745 UseList = mergeUseLists(Slots[I], UseList, Cmp);
748 for (
Use *I = UseList, **Prev = &UseList;
I; I = I->Next) {
759 return Val.
getValueID() >= Value::ConstantFirstVal &&
766 return Val.
getValueID() >= Value::ConstantDataFirstVal &&
767 Val.
getValueID() <= Value::ConstantDataLastVal;
773 return Val.
getValueID() >= Value::ConstantAggregateFirstVal &&
774 Val.
getValueID() <= Value::ConstantAggregateLastVal;
780 return Val.
getValueID() == Value::ArgumentVal;
786 return Val.
getValueID() == Value::InlineAsmVal;
792 return Val.
getValueID() >= Value::InstructionVal;
798 return Val.
getValueID() == Value::BasicBlockVal;
804 return Val.
getValueID() == Value::FunctionVal;
810 return Val.
getValueID() == Value::GlobalVariableVal;
816 return Val.
getValueID() == Value::GlobalAliasVal;
822 return Val.
getValueID() == Value::GlobalIFuncVal;
828 return isa<GlobalAlias>(Val) || isa<GlobalIFunc>(Val);
834 return isa<GlobalObject>(Val) || isa<GlobalIndirectSymbol>(Val);
840 return isa<GlobalVariable>(Val) || isa<Function>(Val);
849 return reinterpret_cast<Value**
>(Vals);
859 return reinterpret_cast<T**
>(Vals);
868 #endif // LLVM_IR_VALUE_H
const Value * stripPointerCastsNoFollowAliases() const
Strip off pointer casts and all-zero GEPs.
This is the common base class of value handles.
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.
static bool doit(const Value &Val)
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 * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
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()
void assertModuleIsMaterialized() const
static bool doit(const Value &Val)
void deleteValue()
Delete a pointer to a generic Value.
const_user_iterator user_begin() const
This defines the Use class.
use_iterator_impl< const Use > const_use_iterator
const Value * stripInBoundsOffsets() const
Strip off pointer casts and inbounds GEPs.
const_use_iterator use_begin() 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)
const Value * stripPointerCastsAndBarriers() const
Strip off pointer casts, all-zero GEPs, aliases and barriers.
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
void setName(const Twine &Name)
Change the name of the value.
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()
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)
Value * stripPointerCastsNoFollowAliases()
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
use_iterator_impl< Use > use_iterator
void assertModuleIsMaterializedImpl() const
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.
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.
Value * stripInBoundsConstantOffsets()
iterator_range< const_user_iterator > users() const
Value(Type *Ty, unsigned scid)
LLVMContext & getContext() const
All values hold a context through their type.
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.
Value * stripPointerCasts()
Value & operator=(const Value &)=delete
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
void dump() const
Support for debugging, callable in GDB: V->dump()
const Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB) const
Translate PHI node to its predecessor from the given basic block.
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)
const_user_iterator materialized_user_begin() const
Type * getType() const
All values are typed, get the type of this value.
std::unique_ptr< Value, ValueDeleter > unique_value
Use this instead of std::unique_ptr<Value> or std::unique_ptr<Instruction>.
bool isSwiftError() const
Return true if this value is a swifterror value.
ValueTy
Concrete subclass of this.
void setValueSubclassData(unsigned short D)
A range adaptor for a pair of iterators.
Class for arbitrary precision integers.
iterator_range< user_iterator > users()
user_iterator_impl< const User > const_user_iterator
void reverseUseList()
Reverse the use-list.
bool operator!=(uint64_t V1, const APInt &V2)
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.
user_iterator_impl< User > user_iterator
const Value * stripInBoundsConstantOffsets() const
Strip off pointer casts and all-constant inbounds GEPs.
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.
bool hasNUsesOrMore(unsigned N) const
Return true if this value has N users or more.
~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())
user_iterator user_begin()
Value * stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL, APInt &Offset)
Base class for aggregate constants (with operands).
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)
Value * stripPointerCastsAndBarriers()
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)
const Value * stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL, APInt &Offset) const
Accumulate offsets from stripInBoundsConstantOffsets().
static bool doit(const Value &Val)
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
static bool doit(const Value &Val)