Home | History | Annotate | Download | only in CodeGen

Lines Matching refs:CGF

25 static llvm::Constant *getAllocateExceptionFn(CodeGenFunction &CGF) {
29 llvm::FunctionType::get(CGF.Int8PtrTy, CGF.SizeTy, /*IsVarArgs=*/false);
31 return CGF.CGM.CreateRuntimeFunction(FTy, "__cxa_allocate_exception");
34 static llvm::Constant *getFreeExceptionFn(CodeGenFunction &CGF) {
38 llvm::FunctionType::get(CGF.VoidTy, CGF.Int8PtrTy, /*IsVarArgs=*/false);
40 return CGF.CGM.CreateRuntimeFunction(FTy, "__cxa_free_exception");
43 static llvm::Constant *getThrowFn(CodeGenFunction &CGF) {
47 llvm::Type *Args[3] = { CGF.Int8PtrTy, CGF.Int8PtrTy, CGF.Int8PtrTy };
49 llvm::FunctionType::get(CGF.VoidTy, Args, /*IsVarArgs=*/false);
51 return CGF.CGM.CreateRuntimeFunction(FTy, "__cxa_throw");
54 static llvm::Constant *getReThrowFn(CodeGenFunction &CGF) {
58 llvm::FunctionType::get(CGF.VoidTy, /*IsVarArgs=*/false);
60 return CGF.CGM.CreateRuntimeFunction(FTy, "__cxa_rethrow");
63 static llvm::Constant *getGetExceptionPtrFn(CodeGenFunction &CGF) {
67 llvm::FunctionType::get(CGF.Int8PtrTy, CGF.Int8PtrTy, /*IsVarArgs=*/false);
69 return CGF.CGM.CreateRuntimeFunction(FTy, "__cxa_get_exception_ptr");
72 static llvm::Constant *getBeginCatchFn(CodeGenFunction &CGF) {
76 llvm::FunctionType::get(CGF.Int8PtrTy, CGF.Int8PtrTy, /*IsVarArgs=*/false);
78 return CGF.CGM.CreateRuntimeFunction(FTy, "__cxa_begin_catch");
81 static llvm::Constant *getEndCatchFn(CodeGenFunction &CGF) {
85 llvm::FunctionType::get(CGF.VoidTy, /*IsVarArgs=*/false);
87 return CGF.CGM.CreateRuntimeFunction(FTy, "__cxa_end_catch");
90 static llvm::Constant *getUnexpectedFn(CodeGenFunction &CGF) {
94 llvm::FunctionType::get(CGF.VoidTy, CGF.Int8PtrTy, /*IsVarArgs=*/false);
96 return CGF.CGM.CreateRuntimeFunction(FTy, "__cxa_call_unexpected");
117 static llvm::Constant *getTerminateFn(CodeGenFunction &CGF) {
121 llvm::FunctionType::get(CGF.VoidTy, /*IsVarArgs=*/false);
126 if (CGF.getLangOpts().CPlusPlus)
128 else if (CGF.getLangOpts().ObjC1 &&
129 CGF.CGM.getCodeGenOpts().ObjCRuntimeHasTerminate)
133 return CGF.CGM.CreateRuntimeFunction(FTy, name);
136 static llvm::Constant *getCatchallRethrowFn(CodeGenFunction &CGF,
139 llvm::FunctionType::get(CGF.VoidTy, CGF.Int8PtrTy, /*IsVarArgs=*/false);
141 return CGF.CGM.CreateRuntimeFunction(FTy, Name);
335 static llvm::Constant *getCatchAllValue(CodeGenFunction &CGF) {
337 return llvm::ConstantPointerNull::get(CGF.Int8PtrTy);
346 void Emit(CodeGenFunction &CGF, Flags flags) {
347 CGF.Builder.CreateCall(getFreeExceptionFn(CGF), exn)
357 static void EmitAnyExprToExn(CodeGenFunction &CGF, const Expr *e,
361 CGF.pushFullExprCleanup<FreeException>(EHCleanup, addr);
362 EHScopeStack::stable_iterator cleanup = CGF.EHStack.stable_begin();
366 llvm::Type *ty = CGF.ConvertTypeForMem(e->getType())->getPointerTo();
367 llvm::Value *typedAddr = CGF.Builder.CreateBitCast(addr, ty);
376 CGF.EmitAnyExprToMem(e, typedAddr, e->getType().getQualifiers(),
380 CGF.DeactivateCleanupBlock(cleanup, cast<llvm::Instruction>(typedAddr));
504 static void emitFilterDispatchBlock(CodeGenFunction &CGF,
513 CGF.EmitBlockAfterUses(dispatchBlock);
519 llvm::Value *selector = CGF.getSelectorFromSlot();
520 llvm::BasicBlock *unexpectedBB = CGF.createBasicBlock("ehspec.unexpected");
522 llvm::Value *zero = CGF.Builder.getInt32(0);
524 CGF.Builder.CreateICmpSLT(selector, zero, "ehspec.fails");
525 CGF.Builder.CreateCondBr(failsFilter, unexpectedBB, CGF.getEHResumeBlock());
527 CGF.EmitBlock(unexpectedBB);
534 llvm::Value *exn = CGF.getExceptionFromSlot();
535 CGF.Builder.CreateCall(getUnexpectedFn(CGF), exn)
537 CGF.Builder.CreateUnreachable();
895 void Emit(CodeGenFunction &CGF, Flags flags) {
897 CGF.Builder.CreateCall(getEndCatchFn(CGF))->setDoesNotThrow();
901 CGF.EmitCallOrInvoke(getEndCatchFn(CGF));
910 static llvm::Value *CallBeginCatch(CodeGenFunction &CGF,
913 llvm::CallInst *Call = CGF.Builder.CreateCall(getBeginCatchFn(CGF), Exn);
916 CGF.EHStack.pushCleanup<CallEndCatch>(NormalAndEHCleanup, EndMightThrow);
923 static void InitCatchParam(CodeGenFunction &CGF,
927 llvm::Value *Exn = CGF.getExceptionFromSlot();
930 CGF.CGM.getContext().getCanonicalType(CatchParam.getType());
931 llvm::Type *LLVMCatchTy = CGF.ConvertTypeForMem(CatchType);
940 llvm::Value *AdjustedExn = CallBeginCatch(CGF, Exn, EndCatchMightThrow);
955 CGF.CGM.getTargetCodeGenInfo().getSizeOfUnwindException();
956 AdjustedExn = CGF.Builder.CreateConstGEP1_32(Exn, HeaderSize);
978 llvm::Value *ExnPtrTmp = CGF.CreateTempAlloca(PtrTy, "exn.byref.tmp");
979 llvm::Value *Casted = CGF.Builder.CreateBitCast(AdjustedExn, PtrTy);
980 CGF.Builder.CreateStore(Casted, ExnPtrTmp);
988 CGF.Builder.CreateBitCast(AdjustedExn, LLVMCatchTy, "exn.byref");
989 CGF.Builder.CreateStore(ExnCast, ParamAddr);
995 if (!CGF.hasAggregateLLVMType(CatchType) ||
997 llvm::Value *AdjustedExn = CallBeginCatch(CGF, Exn, false);
1003 CGF.Builder.CreateBitCast(AdjustedExn, LLVMCatchTy, "exn.casted");
1007 CastExn = CGF.EmitARCRetainNonBlock(CastExn);
1013 CGF.Builder.CreateStore(CastExn, ParamAddr);
1017 CGF.EmitARCInitWeak(ParamAddr, CastExn);
1026 llvm::Value *Cast = CGF.Builder.CreateBitCast(AdjustedExn, PtrTy);
1029 CGF.StoreComplexToAddr(CGF.LoadComplexFromAddr(Cast, /*volatile*/ false),
1033 CGF.getContext().getDeclAlign(&CatchParam).getQuantity();
1034 llvm::Value *ExnLoad = CGF.Builder.CreateLoad(Cast, "exn.scalar");
1035 CGF.EmitStoreOfScalar(ExnLoad, ParamAddr, /*volatile*/ false, Alignment,
1049 llvm::Value *rawAdjustedExn = CallBeginCatch(CGF, Exn, true);
1050 llvm::Value *adjustedExn = CGF.Builder.CreateBitCast(rawAdjustedExn, PtrTy);
1051 CGF.EmitAggregateCopy(ParamAddr, adjustedExn, CatchType);
1058 CGF.Builder.CreateCall(getGetExceptionPtrFn(CGF), Exn);
1062 llvm::Value *adjustedExn = CGF.Builder.CreateBitCast(rawAdjustedExn, PtrTy);
1067 opaque(CGF, OpaqueValueExpr::findInCopyConstruct(copyExpr),
1068 CGF.MakeAddrLValue(adjustedExn, CatchParam.getType()));
1071 CGF.EHStack.pushTerminate();
1074 CharUnits Alignment = CGF.getContext().getDeclAlign(&CatchParam);
1075 CGF.EmitAggExpr(copyExpr,
1082 CGF.EHStack.popTerminate();
1088 CallBeginCatch(CGF, Exn, true);
1093 static void BeginCatch(CodeGenFunction &CGF, const CXXCatchStmt *S) {
1119 llvm::Value *Exn = CGF.getExceptionFromSlot();
1120 CallBeginCatch(CGF, Exn, true);
1125 CodeGenFunction::AutoVarEmission var = CGF.EmitAutoVarAlloca(*CatchParam);
1126 InitCatchParam(CGF, *CatchParam, var.getObjectAddress(CGF));
1127 CGF.EmitAutoVarCleanups(var);
1132 void Emit(CodeGenFunction &CGF, Flags flags) {
1133 CGF.EmitCallOrInvoke(getReThrowFn(CGF));
1140 static void emitCatchDispatchBlock(CodeGenFunction &CGF,
1153 CGBuilderTy::InsertPoint savedIP = CGF.Builder.saveIP();
1154 CGF.EmitBlockAfterUses(dispatchBlock);
1158 CGF.CGM.getIntrinsic(llvm::Intrinsic::eh_typeid_for);
1161 llvm::Value *selector = CGF.getSelectorFromSlot();
1170 typeValue = CGF.Builder.CreateBitCast(typeValue, CGF.Int8PtrTy);
1179 nextBlock = CGF.getEHDispatchBlock(catchScope.getEnclosingEHScope());
1190 nextBlock = CGF.createBasicBlock("catch.fallthrough");
1196 CGF.Builder.CreateCall(llvm_eh_typeid_for, typeValue);
1200 CGF.Builder.CreateICmpEQ(selector, typeIndex, "matches");
1201 CGF.Builder.CreateCondBr(matchesTypeIndex, handler.Block, nextBlock);
1205 CGF.Builder.restoreIP(savedIP);
1209 CGF.EmitBlock(nextBlock);
1303 void Emit(CodeGenFunction &CGF, Flags flags) {
1304 llvm::BasicBlock *EndCatchBB = CGF.createBasicBlock("finally.endcatch");
1306 CGF.createBasicBlock("finally.cleanup.cont");
1309 CGF.Builder.CreateLoad(ForEHVar, "finally.endcatch");
1310 CGF.Builder.CreateCondBr(ShouldEndCatch, EndCatchBB, CleanupContBB);
1311 CGF.EmitBlock(EndCatchBB);
1312 CGF.EmitCallOrInvoke(EndCatchFn); // catch-all, so might throw
1313 CGF.EmitBlock(CleanupContBB);
1330 void Emit(CodeGenFunction &CGF, Flags flags) {
1333 CGF.EHStack.pushCleanup<CallEndCatchForFinally>(NormalAndEHCleanup,
1339 CGFCGF.getNormalCleanupDestSlot(),
1343 CGF.EmitStmt(Body);
1347 if (CGF.HaveInsertPoint()) {
1348 llvm::BasicBlock *RethrowBB = CGF.createBasicBlock("finally.rethrow");
1349 llvm::BasicBlock *ContBB = CGF.createBasicBlock("finally.cont");
1352 CGF.Builder.CreateLoad(ForEHVar, "finally.shouldthrow");
1353 CGF.Builder.CreateCondBr(ShouldRethrow, RethrowBB, ContBB);
1355 CGF.EmitBlock(RethrowBB);
1357 CGF.EmitCallOrInvoke(RethrowFn, CGF.Builder.CreateLoad(SavedExnVar));
1359 CGF.EmitCallOrInvoke(RethrowFn);
1361 CGF.Builder.CreateUnreachable();
1363 CGF.EmitBlock(ContBB);
1366 CGF.Builder.CreateStore(SavedCleanupDest,
1367 CGF.getNormalCleanupDestSlot());
1374 CGBuilderTy::InsertPoint SavedIP = CGF.Builder.saveAndClearIP();
1375 CGF.PopCleanupBlock();
1376 CGF.Builder.restoreIP(SavedIP);
1381 CGF.EnsureInsertPoint();
1389 void CodeGenFunction::FinallyInfo::enter(CodeGenFunction &CGF,
1411 SavedExnVar = CGF.CreateTempAlloca(CGF.Int8PtrTy, "finally.exn");
1428 RethrowDest = CGF.getJumpDestInCurrentScope(CGF.getUnreachableBlock());
1431 ForEHVar = CGF.CreateTempAlloca(CGF.Builder.getInt1Ty(), "finally.for-eh");
1432 CGF.Builder.CreateStore(CGF.Builder.getFalse(), ForEHVar);
1435 CGF.EHStack.pushCleanup<PerformFinally>(NormalCleanup, body,
1440 llvm::BasicBlock *catchBB = CGF.createBasicBlock("finally.catchall");
1441 EHCatchScope *catchScope = CGF.EHStack.pushCatch(1);
1445 void CodeGenFunction::FinallyInfo::exit(CodeGenFunction &CGF) {
1447 EHCatchScope &catchScope = cast<EHCatchScope>(*CGF.EHStack.begin());
1450 CGF.popCatchScope();
1456 CGBuilderTy::InsertPoint savedIP = CGF.Builder.saveAndClearIP();
1457 CGF.EmitBlock(catchBB);
1463 exn = CGF.getExceptionFromSlot();
1464 CGF.Builder.CreateCall(BeginCatchFn, exn)->setDoesNotThrow();
1469 if (!exn) exn = CGF.getExceptionFromSlot();
1470 CGF.Builder.CreateStore(exn, SavedExnVar);
1474 CGF.Builder.CreateStore(CGF.Builder.getTrue(), ForEHVar);
1477 CGF.EmitBranchThroughCleanup(RethrowDest);
1479 CGF.Builder.restoreIP(savedIP);
1483 CGF.PopCleanupBlock();