From d4229601e0fb46b0a013b52370aeda3887aea8e9 Mon Sep 17 00:00:00 2001 From: Santiago Aboy Solanes Date: Tue, 3 Jan 2023 16:20:50 +0000 Subject: Add a write barrier elimination pass We can eliminate redundant write barriers as we don't need several for the same receiver. For example: ``` MyObject o; o.inner_obj = io; o.inner_obj2 = io2; o.inner_obj3 = io3; ``` We can keep the write barrier for `inner_obj` and remove the other two. Note that we cannot perform this optimization across invokes, suspend check, or instructions that can throw. Local improvements (pixel 5, speed compile): * System server: -280KB (-0.56%) * SystemUIGoogle: -330KB (-1.16%) * AGSA: -3876KB (-1.19%) Bug: 260843353 Fixes: 260843353 Change-Id: Ibf98efbe891ee00e46125853c3e97ae30aa3ff30 --- compiler/optimizing/optimizing_compiler.cc | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'compiler/optimizing/optimizing_compiler.cc') diff --git a/compiler/optimizing/optimizing_compiler.cc b/compiler/optimizing/optimizing_compiler.cc index 807c78e62a..dbf247cd64 100644 --- a/compiler/optimizing/optimizing_compiler.cc +++ b/compiler/optimizing/optimizing_compiler.cc @@ -51,6 +51,7 @@ #include "linker/linker_patch.h" #include "nodes.h" #include "oat_quick_method_header.h" +#include "optimizing/write_barrier_elimination.h" #include "prepare_for_register_allocation.h" #include "reference_type_propagation.h" #include "register_allocator_linear_scan.h" @@ -899,6 +900,8 @@ CodeGenerator* OptimizingCompiler::TryCompile(ArenaAllocator* allocator, RunBaselineOptimizations(graph, codegen.get(), dex_compilation_unit, &pass_observer); } else { RunOptimizations(graph, codegen.get(), dex_compilation_unit, &pass_observer); + PassScope scope(WriteBarrierElimination::kWBEPassName, &pass_observer); + WriteBarrierElimination(graph, compilation_stats_.get()).Run(); } RegisterAllocator::Strategy regalloc_strategy = @@ -992,6 +995,10 @@ CodeGenerator* OptimizingCompiler::TryCompileIntrinsic( optimizations); RunArchOptimizations(graph, codegen.get(), dex_compilation_unit, &pass_observer); + { + PassScope scope(WriteBarrierElimination::kWBEPassName, &pass_observer); + WriteBarrierElimination(graph, compilation_stats_.get()).Run(); + } AllocateRegisters(graph, codegen.get(), -- cgit v1.2.3-59-g8ed1b