Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +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 | |
| 17 | #include "compiler.h" |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 18 | |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 19 | #include "base/logging.h" |
| 20 | #include "dex/quick/quick_compiler.h" |
| 21 | #include "driver/compiler_driver.h" |
| 22 | #include "llvm/llvm_compiler.h" |
| 23 | #include "optimizing/optimizing_compiler.h" |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 24 | |
| 25 | namespace art { |
| 26 | |
| 27 | #ifdef ART_SEA_IR_MODE |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 28 | constexpr bool kCanUseSeaIR = true; |
| 29 | #else |
| 30 | constexpr bool kCanUseSeaIR = false; |
| 31 | #endif |
| 32 | |
| 33 | extern "C" art::CompiledMethod* SeaIrCompileMethod(const art::DexFile::CodeItem* code_item ATTRIBUTE_UNUSED, |
| 34 | uint32_t access_flags ATTRIBUTE_UNUSED, |
| 35 | art::InvokeType invoke_type ATTRIBUTE_UNUSED, |
| 36 | uint16_t class_def_idx ATTRIBUTE_UNUSED, |
| 37 | uint32_t method_idx ATTRIBUTE_UNUSED, |
| 38 | jobject class_loader ATTRIBUTE_UNUSED, |
| 39 | const art::DexFile& dex_file ATTRIBUTE_UNUSED) |
| 40 | #ifdef ART_SEA_IR_MODE |
| 41 | ; // NOLINT(whitespace/semicolon) |
| 42 | #else |
| 43 | { |
| 44 | UNREACHABLE(); |
| 45 | } |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 46 | #endif |
| 47 | |
| 48 | |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 49 | CompiledMethod* Compiler::TryCompileWithSeaIR(const art::DexFile::CodeItem* code_item, |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 50 | uint32_t access_flags, |
| 51 | art::InvokeType invoke_type, |
| 52 | uint16_t class_def_idx, |
| 53 | uint32_t method_idx, |
| 54 | jobject class_loader, |
| 55 | const art::DexFile& dex_file) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 56 | bool use_sea = kCanUseSeaIR && |
| 57 | (std::string::npos != PrettyMethod(method_idx, dex_file).find("fibonacci")); |
| 58 | if (use_sea) { |
| 59 | LOG(INFO) << "Using SEA IR to compile..." << std::endl; |
| 60 | return SeaIrCompileMethod(code_item, |
| 61 | access_flags, |
| 62 | invoke_type, |
| 63 | class_def_idx, |
| 64 | method_idx, |
| 65 | class_loader, |
| 66 | dex_file); |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 67 | } |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 68 | return nullptr; |
| 69 | } |
| 70 | |
Ian Rogers | 72d3262 | 2014-05-06 16:20:11 -0700 | [diff] [blame] | 71 | Compiler* Compiler::Create(CompilerDriver* driver, Compiler::Kind kind) { |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 72 | switch (kind) { |
| 73 | case kQuick: |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 74 | return CreateQuickCompiler(driver); |
| 75 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 76 | case kOptimizing: |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 77 | return CreateOptimizingCompiler(driver); |
| 78 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 79 | case kPortable: |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 80 | { |
| 81 | Compiler* compiler = CreateLLVMCompiler(driver); |
| 82 | CHECK(compiler != nullptr) << "Portable compiler not compiled"; |
| 83 | return compiler; |
| 84 | } |
| 85 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 86 | default: |
| 87 | LOG(FATAL) << "UNREACHABLE"; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 88 | UNREACHABLE(); |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 89 | } |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 92 | bool Compiler::IsPathologicalCase(const DexFile::CodeItem& code_item, |
| 93 | uint32_t method_idx, |
| 94 | const DexFile& dex_file) { |
| 95 | /* |
| 96 | * Skip compilation for pathologically large methods - either by instruction count or num vregs. |
| 97 | * Dalvik uses 16-bit uints for instruction and register counts. We'll limit to a quarter |
| 98 | * of that, which also guarantees we cannot overflow our 16-bit internal Quick SSA name space. |
| 99 | */ |
| 100 | if (code_item.insns_size_in_code_units_ >= UINT16_MAX / 4) { |
| 101 | LOG(INFO) << "Method exceeds compiler instruction limit: " |
| 102 | << code_item.insns_size_in_code_units_ |
| 103 | << " in " << PrettyMethod(method_idx, dex_file); |
| 104 | return true; |
| 105 | } |
| 106 | if (code_item.registers_size_ >= UINT16_MAX / 4) { |
| 107 | LOG(INFO) << "Method exceeds compiler virtual register limit: " |
| 108 | << code_item.registers_size_ << " in " << PrettyMethod(method_idx, dex_file); |
| 109 | return true; |
| 110 | } |
| 111 | return false; |
| 112 | } |
| 113 | |
Nicolas Geoffray | b34f69a | 2014-03-07 15:28:39 +0000 | [diff] [blame] | 114 | } // namespace art |