Eliminate static ctors due to Statistic objects
[oota-llvm.git] / lib / Transforms / IPO / LowerSetJmp.cpp
index 9dd9501f1cc54ea9465762653fa20e28cbd617f6..d7f22fb9cb75d5ff2cbb89335a244e32ea10cf32 100644 (file)
@@ -33,6 +33,7 @@
 // pass invokable via the "opt" command at will.
 //===----------------------------------------------------------------------===//
 
+#define DEBUG_TYPE "lowersetjmp"
 #include "llvm/Transforms/IPO.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/ADT/VectorExtras.h"
 using namespace llvm;
 
-namespace {
-  Statistic<> LongJmpsTransformed("lowersetjmp",
-                                  "Number of longjmps transformed");
-  Statistic<> SetJmpsTransformed("lowersetjmp",
-                                 "Number of setjmps transformed");
-  Statistic<> CallsTransformed("lowersetjmp",
-                               "Number of calls invokified");
-  Statistic<> InvokesTransformed("lowersetjmp",
-                                 "Number of invokes modified");
+STATISTIC(LongJmpsTransformed, "Number of longjmps transformed");
+STATISTIC(SetJmpsTransformed , "Number of setjmps transformed");
+STATISTIC(CallsTransformed   , "Number of calls invokified");
+STATISTIC(InvokesTransformed , "Number of invokes modified");
 
+namespace {
   //===--------------------------------------------------------------------===//
   // LowerSetJmp pass implementation.
   class LowerSetJmp : public ModulePass,
@@ -120,7 +117,7 @@ namespace {
     bool doInitialization(Module& M);
   };
 
-  RegisterOpt<LowerSetJmp> X("lowersetjmp", "Lower Set Jump");
+  RegisterPass<LowerSetJmp> X("lowersetjmp", "Lower Set Jump");
 } // end anonymous namespace
 
 // run - Run the transformation on the program. We grab the function
@@ -259,7 +256,8 @@ void LowerSetJmp::TransformLongJmpCall(CallInst* Inst)
   // same parameters as "longjmp", except that the buffer is cast to a
   // char*. It returns "void", so it doesn't need to replace any of
   // Inst's uses and doesn't get a name.
-  CastInst* CI = new CastInst(Inst->getOperand(1), SBPTy, "LJBuf", Inst);
+  CastInst* CI = 
+    new BitCastInst(Inst->getOperand(1), SBPTy, "LJBuf", Inst);
   new CallInst(ThrowLongJmp, make_vector<Value*>(CI, Inst->getOperand(2), 0),
                "", Inst);
 
@@ -375,10 +373,11 @@ void LowerSetJmp::TransformSetJmpCall(CallInst* Inst)
 
   // Add this setjmp to the setjmp map.
   const Type* SBPTy = PointerType::get(Type::SByteTy);
-  CastInst* BufPtr = new CastInst(Inst->getOperand(1), SBPTy, "SBJmpBuf", Inst);
+  CastInst* BufPtr = 
+    new BitCastInst(Inst->getOperand(1), SBPTy, "SBJmpBuf", Inst);
   new CallInst(AddSJToMap,
                make_vector<Value*>(GetSetJmpMap(Func), BufPtr,
-                                   ConstantUInt::get(Type::UIntTy,
+                                   ConstantInt::get(Type::UIntTy,
                                                      SetJmpIDMap[Func]++), 0),
                "", Inst);
 
@@ -429,7 +428,7 @@ void LowerSetJmp::TransformSetJmpCall(CallInst* Inst)
 
   // Add the case for this setjmp's number...
   SwitchValuePair SVP = GetSJSwitch(Func, GetRethrowBB(Func));
-  SVP.first->addCase(ConstantUInt::get(Type::UIntTy, SetJmpIDMap[Func] - 1),
+  SVP.first->addCase(ConstantInt::get(Type::UIntTy, SetJmpIDMap[Func] - 1),
                      SetJmpContBlock);
 
   // Value coming from the handling of the exception.
@@ -496,7 +495,6 @@ void LowerSetJmp::visitInvokeInst(InvokeInst& II)
   // If not reachable from a setjmp call, don't transform.
   if (!DFSBlocks.count(BB)) return;
 
-  BasicBlock* NormalBB = II.getNormalDest();
   BasicBlock* ExceptBB = II.getUnwindDest();
 
   Function* Func = BB->getParent();