Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_COMPILER_DEX_COMPILER_IR_H_ |
| 18 | #define ART_COMPILER_DEX_COMPILER_IR_H_ |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 19 | |
| 20 | #include <vector> |
| 21 | #include <llvm/IR/Module.h> |
| 22 | #include "arena_allocator.h" |
| 23 | #include "backend.h" |
| 24 | #include "compiler_enums.h" |
| 25 | #include "dex/quick/mir_to_lir.h" |
| 26 | #include "dex_instruction.h" |
| 27 | #include "driver/compiler_driver.h" |
| 28 | #include "driver/dex_compilation_unit.h" |
| 29 | #include "llvm/intrinsic_helper.h" |
| 30 | #include "llvm/ir_builder.h" |
| 31 | #include "safe_map.h" |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 32 | #include "base/timing_logger.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 33 | |
| 34 | namespace art { |
| 35 | |
| 36 | class LLVMInfo; |
| 37 | namespace llvm { |
| 38 | class LlvmCompilationUnit; |
| 39 | } // namespace llvm |
| 40 | |
| 41 | struct ArenaMemBlock; |
| 42 | struct Memstats; |
| 43 | class MIRGraph; |
| 44 | class Mir2Lir; |
| 45 | |
| 46 | struct CompilationUnit { |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 47 | explicit CompilationUnit(ArenaPool* pool) |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 48 | : compiler_driver(NULL), |
| 49 | class_linker(NULL), |
| 50 | dex_file(NULL), |
| 51 | class_loader(NULL), |
| 52 | class_def_idx(0), |
| 53 | method_idx(0), |
| 54 | code_item(NULL), |
| 55 | access_flags(0), |
| 56 | invoke_type(kDirect), |
| 57 | shorty(NULL), |
| 58 | disable_opt(0), |
| 59 | enable_debug(0), |
| 60 | verbose(false), |
| 61 | compiler_backend(kNoBackend), |
| 62 | instruction_set(kNone), |
| 63 | num_dalvik_registers(0), |
| 64 | insns(NULL), |
| 65 | num_ins(0), |
| 66 | num_outs(0), |
| 67 | num_regs(0), |
| 68 | num_compiler_temps(0), |
| 69 | compiler_flip_match(false), |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 70 | arena(pool), |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 71 | mir_graph(NULL), |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 72 | cg(NULL), |
| 73 | timings("QuickCompiler", true, false) { |
| 74 | } |
| 75 | |
| 76 | void StartTimingSplit(const char* label); |
| 77 | void NewTimingSplit(const char* label); |
| 78 | void EndTiming(); |
| 79 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 80 | /* |
| 81 | * Fields needed/generated by common frontend and generally used throughout |
| 82 | * the compiler. |
| 83 | */ |
| 84 | CompilerDriver* compiler_driver; |
| 85 | ClassLinker* class_linker; // Linker to resolve fields and methods. |
| 86 | const DexFile* dex_file; // DexFile containing the method being compiled. |
| 87 | jobject class_loader; // compiling method's class loader. |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 88 | uint16_t class_def_idx; // compiling method's defining class definition index. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 89 | uint32_t method_idx; // compiling method's index into method_ids of DexFile. |
| 90 | const DexFile::CodeItem* code_item; // compiling method's DexFile code_item. |
| 91 | uint32_t access_flags; // compiling method's access flags. |
| 92 | InvokeType invoke_type; // compiling method's invocation type. |
| 93 | const char* shorty; // compiling method's shorty. |
| 94 | uint32_t disable_opt; // opt_control_vector flags. |
| 95 | uint32_t enable_debug; // debugControlVector flags. |
| 96 | bool verbose; |
| 97 | CompilerBackend compiler_backend; |
| 98 | InstructionSet instruction_set; |
| 99 | |
Dave Allison | 7020278 | 2013-10-22 17:52:19 -0700 | [diff] [blame^] | 100 | const InstructionSetFeatures& GetInstructionSetFeatures() { |
| 101 | return compiler_driver->GetInstructionSetFeatures(); |
| 102 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 103 | // TODO: much of this info available elsewhere. Go to the original source? |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 104 | uint16_t num_dalvik_registers; // method->registers_size. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 105 | const uint16_t* insns; |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 106 | uint16_t num_ins; |
| 107 | uint16_t num_outs; |
| 108 | uint16_t num_regs; // Unlike num_dalvik_registers, does not include ins. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 109 | |
| 110 | // TODO: may want to move this to MIRGraph. |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 111 | uint16_t num_compiler_temps; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 112 | |
| 113 | // If non-empty, apply optimizer/debug flags only to matching methods. |
| 114 | std::string compiler_method_match; |
| 115 | // Flips sense of compiler_method_match - apply flags if doesn't match. |
| 116 | bool compiler_flip_match; |
| 117 | |
| 118 | // TODO: move memory management to mir_graph, or just switch to using standard containers. |
| 119 | ArenaAllocator arena; |
| 120 | |
| 121 | UniquePtr<MIRGraph> mir_graph; // MIR container. |
| 122 | UniquePtr<Backend> cg; // Target-specific codegen. |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 123 | base::TimingLogger timings; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | } // namespace art |
| 127 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 128 | #endif // ART_COMPILER_DEX_COMPILER_IR_H_ |