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 = (Current++)->Prev.getInt();
65 unsigned Tag = Current->Prev.getInt();
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.setFromOpaqueValue(reinterpret_cast<Use**>(Done == 0 ? fullStopTag : stopTag));
98 Stop->Prev.setFromOpaqueValue(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 {
130 PointerIntPair<User*, 1, Tag> ref;
131 AugmentedUse(); // not implemented
135 //===----------------------------------------------------------------------===//
136 // Use getUser Implementation
137 //===----------------------------------------------------------------------===//
139 User *Use::getUser() const {
140 const Use *End = getImpliedUser();
141 PointerIntPair<User*, 1, Tag>& ref(static_cast<const AugmentedUse*>(End - 1)->ref);
142 User *She = ref.getPointer();
148 //===----------------------------------------------------------------------===//
149 // User allocHungoffUses Implementation
150 //===----------------------------------------------------------------------===//
152 Use *User::allocHungoffUses(unsigned N) const {
153 Use *Begin = static_cast<Use*>(::operator new(sizeof(Use) * N
154 + sizeof(AugmentedUse)
156 Use *End = Begin + N;
157 PointerIntPair<User*, 1, Tag>& ref(static_cast<AugmentedUse&>(End[-1]).ref);
158 ref.setPointer(const_cast<User*>(this));
160 return Use::initTags(Begin, End);
163 } // End llvm namespace