xref: /freebsd/contrib/llvm-project/llvm/lib/IR/Use.cpp (revision e8d8bef961a50d4dc22501cde4fb9fb0be1b2532)
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 
160b57cec5SDimitry Andric void Use::swap(Use &RHS) {
170b57cec5SDimitry Andric   if (Val == RHS.Val)
180b57cec5SDimitry Andric     return;
190b57cec5SDimitry Andric 
20*e8d8bef9SDimitry Andric   std::swap(Val, RHS.Val);
21*e8d8bef9SDimitry Andric   std::swap(Next, RHS.Next);
22*e8d8bef9SDimitry Andric   std::swap(Prev, RHS.Prev);
230b57cec5SDimitry Andric 
24*e8d8bef9SDimitry Andric   *Prev = this;
25*e8d8bef9SDimitry Andric   if (Next)
26*e8d8bef9SDimitry Andric     Next->Prev = &Next;
270b57cec5SDimitry Andric 
28*e8d8bef9SDimitry Andric   *RHS.Prev = &RHS;
29*e8d8bef9SDimitry Andric   if (RHS.Next)
30*e8d8bef9SDimitry Andric     RHS.Next->Prev = &RHS.Next;
310b57cec5SDimitry Andric }
320b57cec5SDimitry Andric 
330b57cec5SDimitry Andric unsigned Use::getOperandNo() const {
340b57cec5SDimitry Andric   return this - getUser()->op_begin();
350b57cec5SDimitry Andric }
360b57cec5SDimitry Andric 
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