Coalesce last catch mismatch block with unwind resume block if possible

Makes IR a bit more compact.
This commit is contained in:
David Nadlinger 2015-08-19 08:24:57 +02:00
parent 4bcae9731a
commit db8f0fd8e2

View file

@ -341,7 +341,7 @@ llvm::BasicBlock* ScopeStack::emitLandingPad() {
} }
irs->ir->CreateStore(ehSelector, irs->func()->ehSelectorSlot); irs->ir->CreateStore(ehSelector, irs->func()->ehSelectorSlot);
// Add landingpad clauses, emit finallys and 'if' chain to catch the exception, // Add landingpad clauses, emit finallys and 'if' chain to catch the exception.
CleanupCursor lastCleanup = currentCleanupScope(); CleanupCursor lastCleanup = currentCleanupScope();
for (std::vector<CatchScope>::reverse_iterator it = catchScopes.rbegin(), for (std::vector<CatchScope>::reverse_iterator it = catchScopes.rbegin(),
end = catchScopes.rend(); end = catchScopes.rend();
@ -389,6 +389,11 @@ llvm::BasicBlock* ScopeStack::emitLandingPad() {
if (lastCleanup > 0) { if (lastCleanup > 0) {
landingPad->setCleanup(true); landingPad->setCleanup(true);
runCleanups(lastCleanup, 0, irs->func()->resumeUnwindBlock); runCleanups(lastCleanup, 0, irs->func()->resumeUnwindBlock);
} else if (!catchScopes.empty()) {
// Directly convert the last mismatch branch into a branch to the
// unwind resume block.
irs->scopebb()->replaceAllUsesWith(irs->func()->resumeUnwindBlock);
irs->scopebb()->eraseFromParent();
} else { } else {
irs->ir->CreateBr(irs->func()->resumeUnwindBlock); irs->ir->CreateBr(irs->func()->resumeUnwindBlock);
} }