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; }
228 bool IsForDebug =
false)
const;
239 const Module *M =
nullptr)
const;
256 void destroyValueName();
257 enum class ReplaceMetadataUses {
No,
Yes };
258 void doRAUW(
Value *New, ReplaceMetadataUses);
325 return UseList ==
nullptr;
329 return UseList ==
nullptr;
366 return UseList ==
nullptr;
415 if (I ==
E)
return false;
446 #define HANDLE_VALUE(Name) Name##Val, 447 #include "llvm/IR/Value.def" 450 #define HANDLE_CONSTANT_MARKER(Marker, Constant) Marker = Constant##Val, 451 #include "llvm/IR/Value.def" 503 return const_cast<Value *
>(
515 return const_cast<Value *
>(
525 return const_cast<Value *
>(
535 return const_cast<Value *
>(
550 return const_cast<Value *
>(
static_cast<const Value *
>(
this)
560 return const_cast<Value *
>(
570 bool &CanBeNull)
const;
587 return const_cast<Value *
>(
626 template <
class Compare>
629 Use **Next = &Merged;
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 static_assert(Value::ConstantFirstVal == 0,
"Val.getValueID() >= Value::ConstantFirstVal");
760 return Val.
getValueID() <= Value::ConstantLastVal;
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 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. ...
Type
MessagePack types as defined in the standard, with the exception of Integer being divided into a sign...
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. ...
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
use_iterator materialized_use_begin()
bool hasValueHandle() const
Return true if there is a value handle associated with this value.
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.
unsigned getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
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
amdgpu Simplify well known AMD library false Value Value const Twine & Name
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
Value * stripPointerCastsNoFollowAliases()
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.
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.
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 * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
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)
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, aliases 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.
const Value * stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL, APInt &Offset) const
Accumulate offsets from stripInBoundsConstantOffsets().
Class for arbitrary precision integers.
const_user_iterator user_begin() const
iterator_range< user_iterator > users()
user_iterator_impl< const User > const_user_iterator
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)
const Value * stripPointerCastsNoFollowAliases() const
Strip off pointer casts and all-zero GEPs.
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())
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)
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)