10b57cec5SDimitry Andric //===-- Use.cpp - Implement the Use class ---------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #include "llvm/IR/Use.h"
100b57cec5SDimitry Andric #include "llvm/IR/User.h"
110b57cec5SDimitry Andric #include "llvm/IR/Value.h"
120b57cec5SDimitry Andric #include <new>
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric namespace llvm {
150b57cec5SDimitry Andric 
swap(Use & RHS)160b57cec5SDimitry Andric void Use::swap(Use &RHS) {
170b57cec5SDimitry Andric   if (Val == RHS.Val)
180b57cec5SDimitry Andric     return;
190b57cec5SDimitry Andric 
20*af732203SDimitry Andric   std::swap(Val, RHS.Val);
21*af732203SDimitry Andric   std::swap(Next, RHS.Next);
22*af732203SDimitry Andric   std::swap(Prev, RHS.Prev);
230b57cec5SDimitry Andric 
24*af732203SDimitry Andric   *Prev = this;
25*af732203SDimitry Andric   if (Next)
26*af732203SDimitry Andric     Next->Prev = &Next;
270b57cec5SDimitry Andric 
28*af732203SDimitry Andric   *RHS.Prev = &RHS;
29*af732203SDimitry Andric   if (RHS.Next)
30*af732203SDimitry Andric     RHS.Next->Prev = &RHS.Next;
310b57cec5SDimitry Andric }
320b57cec5SDimitry Andric 
getOperandNo() const330b57cec5SDimitry Andric unsigned Use::getOperandNo() const {
340b57cec5SDimitry Andric   return this - getUser()->op_begin();
350b57cec5SDimitry Andric }
360b57cec5SDimitry Andric 
zap(Use * Start,const Use * Stop,bool del)370b57cec5SDimitry Andric void Use::zap(Use *Start, const Use *Stop, bool del) {
380b57cec5SDimitry Andric   while (Start != Stop)
390b57cec5SDimitry Andric     (--Stop)->~Use();
400b57cec5SDimitry Andric   if (del)
410b57cec5SDimitry Andric     ::operator delete(Start);
420b57cec5SDimitry Andric }
430b57cec5SDimitry Andric 
445ffd83dbSDimitry Andric } // namespace llvm
45