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 | // |
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. |
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 | |
Devang Patel | 1997473 | 2007-05-03 01:11:54 +0000 | [diff] [blame] | 33 | static char ID; |
Devang Patel | 794fd75 | 2007-05-01 21:15:47 +0000 | [diff] [blame] | 34 | Filler(TargetMachine &tm) |
Owen Anderson | 1f74590 | 2010-08-06 00:23:35 +0000 | [diff] [blame] | 35 | : MachineFunctionPass(&ID), TM(tm), TII(tm.getInstrInfo()) { } |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 36 | |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 37 | virtual const char *getPassName() const { |
| 38 | return "SPARC Delay Slot Filler"; |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 41 | bool runOnMachineBasicBlock(MachineBasicBlock &MBB); |
| 42 | bool runOnMachineFunction(MachineFunction &F) { |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 43 | bool Changed = false; |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 44 | for (MachineFunction::iterator FI = F.begin(), FE = F.end(); |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 45 | FI != FE; ++FI) |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 46 | Changed |= runOnMachineBasicBlock(*FI); |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 47 | return Changed; |
| 48 | } |
| 49 | |
| 50 | }; |
Devang Patel | 1997473 | 2007-05-03 01:11:54 +0000 | [diff] [blame] | 51 | char Filler::ID = 0; |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 52 | } // end of anonymous namespace |
| 53 | |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 54 | /// createSparcDelaySlotFillerPass - Returns a pass that fills in delay |
| 55 | /// slots in Sparc MachineFunctions |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 56 | /// |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 57 | FunctionPass *llvm::createSparcDelaySlotFillerPass(TargetMachine &tm) { |
| 58 | return new Filler(tm); |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 61 | /// runOnMachineBasicBlock - Fill in delay slots for the given basic block. |
Brian Gaeke | 0f51cc1 | 2004-04-07 04:05:12 +0000 | [diff] [blame] | 62 | /// Currently, we fill delay slots with NOPs. We assume there is only one |
| 63 | /// delay slot per delayed instruction. |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 64 | /// |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 65 | bool Filler::runOnMachineBasicBlock(MachineBasicBlock &MBB) { |
Brian Gaeke | 0f51cc1 | 2004-04-07 04:05:12 +0000 | [diff] [blame] | 66 | bool Changed = false; |
Chris Lattner | 7c90f73 | 2006-02-05 05:50:24 +0000 | [diff] [blame] | 67 | for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I) |
Chris Lattner | 749c6f6 | 2008-01-07 07:27:27 +0000 | [diff] [blame] | 68 | if (I->getDesc().hasDelaySlot()) { |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 69 | MachineBasicBlock::iterator J = I; |
| 70 | ++J; |
Chris Lattner | c7f3ace | 2010-04-02 20:16:16 +0000 | [diff] [blame] | 71 | BuildMI(MBB, J, DebugLoc(), TII->get(SP::NOP)); |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 72 | ++FilledSlots; |
Brian Gaeke | 0f51cc1 | 2004-04-07 04:05:12 +0000 | [diff] [blame] | 73 | Changed = true; |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 74 | } |
Brian Gaeke | 0f51cc1 | 2004-04-07 04:05:12 +0000 | [diff] [blame] | 75 | return Changed; |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 76 | } |