Index: lib/CodeGen/CMakeLists.txt =================================================================== --- lib/CodeGen/CMakeLists.txt +++ lib/CodeGen/CMakeLists.txt @@ -117,6 +117,7 @@ TargetRegisterInfo.cpp TargetSchedule.cpp TwoAddressInstructionPass.cpp + UnpackMachineBundles.cpp UnreachableBlockElim.cpp VirtRegMap.cpp WinEHPrepare.cpp Index: lib/CodeGen/MachineInstrBundle.cpp =================================================================== --- lib/CodeGen/MachineInstrBundle.cpp +++ lib/CodeGen/MachineInstrBundle.cpp @@ -20,57 +20,6 @@ using namespace llvm; namespace { - class UnpackMachineBundles : public MachineFunctionPass { - public: - static char ID; // Pass identification - UnpackMachineBundles() : MachineFunctionPass(ID) { - initializeUnpackMachineBundlesPass(*PassRegistry::getPassRegistry()); - } - - bool runOnMachineFunction(MachineFunction &MF) override; - }; -} // end anonymous namespace - -char UnpackMachineBundles::ID = 0; -char &llvm::UnpackMachineBundlesID = UnpackMachineBundles::ID; -INITIALIZE_PASS(UnpackMachineBundles, "unpack-mi-bundles", - "Unpack machine instruction bundles", false, false) - -bool UnpackMachineBundles::runOnMachineFunction(MachineFunction &MF) { - bool Changed = false; - for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) { - MachineBasicBlock *MBB = &*I; - - for (MachineBasicBlock::instr_iterator MII = MBB->instr_begin(), - MIE = MBB->instr_end(); MII != MIE; ) { - MachineInstr *MI = &*MII; - - // Remove BUNDLE instruction and the InsideBundle flags from bundled - // instructions. - if (MI->isBundle()) { - while (++MII != MIE && MII->isBundledWithPred()) { - MII->unbundleFromPred(); - for (unsigned i = 0, e = MII->getNumOperands(); i != e; ++i) { - MachineOperand &MO = MII->getOperand(i); - if (MO.isReg() && MO.isInternalRead()) - MO.setIsInternalRead(false); - } - } - MI->eraseFromParent(); - - Changed = true; - continue; - } - - ++MII; - } - } - - return Changed; -} - - -namespace { class FinalizeMachineBundles : public MachineFunctionPass { public: static char ID; // Pass identification Index: lib/CodeGen/UnpackMachineBundles.cpp =================================================================== --- /dev/null +++ lib/CodeGen/UnpackMachineBundles.cpp @@ -0,0 +1,72 @@ +//===-- lib/CodeGen/UnpackMachineBundle.cpp -------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements the UnpackMachineBundles pass. +// +//===----------------------------------------------------------------------===// + +#include "llvm/CodeGen/MachineFunction.h" +#include "llvm/CodeGen/MachineFunctionPass.h" +#include "llvm/CodeGen/MachineInstrBundle.h" +#include "llvm/CodeGen/Passes.h" + +using namespace llvm; + +namespace { + +class UnpackMachineBundles : public MachineFunctionPass { +public: + static char ID; // Pass identification + UnpackMachineBundles() : MachineFunctionPass(ID) { + initializeUnpackMachineBundlesPass(*PassRegistry::getPassRegistry()); + } + + bool runOnMachineFunction(MachineFunction &MF) override; +}; + +} // end anonymous namespace + +char UnpackMachineBundles::ID = 0; +char &llvm::UnpackMachineBundlesID = UnpackMachineBundles::ID; +INITIALIZE_PASS(UnpackMachineBundles, "unpack-mi-bundles", + "Unpack machine instruction bundles", false, false) + +bool UnpackMachineBundles::runOnMachineFunction(MachineFunction &MF) { + bool Changed = false; + for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) { + MachineBasicBlock *MBB = &*I; + + for (MachineBasicBlock::instr_iterator MII = MBB->instr_begin(), + MIE = MBB->instr_end(); + MII != MIE;) { + MachineInstr *MI = &*MII; + + // Remove BUNDLE instruction and the InsideBundle flags from bundled + // instructions. + if (MI->isBundle()) { + while (++MII != MIE && MII->isBundledWithPred()) { + MII->unbundleFromPred(); + for (unsigned i = 0, e = MII->getNumOperands(); i != e; ++i) { + MachineOperand &MO = MII->getOperand(i); + if (MO.isReg() && MO.isInternalRead()) + MO.setIsInternalRead(false); + } + } + MI->eraseFromParent(); + + Changed = true; + continue; + } + + ++MII; + } + } + + return Changed; +}