diff options
Diffstat (limited to 'include/llvm/IR/Use.h')
-rw-r--r-- | include/llvm/IR/Use.h | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/include/llvm/IR/Use.h b/include/llvm/IR/Use.h index 6b56546f4421..d3a59d8a060e 100644 --- a/include/llvm/IR/Use.h +++ b/include/llvm/IR/Use.h @@ -1,4 +1,4 @@ -//===-- llvm/Use.h - Definition of the Use class ----------------*- C++ -*-===// +//===- llvm/Use.h - Definition of the Use class -----------------*- C++ -*-===// // // The LLVM Compiler Infrastructure // @@ -27,14 +27,14 @@ #include "llvm/ADT/PointerIntPair.h" #include "llvm/Support/CBindingWrapping.h" +#include "llvm/Support/Compiler.h" #include "llvm-c/Types.h" namespace llvm { -class Value; -class User; -class Use; template <typename> struct simplify_type; +class User; +class Value; /// \brief A Use represents the edge between a Value definition and its users. /// @@ -65,23 +65,27 @@ public: /// use the LSB regardless of pointer alignment on different targets. struct UserRefPointerTraits { static inline void *getAsVoidPointer(User *P) { return P; } + static inline User *getFromVoidPointer(void *P) { return (User *)P; } + enum { NumLowBitsAvailable = 1 }; }; // A type for the word following an array of hung-off Uses in memory, which is // a pointer back to their User with the bottom bit set. - typedef PointerIntPair<User *, 1, unsigned, UserRefPointerTraits> UserRef; + using UserRef = PointerIntPair<User *, 1, unsigned, UserRefPointerTraits>; /// Pointer traits for the Prev PointerIntPair. This ensures we always use /// the two LSBs regardless of pointer alignment on different targets. struct PrevPointerTraits { static inline void *getAsVoidPointer(Use **P) { return P; } + static inline Use **getFromVoidPointer(void *P) { return (Use **)P; } + enum { NumLowBitsAvailable = 2 }; }; @@ -95,9 +99,11 @@ private: enum PrevPtrTag { zeroDigitTag, oneDigitTag, stopTag, fullStopTag }; /// Constructor - Use(PrevPtrTag tag) : Val(nullptr) { Prev.setInt(tag); } + Use(PrevPtrTag tag) { Prev.setInt(tag); } public: + friend class Value; + operator Value *() const { return Val; } Value *get() const { return Val; } @@ -133,7 +139,7 @@ public: private: const Use *getImpliedUser() const LLVM_READONLY; - Value *Val; + Value *Val = nullptr; Use *Next; PointerIntPair<Use **, 2, PrevPtrTag, PrevPointerTraits> Prev; @@ -153,18 +159,18 @@ private: if (Next) Next->setPrev(StrippedPrev); } - - friend class Value; }; /// \brief Allow clients to treat uses just like values when using /// casting operators. template <> struct simplify_type<Use> { - typedef Value *SimpleType; + using SimpleType = Value *; + static SimpleType getSimplifiedValue(Use &Val) { return Val.get(); } }; template <> struct simplify_type<const Use> { - typedef /*const*/ Value *SimpleType; + using SimpleType = /*const*/ Value *; + static SimpleType getSimplifiedValue(const Use &Val) { return Val.get(); } }; |