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 | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 21 | |
Brian Carlstrom | 37d4879 | 2013-03-22 14:14:45 -0700 | [diff] [blame] | 22 | #include <llvm/IR/Module.h> |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 23 | |
| 24 | #include "compiler/dex/quick/codegen.h" |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame] | 25 | #include "compiler/driver/compiler_driver.h" |
Ian Rogers | 89756f2 | 2013-03-04 16:40:02 -0800 | [diff] [blame] | 26 | #include "compiler/driver/dex_compilation_unit.h" |
Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame] | 27 | #include "compiler/llvm/intrinsic_helper.h" |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 28 | #include "compiler/llvm/ir_builder.h" |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 29 | #include "compiler_enums.h" |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 30 | #include "compiler_utility.h" |
| 31 | #include "dex_instruction.h" |
| 32 | #include "safe_map.h" |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 33 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 34 | namespace art { |
| 35 | |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 36 | //TODO: replace these macros |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 37 | #define SLOW_FIELD_PATH (cu->enable_debug & (1 << kDebugSlowFieldPath)) |
| 38 | #define SLOW_INVOKE_PATH (cu->enable_debug & (1 << kDebugSlowInvokePath)) |
| 39 | #define SLOW_STRING_PATH (cu->enable_debug & (1 << kDebugSlowStringPath)) |
| 40 | #define SLOW_TYPE_PATH (cu->enable_debug & (1 << kDebugSlowTypePath)) |
| 41 | #define EXERCISE_SLOWEST_STRING_PATH (cu->enable_debug & \ |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 42 | (1 << kDebugSlowestStringPath)) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 43 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 44 | // Minimum field size to contain Dalvik v_reg number. |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 45 | #define VREG_NUM_WIDTH 16 |
| 46 | |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 47 | struct ArenaBitVector; |
| 48 | struct LIR; |
| 49 | class LLVMInfo; |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 50 | namespace llvm { |
| 51 | class LlvmCompilationUnit; |
| 52 | } // namespace llvm |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 53 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 54 | struct PromotionMap { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 55 | RegLocationType core_location:3; |
| 56 | uint8_t core_reg; |
| 57 | RegLocationType fp_location:3; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 58 | uint8_t FpReg; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 59 | bool first_in_pair; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 60 | }; |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 61 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 62 | struct RegLocation { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 63 | RegLocationType location:3; |
| 64 | unsigned wide:1; |
| 65 | unsigned defined:1; // Do we know the type? |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 66 | unsigned is_const:1; // Constant, value in mir_graph->constant_values[]. |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 67 | unsigned fp:1; // Floating point? |
| 68 | unsigned core:1; // Non-floating point? |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 69 | unsigned ref:1; // Something GC cares about. |
| 70 | unsigned high_word:1; // High word of pair? |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 71 | unsigned home:1; // Does this represent the home location? |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 72 | uint8_t low_reg; // First physical register. |
| 73 | uint8_t high_reg; // 2nd physical register (if wide). |
| 74 | int32_t s_reg_low; // SSA name for low Dalvik word. |
| 75 | int32_t orig_sreg; // TODO: remove after Bitcode gen complete |
| 76 | // and consolodate usage w/ s_reg_low. |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | struct CompilerTemp { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 80 | int s_reg; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 81 | ArenaBitVector* bv; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 82 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 83 | |
buzbee | 3b3dbdd | 2012-06-13 13:39:34 -0700 | [diff] [blame] | 84 | struct CallInfo { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 85 | int num_arg_words; // Note: word count, not arg count. |
| 86 | RegLocation* args; // One for each word of arguments. |
| 87 | RegLocation result; // Eventual target of MOVE_RESULT. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 88 | int opt_flags; |
buzbee | 15bf980 | 2012-06-12 17:49:27 -0700 | [diff] [blame] | 89 | InvokeType type; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 90 | uint32_t dex_idx; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 91 | uint32_t index; // Method idx for invokes, type idx for FilledNewArray. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 92 | uintptr_t direct_code; |
| 93 | uintptr_t direct_method; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 94 | RegLocation target; // Target of following move_result. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 95 | bool skip_this; |
| 96 | bool is_range; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 97 | int offset; // Dalvik offset. |
buzbee | 15bf980 | 2012-06-12 17:49:27 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 100 | /* |
| 101 | * Data structure tracking the mapping between a Dalvik register (pair) and a |
| 102 | * native register (pair). The idea is to reuse the previously loaded value |
| 103 | * if possible, otherwise to keep the value in a native register as long as |
| 104 | * possible. |
| 105 | */ |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 106 | struct RegisterInfo { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 107 | int reg; // Reg number |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 108 | bool in_use; // Has it been allocated? |
| 109 | bool is_temp; // Can allocate as temp? |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 110 | bool pair; // Part of a register pair? |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 111 | int partner; // If pair, other reg of pair. |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 112 | bool live; // Is there an associated SSA name? |
| 113 | bool dirty; // If live, is it dirty? |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 114 | int s_reg; // Name of live value. |
| 115 | LIR *def_start; // Starting inst in last def sequence. |
| 116 | LIR *def_end; // Ending inst in last def sequence. |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 117 | }; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 118 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 119 | struct RegisterPool { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 120 | int num_core_regs; |
| 121 | RegisterInfo *core_regs; |
| 122 | int next_core_reg; |
| 123 | int num_fp_regs; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 124 | RegisterInfo *FPRegs; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 125 | int next_fp_reg; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 126 | }; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 127 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 128 | #define INVALID_SREG (-1) |
buzbee | 3ddc0d1 | 2011-10-05 10:36:21 -0700 | [diff] [blame] | 129 | #define INVALID_VREG (0xFFFFU) |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 130 | #define INVALID_REG (0xFF) |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame] | 131 | #define INVALID_OFFSET (0xDEADF00FU) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 132 | |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 133 | /* SSA encodings for special registers */ |
buzbee | 9c044ce | 2012-03-18 13:24:07 -0700 | [diff] [blame] | 134 | #define SSA_METHOD_BASEREG (-2) |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 135 | /* First compiler temp basereg, grows smaller */ |
buzbee | 9c044ce | 2012-03-18 13:24:07 -0700 | [diff] [blame] | 136 | #define SSA_CTEMP_BASEREG (SSA_METHOD_BASEREG - 1) |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 137 | |
buzbee | 99ba964 | 2012-01-25 14:23:14 -0800 | [diff] [blame] | 138 | /* |
| 139 | * Some code patterns cause the generation of excessively large |
| 140 | * methods - in particular initialization sequences. There isn't much |
| 141 | * benefit in optimizing these methods, and the cost can be very high. |
| 142 | * We attempt to identify these cases, and avoid performing most dataflow |
| 143 | * analysis. Two thresholds are used - one for known initializers and one |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 144 | * for everything else. |
buzbee | 99ba964 | 2012-01-25 14:23:14 -0800 | [diff] [blame] | 145 | */ |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 146 | #define MANY_BLOCKS_INITIALIZER 1000 /* Threshold for switching dataflow off */ |
| 147 | #define MANY_BLOCKS 4000 /* Non-initializer threshold */ |
buzbee | 99ba964 | 2012-01-25 14:23:14 -0800 | [diff] [blame] | 148 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 149 | // Utility macros to traverse the LIR list. |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 150 | #define NEXT_LIR(lir) (lir->next) |
| 151 | #define PREV_LIR(lir) (lir->prev) |
| 152 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 153 | // Defines for alias_info (tracks Dalvik register references). |
buzbee | ec13743 | 2012-11-13 12:13:16 -0800 | [diff] [blame] | 154 | #define DECODE_ALIAS_INFO_REG(X) (X & 0xffff) |
| 155 | #define DECODE_ALIAS_INFO_WIDE_FLAG (0x80000000) |
| 156 | #define DECODE_ALIAS_INFO_WIDE(X) ((X & DECODE_ALIAS_INFO_WIDE_FLAG) ? 1 : 0) |
| 157 | #define ENCODE_ALIAS_INFO(REG, ISWIDE) (REG | (ISWIDE ? DECODE_ALIAS_INFO_WIDE_FLAG : 0)) |
| 158 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 159 | // Common resource macros. |
buzbee | ec13743 | 2012-11-13 12:13:16 -0800 | [diff] [blame] | 160 | #define ENCODE_CCODE (1ULL << kCCode) |
| 161 | #define ENCODE_FP_STATUS (1ULL << kFPStatus) |
| 162 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 163 | // Abstract memory locations. |
buzbee | ec13743 | 2012-11-13 12:13:16 -0800 | [diff] [blame] | 164 | #define ENCODE_DALVIK_REG (1ULL << kDalvikReg) |
| 165 | #define ENCODE_LITERAL (1ULL << kLiteral) |
| 166 | #define ENCODE_HEAP_REF (1ULL << kHeapRef) |
| 167 | #define ENCODE_MUST_NOT_ALIAS (1ULL << kMustNotAlias) |
| 168 | |
| 169 | #define ENCODE_ALL (~0ULL) |
| 170 | #define ENCODE_MEM (ENCODE_DALVIK_REG | ENCODE_LITERAL | \ |
| 171 | ENCODE_HEAP_REF | ENCODE_MUST_NOT_ALIAS) |
| 172 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 173 | #define is_pseudo_opcode(opcode) (static_cast<int>(opcode) < 0) |
buzbee | 1bc37c6 | 2012-11-20 13:35:41 -0800 | [diff] [blame] | 174 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 175 | struct LIR { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 176 | int offset; // Offset of this instruction. |
| 177 | int dalvik_offset; // Offset of Dalvik opcode. |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 178 | LIR* next; |
| 179 | LIR* prev; |
| 180 | LIR* target; |
| 181 | int opcode; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 182 | int operands[5]; // [0..4] = [dest, src1, src2, extra, extra2]. |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 183 | struct { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 184 | bool is_nop:1; // LIR is optimized away. |
| 185 | bool pcRelFixup:1; // May need pc-relative fixup. |
| 186 | unsigned int size:5; // Note: size is in bytes. |
buzbee | f5f5a12 | 2012-09-21 13:57:36 -0700 | [diff] [blame] | 187 | unsigned int unused:25; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 188 | } flags; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 189 | int alias_info; // For Dalvik register & litpool disambiguation. |
| 190 | uint64_t use_mask; // Resource mask for use. |
| 191 | uint64_t def_mask; // Resource mask for def. |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 192 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 193 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 194 | extern const char* extended_mir_op_names[kMirOpLast - kMirOpFirst]; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 195 | |
| 196 | struct SSARepresentation; |
| 197 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 198 | #define MIR_IGNORE_NULL_CHECK (1 << kMIRIgnoreNullCheck) |
| 199 | #define MIR_NULL_CHECK_ONLY (1 << kMIRNullCheckOnly) |
| 200 | #define MIR_IGNORE_RANGE_CHECK (1 << kMIRIgnoreRangeCheck) |
| 201 | #define MIR_RANGE_CHECK_ONLY (1 << kMIRRangeCheckOnly) |
| 202 | #define MIR_INLINED (1 << kMIRInlined) |
| 203 | #define MIR_INLINED_PRED (1 << kMIRInlinedPred) |
| 204 | #define MIR_CALLEE (1 << kMIRCallee) |
buzbee | c1f4504 | 2011-09-21 16:03:19 -0700 | [diff] [blame] | 205 | #define MIR_IGNORE_SUSPEND_CHECK (1 << kMIRIgnoreSuspendCheck) |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 206 | #define MIR_DUP (1 << kMIRDup) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 207 | |
buzbee | d1643e4 | 2012-09-05 14:06:51 -0700 | [diff] [blame] | 208 | struct Checkstats { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 209 | int null_checks; |
| 210 | int null_checks_eliminated; |
| 211 | int range_checks; |
| 212 | int range_checks_eliminated; |
buzbee | d1643e4 | 2012-09-05 14:06:51 -0700 | [diff] [blame] | 213 | }; |
| 214 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 215 | struct MIR { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 216 | DecodedInstruction dalvikInsn; |
| 217 | unsigned int width; |
| 218 | unsigned int offset; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 219 | int m_unit_index; // From which method was this MIR included |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 220 | MIR* prev; |
| 221 | MIR* next; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 222 | SSARepresentation* ssa_rep; |
| 223 | int optimization_flags; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 224 | union { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 225 | // Establish link between two halves of throwing instructions. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 226 | MIR* throw_insn; |
buzbee | a169e1d | 2012-12-05 14:26:44 -0800 | [diff] [blame] | 227 | // Saved opcode for NOP'd MIRs |
| 228 | Instruction::Code original_opcode; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 229 | } meta; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 230 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 231 | |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 232 | struct BasicBlockDataFlow { |
| 233 | ArenaBitVector* use_v; |
| 234 | ArenaBitVector* def_v; |
| 235 | ArenaBitVector* live_in_v; |
| 236 | ArenaBitVector* phi_v; |
| 237 | int* vreg_to_ssa_map; |
| 238 | ArenaBitVector* ending_null_check_v; |
| 239 | }; |
| 240 | |
| 241 | struct SSARepresentation { |
| 242 | int num_uses; |
| 243 | int* uses; |
| 244 | bool* fp_use; |
| 245 | int num_defs; |
| 246 | int* defs; |
| 247 | bool* fp_def; |
| 248 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 249 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 250 | struct BasicBlock { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 251 | int id; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 252 | int dfs_id; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 253 | bool visited; |
| 254 | bool hidden; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 255 | bool catch_entry; |
| 256 | bool explicit_throw; |
| 257 | bool conditional_branch; |
buzbee | bbdd053 | 2013-02-07 09:33:02 -0800 | [diff] [blame] | 258 | bool terminated_by_return; // Block ends with a Dalvik return opcode. |
| 259 | bool dominates_return; // Is a member of return extended basic block. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 260 | uint16_t start_offset; |
| 261 | uint16_t nesting_depth; |
| 262 | BBType block_type; |
| 263 | MIR* first_mir_insn; |
| 264 | MIR* last_mir_insn; |
| 265 | BasicBlock* fall_through; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 266 | BasicBlock* taken; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 267 | BasicBlock* i_dom; // Immediate dominator. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 268 | BasicBlockDataFlow* data_flow_info; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 269 | GrowableList* predecessors; |
| 270 | ArenaBitVector* dominators; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 271 | ArenaBitVector* i_dominated; // Set nodes being immediately dominated. |
| 272 | ArenaBitVector* dom_frontier; // Dominance frontier. |
| 273 | struct { // For one-to-many successors like. |
| 274 | BlockListType block_list_type; // switch and exception handling. |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 275 | GrowableList blocks; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 276 | } successor_block_list; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 277 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 278 | |
| 279 | /* |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 280 | * The "blocks" field in "successor_block_list" points to an array of |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 281 | * elements with the type "SuccessorBlockInfo". |
| 282 | * For catch blocks, key is type index for the exception. |
| 283 | * For swtich blocks, key is the case value. |
| 284 | */ |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 285 | struct SuccessorBlockInfo { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 286 | BasicBlock* block; |
| 287 | int key; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 288 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 289 | |
| 290 | struct LoopAnalysis; |
| 291 | struct RegisterPool; |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 292 | struct ArenaMemBlock; |
| 293 | struct Memstats; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 294 | class MIRGraph; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 295 | class Codegen; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 296 | |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 297 | #define NOTVISITED (-1) |
| 298 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 299 | struct CompilationUnit { |
Elliott Hughes | e52e49b | 2012-04-02 16:05:44 -0700 | [diff] [blame] | 300 | CompilationUnit() |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 301 | : compiler_driver(NULL), |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 302 | class_linker(NULL), |
| 303 | dex_file(NULL), |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 304 | class_loader(NULL), |
Ian Rogers | fffdb02 | 2013-01-04 15:14:08 -0800 | [diff] [blame] | 305 | class_def_idx(0), |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 306 | method_idx(0), |
| 307 | code_item(NULL), |
| 308 | access_flags(0), |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 309 | invoke_type(kDirect), |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 310 | shorty(NULL), |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 311 | disable_opt(0), |
| 312 | enable_debug(0), |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 313 | verbose(false), |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 314 | gen_bitcode(false), |
| 315 | disable_dataflow(false), |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 316 | instruction_set(kNone), |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 317 | num_dalvik_registers(0), |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 318 | insns(NULL), |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 319 | num_ins(0), |
| 320 | num_outs(0), |
| 321 | num_regs(0), |
| 322 | num_core_spills(0), |
| 323 | num_fp_spills(0), |
| 324 | num_compiler_temps(0), |
| 325 | frame_size(0), |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 326 | core_spill_mask(0), |
| 327 | fp_spill_mask(0), |
| 328 | attributes(0), |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 329 | compiler_flip_match(false), |
| 330 | arena_head(NULL), |
| 331 | current_arena(NULL), |
| 332 | num_arena_blocks(0), |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 333 | mstats(NULL), |
buzbee | d1643e4 | 2012-09-05 14:06:51 -0700 | [diff] [blame] | 334 | checkstats(NULL), |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 335 | mir_graph(NULL), |
| 336 | cg(NULL), |
| 337 | live_sreg(0), |
Ian Rogers | fffdb02 | 2013-01-04 15:14:08 -0800 | [diff] [blame] | 338 | llvm_info(NULL), |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 339 | context(NULL), |
| 340 | module(NULL), |
| 341 | func(NULL), |
| 342 | intrinsic_helper(NULL), |
| 343 | irb(NULL), |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 344 | placeholder_bb(NULL), |
| 345 | entry_bb(NULL), |
| 346 | entryTarget_bb(NULL), |
| 347 | temp_name(0), |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 348 | first_lir_insn(NULL), |
| 349 | last_lir_insn(NULL), |
| 350 | literal_list(NULL), |
| 351 | method_literal_list(NULL), |
| 352 | code_literal_list(NULL), |
| 353 | data_offset(0), |
| 354 | total_size(0), |
| 355 | reg_pool(NULL), |
| 356 | reg_location(NULL), |
| 357 | promotion_map(NULL), |
| 358 | method_sreg(0), |
| 359 | block_label_list(NULL), |
| 360 | current_dalvik_offset(0) |
| 361 | {} |
| 362 | /* |
| 363 | * Fields needed/generated by common frontend and generally used throughout |
| 364 | * the compiler. |
| 365 | */ |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame] | 366 | CompilerDriver* compiler_driver; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 367 | ClassLinker* class_linker; // Linker to resolve fields and methods. |
| 368 | const DexFile* dex_file; // DexFile containing the method being compiled. |
| 369 | jobject class_loader; // compiling method's class loader. |
Ian Rogers | fffdb02 | 2013-01-04 15:14:08 -0800 | [diff] [blame] | 370 | uint32_t class_def_idx; // compiling method's defining class definition index. |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 371 | uint32_t method_idx; // compiling method's index into method_ids of DexFile. |
| 372 | const DexFile::CodeItem* code_item; // compiling method's DexFile code_item. |
| 373 | uint32_t access_flags; // compiling method's access flags. |
| 374 | InvokeType invoke_type; // compiling method's invocation type. |
| 375 | const char* shorty; // compiling method's shorty. |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 376 | uint32_t disable_opt; // opt_control_vector flags. |
| 377 | uint32_t enable_debug; // debugControlVector flags. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 378 | std::vector<uint8_t> code_buffer; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 379 | bool verbose; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 380 | std::vector<uint32_t> combined_mapping_table; |
| 381 | std::vector<uint32_t> core_vmap_table; |
| 382 | std::vector<uint32_t> fp_vmap_table; |
| 383 | std::vector<uint8_t> native_gc_map; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 384 | bool gen_bitcode; |
| 385 | bool disable_dataflow; // Skip dataflow analysis if possible |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 386 | InstructionSet instruction_set; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 387 | |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 388 | // CLEANUP: much of this info available elsewhere. Go to the original source? |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 389 | int num_dalvik_registers; // method->registers_size. |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 390 | const uint16_t* insns; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 391 | /* |
| 392 | * Frame layout details. |
| 393 | * NOTE: for debug support it will be necessary to add a structure |
| 394 | * to map the Dalvik virtual registers to the promoted registers. |
| 395 | * NOTE: "num" fields are in 4-byte words, "Size" and "Offset" in bytes. |
| 396 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 397 | int num_ins; |
| 398 | int num_outs; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 399 | int num_regs; // Unlike num_dalvik_registers, does not include ins. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 400 | int num_core_spills; |
| 401 | int num_fp_spills; |
| 402 | int num_compiler_temps; |
| 403 | int frame_size; |
| 404 | unsigned int core_spill_mask; |
| 405 | unsigned int fp_spill_mask; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 406 | unsigned int attributes; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 407 | // If non-empty, apply optimizer/debug flags only to matching methods. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 408 | std::string compiler_method_match; |
| 409 | // Flips sense of compiler_method_match - apply flags if doesn't match. |
| 410 | bool compiler_flip_match; |
| 411 | ArenaMemBlock* arena_head; |
| 412 | ArenaMemBlock* current_arena; |
| 413 | int num_arena_blocks; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 414 | Memstats* mstats; |
buzbee | d1643e4 | 2012-09-05 14:06:51 -0700 | [diff] [blame] | 415 | Checkstats* checkstats; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 416 | UniquePtr<MIRGraph> mir_graph; // MIR container. |
| 417 | UniquePtr<Codegen> cg; // Target-specific codegen. |
| 418 | /* |
| 419 | * Sanity checking for the register temp tracking. The same ssa |
| 420 | * name should never be associated with one temp register per |
| 421 | * instruction compilation. |
| 422 | */ |
| 423 | int live_sreg; |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 424 | |
| 425 | // Fields for Portable |
| 426 | llvm::LlvmCompilationUnit* llvm_compilation_unit; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 427 | /* |
| 428 | * Fields needed by GBC creation. Candidates for moving to a new MIR to |
| 429 | * llvm bitcode class. |
| 430 | */ |
buzbee | 4df2bbd | 2012-10-11 14:46:06 -0700 | [diff] [blame] | 431 | LLVMInfo* llvm_info; |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 432 | std::string symbol; |
Ian Rogers | 4c1c283 | 2013-03-04 18:30:13 -0800 | [diff] [blame] | 433 | ::llvm::LLVMContext* context; |
| 434 | ::llvm::Module* module; |
| 435 | ::llvm::Function* func; |
| 436 | art::llvm::IntrinsicHelper* intrinsic_helper; |
| 437 | art::llvm::IRBuilder* irb; |
| 438 | ::llvm::BasicBlock* placeholder_bb; |
| 439 | ::llvm::BasicBlock* entry_bb; |
| 440 | ::llvm::BasicBlock* entryTarget_bb; |
Brian Carlstrom | 265091e | 2013-01-30 14:08:26 -0800 | [diff] [blame] | 441 | |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 442 | std::string bitcode_filename; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 443 | GrowableList llvm_values; |
| 444 | int32_t temp_name; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 445 | SafeMap<int32_t, ::llvm::BasicBlock*> id_to_block_map; // block id -> llvm bb. |
| 446 | |
| 447 | /* |
| 448 | * Fields needed by the Quick backend. Candidates for moving to a new |
| 449 | * QuickBackend class. |
| 450 | */ |
| 451 | LIR* first_lir_insn; |
| 452 | LIR* last_lir_insn; |
| 453 | LIR* literal_list; // Constants. |
| 454 | LIR* method_literal_list; // Method literals requiring patching. |
| 455 | LIR* code_literal_list; // Code literals requiring patching. |
| 456 | int data_offset; // starting offset of literal pool. |
| 457 | int total_size; // header + code size. |
| 458 | RegisterPool* reg_pool; |
| 459 | // Map SSA names to location. |
| 460 | RegLocation* reg_location; |
| 461 | // Keep track of Dalvik v_reg to physical register mappings. |
| 462 | PromotionMap* promotion_map; |
| 463 | // SSA name for Method*. |
| 464 | int method_sreg; |
| 465 | RegLocation method_loc; // Describes location of method*. |
| 466 | GrowableList throw_launchpads; |
| 467 | GrowableList suspend_launchpads; |
| 468 | GrowableList intrinsic_launchpads; |
| 469 | GrowableList compiler_temps; |
| 470 | LIR* block_label_list; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 471 | /* |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 472 | * TODO: The code generation utilities don't have a built-in |
| 473 | * mechanism to propagate the original Dalvik opcode address to the |
| 474 | * associated generated instructions. For the trace compiler, this wasn't |
| 475 | * necessary because the interpreter handled all throws and debugging |
| 476 | * requests. For now we'll handle this by placing the Dalvik offset |
| 477 | * in the CompilationUnit struct before codegen for each instruction. |
| 478 | * The low-level LIR creation utilites will pull it from here. Rework this. |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 479 | */ |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 480 | int current_dalvik_offset; |
| 481 | GrowableList switch_tables; |
| 482 | GrowableList fill_array_data; |
| 483 | SafeMap<unsigned int, unsigned int> block_id_map; // Block collapse lookup cache. |
| 484 | SafeMap<unsigned int, LIR*> boundary_map; // boundary lookup cache. |
| 485 | /* |
| 486 | * Holds mapping from native PC to dex PC for safepoints where we may deoptimize. |
| 487 | * Native PC is on the return address of the safepointed operation. Dex PC is for |
| 488 | * the instruction being executed at the safepoint. |
| 489 | */ |
| 490 | std::vector<uint32_t> pc2dexMappingTable; |
| 491 | /* |
| 492 | * Holds mapping from Dex PC to native PC for catch entry points. Native PC and Dex PC |
| 493 | * immediately preceed the instruction. |
| 494 | */ |
| 495 | std::vector<uint32_t> dex2pcMappingTable; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 496 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 497 | |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 498 | // TODO: move this |
| 499 | int SRegToVReg(const CompilationUnit* cu, int ssa_reg); |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 500 | |
buzbee | 4ef3e45 | 2012-12-14 13:35:28 -0800 | [diff] [blame] | 501 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 502 | } // namespace art |
| 503 | |
buzbee | 395116c | 2013-02-27 14:30:25 -0800 | [diff] [blame] | 504 | #endif // ART_SRC_COMPILER_DEX_COMPILER_IR_H_ |