From d8e91e46262bc44006913e6796843909f1ac7bcd Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sat, 19 Jan 2019 10:01:25 +0000 Subject: Vendor import of llvm trunk r351319 (just before the release_80 branch point): https://llvm.org/svn/llvm-project/llvm/trunk@351319 --- lib/CodeGen/MachineInstrBundle.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'lib/CodeGen/MachineInstrBundle.cpp') diff --git a/lib/CodeGen/MachineInstrBundle.cpp b/lib/CodeGen/MachineInstrBundle.cpp index ed16a2b6084c1..ae378cc8c4647 100644 --- a/lib/CodeGen/MachineInstrBundle.cpp +++ b/lib/CodeGen/MachineInstrBundle.cpp @@ -105,6 +105,16 @@ bool FinalizeMachineBundles::runOnMachineFunction(MachineFunction &MF) { return llvm::finalizeBundles(MF); } +/// Return the first found DebugLoc that has a DILocation, given a range of +/// instructions. The search range is from FirstMI to LastMI (exclusive). If no +/// DILocation is found, then an empty location is returned. +static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, + MachineBasicBlock::instr_iterator LastMI) { + for (auto MII = FirstMI; MII != LastMI; ++MII) + if (MII->getDebugLoc().get()) + return MII->getDebugLoc(); + return DebugLoc(); +} /// finalizeBundle - Finalize a machine instruction bundle which includes /// a sequence of instructions starting from FirstMI to LastMI (exclusive). @@ -123,7 +133,7 @@ void llvm::finalizeBundle(MachineBasicBlock &MBB, const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo(); MachineInstrBuilder MIB = - BuildMI(MF, FirstMI->getDebugLoc(), TII->get(TargetOpcode::BUNDLE)); + BuildMI(MF, getDebugLoc(FirstMI, LastMI), TII->get(TargetOpcode::BUNDLE)); Bundle.prepend(MIB); SmallVector LocalDefs; @@ -135,9 +145,9 @@ void llvm::finalizeBundle(MachineBasicBlock &MBB, SmallSet KilledUseSet; SmallSet UndefUseSet; SmallVector Defs; - for (; FirstMI != LastMI; ++FirstMI) { - for (unsigned i = 0, e = FirstMI->getNumOperands(); i != e; ++i) { - MachineOperand &MO = FirstMI->getOperand(i); + for (auto MII = FirstMI; MII != LastMI; ++MII) { + for (unsigned i = 0, e = MII->getNumOperands(); i != e; ++i) { + MachineOperand &MO = MII->getOperand(i); if (!MO.isReg()) continue; if (MO.isDef()) { @@ -215,6 +225,15 @@ void llvm::finalizeBundle(MachineBasicBlock &MBB, MIB.addReg(Reg, getKillRegState(isKill) | getUndefRegState(isUndef) | getImplRegState(true)); } + + // Set FrameSetup/FrameDestroy for the bundle. If any of the instructions got + // the property, then also set it on the bundle. + for (auto MII = FirstMI; MII != LastMI; ++MII) { + if (MII->getFlag(MachineInstr::FrameSetup)) + MIB.setMIFlag(MachineInstr::FrameSetup); + if (MII->getFlag(MachineInstr::FrameDestroy)) + MIB.setMIFlag(MachineInstr::FrameDestroy); + } } /// finalizeBundle - Same functionality as the previous finalizeBundle except -- cgit v1.2.3