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/Value.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
) {
93 static const PrevPtrTag tags
[20] = { fullStopTag
, oneDigitTag
, stopTag
,
94 oneDigitTag
, oneDigitTag
, stopTag
,
95 zeroDigitTag
, oneDigitTag
, oneDigitTag
,
96 stopTag
, zeroDigitTag
, oneDigitTag
,
97 zeroDigitTag
, oneDigitTag
, stopTag
,
98 oneDigitTag
, oneDigitTag
, oneDigitTag
,
101 new(Stop
) Use(tags
[Done
++]);
104 ptrdiff_t Count
= Done
;
105 while (Start
!= Stop
) {
108 new(Stop
) Use(stopTag
);
112 new(Stop
) Use(PrevPtrTag(Count
& 1));
121 //===----------------------------------------------------------------------===//
122 // Use zap Implementation
123 //===----------------------------------------------------------------------===//
125 void Use::zap(Use
*Start
, const Use
*Stop
, bool del
) {
126 while (Start
!= Stop
)
129 ::operator delete(Start
);
132 //===----------------------------------------------------------------------===//
133 // Use getUser Implementation
134 //===----------------------------------------------------------------------===//
136 User
*Use::getUser() const {
137 const Use
*End
= getImpliedUser();
138 const PointerIntPair
<User
*, 1, unsigned>&
139 ref(static_cast<const AugmentedUse
*>(End
- 1)->ref
);
140 User
*She
= ref
.getPointer();
146 } // End llvm namespace