2006-02-05 05:50:24 +00:00
|
|
|
//===-- DelaySlotFiller.cpp - SPARC 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
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-02-05 05:50:24 +00:00
|
|
|
#include "Sparc.h"
|
2004-04-06 23:21:45 +00:00
|
|
|
#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:21:45 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
2006-02-05 05:50:24 +00:00
|
|
|
Statistic<> FilledSlots("delayslotfiller", "Num. of delay slots filled");
|
2004-04-06 23:21:45 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2006-02-05 05:50:24 +00:00
|
|
|
Filler(TargetMachine &tm) : TM(tm), TII(tm.getInstrInfo()) { }
|
2004-04-06 23:21:45 +00:00
|
|
|
|
2006-02-05 05:50:24 +00:00
|
|
|
virtual const char *getPassName() const {
|
|
|
|
return "SPARC Delay Slot Filler";
|
2004-04-06 23:21:45 +00:00
|
|
|
}
|
|
|
|
|
2006-02-05 05:50:24 +00:00
|
|
|
bool runOnMachineBasicBlock(MachineBasicBlock &MBB);
|
|
|
|
bool runOnMachineFunction(MachineFunction &F) {
|
2004-04-06 23:21:45 +00:00
|
|
|
bool Changed = false;
|
2006-02-05 05:50:24 +00:00
|
|
|
for (MachineFunction::iterator FI = F.begin(), FE = F.end();
|
2004-04-06 23:21:45 +00:00
|
|
|
FI != FE; ++FI)
|
2006-02-05 05:50:24 +00:00
|
|
|
Changed |= runOnMachineBasicBlock(*FI);
|
2004-04-06 23:21:45 +00:00
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
} // end of anonymous namespace
|
|
|
|
|
2006-02-05 05:50:24 +00:00
|
|
|
/// createSparcDelaySlotFillerPass - Returns a pass that fills in delay
|
|
|
|
/// slots in Sparc MachineFunctions
|
2004-04-06 23:21:45 +00:00
|
|
|
///
|
2006-02-05 05:50:24 +00:00
|
|
|
FunctionPass *llvm::createSparcDelaySlotFillerPass(TargetMachine &tm) {
|
|
|
|
return new Filler(tm);
|
2004-04-06 23:21:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// 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
|
|
|
///
|
2006-02-05 05:50:24 +00:00
|
|
|
bool Filler::runOnMachineBasicBlock(MachineBasicBlock &MBB) {
|
2004-04-07 04:05:12 +00:00
|
|
|
bool Changed = false;
|
2006-02-05 05:50:24 +00:00
|
|
|
for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ++I)
|
|
|
|
if (TII->hasDelaySlot(I->getOpcode())) {
|
2004-04-06 23:21:45 +00:00
|
|
|
MachineBasicBlock::iterator J = I;
|
|
|
|
++J;
|
2006-02-05 05:50:24 +00:00
|
|
|
BuildMI(MBB, J, SP::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
|
|
|
}
|