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 "SparcV8InstrInfo.h"
16 #include "llvm/Constants.h"
17 #include "llvm/DerivedTypes.h"
18 #include "llvm/Module.h"
19 #include "llvm/Assembly/Writer.h"
20 #include "llvm/CodeGen/MachineFunctionPass.h"
21 #include "llvm/CodeGen/MachineConstantPool.h"
22 #include "llvm/CodeGen/MachineInstr.h"
23 #include "llvm/CodeGen/MachineInstrBuilder.h"
24 #include "llvm/Target/TargetMachine.h"
25 #include "llvm/Support/Mangler.h"
26 #include "Support/Statistic.h"
27 #include "Support/StringExtras.h"
28 #include "Support/CommandLine.h"
33 Statistic<> FilledSlots ("delayslotfiller", "Num. of delay slots filled");
35 struct Filler : public MachineFunctionPass {
36 /// Target machine description which we query for reg. names, data
41 Filler (TargetMachine &tm) : TM (tm) { }
43 virtual const char *getPassName () const {
44 return "SparcV8 Delay Slot Filler";
47 bool runOnMachineBasicBlock (MachineBasicBlock &MBB);
48 bool runOnMachineFunction (MachineFunction &F) {
50 for (MachineFunction::iterator FI = F.begin (), FE = F.end ();
52 Changed |= runOnMachineBasicBlock (*FI);
57 } // end of anonymous namespace
59 /// createSparcV8DelaySlotFillerPass - Returns a pass that fills in delay
60 /// slots in SparcV8 MachineFunctions
62 FunctionPass *llvm::createSparcV8DelaySlotFillerPass (TargetMachine &tm) {
63 return new Filler (tm);
66 static bool hasDelaySlot (unsigned Opcode) {
76 /// runOnMachineBasicBlock - Fill in delay slots for the given basic block.
78 bool Filler::runOnMachineBasicBlock (MachineBasicBlock &MBB) {
79 for (MachineBasicBlock::iterator I = MBB.begin (); I != MBB.end (); ++I)
80 if (hasDelaySlot (I->getOpcode ())) {
81 MachineBasicBlock::iterator J = I;
83 MBB.insert (J, BuildMI (V8::NOP, 0));