1b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray/* 2b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray * Copyright (C) 2014 The Android Open Source Project 3b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray * 4b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray * Licensed under the Apache License, Version 2.0 (the "License"); 5b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray * you may not use this file except in compliance with the License. 6b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray * You may obtain a copy of the License at 7b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray * 8b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray * http://www.apache.org/licenses/LICENSE-2.0 9b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray * 10b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray * Unless required by applicable law or agreed to in writing, software 11b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray * distributed under the License is distributed on an "AS IS" BASIS, 12b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray * See the License for the specific language governing permissions and 14b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray * limitations under the License. 15b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray */ 16b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray 17b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray#include "compiler.h" 18b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray 1953c913bb71b218714823c8c87a1f92830c336f61Andreas Gampe#include "base/logging.h" 2053c913bb71b218714823c8c87a1f92830c336f61Andreas Gampe#include "driver/compiler_driver.h" 2153c913bb71b218714823c8c87a1f92830c336f61Andreas Gampe#include "optimizing/optimizing_compiler.h" 2280afd02024d20e60b197d3adfbb43cc303cf29e0Vladimir Marko#include "utils.h" 23b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray 24b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffraynamespace art { 25b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray 2672d32629303f8f39362a4099481f48646aed042fIan RogersCompiler* Compiler::Create(CompilerDriver* driver, Compiler::Kind kind) { 27b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray switch (kind) { 28b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray case kQuick: 293c94f0945ed596ceee39783fa075f013b65e80a1Nicolas Geoffray // TODO: Remove Quick in options. 30b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray case kOptimizing: 3153c913bb71b218714823c8c87a1f92830c336f61Andreas Gampe return CreateOptimizingCompiler(driver); 3253c913bb71b218714823c8c87a1f92830c336f61Andreas Gampe 33b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray default: 34b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray LOG(FATAL) << "UNREACHABLE"; 352c4257be8191c5eefde744e8965fcefc80a0a97dIan Rogers UNREACHABLE(); 36b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray } 37b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray} 38b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray 39b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffraybool Compiler::IsPathologicalCase(const DexFile::CodeItem& code_item, 40b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray uint32_t method_idx, 41b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray const DexFile& dex_file) { 42b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray /* 43b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray * Skip compilation for pathologically large methods - either by instruction count or num vregs. 44b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray * Dalvik uses 16-bit uints for instruction and register counts. We'll limit to a quarter 45b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray * of that, which also guarantees we cannot overflow our 16-bit internal Quick SSA name space. 46b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray */ 47b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray if (code_item.insns_size_in_code_units_ >= UINT16_MAX / 4) { 48b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray LOG(INFO) << "Method exceeds compiler instruction limit: " 49b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray << code_item.insns_size_in_code_units_ 50b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray << " in " << PrettyMethod(method_idx, dex_file); 51b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray return true; 52b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray } 53b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray if (code_item.registers_size_ >= UINT16_MAX / 4) { 54b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray LOG(INFO) << "Method exceeds compiler virtual register limit: " 55b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray << code_item.registers_size_ << " in " << PrettyMethod(method_idx, dex_file); 56b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray return true; 57b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray } 58b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray return false; 59b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray} 60b5f62b3dc5ac2731ba8ad53cdf3d9bdb14fbf86bNicolas Geoffray 61b34f69ab43aaf7a6e6045c95f398baf566ef5023Nicolas Geoffray} // namespace art 62