Use.cpp 998 B

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