diff --git a/runtime/vm/compiler/backend/flow_graph_compiler_arm.cc b/runtime/vm/compiler/backend/flow_graph_compiler_arm.cc index 8762e1bcb1e..c02c1e3e9d7 100644 --- a/runtime/vm/compiler/backend/flow_graph_compiler_arm.cc +++ b/runtime/vm/compiler/backend/flow_graph_compiler_arm.cc @@ -890,16 +890,25 @@ void FlowGraphCompiler::EmitPrologue() { // R4: arguments descriptor array. void FlowGraphCompiler::CompileGraph() { InitCompiler(); -#ifdef DART_PRECOMPILER - const Function& function = parsed_function().function(); - if (function.IsDynamicFunction()) { - SpecialStatsBegin(CombinedCodeStatistics::kTagCheckedEntry); - __ MonomorphicCheckedEntry(); - SpecialStatsEnd(CombinedCodeStatistics::kTagCheckedEntry); - } -#endif // DART_PRECOMPILER + if (FLAG_precompiled_mode) { + const Function& function = parsed_function().function(); + if (function.IsDynamicFunction()) { + SpecialStatsBegin(CombinedCodeStatistics::kTagCheckedEntry); + __ MonomorphicCheckedEntry(); + SpecialStatsEnd(CombinedCodeStatistics::kTagCheckedEntry); + } + + // For JIT we have multiple entrypoints functionality which moved the + // intrinsification as well as the setup of the frame to the + // [TargetEntryInstr::EmitNativeCode]. + if (TryIntrinsify()) { + // Skip regular code generation. + return; + } + EmitFrameEntry(); + ASSERT(__ constant_pool_allowed()); + } - __ set_constant_pool_allowed(true); VisitBlocks(); __ bkpt(0); diff --git a/runtime/vm/compiler/backend/flow_graph_compiler_arm64.cc b/runtime/vm/compiler/backend/flow_graph_compiler_arm64.cc index 358afcf0f36..3c77a2f85cb 100644 --- a/runtime/vm/compiler/backend/flow_graph_compiler_arm64.cc +++ b/runtime/vm/compiler/backend/flow_graph_compiler_arm64.cc @@ -842,18 +842,26 @@ void FlowGraphCompiler::EmitFrameEntry() { // R4: arguments descriptor array. void FlowGraphCompiler::CompileGraph() { InitCompiler(); -#ifdef DART_PRECOMPILER - const Function& function = parsed_function().function(); - if (function.IsDynamicFunction()) { - __ MonomorphicCheckedEntry(); - } -#endif // DART_PRECOMPILER + if (FLAG_precompiled_mode) { + const Function& function = parsed_function().function(); + if (function.IsDynamicFunction()) { + SpecialStatsBegin(CombinedCodeStatistics::kTagCheckedEntry); + __ MonomorphicCheckedEntry(); + SpecialStatsEnd(CombinedCodeStatistics::kTagCheckedEntry); + } + } + + // For JIT we have multiple entrypoints functionality which moved the + // intrinsification as well as the setup of the frame to the + // [TargetEntryInstr::EmitNativeCode]. + // + // Though this has not been implemented on ARM64, which is why this code here + // is outside the "ifdef DART_PRECOMPILER". if (TryIntrinsify()) { // Skip regular code generation. return; } - EmitFrameEntry(); ASSERT(assembler()->constant_pool_allowed()); diff --git a/runtime/vm/compiler/backend/flow_graph_compiler_x64.cc b/runtime/vm/compiler/backend/flow_graph_compiler_x64.cc index 3259e3e88bf..09d4d95b94e 100644 --- a/runtime/vm/compiler/backend/flow_graph_compiler_x64.cc +++ b/runtime/vm/compiler/backend/flow_graph_compiler_x64.cc @@ -880,14 +880,25 @@ void FlowGraphCompiler::EmitPrologue() { void FlowGraphCompiler::CompileGraph() { InitCompiler(); -#ifdef DART_PRECOMPILER - const Function& function = parsed_function().function(); - if (function.IsDynamicFunction()) { - __ MonomorphicCheckedEntry(); - } -#endif // DART_PRECOMPILER - __ set_constant_pool_allowed(true); + if (FLAG_precompiled_mode) { + const Function& function = parsed_function().function(); + if (function.IsDynamicFunction()) { + SpecialStatsBegin(CombinedCodeStatistics::kTagCheckedEntry); + __ MonomorphicCheckedEntry(); + SpecialStatsEnd(CombinedCodeStatistics::kTagCheckedEntry); + } + + // For JIT we have multiple entrypoints functionality which moved the + // intrinsification to the [TargetEntryInstr::EmitNativeCode]. + if (TryIntrinsify()) { + // Skip regular code generation. + return; + } + EmitFrameEntry(); + ASSERT(__ constant_pool_allowed()); + } + ASSERT(!block_order().is_empty()); VisitBlocks(); diff --git a/runtime/vm/compiler/backend/il.cc b/runtime/vm/compiler/backend/il.cc index a5f64651b9f..88cec817052 100644 --- a/runtime/vm/compiler/backend/il.cc +++ b/runtime/vm/compiler/backend/il.cc @@ -3620,16 +3620,26 @@ LocationSummary* TargetEntryInstr::MakeLocationSummary(Zone* zone, void TargetEntryInstr::EmitNativeCode(FlowGraphCompiler* compiler) { __ Bind(compiler->GetJumpLabel(this)); + // In the AOT compiler we want to reduce code size, so generate no + // fall-through code in [FlowGraphCompiler::CompileGraph()]. + // (As opposed to here where we don't check for the return value of + // [Intrinsify]). + if (!FLAG_precompiled_mode) { #if defined(TARGET_ARCH_X64) || defined(TARGET_ARCH_ARM) - if (compiler->flow_graph().IsEntryPoint(this)) { - __ set_constant_pool_allowed(false); - // TODO(#34162): Don't emit more code if 'TryIntrinsify' returns 'true' - // (meaning the function was fully intrinsified). - compiler->TryIntrinsify(); - compiler->EmitPrologue(); - ASSERT(__ constant_pool_allowed()); - } + if (compiler->flow_graph().IsEntryPoint(this)) { + // NOTE: Because in JIT X64/ARM mode the graph can have multiple + // entrypoints, so we generate several times the same intrinsification & + // frame setup. That's why we cannot rely on the constant pool being + // `false` when we come in here. + __ set_constant_pool_allowed(false); + // TODO(#34162): Don't emit more code if 'TryIntrinsify' returns 'true' + // (meaning the function was fully intrinsified). + compiler->TryIntrinsify(); + compiler->EmitPrologue(); + ASSERT(__ constant_pool_allowed()); + } #endif + } if (!compiler->is_optimizing()) { #if !defined(TARGET_ARCH_DBC)