diff options
author | Nicolas Geoffray <ngeoffray@google.com> | 2014-03-07 15:28:39 +0000 |
---|---|---|
committer | Nicolas Geoffray <ngeoffray@google.com> | 2014-03-13 09:10:43 +0000 |
commit | b34f69ab43aaf7a6e6045c95f398baf566ef5023 (patch) | |
tree | 4090a650de1de3806f6273f3828e77bef9704453 /compiler | |
parent | 113f7a4b6093280e4783c69e06467f816a568e72 (diff) | |
download | android_art-b34f69ab43aaf7a6e6045c95f398baf566ef5023.tar.gz android_art-b34f69ab43aaf7a6e6045c95f398baf566ef5023.tar.bz2 android_art-b34f69ab43aaf7a6e6045c95f398baf566ef5023.zip |
Add command line support for enabling the optimizing compiler.
Also run tests with the optimizing compiler enabled when
the file art/USE_OPTIMIZING_COMPILER is present.
Change-Id: Ibc33eed62a43547bc3b9fe786d014c0d81b5add8
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/Android.mk | 6 | ||||
-rw-r--r-- | compiler/common_compiler_test.h | 8 | ||||
-rw-r--r-- | compiler/compiler.cc (renamed from compiler/compiler_backend.cc) | 169 | ||||
-rw-r--r-- | compiler/compiler.h (renamed from compiler/compiler_backend.h) | 26 | ||||
-rw-r--r-- | compiler/compilers.cc | 152 | ||||
-rw-r--r-- | compiler/compilers.h | 103 | ||||
-rw-r--r-- | compiler/dex/compiler_ir.h | 2 | ||||
-rw-r--r-- | compiler/dex/frontend.cc | 25 | ||||
-rw-r--r-- | compiler/dex/mir_optimization.cc | 2 | ||||
-rw-r--r-- | compiler/driver/compiler_driver.cc | 26 | ||||
-rw-r--r-- | compiler/driver/compiler_driver.h | 10 | ||||
-rw-r--r-- | compiler/llvm/compiler_llvm.cc | 4 | ||||
-rw-r--r-- | compiler/oat_test.cc | 10 | ||||
-rw-r--r-- | compiler/optimizing/optimizing_compiler.cc | 32 |
14 files changed, 374 insertions, 201 deletions
diff --git a/compiler/Android.mk b/compiler/Android.mk index 48e2bcd732..27a84ec753 100644 --- a/compiler/Android.mk +++ b/compiler/Android.mk @@ -75,6 +75,7 @@ LIBART_COMPILER_SRC_FILES := \ optimizing/code_generator_arm.cc \ optimizing/code_generator_x86.cc \ optimizing/nodes.cc \ + optimizing/optimizing_compiler.cc \ trampolines/trampoline_compiler.cc \ utils/arena_allocator.cc \ utils/arena_bit_vector.cc \ @@ -89,7 +90,8 @@ LIBART_COMPILER_SRC_FILES := \ utils/x86/managed_register_x86.cc \ utils/scoped_arena_allocator.cc \ buffered_output_stream.cc \ - compiler_backend.cc \ + compilers.cc \ + compiler.cc \ elf_fixup.cc \ elf_stripper.cc \ elf_writer.cc \ @@ -210,7 +212,7 @@ $$(ENUM_OPERATOR_OUT_GEN): $$(GENERATED_SRC_DIR)/%_operator_out.cc : $(LOCAL_PAT LOCAL_SHARED_LIBRARIES += libart endif ifeq ($(ART_USE_PORTABLE_COMPILER),true) - LOCAL_SHARED_LIBRARIES += libbcc libbcinfo libLLVM + LOCAL_SHARED_LIBRARIES += libLLVM LOCAL_CFLAGS += -DART_USE_PORTABLE_COMPILER=1 ifeq ($$(art_target_or_host),target) LOCAL_STATIC_LIBRARIES_arm += libmcldARMInfo libmcldARMTarget diff --git a/compiler/common_compiler_test.h b/compiler/common_compiler_test.h index d28b0fedac..49c1283809 100644 --- a/compiler/common_compiler_test.h +++ b/compiler/common_compiler_test.h @@ -17,7 +17,7 @@ #ifndef ART_COMPILER_COMMON_COMPILER_TEST_H_ #define ART_COMPILER_COMMON_COMPILER_TEST_H_ -#include "compiler_backend.h" +#include "compiler.h" #include "compiler_callbacks.h" #include "common_runtime_test.h" #include "dex/quick/dex_file_to_method_inliner_map.h" @@ -319,13 +319,13 @@ class CommonCompilerTest : public CommonRuntimeTest { } // TODO: make selectable - CompilerBackend::Kind compiler_backend - = (kUsePortableCompiler) ? CompilerBackend::kPortable : CompilerBackend::kQuick; + Compiler::Kind compiler_kind + = (kUsePortableCompiler) ? Compiler::kPortable : Compiler::kQuick; timer_.reset(new CumulativeLogger("Compilation times")); compiler_driver_.reset(new CompilerDriver(compiler_options_.get(), verification_results_.get(), method_inliner_map_.get(), - compiler_backend, instruction_set, + compiler_kind, instruction_set, instruction_set_features, true, new CompilerDriver::DescriptorSet, 2, true, true, timer_.get())); diff --git a/compiler/compiler_backend.cc b/compiler/compiler.cc index 0afa665eb7..c88c38ed17 100644 --- a/compiler/compiler_backend.cc +++ b/compiler/compiler.cc @@ -14,10 +14,8 @@ * limitations under the License. */ -#include "compiler_backend.h" -#include "elf_writer_quick.h" -#include "dex/quick/mir_to_lir.h" -#include "dex/mir_graph.h" +#include "compiler.h" +#include "compilers.h" #include "driver/compiler_driver.h" #include "mirror/art_method-inl.h" @@ -29,7 +27,7 @@ namespace art { #ifdef ART_SEA_IR_MODE -extern "C" art::CompiledMethod* SeaIrCompileMethod(art::CompilerDriver& compiler, +extern "C" art::CompiledMethod* SeaIrCompileMethod(art::CompilerDriver& driver, const art::DexFile::CodeItem* code_item, uint32_t access_flags, art::InvokeType invoke_type, @@ -39,30 +37,15 @@ extern "C" art::CompiledMethod* SeaIrCompileMethod(art::CompilerDriver& compiler const art::DexFile& dex_file); #endif -extern "C" void ArtInitQuickCompilerContext(art::CompilerDriver& driver); -extern "C" void ArtUnInitQuickCompilerContext(art::CompilerDriver& driver); -extern "C" art::CompiledMethod* ArtQuickCompileMethod(art::CompilerDriver& compiler, - const art::DexFile::CodeItem* code_item, - uint32_t access_flags, - art::InvokeType invoke_type, - uint16_t class_def_idx, - uint32_t method_idx, - jobject class_loader, - const art::DexFile& dex_file); -extern "C" art::CompiledMethod* ArtQuickJniCompileMethod(art::CompilerDriver& compiler, - uint32_t access_flags, uint32_t method_idx, - const art::DexFile& dex_file); - - -static CompiledMethod* TryCompileWithSeaIR(art::CompilerDriver& compiler, - const art::DexFile::CodeItem* code_item, - uint32_t access_flags, - art::InvokeType invoke_type, - uint16_t class_def_idx, - uint32_t method_idx, - jobject class_loader, - const art::DexFile& dex_file) { +CompiledMethod* Compiler::TryCompileWithSeaIR(art::CompilerDriver& driver, + const art::DexFile::CodeItem* code_item, + uint32_t access_flags, + art::InvokeType invoke_type, + uint16_t class_def_idx, + uint32_t method_idx, + jobject class_loader, + const art::DexFile& dex_file) { #ifdef ART_SEA_IR_MODE bool use_sea = Runtime::Current()->IsSeaIRMode(); use_sea = use_sea && @@ -83,117 +66,6 @@ static CompiledMethod* TryCompileWithSeaIR(art::CompilerDriver& compiler, } -// Hack for CFI CIE initialization -extern std::vector<uint8_t>* X86CFIInitialization(); - -class QuickBackend : public CompilerBackend { - public: - QuickBackend() : CompilerBackend(100) {} - - void Init(CompilerDriver& driver) const { - ArtInitQuickCompilerContext(driver); - } - - void UnInit(CompilerDriver& driver) const { - ArtUnInitQuickCompilerContext(driver); - } - - CompiledMethod* Compile(CompilerDriver& compiler, - const DexFile::CodeItem* code_item, - uint32_t access_flags, - InvokeType invoke_type, - uint16_t class_def_idx, - uint32_t method_idx, - jobject class_loader, - const DexFile& dex_file) const { - CompiledMethod* method = TryCompileWithSeaIR(compiler, - code_item, - access_flags, - invoke_type, - class_def_idx, - method_idx, - class_loader, - dex_file); - if (method != nullptr) return method; - - return ArtQuickCompileMethod(compiler, - code_item, - access_flags, - invoke_type, - class_def_idx, - method_idx, - class_loader, - dex_file); - } - - CompiledMethod* JniCompile(CompilerDriver& driver, - uint32_t access_flags, - uint32_t method_idx, - const DexFile& dex_file) const { - return ArtQuickJniCompileMethod(driver, access_flags, method_idx, dex_file); - } - - uintptr_t GetEntryPointOf(mirror::ArtMethod* method) const { - return reinterpret_cast<uintptr_t>(method->GetEntryPointFromQuickCompiledCode()); - } - - bool WriteElf(art::File* file, - OatWriter* oat_writer, - const std::vector<const art::DexFile*>& dex_files, - const std::string& android_root, - bool is_host, const CompilerDriver& driver) const - OVERRIDE - SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - return art::ElfWriterQuick::Create(file, oat_writer, dex_files, android_root, is_host, driver); - } - - Backend* GetCodeGenerator(CompilationUnit* cu, void* compilation_unit) const { - Mir2Lir* mir_to_lir = nullptr; - switch (cu->instruction_set) { - case kThumb2: - mir_to_lir = ArmCodeGenerator(cu, cu->mir_graph.get(), &cu->arena); - break; - case kMips: - mir_to_lir = MipsCodeGenerator(cu, cu->mir_graph.get(), &cu->arena); - break; - case kX86: - mir_to_lir = X86CodeGenerator(cu, cu->mir_graph.get(), &cu->arena); - break; - default: - LOG(FATAL) << "Unexpected instruction set: " << cu->instruction_set; - } - - /* The number of compiler temporaries depends on backend so set it up now if possible */ - if (mir_to_lir) { - size_t max_temps = mir_to_lir->GetMaxPossibleCompilerTemps(); - bool set_max = cu->mir_graph->SetMaxAvailableNonSpecialCompilerTemps(max_temps); - CHECK(set_max); - } - return mir_to_lir; - } - - void InitCompilationUnit(CompilationUnit& cu) const {} - - /* - * @brief Generate and return Dwarf CFI initialization, if supported by the - * backend. - * @param driver CompilerDriver for this compile. - * @returns nullptr if not supported by backend or a vector of bytes for CFI DWARF - * information. - * @note This is used for backtrace information in generated code. - */ - std::vector<uint8_t>* GetCallFrameInformationInitialization(const CompilerDriver& driver) const - OVERRIDE { - if (driver.GetInstructionSet() == kX86) { - return X86CFIInitialization(); - } - return nullptr; - } - - private: - DISALLOW_COPY_AND_ASSIGN(QuickBackend); -}; - #ifdef ART_USE_PORTABLE_COMPILER extern "C" void ArtInitCompilerContext(art::CompilerDriver& driver); @@ -217,9 +89,9 @@ extern "C" void compilerLLVMSetBitcodeFileName(art::CompilerDriver& driver, std::string const& filename); -class LLVMBackend : public CompilerBackend { +class LLVMCompiler : public Compiler { public: - LLVMBackend() : CompilerBackend(1000) {} + LLVMCompiler() : Compiler(1000) {} void Init(CompilerDriver& driver) const { ArtInitCompilerContext(driver); @@ -229,7 +101,7 @@ class LLVMBackend : public CompilerBackend { ArtUnInitCompilerContext(driver); } - CompiledMethod* Compile(CompilerDriver& compiler, + CompiledMethod* Compile(CompilerDriver& driver, const DexFile::CodeItem* code_item, uint32_t access_flags, InvokeType invoke_type, @@ -237,7 +109,7 @@ class LLVMBackend : public CompilerBackend { uint32_t method_idx, jobject class_loader, const DexFile& dex_file) const { - CompiledMethod* method = TryCompileWithSeaIR(compiler, + CompiledMethod* method = TryCompileWithSeaIR(driver, code_item, access_flags, invoke_type, @@ -306,18 +178,21 @@ class LLVMBackend : public CompilerBackend { } private: - DISALLOW_COPY_AND_ASSIGN(LLVMBackend); + DISALLOW_COPY_AND_ASSIGN(LLVMCompiler); }; #endif -CompilerBackend* CompilerBackend::Create(CompilerBackend::Kind kind) { +Compiler* Compiler::Create(Compiler::Kind kind) { switch (kind) { case kQuick: - return new QuickBackend(); + return new QuickCompiler(); + break; + case kOptimizing: + return new OptimizingCompiler(); break; case kPortable: #ifdef ART_USE_PORTABLE_COMPILER - return new LLVMBackend(); + return new LLVMCompiler(); #else LOG(FATAL) << "Portable compiler not compiled"; #endif diff --git a/compiler/compiler_backend.h b/compiler/compiler.h index b473806bba..1d5fc24e9f 100644 --- a/compiler/compiler_backend.h +++ b/compiler/compiler.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef ART_COMPILER_COMPILER_BACKEND_H_ -#define ART_COMPILER_COMPILER_BACKEND_H_ +#ifndef ART_COMPILER_COMPILER_H_ +#define ART_COMPILER_COMPILER_H_ #include "dex_file.h" #include "os.h" @@ -33,18 +33,19 @@ namespace mirror { class ArtMethod; } -class CompilerBackend { +class Compiler { public: enum Kind { kQuick, + kOptimizing, kPortable }; - explicit CompilerBackend(uint64_t warning) + explicit Compiler(uint64_t warning) : maximum_compilation_time_before_warning_(warning) { } - static CompilerBackend* Create(Kind kind); + static Compiler* Create(Kind kind); virtual void Init(CompilerDriver& driver) const = 0; @@ -59,6 +60,15 @@ class CompilerBackend { jobject class_loader, const DexFile& dex_file) const = 0; + static CompiledMethod* TryCompileWithSeaIR(art::CompilerDriver& driver, + const art::DexFile::CodeItem* code_item, + uint32_t access_flags, + art::InvokeType invoke_type, + uint16_t class_def_idx, + uint32_t method_idx, + jobject class_loader, + const art::DexFile& dex_file); + virtual CompiledMethod* JniCompile(CompilerDriver& driver, uint32_t access_flags, uint32_t method_idx, @@ -91,7 +101,7 @@ class CompilerBackend { virtual void InitCompilationUnit(CompilationUnit& cu) const = 0; - virtual ~CompilerBackend() {} + virtual ~Compiler() {} /* * @brief Generate and return Dwarf CFI initialization, if supported by the @@ -109,9 +119,9 @@ class CompilerBackend { private: const uint64_t maximum_compilation_time_before_warning_; - DISALLOW_COPY_AND_ASSIGN(CompilerBackend); + DISALLOW_COPY_AND_ASSIGN(Compiler); }; } // namespace art -#endif // ART_COMPILER_COMPILER_BACKEND_H_ +#endif // ART_COMPILER_COMPILER_H_ diff --git a/compiler/compilers.cc b/compiler/compilers.cc new file mode 100644 index 0000000000..3c66021fdf --- /dev/null +++ b/compiler/compilers.cc @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "compilers.h" +#include "dex/mir_graph.h" +#include "dex/quick/mir_to_lir.h" +#include "elf_writer_quick.h" +#include "mirror/art_method-inl.h" + +namespace art { + +extern "C" void ArtInitQuickCompilerContext(art::CompilerDriver& driver); +extern "C" void ArtUnInitQuickCompilerContext(art::CompilerDriver& driver); +extern "C" art::CompiledMethod* ArtQuickCompileMethod(art::CompilerDriver& driver, + const art::DexFile::CodeItem* code_item, + uint32_t access_flags, + art::InvokeType invoke_type, + uint16_t class_def_idx, + uint32_t method_idx, + jobject class_loader, + const art::DexFile& dex_file); + +extern "C" art::CompiledMethod* ArtQuickJniCompileMethod(art::CompilerDriver& driver, + uint32_t access_flags, uint32_t method_idx, + const art::DexFile& dex_file); + +// Hack for CFI CIE initialization +extern std::vector<uint8_t>* X86CFIInitialization(); + +void QuickCompiler::Init(CompilerDriver& driver) const { + ArtInitQuickCompilerContext(driver); +} + +void QuickCompiler::UnInit(CompilerDriver& driver) const { + ArtUnInitQuickCompilerContext(driver); +} + +CompiledMethod* QuickCompiler::Compile(CompilerDriver& driver, + const DexFile::CodeItem* code_item, + uint32_t access_flags, + InvokeType invoke_type, + uint16_t class_def_idx, + uint32_t method_idx, + jobject class_loader, + const DexFile& dex_file) const { + CompiledMethod* method = TryCompileWithSeaIR(driver, + code_item, + access_flags, + invoke_type, + class_def_idx, + method_idx, + class_loader, + dex_file); + if (method != nullptr) return method; + + return ArtQuickCompileMethod(driver, + code_item, + access_flags, + invoke_type, + class_def_idx, + method_idx, + class_loader, + dex_file); +} + +CompiledMethod* QuickCompiler::JniCompile(CompilerDriver& driver, + uint32_t access_flags, + uint32_t method_idx, + const DexFile& dex_file) const { + return ArtQuickJniCompileMethod(driver, access_flags, method_idx, dex_file); +} + +uintptr_t QuickCompiler::GetEntryPointOf(mirror::ArtMethod* method) const { + return reinterpret_cast<uintptr_t>(method->GetEntryPointFromQuickCompiledCode()); +} + +bool QuickCompiler::WriteElf(art::File* file, + OatWriter* oat_writer, + const std::vector<const art::DexFile*>& dex_files, + const std::string& android_root, + bool is_host, const CompilerDriver& driver) const + OVERRIDE + SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { + return art::ElfWriterQuick::Create(file, oat_writer, dex_files, android_root, is_host, driver); +} + +Backend* QuickCompiler::GetCodeGenerator(CompilationUnit* cu, void* compilation_unit) const { + Mir2Lir* mir_to_lir = nullptr; + switch (cu->instruction_set) { + case kThumb2: + mir_to_lir = ArmCodeGenerator(cu, cu->mir_graph.get(), &cu->arena); + break; + case kMips: + mir_to_lir = MipsCodeGenerator(cu, cu->mir_graph.get(), &cu->arena); + break; + case kX86: + mir_to_lir = X86CodeGenerator(cu, cu->mir_graph.get(), &cu->arena); + break; + default: + LOG(FATAL) << "Unexpected instruction set: " << cu->instruction_set; + } + + /* The number of compiler temporaries depends on backend so set it up now if possible */ + if (mir_to_lir) { + size_t max_temps = mir_to_lir->GetMaxPossibleCompilerTemps(); + bool set_max = cu->mir_graph->SetMaxAvailableNonSpecialCompilerTemps(max_temps); + CHECK(set_max); + } + return mir_to_lir; +} + +std::vector<uint8_t>* QuickCompiler::GetCallFrameInformationInitialization( + const CompilerDriver& driver) const + OVERRIDE { + if (driver.GetInstructionSet() == kX86) { + return X86CFIInitialization(); + } + return nullptr; +} + +CompiledMethod* OptimizingCompiler::Compile(CompilerDriver& driver, + const DexFile::CodeItem* code_item, + uint32_t access_flags, + InvokeType invoke_type, + uint16_t class_def_idx, + uint32_t method_idx, + jobject class_loader, + const DexFile& dex_file) const { + CompiledMethod* method = TryCompile( + driver, code_item, access_flags, invoke_type, class_def_idx, method_idx, + class_loader, dex_file); + if (method != nullptr) return method; + + return QuickCompiler::Compile( + driver, code_item, access_flags, invoke_type, class_def_idx, method_idx, + class_loader, dex_file); +} + +} // namespace art diff --git a/compiler/compilers.h b/compiler/compilers.h new file mode 100644 index 0000000000..65c8428383 --- /dev/null +++ b/compiler/compilers.h @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ART_COMPILER_COMPILERS_H_ +#define ART_COMPILER_COMPILERS_H_ + +#include "compiler.h" + +namespace art { + +class QuickCompiler : public Compiler { + public: + QuickCompiler() : Compiler(100) {} + + void Init(CompilerDriver& driver) const; + + void UnInit(CompilerDriver& driver) const; + + CompiledMethod* Compile(CompilerDriver& driver, + const DexFile::CodeItem* code_item, + uint32_t access_flags, + InvokeType invoke_type, + uint16_t class_def_idx, + uint32_t method_idx, + jobject class_loader, + const DexFile& dex_file) const; + + CompiledMethod* JniCompile(CompilerDriver& driver, + uint32_t access_flags, + uint32_t method_idx, + const DexFile& dex_file) const; + + uintptr_t GetEntryPointOf(mirror::ArtMethod* method) const; + + bool WriteElf(art::File* file, + OatWriter* oat_writer, + const std::vector<const art::DexFile*>& dex_files, + const std::string& android_root, + bool is_host, const CompilerDriver& driver) const + OVERRIDE + SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); + + Backend* GetCodeGenerator(CompilationUnit* cu, void* compilation_unit) const; + + void InitCompilationUnit(CompilationUnit& cu) const {} + + /* + * @brief Generate and return Dwarf CFI initialization, if supported by the + * backend. + * @param driver CompilerDriver for this compile. + * @returns nullptr if not supported by backend or a vector of bytes for CFI DWARF + * information. + * @note This is used for backtrace information in generated code. + */ + std::vector<uint8_t>* GetCallFrameInformationInitialization(const CompilerDriver& driver) const + OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(QuickCompiler); +}; + +class OptimizingCompiler : public QuickCompiler { + public: + OptimizingCompiler() { } + + CompiledMethod* Compile(CompilerDriver& driver, + const DexFile::CodeItem* code_item, + uint32_t access_flags, + InvokeType invoke_type, + uint16_t class_def_idx, + uint32_t method_idx, + jobject class_loader, + const DexFile& dex_file) const; + + CompiledMethod* TryCompile(CompilerDriver& driver, + const DexFile::CodeItem* code_item, + uint32_t access_flags, + InvokeType invoke_type, + uint16_t class_def_idx, + uint32_t method_idx, + jobject class_loader, + const DexFile& dex_file) const; + + private: + DISALLOW_COPY_AND_ASSIGN(OptimizingCompiler); +}; + +} // namespace art + +#endif // ART_COMPILER_COMPILERS_H_ diff --git a/compiler/dex/compiler_ir.h b/compiler/dex/compiler_ir.h index c71f0473f1..70159cae9f 100644 --- a/compiler/dex/compiler_ir.h +++ b/compiler/dex/compiler_ir.h @@ -62,7 +62,7 @@ struct CompilationUnit { uint32_t disable_opt; // opt_control_vector flags. uint32_t enable_debug; // debugControlVector flags. bool verbose; - const CompilerBackend* compiler_backend; + const Compiler* compiler; InstructionSet instruction_set; bool target64; diff --git a/compiler/dex/frontend.cc b/compiler/dex/frontend.cc index 3bd71d1c0a..83fbca5aca 100644 --- a/compiler/dex/frontend.cc +++ b/compiler/dex/frontend.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "compiler_backend.h" +#include "compiler.h" #include "compiler_internals.h" #include "driver/compiler_driver.h" #include "driver/compiler_options.h" @@ -23,7 +23,6 @@ #include "mirror/object.h" #include "pass_driver.h" #include "runtime.h" -#include "backend.h" #include "base/logging.h" #include "base/timing_logger.h" #include "driver/compiler_options.h" @@ -90,7 +89,7 @@ CompilationUnit::CompilationUnit(ArenaPool* pool) disable_opt(0), enable_debug(0), verbose(false), - compiler_backend(NULL), + compiler(NULL), instruction_set(kNone), num_dalvik_registers(0), insns(NULL), @@ -131,7 +130,7 @@ void CompilationUnit::EndTiming() { } static CompiledMethod* CompileMethod(CompilerDriver& driver, - CompilerBackend* compiler_backend, + Compiler* compiler, const DexFile::CodeItem* code_item, uint32_t access_flags, InvokeType invoke_type, uint16_t class_def_idx, uint32_t method_idx, @@ -157,7 +156,7 @@ static CompiledMethod* CompileMethod(CompilerDriver& driver, cu.class_linker = class_linker; cu.instruction_set = driver.GetInstructionSet(); cu.target64 = cu.instruction_set == kX86_64; - cu.compiler_backend = compiler_backend; + cu.compiler = compiler; // TODO: x86_64 is not yet implemented. DCHECK((cu.instruction_set == kThumb2) || (cu.instruction_set == kX86) || @@ -184,7 +183,7 @@ static CompiledMethod* CompileMethod(CompilerDriver& driver, * MIR and backend flags? Need command-line setting as well. */ - compiler_backend->InitCompilationUnit(cu); + compiler->InitCompilationUnit(cu); if (cu.instruction_set == kMips) { // Disable some optimizations for mips for now @@ -209,7 +208,7 @@ static CompiledMethod* CompileMethod(CompilerDriver& driver, * The reason we do this is that optimizations on the MIR graph may need to get information * that is only available if a CG exists. */ - cu.cg.reset(compiler_backend->GetCodeGenerator(&cu, llvm_compilation_unit)); + cu.cg.reset(compiler->GetCodeGenerator(&cu, llvm_compilation_unit)); /* Gathering opcode stats? */ if (kCompilerDebugFlags & (1 << kDebugCountOpcodes)) { @@ -286,8 +285,8 @@ static CompiledMethod* CompileMethod(CompilerDriver& driver, return result; } -CompiledMethod* CompileOneMethod(CompilerDriver& compiler, - CompilerBackend* backend, +CompiledMethod* CompileOneMethod(CompilerDriver& driver, + Compiler* compiler, const DexFile::CodeItem* code_item, uint32_t access_flags, InvokeType invoke_type, @@ -296,21 +295,21 @@ CompiledMethod* CompileOneMethod(CompilerDriver& compiler, jobject class_loader, const DexFile& dex_file, void* compilation_unit) { - return CompileMethod(compiler, backend, code_item, access_flags, invoke_type, class_def_idx, + return CompileMethod(driver, compiler, code_item, access_flags, invoke_type, class_def_idx, method_idx, class_loader, dex_file, compilation_unit); } } // namespace art extern "C" art::CompiledMethod* - ArtQuickCompileMethod(art::CompilerDriver& compiler, + ArtQuickCompileMethod(art::CompilerDriver& driver, const art::DexFile::CodeItem* code_item, uint32_t access_flags, art::InvokeType invoke_type, uint16_t class_def_idx, uint32_t method_idx, jobject class_loader, const art::DexFile& dex_file) { // TODO: check method fingerprint here to determine appropriate backend type. Until then, use build default - art::CompilerBackend* backend = compiler.GetCompilerBackend(); - return art::CompileOneMethod(compiler, backend, code_item, access_flags, invoke_type, + art::Compiler* compiler = driver.GetCompiler(); + return art::CompileOneMethod(driver, compiler, code_item, access_flags, invoke_type, class_def_idx, method_idx, class_loader, dex_file, NULL /* use thread llvm_info */); } diff --git a/compiler/dex/mir_optimization.cc b/compiler/dex/mir_optimization.cc index 03fc091e4d..cb737ab294 100644 --- a/compiler/dex/mir_optimization.cc +++ b/compiler/dex/mir_optimization.cc @@ -405,7 +405,7 @@ bool MIRGraph::BasicBlockOpt(BasicBlock* bb) { // Is this the select pattern? // TODO: flesh out support for Mips. NOTE: llvm's select op doesn't quite work here. // TUNING: expand to support IF_xx compare & branches - if (!cu_->compiler_backend->IsPortable() && + if (!cu_->compiler->IsPortable() && (cu_->instruction_set == kThumb2 || cu_->instruction_set == kX86) && IsInstructionIfCcZ(mir->dalvikInsn.opcode)) { BasicBlock* ft = GetBasicBlock(bb->fall_through); diff --git a/compiler/driver/compiler_driver.cc b/compiler/driver/compiler_driver.cc index 7c4a6f7c19..c9846cb0f8 100644 --- a/compiler/driver/compiler_driver.cc +++ b/compiler/driver/compiler_driver.cc @@ -26,7 +26,7 @@ #include "base/stl_util.h" #include "base/timing_logger.h" #include "class_linker.h" -#include "compiler_backend.h" +#include "compiler.h" #include "compiler_driver-inl.h" #include "dex_compilation_unit.h" #include "dex_file-inl.h" @@ -324,7 +324,7 @@ extern "C" art::CompiledMethod* ArtCompileDEX(art::CompilerDriver& compiler, CompilerDriver::CompilerDriver(const CompilerOptions* compiler_options, VerificationResults* verification_results, DexFileToMethodInlinerMap* method_inliner_map, - CompilerBackend::Kind compiler_backend_kind, + Compiler::Kind compiler_kind, InstructionSet instruction_set, InstructionSetFeatures instruction_set_features, bool image, DescriptorSet* image_classes, size_t thread_count, @@ -333,7 +333,7 @@ CompilerDriver::CompilerDriver(const CompilerOptions* compiler_options, : profile_ok_(false), compiler_options_(compiler_options), verification_results_(verification_results), method_inliner_map_(method_inliner_map), - compiler_backend_(CompilerBackend::Create(compiler_backend_kind)), + compiler_(Compiler::Create(compiler_kind)), instruction_set_(instruction_set), instruction_set_features_(instruction_set_features), freezing_constructor_lock_("freezing constructor lock"), @@ -371,7 +371,7 @@ CompilerDriver::CompilerDriver(const CompilerOptions* compiler_options, dex_to_dex_compiler_ = reinterpret_cast<DexToDexCompilerFn>(ArtCompileDEX); - compiler_backend_->Init(*this); + compiler_->Init(*this); CHECK(!Runtime::Current()->IsStarted()); if (!image_) { @@ -380,7 +380,7 @@ CompilerDriver::CompilerDriver(const CompilerOptions* compiler_options, // Are we generating CFI information? if (compiler_options->GetGenerateGDBInformation()) { - cfi_info_.reset(compiler_backend_->GetCallFrameInformationInitialization(*this)); + cfi_info_.reset(compiler_->GetCallFrameInformationInitialization(*this)); } } @@ -430,7 +430,7 @@ CompilerDriver::~CompilerDriver() { STLDeleteElements(&classes_to_patch_); } CHECK_PTHREAD_CALL(pthread_key_delete, (tls_key_), "delete tls key"); - compiler_backend_->UnInit(*this); + compiler_->UnInit(*this); } CompilerTls* CompilerDriver::GetTls() { @@ -1077,7 +1077,7 @@ void CompilerDriver::GetCodeAndMethodForDirectCall(InvokeType* type, InvokeType *direct_method = 0; bool use_dex_cache = false; const bool compiling_boot = Runtime::Current()->GetHeap()->IsCompilingBoot(); - if (compiler_backend_->IsPortable()) { + if (compiler_->IsPortable()) { if (sharp_type != kStatic && sharp_type != kDirect) { return; } @@ -1153,13 +1153,13 @@ void CompilerDriver::GetCodeAndMethodForDirectCall(InvokeType* type, InvokeType CHECK(!method->IsAbstract()); *type = sharp_type; *direct_method = reinterpret_cast<uintptr_t>(method); - *direct_code = compiler_backend_->GetEntryPointOf(method); + *direct_code = compiler_->GetEntryPointOf(method); target_method->dex_file = method->GetDeclaringClass()->GetDexCache()->GetDexFile(); target_method->dex_method_index = method->GetDexMethodIndex(); } else if (!must_use_direct_pointers) { // Set the code and rely on the dex cache for the method. *type = sharp_type; - *direct_code = compiler_backend_->GetEntryPointOf(method); + *direct_code = compiler_->GetEntryPointOf(method); } else { // Direct pointers were required but none were available. VLOG(compiler) << "Dex cache devirtualization failed for: " << PrettyMethod(method); @@ -1887,7 +1887,7 @@ void CompilerDriver::CompileMethod(const DexFile::CodeItem* code_item, uint32_t #if defined(__x86_64__) // leaving this empty will trigger the generic JNI version #else - compiled_method = compiler_backend_->JniCompile(*this, access_flags, method_idx, dex_file); + compiled_method = compiler_->JniCompile(*this, access_flags, method_idx, dex_file); CHECK(compiled_method != NULL); #endif } else if ((access_flags & kAccAbstract) != 0) { @@ -1896,7 +1896,7 @@ void CompilerDriver::CompileMethod(const DexFile::CodeItem* code_item, uint32_t bool compile = verification_results_->IsCandidateForCompilation(method_ref, access_flags); if (compile) { // NOTE: if compiler declines to compile this method, it will return NULL. - compiled_method = compiler_backend_->Compile( + compiled_method = compiler_->Compile( *this, code_item, access_flags, invoke_type, class_def_idx, method_idx, class_loader, dex_file); } else if (dex_to_dex_compilation_level != kDontDexToDexCompile) { @@ -1908,7 +1908,7 @@ void CompilerDriver::CompileMethod(const DexFile::CodeItem* code_item, uint32_t } } uint64_t duration_ns = NanoTime() - start_ns; - if (duration_ns > MsToNs(compiler_backend_->GetMaximumCompilationTimeBeforeWarning())) { + if (duration_ns > MsToNs(compiler_->GetMaximumCompilationTimeBeforeWarning())) { LOG(WARNING) << "Compilation of " << PrettyMethod(method_idx, dex_file) << " took " << PrettyDuration(duration_ns); } @@ -1995,7 +1995,7 @@ bool CompilerDriver::WriteElf(const std::string& android_root, OatWriter* oat_writer, art::File* file) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - return compiler_backend_->WriteElf(file, oat_writer, dex_files, android_root, is_host, *this); + return compiler_->WriteElf(file, oat_writer, dex_files, android_root, is_host, *this); } void CompilerDriver::InstructionSetToLLVMTarget(InstructionSet instruction_set, std::string* target_triple, diff --git a/compiler/driver/compiler_driver.h b/compiler/driver/compiler_driver.h index 26210c944c..771e359acc 100644 --- a/compiler/driver/compiler_driver.h +++ b/compiler/driver/compiler_driver.h @@ -26,7 +26,7 @@ #include "class_reference.h" #include "compiled_class.h" #include "compiled_method.h" -#include "compiler_backend.h" +#include "compiler.h" #include "dex_file.h" #include "instruction_set.h" #include "invoke_type.h" @@ -99,7 +99,7 @@ class CompilerDriver { explicit CompilerDriver(const CompilerOptions* compiler_options, VerificationResults* verification_results, DexFileToMethodInlinerMap* method_inliner_map, - CompilerBackend::Kind compiler_backend_kind, + Compiler::Kind compiler_kind, InstructionSet instruction_set, InstructionSetFeatures instruction_set_features, bool image, DescriptorSet* image_classes, @@ -137,8 +137,8 @@ class CompilerDriver { return *compiler_options_; } - CompilerBackend* GetCompilerBackend() const { - return compiler_backend_.get(); + Compiler* GetCompiler() const { + return compiler_.get(); } bool ProfilePresent() const { @@ -708,7 +708,7 @@ class CompilerDriver { VerificationResults* const verification_results_; DexFileToMethodInlinerMap* const method_inliner_map_; - UniquePtr<CompilerBackend> compiler_backend_; + UniquePtr<Compiler> compiler_; const InstructionSet instruction_set_; const InstructionSetFeatures instruction_set_features_; diff --git a/compiler/llvm/compiler_llvm.cc b/compiler/llvm/compiler_llvm.cc index 4ce714a183..2812700fa3 100644 --- a/compiler/llvm/compiler_llvm.cc +++ b/compiler/llvm/compiler_llvm.cc @@ -39,7 +39,7 @@ namespace art { void CompileOneMethod(CompilerDriver& driver, - CompilerBackend* compilerBackend, + Compiler* compiler, const DexFile::CodeItem* code_item, uint32_t access_flags, InvokeType invoke_type, uint16_t class_def_idx, uint32_t method_idx, jobject class_loader, @@ -142,7 +142,7 @@ CompileDexMethod(DexCompilationUnit* dex_compilation_unit, InvokeType invoke_typ cunit->SetCompilerDriver(compiler_driver_); // TODO: consolidate ArtCompileMethods CompileOneMethod(*compiler_driver_, - compiler_driver_->GetCompilerBackend(), + compiler_driver_->GetCompiler(), dex_compilation_unit->GetCodeItem(), dex_compilation_unit->GetAccessFlags(), invoke_type, diff --git a/compiler/oat_test.cc b/compiler/oat_test.cc index 93c35022f2..9cfef12b26 100644 --- a/compiler/oat_test.cc +++ b/compiler/oat_test.cc @@ -15,7 +15,7 @@ */ #include "common_compiler_test.h" -#include "compiler/compiler_backend.h" +#include "compiler/compiler.h" #include "compiler/oat_writer.h" #include "mirror/art_method-inl.h" #include "mirror/class-inl.h" @@ -84,9 +84,9 @@ TEST_F(OatTest, WriteRead) { ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); // TODO: make selectable. - CompilerBackend::Kind compiler_backend = kUsePortableCompiler - ? CompilerBackend::kPortable - : CompilerBackend::kQuick; + Compiler::Kind compiler_kind = kUsePortableCompiler + ? Compiler::kPortable + : Compiler::kQuick; InstructionSet insn_set = kIsTargetBuild ? kThumb2 : kX86; InstructionSetFeatures insn_features; @@ -99,7 +99,7 @@ TEST_F(OatTest, WriteRead) { compiler_driver_.reset(new CompilerDriver(compiler_options_.get(), verification_results_.get(), method_inliner_map_.get(), - compiler_backend, insn_set, + compiler_kind, insn_set, insn_features, false, NULL, 2, true, true, timer_.get())); jobject class_loader = NULL; diff --git a/compiler/optimizing/optimizing_compiler.cc b/compiler/optimizing/optimizing_compiler.cc new file mode 100644 index 0000000000..73323a4846 --- /dev/null +++ b/compiler/optimizing/optimizing_compiler.cc @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "compilers.h" + +namespace art { + +CompiledMethod* OptimizingCompiler::TryCompile(CompilerDriver& driver, + const DexFile::CodeItem* code_item, + uint32_t access_flags, + InvokeType invoke_type, + uint16_t class_def_idx, + uint32_t method_idx, + jobject class_loader, + const DexFile& dex_file) const { + return nullptr; +} + +} // namespace art |