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 void doRAUW(
Value *New,
bool NoMetadata);
324 return UseList ==
nullptr;
328 return UseList ==
nullptr;
365 return UseList ==
nullptr;
414 if (I ==
E)
return false;
445 #define HANDLE_VALUE(Name) Name##Val, 446 #include "llvm/IR/Value.def" 449 #define HANDLE_CONSTANT_MARKER(Marker, Constant) Marker = Constant##Val, 450 #include "llvm/IR/Value.def" 502 return const_cast<Value *
>(
514 return const_cast<Value *
>(
524 return const_cast<Value *
>(
534 return const_cast<Value *
>(
549 return const_cast<Value *
>(
static_cast<const Value *
>(
this)
559 return const_cast<Value *
>(
569 bool &CanBeNull)
const;
586 return const_cast<Value *
>(
625 template <
class Compare>
628 Use **Next = &Merged;
671 if (Val) removeFromList();
687 if (!UseList || !UseList->Next)
696 const unsigned MaxSlots = 32;
697 Use *Slots[MaxSlots];
700 Use *Next = UseList->Next;
701 UseList->Next =
nullptr;
702 unsigned NumSlots = 1;
708 Next = Current->Next;
711 Current->Next =
nullptr;
715 for (I = 0; I < NumSlots; ++
I) {
723 Current = mergeUseLists(Slots[I], Current, Cmp);
729 assert(NumSlots <= MaxSlots &&
"Use list bigger than 2^32");
737 assert(Next &&
"Expected one more Use");
738 assert(!Next->Next &&
"Expected only one Use");
740 for (
unsigned I = 0;
I < NumSlots; ++
I)
744 UseList = mergeUseLists(Slots[I], UseList, Cmp);
747 for (
Use *I = UseList, **Prev = &UseList;
I; I = I->Next) {
758 static_assert(Value::ConstantFirstVal == 0,
"Val.getValueID() >= Value::ConstantFirstVal");
759 return Val.
getValueID() <= Value::ConstantLastVal;
765 return Val.
getValueID() >= Value::ConstantDataFirstVal &&
766 Val.
getValueID() <= Value::ConstantDataLastVal;
772 return Val.
getValueID() >= Value::ConstantAggregateFirstVal &&
773 Val.
getValueID() <= Value::ConstantAggregateLastVal;
779 return Val.
getValueID() == Value::ArgumentVal;
785 return Val.
getValueID() == Value::InlineAsmVal;
791 return Val.
getValueID() >= Value::InstructionVal;
797 return Val.
getValueID() == Value::BasicBlockVal;
803 return Val.
getValueID() == Value::FunctionVal;
809 return Val.
getValueID() == Value::GlobalVariableVal;
815 return Val.
getValueID() == Value::GlobalAliasVal;
821 return Val.
getValueID() == Value::GlobalIFuncVal;
827 return isa<GlobalAlias>(Val) || isa<GlobalIFunc>(Val);
833 return isa<GlobalObject>(Val) || isa<GlobalIndirectSymbol>(Val);
839 return isa<GlobalVariable>(Val) || isa<Function>(Val);
848 return reinterpret_cast<Value**
>(Vals);
858 return reinterpret_cast<T**
>(Vals);
867 #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)
Compute iterated dominance frontiers using a linear time algorithm.
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
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)