LLVM API Documentation
00001 //===-- DelaySlotFiller.cpp - SPARC 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 // This is a simple local pass that fills delay slots with NOPs. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #define DEBUG_TYPE "delayslotfiller" 00015 #include "Sparc.h" 00016 #include "llvm/CodeGen/MachineFunctionPass.h" 00017 #include "llvm/CodeGen/MachineInstrBuilder.h" 00018 #include "llvm/Target/TargetMachine.h" 00019 #include "llvm/Target/TargetInstrInfo.h" 00020 #include "llvm/ADT/Statistic.h" 00021 using namespace llvm; 00022 00023 STATISTIC(FilledSlots, "Number of delay slots filled"); 00024 00025 namespace { 00026 struct Filler : public MachineFunctionPass { 00027 /// Target machine description which we query for reg. names, data 00028 /// layout, etc. 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 "SPARC 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 /// createSparcDelaySlotFillerPass - Returns a pass that fills in delay 00055 /// slots in Sparc MachineFunctions 00056 /// 00057 FunctionPass *llvm::createSparcDelaySlotFillerPass(TargetMachine &tm) { 00058 return new Filler(tm); 00059 } 00060 00061 /// runOnMachineBasicBlock - Fill in delay slots for the given basic block. 00062 /// Currently, we fill delay slots with NOPs. We assume there is only one 00063 /// delay slot per delayed instruction. 00064 /// 00065 bool Filler::runOnMachineBasicBlock(MachineBasicBlock &MBB) { 00066 bool Changed = false; 00067 for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I) 00068 if (I->getDesc().hasDelaySlot()) { 00069 MachineBasicBlock::iterator J = I; 00070 ++J; 00071 BuildMI(MBB, J, TII->get(SP::NOP)); 00072 ++FilledSlots; 00073 Changed = true; 00074 } 00075 return Changed; 00076 }