From 6123e0effb35eda85af2fc4b9c56270afe2e9415 Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Fri, 6 Dec 2024 16:23:09 +0000 Subject: [PATCH] [vm/inlining] Set try-index for inlined function after decision is made. Delay setting try-index for callee flow graph until the decision to inline is made. This avoids confusing situation when running optimization passes on callee, where InsideTryBlock reports that the instruction is in try block, but there is no try block in the flow graph. TEST=ci Change-Id: Ia9dfa8b53dda9ca259dc73d810e7a4344971b904 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/399320 Reviewed-by: Alexander Markov Commit-Queue: Alexander Aprelev --- runtime/vm/compiler/backend/inliner.cc | 35 ++++++++++++-------------- runtime/vm/compiler/backend/inliner.h | 4 ++- runtime/vm/compiler/compiler_pass.cc | 5 ++-- runtime/vm/compiler/compiler_timings.h | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/runtime/vm/compiler/backend/inliner.cc b/runtime/vm/compiler/backend/inliner.cc index a98845cf41e..b5c4749079e 100644 --- a/runtime/vm/compiler/backend/inliner.cc +++ b/runtime/vm/compiler/backend/inliner.cc @@ -1399,17 +1399,6 @@ class CallSiteInliner : public ValueObject { ASSERT(arguments->length() == first_actual_param_index + function.NumParameters()); - // Update try-index of the callee graph. - BlockEntryInstr* call_block = call_data->call->GetBlock(); - if (call_block->InsideTryBlock()) { - intptr_t try_index = call_block->try_index(); - for (BlockIterator it = callee_graph->reverse_postorder_iterator(); - !it.Done(); it.Advance()) { - BlockEntryInstr* block = it.Current(); - block->set_try_index(try_index); - } - } - BlockScheduler::AssignEdgeWeights(callee_graph); { @@ -1574,10 +1563,12 @@ class CallSiteInliner : public ValueObject { } { - COMPILER_TIMINGS_TIMER_SCOPE(thread(), SetInliningId); - FlowGraphInliner::SetInliningId( - callee_graph, inliner_->NextInlineId(callee_graph->function(), - call_data->call->source())); + COMPILER_TIMINGS_TIMER_SCOPE(thread(), SetInliningIdAndTryIndex); + FlowGraphInliner::SetInliningIdAndTryIndex( + callee_graph, + inliner_->NextInlineId(callee_graph->function(), + call_data->call->source()), + call_data->call->GetBlock()->try_index()); } TRACE_INLINING(THR_Print(" Success\n")); TRACE_INLINING(THR_Print( @@ -2449,8 +2440,9 @@ void FlowGraphInliner::CollectGraphInfo(FlowGraph* flow_graph, *call_site_count = function.optimized_call_site_count(); } -void FlowGraphInliner::SetInliningId(FlowGraph* flow_graph, - intptr_t inlining_id) { +void FlowGraphInliner::SetInliningIdAndTryIndex(FlowGraph* flow_graph, + intptr_t inlining_id, + intptr_t caller_try_index) { ASSERT(flow_graph->inlining_id() < 0); flow_graph->set_inlining_id(inlining_id); // We only need to set the inlining ID on instructions that may possibly @@ -2458,8 +2450,13 @@ void FlowGraphInliner::SetInliningId(FlowGraph* flow_graph, // definitions. for (BlockIterator block_it = flow_graph->postorder_iterator(); !block_it.Done(); block_it.Advance()) { - for (ForwardInstructionIterator it(block_it.Current()); !it.Done(); - it.Advance()) { + BlockEntryInstr* block = block_it.Current(); + if (caller_try_index != kInvalidTryIndex) { + // Inlining of functions with try-blocks is not supported at the moment. + ASSERT(!block->InsideTryBlock()); + block->set_try_index(caller_try_index); + } + for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) { Instruction* current = it.Current(); current->set_inlining_id(inlining_id); } diff --git a/runtime/vm/compiler/backend/inliner.h b/runtime/vm/compiler/backend/inliner.h index 0aa19c9d100..4aa60c494e0 100644 --- a/runtime/vm/compiler/backend/inliner.h +++ b/runtime/vm/compiler/backend/inliner.h @@ -117,7 +117,9 @@ class FlowGraphInliner : ValueObject { intptr_t* instruction_count, intptr_t* call_site_count); - static void SetInliningId(FlowGraph* flow_graph, intptr_t inlining_id); + static void SetInliningIdAndTryIndex(FlowGraph* flow_graph, + intptr_t inlining_id, + intptr_t caller_try_index); bool AlwaysInline(const Function& function); diff --git a/runtime/vm/compiler/compiler_pass.cc b/runtime/vm/compiler/compiler_pass.cc index 4c2e9984782..978bbb7df1a 100644 --- a/runtime/vm/compiler/compiler_pass.cc +++ b/runtime/vm/compiler/compiler_pass.cc @@ -390,8 +390,9 @@ COMPILER_PASS(ApplyICData, { state->call_specializer->ApplyICData(); }); COMPILER_PASS(TryOptimizePatterns, { flow_graph->TryOptimizePatterns(); }); -COMPILER_PASS(SetOuterInliningId, - { FlowGraphInliner::SetInliningId(flow_graph, 0); }); +COMPILER_PASS(SetOuterInliningId, { + FlowGraphInliner::SetInliningIdAndTryIndex(flow_graph, 0, kInvalidTryIndex); +}); COMPILER_PASS(Inlining, { FlowGraphInliner inliner( diff --git a/runtime/vm/compiler/compiler_timings.h b/runtime/vm/compiler/compiler_timings.h index 26565b33392..b2266f16c4a 100644 --- a/runtime/vm/compiler/compiler_timings.h +++ b/runtime/vm/compiler/compiler_timings.h @@ -37,7 +37,7 @@ V(CollectGraphInfo) \ V(PopulateWithICData) \ V(FindCallSites) \ - V(SetInliningId) \ + V(SetInliningIdAndTryIndex) \ V(MakeInliningDecision) \ V(CheckForPragma) \ V(InlineCall) \