From bca15f9c8059ccb9244853f86593c35ac35c8801 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Thu, 19 Jan 2012 00:46:06 +0000 Subject: [PATCH] - Slight change to finalizeBundle() interface. LastMI is not exclusive (pointing to instruction right after the last instruction in the bundle. - Add a finalizeBundle() variant that doesn't specify LastMI. Instead, the code will find the last instruction in the bundle by following the 'InsideBundle' marker. This is useful in case bundles are formed early (i.e. during MI scheduling) but finalized later (i.e. after register allocator has finished rewriting virtual registers with physical registers). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148444 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/MachineInstrBundle.h | 9 ++++++++- lib/CodeGen/MachineInstrBundle.cpp | 21 ++++++++++++++++++--- lib/Target/ARM/Thumb2ITBlockPass.cpp | 3 ++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/include/llvm/CodeGen/MachineInstrBundle.h b/include/llvm/CodeGen/MachineInstrBundle.h index 2bc78ccbfe6..8189507a9e3 100644 --- a/include/llvm/CodeGen/MachineInstrBundle.h +++ b/include/llvm/CodeGen/MachineInstrBundle.h @@ -20,7 +20,7 @@ namespace llvm { /// finalizeBundle - Finalize a machine instruction bundle which includes -/// a sequence of instructions starting from FirstMI to LastMI (inclusive). +/// a sequence of instructions starting from FirstMI to LastMI (exclusive). /// This routine adds a BUNDLE instruction to represent the bundle, it adds /// IsInternalRead markers to MachineOperands which are defined inside the /// bundle, and it copies externally visible defs and uses to the BUNDLE @@ -29,6 +29,13 @@ void finalizeBundle(MachineBasicBlock &MBB, MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI); +/// finalizeBundle - Same functionality as the previous finalizeBundle except +/// the last instruction in the bundle is not provided as an input. This is +/// used in cases where bundles are pre-determined by marking instructions +/// with 'InsideBundle' marker. +void finalizeBundle(MachineBasicBlock &MBB, + MachineBasicBlock::instr_iterator FirstMI); + } // End llvm namespace #endif diff --git a/lib/CodeGen/MachineInstrBundle.cpp b/lib/CodeGen/MachineInstrBundle.cpp index ce8c09a3e92..7873fd0bdf3 100644 --- a/lib/CodeGen/MachineInstrBundle.cpp +++ b/lib/CodeGen/MachineInstrBundle.cpp @@ -72,7 +72,7 @@ bool UnpackMachineBundles::runOnMachineFunction(MachineFunction &MF) { } /// finalizeBundle - Finalize a machine instruction bundle which includes -/// a sequence of instructions starting from FirstMI to LastMI (inclusive). +/// a sequence of instructions starting from FirstMI to LastMI (exclusive). /// This routine adds a BUNDLE instruction to represent the bundle, it adds /// IsInternalRead markers to MachineOperands which are defined inside the /// bundle, and it copies externally visible defs and uses to the BUNDLE @@ -80,6 +80,8 @@ bool UnpackMachineBundles::runOnMachineFunction(MachineFunction &MF) { void llvm::finalizeBundle(MachineBasicBlock &MBB, MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI) { + assert(FirstMI != LastMI && "Empty bundle?"); + const TargetMachine &TM = MBB.getParent()->getTarget(); const TargetInstrInfo *TII = TM.getInstrInfo(); const TargetRegisterInfo *TRI = TM.getRegisterInfo(); @@ -96,7 +98,7 @@ void llvm::finalizeBundle(MachineBasicBlock &MBB, SmallSet KilledUseSet; SmallSet UndefUseSet; SmallVector Defs; - do { + for (; FirstMI != LastMI; ++FirstMI) { for (unsigned i = 0, e = FirstMI->getNumOperands(); i != e; ++i) { MachineOperand &MO = FirstMI->getOperand(i); if (!MO.isReg()) @@ -157,7 +159,7 @@ void llvm::finalizeBundle(MachineBasicBlock &MBB, FirstMI->setIsInsideBundle(); Defs.clear(); - } while (FirstMI++ != LastMI); + } SmallSet Added; for (unsigned i = 0, e = LocalDefs.size(); i != e; ++i) { @@ -178,3 +180,16 @@ void llvm::finalizeBundle(MachineBasicBlock &MBB, getImplRegState(true)); } } + +/// finalizeBundle - Same functionality as the previous finalizeBundle except +/// the last instruction in the bundle is not provided as an input. This is +/// used in cases where bundles are pre-determined by marking instructions +/// with 'InsideBundle' marker. +void llvm::finalizeBundle(MachineBasicBlock &MBB, + MachineBasicBlock::instr_iterator FirstMI) { + MachineBasicBlock::instr_iterator E = MBB.instr_end(); + MachineBasicBlock::instr_iterator LastMI = llvm::next(FirstMI); + while (LastMI != E && LastMI->isInsideBundle()) + ++LastMI; + finalizeBundle(MBB, FirstMI, LastMI); +} diff --git a/lib/Target/ARM/Thumb2ITBlockPass.cpp b/lib/Target/ARM/Thumb2ITBlockPass.cpp index 6c4bb96835a..b13ab216c3d 100644 --- a/lib/Target/ARM/Thumb2ITBlockPass.cpp +++ b/lib/Target/ARM/Thumb2ITBlockPass.cpp @@ -239,7 +239,8 @@ bool Thumb2ITBlockPass::InsertITInstructions(MachineBasicBlock &MBB) { LastITMI->findRegisterUseOperand(ARM::ITSTATE)->setIsKill(); // Finalize the bundle. - finalizeBundle(MBB, InsertPos.getInstrIterator(), LastITMI); + MachineBasicBlock::instr_iterator LI = LastITMI; + finalizeBundle(MBB, InsertPos.getInstrIterator(), llvm::next(LI)); Modified = true; ++NumITs;