Disable an xform that causes an infinite loop. This fixes PR1594
[oota-llvm.git] / lib / Transforms / Utils / LowerSelect.cpp
index 7555768293560a4133f0fa402405a8ee9dd5f531..317e84aa96f345e146c0668d86df67a0df4674d7 100644 (file)
 //===----------------------------------------------------------------------===//
 
 #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,8 +88,8 @@ 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);