Use.cpp 956 B

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