1b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray/*
2b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray * Copyright (C) 2014 The Android Open Source Project
3b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray *
4b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray * Licensed under the Apache License, Version 2.0 (the "License");
5b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray * you may not use this file except in compliance with the License.
6b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray * You may obtain a copy of the License at
7b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray *
8b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray *      http://www.apache.org/licenses/LICENSE-2.0
9b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray *
10b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray * Unless required by applicable law or agreed to in writing, software
11b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray * distributed under the License is distributed on an "AS IS" BASIS,
12b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray * See the License for the specific language governing permissions and
14b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray * limitations under the License.
15b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray */
16b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray
17b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray#ifndef ART_COMPILER_COMPILERS_H_
18b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray#define ART_COMPILER_COMPILERS_H_
19b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray
20b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray#include "compiler.h"
21b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray
22b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffraynamespace art {
23b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray
24b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffrayclass QuickCompiler : public Compiler {
25b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray public:
2672d32629303f8f39362a4099481f48646aed042fIan Rogers  explicit QuickCompiler(CompilerDriver* driver) : Compiler(driver, 100) {}
27b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray
2872d32629303f8f39362a4099481f48646aed042fIan Rogers  void Init() const OVERRIDE;
29b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray
3072d32629303f8f39362a4099481f48646aed042fIan Rogers  void UnInit() const OVERRIDE;
31b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray
3272d32629303f8f39362a4099481f48646aed042fIan Rogers  CompiledMethod* Compile(const DexFile::CodeItem* code_item,
33b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                          uint32_t access_flags,
34b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                          InvokeType invoke_type,
35b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                          uint16_t class_def_idx,
36b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                          uint32_t method_idx,
37b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                          jobject class_loader,
38896362bbfa11b66b45f3ce5a9e8570a878d49e07Nicolas Geoffray                          const DexFile& dex_file) const OVERRIDE;
39b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray
4072d32629303f8f39362a4099481f48646aed042fIan Rogers  CompiledMethod* JniCompile(uint32_t access_flags,
41b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                             uint32_t method_idx,
42896362bbfa11b66b45f3ce5a9e8570a878d49e07Nicolas Geoffray                             const DexFile& dex_file) const OVERRIDE;
43b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray
44b0fa5dc7769c1e054032f39de0a3f6d6dd06f8cfIan Rogers  uintptr_t GetEntryPointOf(mirror::ArtMethod* method) const OVERRIDE
45b0fa5dc7769c1e054032f39de0a3f6d6dd06f8cfIan Rogers      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
46b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray
47b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray  bool WriteElf(art::File* file,
48b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                OatWriter* oat_writer,
49b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                const std::vector<const art::DexFile*>& dex_files,
50b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                const std::string& android_root,
5172d32629303f8f39362a4099481f48646aed042fIan Rogers                bool is_host) const
52b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray    OVERRIDE
53b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
54b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray
55896362bbfa11b66b45f3ce5a9e8570a878d49e07Nicolas Geoffray  Backend* GetCodeGenerator(CompilationUnit* cu, void* compilation_unit) const OVERRIDE;
56b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray
57896362bbfa11b66b45f3ce5a9e8570a878d49e07Nicolas Geoffray  void InitCompilationUnit(CompilationUnit& cu) const OVERRIDE {}
58b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray
59b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray  /*
60b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray   * @brief Generate and return Dwarf CFI initialization, if supported by the
61b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray   * backend.
62b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray   * @param driver CompilerDriver for this compile.
63b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray   * @returns nullptr if not supported by backend or a vector of bytes for CFI DWARF
64b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray   * information.
65b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray   * @note This is used for backtrace information in generated code.
66b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray   */
67b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray  std::vector<uint8_t>* GetCallFrameInformationInitialization(const CompilerDriver& driver) const
68b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray      OVERRIDE;
69b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray
70b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray private:
71b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(QuickCompiler);
72b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray};
73b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray
7472d32629303f8f39362a4099481f48646aed042fIan Rogersclass OptimizingCompiler FINAL : public QuickCompiler {
75b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray public:
76f635e63318447ca04731b265a86a573c9ed1737cNicolas Geoffray  explicit OptimizingCompiler(CompilerDriver* driver);
77b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray
7872d32629303f8f39362a4099481f48646aed042fIan Rogers  CompiledMethod* Compile(const DexFile::CodeItem* code_item,
79b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                          uint32_t access_flags,
80b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                          InvokeType invoke_type,
81b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                          uint16_t class_def_idx,
82b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                          uint32_t method_idx,
83b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                          jobject class_loader,
84896362bbfa11b66b45f3ce5a9e8570a878d49e07Nicolas Geoffray                          const DexFile& dex_file) const OVERRIDE;
85b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray
8672d32629303f8f39362a4099481f48646aed042fIan Rogers  CompiledMethod* TryCompile(const DexFile::CodeItem* code_item,
87b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                             uint32_t access_flags,
88b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                             InvokeType invoke_type,
89b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                             uint16_t class_def_idx,
90b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                             uint32_t method_idx,
91b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                             jobject class_loader,
92b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray                             const DexFile& dex_file) const;
93b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray
94b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray private:
95700a402244a1a423da4f3ba8032459f4b65fa18fIan Rogers  std::unique_ptr<std::ostream> visualizer_output_;
96f635e63318447ca04731b265a86a573c9ed1737cNicolas Geoffray
97b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray  DISALLOW_COPY_AND_ASSIGN(OptimizingCompiler);
98b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray};
99b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray
100b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray}  // namespace art
101b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray
102b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray#endif  // ART_COMPILER_COMPILERS_H_
103