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/User.h"
18 //===----------------------------------------------------------------------===//
19 // Use swap Implementation
20 //===----------------------------------------------------------------------===//
22 void Use::swap(Use &RHS) {
47 //===----------------------------------------------------------------------===//
48 // Use getImpliedUser Implementation
49 //===----------------------------------------------------------------------===//
51 const Use *Use::getImpliedUser() const {
52 const Use *Current = this;
55 unsigned Tag = extractTag<PrevPtrTag, fullStopTag>((Current++)->Prev);
65 unsigned Tag = extractTag<PrevPtrTag, fullStopTag>(Current->Prev);
70 Offset = (Offset << 1) + Tag;
73 return Current + Offset;
84 //===----------------------------------------------------------------------===//
85 // Use initTags Implementation
86 //===----------------------------------------------------------------------===//
88 Use *Use::initTags(Use * const Start, Use *Stop, ptrdiff_t Done) {
89 ptrdiff_t Count = Done;
90 while (Start != Stop) {
94 Stop->Prev = reinterpret_cast<Use**>(Done == 0 ? fullStopTag : stopTag);
98 Stop->Prev = reinterpret_cast<Use**>(Count & 1);
107 //===----------------------------------------------------------------------===//
108 // Use zap Implementation
109 //===----------------------------------------------------------------------===//
111 void Use::zap(Use *Start, const Use *Stop, bool del) {
113 while (Start != Stop) {
116 ::operator delete(Start);
120 while (Start != Stop) {
125 //===----------------------------------------------------------------------===//
126 // AugmentedUse layout struct
127 //===----------------------------------------------------------------------===//
129 struct AugmentedUse : Use {
131 AugmentedUse(); // not implemented
135 //===----------------------------------------------------------------------===//
136 // Use getUser Implementation
137 //===----------------------------------------------------------------------===//
139 User *Use::getUser() const {
140 const Use *End = getImpliedUser();
141 User *She = static_cast<const AugmentedUse*>(End - 1)->ref;
142 She = extractTag<Tag, tagOne>(She)
143 ? llvm::stripTag<tagOne>(She)
144 : reinterpret_cast<User*>(const_cast<Use*>(End));
149 //===----------------------------------------------------------------------===//
150 // User allocHungoffUses Implementation
151 //===----------------------------------------------------------------------===//
153 Use *User::allocHungoffUses(unsigned N) const {
154 Use *Begin = static_cast<Use*>(::operator new(sizeof(Use) * N
155 + sizeof(AugmentedUse)
157 Use *End = Begin + N;
158 static_cast<AugmentedUse&>(End[-1]).ref = addTag(this, tagOne);
159 return Use::initTags(Begin, End);
162 } // End llvm namespace