Factor local liveness computation out into its own function.
[oota-llvm.git] / lib / CodeGen / IfConversion.cpp
index a98347b486ed759f1dc70291e3c13e7952d213cf..b59674c41a0cbe0cd560c3825f1e2a592f513cf8 100644 (file)
@@ -56,7 +56,7 @@ STATISTIC(NumIfConvBBs,    "Number of if-converted blocks");
 STATISTIC(NumDupBBs,       "Number of duplicated blocks");
 
 namespace {
-  class IfConverter : public MachineFunctionPass {
+  class VISIBILITY_HIDDEN IfConverter : public MachineFunctionPass {
     enum IfcvtKind {
       ICNotClassfied,  // BB data valid, but not classified.
       ICSimpleFalse,   // Same as ICSimple, but on the false path.
@@ -149,7 +149,7 @@ namespace {
     IfConverter() : MachineFunctionPass((intptr_t)&ID) {}
 
     virtual bool runOnMachineFunction(MachineFunction &MF);
-    virtual const char *getPassName() const { return "If converter"; }
+    virtual const char *getPassName() const { return "If Converter"; }
 
   private:
     bool ReverseBranchCondition(BBInfo &BBI);
@@ -215,6 +215,9 @@ namespace {
   char IfConverter::ID = 0;
 }
 
+static RegisterPass<IfConverter>
+X("if-converter", "If Converter");
+
 FunctionPass *llvm::createIfConverterPass() { return new IfConverter(); }
 
 bool IfConverter::runOnMachineFunction(MachineFunction &MF) {
@@ -237,7 +240,7 @@ bool IfConverter::runOnMachineFunction(MachineFunction &MF) {
 
   // Look for root nodes, i.e. blocks without successors.
   for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I)
-    if (I->succ_size() == 0)
+    if (I->succ_empty())
       Roots.push_back(I);
 
   std::vector<IfcvtToken*> Tokens;
@@ -278,9 +281,10 @@ bool IfConverter::runOnMachineFunction(MachineFunction &MF) {
                  : BBI.TrueBB->getNumber()) << ") ";
         RetVal = IfConvertSimple(BBI, Kind);
         DOUT << (RetVal ? "succeeded!" : "failed!") << "\n";
-        if (RetVal)
+        if (RetVal) {
           if (isFalse) NumSimpleFalse++;
           else         NumSimple++;
+        }
        break;
       }
       case ICTriangle:
@@ -428,7 +432,7 @@ bool IfConverter::ValidTriangle(BBInfo &TrueBBI, BBInfo &FalseBBI,
 
     unsigned Size = TrueBBI.NonPredSize;
     if (TrueBBI.IsBrAnalyzable) {
-      if (TrueBBI.TrueBB && TrueBBI.BrCond.size() == 0)
+      if (TrueBBI.TrueBB && TrueBBI.BrCond.empty())
         // End with an unconditional branch. It will be removed.
         --Size;
       else {
@@ -460,7 +464,7 @@ MachineBasicBlock::iterator firstNonBranchInst(MachineBasicBlock *BB,
   MachineBasicBlock::iterator I = BB->end();
   while (I != BB->begin()) {
     --I;
-    if (!I->getDesc()->isBranch())
+    if (!I->getDesc().isBranch())
       break;
   }
   return I;
@@ -548,12 +552,12 @@ void IfConverter::ScanInstructions(BBInfo &BBI) {
   bool SeenCondBr = false;
   for (MachineBasicBlock::iterator I = BBI.BB->begin(), E = BBI.BB->end();
        I != E; ++I) {
-    const TargetInstrDescriptor *TID = I->getDesc();
-    if (TID->isNotDuplicable())
+    const TargetInstrDesc &TID = I->getDesc();
+    if (TID.isNotDuplicable())
       BBI.CannotBeCopied = true;
 
     bool isPredicated = TII->isPredicated(I);
-    bool isCondBr = BBI.IsBrAnalyzable && TID->isConditionalBranch();
+    bool isCondBr = BBI.IsBrAnalyzable && TID.isConditionalBranch();
 
     if (!isCondBr) {
       if (!isPredicated)
@@ -590,7 +594,7 @@ void IfConverter::ScanInstructions(BBInfo &BBI) {
     if (TII->DefinesPredicate(I, PredDefs))
       BBI.ClobbersPred = true;
 
-    if (!TID->isPredicable()) {
+    if (!TID.isPredicable()) {
       BBI.IsUnpredicable = true;
       return;
     }
@@ -646,7 +650,7 @@ IfConverter::BBInfo &IfConverter::AnalyzeBlock(MachineBasicBlock *BB,
   ScanInstructions(BBI);
 
   // Unanalyable or ends with fallthrough or unconditional branch.
-  if (!BBI.IsBrAnalyzable || BBI.BrCond.size() == 0) {
+  if (!BBI.IsBrAnalyzable || BBI.BrCond.empty()) {
     BBI.IsBeingAnalyzed = false;
     BBI.IsAnalyzed = true;
     return BBI;
@@ -1130,15 +1134,17 @@ void IfConverter::PredicateBlock(BBInfo &BBI,
 void IfConverter::CopyAndPredicateBlock(BBInfo &ToBBI, BBInfo &FromBBI,
                                         std::vector<MachineOperand> &Cond,
                                         bool IgnoreBr) {
+  MachineFunction &MF = *ToBBI.BB->getParent();
+
   for (MachineBasicBlock::iterator I = FromBBI.BB->begin(),
          E = FromBBI.BB->end(); I != E; ++I) {
-    const TargetInstrDescriptor *TID = I->getDesc();
+    const TargetInstrDesc &TID = I->getDesc();
     bool isPredicated = TII->isPredicated(I);
     // Do not copy the end of the block branches.
-    if (IgnoreBr && !isPredicated && TID->isBranch())
+    if (IgnoreBr && !isPredicated && TID.isBranch())
       break;
 
-    MachineInstr *MI = I->clone();
+    MachineInstr *MI = MF.CloneMachineInstr(I);
     ToBBI.BB->insert(ToBBI.BB->end(), MI);
     ToBBI.NonPredSize++;