xref: /freebsd/contrib/llvm-project/llvm/lib/IR/Use.cpp (revision dd41de95a84d979615a2ef11df6850622bf6184e)
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 
16 void Use::swap(Use &RHS) {
17   if (Val == RHS.Val)
18     return;
19 
20   if (Val)
21     removeFromList();
22 
23   Value *OldVal = Val;
24   if (RHS.Val) {
25     RHS.removeFromList();
26     Val = RHS.Val;
27     Val->addUse(*this);
28   } else {
29     Val = nullptr;
30   }
31 
32   if (OldVal) {
33     RHS.Val = OldVal;
34     RHS.Val->addUse(RHS);
35   } else {
36     RHS.Val = nullptr;
37   }
38 }
39 
40 unsigned Use::getOperandNo() const {
41   return this - getUser()->op_begin();
42 }
43 
44 void Use::zap(Use *Start, const Use *Stop, bool del) {
45   while (Start != Stop)
46     (--Stop)->~Use();
47   if (del)
48     ::operator delete(Start);
49 }
50 
51 } // namespace llvm
52