1 //===-- Use.cpp - Implement the Use class ---------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/IR/Use.h"
10 #include "llvm/IR/User.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 unsigned Use::getOperandNo() const {
48 return this - getUser()->op_begin();
51 // Sets up the waymarking algorithm's tags for a series of Uses. See the
52 // algorithm details here:
54 // http://www.llvm.org/docs/ProgrammersManual.html#the-waymarking-algorithm
56 Use
*Use::initTags(Use
*const Start
, Use
*Stop
) {
61 static const PrevPtrTag tags
[20] = {
62 fullStopTag
, oneDigitTag
, stopTag
, oneDigitTag
, oneDigitTag
,
63 stopTag
, zeroDigitTag
, oneDigitTag
, oneDigitTag
, stopTag
,
64 zeroDigitTag
, oneDigitTag
, zeroDigitTag
, oneDigitTag
, stopTag
,
65 oneDigitTag
, oneDigitTag
, oneDigitTag
, oneDigitTag
, stopTag
};
66 new (Stop
) Use(tags
[Done
++]);
69 ptrdiff_t Count
= Done
;
70 while (Start
!= Stop
) {
73 new (Stop
) Use(stopTag
);
77 new (Stop
) Use(PrevPtrTag(Count
& 1));
86 void Use::zap(Use
*Start
, const Use
*Stop
, bool del
) {
90 ::operator delete(Start
);
93 const Use
*Use::getImpliedUser() const {
94 const Use
*Current
= this;
97 unsigned Tag
= (Current
++)->Prev
.getInt();
105 ptrdiff_t Offset
= 1;
107 unsigned Tag
= Current
->Prev
.getInt();
112 Offset
= (Offset
<< 1) + Tag
;
115 return Current
+ Offset
;
126 } // End llvm namespace