blob: 09937dea26b72c764a05e501954214c51c429842 [file] [log] [blame]
Brian Gaeke20117102004-04-06 23:21:45 +00001//===-- 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//
Brian Gaeke870248b2004-09-30 04:04:47 +000010// This is a simple local pass that fills delay slots with NOPs.
Brian Gaeke20117102004-04-06 23:21:45 +000011//
12//===----------------------------------------------------------------------===//
13
14#include "SparcV8.h"
Brian Gaeke20117102004-04-06 23:21:45 +000015#include "llvm/CodeGen/MachineFunctionPass.h"
Brian Gaeke20117102004-04-06 23:21:45 +000016#include "llvm/CodeGen/MachineInstrBuilder.h"
Brian Gaeke870248b2004-09-30 04:04:47 +000017#include "llvm/Target/TargetMachine.h"
18#include "llvm/Target/TargetInstrInfo.h"
Brian Gaeke74dfcf12004-09-02 02:37:43 +000019#include "llvm/ADT/Statistic.h"
Brian Gaekeff828262004-04-06 23:25:07 +000020
Brian Gaeke20117102004-04-06 23:21:45 +000021using namespace llvm;
22
23namespace {
24 Statistic<> FilledSlots ("delayslotfiller", "Num. of delay slots filled");
25
26 struct Filler : public MachineFunctionPass {
27 /// Target machine description which we query for reg. names, data
28 /// layout, etc.
29 ///
30 TargetMachine &TM;
Brian Gaeke870248b2004-09-30 04:04:47 +000031 const TargetInstrInfo *TII;
Brian Gaeke20117102004-04-06 23:21:45 +000032
Brian Gaeke870248b2004-09-30 04:04:47 +000033 Filler (TargetMachine &tm) : TM (tm), TII (tm.getInstrInfo ()) { }
Brian Gaeke20117102004-04-06 23:21:45 +000034
35 virtual const char *getPassName () const {
36 return "SparcV8 Delay Slot Filler";
37 }
38
39 bool runOnMachineBasicBlock (MachineBasicBlock &MBB);
40 bool runOnMachineFunction (MachineFunction &F) {
41 bool Changed = false;
42 for (MachineFunction::iterator FI = F.begin (), FE = F.end ();
43 FI != FE; ++FI)
44 Changed |= runOnMachineBasicBlock (*FI);
45 return Changed;
46 }
47
48 };
49} // end of anonymous namespace
50
51/// createSparcV8DelaySlotFillerPass - Returns a pass that fills in delay
52/// slots in SparcV8 MachineFunctions
53///
54FunctionPass *llvm::createSparcV8DelaySlotFillerPass (TargetMachine &tm) {
55 return new Filler (tm);
56}
57
Brian Gaeke20117102004-04-06 23:21:45 +000058/// runOnMachineBasicBlock - Fill in delay slots for the given basic block.
Brian Gaeke0f51cc12004-04-07 04:05:12 +000059/// Currently, we fill delay slots with NOPs. We assume there is only one
60/// delay slot per delayed instruction.
Brian Gaeke20117102004-04-06 23:21:45 +000061///
62bool Filler::runOnMachineBasicBlock (MachineBasicBlock &MBB) {
Brian Gaeke0f51cc12004-04-07 04:05:12 +000063 bool Changed = false;
Brian Gaeke20117102004-04-06 23:21:45 +000064 for (MachineBasicBlock::iterator I = MBB.begin (); I != MBB.end (); ++I)
Brian Gaeke870248b2004-09-30 04:04:47 +000065 if (TII->hasDelaySlot (I->getOpcode ())) {
Brian Gaeke20117102004-04-06 23:21:45 +000066 MachineBasicBlock::iterator J = I;
67 ++J;
Brian Gaeke0f51cc12004-04-07 04:05:12 +000068 BuildMI (MBB, J, V8::NOP, 0);
Brian Gaeke20117102004-04-06 23:21:45 +000069 ++FilledSlots;
Brian Gaeke0f51cc12004-04-07 04:05:12 +000070 Changed = true;
Brian Gaeke20117102004-04-06 23:21:45 +000071 }
Brian Gaeke0f51cc12004-04-07 04:05:12 +000072 return Changed;
Brian Gaeke20117102004-04-06 23:21:45 +000073}