remove the SelectSectionForMachineConst hook, replacing it with
[oota-llvm.git] / lib / CodeGen / IfConversion.cpp
index 93e7ff6cfb65e1612ef6d276e4aa4c48675f9251..608d18d591eb784c2a1b96ce36a639c7d6490a2c 100644 (file)
@@ -21,6 +21,8 @@
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/ADT/DepthFirstIterator.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/STLExtras.h"
@@ -144,9 +146,10 @@ namespace {
     const TargetLowering *TLI;
     const TargetInstrInfo *TII;
     bool MadeChange;
+    int FnNum;
   public:
     static char ID;
-    IfConverter() : MachineFunctionPass(&ID) {}
+    IfConverter() : MachineFunctionPass(&ID), FnNum(-1) {}
 
     virtual bool runOnMachineFunction(MachineFunction &MF);
     virtual const char *getPassName() const { return "If Converter"; }
@@ -225,7 +228,6 @@ bool IfConverter::runOnMachineFunction(MachineFunction &MF) {
   TII = MF.getTarget().getInstrInfo();
   if (!TII) return false;
 
-  static int FnNum = -1;
   DOUT << "\nIfcvt: function (" << ++FnNum <<  ") \'"
        << MF.getFunction()->getName() << "\'";
 
@@ -547,7 +549,11 @@ void IfConverter::ScanInstructions(BBInfo &BBI) {
     // fallthrough.
     if (!BBI.FalseBB)
       BBI.FalseBB = findFalseBlock(BBI.BB, BBI.TrueBB);  
-    assert(BBI.FalseBB && "Expected to find the fallthrough block!");
+    if (!BBI.FalseBB) {
+      // Malformed bcc? True and false blocks are the same?
+      BBI.IsUnpredicable = true;
+      return;
+    }
   }
 
   // Then scan all the instructions.
@@ -663,6 +669,13 @@ IfConverter::BBInfo &IfConverter::AnalyzeBlock(MachineBasicBlock *BB,
     return BBI;
   }
 
+  // Do not ifcvt if true and false fallthrough blocks are the same.
+  if (!BBI.FalseBB) {
+    BBI.IsBeingAnalyzed = false;
+    BBI.IsAnalyzed = true;
+    return BBI;
+  }
+
   BBInfo &TrueBBI  = AnalyzeBlock(BBI.TrueBB, Tokens);
   BBInfo &FalseBBI = AnalyzeBlock(BBI.FalseBB, Tokens);
 
@@ -1119,8 +1132,10 @@ void IfConverter::PredicateBlock(BBInfo &BBI,
     if (TII->isPredicated(I))
       continue;
     if (!TII->PredicateInstruction(I, Cond)) {
+#ifndef NDEBUG
       cerr << "Unable to predicate " << *I << "!\n";
-      abort();
+#endif
+      llvm_unreachable(0);
     }
   }
 
@@ -1153,8 +1168,10 @@ void IfConverter::CopyAndPredicateBlock(BBInfo &ToBBI, BBInfo &FromBBI,
 
     if (!isPredicated)
       if (!TII->PredicateInstruction(MI, Cond)) {
-        cerr << "Unable to predicate " << *MI << "!\n";
-        abort();
+#ifndef NDEBUG
+        cerr << "Unable to predicate " << *I << "!\n";
+#endif
+        llvm_unreachable(0);
       }
   }
 
@@ -1212,7 +1229,7 @@ void IfConverter::MergeBlocks(BBInfo &ToBBI, BBInfo &FromBBI) {
   }
 
   // Now FromBBI always falls through to the next block!
-  if (NBB)
+  if (NBB && !FromBBI.BB->isSuccessor(NBB))
     FromBBI.BB->addSuccessor(NBB);
 
   std::copy(FromBBI.Predicate.begin(), FromBBI.Predicate.end(),