Use.cpp 1.0 KB

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