X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;ds=sidebyside;f=include%2Fllvm%2FIR%2FValue.h;h=fbcfd2b03d58c9a6339de1845b077943480be087;hb=cca8dbee4ea6ee37ef32e1794008d4d15bbd566b;hp=7541ffbe6e21785c1a2996e4b6775e00ca9d1f8c;hpb=5182ad54b24df52557c7c7170d4b874b6b156673;p=oota-llvm.git diff --git a/include/llvm/IR/Value.h b/include/llvm/IR/Value.h index 7541ffbe6e2..fbcfd2b03d5 100644 --- a/include/llvm/IR/Value.h +++ b/include/llvm/IR/Value.h @@ -14,7 +14,6 @@ #ifndef LLVM_IR_VALUE_H #define LLVM_IR_VALUE_H -#include "llvm-c/Core.h" #include "llvm/ADT/iterator_range.h" #include "llvm/IR/Use.h" #include "llvm/Support/CBindingWrapping.h" @@ -37,8 +36,8 @@ class GlobalVariable; class InlineAsm; class Instruction; class LLVMContext; -class MDNode; class Module; +class ModuleSlotTracker; class StringRef; class Twine; class Type; @@ -70,9 +69,8 @@ class Value { Type *VTy; Use *UseList; - friend class ValueSymbolTable; // Allow ValueSymbolTable to directly mod Name. + friend class ValueAsMetadata; // Allow access to IsUsedByMD. friend class ValueHandleBase; - ValueName *Name; const unsigned char SubclassID; // Subclass identifier (for isa/dyn_cast) unsigned char HasValueHandle : 1; // Has a ValueHandle pointing to this? @@ -102,22 +100,26 @@ protected: /// This is stored here to save space in User on 64-bit hosts. Since most /// instances of Value have operands, 32-bit hosts aren't significantly /// affected. - unsigned NumOperands; + /// + /// Note, this should *NOT* be used directly by any class other than User. + /// User uses this value to find the Use list. + enum : unsigned { NumUserOperandsBits = 28 }; + unsigned NumUserOperands : NumUserOperandsBits; + + bool IsUsedByMD : 1; + bool HasName : 1; + bool HasHungOffUses : 1; + bool HasDescriptor : 1; private: template // UseT == 'Use' or 'const Use' class use_iterator_impl - : public std::iterator { - typedef std::iterator super; - + : public std::iterator { UseT *U; explicit use_iterator_impl(UseT *u) : U(u) {} friend class Value; public: - typedef typename super::reference reference; - typedef typename super::pointer pointer; - use_iterator_impl() : U() {} bool operator==(const use_iterator_impl &x) const { return U == x.U; } @@ -148,17 +150,12 @@ private: template // UserTy == 'User' or 'const User' class user_iterator_impl - : public std::iterator { - typedef std::iterator super; - + : public std::iterator { use_iterator_impl UI; explicit user_iterator_impl(Use *U) : UI(U) {} friend class Value; public: - typedef typename super::reference reference; - typedef typename super::pointer pointer; - user_iterator_impl() {} bool operator==(const user_iterator_impl &x) const { return UI == x.UI; } @@ -189,15 +186,10 @@ private: } Use &getUse() const { return *UI; } - - /// \brief Return the operand # of this use in its User. - /// - /// FIXME: Replace all callers with a direct call to Use::getOperandNo. - unsigned getOperandNo() const { return UI->getOperandNo(); } }; - void operator=(const Value &) LLVM_DELETED_FUNCTION; - Value(const Value &) LLVM_DELETED_FUNCTION; + void operator=(const Value &) = delete; + Value(const Value &) = delete; protected: Value(Type *Ty, unsigned scid); @@ -208,7 +200,11 @@ public: void dump() const; /// \brief Implement operator<< on Value. - void print(raw_ostream &O) const; + /// @{ + void print(raw_ostream &O, bool IsForDebug = false) const; + void print(raw_ostream &O, ModuleSlotTracker &MST, + bool IsForDebug = false) const; + /// @} /// \brief Print the name of this Value out to the specified raw_ostream. /// @@ -216,8 +212,12 @@ public: /// instruction that generated it. If you specify a Module for context, then /// even constanst get pretty-printed; for example, the type of a null /// pointer is printed symbolically. + /// @{ void printAsOperand(raw_ostream &O, bool PrintType = true, const Module *M = nullptr) const; + void printAsOperand(raw_ostream &O, bool PrintType, + ModuleSlotTracker &MST) const; + /// @} /// \brief All values are typed, get the type of this value. Type *getType() const { return VTy; } @@ -226,10 +226,15 @@ public: LLVMContext &getContext() const; // \brief All values can potentially be named. - bool hasName() const { return Name != nullptr; } - ValueName *getValueName() const { return Name; } - void setValueName(ValueName *VN) { Name = VN; } + bool hasName() const { return HasName; } + ValueName *getValueName() const; + void setValueName(ValueName *VN); + +private: + void destroyValueName(); + void setNameImpl(const Twine &Name); +public: /// \brief Return a constant reference to the value's name. /// /// This is cheap and guaranteed to return the same reference as long as the @@ -277,12 +282,14 @@ public: use_iterator use_end() { return use_iterator(); } const_use_iterator use_end() const { return const_use_iterator(); } iterator_range uses() { - return iterator_range(use_begin(), use_end()); + return make_range(use_begin(), use_end()); } iterator_range uses() const { - return iterator_range(use_begin(), use_end()); + return make_range(use_begin(), use_end()); } + bool user_empty() const { return UseList == nullptr; } + typedef user_iterator_impl user_iterator; typedef user_iterator_impl const_user_iterator; user_iterator user_begin() { return user_iterator(UseList); } @@ -292,10 +299,10 @@ public: User *user_back() { return *user_begin(); } const User *user_back() const { return *user_begin(); } iterator_range users() { - return iterator_range(user_begin(), user_end()); + return make_range(user_begin(), user_end()); } iterator_range users() const { - return iterator_range(user_begin(), user_end()); + return make_range(user_begin(), user_end()); } /// \brief Return true if there is exactly one user of this value. @@ -335,34 +342,12 @@ public: /// Value classes SubclassID field. They are used for concrete type /// identification. enum ValueTy { - ArgumentVal, // This is an instance of Argument - BasicBlockVal, // This is an instance of BasicBlock - FunctionVal, // This is an instance of Function - GlobalAliasVal, // This is an instance of GlobalAlias - GlobalVariableVal, // This is an instance of GlobalVariable - UndefValueVal, // This is an instance of UndefValue - BlockAddressVal, // This is an instance of BlockAddress - ConstantExprVal, // This is an instance of ConstantExpr - ConstantAggregateZeroVal, // This is an instance of ConstantAggregateZero - ConstantDataArrayVal, // This is an instance of ConstantDataArray - ConstantDataVectorVal, // This is an instance of ConstantDataVector - ConstantIntVal, // This is an instance of ConstantInt - ConstantFPVal, // This is an instance of ConstantFP - ConstantArrayVal, // This is an instance of ConstantArray - ConstantStructVal, // This is an instance of ConstantStruct - ConstantVectorVal, // This is an instance of ConstantVector - ConstantPointerNullVal, // This is an instance of ConstantPointerNull - GenericMDNodeVal, // This is an instance of GenericMDNode - MDNodeFwdDeclVal, // This is an instance of MDNodeFwdDecl - MDStringVal, // This is an instance of MDString - InlineAsmVal, // This is an instance of InlineAsm - InstructionVal, // This is an instance of Instruction - // Enum values starting at InstructionVal are used for Instructions; - // don't add new values here! +#define HANDLE_VALUE(Name) Name##Val, +#include "llvm/IR/Value.def" // Markers: - ConstantFirstVal = FunctionVal, - ConstantLastVal = ConstantPointerNullVal +#define HANDLE_CONSTANT_MARKER(Marker, Constant) Marker = Constant##Val, +#include "llvm/IR/Value.def" }; /// \brief Return an ID for the concrete type of this object. @@ -404,6 +389,9 @@ public: /// \brief Return true if there is a value handle associated with this value. bool hasValueHandle() const { return HasValueHandle; } + /// \brief Return true if there is metadata referencing this value. + bool isUsedByMetadata() const { return IsUsedByMD; } + /// \brief Strip off pointer casts, all-zero GEPs, and aliases. /// /// Returns the original uncasted value. If this is called on a non-pointer @@ -455,12 +443,6 @@ public: return const_cast(this)->stripInBoundsOffsets(); } - /// \brief Check if this is always a dereferenceable pointer. - /// - /// Test if this value is always a pointer to allocated and suitably aligned - /// memory for a simple load or store. - bool isDereferenceablePointer(const DataLayout *DL = nullptr) const; - /// \brief Translate PHI node to its predecessor from the given basic block. /// /// If this value is a PHI node with CurBB as its parent, return the value in @@ -478,7 +460,8 @@ public: /// /// This is the greatest alignment value supported by load, store, and alloca /// instructions, and global values. - static const unsigned MaximumAlignment = 1u << 29; + static const unsigned MaxAlignmentExponent = 29; + static const unsigned MaximumAlignment = 1u << MaxAlignmentExponent; /// \brief Mutate the type of this Value to be of the specified type. /// @@ -511,7 +494,28 @@ private: template static Use *mergeUseLists(Use *L, Use *R, Compare Cmp) { Use *Merged; - mergeUseListsImpl(L, R, &Merged, Cmp); + Use **Next = &Merged; + + for (;;) { + if (!L) { + *Next = R; + break; + } + if (!R) { + *Next = L; + break; + } + if (Cmp(*R, *L)) { + *Next = R; + Next = &R->Next; + R = R->Next; + } else { + *Next = L; + Next = &L->Next; + L = L->Next; + } + } + return Merged; } @@ -604,25 +608,6 @@ template void Value::sortUseList(Compare Cmp) { } } -template -void Value::mergeUseListsImpl(Use *L, Use *R, Use **Next, Compare Cmp) { - if (!L) { - *Next = R; - return; - } - if (!R) { - *Next = L; - return; - } - if (Cmp(*R, *L)) { - *Next = R; - mergeUseListsImpl(L, R->Next, &R->Next, Cmp); - return; - } - *Next = L; - mergeUseListsImpl(L->Next, R, &L->Next, Cmp); -} - // isa - Provide some specializations of isa so that we don't have to include // the subtype header files to test to see if the value is a subclass... // @@ -687,13 +672,6 @@ template <> struct isa_impl { } }; -template <> struct isa_impl { - static inline bool doit(const Value &Val) { - return Val.getValueID() == Value::GenericMDNodeVal || - Val.getValueID() == Value::MDNodeFwdDeclVal; - } -}; - // Value* is only 4-byte aligned. template<> class PointerLikeTypeTraits {