eliminate static ctors for Statistic objects.
[oota-llvm.git] / lib / Target / Sparc / DelaySlotFiller.cpp
1 //===-- DelaySlotFiller.cpp - SPARC delay slot filler ---------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This is a simple local pass that fills delay slots with NOPs.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #define DEBUG_TYPE "delayslotfiller"
15 #include "Sparc.h"
16 #include "llvm/CodeGen/MachineFunctionPass.h"
17 #include "llvm/CodeGen/MachineInstrBuilder.h"
18 #include "llvm/Target/TargetMachine.h"
19 #include "llvm/Target/TargetInstrInfo.h"
20 #include "llvm/ADT/Statistic.h"
21 using namespace llvm;
22
23 STATISTIC(FilledSlots, "Number of delay slots filled");
24
25 namespace {
26   struct Filler : public MachineFunctionPass {
27     /// Target machine description which we query for reg. names, data
28     /// layout, etc.
29     ///
30     TargetMachine &TM;
31     const TargetInstrInfo *TII;
32
33     Filler(TargetMachine &tm) : TM(tm), TII(tm.getInstrInfo()) { }
34
35     virtual const char *getPassName() const {
36       return "SPARC Delay Slot Filler";
37     }
38
39     bool runOnMachineBasicBlock(MachineBasicBlock &MBB);
40     bool runOnMachineFunction(MachineFunction &F) {
41       bool Changed = false;
42       for (MachineFunction::iterator FI = F.begin(), FE = F.end();
43            FI != FE; ++FI)
44         Changed |= runOnMachineBasicBlock(*FI);
45       return Changed;
46     }
47
48   };
49 } // end of anonymous namespace
50
51 /// createSparcDelaySlotFillerPass - Returns a pass that fills in delay
52 /// slots in Sparc MachineFunctions
53 ///
54 FunctionPass *llvm::createSparcDelaySlotFillerPass(TargetMachine &tm) {
55   return new Filler(tm);
56 }
57
58 /// runOnMachineBasicBlock - Fill in delay slots for the given basic block.
59 /// Currently, we fill delay slots with NOPs. We assume there is only one
60 /// delay slot per delayed instruction.
61 ///
62 bool Filler::runOnMachineBasicBlock(MachineBasicBlock &MBB) {
63   bool Changed = false;
64   for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I)
65     if (TII->hasDelaySlot(I->getOpcode())) {
66       MachineBasicBlock::iterator J = I;
67       ++J;
68       BuildMI(MBB, J, TII->get(SP::NOP));
69       ++FilledSlots;
70       Changed = true;
71     }
72   return Changed;
73 }