LLVM API Documentation
00001 //===-- DelaySlotFiller.cpp - SPARC delay slot filler ---------------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file was developed by the LLVM research group and is distributed under 00006 // the University of Illinois Open Source 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 #include "Sparc.h" 00015 #include "llvm/CodeGen/MachineFunctionPass.h" 00016 #include "llvm/CodeGen/MachineInstrBuilder.h" 00017 #include "llvm/Target/TargetMachine.h" 00018 #include "llvm/Target/TargetInstrInfo.h" 00019 #include "llvm/ADT/Statistic.h" 00020 using namespace llvm; 00021 00022 namespace { 00023 Statistic<> FilledSlots("delayslotfiller", "Num. of delay slots filled"); 00024 00025 struct Filler : public MachineFunctionPass { 00026 /// Target machine description which we query for reg. names, data 00027 /// layout, etc. 00028 /// 00029 TargetMachine &TM; 00030 const TargetInstrInfo *TII; 00031 00032 Filler(TargetMachine &tm) : TM(tm), TII(tm.getInstrInfo()) { } 00033 00034 virtual const char *getPassName() const { 00035 return "SPARC Delay Slot Filler"; 00036 } 00037 00038 bool runOnMachineBasicBlock(MachineBasicBlock &MBB); 00039 bool runOnMachineFunction(MachineFunction &F) { 00040 bool Changed = false; 00041 for (MachineFunction::iterator FI = F.begin(), FE = F.end(); 00042 FI != FE; ++FI) 00043 Changed |= runOnMachineBasicBlock(*FI); 00044 return Changed; 00045 } 00046 00047 }; 00048 } // end of anonymous namespace 00049 00050 /// createSparcDelaySlotFillerPass - Returns a pass that fills in delay 00051 /// slots in Sparc MachineFunctions 00052 /// 00053 FunctionPass *llvm::createSparcDelaySlotFillerPass(TargetMachine &tm) { 00054 return new Filler(tm); 00055 } 00056 00057 /// runOnMachineBasicBlock - Fill in delay slots for the given basic block. 00058 /// Currently, we fill delay slots with NOPs. We assume there is only one 00059 /// delay slot per delayed instruction. 00060 /// 00061 bool Filler::runOnMachineBasicBlock(MachineBasicBlock &MBB) { 00062 bool Changed = false; 00063 for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I) 00064 if (TII->hasDelaySlot(I->getOpcode())) { 00065 MachineBasicBlock::iterator J = I; 00066 ++J; 00067 BuildMI(MBB, J, SP::NOP, 0); 00068 ++FilledSlots; 00069 Changed = true; 00070 } 00071 return Changed; 00072 }