llvm.org GIT mirror llvm / 08e8db4
Update to the new EH system...remove OLD EH code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149728 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 7 years ago
1 changed file(s) with 4 addition(s) and 88 deletion(s). Raw diff Collapse all Expand all
6262 #include "llvm/Support/Dwarf.h"
6363 #include "llvm/Support/TargetSelect.h"
6464
65 #ifdef OLD_EXC_SYSTEM
66 // See use of UpgradeExceptionHandling(...) below
67 #include "llvm/AutoUpgrade.h"
68 #endif
69
7065 // FIXME: Although all systems tested with (Linux, OS X), do not need this
7166 // header file included. A user on ubuntu reported, undefined symbols
7267 // for stderr, and fprintf, and the addition of this include fixed the
187182 static std::map ourTypeInfoNamesIndex;
188183
189184 static llvm::StructType *ourTypeInfoType;
190 #ifndef OLD_EXC_SYSTEM
191185 static llvm::StructType *ourCaughtResultType;
192 #endif
193186 static llvm::StructType *ourExceptionType;
194187 static llvm::StructType *ourUnwindExceptionType;
195188
968961 /// @param unwindResumeBlock unwind resume block
969962 /// @param exceptionCaughtFlag reference exception caught/thrown status storage
970963 /// @param exceptionStorage reference to exception pointer storage
971 #ifndef OLD_EXC_SYSTEM
972964 /// @param caughtResultStorage reference to landingpad result storage
973 #endif
974965 /// @returns newly created block
975966 static llvm::BasicBlock *createFinallyBlock(llvm::LLVMContext &context,
976967 llvm::Module &module,
981972 llvm::BasicBlock &terminatorBlock,
982973 llvm::BasicBlock &unwindResumeBlock,
983974 llvm::Value **exceptionCaughtFlag,
984 llvm::Value **exceptionStorage
985 #ifndef OLD_EXC_SYSTEM
986 ,llvm::Value **caughtResultStorage
987 #endif
988 ) {
975 llvm::Value **exceptionStorage,
976 llvm::Value **caughtResultStorage) {
989977 assert(exceptionCaughtFlag &&
990978 "ExceptionDemo::createFinallyBlock(...):exceptionCaughtFlag "
991979 "is NULL");
992980 assert(exceptionStorage &&
993981 "ExceptionDemo::createFinallyBlock(...):exceptionStorage "
994982 "is NULL");
995
996 #ifndef OLD_EXC_SYSTEM
997983 assert(caughtResultStorage &&
998984 "ExceptionDemo::createFinallyBlock(...):caughtResultStorage "
999985 "is NULL");
1000 #endif
1001986
1002987 *exceptionCaughtFlag = createEntryBlockAlloca(toAddTo,
1003988 "exceptionCaught",
1010995 exceptionStorageType,
1011996 llvm::ConstantPointerNull::get(
1012997 exceptionStorageType));
1013 #ifndef OLD_EXC_SYSTEM
1014998 *caughtResultStorage = createEntryBlockAlloca(toAddTo,
1015999 "caughtResultStorage",
10161000 ourCaughtResultType,
10171001 llvm::ConstantAggregateZero::get(
10181002 ourCaughtResultType));
1019 #endif
10201003
10211004 llvm::BasicBlock *ret = llvm::BasicBlock::Create(context,
10221005 blockName,
11701153 std::vector catchBlocks(numExceptionsToCatch);
11711154 llvm::Value *exceptionCaughtFlag = NULL;
11721155 llvm::Value *exceptionStorage = NULL;
1173 #ifndef OLD_EXC_SYSTEM
11741156 llvm::Value *caughtResultStorage = NULL;
1175 #endif
11761157
11771158 // Finally block which will branch to unwindResumeBlock if
11781159 // exception is not caught. Initializes/allocates stack locations.
11851166 *endBlock,
11861167 *unwindResumeBlock,
11871168 &exceptionCaughtFlag,
1188 &exceptionStorage
1189 #ifndef OLD_EXC_SYSTEM
1190 ,&caughtResultStorage
1191 #endif
1169 &exceptionStorage,
1170 &caughtResultStorage
11921171 );
11931172
11941173 for (unsigned i = 0; i < numExceptionsToCatch; ++i) {
12491228
12501229 builder.SetInsertPoint(unwindResumeBlock);
12511230
1252
1253 #ifndef OLD_EXC_SYSTEM
12541231 builder.CreateResume(builder.CreateLoad(caughtResultStorage));
1255 #else
1256 llvm::Function *resumeOurException = module.getFunction("_Unwind_Resume");
1257 builder.CreateCall(resumeOurException,
1258 builder.CreateLoad(exceptionStorage));
1259 builder.CreateUnreachable();
1260 #endif
12611232
12621233 // Exception Block
12631234
12651236
12661237 llvm::Function *personality = module.getFunction("ourPersonality");
12671238
1268 #ifndef OLD_EXC_SYSTEM
12691239 llvm::LandingPadInst *caughtResult =
12701240 builder.CreateLandingPad(ourCaughtResultType,
12711241 personality,
12891259 builder.CreateStore(caughtResult, caughtResultStorage);
12901260 builder.CreateStore(unwindException, exceptionStorage);
12911261 builder.CreateStore(ourExceptionThrownState, exceptionCaughtFlag);
1292 #else
1293 llvm::Function *ehException = module.getFunction("llvm.eh.exception");
1294
1295 // Retrieve thrown exception
1296 llvm::Value *unwindException = builder.CreateCall(ehException);
1297
1298 // Store exception and flag
1299 builder.CreateStore(unwindException, exceptionStorage);
1300 builder.CreateStore(ourExceptionThrownState, exceptionCaughtFlag);
1301 llvm::Value *functPtr = builder.CreatePointerCast(personality,
1302 builder.getInt8PtrTy());
1303
1304 args.clear();
1305 args.push_back(unwindException);
1306 args.push_back(functPtr);
1307
1308 // Note: Skipping index 0
1309 for (unsigned i = 0; i < numExceptionsToCatch; ++i) {
1310 // Set up type infos to be caught
1311 args.push_back(module.getGlobalVariable(
1312 ourTypeInfoNames[exceptionTypesToCatch[i]]));
1313 }
1314
1315 args.push_back(llvm::ConstantInt::get(builder.getInt32Ty(), 0));
1316
1317 llvm::Function *ehSelector = module.getFunction("llvm.eh.selector");
1318
1319 // Set up this exeption block as the landing pad which will handle
1320 // given type infos. See case Intrinsic::eh_selector in
1321 // SelectionDAGBuilder::visitIntrinsicCall(...) and AddCatchInfo(...)
1322 // implemented in FunctionLoweringInfo.cpp to see how the implementation
1323 // handles this call. This landing pad (this exception block), will be
1324 // called either because it nees to cleanup (call finally) or a type
1325 // info was found which matched the thrown exception.
1326 llvm::Value *retTypeInfoIndex = builder.CreateCall(ehSelector, args);
1327 #endif
13281262
13291263 // Retrieve exception_class member from thrown exception
13301264 // (_Unwind_Exception instance). This member tells us whether or not
14031337 catchBlocks[nextTypeToCatch]);
14041338 }
14051339
1406 #ifdef OLD_EXC_SYSTEM
1407 // Must be run before verifier
1408 UpgradeExceptionHandling(&module);
1409 #endif
1410
1411
14121340 llvm::verifyFunction(*ret);
14131341 fpm.run(*ret);
14141342
17081636 ourTypeInfoType = llvm::StructType::get(context,
17091637 TypeArray(builder.getInt32Ty()));
17101638
1711 #ifndef OLD_EXC_SYSTEM
1712
17131639 llvm::Type *caughtResultFieldTypes[] = {
17141640 builder.getInt8PtrTy(),
17151641 builder.getInt32Ty()
17181644 // Create our landingpad result type
17191645 ourCaughtResultType = llvm::StructType::get(context,
17201646 TypeArray(caughtResultFieldTypes));
1721
1722 #endif
17231647
17241648 // Create OurException type
17251649 ourExceptionType = llvm::StructType::get(context,
19631887 llvm::Function::ExternalLinkage,
19641888 true,
19651889 false);
1966
1967 // llvm.eh.selector intrinsic
1968
1969 getDeclaration(&module, llvm::Intrinsic::eh_selector);
1970
1971 // llvm.eh.exception intrinsic
1972
1973 getDeclaration(&module, llvm::Intrinsic::eh_exception);
19741890
19751891 // llvm.eh.typeid.for intrinsic
19761892