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