2004-04-06 23:21:45 +00:00
|
|
|
//===-- DelaySlotFiller.cpp - SparcV8 delay slot filler -------------------===//
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2004-04-06 23:21:45 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2004-04-06 23:21:45 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2004-09-30 04:04:47 +00:00
|
|
|
// This is a simple local pass that fills delay slots with NOPs.
|
2004-04-06 23:21:45 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "SparcV8.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2004-09-30 04:04:47 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2004-09-02 02:37:43 +00:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2004-04-06 23:25:07 +00:00
|
|
|
|
2004-04-06 23:21:45 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
Statistic<> FilledSlots ("delayslotfiller", "Num. of delay slots filled");
|
|
|
|
|
|
|
|
struct Filler : public MachineFunctionPass {
|
|
|
|
/// Target machine description which we query for reg. names, data
|
|
|
|
/// layout, etc.
|
|
|
|
///
|
|
|
|
TargetMachine &TM;
|
2004-09-30 04:04:47 +00:00
|
|
|
const TargetInstrInfo *TII;
|
2004-04-06 23:21:45 +00:00
|
|
|
|
2004-09-30 04:04:47 +00:00
|
|
|
Filler (TargetMachine &tm) : TM (tm), TII (tm.getInstrInfo ()) { }
|
2004-04-06 23:21:45 +00:00
|
|
|
|
|
|
|
virtual const char *getPassName () const {
|
|
|
|
return "SparcV8 Delay Slot Filler";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool runOnMachineBasicBlock (MachineBasicBlock &MBB);
|
|
|
|
bool runOnMachineFunction (MachineFunction &F) {
|
|
|
|
bool Changed = false;
|
|
|
|
for (MachineFunction::iterator FI = F.begin (), FE = F.end ();
|
|
|
|
FI != FE; ++FI)
|
|
|
|
Changed |= runOnMachineBasicBlock (*FI);
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
} // end of anonymous namespace
|
|
|
|
|
|
|
|
/// createSparcV8DelaySlotFillerPass - Returns a pass that fills in delay
|
|
|
|
/// slots in SparcV8 MachineFunctions
|
|
|
|
///
|
|
|
|
FunctionPass *llvm::createSparcV8DelaySlotFillerPass (TargetMachine &tm) {
|
|
|
|
return new Filler (tm);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// runOnMachineBasicBlock - Fill in delay slots for the given basic block.
|
2004-04-07 04:05:12 +00:00
|
|
|
/// Currently, we fill delay slots with NOPs. We assume there is only one
|
|
|
|
/// delay slot per delayed instruction.
|
2004-04-06 23:21:45 +00:00
|
|
|
///
|
|
|
|
bool Filler::runOnMachineBasicBlock (MachineBasicBlock &MBB) {
|
2004-04-07 04:05:12 +00:00
|
|
|
bool Changed = false;
|
2004-04-06 23:21:45 +00:00
|
|
|
for (MachineBasicBlock::iterator I = MBB.begin (); I != MBB.end (); ++I)
|
2004-09-30 04:04:47 +00:00
|
|
|
if (TII->hasDelaySlot (I->getOpcode ())) {
|
2004-04-06 23:21:45 +00:00
|
|
|
MachineBasicBlock::iterator J = I;
|
|
|
|
++J;
|
2004-04-07 04:05:12 +00:00
|
|
|
BuildMI (MBB, J, V8::NOP, 0);
|
2004-04-06 23:21:45 +00:00
|
|
|
++FilledSlots;
|
2004-04-07 04:05:12 +00:00
|
|
|
Changed = true;
|
2004-04-06 23:21:45 +00:00
|
|
|
}
|
2004-04-07 04:05:12 +00:00
|
|
|
return Changed;
|
2004-04-06 23:21:45 +00:00
|
|
|
}
|