blob: fbfd8e64152520ab47516aca160a36fbde2f0b68 [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 Rogers72d32622014-05-06 16:20:11 -070028extern "C" art::CompiledMethod* SeaIrCompileMethod(const art::DexFile::CodeItem* code_item,
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000029 uint32_t access_flags,
30 art::InvokeType invoke_type,
31 uint16_t class_def_idx,
32 uint32_t method_idx,
33 jobject class_loader,
34 const art::DexFile& dex_file);
35#endif
36
37
Ian Rogers72d32622014-05-06 16:20:11 -070038CompiledMethod* Compiler::TryCompileWithSeaIR(const art::DexFile::CodeItem* code_item,
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000039 uint32_t access_flags,
40 art::InvokeType invoke_type,
41 uint16_t class_def_idx,
42 uint32_t method_idx,
43 jobject class_loader,
44 const art::DexFile& dex_file) {
45#ifdef ART_SEA_IR_MODE
Ian Rogers72d32622014-05-06 16:20:11 -070046 bool use_sea = (std::string::npos != PrettyMethod(method_idx, dex_file).find("fibonacci"));
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000047 if (use_sea) {
48 LOG(INFO) << "Using SEA IR to compile..." << std::endl;
Ian Rogers72d32622014-05-06 16:20:11 -070049 return SeaIrCompileMethod(code_item,
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000050 access_flags,
51 invoke_type,
52 class_def_idx,
53 method_idx,
54 class_loader,
55 dex_file);
56 }
57#endif
58 return nullptr;
59}
60
Ian Rogers72d32622014-05-06 16:20:11 -070061Compiler* Compiler::Create(CompilerDriver* driver, Compiler::Kind kind) {
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000062 switch (kind) {
63 case kQuick:
Andreas Gampe53c913b2014-08-12 23:19:23 -070064 return CreateQuickCompiler(driver);
65
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000066 case kOptimizing:
Andreas Gampe53c913b2014-08-12 23:19:23 -070067 return CreateOptimizingCompiler(driver);
68
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000069 case kPortable:
Andreas Gampe53c913b2014-08-12 23:19:23 -070070 {
71 Compiler* compiler = CreateLLVMCompiler(driver);
72 CHECK(compiler != nullptr) << "Portable compiler not compiled";
73 return compiler;
74 }
75
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000076 default:
77 LOG(FATAL) << "UNREACHABLE";
78 }
79 return nullptr;
80}
81
82} // namespace art