Lines Matching +full:actions +full:- +full:builder

1 //===-- ExceptionDemo.cpp - An example using llvm Exceptions --------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
13 // of -1 will trigger a foreign C++ exception to be thrown; type info types
28 // ExceptionDemo 2 3 7 -1
31 // - Value 2 causes an exception with a type info type of 2 to be
33 // - Value 3 causes an exception with a type info type of 3 to be
35 // - Value 7 causes an exception with a type info type of 7 to be
37 // - Value -1 causes a foreign C++ exception to be thrown and not be
40 // Cases -1 and 7 are caught by a C++ test harness where the validity of
43 // http://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html (v1.22)
45 // This code uses code from the llvm compiler-rt project and the llvm
48 //===----------------------------------------------------------------------===//
106 /// http://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html
183 for (llvm::Function::arg_iterator argIndex = ret->arg_begin();
187 argIndex->setName(theArgNames[i]);
295 (expToDelete->exception_class == ourBaseExceptionClass)) {
305 /// @param reason See @link http://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html
325 (ret->type).type = type;
326 (ret->unwindException).exception_class = ourBaseExceptionClass;
327 (ret->unwindException).exception_cleanup = deleteFromUnwindOurException;
329 return(&(ret->unwindException));
487 /// Deals with Dwarf actions matching our type infos
495 /// Also see @link http://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html @unlink
520 struct OurExceptionType_t *excpType = &(excp->type);
521 int type = excpType->type;
563 const uint8_t *EntryP = ClassInfo - typeOffset * EncSize;
567 if (ThisClassInfo->type == type) {
589 /// See @link http://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html @unlink
592 /// @param _Unwind_Action actions minimally supported unwind stage
600 _Unwind_Action actions,
611 "handleLsda(...):lsda is non-zero.\n");
616 uintptr_t pc = _Unwind_GetIP(context)-1;
621 uintptr_t pcOffset = pc - funcStart;
645 // Walk call-site table looking for range that
683 actionEntry += ((uintptr_t) actionTableStart) - 1;
710 if (!(actions & _UA_SEARCH_PHASE)) {
718 // Set Instruction Pointer to so we re-enter function
753 // Note: Only non-clean up handlers are marked as
755 // re-found and executed during the clean up
773 /// See @link http://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html @unlink
775 /// @param _Unwind_Action actions minimally supported unwind stage
782 _Unwind_Reason_Code ourPersonality(int version, _Unwind_Action actions,
788 "We are in ourPersonality(...):actions is <%d>.\n",
789 actions);
791 if (actions & _UA_SEARCH_PHASE) {
795 fprintf(stderr, "ourPersonality(...):In non-search phase.\n");
810 actions,
820 /// See @link http://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html @unlink
849 /// @param builder builder instance
857 llvm::IRBuilder<> &builder,
870 stringConstant->getType(),
877 stringVar = builder.CreateAlloca(stringConstant->getType());
878 builder.CreateStore(stringConstant, stringVar);
881 llvm::Value *cast = builder.CreatePointerCast(stringVar,
882 builder.getPtrTy());
883 builder.CreateCall(printFunct, cast);
890 /// @param builder builder instance
899 llvm::IRBuilder<> &builder,
910 stringConstant->getType(),
917 stringVar = builder.CreateAlloca(stringConstant->getType());
918 builder.CreateStore(stringConstant, stringVar);
921 llvm::Value *cast = builder.CreateBitCast(stringVar,
922 builder.getPtrTy());
923 builder.CreateCall(&printFunct, {toPrint, cast});
929 /// to stderr, this code will resume the exception handling--runs the
936 /// @param builder builder instance
948 llvm::IRBuilder<> &builder,
969 ourExceptionNotThrownState->getType(),
972 llvm::PointerType *exceptionStorageType = builder.getPtrTy();
988 builder.SetInsertPoint(ret);
995 builder,
999 llvm::SwitchInst *theSwitch = builder.CreateSwitch(
1000 builder.CreateLoad(ourExceptionNotThrownState->getType(),
1003 theSwitch->addCase(ourExceptionCaughtState, &terminatorBlock);
1004 theSwitch->addCase(ourExceptionThrownState, &unwindResumeBlock);
1015 /// @param builder builder instance
1024 llvm::IRBuilder<> &builder,
1035 builder.SetInsertPoint(ret);
1045 builder,
1048 builder.CreateStore(ourExceptionCaughtState, &exceptionCaughtFlag);
1049 builder.CreateBr(&terminatorBlock);
1066 /// @param builder builder instance
1075 llvm::Module &module, llvm::IRBuilder<> &builder,
1084 argTypes.push_back(builder.getInt32Ty());
1090 builder.getVoidTy(),
1139 builder,
1156 builder,
1166 builder.SetInsertPoint(entryBlock);
1170 builder.CreateInvoke(&toInvoke,
1177 builder.SetInsertPoint(endBlock);
1181 builder,
1187 builder.CreateCall(deleteOurException,
1188 builder.CreateLoad(builder.getPtrTy(), exceptionStorage));
1189 builder.CreateRetVoid();
1193 builder.SetInsertPoint(normalBlock);
1197 builder,
1202 builder.CreateBr(finallyBlock);
1206 builder.SetInsertPoint(unwindResumeBlock);
1208 builder.CreateResume(
1209 builder.CreateLoad(ourCaughtResultType, caughtResultStorage));
1213 builder.SetInsertPoint(exceptionBlock);
1216 ret->setPersonalityFn(personality);
1219 builder.CreateLandingPad(ourCaughtResultType,
1223 caughtResult->setCleanup(true);
1227 caughtResult->addClause(module.getGlobalVariable(
1231 llvm::Value *unwindException = builder.CreateExtractValue(caughtResult, 0);
1232 llvm::Value *retTypeInfoIndex = builder.CreateExtractValue(caughtResult, 1);
1237 builder.CreateStore(caughtResult, caughtResultStorage);
1238 builder.CreateStore(unwindException, exceptionStorage);
1239 builder.CreateStore(ourExceptionThrownState, exceptionCaughtFlag);
1244 llvm::Value *unwindExceptionClass = builder.CreateLoad(
1245 builder.getInt64Ty(),
1246 builder.CreateStructGEP(ourUnwindExceptionType, unwindException, 0));
1250 builder.CreateCondBr(builder.CreateICmpEQ(unwindExceptionClass,
1251 llvm::ConstantInt::get(builder.getInt64Ty(),
1258 builder.SetInsertPoint(externalExceptionBlock);
1262 builder,
1267 builder.CreateBr(finallyBlock);
1271 builder.SetInsertPoint(exceptionRouteBlock);
1277 llvm::Value *typeInfoThrown = builder.CreateConstGEP1_64(
1278 builder.getInt8Ty(), unwindException, ourBaseFromUnwindOffset);
1284 typeInfoThrown = builder.CreateStructGEP(ourExceptionType, typeInfoThrown, 0);
1287 builder.CreateStructGEP(ourTypeInfoType, typeInfoThrown, 0);
1290 builder.CreateLoad(builder.getInt32Ty(), typeInfoThrownType);
1291 generateIntegerPrint(context, module, builder, *toPrint32Int, ti32,
1298 llvm::SwitchInst *switchToCatchBlock = builder.CreateSwitch(retTypeInfoIndex,
1305 nextTypeToCatch = i - 1;
1306 switchToCatchBlock->addCase(llvm::ConstantInt::get(builder.getInt32Ty(), i),
1322 /// @param builder builder instance
1332 createThrowExceptionFunction(llvm::Module &module, llvm::IRBuilder<> &builder,
1339 unwindArgTypes.push_back(builder.getInt32Ty());
1344 builder.getVoidTy(),
1370 builder.SetInsertPoint(nativeThrowBlock);
1373 builder.CreateCall(&nativeThrowFunct, exceptionType);
1374 builder.CreateUnreachable();
1378 builder.SetInsertPoint(entryBlock);
1381 generateIntegerPrint(context, module, builder, *toPrint32Int,
1382 builder.CreateZExt(exceptionType, builder.getInt32Ty()),
1390 llvm::SwitchInst *theSwitch = builder.CreateSwitch(exceptionType,
1394 theSwitch->addCase(llvm::ConstantInt::get(llvm::Type::getInt32Ty(context),
1400 builder.SetInsertPoint(generatedThrowBlock);
1407 llvm::Value *exception = builder.CreateCall(createOurException,
1411 builder.CreateCall(raiseOurException, exception);
1412 builder.CreateUnreachable();
1422 llvm::IRBuilder<> &builder);
1438 /// @param builder builder instance
1445 createUnwindExceptionTest(llvm::Module &module, llvm::IRBuilder<> &builder,
1455 builder);
1461 builder,
1473 builder,
1487 builder,
1541 ExitOnErr(JIT->lookup(function)).toPtr<OurExceptionThrowFunctType>();
1557 // http://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html (v1.22),
1575 /// @param builder builder instance
1578 llvm::IRBuilder<> &builder) {
1596 TypeArray(builder.getInt32Ty()));
1599 builder.getPtrTy(),
1600 builder.getInt32Ty()
1617 TypeArray(builder.getInt64Ty()));
1622 ourBaseFromUnwindOffset = ((uintptr_t) &dummyException) -
1628 "= %" PRIi64 ", sizeof(struct OurBaseException_t) - "
1631 sizeof(struct OurBaseException_t) -
1653 structVals.push_back(llvm::ConstantInt::get(builder.getInt32Ty(), i));
1678 llvm::Type *retType = builder.getVoidTy();
1681 argTypes.push_back(builder.getInt32Ty());
1682 argTypes.push_back(builder.getPtrTy());
1697 retType = builder.getVoidTy();
1700 argTypes.push_back(builder.getInt64Ty());
1701 argTypes.push_back(builder.getPtrTy());
1716 retType = builder.getVoidTy();
1719 argTypes.push_back(builder.getPtrTy());
1734 retType = builder.getVoidTy();
1737 argTypes.push_back(builder.getInt32Ty());
1752 retType = builder.getVoidTy();
1755 argTypes.push_back(builder.getPtrTy());
1770 retType = builder.getPtrTy();
1773 argTypes.push_back(builder.getInt32Ty());
1788 retType = builder.getInt32Ty();
1791 argTypes.push_back(builder.getPtrTy());
1804 funct->setDoesNotReturn();
1808 retType = builder.getInt32Ty();
1811 argTypes.push_back(builder.getPtrTy());
1824 funct->setDoesNotReturn();
1828 retType = builder.getInt32Ty();
1831 argTypes.push_back(builder.getInt32Ty());
1832 argTypes.push_back(builder.getInt32Ty());
1833 argTypes.push_back(builder.getInt64Ty());
1834 argTypes.push_back(builder.getPtrTy());
1835 argTypes.push_back(builder.getPtrTy());
1851 builder.getPtrTy());
1855 //===----------------------------------------------------------------------===//
1857 //===----------------------------------------------------------------------===//
1861 /// of -1 will trigger a foreign C++ exception to be thrown; type info types
1870 " Each type must have the value of 1 - 6 for "
1872 " the value -1 for foreign C++ exceptions to be "
1875 "\nTry: ExceptionDemo 2 3 7 -1\n"
1906 // Do simple "peephole" optimizations and bit-twiddling optzns.
1926 ExitOnErr(JIT->addIRModule(
1932 module->print(llvm::errs(), nullptr);