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 //===----------------------------------------------------------------------===//
14 #define DEBUG_TYPE "delayslotfiller"
16 #include "llvm/CodeGen/MachineFunctionPass.h"
17 #include "llvm/CodeGen/MachineInstrBuilder.h"
18 #include "llvm/Target/TargetMachine.h"
19 #include "llvm/Target/TargetInstrInfo.h"
20 #include "llvm/ADT/Statistic.h"
23 STATISTIC(FilledSlots, "Number 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 "SPARC 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 /// createSparcDelaySlotFillerPass - Returns a pass that fills in delay
52 /// slots in Sparc MachineFunctions
54 FunctionPass *llvm::createSparcDelaySlotFillerPass(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, TII->get(SP::NOP));