blob: 9269e7984075eabae4fd40625e8ac5b29fc4247c [file] [log] [blame]
Bruno Cardoso Lopes9684a692007-08-18 01:50:47 +00001//===-- DelaySlotFiller.cpp - Mips delay slot filler ---------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Bruno Cardoso Lopes9684a692007-08-18 01:50:47 +00007//
8//===----------------------------------------------------------------------===//
9//
10// Simple pass to fills delay slots with NOPs.
11//
12//===----------------------------------------------------------------------===//
13
14#define DEBUG_TYPE "delay-slot-filler"
15
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"
22
23using namespace llvm;
24
25STATISTIC(FilledSlots, "Number of delay slots filled");
26
27namespace {
28 struct Filler : public MachineFunctionPass {
29
30 TargetMachine &TM;
31 const TargetInstrInfo *TII;
32
33 static char ID;
34 Filler(TargetMachine &tm)
Owen Anderson90c579d2010-08-06 18:33:48 +000035 : MachineFunctionPass(ID), TM(tm), TII(tm.getInstrInfo()) { }
Bruno Cardoso Lopes9684a692007-08-18 01:50:47 +000036
37 virtual const char *getPassName() const {
38 return "Mips 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.
57bool Filler::
58runOnMachineBasicBlock(MachineBasicBlock &MBB)
59{
60 bool Changed = false;
61 for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I)
Bruno Cardoso Lopes2c2304c2010-11-08 21:42:32 +000062 if (TM.getSubtarget<MipsSubtarget>().isMips1() &&
63 I->getDesc().hasDelaySlot()) {
Bruno Cardoso Lopes9684a692007-08-18 01:50:47 +000064 MachineBasicBlock::iterator J = I;
65 ++J;
Dale Johannesen94817572009-02-13 02:34:39 +000066 BuildMI(MBB, J, I->getDebugLoc(), TII->get(Mips::NOP));
Bruno Cardoso Lopes9684a692007-08-18 01:50:47 +000067 ++FilledSlots;
68 Changed = true;
69 }
70 return Changed;
71}
72
73/// createMipsDelaySlotFillerPass - Returns a pass that fills in delay
74/// slots in Mips MachineFunctions
75FunctionPass *llvm::createMipsDelaySlotFillerPass(MipsTargetMachine &tm) {
76 return new Filler(tm);
77}
78