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> |
Dragos Sbirlea | bd136a2 | 2013-08-13 18:07:04 -0700 | [diff] [blame] | 19 | #include <llvm/Support/raw_ostream.h> |
| 20 | #include <llvm/Bitcode/ReaderWriter.h> |
| 21 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 22 | #include "base/logging.h" |
Dragos Sbirlea | bd136a2 | 2013-08-13 18:07:04 -0700 | [diff] [blame] | 23 | #include "llvm/llvm_compilation_unit.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 24 | #include "dex/portable/mir_to_gbc.h" |
| 25 | #include "driver/compiler_driver.h" |
Dragos Sbirlea | bd136a2 | 2013-08-13 18:07:04 -0700 | [diff] [blame] | 26 | #include "verifier/method_verifier.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 27 | #include "mirror/object.h" |
Dragos Sbirlea | bd136a2 | 2013-08-13 18:07:04 -0700 | [diff] [blame] | 28 | #include "utils.h" |
| 29 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 30 | #include "runtime.h" |
Dragos Sbirlea | 6547fa9 | 2013-08-05 18:33:30 -0700 | [diff] [blame] | 31 | #include "safe_map.h" |
Dragos Sbirlea | 6447919 | 2013-08-01 15:38:43 -0700 | [diff] [blame] | 32 | |
Dragos Sbirlea | bfaf44f | 2013-08-06 15:41:44 -0700 | [diff] [blame] | 33 | #include "sea_ir/ir/sea.h" |
Dragos Sbirlea | 6447919 | 2013-08-01 15:38:43 -0700 | [diff] [blame] | 34 | #include "sea_ir/debug/dot_gen.h" |
| 35 | #include "sea_ir/types/types.h" |
Dragos Sbirlea | bd136a2 | 2013-08-13 18:07:04 -0700 | [diff] [blame] | 36 | #include "sea_ir/code_gen/code_gen.h" |
| 37 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 38 | namespace art { |
| 39 | |
| 40 | static CompiledMethod* CompileMethodWithSeaIr(CompilerDriver& compiler, |
| 41 | const CompilerBackend compiler_backend, |
| 42 | const DexFile::CodeItem* code_item, |
Dragos Sbirlea | b40eddf | 2013-07-31 13:37:31 -0700 | [diff] [blame] | 43 | uint32_t method_access_flags, InvokeType invoke_type, |
Ian Rogers | ee39a10 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 44 | uint16_t class_def_idx, uint32_t method_idx, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 45 | jobject class_loader, const DexFile& dex_file |
| 46 | #if defined(ART_USE_PORTABLE_COMPILER) |
| 47 | , llvm::LlvmCompilationUnit* llvm_compilation_unit |
| 48 | #endif |
| 49 | ) { |
Dragos Sbirlea | 90af14d | 2013-08-15 17:50:16 -0700 | [diff] [blame] | 50 | LOG(INFO) << "Compiling " << PrettyMethod(method_idx, dex_file) << "."; |
Dragos Sbirlea | a3519a4 | 2013-08-07 14:41:55 -0700 | [diff] [blame] | 51 | sea_ir::SeaGraph* ir_graph = sea_ir::SeaGraph::GetGraph(dex_file); |
Dragos Sbirlea | 90af14d | 2013-08-15 17:50:16 -0700 | [diff] [blame] | 52 | std::string symbol = "dex_" + MangleForJni(PrettyMethod(method_idx, dex_file)); |
| 53 | sea_ir::CodeGenData* llvm_data = ir_graph->CompileMethod(symbol, |
| 54 | code_item, class_def_idx, method_idx, method_access_flags, dex_file); |
Dragos Sbirlea | 6447919 | 2013-08-01 15:38:43 -0700 | [diff] [blame] | 55 | sea_ir::DotConversion dc; |
Dragos Sbirlea | 6547fa9 | 2013-08-05 18:33:30 -0700 | [diff] [blame] | 56 | SafeMap<int, const sea_ir::Type*>* types = ir_graph->ti_->GetTypeMap(); |
| 57 | dc.DumpSea(ir_graph, "/tmp/temp.dot", types); |
Dragos Sbirlea | bd136a2 | 2013-08-13 18:07:04 -0700 | [diff] [blame] | 58 | MethodReference mref(&dex_file, method_idx); |
Dragos Sbirlea | 90af14d | 2013-08-15 17:50:16 -0700 | [diff] [blame] | 59 | std::string llvm_code = llvm_data->GetElf(compiler.GetInstructionSet()); |
Mathieu Chartier | 193bad9 | 2013-08-29 18:46:00 -0700 | [diff] [blame] | 60 | CompiledMethod* compiled_method = |
| 61 | new CompiledMethod(compiler, compiler.GetInstructionSet(), llvm_code, |
Vladimir Marko | 2b5eaa2 | 2013-12-13 13:59:30 +0000 | [diff] [blame] | 62 | *compiler.GetVerifiedMethodsData()->GetDexGcMap(mref), symbol); |
Dragos Sbirlea | 90af14d | 2013-08-15 17:50:16 -0700 | [diff] [blame] | 63 | LOG(INFO) << "Compiled SEA IR method " << PrettyMethod(method_idx, dex_file) << "."; |
Dragos Sbirlea | bd136a2 | 2013-08-13 18:07:04 -0700 | [diff] [blame] | 64 | return compiled_method; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 67 | CompiledMethod* SeaIrCompileOneMethod(CompilerDriver& compiler, |
| 68 | const CompilerBackend backend, |
| 69 | const DexFile::CodeItem* code_item, |
Dragos Sbirlea | b40eddf | 2013-07-31 13:37:31 -0700 | [diff] [blame] | 70 | uint32_t method_access_flags, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 71 | InvokeType invoke_type, |
Ian Rogers | ee39a10 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 72 | uint16_t class_def_idx, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 73 | uint32_t method_idx, |
| 74 | jobject class_loader, |
| 75 | const DexFile& dex_file, |
| 76 | llvm::LlvmCompilationUnit* llvm_compilation_unit) { |
Dragos Sbirlea | b40eddf | 2013-07-31 13:37:31 -0700 | [diff] [blame] | 77 | return CompileMethodWithSeaIr(compiler, backend, code_item, method_access_flags, invoke_type, |
Dragos Sbirlea | c16c5b4 | 2013-07-26 18:08:35 -0700 | [diff] [blame] | 78 | class_def_idx, method_idx, class_loader, dex_file |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 79 | #if defined(ART_USE_PORTABLE_COMPILER) |
| 80 | , llvm_compilation_unit |
| 81 | #endif |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 82 | ); // NOLINT |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | extern "C" art::CompiledMethod* |
| 86 | SeaIrCompileMethod(art::CompilerDriver& compiler, |
| 87 | const art::DexFile::CodeItem* code_item, |
Dragos Sbirlea | b40eddf | 2013-07-31 13:37:31 -0700 | [diff] [blame] | 88 | uint32_t method_access_flags, art::InvokeType invoke_type, |
Ian Rogers | ee39a10 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 89 | uint16_t class_def_idx, uint32_t method_idx, jobject class_loader, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 90 | const art::DexFile& dex_file) { |
Dragos Sbirlea | c16c5b4 | 2013-07-26 18:08:35 -0700 | [diff] [blame] | 91 | // TODO: Check method fingerprint here to determine appropriate backend type. |
| 92 | // Until then, use build default |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 93 | art::CompilerBackend backend = compiler.GetCompilerBackend(); |
Dragos Sbirlea | b40eddf | 2013-07-31 13:37:31 -0700 | [diff] [blame] | 94 | return art::SeaIrCompileOneMethod(compiler, backend, code_item, method_access_flags, invoke_type, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 95 | class_def_idx, method_idx, class_loader, dex_file, |
| 96 | NULL /* use thread llvm_info */); |
| 97 | } |
| 98 | #endif |
| 99 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 100 | } // namespace art |