1 //===-- Use.cpp - Implement the Use class ---------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "llvm/IR/Use.h"
10 #include "llvm/IR/User.h"
11 #include "llvm/IR/Value.h"
12 #include <new>
13 
14 namespace llvm {
15 
swap(Use & RHS)16 void Use::swap(Use &RHS) {
17   if (Val == RHS.Val)
18     return;
19 
20   std::swap(Val, RHS.Val);
21   std::swap(Next, RHS.Next);
22   std::swap(Prev, RHS.Prev);
23 
24   *Prev = this;
25   if (Next)
26     Next->Prev = &Next;
27 
28   *RHS.Prev = &RHS;
29   if (RHS.Next)
30     RHS.Next->Prev = &RHS.Next;
31 }
32 
getOperandNo() const33 unsigned Use::getOperandNo() const {
34   return this - getUser()->op_begin();
35 }
36 
zap(Use * Start,const Use * Stop,bool del)37 void Use::zap(Use *Start, const Use *Stop, bool del) {
38   while (Start != Stop)
39     (--Stop)->~Use();
40   if (del)
41     ::operator delete(Start);
42 }
43 
44 } // namespace llvm
45