Turn off the old way of handling debug information in the code generator. Use
[oota-llvm.git] / lib / Target / X86 / X86FloatingPoint.cpp
index 897edcbaddb52ac4828657fc5a806a68856b3a37..0c98205980dbc35a6861a16274360a335e53fc22 100644 (file)
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/ADT/DepthFirstIterator.h"
+#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/STLExtras.h"
 #include <algorithm>
-#include <set>
 using namespace llvm;
 
 STATISTIC(NumFXCH, "Number of fxch instructions inserted");
@@ -53,7 +53,13 @@ STATISTIC(NumFP  , "Number of floating point instructions");
 namespace {
   struct VISIBILITY_HIDDEN FPS : public MachineFunctionPass {
     static char ID;
-    FPS() : MachineFunctionPass((intptr_t)&ID) {}
+    FPS() : MachineFunctionPass(&ID) {}
+
+    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+      AU.addPreservedID(MachineLoopInfoID);
+      AU.addPreservedID(MachineDominatorsID);
+      MachineFunctionPass::getAnalysisUsage(AU);
+    }
 
     virtual bool runOnMachineFunction(MachineFunction &MF);
 
@@ -162,7 +168,7 @@ FunctionPass *llvm::createX86FloatingPointStackifierPass() { return new FPS(); }
 /// getFPReg - Return the X86::FPx register number for the specified operand.
 /// For example, this returns 3 for X86::FP3.
 static unsigned getFPReg(const MachineOperand &MO) {
-  assert(MO.isRegister() && "Expected an FP register!");
+  assert(MO.isReg() && "Expected an FP register!");
   unsigned Reg = MO.getReg();
   assert(Reg >= X86::FP0 && Reg <= X86::FP6 && "Expected FP register!");
   return Reg - X86::FP0;
@@ -192,11 +198,11 @@ bool FPS::runOnMachineFunction(MachineFunction &MF) {
 
   // Process the function in depth first order so that we process at least one
   // of the predecessors for every reachable block in the function.
-  std::set<MachineBasicBlock*> Processed;
+  SmallPtrSet<MachineBasicBlock*, 8> Processed;
   MachineBasicBlock *Entry = MF.begin();
 
   bool Changed = false;
-  for (df_ext_iterator<MachineBasicBlock*, std::set<MachineBasicBlock*> >
+  for (df_ext_iterator<MachineBasicBlock*, SmallPtrSet<MachineBasicBlock*, 8> >
          I = df_ext_begin(Entry, Processed), E = df_ext_end(Entry, Processed);
        I != E; ++I)
     Changed |= processBasicBlock(MF, **I);
@@ -234,7 +240,7 @@ bool FPS::processBasicBlock(MachineFunction &MF, MachineBasicBlock &BB) {
     SmallVector<unsigned, 8> DeadRegs;
     for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
       const MachineOperand &MO = MI->getOperand(i);
-      if (MO.isRegister() && MO.isDead())
+      if (MO.isReg() && MO.isDead())
         DeadRegs.push_back(MO.getReg());
     }
 
@@ -300,11 +306,13 @@ namespace {
   };
 }
 
+#ifndef NDEBUG
 static bool TableIsSorted(const TableEntry *Table, unsigned NumEntries) {
   for (unsigned i = 0; i != NumEntries-1; ++i)
     if (!(Table[i] < Table[i+1])) return false;
   return true;
 }
+#endif
 
 static int Lookup(const TableEntry *Table, unsigned N, unsigned Opcode) {
   const TableEntry *I = std::lower_bound(Table, Table+N, Opcode);
@@ -662,8 +670,10 @@ void FPS::handleOneArgFP(MachineBasicBlock::iterator &I) {
 ///
 void FPS::handleOneArgFPRW(MachineBasicBlock::iterator &I) {
   MachineInstr *MI = I;
+#ifndef NDEBUG
   unsigned NumOps = MI->getDesc().getNumOperands();
   assert(NumOps >= 2 && "FPRW instructions must have 2 ops!!");
+#endif
 
   // Is this the last use of the source register?
   unsigned Reg = getFPReg(MI->getOperand(1));
@@ -858,7 +868,7 @@ void FPS::handleTwoArgFP(MachineBasicBlock::iterator &I) {
   assert(UpdatedSlot < StackTop && Dest < 7);
   Stack[UpdatedSlot]   = Dest;
   RegMap[Dest]         = UpdatedSlot;
-  delete MI;   // Remove the old instruction
+  MBB->getParent()->DeleteMachineInstr(MI); // Remove the old instruction
 }
 
 /// handleCompareFP - Handle FUCOM and FUCOMI instructions, which have two FP
@@ -969,15 +979,24 @@ void FPS::handleSpecialFP(MachineBasicBlock::iterator &I) {
     std::swap(Stack[RegMap[RegOnTop]], Stack[StackTop-1]);
     break;
   }
-  case X86::FpGET_ST0_ST1:
-    assert(StackTop == 0 && "Stack should be empty after a call!");
-    pushReg(getFPReg(MI->getOperand(0)));
-    pushReg(getFPReg(MI->getOperand(1)));
-    break;
   case X86::FpSET_ST0_32:
   case X86::FpSET_ST0_64:
   case X86::FpSET_ST0_80:
-    assert(StackTop == 1 && "Stack should have one element on it to return!");
+    assert((StackTop == 1 || StackTop == 2)
+           && "Stack should have one or two element on it to return!");
+    --StackTop;   // "Forget" we have something on the top of stack!
+    break;
+  case X86::FpSET_ST1_32:
+  case X86::FpSET_ST1_64:
+  case X86::FpSET_ST1_80:
+    // StackTop can be 1 if a FpSET_ST0_* was before this. Exchange them.
+    if (StackTop == 1) {
+      BuildMI(*MBB, I, TII->get(X86::XCH_F)).addReg(X86::ST1);
+      NumFXCH++;
+      StackTop = 0;
+      break;
+    }
+    assert(StackTop == 2 && "Stack should have two element on it to return!");
     --StackTop;   // "Forget" we have something on the top of stack!
     break;
   case X86::MOV_Fp3232:
@@ -1058,8 +1077,13 @@ void FPS::handleSpecialFP(MachineBasicBlock::iterator &I) {
       MachineOperand &Op = MI->getOperand(i);
       if (!Op.isReg() || Op.getReg() < X86::FP0 || Op.getReg() > X86::FP6)
         continue;
-//      assert(Op.isUse() && Op.isKill() &&
-//             "Ret only defs operands, and values aren't live beyond it");
+      // FP Register uses must be kills unless there are two uses of the same
+      // register, in which case only one will be a kill.
+      assert(Op.isUse() &&
+             (Op.isKill() ||                        // Marked kill.
+              getFPReg(Op) == FirstFPRegOp ||       // Second instance.
+              MI->killsRegister(Op.getReg())) &&    // Later use is marked kill.
+             "Ret only defs operands, and values aren't live beyond it");
 
       if (FirstFPRegOp == ~0U)
         FirstFPRegOp = getFPReg(Op);