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