DelaySlotFiller.cpp revision 870248b16491c9a9a604494b4e7aa94035af2158
1//===-- DelaySlotFiller.cpp - SparcV8 delay slot filler -------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 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. 7// 8//===----------------------------------------------------------------------===// 9// 10// This is a simple local pass that fills delay slots with NOPs. 11// 12//===----------------------------------------------------------------------===// 13 14#include "SparcV8.h" 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" 20 21using namespace llvm; 22 23namespace { 24 Statistic<> FilledSlots ("delayslotfiller", "Num. of delay slots filled"); 25 26 struct Filler : public MachineFunctionPass { 27 /// Target machine description which we query for reg. names, data 28 /// layout, etc. 29 /// 30 TargetMachine &TM; 31 const TargetInstrInfo *TII; 32 33 Filler (TargetMachine &tm) : TM (tm), TII (tm.getInstrInfo ()) { } 34 35 virtual const char *getPassName () const { 36 return "SparcV8 Delay Slot Filler"; 37 } 38 39 bool runOnMachineBasicBlock (MachineBasicBlock &MBB); 40 bool runOnMachineFunction (MachineFunction &F) { 41 bool Changed = false; 42 for (MachineFunction::iterator FI = F.begin (), FE = F.end (); 43 FI != FE; ++FI) 44 Changed |= runOnMachineBasicBlock (*FI); 45 return Changed; 46 } 47 48 }; 49} // end of anonymous namespace 50 51/// createSparcV8DelaySlotFillerPass - Returns a pass that fills in delay 52/// slots in SparcV8 MachineFunctions 53/// 54FunctionPass *llvm::createSparcV8DelaySlotFillerPass (TargetMachine &tm) { 55 return new Filler (tm); 56} 57 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. 61/// 62bool Filler::runOnMachineBasicBlock (MachineBasicBlock &MBB) { 63 bool Changed = false; 64 for (MachineBasicBlock::iterator I = MBB.begin (); I != MBB.end (); ++I) 65 if (TII->hasDelaySlot (I->getOpcode ())) { 66 MachineBasicBlock::iterator J = I; 67 ++J; 68 BuildMI (MBB, J, V8::NOP, 0); 69 ++FilledSlots; 70 Changed = true; 71 } 72 return Changed; 73} 74