llvm.org GIT mirror llvm / 9684a69
A Pass to insert Nops on intructions with DelaySlot git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41150 91177308-0d34-0410-b5e6-96231b3b80d8 Bruno Cardoso Lopes 13 years ago
1 changed file(s) with 77 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 //===-- DelaySlotFiller.cpp - Mips delay slot filler ---------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file was developed by Bruno Cardoso Lopes and is distributed under
5 // the University of Illinois Open Source License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Simple pass to fills delay slots with NOPs.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #define DEBUG_TYPE "delay-slot-filler"
14
15 #include "Mips.h"
16 #include "MipsTargetMachine.h"
17 #include "llvm/CodeGen/MachineFunctionPass.h"
18 #include "llvm/CodeGen/MachineInstrBuilder.h"
19 #include "llvm/Target/TargetInstrInfo.h"
20 #include "llvm/ADT/Statistic.h"
21
22 using namespace llvm;
23
24 STATISTIC(FilledSlots, "Number of delay slots filled");
25
26 namespace {
27 struct Filler : public MachineFunctionPass {
28
29 TargetMachine &TM;
30 const TargetInstrInfo *TII;
31
32 static char ID;
33 Filler(TargetMachine &tm)
34 : MachineFunctionPass((intptr_t)&ID), TM(tm), TII(tm.getInstrInfo()) { }
35
36 virtual const char *getPassName() const {
37 return "Mips Delay Slot Filler";
38 }
39
40 bool runOnMachineBasicBlock(MachineBasicBlock &MBB);
41 bool runOnMachineFunction(MachineFunction &F) {
42 bool Changed = false;
43 for (MachineFunction::iterator FI = F.begin(), FE = F.end();
44 FI != FE; ++FI)
45 Changed |= runOnMachineBasicBlock(*FI);
46 return Changed;
47 }
48
49 };
50 char Filler::ID = 0;
51 } // end of anonymous namespace
52
53 /// runOnMachineBasicBlock - Fill in delay slots for the given basic block.
54 /// Currently, we fill delay slots with NOPs. We assume there is only one
55 /// delay slot per delayed instruction.
56 bool Filler::
57 runOnMachineBasicBlock(MachineBasicBlock &MBB)
58 {
59 bool Changed = false;
60 for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I)
61 if (TII->hasDelaySlot(I->getOpcode())) {
62 MachineBasicBlock::iterator J = I;
63 ++J;
64 BuildMI(MBB, J, TII->get(Mips::NOP));
65 ++FilledSlots;
66 Changed = true;
67 }
68 return Changed;
69 }
70
71 /// createMipsDelaySlotFillerPass - Returns a pass that fills in delay
72 /// slots in Mips MachineFunctions
73 FunctionPass *llvm::createMipsDelaySlotFillerPass(MipsTargetMachine &tm) {
74 return new Filler(tm);
75 }
76