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 // Simple local delay slot filler for SparcV8 machine code
12 //===----------------------------------------------------------------------===//
15 #include "llvm/CodeGen/MachineFunctionPass.h"
16 #include "llvm/CodeGen/MachineInstrBuilder.h"
17 #include "Support/Statistic.h"
22 Statistic<> FilledSlots ("delayslotfiller", "Num. of delay slots filled");
24 struct Filler : public MachineFunctionPass {
25 /// Target machine description which we query for reg. names, data
30 Filler (TargetMachine &tm) : TM (tm) { }
32 virtual const char *getPassName () const {
33 return "SparcV8 Delay Slot Filler";
36 bool runOnMachineBasicBlock (MachineBasicBlock &MBB);
37 bool runOnMachineFunction (MachineFunction &F) {
39 for (MachineFunction::iterator FI = F.begin (), FE = F.end ();
41 Changed |= runOnMachineBasicBlock (*FI);
46 } // end of anonymous namespace
48 /// createSparcV8DelaySlotFillerPass - Returns a pass that fills in delay
49 /// slots in SparcV8 MachineFunctions
51 FunctionPass *llvm::createSparcV8DelaySlotFillerPass (TargetMachine &tm) {
52 return new Filler (tm);
55 static bool hasDelaySlot (unsigned Opcode) {
77 /// runOnMachineBasicBlock - Fill in delay slots for the given basic block.
78 /// Currently, we fill delay slots with NOPs. We assume there is only one
79 /// delay slot per delayed instruction.
81 bool Filler::runOnMachineBasicBlock (MachineBasicBlock &MBB) {
83 for (MachineBasicBlock::iterator I = MBB.begin (); I != MBB.end (); ++I)
84 if (hasDelaySlot (I->getOpcode ())) {
85 MachineBasicBlock::iterator J = I;
87 BuildMI (MBB, J, V8::NOP, 0);