2007-08-18 01:50:47 +00:00
|
|
|
//===-- DelaySlotFiller.cpp - Mips delay slot filler ---------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-08-18 01:50:47 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Simple pass to fills delay slots with NOPs.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "delay-slot-filler"
|
|
|
|
|
|
|
|
#include "Mips.h"
|
|
|
|
#include "MipsTargetMachine.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
STATISTIC(FilledSlots, "Number of delay slots filled");
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
struct Filler : public MachineFunctionPass {
|
|
|
|
|
|
|
|
TargetMachine &TM;
|
|
|
|
const TargetInstrInfo *TII;
|
|
|
|
|
|
|
|
static char ID;
|
|
|
|
Filler(TargetMachine &tm)
|
2008-09-04 17:05:41 +00:00
|
|
|
: MachineFunctionPass(&ID), TM(tm), TII(tm.getInstrInfo()) { }
|
2007-08-18 01:50:47 +00:00
|
|
|
|
|
|
|
virtual const char *getPassName() const {
|
|
|
|
return "Mips 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
char Filler::ID = 0;
|
|
|
|
} // end of anonymous namespace
|
|
|
|
|
|
|
|
/// runOnMachineBasicBlock - Fill in delay slots for the given basic block.
|
|
|
|
/// Currently, we fill delay slots with NOPs. We assume there is only one
|
|
|
|
/// delay slot per delayed instruction.
|
|
|
|
bool Filler::
|
|
|
|
runOnMachineBasicBlock(MachineBasicBlock &MBB)
|
|
|
|
{
|
|
|
|
bool Changed = false;
|
|
|
|
for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I)
|
2008-01-07 07:27:27 +00:00
|
|
|
if (I->getDesc().hasDelaySlot()) {
|
2007-08-18 01:50:47 +00:00
|
|
|
MachineBasicBlock::iterator J = I;
|
|
|
|
++J;
|
|
|
|
BuildMI(MBB, J, TII->get(Mips::NOP));
|
|
|
|
++FilledSlots;
|
|
|
|
Changed = true;
|
|
|
|
}
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// createMipsDelaySlotFillerPass - Returns a pass that fills in delay
|
|
|
|
/// slots in Mips MachineFunctions
|
|
|
|
FunctionPass *llvm::createMipsDelaySlotFillerPass(MipsTargetMachine &tm) {
|
|
|
|
return new Filler(tm);
|
|
|
|
}
|
|
|
|
|