Silence -Wunused-variable in release builds.
[llvm/stm8.git] / lib / Target / Mips / MipsDelaySlotFiller.cpp
blobc3a6211399cd97ae0f1525b20af50346144d6259
1 //===-- DelaySlotFiller.cpp - Mips delay slot filler ---------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Simple pass to fills delay slots with NOPs.
12 //===----------------------------------------------------------------------===//
14 #define DEBUG_TYPE "delay-slot-filler"
16 #include "Mips.h"
17 #include "MipsTargetMachine.h"
18 #include "llvm/CodeGen/MachineFunctionPass.h"
19 #include "llvm/CodeGen/MachineInstrBuilder.h"
20 #include "llvm/Target/TargetInstrInfo.h"
21 #include "llvm/ADT/Statistic.h"
23 using namespace llvm;
25 STATISTIC(FilledSlots, "Number of delay slots filled");
27 namespace {
28 struct Filler : public MachineFunctionPass {
30 TargetMachine &TM;
31 const TargetInstrInfo *TII;
33 static char ID;
34 Filler(TargetMachine &tm)
35 : MachineFunctionPass(ID), TM(tm), TII(tm.getInstrInfo()) { }
37 virtual const char *getPassName() const {
38 return "Mips Delay Slot Filler";
41 bool runOnMachineBasicBlock(MachineBasicBlock &MBB);
42 bool runOnMachineFunction(MachineFunction &F) {
43 bool Changed = false;
44 for (MachineFunction::iterator FI = F.begin(), FE = F.end();
45 FI != FE; ++FI)
46 Changed |= runOnMachineBasicBlock(*FI);
47 return Changed;
51 char Filler::ID = 0;
52 } // end of anonymous namespace
54 /// runOnMachineBasicBlock - Fill in delay slots for the given basic block.
55 /// Currently, we fill delay slots with NOPs. We assume there is only one
56 /// delay slot per delayed instruction.
57 bool Filler::
58 runOnMachineBasicBlock(MachineBasicBlock &MBB)
60 bool Changed = false;
61 for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I) {
62 const MCInstrDesc& MCid = I->getDesc();
63 if (MCid.hasDelaySlot() &&
64 (TM.getSubtarget<MipsSubtarget>().isMips1() ||
65 MCid.isCall() || MCid.isBranch() || MCid.isReturn())) {
66 MachineBasicBlock::iterator J = I;
67 ++J;
68 BuildMI(MBB, J, I->getDebugLoc(), TII->get(Mips::NOP));
69 ++FilledSlots;
70 Changed = true;
74 return Changed;
77 /// createMipsDelaySlotFillerPass - Returns a pass that fills in delay
78 /// slots in Mips MachineFunctions
79 FunctionPass *llvm::createMipsDelaySlotFillerPass(MipsTargetMachine &tm) {
80 return new Filler(tm);