Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 1 | //===-- DelaySlotFiller.cpp - SparcV8 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 | // Simple local delay slot filler for SparcV8 machine code |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "SparcV8.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 | 74dfcf1 | 2004-09-02 02:37:43 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/Statistic.h" |
Brian Gaeke | ff82826 | 2004-04-06 23:25:07 +0000 | [diff] [blame] | 18 | |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 19 | using namespace llvm; |
| 20 | |
| 21 | namespace { |
| 22 | Statistic<> FilledSlots ("delayslotfiller", "Num. of delay slots filled"); |
| 23 | |
| 24 | struct Filler : public MachineFunctionPass { |
| 25 | /// Target machine description which we query for reg. names, data |
| 26 | /// layout, etc. |
| 27 | /// |
| 28 | TargetMachine &TM; |
| 29 | |
| 30 | Filler (TargetMachine &tm) : TM (tm) { } |
| 31 | |
| 32 | virtual const char *getPassName () const { |
| 33 | return "SparcV8 Delay Slot Filler"; |
| 34 | } |
| 35 | |
| 36 | bool runOnMachineBasicBlock (MachineBasicBlock &MBB); |
| 37 | bool runOnMachineFunction (MachineFunction &F) { |
| 38 | bool Changed = false; |
| 39 | for (MachineFunction::iterator FI = F.begin (), FE = F.end (); |
| 40 | FI != FE; ++FI) |
| 41 | Changed |= runOnMachineBasicBlock (*FI); |
| 42 | return Changed; |
| 43 | } |
| 44 | |
| 45 | }; |
| 46 | } // end of anonymous namespace |
| 47 | |
| 48 | /// createSparcV8DelaySlotFillerPass - Returns a pass that fills in delay |
| 49 | /// slots in SparcV8 MachineFunctions |
| 50 | /// |
| 51 | FunctionPass *llvm::createSparcV8DelaySlotFillerPass (TargetMachine &tm) { |
| 52 | return new Filler (tm); |
| 53 | } |
| 54 | |
| 55 | static bool hasDelaySlot (unsigned Opcode) { |
| 56 | switch (Opcode) { |
Brian Gaeke | fc7fa31 | 2004-06-17 22:33:57 +0000 | [diff] [blame] | 57 | case V8::BA: |
| 58 | case V8::BCC: |
| 59 | case V8::BCS: |
| 60 | case V8::BE: |
| 61 | case V8::BG: |
| 62 | case V8::BGE: |
| 63 | case V8::BGU: |
| 64 | case V8::BL: |
| 65 | case V8::BLE: |
| 66 | case V8::BLEU: |
| 67 | case V8::BNE: |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 68 | case V8::CALL: |
Brian Gaeke | fbaae01 | 2004-06-18 08:18:54 +0000 | [diff] [blame] | 69 | case V8::JMPLrr: |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 70 | case V8::RETL: |
Brian Gaeke | 4185d03 | 2004-07-08 09:08:22 +0000 | [diff] [blame] | 71 | case V8::FBA: |
| 72 | case V8::FBN: |
| 73 | case V8::FBU: |
| 74 | case V8::FBG: |
| 75 | case V8::FBUG: |
| 76 | case V8::FBL: |
| 77 | case V8::FBUL: |
| 78 | case V8::FBLG: |
| 79 | case V8::FBNE: |
| 80 | case V8::FBE: |
| 81 | case V8::FBUE: |
| 82 | case V8::FBGE: |
| 83 | case V8::FBUGE: |
| 84 | case V8::FBLE: |
| 85 | case V8::FBULE: |
| 86 | case V8::FBO: |
| 87 | case V8::FCMPS: |
| 88 | case V8::FCMPD: |
| 89 | case V8::FCMPES: |
| 90 | case V8::FCMPED: |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 91 | return true; |
| 92 | default: |
| 93 | return false; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | /// runOnMachineBasicBlock - Fill in delay slots for the given basic block. |
Brian Gaeke | 0f51cc1 | 2004-04-07 04:05:12 +0000 | [diff] [blame] | 98 | /// Currently, we fill delay slots with NOPs. We assume there is only one |
| 99 | /// delay slot per delayed instruction. |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 100 | /// |
| 101 | bool Filler::runOnMachineBasicBlock (MachineBasicBlock &MBB) { |
Brian Gaeke | 0f51cc1 | 2004-04-07 04:05:12 +0000 | [diff] [blame] | 102 | bool Changed = false; |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 103 | for (MachineBasicBlock::iterator I = MBB.begin (); I != MBB.end (); ++I) |
| 104 | if (hasDelaySlot (I->getOpcode ())) { |
| 105 | MachineBasicBlock::iterator J = I; |
| 106 | ++J; |
Brian Gaeke | 0f51cc1 | 2004-04-07 04:05:12 +0000 | [diff] [blame] | 107 | BuildMI (MBB, J, V8::NOP, 0); |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 108 | ++FilledSlots; |
Brian Gaeke | 0f51cc1 | 2004-04-07 04:05:12 +0000 | [diff] [blame] | 109 | Changed = true; |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 110 | } |
Brian Gaeke | 0f51cc1 | 2004-04-07 04:05:12 +0000 | [diff] [blame] | 111 | return Changed; |
Brian Gaeke | 2011710 | 2004-04-06 23:21:45 +0000 | [diff] [blame] | 112 | } |