diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2014-03-04 08:51:00 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2014-03-04 08:51:00 +0000 |
commit | 0a6057117e6f0b15c334e1a701d7c29f97c60b88 (patch) | |
tree | c184b487f6eda76c336555068067db7c31dffda0 | |
parent | d186c936bb9ef9ebb03d09e9ed1ed4e496a0d762 (diff) | |
download | llvm-0a6057117e6f0b15c334e1a701d7c29f97c60b88.tar.gz llvm-0a6057117e6f0b15c334e1a701d7c29f97c60b88.tar.bz2 llvm-0a6057117e6f0b15c334e1a701d7c29f97c60b88.tar.xz |
[cleanup] Tidy up and modernize comments and the definition order for
the Use class.
More cleanups to come here. This class just needs some TLC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202798 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/IR/Use.h | 90 | ||||
-rw-r--r-- | lib/IR/Use.cpp | 102 |
2 files changed, 92 insertions, 100 deletions
diff --git a/include/llvm/IR/Use.h b/include/llvm/IR/Use.h index 9aa2968169..846952aa6b 100644 --- a/include/llvm/IR/Use.h +++ b/include/llvm/IR/Use.h @@ -6,20 +6,20 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -// -// This defines the Use class. The Use class represents the operand of an -// instruction or some other User instance which refers to a Value. The Use -// class keeps the "use list" of the referenced value up to date. -// -// Pointer tagging is used to efficiently find the User corresponding -// to a Use without having to store a User pointer in every Use. A -// User is preceded in memory by all the Uses corresponding to its -// operands, and the low bits of one of the fields (Prev) of the Use -// class are used to encode offsets to be able to find that User given -// a pointer to any Use. For details, see: -// -// http://www.llvm.org/docs/ProgrammersManual.html#UserLayout -// +/// \file +/// +/// This defines the Use class. The Use class represents the operand of an +/// instruction or some other User instance which refers to a Value. The Use +/// class keeps the "use list" of the referenced value up to date. +/// +/// Pointer tagging is used to efficiently find the User corresponding to a Use +/// without having to store a User pointer in every Use. A User is preceded in +/// memory by all the Uses corresponding to its operands, and the low bits of +/// one of the fields (Prev) of the Use class are used to encode offsets to be +/// able to find that User given a pointer to any Use. For details, see: +/// +/// http://www.llvm.org/docs/ProgrammersManual.html#UserLayout +/// //===----------------------------------------------------------------------===// #ifndef LLVM_IR_USE_H @@ -51,15 +51,26 @@ public: enum { NumLowBitsAvailable = 2 }; }; -//===----------------------------------------------------------------------===// -// Use Class -//===----------------------------------------------------------------------===// - -/// Use is here to make keeping the "use" list of a Value up-to-date really -/// easy. +/// \brief A Use represents the edge between a Value definition and its users. +/// +/// This is notionally a two-dimensional linked list. It supports traversing +/// all of the uses for a particular value definition. It also supports jumping +/// directly to the used value when we arrive from the User's operands, and +/// jumping directly to the User when we arrive from the Value's uses. +/// +/// The pointer to the used Value is explicit, and the pointer to the User is +/// implicit. The implicit pointer is found via a waymarking algorithm +/// described in the programmer's manual: +/// +/// http://www.llvm.org/docs/ProgrammersManual.html#UserLayout +/// +/// This is essentially the single most memory intensive object in LLVM because +/// of the number of uses in the system. At the same time, the constant time +/// operations it allows are essential to many optimizations having reasonable +/// time complexity. class Use { public: - /// swap - provide a fast substitute to std::swap<Use> + /// \brief Provide a fast substitute to std::swap<Use> /// that also works with less standard-compliant compilers void swap(Use &RHS); @@ -86,15 +97,13 @@ private: } public: - /// Normally Use will just implicitly convert to a Value* that it holds. operator Value*() const { return Val; } - - /// If implicit conversion to Value* doesn't work, the get() method returns - /// the Value*. Value *get() const { return Val; } - - /// getUser - This returns the User that contains this Use. For an - /// instruction operand, for example, this will return the instruction. + + /// \brief Returns the User that contains this Use. + /// + /// For an instruction operand, for example, this will return the + /// instruction. User *getUser() const; inline void set(Value *Val); @@ -113,18 +122,19 @@ public: Use *getNext() const { return Next; } - - /// initTags - initialize the waymarking tags on an array of Uses, so that - /// getUser() can find the User from any of those Uses. + /// \brief Initializes the waymarking tags on an array of Uses. + /// + /// This sets up the array of Uses such that getUser() can find the User from + /// any of those Uses. static Use *initTags(Use *Start, Use *Stop); - /// zap - This is used to destroy Use operands when the number of operands of + /// \brief Destroys Use operands when the number of operands of /// a User changes. static void zap(Use *Start, const Use *Stop, bool del = false); private: const Use* getImpliedUser() const; - + Value *Val; Use *Next; PointerIntPair<Use**, 2, PrevPtrTag> Prev; @@ -147,8 +157,8 @@ private: friend class Value; }; -// simplify_type - Allow clients to treat uses just like values when using -// casting operators. +/// \brief Allow clients to treat uses just like values when using +/// casting operators. template<> struct simplify_type<Use> { typedef Value* SimpleType; static SimpleType getSimplifiedValue(Use &Val) { @@ -186,7 +196,7 @@ public: return !operator==(x); } - /// atEnd - return true if this iterator is equal to use_end() on the value. + /// \brief Returns true if this iterator is equal to use_end() on the value. bool atEnd() const { return U == 0; } // Iterator traversal: forward iteration only @@ -208,16 +218,16 @@ public: UserTy *operator->() const { return operator*(); } Use &getUse() const { return *U; } - - /// getOperandNo - Return the operand # of this use in its User. Defined in - /// User.h + + /// \brief Return the operand # of this use in its User. /// + /// Defined in User.h unsigned getOperandNo() const; }; // Create wrappers for C Binding types (see CBindingWrapping.h). DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Use, LLVMUseRef) -} // End llvm namespace +} #endif diff --git a/lib/IR/Use.cpp b/lib/IR/Use.cpp index 1d343e8030..20c47a5f1a 100644 --- a/lib/IR/Use.cpp +++ b/lib/IR/Use.cpp @@ -6,20 +6,13 @@ // License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// -// -// This file implements the algorithm for finding the User of a Use. -// -//===----------------------------------------------------------------------===// +#include "llvm/IR/Use.h" #include "llvm/IR/Value.h" #include <new> namespace llvm { -//===----------------------------------------------------------------------===// -// Use swap Implementation -//===----------------------------------------------------------------------===// - void Use::swap(Use &RHS) { Value *V1(Val); Value *V2(RHS.Val); @@ -45,47 +38,19 @@ void Use::swap(Use &RHS) { } } -//===----------------------------------------------------------------------===// -// Use getImpliedUser Implementation -//===----------------------------------------------------------------------===// - -const Use *Use::getImpliedUser() const { - const Use *Current = this; - - while (true) { - unsigned Tag = (Current++)->Prev.getInt(); - switch (Tag) { - case zeroDigitTag: - case oneDigitTag: - continue; - - case stopTag: { - ++Current; - ptrdiff_t Offset = 1; - while (true) { - unsigned Tag = Current->Prev.getInt(); - switch (Tag) { - case zeroDigitTag: - case oneDigitTag: - ++Current; - Offset = (Offset << 1) + Tag; - continue; - default: - return Current + Offset; - } - } - } - - case fullStopTag: - return Current; - } - } +User *Use::getUser() const { + const Use *End = getImpliedUser(); + const UserRef *ref = reinterpret_cast<const UserRef*>(End); + return ref->getInt() + ? ref->getPointer() + : reinterpret_cast<User*>(const_cast<Use*>(End)); } -//===----------------------------------------------------------------------===// -// Use initTags Implementation -//===----------------------------------------------------------------------===// - +// Sets up the waymarking algoritm's tags for a series of Uses. See the +// algorithm details here: +// +// http://www.llvm.org/docs/ProgrammersManual.html#UserLayout +// Use *Use::initTags(Use * const Start, Use *Stop) { ptrdiff_t Done = 0; while (Done < 20) { @@ -119,10 +84,6 @@ Use *Use::initTags(Use * const Start, Use *Stop) { return Start; } -//===----------------------------------------------------------------------===// -// Use zap Implementation -//===----------------------------------------------------------------------===// - void Use::zap(Use *Start, const Use *Stop, bool del) { while (Start != Stop) (--Stop)->~Use(); @@ -130,16 +91,37 @@ void Use::zap(Use *Start, const Use *Stop, bool del) { ::operator delete(Start); } -//===----------------------------------------------------------------------===// -// Use getUser Implementation -//===----------------------------------------------------------------------===// +const Use *Use::getImpliedUser() const { + const Use *Current = this; -User *Use::getUser() const { - const Use *End = getImpliedUser(); - const UserRef *ref = reinterpret_cast<const UserRef*>(End); - return ref->getInt() - ? ref->getPointer() - : reinterpret_cast<User*>(const_cast<Use*>(End)); + while (true) { + unsigned Tag = (Current++)->Prev.getInt(); + switch (Tag) { + case zeroDigitTag: + case oneDigitTag: + continue; + + case stopTag: { + ++Current; + ptrdiff_t Offset = 1; + while (true) { + unsigned Tag = Current->Prev.getInt(); + switch (Tag) { + case zeroDigitTag: + case oneDigitTag: + ++Current; + Offset = (Offset << 1) + Tag; + continue; + default: + return Current + Offset; + } + } + } + + case fullStopTag: + return Current; + } + } } } // End llvm namespace |