blob: 05fa8587fcb06004eaa223162cbeee781dff8432 [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;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000029class OatWriter;
30
31namespace mirror {
32 class ArtMethod;
33}
34
Andreas Gampe53c913b2014-08-12 23:19:23 -070035// Base class for compiler-specific thread-local storage for compiler worker threads
36class CompilerTls {
37 public:
38 CompilerTls() {}
39 ~CompilerTls() {}
40};
41
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000042class Compiler {
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000043 public:
44 enum Kind {
45 kQuick,
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000046 kOptimizing,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000047 kPortable
48 };
49
Ian Rogers72d32622014-05-06 16:20:11 -070050 static Compiler* Create(CompilerDriver* driver, Kind kind);
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000051
Ian Rogers72d32622014-05-06 16:20:11 -070052 virtual void Init() const = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000053
Ian Rogers72d32622014-05-06 16:20:11 -070054 virtual void UnInit() const = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000055
Andreas Gampe53c913b2014-08-12 23:19:23 -070056 virtual bool CanCompileMethod(uint32_t method_idx, const DexFile& dex_file, CompilationUnit* cu)
57 const = 0;
58
Ian Rogers72d32622014-05-06 16:20:11 -070059 virtual CompiledMethod* Compile(const DexFile::CodeItem* code_item,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000060 uint32_t access_flags,
61 InvokeType invoke_type,
62 uint16_t class_def_idx,
63 uint32_t method_idx,
64 jobject class_loader,
65 const DexFile& dex_file) const = 0;
66
Ian Rogers72d32622014-05-06 16:20:11 -070067 static CompiledMethod* TryCompileWithSeaIR(const art::DexFile::CodeItem* code_item,
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000068 uint32_t access_flags,
69 art::InvokeType invoke_type,
70 uint16_t class_def_idx,
71 uint32_t method_idx,
72 jobject class_loader,
73 const art::DexFile& dex_file);
74
Ian Rogers72d32622014-05-06 16:20:11 -070075 virtual CompiledMethod* JniCompile(uint32_t access_flags,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000076 uint32_t method_idx,
77 const DexFile& dex_file) const = 0;
78
Ian Rogersb0fa5dc2014-04-28 16:47:08 -070079 virtual uintptr_t GetEntryPointOf(mirror::ArtMethod* method) const
80 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000081
82 virtual bool WriteElf(art::File* file,
Ian Rogers3d504072014-03-01 09:16:49 -080083 OatWriter* oat_writer,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000084 const std::vector<const art::DexFile*>& dex_files,
85 const std::string& android_root,
Ian Rogers72d32622014-05-06 16:20:11 -070086 bool is_host) const
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000087 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0;
88
Ian Rogers72d32622014-05-06 16:20:11 -070089 virtual Backend* GetCodeGenerator(CompilationUnit* cu, void* compilation_unit) const = 0;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000090
91 uint64_t GetMaximumCompilationTimeBeforeWarning() const {
92 return maximum_compilation_time_before_warning_;
93 }
94
Ian Rogers3d504072014-03-01 09:16:49 -080095 virtual bool IsPortable() const {
96 return false;
97 }
98
99 void SetBitcodeFileName(const CompilerDriver& driver, const std::string& filename) {
100 UNUSED(driver);
Nicolas Geoffrayf3e2cc42014-02-18 18:37:26 +0000101 UNUSED(filename);
102 }
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000103
104 virtual void InitCompilationUnit(CompilationUnit& cu) const = 0;
105
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000106 virtual ~Compiler() {}
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000107
Mark Mendellae9fd932014-02-10 16:14:35 -0800108 /*
109 * @brief Generate and return Dwarf CFI initialization, if supported by the
110 * backend.
111 * @param driver CompilerDriver for this compile.
112 * @returns nullptr if not supported by backend or a vector of bytes for CFI DWARF
113 * information.
114 * @note This is used for backtrace information in generated code.
115 */
116 virtual std::vector<uint8_t>* GetCallFrameInformationInitialization(const CompilerDriver& driver)
117 const {
118 return nullptr;
119 }
120
Andreas Gampe53c913b2014-08-12 23:19:23 -0700121 virtual CompilerTls* CreateNewCompilerTls() {
122 return nullptr;
123 }
124
Ian Rogers72d32622014-05-06 16:20:11 -0700125 protected:
126 explicit Compiler(CompilerDriver* driver, uint64_t warning) :
127 driver_(driver), maximum_compilation_time_before_warning_(warning) {
128 }
129
130 CompilerDriver* GetCompilerDriver() const {
131 return driver_;
132 }
133
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000134 private:
Ian Rogers72d32622014-05-06 16:20:11 -0700135 CompilerDriver* const driver_;
Ian Rogers3d504072014-03-01 09:16:49 -0800136 const uint64_t maximum_compilation_time_before_warning_;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000137
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000138 DISALLOW_COPY_AND_ASSIGN(Compiler);
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000139};
140
141} // namespace art
142
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000143#endif // ART_COMPILER_COMPILER_H_