-//===-- FloatingPoint.cpp - Floating point Reg -> Stack converter ---------===//
+//===-- X86FloatingPoint.cpp - Floating point Reg -> Stack converter ------===//
//
// The LLVM Compiler Infrastructure
//
#include "llvm/CodeGen/Passes.h"
#include "llvm/Target/TargetInstrInfo.h"
#include "llvm/Target/TargetMachine.h"
-#include "Support/Debug.h"
-#include "Support/DepthFirstIterator.h"
-#include "Support/Statistic.h"
-#include "Support/STLExtras.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/ADT/DepthFirstIterator.h"
+#include "llvm/ADT/Statistic.h"
+#include "llvm/ADT/STLExtras.h"
#include <algorithm>
#include <set>
using namespace llvm;
/// register references into FP stack references.
///
bool FPS::runOnMachineFunction(MachineFunction &MF) {
+ // We only need to run this pass if there are any FP registers used in this
+ // function. If it is all integer, there is nothing for us to do!
+ const bool *PhysRegsUsed = MF.getUsedPhysregs();
+ bool FPIsUsed = false;
+
+ assert(X86::FP6 == X86::FP0+6 && "Register enums aren't sorted right!");
+ for (unsigned i = 0; i <= 6; ++i)
+ if (PhysRegsUsed[X86::FP0+i]) {
+ FPIsUsed = true;
+ break;
+ }
+
+ // Early exit.
+ if (!FPIsUsed) return false;
+
LV = &getAnalysis<LiveVariables>();
StackTop = 0;
++NumFP; // Keep track of # of pseudo instrs
DEBUG(std::cerr << "\nFPInst:\t";
- MI->print(std::cerr, MF.getTarget()));
+ MI->print(std::cerr, &(MF.getTarget())));
// Get dead variables list now because the MI pointer may be deleted as part
// of processing!
case X86II::ZeroArgFP: handleZeroArgFP(I); break;
case X86II::OneArgFP: handleOneArgFP(I); break; // fstp ST(0)
case X86II::OneArgFPRW: handleOneArgFPRW(I); break; // ST(0) = fsqrt(ST(0))
- case X86II::TwoArgFP:
- if (I->getOpcode() != X86::FpUCOM && I->getOpcode() != X86::FpUCOMI)
- handleTwoArgFP(I);
- else
- handleCompareFP(I);
- break;
+ case X86II::TwoArgFP: handleTwoArgFP(I); break;
+ case X86II::CompareFP: handleCompareFP(I); break;
case X86II::CondMovFP: handleCondMovFP(I); break;
case X86II::SpecialFP: handleSpecialFP(I); break;
default: assert(0 && "Unknown FP Type!");
// Rewind to first instruction newly inserted.
while (Start != BB.begin() && prior(Start) != PrevI) --Start;
std::cerr << "Inserted instructions:\n\t";
- Start->print(std::cerr, MF.getTarget());
+ Start->print(std::cerr, &MF.getTarget());
while (++Start != next(I));
}
dumpStack();
delete MI; // Remove the old instruction
}
-/// handleCompareFP - Handle FpUCOM and FpUCOMI instructions, which have two FP
+/// handleCompareFP - Handle FUCOM and FUCOMI instructions, which have two FP
/// register arguments and no explicit destinations.
///
void FPS::handleCompareFP(MachineBasicBlock::iterator &I) {
MachineInstr *MI = I;
unsigned NumOperands = MI->getNumOperands();
- assert(NumOperands == 2 && "Illegal FpUCOM* instruction!");
+ assert(NumOperands == 2 && "Illegal FUCOM* instruction!");
unsigned Op0 = getFPReg(MI->getOperand(NumOperands-2));
unsigned Op1 = getFPReg(MI->getOperand(NumOperands-1));
bool KillsOp0 = false, KillsOp1 = false;
// anywhere.
moveToTop(Op0, I);
- // Replace the old instruction with a new instruction
- MBB->remove(I++);
- unsigned Opcode = MI->getOpcode() == X86::FpUCOM ? X86::FUCOMr : X86::FUCOMIr;
- I = BuildMI(*MBB, I, Opcode, 1).addReg(getSTReg(Op1));
+ MI->getOperand(0).setReg(getSTReg(Op1));
+ MI->RemoveOperand(1);
// If any of the operands are killed by this instruction, free them.
if (KillsOp0) freeStackSlotAfter(I, Op0);
if (KillsOp1 && Op0 != Op1) freeStackSlotAfter(I, Op1);
- delete MI; // Remove the old instruction
}
/// handleCondMovFP - Handle two address conditional move instructions. These