blob: 51fb29afd24f5a71c3516a0a11daa1a2d4f795b1 [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
17#ifndef ART_COMPILER_COMPILER_BACKEND_H_
18#define ART_COMPILER_COMPILER_BACKEND_H_
19
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
36class CompilerBackend {
37 public:
38 enum Kind {
39 kQuick,
40 kPortable
41 };
42
Ian Rogers3d504072014-03-01 09:16:49 -080043 explicit CompilerBackend(uint64_t warning)
44 : maximum_compilation_time_before_warning_(warning) {
45 }
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000046
47 static CompilerBackend* Create(Kind kind);
48
49 virtual void Init(CompilerDriver& driver) const = 0;
50
51 virtual void UnInit(CompilerDriver& driver) const = 0;
52
Ian Rogers3d504072014-03-01 09:16:49 -080053 virtual CompiledMethod* Compile(CompilerDriver& driver,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000054 const DexFile::CodeItem* code_item,
55 uint32_t access_flags,
56 InvokeType invoke_type,
57 uint16_t class_def_idx,
58 uint32_t method_idx,
59 jobject class_loader,
60 const DexFile& dex_file) const = 0;
61
62 virtual CompiledMethod* JniCompile(CompilerDriver& driver,
63 uint32_t access_flags,
64 uint32_t method_idx,
65 const DexFile& dex_file) const = 0;
66
67 virtual uintptr_t GetEntryPointOf(mirror::ArtMethod* method) const = 0;
68
69 virtual bool WriteElf(art::File* file,
Ian Rogers3d504072014-03-01 09:16:49 -080070 OatWriter* oat_writer,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000071 const std::vector<const art::DexFile*>& dex_files,
72 const std::string& android_root,
73 bool is_host, const CompilerDriver& driver) const
74 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0;
75
76 virtual Backend* GetCodeGenerator(CompilationUnit* cu,
77 void* compilation_unit) const = 0;
78
79 uint64_t GetMaximumCompilationTimeBeforeWarning() const {
80 return maximum_compilation_time_before_warning_;
81 }
82
Ian Rogers3d504072014-03-01 09:16:49 -080083 virtual bool IsPortable() const {
84 return false;
85 }
86
87 void SetBitcodeFileName(const CompilerDriver& driver, const std::string& filename) {
88 UNUSED(driver);
Nicolas Geoffrayf3e2cc42014-02-18 18:37:26 +000089 UNUSED(filename);
90 }
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000091
92 virtual void InitCompilationUnit(CompilationUnit& cu) const = 0;
93
94 virtual ~CompilerBackend() {}
95
96 private:
Ian Rogers3d504072014-03-01 09:16:49 -080097 const uint64_t maximum_compilation_time_before_warning_;
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +000098
99 DISALLOW_COPY_AND_ASSIGN(CompilerBackend);
100};
101
102} // namespace art
103
Nicolas Geoffrayb84f5222014-02-18 10:18:47 +0000104#endif // ART_COMPILER_COMPILER_BACKEND_H_