Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 1 | //===-- DelaySlotFiller.cpp - SPARC delay slot filler ---------------------===// |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 2 | // |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 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. |
Misha Brukman | b5f662f | 2005-04-21 23:30:14 +0000 | [diff] [blame] | 7 | // |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Brian Gaeke | 870248b | 2004-09-30 04:04:47 +0000 | [diff] [blame] | 10 | // This is a simple local pass that fills delay slots with NOPs. |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 14 | #include "Sparc.h" |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Brian Gaeke | 870248b | 2004-09-30 04:04:47 +0000 | [diff] [blame] | 17 | #include "llvm/Target/TargetMachine.h" |
| 18 | #include "llvm/Target/TargetInstrInfo.h" |
Brian Gaeke | 74dfcf1 | 2004-09-02 02:37:43 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/Statistic.h" |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 20 | using namespace llvm; |
| 21 | |
| 22 | namespace { |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 23 | Statistic<> FilledSlots("delayslotfiller", "Num. of delay slots filled"); |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 24 | |
| 25 | struct Filler : public MachineFunctionPass { |
| 26 | /// Target machine description which we query for reg. names, data |
| 27 | /// layout, etc. |
| 28 | /// |
| 29 | TargetMachine &TM; |
Brian Gaeke | 870248b | 2004-09-30 04:04:47 +0000 | [diff] [blame] | 30 | const TargetInstrInfo *TII; |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 31 | |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 32 | Filler(TargetMachine &tm) : TM(tm), TII(tm.getInstrInfo()) { } |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 33 | |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 34 | virtual const char *getPassName() const { |
| 35 | return "SPARC Delay Slot Filler"; |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 38 | bool runOnMachineBasicBlock(MachineBasicBlock &MBB); |
| 39 | bool runOnMachineFunction(MachineFunction &F) { |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 40 | bool Changed = false; |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 41 | for (MachineFunction::iterator FI = F.begin(), FE = F.end(); |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 42 | FI != FE; ++FI) |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 43 | Changed |= runOnMachineBasicBlock(*FI); |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 44 | return Changed; |
| 45 | } |
| 46 | |
| 47 | }; |
| 48 | } // end of anonymous namespace |
| 49 | |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 50 | /// createSparcDelaySlotFillerPass - Returns a pass that fills in delay |
| 51 | /// slots in Sparc MachineFunctions |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 52 | /// |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 53 | FunctionPass *llvm::createSparcDelaySlotFillerPass(TargetMachine &tm) { |
| 54 | return new Filler(tm); |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 57 | /// runOnMachineBasicBlock - Fill in delay slots for the given basic block. |
Brian Gaeke | 0f51cc1 | 2004-04-07 04:05:12 +0000 | [diff] [blame] | 58 | /// Currently, we fill delay slots with NOPs. We assume there is only one |
| 59 | /// delay slot per delayed instruction. |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 60 | /// |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 61 | bool Filler::runOnMachineBasicBlock(MachineBasicBlock &MBB) { |
Brian Gaeke | 0f51cc1 | 2004-04-07 04:05:12 +0000 | [diff] [blame] | 62 | bool Changed = false; |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 63 | for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I) |
| 64 | if (TII->hasDelaySlot(I->getOpcode())) { |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 65 | MachineBasicBlock::iterator J = I; |
| 66 | ++J; |
Evan Cheng | c0f64ff | 2006-11-27 23:37:22 +0000 | [diff] [blame^] | 67 | BuildMI(MBB, J, TII->get(SP::NOP)); |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 68 | ++FilledSlots; |
Brian Gaeke | 0f51cc1 | 2004-04-07 04:05:12 +0000 | [diff] [blame] | 69 | Changed = true; |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 70 | } |
Brian Gaeke | 0f51cc1 | 2004-04-07 04:05:12 +0000 | [diff] [blame] | 71 | return Changed; |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 72 | } |