// 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,
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
// 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);
// 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);
// 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.
// 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();