Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 1 | /* |
| 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 Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame^] | 17 | #ifndef ART_COMPILER_COMPILER_H_ |
| 18 | #define ART_COMPILER_COMPILER_H_ |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 19 | |
| 20 | #include "dex_file.h" |
| 21 | #include "os.h" |
| 22 | |
| 23 | namespace art { |
| 24 | |
| 25 | class Backend; |
Ian Rogers | b48b9eb | 2014-02-28 16:20:21 -0800 | [diff] [blame] | 26 | struct CompilationUnit; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 27 | class CompilerDriver; |
| 28 | class CompiledMethod; |
| 29 | class MIRGraph; |
| 30 | class OatWriter; |
| 31 | |
| 32 | namespace mirror { |
| 33 | class ArtMethod; |
| 34 | } |
| 35 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame^] | 36 | class Compiler { |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 37 | public: |
| 38 | enum Kind { |
| 39 | kQuick, |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame^] | 40 | kOptimizing, |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 41 | kPortable |
| 42 | }; |
| 43 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame^] | 44 | explicit Compiler(uint64_t warning) |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 45 | : maximum_compilation_time_before_warning_(warning) { |
| 46 | } |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 47 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame^] | 48 | static Compiler* Create(Kind kind); |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 49 | |
| 50 | virtual void Init(CompilerDriver& driver) const = 0; |
| 51 | |
| 52 | virtual void UnInit(CompilerDriver& driver) const = 0; |
| 53 | |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 54 | virtual CompiledMethod* Compile(CompilerDriver& driver, |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 55 | 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 Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame^] | 63 | 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 Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 72 | virtual CompiledMethod* JniCompile(CompilerDriver& driver, |
| 73 | uint32_t access_flags, |
| 74 | uint32_t method_idx, |
| 75 | const DexFile& dex_file) const = 0; |
| 76 | |
| 77 | virtual uintptr_t GetEntryPointOf(mirror::ArtMethod* method) const = 0; |
| 78 | |
| 79 | virtual bool WriteElf(art::File* file, |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 80 | OatWriter* oat_writer, |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 81 | const std::vector<const art::DexFile*>& dex_files, |
| 82 | const std::string& android_root, |
| 83 | bool is_host, const CompilerDriver& driver) const |
| 84 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) = 0; |
| 85 | |
| 86 | virtual Backend* GetCodeGenerator(CompilationUnit* cu, |
| 87 | void* compilation_unit) const = 0; |
| 88 | |
| 89 | uint64_t GetMaximumCompilationTimeBeforeWarning() const { |
| 90 | return maximum_compilation_time_before_warning_; |
| 91 | } |
| 92 | |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 93 | virtual bool IsPortable() const { |
| 94 | return false; |
| 95 | } |
| 96 | |
| 97 | void SetBitcodeFileName(const CompilerDriver& driver, const std::string& filename) { |
| 98 | UNUSED(driver); |
Nicolas Geoffray | f3e2cc4 | 2014-02-18 18:37:26 +0000 | [diff] [blame] | 99 | UNUSED(filename); |
| 100 | } |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 101 | |
| 102 | virtual void InitCompilationUnit(CompilationUnit& cu) const = 0; |
| 103 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame^] | 104 | virtual ~Compiler() {} |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 105 | |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 106 | /* |
| 107 | * @brief Generate and return Dwarf CFI initialization, if supported by the |
| 108 | * backend. |
| 109 | * @param driver CompilerDriver for this compile. |
| 110 | * @returns nullptr if not supported by backend or a vector of bytes for CFI DWARF |
| 111 | * information. |
| 112 | * @note This is used for backtrace information in generated code. |
| 113 | */ |
| 114 | virtual std::vector<uint8_t>* GetCallFrameInformationInitialization(const CompilerDriver& driver) |
| 115 | const { |
| 116 | return nullptr; |
| 117 | } |
| 118 | |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 119 | private: |
Ian Rogers | 3d50407 | 2014-03-01 09:16:49 -0800 | [diff] [blame] | 120 | const uint64_t maximum_compilation_time_before_warning_; |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 121 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame^] | 122 | DISALLOW_COPY_AND_ASSIGN(Compiler); |
Nicolas Geoffray | f5df897 | 2014-02-14 18:37:08 +0000 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | } // namespace art |
| 126 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame^] | 127 | #endif // ART_COMPILER_COMPILER_H_ |