blob: bb614ae7b2b7628a55aaabd052c4f49492404f4e [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 Gampe57943812017-12-06 21:39:13 -080019#include <android-base/logging.h>
20
21#include "base/macros.h"
Andreas Gampe53c913b2014-08-12 23:19:23 -070022#include "driver/compiler_driver.h"
Andreas Gampe53c913b2014-08-12 23:19:23 -070023#include "optimizing/optimizing_compiler.h"
Vladimir Marko80afd022015-05-19 18:08:00 +010024#include "utils.h"
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000025
26namespace art {
27
Ian Rogers72d32622014-05-06 16:20:11 -070028Compiler* Compiler::Create(CompilerDriver* driver, Compiler::Kind kind) {
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000029 switch (kind) {
30 case kQuick:
Nicolas Geoffray3c94f092016-03-21 17:10:24 +000031 // TODO: Remove Quick in options.
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000032 case kOptimizing:
Andreas Gampe53c913b2014-08-12 23:19:23 -070033 return CreateOptimizingCompiler(driver);
34
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000035 default:
36 LOG(FATAL) << "UNREACHABLE";
Ian Rogers2c4257b2014-10-24 14:20:06 -070037 UNREACHABLE();
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000038 }
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000039}
40
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +000041bool Compiler::IsPathologicalCase(const DexFile::CodeItem& code_item,
42 uint32_t method_idx,
43 const DexFile& dex_file) {
44 /*
45 * Skip compilation for pathologically large methods - either by instruction count or num vregs.
46 * Dalvik uses 16-bit uints for instruction and register counts. We'll limit to a quarter
47 * of that, which also guarantees we cannot overflow our 16-bit internal Quick SSA name space.
48 */
49 if (code_item.insns_size_in_code_units_ >= UINT16_MAX / 4) {
50 LOG(INFO) << "Method exceeds compiler instruction limit: "
51 << code_item.insns_size_in_code_units_
David Sehr709b0702016-10-13 09:12:37 -070052 << " in " << dex_file.PrettyMethod(method_idx);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +000053 return true;
54 }
55 if (code_item.registers_size_ >= UINT16_MAX / 4) {
56 LOG(INFO) << "Method exceeds compiler virtual register limit: "
David Sehr709b0702016-10-13 09:12:37 -070057 << code_item.registers_size_ << " in " << dex_file.PrettyMethod(method_idx);
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +000058 return true;
59 }
60 return false;
61}
62
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000063} // namespace art