Add the necessary support to codegen condition register logical ops with
[oota-llvm.git] / lib / Target / X86 / X86FloatingPoint.cpp
index 0a8f4ac47866a9a42b62a635f58d9bac2d5d655c..899f7cd6fec184f80d5b6e3af398f5206fa4b811 100644 (file)
@@ -1,4 +1,4 @@
-//===-- 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;
@@ -157,6 +157,21 @@ FunctionPass *llvm::createX86FloatingPointStackifierPass() { return new FPS(); }
 /// 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;
 
@@ -194,7 +209,7 @@ bool FPS::processBasicBlock(MachineFunction &MF, MachineBasicBlock &BB) {
 
     ++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!
@@ -215,12 +230,8 @@ bool FPS::processBasicBlock(MachineFunction &MF, MachineBasicBlock &BB) {
     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!");
@@ -246,7 +257,7 @@ bool FPS::processBasicBlock(MachineFunction &MF, MachineBasicBlock &BB) {
         // 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();
@@ -618,7 +629,7 @@ void FPS::handleTwoArgFP(MachineBasicBlock::iterator &I) {
   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) {
@@ -627,7 +638,7 @@ 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;
@@ -642,15 +653,12 @@ void FPS::handleCompareFP(MachineBasicBlock::iterator &I) {
   // 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