1 //===-- Use.cpp - Implement the Use class ---------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/IR/Use.h"
11 #include "llvm/IR/Value.h"
16 void Use::swap(Use &RHS) {
40 User *Use::getUser() const {
41 const Use *End = getImpliedUser();
42 const UserRef *ref = reinterpret_cast<const UserRef *>(End);
43 return ref->getInt() ? ref->getPointer()
44 : reinterpret_cast<User *>(const_cast<Use *>(End));
47 // Sets up the waymarking algoritm's tags for a series of Uses. See the
48 // algorithm details here:
50 // http://www.llvm.org/docs/ProgrammersManual.html#UserLayout
52 Use *Use::initTags(Use *const Start, Use *Stop) {
57 static const PrevPtrTag tags[20] = {
58 fullStopTag, oneDigitTag, stopTag, oneDigitTag, oneDigitTag,
59 stopTag, zeroDigitTag, oneDigitTag, oneDigitTag, stopTag,
60 zeroDigitTag, oneDigitTag, zeroDigitTag, oneDigitTag, stopTag,
61 oneDigitTag, oneDigitTag, oneDigitTag, oneDigitTag, stopTag};
62 new (Stop) Use(tags[Done++]);
65 ptrdiff_t Count = Done;
66 while (Start != Stop) {
69 new (Stop) Use(stopTag);
73 new (Stop) Use(PrevPtrTag(Count & 1));
82 void Use::zap(Use *Start, const Use *Stop, bool del) {
86 ::operator delete(Start);
89 const Use *Use::getImpliedUser() const {
90 const Use *Current = this;
93 unsigned Tag = (Current++)->Prev.getInt();
101 ptrdiff_t Offset = 1;
103 unsigned Tag = Current->Prev.getInt();
108 Offset = (Offset << 1) + Tag;
111 return Current + Offset;
122 } // End llvm namespace