14 #ifndef LLVM_IR_VALUE_H
15 #define LLVM_IR_VALUE_H
28 class AssemblyAnnotationWriter;
41 class ModuleSlotTracker;
45 class ValueHandleBase;
46 class ValueSymbolTable;
76 const unsigned char SubclassID;
77 unsigned char HasValueHandle : 1;
92 unsigned short SubclassData;
115 template <
typename UseT>
116 class use_iterator_impl
117 :
public std::iterator<std::forward_iterator_tag, UseT *> {
119 explicit use_iterator_impl(UseT *u) : U(u) {}
123 use_iterator_impl() : U() {}
125 bool operator==(
const use_iterator_impl &x)
const {
return U == x.U; }
128 use_iterator_impl &operator++() {
129 assert(U &&
"Cannot increment end iterator!");
133 use_iterator_impl operator++(
int) {
140 assert(U &&
"Cannot dereference end iterator!");
144 UseT *operator->()
const {
return &
operator*(); }
146 operator use_iterator_impl<const UseT>()
const {
147 return use_iterator_impl<const UseT>(U);
151 template <
typename UserTy>
152 class user_iterator_impl
153 :
public std::iterator<std::forward_iterator_tag, UserTy *> {
154 use_iterator_impl<Use> UI;
155 explicit user_iterator_impl(
Use *U) : UI(U) {}
159 user_iterator_impl() {}
161 bool operator==(
const user_iterator_impl &x)
const {
return UI == x.UI; }
165 bool atEnd()
const {
return *
this == user_iterator_impl(); }
167 user_iterator_impl &operator++() {
171 user_iterator_impl operator++(
int) {
179 return UI->getUser();
182 UserTy *operator->()
const {
return operator*(); }
184 operator user_iterator_impl<const UserTy>()
const {
185 return user_iterator_impl<const UserTy>(*UI);
188 Use &getUse()
const {
return *UI; }
191 void operator=(
const Value &) =
delete;
192 Value(
const Value &) =
delete;
195 Value(
Type *Ty,
unsigned scid);
204 void print(raw_ostream &O)
const;
205 void print(raw_ostream &O, ModuleSlotTracker &MST)
const;
216 const Module *M =
nullptr)
const;
218 ModuleSlotTracker &MST)
const;
233 void destroyValueName();
313 if (I == E)
return false;
344 #define HANDLE_VALUE(Name) Name##Val,
345 #include "llvm/IR/Value.def"
348 #define HANDLE_CONSTANT_MARKER(Marker, Constant) Marker = Constant##Val,
349 #include "llvm/IR/Value.def"
431 APInt &Offset)
const {
432 return const_cast<Value *
>(
this)
493 template <
class Compare>
496 mergeUseListsImpl(L, R, &Merged, Cmp);
503 template <
class Compare>
504 static void mergeUseListsImpl(Use *L, Use *R, Use **Next,
Compare Cmp);
517 if (Val) removeFromList();
523 if (!UseList || !UseList->Next)
532 const unsigned MaxSlots = 32;
533 Use *Slots[MaxSlots];
536 Use *Next = UseList->Next;
537 UseList->Next =
nullptr;
538 unsigned NumSlots = 1;
544 Next = Current->Next;
547 Current->Next =
nullptr;
551 for (I = 0; I < NumSlots; ++
I) {
559 Current = mergeUseLists(Slots[I], Current, Cmp);
565 assert(NumSlots <= MaxSlots &&
"Use list bigger than 2^32");
573 assert(Next &&
"Expected one more Use");
574 assert(!Next->Next &&
"Expected only one Use");
576 for (
unsigned I = 0;
I < NumSlots; ++
I)
580 UseList = mergeUseLists(Slots[I], UseList, Cmp);
583 for (
Use *I = UseList, **Prev = &UseList;
I; I = I->Next) {
589 template <
class Compare>
601 mergeUseListsImpl(L, R->Next, &R->Next, Cmp);
605 mergeUseListsImpl(L->Next, R, &L->Next, Cmp);
613 return Val.
getValueID() >= Value::ConstantFirstVal &&
620 return Val.
getValueID() == Value::ArgumentVal;
626 return Val.
getValueID() == Value::InlineAsmVal;
632 return Val.
getValueID() >= Value::InstructionVal;
638 return Val.
getValueID() == Value::BasicBlockVal;
644 return Val.
getValueID() == Value::FunctionVal;
650 return Val.
getValueID() == Value::GlobalVariableVal;
656 return Val.
getValueID() == Value::GlobalAliasVal;
662 return isa<GlobalObject>(Val) || isa<GlobalAlias>(Val);
668 return isa<GlobalVariable>(Val) || isa<Function>(Val);
679 return static_cast<PT
>(
P);
681 enum { NumLowBitsAvailable = 2 };
690 return reinterpret_cast<Value**
>(Vals);
700 return reinterpret_cast<T**
>(Vals);
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.
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.
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
static bool doit(const Value &Val)
static void * getAsVoidPointer(PT P)
const_user_iterator user_begin() const
This defines the Use class.
PointerLikeTypeTraits - This is a traits object that is used to handle pointer types and things that ...
static PT getFromVoidPointer(void *P)
const_use_iterator use_begin() const
const Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB) const
StringRef getName() const
Return a constant reference to the value's name.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
A Use represents the edge between a Value definition and its users.
void setName(const Twine &Name)
Change the name of the value.
void print(raw_ostream &O) const
Implement operator<< on 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)
LLVMTargetDataRef wrap(const DataLayout *P)
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.
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
Value * stripPointerCastsNoFollowAliases()
Strip off pointer casts and all-zero GEPs.
void intersectOptionalDataWith(const Value *V)
Clear any optional flags not set in the given Value.
DataLayout * unwrap(LLVMTargetDataRef P)
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.
Value * stripInBoundsOffsets()
Strip off pointer casts and inbounds GEPs.
bool isUsedByMetadata() const
Return true if there is metadata referencing this value.
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.
iterator_range< const_user_iterator > users() const
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.
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
unsigned char SubclassOptionalData
Hold subclass data that can be dropped.
void dump() const
Support for debugging, callable in GDB: V->dump()
const User * user_back() const
static const unsigned MaxAlignmentExponent
The maximum alignment for instructions.
BlockMass operator*(const BlockMass &L, const BranchProbability &R)
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.
Type * getType() const
All values are typed, get the type of this 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)
user_iterator_impl< const User > const_user_iterator
unsigned short getSubclassDataFromValue() const
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.
user_iterator user_begin()
StringMapEntry< Value * > ValueName
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...
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.
const_user_iterator user_end() const
static bool doit(const Value &Val)
const Value * stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL, APInt &Offset) const