Disable an xform that causes an infinite loop. This fixes PR1594
[oota-llvm.git] / lib / Transforms / Utils / LowerSelect.cpp
index f914e747a1538434faa807d7904abafb45c8014b..317e84aa96f345e146c0668d86df67a0df4674d7 100644 (file)
@@ -1,10 +1,10 @@
 //===- LowerSelect.cpp - Transform select insts to branches ---------------===//
-// 
+//
 //                     The LLVM Compiler Infrastructure
 //
 // This file was developed by the LLVM research group and is distributed under
 // the University of Illinois Open Source License. See LICENSE.TXT for details.
-// 
+//
 //===----------------------------------------------------------------------===//
 //
 // This pass lowers select instructions into conditional branches for targets
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Transforms/Scalar.h"
+#include "llvm/Transforms/Utils/UnifyFunctionExitNodes.h"
 #include "llvm/Function.h"
 #include "llvm/Instructions.h"
 #include "llvm/Pass.h"
 #include "llvm/Type.h"
-#include "llvm/ADT/Statistic.h"
+#include "llvm/Support/Compiler.h"
 using namespace llvm;
 
 namespace {
-  Statistic<> NumLowered("lowerselect","Number of select instructions lowered");
-
   /// LowerSelect - Turn select instructions into conditional branches.
   ///
-  class LowerSelect : public FunctionPass {
+  class VISIBILITY_HIDDEN LowerSelect : public FunctionPass {
     bool OnlyFP;   // Only lower FP select instructions?
   public:
-    LowerSelect(bool onlyfp = false) : OnlyFP(onlyfp) {}
+    static char ID; // Pass identification, replacement for typeid
+    explicit LowerSelect(bool onlyfp = false) : FunctionPass((intptr_t)&ID), 
+      OnlyFP(onlyfp) {}
 
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-      // Doesn't really preserve anything.  It can certainly destroy the CFG.
+      // This certainly destroys the CFG.
+      // This is a cluster of orthogonal Transforms:
+      AU.addPreserved<UnifyFunctionExitNodes>();
+      AU.addPreservedID(PromoteMemoryToRegisterID);
+      AU.addPreservedID(LowerSwitchID);
+      AU.addPreservedID(LowerInvokePassID);
+      AU.addPreservedID(LowerAllocationsID);
     }
 
     bool runOnFunction(Function &F);
   };
 
-  RegisterOpt<LowerSelect>
+  char LowerSelect::ID = 0;
+  RegisterPass<LowerSelect>
   X("lowerselect", "Lower select instructions to branches");
 }
 
+// Publically exposed interface to pass...
+const PassInfo *llvm::LowerSelectID = X.getPassInfo();
 //===----------------------------------------------------------------------===//
 // This pass converts SelectInst instructions into conditional branch and PHI
 // instructions.  If the OnlyFP flag is set to true, then only floating point
@@ -78,15 +88,15 @@ bool LowerSelect::runOnFunction(Function &F) {
           new BranchInst(NewTrue, NewCont, SI->getCondition(), BB);
 
           // Create a new PHI node in the cont block with the entries we need.
-          std::string Name = SI->getName(); SI->setName("");
-          PHINode *PN = new PHINode(SI->getType(), Name, NewCont->begin());
+          PHINode *PN = new PHINode(SI->getType(), "", NewCont->begin());
+          PN->takeName(SI);
           PN->addIncoming(SI->getTrueValue(), NewTrue);
           PN->addIncoming(SI->getFalseValue(), BB);
 
           // Use the PHI instead of the select.
           SI->replaceAllUsesWith(PN);
           NewCont->getInstList().erase(SI);
-        
+
           Changed = true;
           break; // This block is done with.
         }