Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(473)

Unified Diff: runtime/vm/flow_graph_builder.cc

Issue 2322853003: VM: Zero-cost try-finally with an empty finally-block. (Closed)
Patch Set: rebased Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/ast.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/flow_graph_builder.cc
diff --git a/runtime/vm/flow_graph_builder.cc b/runtime/vm/flow_graph_builder.cc
index 6ac47b80e3f930d349e5ef254c03bef06c94de6d..7a014804248ad8e381043bd17491e6f97f3653d3 100644
--- a/runtime/vm/flow_graph_builder.cc
+++ b/runtime/vm/flow_graph_builder.cc
@@ -4225,6 +4225,24 @@ void EffectGraphVisitor::VisitCatchClauseNode(CatchClauseNode* node) {
void EffectGraphVisitor::VisitTryCatchNode(TryCatchNode* node) {
InlineBailout("EffectGraphVisitor::VisitTryCatchNode (exception)");
+ CatchClauseNode* catch_block = node->catch_block();
+ SequenceNode* finally_block = node->finally_block();
+ if ((finally_block != NULL) && (finally_block->length() == 0)) {
+ SequenceNode* catch_sequence = catch_block->sequence();
+ if (catch_sequence->length() == 1) {
+ // Check for a single rethrow statement. This only matches the synthetic
+ // catch-clause generated for try-finally.
+ ThrowNode* throw_node = catch_sequence->NodeAt(0)->AsThrowNode();
+ if ((throw_node != NULL) && (throw_node->stacktrace() != NULL)) {
+ // Empty finally-block in a try-finally can be optimized away.
+ EffectGraphVisitor for_try(owner());
+ node->try_block()->Visit(&for_try);
+ Append(for_try);
+ return;
+ }
+ }
+ }
+
const intptr_t original_handler_index = owner()->try_index();
const intptr_t try_handler_index = node->try_index();
ASSERT(try_handler_index != original_handler_index);
@@ -4254,9 +4272,6 @@ void EffectGraphVisitor::VisitTryCatchNode(TryCatchNode* node) {
// We are done generating code for the try block.
owner()->set_try_index(original_handler_index);
- CatchClauseNode* catch_block = node->catch_block();
- SequenceNode* finally_block = node->finally_block();
-
// If there is a finally block, it is the handler for code in the catch
// block.
const intptr_t catch_handler_index = (finally_block == NULL)
« no previous file with comments | « runtime/vm/ast.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698