blob: 898b23ab50fb9892b4697c65e5d9ed64cdda6663 [file] [log] [blame]
Chris Lattner158e1f52006-02-05 05:50:24 +00001//===-- 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
Chris Lattner1ef9cd42006-12-19 22:59:26 +000014#define DEBUG_TYPE "delayslotfiller"
Chris Lattner158e1f52006-02-05 05:50:24 +000015#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"
21using namespace llvm;
22
Chris Lattner1ef9cd42006-12-19 22:59:26 +000023STATISTIC(FilledSlots, "Number of delay slots filled");
Chris Lattner158e1f52006-02-05 05:50:24 +000024
Chris Lattner1ef9cd42006-12-19 22:59:26 +000025namespace {
Chris Lattner158e1f52006-02-05 05:50:24 +000026 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///
54FunctionPass *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///
62bool 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;
Evan Cheng20350c42006-11-27 23:37:22 +000068 BuildMI(MBB, J, TII->get(SP::NOP));
Chris Lattner158e1f52006-02-05 05:50:24 +000069 ++FilledSlots;
70 Changed = true;
71 }
72 return Changed;
73}