summaryrefslogtreecommitdiff
path: root/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
commit0a6057117e6f0b15c334e1a701d7c29f97c60b88 (patch)
treec184b487f6eda76c336555068067db7c31dffda0 /lib/IR/Use.cpp
parentd186c936bb9ef9ebb03d09e9ed1ed4e496a0d762 (diff)
[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
Diffstat (limited to 'lib/IR/Use.cpp')
-rw-r--r--lib/IR/Use.cpp102
1 files changed, 42 insertions, 60 deletions
diff --git a/lib/IR/Use.cpp b/lib/IR/Use.cpp
index 1d343e80309..20c47a5f1a4 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