blob: 2357297b1dc8b8f1acee61a8b314337a9317eb8a [file] [log] [blame]
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +00001/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000017#ifndef ART_COMPILER_COMPILER_H_
18#define ART_COMPILER_COMPILER_H_
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000019
20#include "dex_file.h"
21#include "os.h"
22
23namespace art {
24
25class Backend;
Ian Rogersb48b9eb2014-02-28 16:20:21 -080026struct CompilationUnit;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000027class CompilerDriver;
28class CompiledMethod;
29class MIRGraph;
30class OatWriter;
31
32namespace mirror {
33 class ArtMethod;
34}
35
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000036class Compiler {
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000037 public:
38 enum Kind {
39 kQuick,
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000040 kOptimizing,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000041 kPortable
42 };
43
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000044 explicit Compiler(uint64_t warning)
Ian Rogers3d504072014-03-01 09:16:49 -080045 : maximum_compilation_time_before_warning_(warning) {
46 }
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000047
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000048 static Compiler* Create(Kind kind);
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000049
50 virtual void Init(CompilerDriver& driver) const = 0;
51
52 virtual void UnInit(CompilerDriver& driver) const = 0;
53
Ian Rogers3d504072014-03-01 09:16:49 -080054 virtual CompiledMethod* Compile(CompilerDriver& driver,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000055 const DexFile::CodeItem* code_item,
56 uint32_t access_flags,
57 InvokeType invoke_type,
58 uint16_t class_def_idx,
59 uint32_t method_idx,
60 jobject class_loader,
61 const DexFile& dex_file) const = 0;
62
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000063 static CompiledMethod* TryCompileWithSeaIR(art::CompilerDriver& driver,
64 const art::DexFile::CodeItem* code_item,
65 uint32_t access_flags,
66 art::InvokeType invoke_type,
67 uint16_t class_def_idx,
68 uint32_t method_idx,
69 jobject class_loader,
70 const art::DexFile& dex_file);
71
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000072 virtual CompiledMethod* JniCompile(CompilerDriver& driver,
73 uint32_t access_flags,
74 uint32_t method_idx,
75 const DexFile& dex_file) const = 0;
76
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070077 virtual uintptr_t GetEntryPointOf(mirror::ArtMethod* method) const
78 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000079
80 virtual bool WriteElf(art::File* file,
Ian Rogers3d504072014-03-01 09:16:49 -080081 OatWriter* oat_writer,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000082 const std::vector<const art::DexFile*>& dex_files,
83 const std::string& android_root,
84 bool is_host, const CompilerDriver& driver) const
85 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0;
86
87 virtual Backend* GetCodeGenerator(CompilationUnit* cu,
88 void* compilation_unit) const = 0;
89
90 uint64_t GetMaximumCompilationTimeBeforeWarning() const {
91 return maximum_compilation_time_before_warning_;
92 }
93
Ian Rogers3d504072014-03-01 09:16:49 -080094 virtual bool IsPortable() const {
95 return false;
96 }
97
98 void SetBitcodeFileName(const CompilerDriver& driver, const std::string& filename) {
99 UNUSED(driver);
Nicolas Geoffrayf3e2cc42014-02-18 18:37:26 +0000100 UNUSED(filename);
101 }
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000102
103 virtual void InitCompilationUnit(CompilationUnit& cu) const = 0;
104
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000105 virtual ~Compiler() {}
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000106
Mark Mendellae9fd932014-02-10 16:14:35 -0800107 /*
108 * @brief Generate and return Dwarf CFI initialization, if supported by the
109 * backend.
110 * @param driver CompilerDriver for this compile.
111 * @returns nullptr if not supported by backend or a vector of bytes for CFI DWARF
112 * information.
113 * @note This is used for backtrace information in generated code.
114 */
115 virtual std::vector<uint8_t>* GetCallFrameInformationInitialization(const CompilerDriver& driver)
116 const {
117 return nullptr;
118 }
119
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000120 private:
Ian Rogers3d504072014-03-01 09:16:49 -0800121 const uint64_t maximum_compilation_time_before_warning_;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000122
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000123 DISALLOW_COPY_AND_ASSIGN(Compiler);
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000124};
125
126} // namespace art
127
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000128#endif // ART_COMPILER_COMPILER_H_