blob: b9fcf5bab660a7d9a0d11e7ba99d5324b708662c [file] [log] [blame]
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +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#include "compiler.h"
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000018
Andreas Gampe53c913b2014-08-12 23:19:23 -070019#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 Geoffrayb34f69a2014-03-07 15:28:39 +000024
25namespace art {
26
27#ifdef ART_SEA_IR_MODE
Ian Rogers6a3c1fc2014-10-31 00:33:20 -070028constexpr bool kCanUseSeaIR = true;
29#else
30constexpr bool kCanUseSeaIR = false;
31#endif
32
33extern "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 Geoffrayb34f69a2014-03-07 15:28:39 +000046#endif
47
48
Ian Rogers72d32622014-05-06 16:20:11 -070049CompiledMethod* Compiler::TryCompileWithSeaIR(const art::DexFile::CodeItem* code_item,
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000050 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 Rogers6a3c1fc2014-10-31 00:33:20 -070056 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 Geoffrayb34f69a2014-03-07 15:28:39 +000067 }
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000068 return nullptr;
69}
70
Ian Rogers72d32622014-05-06 16:20:11 -070071Compiler* Compiler::Create(CompilerDriver* driver, Compiler::Kind kind) {
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000072 switch (kind) {
73 case kQuick:
Andreas Gampe53c913b2014-08-12 23:19:23 -070074 return CreateQuickCompiler(driver);
75
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000076 case kOptimizing:
Andreas Gampe53c913b2014-08-12 23:19:23 -070077 return CreateOptimizingCompiler(driver);
78
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000079 case kPortable:
Andreas Gampe53c913b2014-08-12 23:19:23 -070080 {
81 Compiler* compiler = CreateLLVMCompiler(driver);
82 CHECK(compiler != nullptr) << "Portable compiler not compiled";
83 return compiler;
84 }
85
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000086 default:
87 LOG(FATAL) << "UNREACHABLE";
Ian Rogers2c4257b2014-10-24 14:20:06 -070088 UNREACHABLE();
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000089 }
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000090}
91
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +000092bool 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 Geoffrayb34f69a2014-03-07 15:28:39 +0000114} // namespace art