blob: bd1ba3f84886ffea3c93add9da5a0ea6bc226783 [file] [log] [blame]
Brian Gaeke20117102004-04-06 23:21:45 +00001//===-- DelaySlotFiller.cpp - SparcV8 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// Simple local delay slot filler for SparcV8 machine code
11//
12//===----------------------------------------------------------------------===//
13
14#include "SparcV8.h"
15#include "SparcV8InstrInfo.h"
16#include "llvm/Constants.h"
17#include "llvm/DerivedTypes.h"
18#include "llvm/Module.h"
19#include "llvm/Assembly/Writer.h"
20#include "llvm/CodeGen/MachineFunctionPass.h"
21#include "llvm/CodeGen/MachineConstantPool.h"
22#include "llvm/CodeGen/MachineInstr.h"
23#include "llvm/CodeGen/MachineInstrBuilder.h"
24#include "llvm/Target/TargetMachine.h"
25#include "llvm/Support/Mangler.h"
26#include "Support/Statistic.h"
27#include "Support/StringExtras.h"
28#include "Support/CommandLine.h"
29#include <cctype>
30using namespace llvm;
31
32namespace {
33 Statistic<> FilledSlots ("delayslotfiller", "Num. of delay slots filled");
34
35 struct Filler : public MachineFunctionPass {
36 /// Target machine description which we query for reg. names, data
37 /// layout, etc.
38 ///
39 TargetMachine &TM;
40
41 Filler (TargetMachine &tm) : TM (tm) { }
42
43 virtual const char *getPassName () const {
44 return "SparcV8 Delay Slot Filler";
45 }
46
47 bool runOnMachineBasicBlock (MachineBasicBlock &MBB);
48 bool runOnMachineFunction (MachineFunction &F) {
49 bool Changed = false;
50 for (MachineFunction::iterator FI = F.begin (), FE = F.end ();
51 FI != FE; ++FI)
52 Changed |= runOnMachineBasicBlock (*FI);
53 return Changed;
54 }
55
56 };
57} // end of anonymous namespace
58
59/// createSparcV8DelaySlotFillerPass - Returns a pass that fills in delay
60/// slots in SparcV8 MachineFunctions
61///
62FunctionPass *llvm::createSparcV8DelaySlotFillerPass (TargetMachine &tm) {
63 return new Filler (tm);
64}
65
66static bool hasDelaySlot (unsigned Opcode) {
67 switch (Opcode) {
68 case V8::CALL:
69 case V8::RETL:
70 return true;
71 default:
72 return false;
73 }
74}
75
76/// runOnMachineBasicBlock - Fill in delay slots for the given basic block.
77///
78bool Filler::runOnMachineBasicBlock (MachineBasicBlock &MBB) {
79 for (MachineBasicBlock::iterator I = MBB.begin (); I != MBB.end (); ++I)
80 if (hasDelaySlot (I->getOpcode ())) {
81 MachineBasicBlock::iterator J = I;
82 ++J;
83 MBB.insert (J, BuildMI (V8::NOP, 0));
84 ++FilledSlots;
85 }
86 return false;
87}