Brian Carlstrom | 751d4ed | 2013-07-18 16:20:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 17 | #ifdef ART_SEA_IR_MODE |
| 18 | #include <llvm/Support/Threading.h> |
| 19 | #include "base/logging.h" |
| 20 | #include "dex/portable/mir_to_gbc.h" |
| 21 | #include "driver/compiler_driver.h" |
| 22 | #include "leb128.h" |
| 23 | #include "llvm/llvm_compilation_unit.h" |
| 24 | #include "mirror/object.h" |
| 25 | #include "runtime.h" |
Dragos Sbirlea | 6547fa9 | 2013-08-05 18:33:30 -0700 | [diff] [blame^] | 26 | #include "safe_map.h" |
Dragos Sbirlea | 6447919 | 2013-08-01 15:38:43 -0700 | [diff] [blame] | 27 | |
| 28 | #include "sea_ir/sea.h" |
| 29 | #include "sea_ir/debug/dot_gen.h" |
| 30 | #include "sea_ir/types/types.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 31 | namespace art { |
| 32 | |
| 33 | static CompiledMethod* CompileMethodWithSeaIr(CompilerDriver& compiler, |
| 34 | const CompilerBackend compiler_backend, |
| 35 | const DexFile::CodeItem* code_item, |
Dragos Sbirlea | b40eddf | 2013-07-31 13:37:31 -0700 | [diff] [blame] | 36 | uint32_t method_access_flags, InvokeType invoke_type, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 37 | uint32_t class_def_idx, uint32_t method_idx, |
| 38 | jobject class_loader, const DexFile& dex_file |
| 39 | #if defined(ART_USE_PORTABLE_COMPILER) |
| 40 | , llvm::LlvmCompilationUnit* llvm_compilation_unit |
| 41 | #endif |
| 42 | ) { |
| 43 | // NOTE: Instead of keeping the convention from the Dalvik frontend.cc |
| 44 | // and silencing the cpplint.py warning, I just corrected the formatting. |
| 45 | VLOG(compiler) << "Compiling " << PrettyMethod(method_idx, dex_file) << "..."; |
Dragos Sbirlea | 6447919 | 2013-08-01 15:38:43 -0700 | [diff] [blame] | 46 | sea_ir::SeaGraph* ir_graph = sea_ir::SeaGraph::GetCurrentGraph(dex_file); |
| 47 | ir_graph->CompileMethod(code_item, class_def_idx, method_idx, method_access_flags, dex_file); |
| 48 | sea_ir::DotConversion dc; |
Dragos Sbirlea | 6547fa9 | 2013-08-05 18:33:30 -0700 | [diff] [blame^] | 49 | SafeMap<int, const sea_ir::Type*>* types = ir_graph->ti_->GetTypeMap(); |
| 50 | dc.DumpSea(ir_graph, "/tmp/temp.dot", types); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 51 | CHECK(0 && "No SEA compiled function exists yet."); |
| 52 | return NULL; |
| 53 | } |
| 54 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 55 | CompiledMethod* SeaIrCompileOneMethod(CompilerDriver& compiler, |
| 56 | const CompilerBackend backend, |
| 57 | const DexFile::CodeItem* code_item, |
Dragos Sbirlea | b40eddf | 2013-07-31 13:37:31 -0700 | [diff] [blame] | 58 | uint32_t method_access_flags, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 59 | InvokeType invoke_type, |
| 60 | uint32_t class_def_idx, |
| 61 | uint32_t method_idx, |
| 62 | jobject class_loader, |
| 63 | const DexFile& dex_file, |
| 64 | llvm::LlvmCompilationUnit* llvm_compilation_unit) { |
Dragos Sbirlea | b40eddf | 2013-07-31 13:37:31 -0700 | [diff] [blame] | 65 | return CompileMethodWithSeaIr(compiler, backend, code_item, method_access_flags, invoke_type, |
Dragos Sbirlea | c16c5b4 | 2013-07-26 18:08:35 -0700 | [diff] [blame] | 66 | class_def_idx, method_idx, class_loader, dex_file |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 67 | #if defined(ART_USE_PORTABLE_COMPILER) |
| 68 | , llvm_compilation_unit |
| 69 | #endif |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 70 | ); // NOLINT |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | extern "C" art::CompiledMethod* |
| 74 | SeaIrCompileMethod(art::CompilerDriver& compiler, |
| 75 | const art::DexFile::CodeItem* code_item, |
Dragos Sbirlea | b40eddf | 2013-07-31 13:37:31 -0700 | [diff] [blame] | 76 | uint32_t method_access_flags, art::InvokeType invoke_type, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 77 | uint32_t class_def_idx, uint32_t method_idx, jobject class_loader, |
| 78 | const art::DexFile& dex_file) { |
Dragos Sbirlea | c16c5b4 | 2013-07-26 18:08:35 -0700 | [diff] [blame] | 79 | // TODO: Check method fingerprint here to determine appropriate backend type. |
| 80 | // Until then, use build default |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 81 | art::CompilerBackend backend = compiler.GetCompilerBackend(); |
Dragos Sbirlea | b40eddf | 2013-07-31 13:37:31 -0700 | [diff] [blame] | 82 | return art::SeaIrCompileOneMethod(compiler, backend, code_item, method_access_flags, invoke_type, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 83 | class_def_idx, method_idx, class_loader, dex_file, |
| 84 | NULL /* use thread llvm_info */); |
| 85 | } |
| 86 | #endif |
| 87 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 88 | } // namespace art |