[VM] Restore small intrinsics (which never take the fall-through path) on AOT
This reduces flutter gallery RX size by around 0.2%
Change-Id: Iaf4db565ce42e70e0d1811b762820d2114daec9b
Reviewed-on: https://dart-review.googlesource.com/72440
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
diff --git a/runtime/vm/compiler/backend/flow_graph_compiler_arm.cc b/runtime/vm/compiler/backend/flow_graph_compiler_arm.cc
index 8762e1b..c02c1e3 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 @@
// 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);
+ }
- __ set_constant_pool_allowed(true);
+ // 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());
+ }
+
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 358afcf..3c77a2f 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 @@
// 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 3259e3e..09d4d95 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::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 a5f6465..88cec81 100644
--- a/runtime/vm/compiler/backend/il.cc
+++ b/runtime/vm/compiler/backend/il.cc
@@ -3620,16 +3620,26 @@
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)