diff --git a/llvm/include/llvm/CodeGen/TargetInstrInfo.h b/llvm/include/llvm/CodeGen/TargetInstrInfo.h --- a/llvm/include/llvm/CodeGen/TargetInstrInfo.h +++ b/llvm/include/llvm/CodeGen/TargetInstrInfo.h @@ -1148,8 +1148,8 @@ /// Return true if target supports reassociation of instructions in machine /// combiner pass to reduce register pressure for a given BB. virtual bool - shouldReduceRegisterPressure(MachineBasicBlock *MBB, - RegisterClassInfo *RegClassInfo) const { + shouldReduceRegisterPressure(const MachineBasicBlock *MBB, + const RegisterClassInfo *RegClassInfo) const { return false; } diff --git a/llvm/lib/Target/PowerPC/PPCInstrInfo.h b/llvm/lib/Target/PowerPC/PPCInstrInfo.h --- a/llvm/lib/Target/PowerPC/PPCInstrInfo.h +++ b/llvm/lib/Target/PowerPC/PPCInstrInfo.h @@ -471,9 +471,9 @@ /// when the register pressure is high for one BB. /// Return true if register pressure for \p MBB is high and ABI is supported /// to reduce register pressure. Otherwise return false. - bool - shouldReduceRegisterPressure(MachineBasicBlock *MBB, - RegisterClassInfo *RegClassInfo) const override; + bool shouldReduceRegisterPressure( + const MachineBasicBlock *MBB, + const RegisterClassInfo *RegClassInfo) const override; /// Fixup the placeholders we put in genAlternativeCodeSequence() for /// MachineCombiner. diff --git a/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp b/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp --- a/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp +++ b/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp @@ -613,7 +613,7 @@ } bool PPCInstrInfo::shouldReduceRegisterPressure( - MachineBasicBlock *MBB, RegisterClassInfo *RegClassInfo) const { + const MachineBasicBlock *MBB, const RegisterClassInfo *RegClassInfo) const { if (!EnableFMARegPressureReduction) return false; @@ -635,10 +635,11 @@ return false; const TargetRegisterInfo *TRI = &getRegisterInfo(); - MachineFunction *MF = MBB->getParent(); - MachineRegisterInfo *MRI = &MF->getRegInfo(); + const MachineFunction *MF = MBB->getParent(); + const MachineRegisterInfo *MRI = &MF->getRegInfo(); - auto GetMBBPressure = [&](MachineBasicBlock *MBB) -> std::vector { + auto GetMBBPressure = + [&](const MachineBasicBlock *MBB) -> std::vector { RegionPressure Pressure; RegPressureTracker RPTracker(Pressure); @@ -646,10 +647,7 @@ RPTracker.init(MBB->getParent(), RegClassInfo, nullptr, MBB, MBB->end(), /*TrackLaneMasks*/ false, /*TrackUntiedDefs=*/true); - for (MachineBasicBlock::iterator MII = MBB->instr_end(), - MIE = MBB->instr_begin(); - MII != MIE; --MII) { - MachineInstr &MI = *std::prev(MII); + for (const auto &MI : reverse(*MBB)) { if (MI.isDebugValue() || MI.isDebugLabel()) continue; RegisterOperands RegOpers;