Revert r110396 to fix buildbots.
[oota-llvm.git] / lib / Target / MBlaze / MBlazeDelaySlotFiller.cpp
1 //===-- DelaySlotFiller.cpp - MBlaze 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.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #define DEBUG_TYPE "delay-slot-filler"
15
16 #include "MBlaze.h"
17 #include "MBlazeTargetMachine.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"
22
23 using namespace llvm;
24
25 STATISTIC(FilledSlots, "Number of delay slots filled");
26
27 namespace {
28   struct Filler : public MachineFunctionPass {
29
30     TargetMachine &TM;
31     const TargetInstrInfo *TII;
32
33     static char ID;
34     Filler(TargetMachine &tm) 
35       : MachineFunctionPass(&ID), TM(tm), TII(tm.getInstrInfo()) { }
36
37     virtual const char *getPassName() const {
38       return "MBlaze Delay Slot Filler";
39     }
40
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;
48     }
49
50   };
51   char Filler::ID = 0;
52 } // end of anonymous namespace
53
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::runOnMachineBasicBlock(MachineBasicBlock &MBB) {
58   bool Changed = false;
59   for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I)
60     if (I->getDesc().hasDelaySlot()) {
61       MachineBasicBlock::iterator J = I;
62       ++J;
63       BuildMI(MBB, J, I->getDebugLoc(), TII->get(MBlaze::NOP));
64       ++FilledSlots;
65       Changed = true;
66     }
67   return Changed;
68 }
69
70 /// createMBlazeDelaySlotFillerPass - Returns a pass that fills in delay
71 /// slots in MBlaze MachineFunctions
72 FunctionPass *llvm::createMBlazeDelaySlotFillerPass(MBlazeTargetMachine &tm) {
73   return new Filler(tm);
74 }
75