1 //===-- DelaySlotFiller.cpp - SPARC delay slot filler ---------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // 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
;
34 Filler(TargetMachine
&tm
)
35 : MachineFunctionPass(&ID
), TM(tm
), TII(tm
.getInstrInfo()) { }
37 virtual const char *getPassName() const {
38 return "SPARC 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 /// createSparcDelaySlotFillerPass - Returns a pass that fills in delay
55 /// slots in Sparc MachineFunctions
57 FunctionPass
*llvm::createSparcDelaySlotFillerPass(TargetMachine
&tm
) {
58 return new Filler(tm
);
61 /// runOnMachineBasicBlock - Fill in delay slots for the given basic block.
62 /// Currently, we fill delay slots with NOPs. We assume there is only one
63 /// delay slot per delayed instruction.
65 bool Filler::runOnMachineBasicBlock(MachineBasicBlock
&MBB
) {
67 for (MachineBasicBlock::iterator I
= MBB
.begin(); I
!= MBB
.end(); ++I
)
68 if (I
->getDesc().hasDelaySlot()) {
69 MachineBasicBlock::iterator J
= I
;
71 BuildMI(MBB
, J
, DebugLoc::getUnknownLoc(), TII
->get(SP::NOP
));