I = MBB->erase(I)-1; // Remove the pseudo instruction
delete MI;
}
-
-namespace {
- struct FPK : public MachineFunctionPass {
- virtual const char *getPassName() const { return "X86 FP Killer"; }
- virtual bool runOnMachineFunction(MachineFunction &MF);
- virtual void getAnalysisUsage(AnalysisUsage &AU) const {
- AU.addPreserved<LiveVariables>();
- AU.addRequired<LiveVariables>();
- AU.addPreservedID(PHIEliminationID);
- AU.addRequiredID(PHIEliminationID);
- MachineFunctionPass::getAnalysisUsage(AU);
- }
- };
-}
-
-FunctionPass *llvm::createX86FloatingPointKillerPass() { return new FPK(); }
-
-bool FPK::runOnMachineFunction(MachineFunction &MF) {
- const TargetInstrInfo& tii = MF.getTarget().getInstrInfo();;
- LiveVariables &LV = getAnalysis<LiveVariables>();
-
- for (MachineFunction::iterator
- mbbi = MF.begin(), mbbe = MF.end(); mbbi != mbbe; ++mbbi) {
- MachineBasicBlock& mbb = *mbbi;
- MachineBasicBlock::reverse_iterator mii = mbb.rbegin();
- // rewind to the last non terminating instruction
- while (mii != mbb.rend() && tii.isTerminatorInstr((*mii)->getOpcode()))
- ++mii;
-
- // add implicit def for all virtual floating point registers so that
- // they are spilled at the end of each basic block, since our
- // register stackifier doesn't handle them otherwise.
- MachineInstr* instr = BuildMI(X86::IMPLICIT_DEF, 7)
- .addReg(X86::FP6, MOTy::Def)
- .addReg(X86::FP5, MOTy::Def)
- .addReg(X86::FP4, MOTy::Def)
- .addReg(X86::FP3, MOTy::Def)
- .addReg(X86::FP2, MOTy::Def)
- .addReg(X86::FP1, MOTy::Def)
- .addReg(X86::FP0, MOTy::Def);
-
- mbb.insert(mii.base(), instr);
-
- for (unsigned i = 0; i < instr->getNumOperands(); ++i) {
- LV.HandlePhysRegDef(instr->getOperand(i).getAllocatedRegNum(), instr);
-
- // force live variables to compute that these registers are dead
- LV.HandlePhysRegDef(instr->getOperand(i).getAllocatedRegNum(), 0);
- }
- }
- return true;
-}
/// ret float/double : Top of FP stack
///
void ISel::visitReturnInst(ReturnInst &I) {
+ BuildMI(BB, X86::FP_REG_KILL, 0);
if (I.getNumOperands() == 0) {
BuildMI(BB, X86::RET, 0); // Just emit a 'ret' instruction
return;
///
void ISel::visitBranchInst(BranchInst &BI) {
BasicBlock *NextBB = getBlockAfter(BI.getParent()); // BB after current one
+ BuildMI(BB, X86::FP_REG_KILL, 0);
if (!BI.isConditional()) { // Unconditional branch?
if (BI.getSuccessor(0) != NextBB)
switch (Desc.TSFlags & X86II::FormMask) {
default: assert(0 && "Unknown FormMask value in X86 MachineCodeEmitter!");
case X86II::Pseudo:
- if (Opcode != X86::IMPLICIT_USE && Opcode != X86::IMPLICIT_DEF)
+ if (Opcode != X86::IMPLICIT_USE &&
+ Opcode != X86::IMPLICIT_DEF &&
+ Opcode != X86::FP_REG_KILL)
std::cerr << "X86 Machine Code Emitter: No 'form', not emitting: " << MI;
break;
I = MBB->erase(I)-1; // Remove the pseudo instruction
delete MI;
}
-
-namespace {
- struct FPK : public MachineFunctionPass {
- virtual const char *getPassName() const { return "X86 FP Killer"; }
- virtual bool runOnMachineFunction(MachineFunction &MF);
- virtual void getAnalysisUsage(AnalysisUsage &AU) const {
- AU.addPreserved<LiveVariables>();
- AU.addRequired<LiveVariables>();
- AU.addPreservedID(PHIEliminationID);
- AU.addRequiredID(PHIEliminationID);
- MachineFunctionPass::getAnalysisUsage(AU);
- }
- };
-}
-
-FunctionPass *llvm::createX86FloatingPointKillerPass() { return new FPK(); }
-
-bool FPK::runOnMachineFunction(MachineFunction &MF) {
- const TargetInstrInfo& tii = MF.getTarget().getInstrInfo();;
- LiveVariables &LV = getAnalysis<LiveVariables>();
-
- for (MachineFunction::iterator
- mbbi = MF.begin(), mbbe = MF.end(); mbbi != mbbe; ++mbbi) {
- MachineBasicBlock& mbb = *mbbi;
- MachineBasicBlock::reverse_iterator mii = mbb.rbegin();
- // rewind to the last non terminating instruction
- while (mii != mbb.rend() && tii.isTerminatorInstr((*mii)->getOpcode()))
- ++mii;
-
- // add implicit def for all virtual floating point registers so that
- // they are spilled at the end of each basic block, since our
- // register stackifier doesn't handle them otherwise.
- MachineInstr* instr = BuildMI(X86::IMPLICIT_DEF, 7)
- .addReg(X86::FP6, MOTy::Def)
- .addReg(X86::FP5, MOTy::Def)
- .addReg(X86::FP4, MOTy::Def)
- .addReg(X86::FP3, MOTy::Def)
- .addReg(X86::FP2, MOTy::Def)
- .addReg(X86::FP1, MOTy::Def)
- .addReg(X86::FP0, MOTy::Def);
-
- mbb.insert(mii.base(), instr);
-
- for (unsigned i = 0; i < instr->getNumOperands(); ++i) {
- LV.HandlePhysRegDef(instr->getOperand(i).getAllocatedRegNum(), instr);
-
- // force live variables to compute that these registers are dead
- LV.HandlePhysRegDef(instr->getOperand(i).getAllocatedRegNum(), 0);
- }
- }
- return true;
-}
/// ret float/double : Top of FP stack
///
void ISel::visitReturnInst(ReturnInst &I) {
+ BuildMI(BB, X86::FP_REG_KILL, 0);
if (I.getNumOperands() == 0) {
BuildMI(BB, X86::RET, 0); // Just emit a 'ret' instruction
return;
///
void ISel::visitBranchInst(BranchInst &BI) {
BasicBlock *NextBB = getBlockAfter(BI.getParent()); // BB after current one
+ BuildMI(BB, X86::FP_REG_KILL, 0);
if (!BI.isConditional()) { // Unconditional branch?
if (BI.getSuccessor(0) != NextBB)
def ADJCALLSTACKUP : X86Inst<"ADJCALLSTACKUP", 0, Pseudo, NoArg>;
def IMPLICIT_USE : X86Inst<"IMPLICIT_USE", 0, Pseudo, NoArg>;
def IMPLICIT_DEF : X86Inst<"IMPLICIT_DEF", 0, Pseudo, NoArg>;
-
+let isTerminator = 1 in
+ let Defs = [FP0, FP1, FP2, FP3, FP4, FP5, FP6] in
+ def FP_REG_KILL : X86Inst<"FP_REG_KILL", 0, Pseudo, NoArg>;
//===----------------------------------------------------------------------===//
// Control Flow Instructions...
//
if (PrintCode)
PM.add(createMachineFunctionPrinterPass());
- // kill floating point registers at the end of basic blocks. this is
- // done because the floating point register stackifier cannot handle
- // floating point regs that are live across basic blocks.
- //PM.add(createX86FloatingPointKillerPass());
-
// Perform register allocation to convert to a concrete x86 representation
PM.add(createRegisterAllocator());
if (PrintCode)
PM.add(createMachineFunctionPrinterPass());
- // kill floating point registers at the end of basic blocks. this is
- // done because the floating point register stackifier cannot handle
- // floating point regs that are live across basic blocks.
- //PM.add(createX86FloatingPointKillerPass());
-
// Perform register allocation to convert to a concrete x86 representation
PM.add(createRegisterAllocator());