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