1 //===-- DelaySlotFiller.cpp - SPARC 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"
23 Statistic<> FilledSlots("delayslotfiller", "Num. of delay slots filled");
25 struct Filler : public MachineFunctionPass {
26 /// Target machine description which we query for reg. names, data
30 const TargetInstrInfo *TII;
32 Filler(TargetMachine &tm) : TM(tm), TII(tm.getInstrInfo()) { }
34 virtual const char *getPassName() const {
35 return "SPARC Delay Slot Filler";
38 bool runOnMachineBasicBlock(MachineBasicBlock &MBB);
39 bool runOnMachineFunction(MachineFunction &F) {
41 for (MachineFunction::iterator FI = F.begin(), FE = F.end();
43 Changed |= runOnMachineBasicBlock(*FI);
48 } // end of anonymous namespace
50 /// createSparcDelaySlotFillerPass - Returns a pass that fills in delay
51 /// slots in Sparc MachineFunctions
53 FunctionPass *llvm::createSparcDelaySlotFillerPass(TargetMachine &tm) {
54 return new Filler(tm);
57 /// runOnMachineBasicBlock - Fill in delay slots for the given basic block.
58 /// Currently, we fill delay slots with NOPs. We assume there is only one
59 /// delay slot per delayed instruction.
61 bool Filler::runOnMachineBasicBlock(MachineBasicBlock &MBB) {
63 for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I)
64 if (TII->hasDelaySlot(I->getOpcode())) {
65 MachineBasicBlock::iterator J = I;
67 BuildMI(MBB, J, SP::NOP, 0);