1 //===-- DelaySlotFiller.cpp - SparcV8 delay slot filler -------------------===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This is a simple local pass that fills delay slots with NOPs.
12 //===----------------------------------------------------------------------===//
15 #include "llvm/CodeGen/MachineFunctionPass.h"
16 #include "llvm/CodeGen/MachineInstrBuilder.h"
17 #include "llvm/Target/TargetMachine.h"
18 #include "llvm/Target/TargetInstrInfo.h"
19 #include "llvm/ADT/Statistic.h"
24 Statistic<> FilledSlots ("delayslotfiller", "Num. of delay slots filled");
26 struct Filler : public MachineFunctionPass {
27 /// Target machine description which we query for reg. names, data
31 const TargetInstrInfo *TII;
33 Filler (TargetMachine &tm) : TM (tm), TII (tm.getInstrInfo ()) { }
35 virtual const char *getPassName () const {
36 return "SparcV8 Delay Slot Filler";
39 bool runOnMachineBasicBlock (MachineBasicBlock &MBB);
40 bool runOnMachineFunction (MachineFunction &F) {
42 for (MachineFunction::iterator FI = F.begin (), FE = F.end ();
44 Changed |= runOnMachineBasicBlock (*FI);
49 } // end of anonymous namespace
51 /// createSparcV8DelaySlotFillerPass - Returns a pass that fills in delay
52 /// slots in SparcV8 MachineFunctions
54 FunctionPass *llvm::createSparcV8DelaySlotFillerPass (TargetMachine &tm) {
55 return new Filler (tm);
58 /// runOnMachineBasicBlock - Fill in delay slots for the given basic block.
59 /// Currently, we fill delay slots with NOPs. We assume there is only one
60 /// delay slot per delayed instruction.
62 bool Filler::runOnMachineBasicBlock (MachineBasicBlock &MBB) {
64 for (MachineBasicBlock::iterator I = MBB.begin (); I != MBB.end (); ++I)
65 if (TII->hasDelaySlot (I->getOpcode ())) {
66 MachineBasicBlock::iterator J = I;
68 BuildMI (MBB, J, V8::NOP, 0);