2006-01-25 02:23:38 +00:00
|
|
|
//===-- IA64Bundling.cpp - IA-64 instruction bundling pass. ------------ --===//
|
|
|
|
//
|
|
|
|
// 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.
|
2006-01-25 02:23:38 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Add stops where required to prevent read-after-write and write-after-write
|
|
|
|
// dependencies, for both registers and memory addresses. There are exceptions:
|
|
|
|
//
|
|
|
|
// - Compare instructions (cmp*, tbit, tnat, fcmp, frcpa) are OK with
|
|
|
|
// WAW dependencies so long as they all target p0, or are of parallel
|
|
|
|
// type (.and*/.or*)
|
|
|
|
//
|
|
|
|
// FIXME: bundling, for now, is left to the assembler.
|
|
|
|
// FIXME: this might be an appropriate place to translate between different
|
|
|
|
// instructions that do the same thing, if this helps bundling.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-12-19 22:59:26 +00:00
|
|
|
#define DEBUG_TYPE "ia64-codegen"
|
2006-01-25 02:23:38 +00:00
|
|
|
#include "IA64.h"
|
2006-11-27 23:37:22 +00:00
|
|
|
#include "IA64InstrInfo.h"
|
|
|
|
#include "IA64TargetMachine.h"
|
2006-01-25 02:23:38 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
|
|
|
#include "llvm/ADT/SetOperations.h"
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include <set>
|
|
|
|
using namespace llvm;
|
|
|
|
|
2006-12-19 22:59:26 +00:00
|
|
|
STATISTIC(StopBitsAdded, "Number of stop bits added");
|
2006-01-25 02:23:38 +00:00
|
|
|
|
2006-12-19 22:59:26 +00:00
|
|
|
namespace {
|
2006-01-25 02:23:38 +00:00
|
|
|
struct IA64BundlingPass : public MachineFunctionPass {
|
2007-05-03 01:11:54 +00:00
|
|
|
static char ID;
|
2006-01-25 02:23:38 +00:00
|
|
|
/// Target machine description which we query for reg. names, data
|
|
|
|
/// layout, etc.
|
|
|
|
///
|
2006-03-13 23:20:37 +00:00
|
|
|
IA64TargetMachine &TM;
|
2006-01-25 02:23:38 +00:00
|
|
|
|
2007-05-01 21:15:47 +00:00
|
|
|
IA64BundlingPass(IA64TargetMachine &tm)
|
2008-09-04 17:05:41 +00:00
|
|
|
: MachineFunctionPass(&ID), TM(tm) { }
|
2006-01-25 02:23:38 +00:00
|
|
|
|
|
|
|
virtual const char *getPassName() const {
|
|
|
|
return "IA64 (Itanium) Bundling Pass";
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-04-16 18:10:23 +00:00
|
|
|
// XXX: ugly global, but pending writes can cross basic blocks. Note that
|
|
|
|
// taken branches end instruction groups. So we only need to worry about
|
|
|
|
// 'fallthrough' code
|
|
|
|
std::set<unsigned> PendingRegWrites;
|
2006-01-25 02:23:38 +00:00
|
|
|
};
|
2007-05-03 01:11:54 +00:00
|
|
|
char IA64BundlingPass::ID = 0;
|
2006-01-25 02:23:38 +00:00
|
|
|
} // end of anonymous namespace
|
|
|
|
|
|
|
|
/// createIA64BundlingPass - Returns a pass that adds STOP (;;) instructions
|
|
|
|
/// and arranges the result into bundles.
|
|
|
|
///
|
2006-03-13 23:20:37 +00:00
|
|
|
FunctionPass *llvm::createIA64BundlingPass(IA64TargetMachine &tm) {
|
2006-01-25 02:23:38 +00:00
|
|
|
return new IA64BundlingPass(tm);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// runOnMachineBasicBlock - add stops and bundle this MBB.
|
|
|
|
///
|
|
|
|
bool IA64BundlingPass::runOnMachineBasicBlock(MachineBasicBlock &MBB) {
|
|
|
|
bool Changed = false;
|
|
|
|
|
|
|
|
for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ) {
|
|
|
|
MachineInstr *CurrentInsn = I++;
|
|
|
|
std::set<unsigned> CurrentReads, CurrentWrites, OrigWrites;
|
|
|
|
|
|
|
|
for(unsigned i=0; i < CurrentInsn->getNumOperands(); i++) {
|
|
|
|
MachineOperand &MO=CurrentInsn->getOperand(i);
|
2008-10-03 15:45:36 +00:00
|
|
|
if (MO.isReg()) {
|
2006-01-25 02:23:38 +00:00
|
|
|
if(MO.isUse()) { // TODO: exclude p0
|
|
|
|
CurrentReads.insert(MO.getReg());
|
|
|
|
}
|
|
|
|
if(MO.isDef()) { // TODO: exclude p0
|
|
|
|
CurrentWrites.insert(MO.getReg());
|
|
|
|
OrigWrites.insert(MO.getReg()); // FIXME: use a nondestructive
|
|
|
|
// set_intersect instead?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// CurrentReads/CurrentWrites contain info for the current instruction.
|
|
|
|
// Does it read or write any registers that are pending a write?
|
|
|
|
// (i.e. not separated by a stop)
|
|
|
|
set_intersect(CurrentReads, PendingRegWrites);
|
|
|
|
set_intersect(CurrentWrites, PendingRegWrites);
|
|
|
|
|
|
|
|
if(! (CurrentReads.empty() && CurrentWrites.empty()) ) {
|
|
|
|
// there is a conflict, insert a stop and reset PendingRegWrites
|
2009-02-13 02:34:39 +00:00
|
|
|
CurrentInsn = BuildMI(MBB, CurrentInsn, CurrentInsn->getDebugLoc(),
|
2006-11-27 23:37:22 +00:00
|
|
|
TM.getInstrInfo()->get(IA64::STOP), 0);
|
2006-01-25 02:23:38 +00:00
|
|
|
PendingRegWrites=OrigWrites; // carry over current writes to next insn
|
|
|
|
Changed=true; StopBitsAdded++; // update stats
|
|
|
|
} else { // otherwise, track additional pending writes
|
|
|
|
set_union(PendingRegWrites, OrigWrites);
|
|
|
|
}
|
|
|
|
} // onto the next insn in the MBB
|
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|