Bruno Cardoso Lopes | 9684a69 | 2007-08-18 01:50:47 +0000 | [diff] [blame] | 1 | //===-- DelaySlotFiller.cpp - Mips delay slot filler ---------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Bruno Cardoso Lopes | 9684a69 | 2007-08-18 01:50:47 +0000 | [diff] [blame] | 7 | // |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 9684a69 | 2007-08-18 01:50:47 +0000 | [diff] [blame] | 9 | // |
| 10 | // Simple pass to fills delay slots with NOPs. |
| 11 | // |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 9684a69 | 2007-08-18 01:50:47 +0000 | [diff] [blame] | 13 | |
| 14 | #define DEBUG_TYPE "delay-slot-filler" |
| 15 | |
| 16 | #include "Mips.h" |
| 17 | #include "MipsTargetMachine.h" |
| 18 | #include "llvm/CodeGen/MachineFunctionPass.h" |
| 19 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 20 | #include "llvm/Target/TargetInstrInfo.h" |
| 21 | #include "llvm/ADT/Statistic.h" |
| 22 | |
| 23 | using namespace llvm; |
| 24 | |
| 25 | STATISTIC(FilledSlots, "Number of delay slots filled"); |
| 26 | |
| 27 | namespace { |
| 28 | struct Filler : public MachineFunctionPass { |
| 29 | |
| 30 | TargetMachine &TM; |
| 31 | const TargetInstrInfo *TII; |
| 32 | |
| 33 | static char ID; |
Bruno Cardoso Lopes | 90c5954 | 2010-12-09 17:31:11 +0000 | [diff] [blame] | 34 | Filler(TargetMachine &tm) |
Owen Anderson | 90c579d | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 35 | : MachineFunctionPass(ID), TM(tm), TII(tm.getInstrInfo()) { } |
Bruno Cardoso Lopes | 9684a69 | 2007-08-18 01:50:47 +0000 | [diff] [blame] | 36 | |
| 37 | virtual const char *getPassName() const { |
| 38 | return "Mips Delay Slot Filler"; |
| 39 | } |
| 40 | |
| 41 | bool runOnMachineBasicBlock(MachineBasicBlock &MBB); |
| 42 | bool runOnMachineFunction(MachineFunction &F) { |
| 43 | bool Changed = false; |
| 44 | for (MachineFunction::iterator FI = F.begin(), FE = F.end(); |
| 45 | FI != FE; ++FI) |
| 46 | Changed |= runOnMachineBasicBlock(*FI); |
| 47 | return Changed; |
| 48 | } |
| 49 | |
| 50 | }; |
| 51 | char Filler::ID = 0; |
| 52 | } // end of anonymous namespace |
| 53 | |
| 54 | /// runOnMachineBasicBlock - Fill in delay slots for the given basic block. |
| 55 | /// Currently, we fill delay slots with NOPs. We assume there is only one |
| 56 | /// delay slot per delayed instruction. |
| 57 | bool Filler:: |
Bruno Cardoso Lopes | 90c5954 | 2010-12-09 17:31:11 +0000 | [diff] [blame] | 58 | runOnMachineBasicBlock(MachineBasicBlock &MBB) |
Bruno Cardoso Lopes | 9684a69 | 2007-08-18 01:50:47 +0000 | [diff] [blame] | 59 | { |
| 60 | bool Changed = false; |
Bruno Cardoso Lopes | 90c5954 | 2010-12-09 17:31:11 +0000 | [diff] [blame] | 61 | for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I) { |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 62 | const MCInstrDesc& MCid = I->getDesc(); |
| 63 | if (MCid.hasDelaySlot() && |
Bruno Cardoso Lopes | 90c5954 | 2010-12-09 17:31:11 +0000 | [diff] [blame] | 64 | (TM.getSubtarget<MipsSubtarget>().isMips1() || |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 65 | MCid.isCall() || MCid.isBranch() || MCid.isReturn())) { |
Bruno Cardoso Lopes | 9684a69 | 2007-08-18 01:50:47 +0000 | [diff] [blame] | 66 | MachineBasicBlock::iterator J = I; |
| 67 | ++J; |
Dale Johannesen | 9481757 | 2009-02-13 02:34:39 +0000 | [diff] [blame] | 68 | BuildMI(MBB, J, I->getDebugLoc(), TII->get(Mips::NOP)); |
Bruno Cardoso Lopes | 9684a69 | 2007-08-18 01:50:47 +0000 | [diff] [blame] | 69 | ++FilledSlots; |
| 70 | Changed = true; |
| 71 | } |
Bruno Cardoso Lopes | 90c5954 | 2010-12-09 17:31:11 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Bruno Cardoso Lopes | 9684a69 | 2007-08-18 01:50:47 +0000 | [diff] [blame] | 74 | return Changed; |
| 75 | } |
| 76 | |
| 77 | /// createMipsDelaySlotFillerPass - Returns a pass that fills in delay |
| 78 | /// slots in Mips MachineFunctions |
| 79 | FunctionPass *llvm::createMipsDelaySlotFillerPass(MipsTargetMachine &tm) { |
| 80 | return new Filler(tm); |
| 81 | } |
| 82 | |