aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Use.cpp
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2014-03-04 08:51:00 +0000
committerChandler Carruth <chandlerc@gmail.com>2014-03-04 08:51:00 +0000
commit06d49183ecf59bb2a8fa45032e39b7afbbe43429 (patch)
treee01dac4de4867f0652856caf4e0b09b0399bdab6 /llvm/lib/IR/Use.cpp
parenta79696d9bf2557c2a18204b24812e3367cc9fc0e (diff)
downloadllvm-06d49183ecf59bb2a8fa45032e39b7afbbe43429.zip
llvm-06d49183ecf59bb2a8fa45032e39b7afbbe43429.tar.gz
llvm-06d49183ecf59bb2a8fa45032e39b7afbbe43429.tar.bz2
[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. llvm-svn: 202798
Diffstat (limited to 'llvm/lib/IR/Use.cpp')
-rw-r--r--llvm/lib/IR/Use.cpp102
1 files changed, 42 insertions, 60 deletions
diff --git a/llvm/lib/IR/Use.cpp b/llvm/lib/IR/Use.cpp
index 1d343e8..20c47a5 100644
--- a/llvm/lib/IR/Use.cpp
+++ b/llvm/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