xref: /freebsd/contrib/llvm-project/llvm/lib/CodeGen/GlobalISel/GISelChangeObserver.cpp (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
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 
13 #include "llvm/CodeGen/GlobalISel/GISelChangeObserver.h"
14 #include "llvm/CodeGen/MachineRegisterInfo.h"
15 
16 using namespace llvm;
17 
18 void GISelChangeObserver::changingAllUsesOfReg(
19     const MachineRegisterInfo &MRI, Register Reg) {
20   for (auto &ChangingMI : MRI.use_instructions(Reg)) {
21     changingInstr(ChangingMI);
22     ChangingAllUsesOfReg.insert(&ChangingMI);
23   }
24 }
25 
26 void GISelChangeObserver::finishedChangingAllUsesOfReg() {
27   for (auto *ChangedMI : ChangingAllUsesOfReg)
28     changedInstr(*ChangedMI);
29   ChangingAllUsesOfReg.clear();
30 }
31 
32 RAIIDelegateInstaller::RAIIDelegateInstaller(MachineFunction &MF,
33                                              MachineFunction::Delegate *Del)
34     : MF(MF), Delegate(Del) {
35   // Register this as the delegate for handling insertions and deletions of
36   // instructions.
37   MF.setDelegate(Del);
38 }
39 
40 RAIIDelegateInstaller::~RAIIDelegateInstaller() { MF.resetDelegate(Delegate); }
41 
42 RAIIMFObserverInstaller::RAIIMFObserverInstaller(MachineFunction &MF,
43                                                  GISelChangeObserver &Observer)
44     : MF(MF) {
45   MF.setObserver(&Observer);
46 }
47 
48 RAIIMFObserverInstaller::~RAIIMFObserverInstaller() { MF.setObserver(nullptr); }
49