diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2012-04-14 13:54:10 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2012-04-14 13:54:10 +0000 |
commit | 63faed5b8e4f2755f127fcb8aa440480c0649327 (patch) | |
tree | 19c69a04768629f2d440944b71cbe90adae0b615 /examples/ExceptionDemo | |
parent | d4c8b5d2e851b0e8a063c6bf8543a4823a26c15a (diff) | |
download | src-test2-63faed5b8e4f2755f127fcb8aa440480c0649327.tar.gz src-test2-63faed5b8e4f2755f127fcb8aa440480c0649327.zip |
Notes
Diffstat (limited to 'examples/ExceptionDemo')
-rw-r--r-- | examples/ExceptionDemo/ExceptionDemo.cpp | 101 |
1 files changed, 10 insertions, 91 deletions
diff --git a/examples/ExceptionDemo/ExceptionDemo.cpp b/examples/ExceptionDemo/ExceptionDemo.cpp index 20516a783b9d..cf078bb3f543 100644 --- a/examples/ExceptionDemo/ExceptionDemo.cpp +++ b/examples/ExceptionDemo/ExceptionDemo.cpp @@ -63,11 +63,6 @@ #include "llvm/Support/Dwarf.h" #include "llvm/Support/TargetSelect.h" -#ifdef OLD_EXC_SYSTEM -// See use of UpgradeExceptionHandling(...) below -#include "llvm/AutoUpgrade.h" -#endif - // FIXME: Although all systems tested with (Linux, OS X), do not need this // header file included. A user on ubuntu reported, undefined symbols // for stderr, and fprintf, and the addition of this include fixed the @@ -188,9 +183,7 @@ static std::vector<std::string> ourTypeInfoNames; static std::map<int, std::string> ourTypeInfoNamesIndex; static llvm::StructType *ourTypeInfoType; -#ifndef OLD_EXC_SYSTEM static llvm::StructType *ourCaughtResultType; -#endif static llvm::StructType *ourExceptionType; static llvm::StructType *ourUnwindExceptionType; @@ -885,7 +878,7 @@ void generateStringPrint(llvm::LLVMContext &context, llvm::Value *stringVar; llvm::Constant *stringConstant = - llvm::ConstantArray::get(context, toPrint); + llvm::ConstantDataArray::getString(context, toPrint); if (useGlobal) { // Note: Does not work without allocation @@ -927,7 +920,8 @@ void generateIntegerPrint(llvm::LLVMContext &context, llvm::Value &toPrint, std::string format, bool useGlobal = true) { - llvm::Constant *stringConstant = llvm::ConstantArray::get(context, format); + llvm::Constant *stringConstant = + llvm::ConstantDataArray::getString(context, format); llvm::Value *stringVar; if (useGlobal) { @@ -969,9 +963,7 @@ void generateIntegerPrint(llvm::LLVMContext &context, /// @param unwindResumeBlock unwind resume block /// @param exceptionCaughtFlag reference exception caught/thrown status storage /// @param exceptionStorage reference to exception pointer storage -#ifndef OLD_EXC_SYSTEM /// @param caughtResultStorage reference to landingpad result storage -#endif /// @returns newly created block static llvm::BasicBlock *createFinallyBlock(llvm::LLVMContext &context, llvm::Module &module, @@ -982,23 +974,17 @@ static llvm::BasicBlock *createFinallyBlock(llvm::LLVMContext &context, llvm::BasicBlock &terminatorBlock, llvm::BasicBlock &unwindResumeBlock, llvm::Value **exceptionCaughtFlag, - llvm::Value **exceptionStorage -#ifndef OLD_EXC_SYSTEM - ,llvm::Value **caughtResultStorage -#endif - ) { + llvm::Value **exceptionStorage, + llvm::Value **caughtResultStorage) { assert(exceptionCaughtFlag && "ExceptionDemo::createFinallyBlock(...):exceptionCaughtFlag " "is NULL"); assert(exceptionStorage && "ExceptionDemo::createFinallyBlock(...):exceptionStorage " "is NULL"); - -#ifndef OLD_EXC_SYSTEM assert(caughtResultStorage && "ExceptionDemo::createFinallyBlock(...):caughtResultStorage " "is NULL"); -#endif *exceptionCaughtFlag = createEntryBlockAlloca(toAddTo, "exceptionCaught", @@ -1011,13 +997,11 @@ static llvm::BasicBlock *createFinallyBlock(llvm::LLVMContext &context, exceptionStorageType, llvm::ConstantPointerNull::get( exceptionStorageType)); -#ifndef OLD_EXC_SYSTEM *caughtResultStorage = createEntryBlockAlloca(toAddTo, "caughtResultStorage", ourCaughtResultType, llvm::ConstantAggregateZero::get( ourCaughtResultType)); -#endif llvm::BasicBlock *ret = llvm::BasicBlock::Create(context, blockName, @@ -1171,9 +1155,7 @@ llvm::Function *createCatchWrappedInvokeFunction(llvm::Module &module, std::vector<llvm::BasicBlock*> catchBlocks(numExceptionsToCatch); llvm::Value *exceptionCaughtFlag = NULL; llvm::Value *exceptionStorage = NULL; -#ifndef OLD_EXC_SYSTEM llvm::Value *caughtResultStorage = NULL; -#endif // Finally block which will branch to unwindResumeBlock if // exception is not caught. Initializes/allocates stack locations. @@ -1186,10 +1168,8 @@ llvm::Function *createCatchWrappedInvokeFunction(llvm::Module &module, *endBlock, *unwindResumeBlock, &exceptionCaughtFlag, - &exceptionStorage -#ifndef OLD_EXC_SYSTEM - ,&caughtResultStorage -#endif + &exceptionStorage, + &caughtResultStorage ); for (unsigned i = 0; i < numExceptionsToCatch; ++i) { @@ -1250,15 +1230,7 @@ llvm::Function *createCatchWrappedInvokeFunction(llvm::Module &module, builder.SetInsertPoint(unwindResumeBlock); - -#ifndef OLD_EXC_SYSTEM builder.CreateResume(builder.CreateLoad(caughtResultStorage)); -#else - llvm::Function *resumeOurException = module.getFunction("_Unwind_Resume"); - builder.CreateCall(resumeOurException, - builder.CreateLoad(exceptionStorage)); - builder.CreateUnreachable(); -#endif // Exception Block @@ -1266,7 +1238,6 @@ llvm::Function *createCatchWrappedInvokeFunction(llvm::Module &module, llvm::Function *personality = module.getFunction("ourPersonality"); -#ifndef OLD_EXC_SYSTEM llvm::LandingPadInst *caughtResult = builder.CreateLandingPad(ourCaughtResultType, personality, @@ -1290,42 +1261,6 @@ llvm::Function *createCatchWrappedInvokeFunction(llvm::Module &module, builder.CreateStore(caughtResult, caughtResultStorage); builder.CreateStore(unwindException, exceptionStorage); builder.CreateStore(ourExceptionThrownState, exceptionCaughtFlag); -#else - llvm::Function *ehException = module.getFunction("llvm.eh.exception"); - - // Retrieve thrown exception - llvm::Value *unwindException = builder.CreateCall(ehException); - - // Store exception and flag - builder.CreateStore(unwindException, exceptionStorage); - builder.CreateStore(ourExceptionThrownState, exceptionCaughtFlag); - llvm::Value *functPtr = builder.CreatePointerCast(personality, - builder.getInt8PtrTy()); - - args.clear(); - args.push_back(unwindException); - args.push_back(functPtr); - - // Note: Skipping index 0 - for (unsigned i = 0; i < numExceptionsToCatch; ++i) { - // Set up type infos to be caught - args.push_back(module.getGlobalVariable( - ourTypeInfoNames[exceptionTypesToCatch[i]])); - } - - args.push_back(llvm::ConstantInt::get(builder.getInt32Ty(), 0)); - - llvm::Function *ehSelector = module.getFunction("llvm.eh.selector"); - - // Set up this exeption block as the landing pad which will handle - // given type infos. See case Intrinsic::eh_selector in - // SelectionDAGBuilder::visitIntrinsicCall(...) and AddCatchInfo(...) - // implemented in FunctionLoweringInfo.cpp to see how the implementation - // handles this call. This landing pad (this exception block), will be - // called either because it nees to cleanup (call finally) or a type - // info was found which matched the thrown exception. - llvm::Value *retTypeInfoIndex = builder.CreateCall(ehSelector, args); -#endif // Retrieve exception_class member from thrown exception // (_Unwind_Exception instance). This member tells us whether or not @@ -1404,12 +1339,6 @@ llvm::Function *createCatchWrappedInvokeFunction(llvm::Module &module, catchBlocks[nextTypeToCatch]); } -#ifdef OLD_EXC_SYSTEM - // Must be run before verifier - UpgradeExceptionHandling(&module); -#endif - - llvm::verifyFunction(*ret); fpm.run(*ret); @@ -1709,8 +1638,6 @@ static void createStandardUtilityFunctions(unsigned numTypeInfos, ourTypeInfoType = llvm::StructType::get(context, TypeArray(builder.getInt32Ty())); -#ifndef OLD_EXC_SYSTEM - llvm::Type *caughtResultFieldTypes[] = { builder.getInt8PtrTy(), builder.getInt32Ty() @@ -1720,8 +1647,6 @@ static void createStandardUtilityFunctions(unsigned numTypeInfos, ourCaughtResultType = llvm::StructType::get(context, TypeArray(caughtResultFieldTypes)); -#endif - // Create OurException type ourExceptionType = llvm::StructType::get(context, TypeArray(ourTypeInfoType)); @@ -1965,14 +1890,6 @@ static void createStandardUtilityFunctions(unsigned numTypeInfos, true, false); - // llvm.eh.selector intrinsic - - getDeclaration(&module, llvm::Intrinsic::eh_selector); - - // llvm.eh.exception intrinsic - - getDeclaration(&module, llvm::Intrinsic::eh_exception); - // llvm.eh.typeid.for intrinsic getDeclaration(&module, llvm::Intrinsic::eh_typeid_for); @@ -2005,7 +1922,8 @@ int main(int argc, char *argv[]) { } // If not set, exception handling will not be turned on - llvm::JITExceptionHandling = true; + llvm::TargetOptions Opts; + Opts.JITExceptionHandling = true; llvm::InitializeNativeTarget(); llvm::LLVMContext &context = llvm::getGlobalContext(); @@ -2018,6 +1936,7 @@ int main(int argc, char *argv[]) { llvm::EngineBuilder factory(module); factory.setEngineKind(llvm::EngineKind::JIT); factory.setAllocateGVsWithCode(false); + factory.setTargetOptions(Opts); llvm::ExecutionEngine *executionEngine = factory.create(); { |