Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===-- DelaySlotFiller.cpp - SPARC delay slot filler ---------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This is a simple local pass that fills delay slots with NOPs. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #define DEBUG_TYPE "delayslotfiller" |
| 15 | #include "Sparc.h" |
| 16 | #include "llvm/CodeGen/MachineFunctionPass.h" |
| 17 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 18 | #include "llvm/Target/TargetMachine.h" |
| 19 | #include "llvm/Target/TargetInstrInfo.h" |
| 20 | #include "llvm/ADT/Statistic.h" |
| 21 | using namespace llvm; |
| 22 | |
| 23 | STATISTIC(FilledSlots, "Number of delay slots filled"); |
| 24 | |
| 25 | namespace { |
| 26 | struct Filler : public MachineFunctionPass { |
| 27 | /// Target machine description which we query for reg. names, data |
| 28 | /// layout, etc. |
| 29 | /// |
| 30 | TargetMachine &TM; |
| 31 | const TargetInstrInfo *TII; |
| 32 | |
| 33 | static char ID; |
| 34 | Filler(TargetMachine &tm) |
| 35 | : MachineFunctionPass((intptr_t)&ID), TM(tm), TII(tm.getInstrInfo()) { } |
| 36 | |
| 37 | virtual const char *getPassName() const { |
| 38 | return "SPARC 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 | /// createSparcDelaySlotFillerPass - Returns a pass that fills in delay |
| 55 | /// slots in Sparc MachineFunctions |
| 56 | /// |
| 57 | FunctionPass *llvm::createSparcDelaySlotFillerPass(TargetMachine &tm) { |
| 58 | return new Filler(tm); |
| 59 | } |
| 60 | |
| 61 | /// runOnMachineBasicBlock - Fill in delay slots for the given basic block. |
| 62 | /// Currently, we fill delay slots with NOPs. We assume there is only one |
| 63 | /// delay slot per delayed instruction. |
| 64 | /// |
| 65 | bool Filler::runOnMachineBasicBlock(MachineBasicBlock &MBB) { |
| 66 | bool Changed = false; |
| 67 | for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I) |
| 68 | if (TII->hasDelaySlot(I->getOpcode())) { |
| 69 | MachineBasicBlock::iterator J = I; |
| 70 | ++J; |
| 71 | BuildMI(MBB, J, TII->get(SP::NOP)); |
| 72 | ++FilledSlots; |
| 73 | Changed = true; |
| 74 | } |
| 75 | return Changed; |
| 76 | } |