buzbee | 67bf885 | 2011-08-17 17:51:35 -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 | |
buzbee | 395116c | 2013-02-27 14:30:25 -0800 | [diff] [blame] | 17 | #ifndef ART_SRC_COMPILER_DEX_COMPILER_IR_H_ |
| 18 | #define ART_SRC_COMPILER_DEX_COMPILER_IR_H_ |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 19 | |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 20 | #include <vector> |
Brian Carlstrom | 37d4879 | 2013-03-22 14:14:45 -0700 | [diff] [blame] | 21 | #include <llvm/IR/Module.h> |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 22 | #include "compiler/dex/quick/mir_to_lir.h" |
| 23 | #include "backend.h" |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame] | 24 | #include "compiler/driver/compiler_driver.h" |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 25 | #include "compiler/driver/dex_compilation_unit.h" |
Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame] | 26 | #include "compiler/llvm/intrinsic_helper.h" |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 27 | #include "compiler/llvm/ir_builder.h" |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 28 | #include "compiler_enums.h" |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 29 | #include "compiler_utility.h" |
| 30 | #include "dex_instruction.h" |
| 31 | #include "safe_map.h" |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 32 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 33 | namespace art { |
| 34 | |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 35 | struct ArenaBitVector; |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 36 | class LLVMInfo; |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 37 | namespace llvm { |
| 38 | class LlvmCompilationUnit; |
| 39 | } // namespace llvm |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 40 | |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 41 | struct ArenaMemBlock; |
| 42 | struct Memstats; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 43 | class MIRGraph; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 44 | class Mir2Lir; |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 45 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 46 | struct CompilationUnit { |
Elliott Hughes | e52e49b | 2012-04-02 16:05:44 -0700 | [diff] [blame] | 47 | CompilationUnit() |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 48 | : compiler_driver(NULL), |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 49 | class_linker(NULL), |
| 50 | dex_file(NULL), |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 51 | class_loader(NULL), |
Ian Rogers | fffdb02 | 2013-01-04 15:14:08 -0800 | [diff] [blame] | 52 | class_def_idx(0), |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 53 | method_idx(0), |
| 54 | code_item(NULL), |
| 55 | access_flags(0), |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 56 | invoke_type(kDirect), |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 57 | shorty(NULL), |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 58 | disable_opt(0), |
| 59 | enable_debug(0), |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 60 | verbose(false), |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 61 | compiler_backend(kNoBackend), |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 62 | instruction_set(kNone), |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 63 | num_dalvik_registers(0), |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 64 | insns(NULL), |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 65 | num_ins(0), |
| 66 | num_outs(0), |
| 67 | num_regs(0), |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 68 | num_compiler_temps(0), |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 69 | compiler_flip_match(false), |
| 70 | arena_head(NULL), |
| 71 | current_arena(NULL), |
| 72 | num_arena_blocks(0), |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 73 | mstats(NULL), |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 74 | mir_graph(NULL), |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 75 | cg(NULL) {} |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 76 | /* |
| 77 | * Fields needed/generated by common frontend and generally used throughout |
| 78 | * the compiler. |
| 79 | */ |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame] | 80 | CompilerDriver* compiler_driver; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 81 | ClassLinker* class_linker; // Linker to resolve fields and methods. |
| 82 | const DexFile* dex_file; // DexFile containing the method being compiled. |
| 83 | jobject class_loader; // compiling method's class loader. |
Ian Rogers | fffdb02 | 2013-01-04 15:14:08 -0800 | [diff] [blame] | 84 | uint32_t class_def_idx; // compiling method's defining class definition index. |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 85 | uint32_t method_idx; // compiling method's index into method_ids of DexFile. |
| 86 | const DexFile::CodeItem* code_item; // compiling method's DexFile code_item. |
| 87 | uint32_t access_flags; // compiling method's access flags. |
| 88 | InvokeType invoke_type; // compiling method's invocation type. |
| 89 | const char* shorty; // compiling method's shorty. |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 90 | uint32_t disable_opt; // opt_control_vector flags. |
| 91 | uint32_t enable_debug; // debugControlVector flags. |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 92 | bool verbose; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 93 | CompilerBackend compiler_backend; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 94 | InstructionSet instruction_set; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 95 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 96 | // TODO: much of this info available elsewhere. Go to the original source? |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 97 | int num_dalvik_registers; // method->registers_size. |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 98 | const uint16_t* insns; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 99 | int num_ins; |
| 100 | int num_outs; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 101 | int num_regs; // Unlike num_dalvik_registers, does not include ins. |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 102 | |
| 103 | // TODO: may want to move this to MIRGraph. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 104 | int num_compiler_temps; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 105 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 106 | // If non-empty, apply optimizer/debug flags only to matching methods. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 107 | std::string compiler_method_match; |
| 108 | // Flips sense of compiler_method_match - apply flags if doesn't match. |
| 109 | bool compiler_flip_match; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 110 | |
| 111 | // TODO: move memory management to mir_graph, or just switch to using standard containers. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 112 | ArenaMemBlock* arena_head; |
| 113 | ArenaMemBlock* current_arena; |
| 114 | int num_arena_blocks; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 115 | Memstats* mstats; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 116 | |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 117 | UniquePtr<MIRGraph> mir_graph; // MIR container. |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 118 | UniquePtr<Backend> cg; // Target-specific codegen. |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 119 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 120 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 121 | } // namespace art |
| 122 | |
buzbee | 395116c | 2013-02-27 14:30:25 -0800 | [diff] [blame] | 123 | #endif // ART_SRC_COMPILER_DEX_COMPILER_IR_H_ |