2006-09-18 19:44:29 +00:00
|
|
|
//===-- AlphaLLRP.cpp - Alpha Load Load Replay Trap elimination 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-09-18 19:44:29 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Here we check for potential replay traps introduced by the spiller
|
2006-12-19 22:59:26 +00:00
|
|
|
// We also align some branch targets if we can do so for free.
|
|
|
|
//
|
2006-09-18 19:44:29 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2006-12-19 22:59:26 +00:00
|
|
|
#define DEBUG_TYPE "alpha-nops"
|
2006-09-18 19:44:29 +00:00
|
|
|
#include "Alpha.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2006-11-27 23:37:22 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2006-09-18 19:44:29 +00:00
|
|
|
#include "llvm/ADT/SetOperations.h"
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
2006-12-19 22:59:26 +00:00
|
|
|
STATISTIC(nopintro, "Number of nops inserted");
|
|
|
|
STATISTIC(nopalign, "Number of nops inserted for alignment");
|
2006-09-18 19:44:29 +00:00
|
|
|
|
2006-12-19 22:59:26 +00:00
|
|
|
namespace {
|
2006-09-18 19:44:29 +00:00
|
|
|
cl::opt<bool>
|
|
|
|
AlignAll("alpha-align-all", cl::Hidden,
|
|
|
|
cl::desc("Align all blocks"));
|
|
|
|
|
|
|
|
struct AlphaLLRPPass : public MachineFunctionPass {
|
|
|
|
/// Target machine description which we query for reg. names, data
|
|
|
|
/// layout, etc.
|
|
|
|
///
|
|
|
|
AlphaTargetMachine &TM;
|
|
|
|
|
2007-05-03 01:11:54 +00:00
|
|
|
static char ID;
|
2007-05-01 21:15:47 +00:00
|
|
|
AlphaLLRPPass(AlphaTargetMachine &tm)
|
|
|
|
: MachineFunctionPass((intptr_t)&ID), TM(tm) { }
|
2006-09-18 19:44:29 +00:00
|
|
|
|
|
|
|
virtual const char *getPassName() const {
|
|
|
|
return "Alpha NOP inserter";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool runOnMachineFunction(MachineFunction &F) {
|
2006-11-27 23:37:22 +00:00
|
|
|
const TargetInstrInfo *TII = F.getTarget().getInstrInfo();
|
2006-09-18 19:44:29 +00:00
|
|
|
bool Changed = false;
|
|
|
|
MachineInstr* prev[3] = {0,0,0};
|
|
|
|
unsigned count = 0;
|
|
|
|
for (MachineFunction::iterator FI = F.begin(), FE = F.end();
|
|
|
|
FI != FE; ++FI) {
|
2007-04-16 18:10:23 +00:00
|
|
|
MachineBasicBlock& MBB = *FI;
|
|
|
|
bool ub = false;
|
|
|
|
for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ) {
|
|
|
|
if (count%4 == 0)
|
|
|
|
prev[0] = prev[1] = prev[2] = 0; //Slots cleared at fetch boundary
|
|
|
|
++count;
|
|
|
|
MachineInstr *MI = I++;
|
|
|
|
switch (MI->getOpcode()) {
|
|
|
|
case Alpha::LDQ: case Alpha::LDL:
|
|
|
|
case Alpha::LDWU: case Alpha::LDBU:
|
|
|
|
case Alpha::LDT: case Alpha::LDS:
|
|
|
|
case Alpha::STQ: case Alpha::STL:
|
|
|
|
case Alpha::STW: case Alpha::STB:
|
|
|
|
case Alpha::STT: case Alpha::STS:
|
|
|
|
if (MI->getOperand(2).getReg() == Alpha::R30) {
|
2007-12-30 20:49:49 +00:00
|
|
|
if (prev[0] &&
|
|
|
|
prev[0]->getOperand(2).getReg() == MI->getOperand(2).getReg()&&
|
|
|
|
prev[0]->getOperand(1).getImm() == MI->getOperand(1).getImm()){
|
2007-04-16 18:10:23 +00:00
|
|
|
prev[0] = prev[1];
|
|
|
|
prev[1] = prev[2];
|
|
|
|
prev[2] = 0;
|
|
|
|
BuildMI(MBB, MI, TII->get(Alpha::BISr), Alpha::R31)
|
|
|
|
.addReg(Alpha::R31)
|
|
|
|
.addReg(Alpha::R31);
|
|
|
|
Changed = true; nopintro += 1;
|
|
|
|
count += 1;
|
|
|
|
} else if (prev[1]
|
|
|
|
&& prev[1]->getOperand(2).getReg() ==
|
|
|
|
MI->getOperand(2).getReg()
|
2007-12-30 20:49:49 +00:00
|
|
|
&& prev[1]->getOperand(1).getImm() ==
|
|
|
|
MI->getOperand(1).getImm()) {
|
2007-04-16 18:10:23 +00:00
|
|
|
prev[0] = prev[2];
|
|
|
|
prev[1] = prev[2] = 0;
|
|
|
|
BuildMI(MBB, MI, TII->get(Alpha::BISr), Alpha::R31)
|
|
|
|
.addReg(Alpha::R31)
|
|
|
|
.addReg(Alpha::R31);
|
|
|
|
BuildMI(MBB, MI, TII->get(Alpha::BISr), Alpha::R31)
|
|
|
|
.addReg(Alpha::R31)
|
|
|
|
.addReg(Alpha::R31);
|
|
|
|
Changed = true; nopintro += 2;
|
|
|
|
count += 2;
|
|
|
|
} else if (prev[2]
|
|
|
|
&& prev[2]->getOperand(2).getReg() ==
|
|
|
|
MI->getOperand(2).getReg()
|
2007-12-30 20:49:49 +00:00
|
|
|
&& prev[2]->getOperand(1).getImm() ==
|
|
|
|
MI->getOperand(1).getImm()) {
|
2007-04-16 18:10:23 +00:00
|
|
|
prev[0] = prev[1] = prev[2] = 0;
|
|
|
|
BuildMI(MBB, MI, TII->get(Alpha::BISr), Alpha::R31).addReg(Alpha::R31)
|
|
|
|
.addReg(Alpha::R31);
|
|
|
|
BuildMI(MBB, MI, TII->get(Alpha::BISr), Alpha::R31).addReg(Alpha::R31)
|
|
|
|
.addReg(Alpha::R31);
|
|
|
|
BuildMI(MBB, MI, TII->get(Alpha::BISr), Alpha::R31).addReg(Alpha::R31)
|
|
|
|
.addReg(Alpha::R31);
|
|
|
|
Changed = true; nopintro += 3;
|
|
|
|
count += 3;
|
|
|
|
}
|
|
|
|
prev[0] = prev[1];
|
|
|
|
prev[1] = prev[2];
|
|
|
|
prev[2] = MI;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prev[0] = prev[1];
|
|
|
|
prev[1] = prev[2];
|
|
|
|
prev[2] = 0;
|
|
|
|
break;
|
|
|
|
case Alpha::ALTENT:
|
|
|
|
case Alpha::MEMLABEL:
|
|
|
|
case Alpha::PCLABEL:
|
|
|
|
case Alpha::IDEF_I:
|
|
|
|
case Alpha::IDEF_F32:
|
|
|
|
case Alpha::IDEF_F64:
|
|
|
|
--count;
|
|
|
|
break;
|
|
|
|
case Alpha::BR:
|
|
|
|
case Alpha::JMP:
|
|
|
|
ub = true;
|
|
|
|
//fall through
|
|
|
|
default:
|
|
|
|
prev[0] = prev[1];
|
|
|
|
prev[1] = prev[2];
|
|
|
|
prev[2] = 0;
|
|
|
|
break;
|
2006-09-20 20:08:52 +00:00
|
|
|
}
|
2007-04-16 18:10:23 +00:00
|
|
|
}
|
|
|
|
if (ub || AlignAll) {
|
|
|
|
//we can align stuff for free at this point
|
|
|
|
while (count % 4) {
|
|
|
|
BuildMI(MBB, MBB.end(), TII->get(Alpha::BISr), Alpha::R31)
|
|
|
|
.addReg(Alpha::R31).addReg(Alpha::R31);
|
|
|
|
++count;
|
|
|
|
++nopalign;
|
|
|
|
prev[0] = prev[1];
|
|
|
|
prev[1] = prev[2];
|
|
|
|
prev[2] = 0;
|
2006-09-20 20:08:52 +00:00
|
|
|
}
|
2007-04-16 18:10:23 +00:00
|
|
|
}
|
2006-09-18 19:44:29 +00:00
|
|
|
}
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
};
|
2007-05-03 01:11:54 +00:00
|
|
|
char AlphaLLRPPass::ID = 0;
|
2006-09-18 19:44:29 +00:00
|
|
|
} // end of anonymous namespace
|
|
|
|
|
|
|
|
FunctionPass *llvm::createAlphaLLRPPass(AlphaTargetMachine &tm) {
|
|
|
|
return new AlphaLLRPPass(tm);
|
|
|
|
}
|