Go to the documentation of this file.
13 #ifndef LLVM_IR_VALUE_H
14 #define LLVM_IR_VALUE_H
35 class ConstantAggregate;
48 class ModuleSlotTracker;
50 template<
typename ValueTy>
class StringMapEntry;
81 const unsigned char SubclassID;
82 unsigned char HasValueHandle : 1;
98 unsigned short SubclassData;
124 template <
typename UseT>
125 class use_iterator_impl {
130 explicit use_iterator_impl(UseT *u) : U(u) {}
133 using iterator_category = std::forward_iterator_tag;
134 using value_type = UseT *;
135 using difference_type = std::ptrdiff_t;
137 using reference = value_type &;
139 use_iterator_impl() : U() {}
141 bool operator==(
const use_iterator_impl &
x)
const {
return U ==
x.U; }
144 use_iterator_impl &operator++() {
145 assert(U &&
"Cannot increment end iterator!");
150 use_iterator_impl operator++(
int) {
157 assert(U &&
"Cannot dereference end iterator!");
161 UseT *operator->()
const {
return &
operator*(); }
163 operator use_iterator_impl<const UseT>()
const {
164 return use_iterator_impl<const UseT>(U);
168 template <
typename UserTy>
169 class user_iterator_impl {
170 use_iterator_impl<Use> UI;
171 explicit user_iterator_impl(
Use *U) : UI(U) {}
175 using iterator_category = std::forward_iterator_tag;
176 using value_type = UserTy *;
177 using difference_type = std::ptrdiff_t;
179 using reference = value_type &;
181 user_iterator_impl() =
default;
183 bool operator==(
const user_iterator_impl &
x)
const {
return UI ==
x.UI; }
187 bool atEnd()
const {
return *
this == user_iterator_impl(); }
189 user_iterator_impl &operator++() {
194 user_iterator_impl operator++(
int) {
202 return UI->getUser();
205 UserTy *operator->()
const {
return operator*(); }
207 operator user_iterator_impl<const UserTy>()
const {
208 return user_iterator_impl<const UserTy>(*UI);
211 Use &getUse()
const {
return *UI; }
236 void print(raw_ostream &
O,
bool IsForDebug =
false)
const;
237 void print(raw_ostream &
O, ModuleSlotTracker &MST,
238 bool IsForDebug =
false)
const;
249 const Module *
M =
nullptr)
const;
251 ModuleSlotTracker &MST)
const;
266 void destroyValueName();
267 enum class ReplaceMetadataUses {
No,
Yes };
268 void doRAUW(
Value *New, ReplaceMetadataUses);
269 void setNameImpl(
const Twine &
Name);
346 return UseList ==
nullptr;
350 return UseList ==
nullptr;
387 return UseList ==
nullptr;
487 [](
const Use *) {
return true; });
514 #define HANDLE_VALUE(Name) Name##Val,
515 #include "llvm/IR/Value.def"
518 #define HANDLE_CONSTANT_MARKER(Marker, Constant) Marker = Constant##Val,
519 #include "llvm/IR/Value.def"
636 return const_cast<Value *
>(
646 return const_cast<Value *
>(
657 return const_cast<Value *
>(
static_cast<const Value *
>(
this)
669 return const_cast<Value *
>(
static_cast<const Value *
>(
this)
679 return const_cast<Value *
>(
714 bool AllowInvariantGroup =
false,
718 bool AllowNonInbounds,
719 bool AllowInvariantGroup =
false) {
720 return const_cast<Value *
>(
722 DL, Offset, AllowNonInbounds, AllowInvariantGroup));
728 APInt &Offset)
const {
743 [](
const Value *) {})
const;
745 [](
const Value *) {}) {
746 return const_cast<Value *
>(
767 bool &CanBeFreed)
const;
784 return const_cast<Value *
>(
823 template <
class Compare>
826 Use **Next = &Merged;
869 if (Val) removeFromList();
885 if (!UseList || !UseList->Next)
894 const unsigned MaxSlots = 32;
895 Use *Slots[MaxSlots];
898 Use *Next = UseList->Next;
899 UseList->Next =
nullptr;
900 unsigned NumSlots = 1;
906 Next = Current->Next;
909 Current->Next =
nullptr;
913 for (
I = 0;
I < NumSlots; ++
I) {
921 Current = mergeUseLists(Slots[
I], Current, Cmp);
927 assert(NumSlots <= MaxSlots &&
"Use list bigger than 2^32");
935 assert(Next &&
"Expected one more Use");
936 assert(!Next->Next &&
"Expected only one Use");
938 for (
unsigned I = 0;
I < NumSlots; ++
I)
942 UseList = mergeUseLists(Slots[
I], UseList, Cmp);
945 for (
Use *
I = UseList, **Prev = &UseList;
I;
I =
I->Next) {
956 static_assert(Value::ConstantFirstVal == 0,
"Val.getValueID() >= Value::ConstantFirstVal");
957 return Val.
getValueID() <= Value::ConstantLastVal;
963 return Val.
getValueID() >= Value::ConstantDataFirstVal &&
964 Val.
getValueID() <= Value::ConstantDataLastVal;
970 return Val.
getValueID() >= Value::ConstantAggregateFirstVal &&
971 Val.
getValueID() <= Value::ConstantAggregateLastVal;
977 return Val.
getValueID() == Value::ArgumentVal;
983 return Val.
getValueID() == Value::InlineAsmVal;
989 return Val.
getValueID() >= Value::InstructionVal;
995 return Val.
getValueID() == Value::BasicBlockVal;
1001 return Val.
getValueID() == Value::FunctionVal;
1007 return Val.
getValueID() == Value::GlobalVariableVal;
1013 return Val.
getValueID() == Value::GlobalAliasVal;
1019 return Val.
getValueID() == Value::GlobalIFuncVal;
1025 return isa<GlobalObject>(Val) || isa<GlobalAlias>(Val);
1031 return isa<GlobalVariable>(Val) || isa<Function>(Val) ||
1032 isa<GlobalIFunc>(Val);
1041 return reinterpret_cast<Value**
>(Vals);
1044 template<
typename T>
1051 return reinterpret_cast<T**
>(Vals);
1060 #endif // LLVM_IR_VALUE_H
@ User
could "use" a pointer
This class represents an incoming formal argument to a Function.
user_iterator_impl< const User > const_user_iterator
const Value * stripPointerCastsAndAliases() const
Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
This is an optimization pass for GlobalISel generic memory operations.
bool isUsedInBasicBlock(const BasicBlock *BB) const
Check if this value is used in the specified basic block.
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
static void dropDroppableUse(Use &U)
Remove the droppable use U.
Align getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
A parsed version of the target data layout string in and methods for querying it.
bool hasOneUse() const
Return true if there is exactly one use of this value.
static constexpr uint64_t MaximumAlignment
Value * stripInBoundsConstantOffsets()
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
bool hasMetadata(unsigned KindID) const
Return true if this value has the given type of metadata attached.
This is the common base class of value handles.
Value * stripPointerCastsAndAliases()
void dump() const
Support for debugging, callable in GDB: V->dump()
unsigned short getSubclassDataFromValue() const
Replace within non kernel function use of LDS with pointer
static bool doit(const Value &Val)
iterator_range< const_use_iterator > uses() const
Base class for aggregate constants (with operands).
iterator_range< const_user_iterator > materialized_users() const
const User * getUniqueUndroppableUser() const
const_user_iterator materialized_user_begin() const
The instances of the Type class are immutable: once they are created, they are never changed.
static bool doit(const Value &Val)
bool operator!=(uint64_t V1, const APInt &V2)
bool hasOneUser() const
Return true if there is exactly one user of this value.
const Value * stripAndAccumulateConstantOffsets(const DataLayout &DL, APInt &Offset, bool AllowNonInbounds, bool AllowInvariantGroup=false, function_ref< bool(Value &Value, APInt &Offset)> ExternalAnalysis=nullptr) const
Accumulate the constant offset this value has compared to a base pointer.
user_iterator user_begin()
alloca< 16 x float >, align 16 %tmp2=alloca< 16 x float >, align 16 store< 16 x float > %A,< 16 x float > *%tmp %s=bitcast< 16 x float > *%tmp to i8 *%s2=bitcast< 16 x float > *%tmp2 to i8 *call void @llvm.memcpy.i64(i8 *%s, i8 *%s2, i64 64, i32 16) %R=load< 16 x float > *%tmp2 ret< 16 x float > %R } declare void @llvm.memcpy.i64(i8 *nocapture, i8 *nocapture, i64, i32) nounwind which compiles to:_foo:subl $140, %esp movaps %xmm3, 112(%esp) movaps %xmm2, 96(%esp) movaps %xmm1, 80(%esp) movaps %xmm0, 64(%esp) movl 60(%esp), %eax movl %eax, 124(%esp) movl 56(%esp), %eax movl %eax, 120(%esp) movl 52(%esp), %eax< many many more 32-bit copies > movaps(%esp), %xmm0 movaps 16(%esp), %xmm1 movaps 32(%esp), %xmm2 movaps 48(%esp), %xmm3 addl $140, %esp ret On Nehalem, it may even be cheaper to just use movups when unaligned than to fall back to lower-granularity chunks. Implement processor-specific optimizations for parity with GCC on these processors. GCC does two optimizations:1. ix86_pad_returns inserts a noop before ret instructions if immediately preceded by a conditional branch or is the target of a jump. 2. ix86_avoid_jump_misspredicts inserts noops in cases where a 16-byte block of code contains more than 3 branches. The first one is done for all AMDs, Core2, and "Generic" The second one is done for:Atom, Pentium Pro, all AMDs, Pentium 4, Nocona, Core 2, and "Generic" Testcase:int x(int a) { return(a &0xf0)> >4 tmp
void setValueSubclassData(unsigned short D)
void dropDroppableUses(llvm::function_ref< bool(const Use *)> ShouldDrop=[](const Use *) { return true;})
Remove every uses that can safely be removed.
user_iterator materialized_user_begin()
static bool doit(const Value &Val)
Value * operator=(Value *RHS)
LLVM Basic Block Representation.
bool isSwiftError() const
Return true if this value is a swifterror value.
Base class for constants with no operands.
static bool doit(const Value &Val)
void reverseUseList()
Reverse the use-list.
#define DEFINE_ISA_CONVERSION_FUNCTIONS(ty, ref)
Value & operator=(const Value &)=delete
use_iterator_impl< Use > use_iterator
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static bool doit(const Value &Val)
Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB)
Use * getSingleUndroppableUse()
Return true if there is exactly one use of this value that cannot be dropped.
std::unique_ptr< Value, ValueDeleter > unique_value
Use this instead of std::unique_ptr<Value> or std::unique_ptr<Instruction>.
Value * stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL, APInt &Offset)
void assertModuleIsMaterializedImpl() const
static bool doit(const Value &Val)
const_user_iterator user_end() const
iterator_range< use_iterator > uses()
unsigned getValueID() const
Return an ID for the concrete type of this object.
Attribute unwrap(LLVMAttributeRef Attr)
This class implements an extremely fast bulk output stream that can only output to a stream.
void setName(const Twine &Name)
Change the name of the value.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
static constexpr unsigned MaxAlignmentExponent
The maximum alignment for instructions.
bool isTransitiveUsedByMetadataOnly() const
void dropDroppableUsesIn(User &Usr)
Remove every use of this value in User that can safely be removed.
bool hasValueHandle() const
Return true if there is a value handle associated with this value.
const_use_iterator use_end() const
An efficient, type-erasing, non-owning reference to a callable.
const Value * stripPointerCastsSameRepresentation() const
Strip off pointer casts, all-zero GEPs and address space casts but ensures the representation of the ...
Value(Type *Ty, unsigned scid)
bool hasNUndroppableUsesOrMore(unsigned N) const
Return true if this value has N uses or more.
static bool doit(const Value &Val)
This is an important base class in LLVM.
std::string getNameOrAsOperand() const
void mutateType(Type *Ty)
Mutate the type of this Value to be of the specified type.
uint64_t getPointerDereferenceableBytes(const DataLayout &DL, bool &CanBeNull, bool &CanBeFreed) const
Returns the number of bytes known to be dereferenceable for the pointer value.
void addMetadata(unsigned KindID, MDNode &MD)
Add a metadata attachment.
static bool doit(const Value &Val)
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
User * getUniqueUndroppableUser()
Return true if there is exactly one unique user of this value that cannot be dropped (that user can h...
This is an important class for using LLVM in a threaded context.
bool hasNUsesOrMore(unsigned N) const
Return true if this value has N uses or more.
bool materialized_use_empty() const
void clearSubclassOptionalData()
Clear the optional flags contained in this value.
const_user_iterator user_begin() const
ValueName * getValueName() const
void replaceNonMetadataUsesWith(Value *V)
Change non-metadata uses of this to point to a new Value.
void print(raw_ostream &O, bool IsForDebug=false) const
Implement operator<< on Value.
into xmm2 addss xmm2 xmm1 xmm3 addss xmm3 movaps xmm0 unpcklps xmm0 ret seems silly when it could just be one addps Expand libm rounding functions inline
static bool doit(const Value &Val)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void setValueName(ValueName *VN)
void replaceUsesOutsideBlock(Value *V, BasicBlock *BB)
replaceUsesOutsideBlock - Go through the uses list for this definition and make each use point to "V"...
const Value * stripPointerCastsForAliasAnalysis() const
Strip off pointer casts, all-zero GEPs, single-argument phi nodes and invariant group info.
iterator_range< use_iterator > materialized_uses()
bool operator==(uint64_t V1, const APInt &V2)
@ BasicBlock
Various leaf nodes.
void clearMetadata()
Erase all metadata attached to this Value.
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.
Class for arbitrary precision integers.
QP Compare Ordered outs ins xscmpudp No builtin are required Or llvm fcmp order unorder compare DP QP Compare builtin are required DP Compare
LLVMAttributeRef wrap(Attribute Attr)
bool hasSingleElement(ContainerTy &&C)
Returns true if the given container only contains a single element.
ValueTy
Concrete subclass of this.
APInt operator*(APInt a, uint64_t RHS)
const Use * getSingleUndroppableUse() const
StringRef - Represent a constant reference to a string, i.e.
bool hasSameSubclassOptionalData(const Value *V) const
Check the optional flags for equality.
unsigned getNumUses() const
This method computes the number of uses of this Value.
Type * getType() const
All values are typed, get the type of this value.
Value * stripPointerCasts()
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVMContext & getContext() const
All values hold a context through their type.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MDNode * getMetadata(unsigned KindID) const
Get the current metadata attachments for the given kind, if any.
Machine Check Debug Module
Value * stripAndAccumulateConstantOffsets(const DataLayout &DL, APInt &Offset, bool AllowNonInbounds, bool AllowInvariantGroup=false)
void setMetadata(unsigned KindID, MDNode *Node)
Set a particular kind of metadata attachment.
unsigned getRawSubclassOptionalData() const
Return the raw optional flags value contained in this value.
StringRef getName() const
Return a constant reference to the value's name.
static bool doit(const Value &Val)
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
const Value * stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL, APInt &Offset) const
This is a wrapper around stripAndAccumulateConstantOffsets with the in-bounds requirement set to fals...
const Value * stripInBoundsOffsets(function_ref< void(const Value *)> Func=[](const Value *) {}) const
Strip off pointer casts and inbounds GEPs.
const_use_iterator use_begin() const
Value * stripPointerCastsSameRepresentation()
void sortUseList(Compare Cmp)
Sort the use-list.
bool eraseMetadata(unsigned KindID)
Erase all metadata attachments with the given kind.
const User * user_back() const
user_iterator_impl< User > user_iterator
bool hasNUndroppableUses(unsigned N) const
Return true if there this value.
~Value()
Value's destructor should be virtual by design, but that would require that Value and all of its subc...
bool hasMetadata(StringRef Kind) const
void addUse(Use &U)
This method should only be used by the Use class.
bool hasNUses(unsigned N) const
Return true if this Value has exactly N uses.
void assertModuleIsMaterialized() const
iterator_range< const_user_iterator > users() const
use_iterator_impl< const Use > const_use_iterator
iterator_range< const_use_iterator > materialized_uses() const
bool canBeFreed() const
Return true if the memory object referred to by V can by freed in the scope for which the SSA value d...
static bool doit(const Value &Val)
Value * stripInBoundsOffsets(function_ref< void(const Value *)> Func=[](const Value *) {})
bool isUsedByMetadata() const
Return true if there is metadata referencing this value.
const Value * stripInBoundsConstantOffsets() const
Strip off pointer casts and all-constant inbounds GEPs.
const Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB) const
Translate PHI node to its predecessor from the given basic block.
void operator()(Value *V)
void deleteValue()
Delete a pointer to a generic Value.
A range adaptor for a pair of iterators.
use_iterator materialized_use_begin()
static bool doit(const Value &Val)
void getAllMetadata(SmallVectorImpl< std::pair< unsigned, MDNode * >> &MDs) const
Appends all metadata attached to this value to MDs, sorting by KindID.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
const_use_iterator materialized_use_begin() const
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
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...
void takeName(Value *V)
Transfer the name from V to this value.
Value * stripPointerCastsForAliasAnalysis()
bool hasMetadata() const
Return true if this value has any metadata attached to it.
static bool doit(const Value &Val)
LLVM Value Representation.
iterator_range< user_iterator > users()
iterator_range< user_iterator > materialized_users()
A Use represents the edge between a Value definition and its users.