LLVM API Documentation
00001 //===-- DelaySlotFiller.cpp - Mips delay slot filler ---------------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // Simple pass to fills delay slots with NOPs. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #define DEBUG_TYPE "delay-slot-filler" 00015 00016 #include "Mips.h" 00017 #include "MipsTargetMachine.h" 00018 #include "llvm/CodeGen/MachineFunctionPass.h" 00019 #include "llvm/CodeGen/MachineInstrBuilder.h" 00020 #include "llvm/Target/TargetInstrInfo.h" 00021 #include "llvm/ADT/Statistic.h" 00022 00023 using namespace llvm; 00024 00025 STATISTIC(FilledSlots, "Number of delay slots filled"); 00026 00027 namespace { 00028 struct Filler : public MachineFunctionPass { 00029 00030 TargetMachine &TM; 00031 const TargetInstrInfo *TII; 00032 00033 static char ID; 00034 Filler(TargetMachine &tm) 00035 : MachineFunctionPass(&ID), TM(tm), TII(tm.getInstrInfo()) { } 00036 00037 virtual const char *getPassName() const { 00038 return "Mips Delay Slot Filler"; 00039 } 00040 00041 bool runOnMachineBasicBlock(MachineBasicBlock &MBB); 00042 bool runOnMachineFunction(MachineFunction &F) { 00043 bool Changed = false; 00044 for (MachineFunction::iterator FI = F.begin(), FE = F.end(); 00045 FI != FE; ++FI) 00046 Changed |= runOnMachineBasicBlock(*FI); 00047 return Changed; 00048 } 00049 00050 }; 00051 char Filler::ID = 0; 00052 } // end of anonymous namespace 00053 00054 /// runOnMachineBasicBlock - Fill in delay slots for the given basic block. 00055 /// Currently, we fill delay slots with NOPs. We assume there is only one 00056 /// delay slot per delayed instruction. 00057 bool Filler:: 00058 runOnMachineBasicBlock(MachineBasicBlock &MBB) 00059 { 00060 bool Changed = false; 00061 for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I) 00062 if (I->getDesc().hasDelaySlot()) { 00063 MachineBasicBlock::iterator J = I; 00064 ++J; 00065 BuildMI(MBB, J, TII->get(Mips::NOP)); 00066 ++FilledSlots; 00067 Changed = true; 00068 } 00069 return Changed; 00070 } 00071 00072 /// createMipsDelaySlotFillerPass - Returns a pass that fills in delay 00073 /// slots in Mips MachineFunctions 00074 FunctionPass *llvm::createMipsDelaySlotFillerPass(MipsTargetMachine &tm) { 00075 return new Filler(tm); 00076 } 00077