1*0b57cec5SDimitry Andric //===-- lib/CodeGen/GlobalISel/GISelChangeObserver.cpp --------------------===// 2*0b57cec5SDimitry Andric // 3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0b57cec5SDimitry Andric // 7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 8*0b57cec5SDimitry Andric // 9*0b57cec5SDimitry Andric // This file constains common code to combine machine functions at generic 10*0b57cec5SDimitry Andric // level. 11*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 12*0b57cec5SDimitry Andric 13*0b57cec5SDimitry Andric #include "llvm/CodeGen/GlobalISel/GISelChangeObserver.h" 14*0b57cec5SDimitry Andric #include "llvm/CodeGen/MachineRegisterInfo.h" 15*0b57cec5SDimitry Andric 16*0b57cec5SDimitry Andric using namespace llvm; 17*0b57cec5SDimitry Andric 18*0b57cec5SDimitry Andric void GISelChangeObserver::changingAllUsesOfReg( 19*0b57cec5SDimitry Andric const MachineRegisterInfo &MRI, unsigned Reg) { 20*0b57cec5SDimitry Andric for (auto &ChangingMI : MRI.use_instructions(Reg)) { 21*0b57cec5SDimitry Andric changingInstr(ChangingMI); 22*0b57cec5SDimitry Andric ChangingAllUsesOfReg.insert(&ChangingMI); 23*0b57cec5SDimitry Andric } 24*0b57cec5SDimitry Andric } 25*0b57cec5SDimitry Andric 26*0b57cec5SDimitry Andric void GISelChangeObserver::finishedChangingAllUsesOfReg() { 27*0b57cec5SDimitry Andric for (auto *ChangedMI : ChangingAllUsesOfReg) 28*0b57cec5SDimitry Andric changedInstr(*ChangedMI); 29*0b57cec5SDimitry Andric ChangingAllUsesOfReg.clear(); 30*0b57cec5SDimitry Andric } 31*0b57cec5SDimitry Andric 32*0b57cec5SDimitry Andric RAIIDelegateInstaller::RAIIDelegateInstaller(MachineFunction &MF, 33*0b57cec5SDimitry Andric MachineFunction::Delegate *Del) 34*0b57cec5SDimitry Andric : MF(MF), Delegate(Del) { 35*0b57cec5SDimitry Andric // Register this as the delegate for handling insertions and deletions of 36*0b57cec5SDimitry Andric // instructions. 37*0b57cec5SDimitry Andric MF.setDelegate(Del); 38*0b57cec5SDimitry Andric } 39*0b57cec5SDimitry Andric 40*0b57cec5SDimitry Andric RAIIDelegateInstaller::~RAIIDelegateInstaller() { MF.resetDelegate(Delegate); } 41