GISelChangeObserver.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //===-- lib/CodeGen/GlobalISel/GISelChangeObserver.cpp --------------------===//
  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. // This file constains common code to combine machine functions at generic
  10. // level.
  11. //===----------------------------------------------------------------------===//
  12. #include "llvm/CodeGen/GlobalISel/GISelChangeObserver.h"
  13. #include "llvm/CodeGen/MachineRegisterInfo.h"
  14. using namespace llvm;
  15. void GISelChangeObserver::changingAllUsesOfReg(
  16. const MachineRegisterInfo &MRI, Register Reg) {
  17. for (auto &ChangingMI : MRI.use_instructions(Reg)) {
  18. changingInstr(ChangingMI);
  19. ChangingAllUsesOfReg.insert(&ChangingMI);
  20. }
  21. }
  22. void GISelChangeObserver::finishedChangingAllUsesOfReg() {
  23. for (auto *ChangedMI : ChangingAllUsesOfReg)
  24. changedInstr(*ChangedMI);
  25. ChangingAllUsesOfReg.clear();
  26. }
  27. RAIIDelegateInstaller::RAIIDelegateInstaller(MachineFunction &MF,
  28. MachineFunction::Delegate *Del)
  29. : MF(MF), Delegate(Del) {
  30. // Register this as the delegate for handling insertions and deletions of
  31. // instructions.
  32. MF.setDelegate(Del);
  33. }
  34. RAIIDelegateInstaller::~RAIIDelegateInstaller() { MF.resetDelegate(Delegate); }
  35. RAIIMFObserverInstaller::RAIIMFObserverInstaller(MachineFunction &MF,
  36. GISelChangeObserver &Observer)
  37. : MF(MF) {
  38. MF.setObserver(&Observer);
  39. }
  40. RAIIMFObserverInstaller::~RAIIMFObserverInstaller() { MF.setObserver(nullptr); }