[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
This commit is contained in:
Chandler Carruth
2014-03-04 08:51:00 +00:00
parent d186c936bb
commit 0a6057117e
2 changed files with 103 additions and 111 deletions
+53 -71
View File
@@ -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,9 +38,58 @@ void Use::swap(Use &RHS) {
}
}
//===----------------------------------------------------------------------===//
// Use getImpliedUser Implementation
//===----------------------------------------------------------------------===//
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));
}
// 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) {
if (Start == Stop--)
return Start;
static const PrevPtrTag tags[20] = { fullStopTag, oneDigitTag, stopTag,
oneDigitTag, oneDigitTag, stopTag,
zeroDigitTag, oneDigitTag, oneDigitTag,
stopTag, zeroDigitTag, oneDigitTag,
zeroDigitTag, oneDigitTag, stopTag,
oneDigitTag, oneDigitTag, oneDigitTag,
oneDigitTag, stopTag
};
new(Stop) Use(tags[Done++]);
}
ptrdiff_t Count = Done;
while (Start != Stop) {
--Stop;
if (!Count) {
new(Stop) Use(stopTag);
++Done;
Count = Done;
} else {
new(Stop) Use(PrevPtrTag(Count & 1));
Count >>= 1;
++Done;
}
}
return Start;
}
void Use::zap(Use *Start, const Use *Stop, bool del) {
while (Start != Stop)
(--Stop)->~Use();
if (del)
::operator delete(Start);
}
const Use *Use::getImpliedUser() const {
const Use *Current = this;
@@ -82,64 +124,4 @@ const Use *Use::getImpliedUser() const {
}
}
//===----------------------------------------------------------------------===//
// Use initTags Implementation
//===----------------------------------------------------------------------===//
Use *Use::initTags(Use * const Start, Use *Stop) {
ptrdiff_t Done = 0;
while (Done < 20) {
if (Start == Stop--)
return Start;
static const PrevPtrTag tags[20] = { fullStopTag, oneDigitTag, stopTag,
oneDigitTag, oneDigitTag, stopTag,
zeroDigitTag, oneDigitTag, oneDigitTag,
stopTag, zeroDigitTag, oneDigitTag,
zeroDigitTag, oneDigitTag, stopTag,
oneDigitTag, oneDigitTag, oneDigitTag,
oneDigitTag, stopTag
};
new(Stop) Use(tags[Done++]);
}
ptrdiff_t Count = Done;
while (Start != Stop) {
--Stop;
if (!Count) {
new(Stop) Use(stopTag);
++Done;
Count = Done;
} else {
new(Stop) Use(PrevPtrTag(Count & 1));
Count >>= 1;
++Done;
}
}
return Start;
}
//===----------------------------------------------------------------------===//
// Use zap Implementation
//===----------------------------------------------------------------------===//
void Use::zap(Use *Start, const Use *Stop, bool del) {
while (Start != Stop)
(--Stop)->~Use();
if (del)
::operator delete(Start);
}
//===----------------------------------------------------------------------===//
// Use getUser Implementation
//===----------------------------------------------------------------------===//
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));
}
} // End llvm namespace