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