From badd826664896d4a9628a5a89b78016894aa414b Mon Sep 17 00:00:00 2001 From: David Brazdil Date: Tue, 2 Feb 2016 16:28:56 +0000 Subject: ART: Run SsaBuilder from HGraphBuilder First step towards merging the two passes, which will later result in HGraphBuilder directly producing SSA form. This CL mostly just updates tests broken by not being able to inspect the pre-SSA form. Using HLocals outside the HGraphBuilder is now deprecated. Bug: 27150508 Change-Id: I00fb6050580f409dcc5aa5b5aa3a536d6e8d759e --- compiler/optimizing/optimizing_compiler.cc | 133 +++++++++++++---------------- 1 file changed, 61 insertions(+), 72 deletions(-) (limited to 'compiler/optimizing/optimizing_compiler.cc') diff --git a/compiler/optimizing/optimizing_compiler.cc b/compiler/optimizing/optimizing_compiler.cc index dcd8e7d216..12b748b7b6 100644 --- a/compiler/optimizing/optimizing_compiler.cc +++ b/compiler/optimizing/optimizing_compiler.cc @@ -186,18 +186,10 @@ class PassObserver : public ValueObject { // Validate the HGraph if running in debug mode. if (kIsDebugBuild) { if (!graph_in_bad_state_) { - if (graph_->IsInSsaForm()) { - SSAChecker checker(graph_); - checker.Run(); - if (!checker.IsValid()) { - LOG(FATAL) << "Error after " << pass_name << ": " << Dumpable(checker); - } - } else { - GraphChecker checker(graph_); - checker.Run(); - if (!checker.IsValid()) { - LOG(FATAL) << "Error after " << pass_name << ": " << Dumpable(checker); - } + GraphChecker checker(graph_); + checker.Run(); + if (!checker.IsValid()) { + LOG(FATAL) << "Error after " << pass_name << ": " << Dumpable(checker); } } } @@ -665,6 +657,7 @@ CodeGenerator* OptimizingCompiler::TryCompile(ArenaAllocator* arena, && compiler_driver->RequiresConstructorBarrier(Thread::Current(), dex_compilation_unit.GetDexFile(), dex_compilation_unit.GetClassDefIndex()); + HGraph* graph = new (arena) HGraph( arena, dex_file, @@ -675,6 +668,21 @@ CodeGenerator* OptimizingCompiler::TryCompile(ArenaAllocator* arena, compiler_driver->GetCompilerOptions().GetDebuggable(), osr); + const uint8_t* interpreter_metadata = nullptr; + { + ScopedObjectAccess soa(Thread::Current()); + StackHandleScope<1> hs(soa.Self()); + Handle loader(hs.NewHandle( + soa.Decode(class_loader))); + ArtMethod* art_method = compiler_driver->ResolveMethod( + soa, dex_cache, loader, &dex_compilation_unit, method_idx, invoke_type); + // We may not get a method, for example if its class is erroneous. + if (art_method != nullptr) { + graph->SetArtMethod(art_method); + interpreter_metadata = art_method->GetQuickenedInfo(); + } + } + std::unique_ptr codegen( CodeGenerator::Create(graph, instruction_set, @@ -692,74 +700,55 @@ CodeGenerator* OptimizingCompiler::TryCompile(ArenaAllocator* arena, visualizer_output_.get(), compiler_driver); - const uint8_t* interpreter_metadata = nullptr; - { - ScopedObjectAccess soa(Thread::Current()); - StackHandleScope<1> hs(soa.Self()); - Handle loader(hs.NewHandle( - soa.Decode(class_loader))); - ArtMethod* art_method = compiler_driver->ResolveMethod( - soa, dex_cache, loader, &dex_compilation_unit, method_idx, invoke_type); - // We may not get a method, for example if its class is erroneous. - if (art_method != nullptr) { - graph->SetArtMethod(art_method); - interpreter_metadata = art_method->GetQuickenedInfo(); - } - } - HGraphBuilder builder(graph, - &dex_compilation_unit, - &dex_compilation_unit, - &dex_file, - compiler_driver, - compilation_stats_.get(), - interpreter_metadata, - dex_cache); - VLOG(compiler) << "Building " << pass_observer.GetMethodName(); { - PassScope scope(HGraphBuilder::kBuilderPassName, &pass_observer); - if (!builder.BuildGraph(*code_item)) { - pass_observer.SetGraphInBadState(); - return nullptr; + ScopedObjectAccess soa(Thread::Current()); + StackHandleScopeCollection handles(soa.Self()); + // Do not hold `mutator_lock_` between optimizations. + ScopedThreadSuspension sts(soa.Self(), kNative); + + { + PassScope scope(HGraphBuilder::kBuilderPassName, &pass_observer); + HGraphBuilder builder(graph, + &dex_compilation_unit, + &dex_compilation_unit, + &dex_file, + compiler_driver, + compilation_stats_.get(), + interpreter_metadata, + dex_cache); + GraphAnalysisResult result = builder.BuildGraph(*code_item, &handles); + if (result != kAnalysisSuccess) { + switch (result) { + case kAnalysisInvalidBytecode: + break; + case kAnalysisFailThrowCatchLoop: + MaybeRecordStat(MethodCompilationStat::kNotCompiledThrowCatchLoop); + break; + case kAnalysisFailAmbiguousArrayOp: + MaybeRecordStat(MethodCompilationStat::kNotCompiledAmbiguousArrayOp); + break; + case kAnalysisSuccess: + UNREACHABLE(); + } + pass_observer.SetGraphInBadState(); + return nullptr; + } } - } - VLOG(compiler) << "Optimizing " << pass_observer.GetMethodName(); + RunOptimizations(graph, + codegen.get(), + compiler_driver, + compilation_stats_.get(), + dex_compilation_unit, + &pass_observer, + &handles); - ScopedObjectAccess soa(Thread::Current()); - StackHandleScopeCollection handles(soa.Self()); - ScopedThreadSuspension sts(soa.Self(), kNative); - - { - PassScope scope(SsaBuilder::kSsaBuilderPassName, &pass_observer); - GraphAnalysisResult result = graph->TryBuildingSsa(&handles); - if (result != kAnalysisSuccess) { - switch (result) { - case kAnalysisFailThrowCatchLoop: - MaybeRecordStat(MethodCompilationStat::kNotCompiledThrowCatchLoop); - break; - case kAnalysisFailAmbiguousArrayOp: - MaybeRecordStat(MethodCompilationStat::kNotCompiledAmbiguousArrayOp); - break; - case kAnalysisSuccess: - UNREACHABLE(); - } - pass_observer.SetGraphInBadState(); - return nullptr; - } + codegen->Compile(code_allocator); + pass_observer.DumpDisassembly(); } - RunOptimizations(graph, - codegen.get(), - compiler_driver, - compilation_stats_.get(), - dex_compilation_unit, - &pass_observer, - &handles); - codegen->Compile(code_allocator); - pass_observer.DumpDisassembly(); - if (kArenaAllocatorCountAllocations) { if (arena->BytesAllocated() > 4 * MB) { MemStats mem_stats(arena->GetMemStats()); -- cgit v1.2.3-59-g8ed1b