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 // This file implements the algorithm for finding the User of a Use.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/IR/Value.h"
19 //===----------------------------------------------------------------------===//
20 // Use swap Implementation
21 //===----------------------------------------------------------------------===//
23 void Use::swap(Use &RHS) {
48 //===----------------------------------------------------------------------===//
49 // Use getImpliedUser Implementation
50 //===----------------------------------------------------------------------===//
52 const Use *Use::getImpliedUser() const {
53 const Use *Current = this;
56 unsigned Tag = (Current++)->Prev.getInt();
66 unsigned Tag = Current->Prev.getInt();
71 Offset = (Offset << 1) + Tag;
74 return Current + Offset;
85 //===----------------------------------------------------------------------===//
86 // Use initTags Implementation
87 //===----------------------------------------------------------------------===//
89 Use *Use::initTags(Use * const Start, Use *Stop) {
94 static const PrevPtrTag tags[20] = { fullStopTag, oneDigitTag, stopTag,
95 oneDigitTag, oneDigitTag, stopTag,
96 zeroDigitTag, oneDigitTag, oneDigitTag,
97 stopTag, zeroDigitTag, oneDigitTag,
98 zeroDigitTag, oneDigitTag, stopTag,
99 oneDigitTag, oneDigitTag, oneDigitTag,
102 new(Stop) Use(tags[Done++]);
105 ptrdiff_t Count = Done;
106 while (Start != Stop) {
109 new(Stop) Use(stopTag);
113 new(Stop) Use(PrevPtrTag(Count & 1));
122 //===----------------------------------------------------------------------===//
123 // Use zap Implementation
124 //===----------------------------------------------------------------------===//
126 void Use::zap(Use *Start, const Use *Stop, bool del) {
127 while (Start != Stop)
130 ::operator delete(Start);
133 //===----------------------------------------------------------------------===//
134 // Use getUser Implementation
135 //===----------------------------------------------------------------------===//
137 User *Use::getUser() const {
138 const Use *End = getImpliedUser();
139 const UserRef *ref = reinterpret_cast<const UserRef*>(End);
145 } // End llvm namespace