1 //===-- DelaySlotFiller.cpp - Mips delay slot filler ---------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Bruno Cardoso Lopes and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Simple pass to fills delay slots with NOPs.
12 //===----------------------------------------------------------------------===//
14 #define DEBUG_TYPE "delay-slot-filler"
17 #include "MipsTargetMachine.h"
18 #include "llvm/CodeGen/MachineFunctionPass.h"
19 #include "llvm/CodeGen/MachineInstrBuilder.h"
20 #include "llvm/Target/TargetInstrInfo.h"
21 #include "llvm/ADT/Statistic.h"
25 STATISTIC(FilledSlots, "Number of delay slots filled");
28 struct Filler : public MachineFunctionPass {
31 const TargetInstrInfo *TII;
34 Filler(TargetMachine &tm)
35 : MachineFunctionPass((intptr_t)&ID), TM(tm), TII(tm.getInstrInfo()) { }
37 virtual const char *getPassName() const {
38 return "Mips Delay Slot Filler";
41 bool runOnMachineBasicBlock(MachineBasicBlock &MBB);
42 bool runOnMachineFunction(MachineFunction &F) {
44 for (MachineFunction::iterator FI = F.begin(), FE = F.end();
46 Changed |= runOnMachineBasicBlock(*FI);
52 } // end of anonymous namespace
54 /// runOnMachineBasicBlock - Fill in delay slots for the given basic block.
55 /// Currently, we fill delay slots with NOPs. We assume there is only one
56 /// delay slot per delayed instruction.
58 runOnMachineBasicBlock(MachineBasicBlock &MBB)
61 for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I)
62 if (TII->hasDelaySlot(I->getOpcode())) {
63 MachineBasicBlock::iterator J = I;
65 BuildMI(MBB, J, TII->get(Mips::NOP));
72 /// createMipsDelaySlotFillerPass - Returns a pass that fills in delay
73 /// slots in Mips MachineFunctions
74 FunctionPass *llvm::createMipsDelaySlotFillerPass(MipsTargetMachine &tm) {
75 return new Filler(tm);