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> |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 21 | #include "dex_instruction.h" |
| 22 | #include "compiler.h" |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 23 | #include "compiler_utility.h" |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 24 | #include "oat_compilation_unit.h" |
Elliott Hughes | a0e1806 | 2012-04-13 15:59:59 -0700 | [diff] [blame] | 25 | #include "safe_map.h" |
Ian Rogers | 76ae4fe | 2013-02-27 16:03:41 -0800 | [diff] [blame] | 26 | #include "compiler_llvm/ir_builder.h" |
| 27 | #include "compiler_llvm/intrinsic_helper.h" |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 28 | #include "llvm/Module.h" |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 29 | #include "compiler_enums.h" |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 30 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 31 | namespace art { |
| 32 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 33 | #define SLOW_FIELD_PATH (cu->enable_debug & (1 << kDebugSlowFieldPath)) |
| 34 | #define SLOW_INVOKE_PATH (cu->enable_debug & (1 << kDebugSlowInvokePath)) |
| 35 | #define SLOW_STRING_PATH (cu->enable_debug & (1 << kDebugSlowStringPath)) |
| 36 | #define SLOW_TYPE_PATH (cu->enable_debug & (1 << kDebugSlowTypePath)) |
| 37 | #define EXERCISE_SLOWEST_STRING_PATH (cu->enable_debug & \ |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 38 | (1 << kDebugSlowestStringPath)) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 39 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 40 | // Minimum field size to contain Dalvik v_reg number. |
buzbee | ca7a5e4 | 2012-08-20 11:12:18 -0700 | [diff] [blame] | 41 | #define VREG_NUM_WIDTH 16 |
| 42 | |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 43 | struct ArenaBitVector; |
| 44 | struct LIR; |
| 45 | class LLVMInfo; |
| 46 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 47 | struct PromotionMap { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 48 | RegLocationType core_location:3; |
| 49 | uint8_t core_reg; |
| 50 | RegLocationType fp_location:3; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 51 | uint8_t FpReg; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 52 | bool first_in_pair; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 53 | }; |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 54 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 55 | struct RegLocation { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 56 | RegLocationType location:3; |
| 57 | unsigned wide:1; |
| 58 | unsigned defined:1; // Do we know the type? |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 59 | unsigned is_const:1; // Constant, value in cu->constant_values[]. |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 60 | unsigned fp:1; // Floating point? |
| 61 | unsigned core:1; // Non-floating point? |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 62 | unsigned ref:1; // Something GC cares about. |
| 63 | unsigned high_word:1; // High word of pair? |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 64 | unsigned home:1; // Does this represent the home location? |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 65 | uint8_t low_reg; // First physical register. |
| 66 | uint8_t high_reg; // 2nd physical register (if wide). |
| 67 | int32_t s_reg_low; // SSA name for low Dalvik word. |
| 68 | int32_t orig_sreg; // TODO: remove after Bitcode gen complete |
| 69 | // and consolodate usage w/ s_reg_low. |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | struct CompilerTemp { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 73 | int s_reg; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 74 | ArenaBitVector* bv; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 75 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 76 | |
buzbee | 3b3dbdd | 2012-06-13 13:39:34 -0700 | [diff] [blame] | 77 | struct CallInfo { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 78 | int num_arg_words; // Note: word count, not arg count. |
| 79 | RegLocation* args; // One for each word of arguments. |
| 80 | RegLocation result; // Eventual target of MOVE_RESULT. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 81 | int opt_flags; |
buzbee | 15bf980 | 2012-06-12 17:49:27 -0700 | [diff] [blame] | 82 | InvokeType type; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 83 | uint32_t dex_idx; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 84 | uint32_t index; // Method idx for invokes, type idx for FilledNewArray. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 85 | uintptr_t direct_code; |
| 86 | uintptr_t direct_method; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 87 | RegLocation target; // Target of following move_result. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 88 | bool skip_this; |
| 89 | bool is_range; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 90 | int offset; // Dalvik offset. |
buzbee | 15bf980 | 2012-06-12 17:49:27 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 93 | /* |
| 94 | * Data structure tracking the mapping between a Dalvik register (pair) and a |
| 95 | * native register (pair). The idea is to reuse the previously loaded value |
| 96 | * if possible, otherwise to keep the value in a native register as long as |
| 97 | * possible. |
| 98 | */ |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 99 | struct RegisterInfo { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 100 | int reg; // Reg number |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 101 | bool in_use; // Has it been allocated? |
| 102 | bool is_temp; // Can allocate as temp? |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 103 | bool pair; // Part of a register pair? |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 104 | int partner; // If pair, other reg of pair. |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 105 | bool live; // Is there an associated SSA name? |
| 106 | bool dirty; // If live, is it dirty? |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 107 | int s_reg; // Name of live value. |
| 108 | LIR *def_start; // Starting inst in last def sequence. |
| 109 | LIR *def_end; // Ending inst in last def sequence. |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 110 | }; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 111 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 112 | struct RegisterPool { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 113 | int num_core_regs; |
| 114 | RegisterInfo *core_regs; |
| 115 | int next_core_reg; |
| 116 | int num_fp_regs; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 117 | RegisterInfo *FPRegs; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 118 | int next_fp_reg; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 119 | }; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 120 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 121 | #define INVALID_SREG (-1) |
buzbee | 3ddc0d1 | 2011-10-05 10:36:21 -0700 | [diff] [blame] | 122 | #define INVALID_VREG (0xFFFFU) |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 123 | #define INVALID_REG (0xFF) |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame] | 124 | #define INVALID_OFFSET (0xDEADF00FU) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 125 | |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 126 | /* SSA encodings for special registers */ |
buzbee | 9c044ce | 2012-03-18 13:24:07 -0700 | [diff] [blame] | 127 | #define SSA_METHOD_BASEREG (-2) |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 128 | /* First compiler temp basereg, grows smaller */ |
buzbee | 9c044ce | 2012-03-18 13:24:07 -0700 | [diff] [blame] | 129 | #define SSA_CTEMP_BASEREG (SSA_METHOD_BASEREG - 1) |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 130 | |
buzbee | 99ba964 | 2012-01-25 14:23:14 -0800 | [diff] [blame] | 131 | /* |
| 132 | * Some code patterns cause the generation of excessively large |
| 133 | * methods - in particular initialization sequences. There isn't much |
| 134 | * benefit in optimizing these methods, and the cost can be very high. |
| 135 | * We attempt to identify these cases, and avoid performing most dataflow |
| 136 | * analysis. Two thresholds are used - one for known initializers and one |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 137 | * for everything else. |
buzbee | 99ba964 | 2012-01-25 14:23:14 -0800 | [diff] [blame] | 138 | */ |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 139 | #define MANY_BLOCKS_INITIALIZER 1000 /* Threshold for switching dataflow off */ |
| 140 | #define MANY_BLOCKS 4000 /* Non-initializer threshold */ |
buzbee | 99ba964 | 2012-01-25 14:23:14 -0800 | [diff] [blame] | 141 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 142 | // Utility macros to traverse the LIR list. |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 143 | #define NEXT_LIR(lir) (lir->next) |
| 144 | #define PREV_LIR(lir) (lir->prev) |
| 145 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 146 | // Defines for alias_info (tracks Dalvik register references). |
buzbee | ec13743 | 2012-11-13 12:13:16 -0800 | [diff] [blame] | 147 | #define DECODE_ALIAS_INFO_REG(X) (X & 0xffff) |
| 148 | #define DECODE_ALIAS_INFO_WIDE_FLAG (0x80000000) |
| 149 | #define DECODE_ALIAS_INFO_WIDE(X) ((X & DECODE_ALIAS_INFO_WIDE_FLAG) ? 1 : 0) |
| 150 | #define ENCODE_ALIAS_INFO(REG, ISWIDE) (REG | (ISWIDE ? DECODE_ALIAS_INFO_WIDE_FLAG : 0)) |
| 151 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 152 | // Common resource macros. |
buzbee | ec13743 | 2012-11-13 12:13:16 -0800 | [diff] [blame] | 153 | #define ENCODE_CCODE (1ULL << kCCode) |
| 154 | #define ENCODE_FP_STATUS (1ULL << kFPStatus) |
| 155 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 156 | // Abstract memory locations. |
buzbee | ec13743 | 2012-11-13 12:13:16 -0800 | [diff] [blame] | 157 | #define ENCODE_DALVIK_REG (1ULL << kDalvikReg) |
| 158 | #define ENCODE_LITERAL (1ULL << kLiteral) |
| 159 | #define ENCODE_HEAP_REF (1ULL << kHeapRef) |
| 160 | #define ENCODE_MUST_NOT_ALIAS (1ULL << kMustNotAlias) |
| 161 | |
| 162 | #define ENCODE_ALL (~0ULL) |
| 163 | #define ENCODE_MEM (ENCODE_DALVIK_REG | ENCODE_LITERAL | \ |
| 164 | ENCODE_HEAP_REF | ENCODE_MUST_NOT_ALIAS) |
| 165 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 166 | #define is_pseudo_opcode(opcode) (static_cast<int>(opcode) < 0) |
buzbee | 1bc37c6 | 2012-11-20 13:35:41 -0800 | [diff] [blame] | 167 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 168 | struct LIR { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 169 | int offset; // Offset of this instruction. |
| 170 | int dalvik_offset; // Offset of Dalvik opcode. |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 171 | LIR* next; |
| 172 | LIR* prev; |
| 173 | LIR* target; |
| 174 | int opcode; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 175 | int operands[5]; // [0..4] = [dest, src1, src2, extra, extra2]. |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 176 | struct { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 177 | bool is_nop:1; // LIR is optimized away. |
| 178 | bool pcRelFixup:1; // May need pc-relative fixup. |
| 179 | unsigned int size:5; // Note: size is in bytes. |
buzbee | f5f5a12 | 2012-09-21 13:57:36 -0700 | [diff] [blame] | 180 | unsigned int unused:25; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 181 | } flags; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 182 | int alias_info; // For Dalvik register & litpool disambiguation. |
| 183 | uint64_t use_mask; // Resource mask for use. |
| 184 | uint64_t def_mask; // Resource mask for def. |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 185 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 186 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 187 | extern const char* extended_mir_op_names[kMirOpLast - kMirOpFirst]; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 188 | |
| 189 | struct SSARepresentation; |
| 190 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 191 | #define MIR_IGNORE_NULL_CHECK (1 << kMIRIgnoreNullCheck) |
| 192 | #define MIR_NULL_CHECK_ONLY (1 << kMIRNullCheckOnly) |
| 193 | #define MIR_IGNORE_RANGE_CHECK (1 << kMIRIgnoreRangeCheck) |
| 194 | #define MIR_RANGE_CHECK_ONLY (1 << kMIRRangeCheckOnly) |
| 195 | #define MIR_INLINED (1 << kMIRInlined) |
| 196 | #define MIR_INLINED_PRED (1 << kMIRInlinedPred) |
| 197 | #define MIR_CALLEE (1 << kMIRCallee) |
buzbee | c1f4504 | 2011-09-21 16:03:19 -0700 | [diff] [blame] | 198 | #define MIR_IGNORE_SUSPEND_CHECK (1 << kMIRIgnoreSuspendCheck) |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 199 | #define MIR_DUP (1 << kMIRDup) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 200 | |
buzbee | d1643e4 | 2012-09-05 14:06:51 -0700 | [diff] [blame] | 201 | struct Checkstats { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 202 | int null_checks; |
| 203 | int null_checks_eliminated; |
| 204 | int range_checks; |
| 205 | int range_checks_eliminated; |
buzbee | d1643e4 | 2012-09-05 14:06:51 -0700 | [diff] [blame] | 206 | }; |
| 207 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 208 | struct MIR { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 209 | DecodedInstruction dalvikInsn; |
| 210 | unsigned int width; |
| 211 | unsigned int offset; |
| 212 | MIR* prev; |
| 213 | MIR* next; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 214 | SSARepresentation* ssa_rep; |
| 215 | int optimization_flags; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 216 | union { |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 217 | // Establish link between two halves of throwing instructions. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 218 | MIR* throw_insn; |
buzbee | a169e1d | 2012-12-05 14:26:44 -0800 | [diff] [blame] | 219 | // Saved opcode for NOP'd MIRs |
| 220 | Instruction::Code original_opcode; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 221 | } meta; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 222 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 223 | |
| 224 | struct BasicBlockDataFlow; |
| 225 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 226 | struct BasicBlock { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 227 | int id; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 228 | int dfs_id; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 229 | bool visited; |
| 230 | bool hidden; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 231 | bool catch_entry; |
| 232 | bool explicit_throw; |
| 233 | bool conditional_branch; |
buzbee | bbdd053 | 2013-02-07 09:33:02 -0800 | [diff] [blame] | 234 | bool terminated_by_return; // Block ends with a Dalvik return opcode. |
| 235 | bool dominates_return; // Is a member of return extended basic block. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 236 | uint16_t start_offset; |
| 237 | uint16_t nesting_depth; |
| 238 | BBType block_type; |
| 239 | MIR* first_mir_insn; |
| 240 | MIR* last_mir_insn; |
| 241 | BasicBlock* fall_through; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 242 | BasicBlock* taken; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 243 | BasicBlock* i_dom; // Immediate dominator. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 244 | BasicBlockDataFlow* data_flow_info; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 245 | GrowableList* predecessors; |
| 246 | ArenaBitVector* dominators; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 247 | ArenaBitVector* i_dominated; // Set nodes being immediately dominated. |
| 248 | ArenaBitVector* dom_frontier; // Dominance frontier. |
| 249 | struct { // For one-to-many successors like. |
| 250 | BlockListType block_list_type; // switch and exception handling. |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 251 | GrowableList blocks; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 252 | } successor_block_list; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 253 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 254 | |
| 255 | /* |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 256 | * The "blocks" field in "successor_block_list" points to an array of |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 257 | * elements with the type "SuccessorBlockInfo". |
| 258 | * For catch blocks, key is type index for the exception. |
| 259 | * For swtich blocks, key is the case value. |
| 260 | */ |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 261 | struct SuccessorBlockInfo { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 262 | BasicBlock* block; |
| 263 | int key; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 264 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 265 | |
| 266 | struct LoopAnalysis; |
| 267 | struct RegisterPool; |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 268 | struct ArenaMemBlock; |
| 269 | struct Memstats; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 270 | class Codegen; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 271 | |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 272 | #define NOTVISITED (-1) |
| 273 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 274 | struct CompilationUnit { |
Elliott Hughes | e52e49b | 2012-04-02 16:05:44 -0700 | [diff] [blame] | 275 | CompilationUnit() |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 276 | : num_blocks(0), |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 277 | compiler(NULL), |
| 278 | class_linker(NULL), |
| 279 | dex_file(NULL), |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 280 | class_loader(NULL), |
Ian Rogers | fffdb02 | 2013-01-04 15:14:08 -0800 | [diff] [blame] | 281 | class_def_idx(0), |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 282 | method_idx(0), |
| 283 | code_item(NULL), |
| 284 | access_flags(0), |
Ian Rogers | 08f753d | 2012-08-24 14:35:25 -0700 | [diff] [blame] | 285 | invoke_type(kDirect), |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 286 | shorty(NULL), |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 287 | first_lir_insn(NULL), |
| 288 | last_lir_insn(NULL), |
| 289 | literal_list(NULL), |
| 290 | method_literal_list(NULL), |
| 291 | code_literal_list(NULL), |
| 292 | disable_opt(0), |
| 293 | enable_debug(0), |
| 294 | data_offset(0), |
| 295 | total_size(0), |
| 296 | assembler_status(kSuccess), |
| 297 | assembler_retries(0), |
| 298 | verbose(false), |
| 299 | has_loop(false), |
| 300 | has_invoke(false), |
| 301 | qd_mode(false), |
| 302 | reg_pool(NULL), |
| 303 | instruction_set(kNone), |
| 304 | num_ssa_regs(0), |
| 305 | ssa_base_vregs(NULL), |
| 306 | ssa_subscripts(NULL), |
| 307 | ssa_strings(NULL), |
| 308 | vreg_to_ssa_map(NULL), |
| 309 | ssa_last_defs(NULL), |
| 310 | is_constant_v(NULL), |
buzbee | 4ef3e45 | 2012-12-14 13:35:28 -0800 | [diff] [blame] | 311 | must_flush_constant_v(NULL), |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 312 | constant_values(NULL), |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 313 | reg_location(NULL), |
| 314 | promotion_map(NULL), |
| 315 | method_sreg(0), |
| 316 | num_reachable_blocks(0), |
| 317 | num_dalvik_registers(0), |
| 318 | entry_block(NULL), |
| 319 | exit_block(NULL), |
| 320 | cur_block(NULL), |
| 321 | i_dom_list(NULL), |
| 322 | try_block_addr(NULL), |
| 323 | def_block_matrix(NULL), |
| 324 | temp_block_v(NULL), |
| 325 | temp_dalvik_register_v(NULL), |
| 326 | temp_ssa_register_v(NULL), |
| 327 | temp_ssa_block_id_v(NULL), |
| 328 | block_label_list(NULL), |
| 329 | num_ins(0), |
| 330 | num_outs(0), |
| 331 | num_regs(0), |
| 332 | num_core_spills(0), |
| 333 | num_fp_spills(0), |
| 334 | num_compiler_temps(0), |
| 335 | frame_size(0), |
| 336 | core_spill_mask(0U), |
| 337 | fp_spill_mask(0U), |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 338 | attrs(0U), |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 339 | current_dalvik_offset(0), |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 340 | insns(NULL), |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 341 | insns_size(0U), |
| 342 | disable_dataflow(false), |
| 343 | def_count(0), |
| 344 | compiler_flip_match(false), |
| 345 | arena_head(NULL), |
| 346 | current_arena(NULL), |
| 347 | num_arena_blocks(0), |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 348 | mstats(NULL), |
buzbee | d1643e4 | 2012-09-05 14:06:51 -0700 | [diff] [blame] | 349 | checkstats(NULL), |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 350 | gen_bitcode(false), |
Ian Rogers | fffdb02 | 2013-01-04 15:14:08 -0800 | [diff] [blame] | 351 | llvm_info(NULL), |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 352 | context(NULL), |
| 353 | module(NULL), |
| 354 | func(NULL), |
| 355 | intrinsic_helper(NULL), |
| 356 | irb(NULL), |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 357 | placeholder_bb(NULL), |
| 358 | entry_bb(NULL), |
| 359 | entryTarget_bb(NULL), |
| 360 | temp_name(0), |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 361 | #ifndef NDEBUG |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 362 | live_sreg(0), |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 363 | #endif |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 364 | opcode_count(NULL), |
| 365 | cg(NULL) {} |
Elliott Hughes | e52e49b | 2012-04-02 16:05:44 -0700 | [diff] [blame] | 366 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 367 | int num_blocks; |
| 368 | GrowableList block_list; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 369 | Compiler* compiler; // Compiler driving this compiler. |
| 370 | ClassLinker* class_linker; // Linker to resolve fields and methods. |
| 371 | const DexFile* dex_file; // DexFile containing the method being compiled. |
| 372 | jobject class_loader; // compiling method's class loader. |
Ian Rogers | fffdb02 | 2013-01-04 15:14:08 -0800 | [diff] [blame] | 373 | uint32_t class_def_idx; // compiling method's defining class definition index. |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 374 | uint32_t method_idx; // compiling method's index into method_ids of DexFile. |
| 375 | const DexFile::CodeItem* code_item; // compiling method's DexFile code_item. |
| 376 | uint32_t access_flags; // compiling method's access flags. |
| 377 | InvokeType invoke_type; // compiling method's invocation type. |
| 378 | const char* shorty; // compiling method's shorty. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 379 | LIR* first_lir_insn; |
| 380 | LIR* last_lir_insn; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 381 | LIR* literal_list; // Constants. |
| 382 | LIR* method_literal_list; // Method literals requiring patching. |
| 383 | LIR* code_literal_list; // Code literals requiring patching. |
| 384 | uint32_t disable_opt; // opt_control_vector flags. |
| 385 | uint32_t enable_debug; // debugControlVector flags. |
| 386 | int data_offset; // starting offset of literal pool. |
| 387 | int total_size; // header + code size. |
| 388 | AssemblerStatus assembler_status; // Success or fix and retry. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 389 | int assembler_retries; |
| 390 | std::vector<uint8_t> code_buffer; |
Bill Buzbee | a5b3024 | 2012-09-28 07:19:44 -0700 | [diff] [blame] | 391 | /* |
| 392 | * Holds mapping from native PC to dex PC for safepoints where we may deoptimize. |
| 393 | * Native PC is on the return address of the safepointed operation. Dex PC is for |
| 394 | * the instruction being executed at the safepoint. |
| 395 | */ |
| 396 | std::vector<uint32_t> pc2dexMappingTable; |
| 397 | /* |
| 398 | * Holds mapping from Dex PC to native PC for catch entry points. Native PC and Dex PC |
| 399 | * immediately preceed the instruction. |
| 400 | */ |
| 401 | std::vector<uint32_t> dex2pcMappingTable; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 402 | std::vector<uint32_t> combined_mapping_table; |
| 403 | std::vector<uint32_t> core_vmap_table; |
| 404 | std::vector<uint32_t> fp_vmap_table; |
| 405 | std::vector<uint8_t> native_gc_map; |
buzbee | 2502e00 | 2012-12-31 16:05:53 -0800 | [diff] [blame] | 406 | std::vector<BasicBlock*> extended_basic_blocks; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 407 | bool verbose; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 408 | bool has_loop; // Contains a loop. |
| 409 | bool has_invoke; // Contains an invoke instruction. |
| 410 | bool qd_mode; // Compile for code size/compile time. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 411 | RegisterPool* reg_pool; |
| 412 | InstructionSet instruction_set; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 413 | // Number of total regs used in the whole cu after SSA transformation . |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 414 | int num_ssa_regs; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 415 | // Map SSA reg i to the base virtual register/subscript. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 416 | GrowableList* ssa_base_vregs; |
| 417 | GrowableList* ssa_subscripts; |
| 418 | GrowableList* ssa_strings; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 419 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 420 | // Map original Dalvik virtual reg i to the current SSA name. |
| 421 | int* vreg_to_ssa_map; // length == method->registers_size |
| 422 | int* ssa_last_defs; // length == method->registers_size |
| 423 | ArenaBitVector* is_constant_v; // length == num_ssa_reg |
buzbee | 4ef3e45 | 2012-12-14 13:35:28 -0800 | [diff] [blame] | 424 | ArenaBitVector* must_flush_constant_v; // length == num_ssa_reg |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 425 | int* constant_values; // length == num_ssa_reg |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 426 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 427 | // Use counts of ssa names. |
| 428 | GrowableList use_counts; // Weighted by nesting depth |
| 429 | GrowableList raw_use_counts; // Not weighted |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame] | 430 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 431 | // Optimization support. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 432 | GrowableList loop_headers; |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame] | 433 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 434 | // Map SSA names to location. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 435 | RegLocation* reg_location; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 436 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 437 | // Keep track of Dalvik v_reg to physical register mappings. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 438 | PromotionMap* promotion_map; |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 439 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 440 | // SSA name for Method*. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 441 | int method_sreg; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 442 | RegLocation method_loc; // Describes location of method*. |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 443 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 444 | int num_reachable_blocks; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 445 | int num_dalvik_registers; // method->registers_size. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 446 | BasicBlock* entry_block; |
| 447 | BasicBlock* exit_block; |
| 448 | BasicBlock* cur_block; |
| 449 | GrowableList dfs_order; |
| 450 | GrowableList dfs_post_order; |
| 451 | GrowableList dom_post_order_traversal; |
| 452 | GrowableList throw_launchpads; |
| 453 | GrowableList suspend_launchpads; |
| 454 | GrowableList intrinsic_launchpads; |
| 455 | GrowableList compiler_temps; |
| 456 | int* i_dom_list; |
| 457 | ArenaBitVector* try_block_addr; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 458 | ArenaBitVector** def_block_matrix; // num_dalvik_register x num_blocks. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 459 | ArenaBitVector* temp_block_v; |
| 460 | ArenaBitVector* temp_dalvik_register_v; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 461 | ArenaBitVector* temp_ssa_register_v; // num_ssa_regs. |
| 462 | int* temp_ssa_block_id_v; // working storage for Phi labels. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 463 | LIR* block_label_list; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 464 | /* |
| 465 | * Frame layout details. |
| 466 | * NOTE: for debug support it will be necessary to add a structure |
| 467 | * to map the Dalvik virtual registers to the promoted registers. |
| 468 | * NOTE: "num" fields are in 4-byte words, "Size" and "Offset" in bytes. |
| 469 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 470 | int num_ins; |
| 471 | int num_outs; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 472 | int num_regs; // Unlike num_dalvik_registers, does not include ins. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 473 | int num_core_spills; |
| 474 | int num_fp_spills; |
| 475 | int num_compiler_temps; |
| 476 | int frame_size; |
| 477 | unsigned int core_spill_mask; |
| 478 | unsigned int fp_spill_mask; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 479 | unsigned int attrs; |
| 480 | /* |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 481 | * TODO: The code generation utilities don't have a built-in |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 482 | * mechanism to propagate the original Dalvik opcode address to the |
| 483 | * associated generated instructions. For the trace compiler, this wasn't |
| 484 | * necessary because the interpreter handled all throws and debugging |
| 485 | * requests. For now we'll handle this by placing the Dalvik offset |
| 486 | * in the CompilationUnit struct before codegen for each instruction. |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 487 | * 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] | 488 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 489 | int current_dalvik_offset; |
| 490 | GrowableList switch_tables; |
| 491 | GrowableList fill_array_data; |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 492 | const uint16_t* insns; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 493 | uint32_t insns_size; |
| 494 | bool disable_dataflow; // Skip dataflow analysis if possible |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 495 | SafeMap<unsigned int, BasicBlock*> block_map; // FindBlock lookup cache. |
| 496 | SafeMap<unsigned int, unsigned int> block_id_map; // Block collapse lookup cache. |
| 497 | SafeMap<unsigned int, LIR*> boundary_map; // boundary lookup cache. |
| 498 | int def_count; // Used to estimate number of SSA names. |
Elliott Hughes | e52e49b | 2012-04-02 16:05:44 -0700 | [diff] [blame] | 499 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 500 | // If non-empty, apply optimizer/debug flags only to matching methods. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 501 | std::string compiler_method_match; |
| 502 | // Flips sense of compiler_method_match - apply flags if doesn't match. |
| 503 | bool compiler_flip_match; |
| 504 | ArenaMemBlock* arena_head; |
| 505 | ArenaMemBlock* current_arena; |
| 506 | int num_arena_blocks; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 507 | Memstats* mstats; |
buzbee | d1643e4 | 2012-09-05 14:06:51 -0700 | [diff] [blame] | 508 | Checkstats* checkstats; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 509 | bool gen_bitcode; |
buzbee | 4df2bbd | 2012-10-11 14:46:06 -0700 | [diff] [blame] | 510 | LLVMInfo* llvm_info; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 511 | llvm::LLVMContext* context; |
| 512 | llvm::Module* module; |
| 513 | llvm::Function* func; |
Ian Rogers | 76ae4fe | 2013-02-27 16:03:41 -0800 | [diff] [blame] | 514 | compiler_llvm::IntrinsicHelper* intrinsic_helper; |
| 515 | compiler_llvm::IRBuilder* irb; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 516 | llvm::BasicBlock* placeholder_bb; |
| 517 | llvm::BasicBlock* entry_bb; |
| 518 | llvm::BasicBlock* entryTarget_bb; |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 519 | std::string bitcode_filename; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 520 | GrowableList llvm_values; |
| 521 | int32_t temp_name; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 522 | SafeMap<llvm::BasicBlock*, LIR*> block_to_label_map; // llvm bb -> LIR label. |
| 523 | SafeMap<int32_t, llvm::BasicBlock*> id_to_block_map; // block id -> llvm bb. |
| 524 | SafeMap<llvm::Value*, RegLocation> loc_map; // llvm Value to loc rec. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 525 | std::set<llvm::BasicBlock*> llvm_blocks; |
buzbee | 3d66194 | 2012-03-14 17:37:27 -0700 | [diff] [blame] | 526 | #ifndef NDEBUG |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 527 | /* |
| 528 | * Sanity checking for the register temp tracking. The same ssa |
| 529 | * name should never be associated with one temp register per |
| 530 | * instruction compilation. |
| 531 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 532 | int live_sreg; |
buzbee | 3d66194 | 2012-03-14 17:37:27 -0700 | [diff] [blame] | 533 | #endif |
buzbee | 6459e7c | 2012-10-02 14:42:41 -0700 | [diff] [blame] | 534 | std::set<uint32_t> catches; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 535 | int* opcode_count; // Count Dalvik opcodes for tuning. |
| 536 | UniquePtr<Codegen> cg; |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 537 | }; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 538 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 539 | struct SwitchTable { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 540 | int offset; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 541 | const uint16_t* table; // Original dex table. |
| 542 | int vaddr; // Dalvik offset of switch opcode. |
| 543 | LIR* anchor; // Reference instruction for relative offsets. |
| 544 | LIR** targets; // Array of case targets. |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 545 | }; |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 546 | |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 547 | struct FillArrayData { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 548 | int offset; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 549 | const uint16_t* table; // Original dex table. |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 550 | int size; |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 551 | int vaddr; // Dalvik offset of FILL_ARRAY_DATA opcode. |
Elliott Hughes | 719ace4 | 2012-03-09 18:06:03 -0800 | [diff] [blame] | 552 | }; |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 553 | |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 554 | #define MAX_PATTERN_LEN 5 |
| 555 | |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 556 | struct CodePattern { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 557 | const Instruction::Code opcodes[MAX_PATTERN_LEN]; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 558 | const SpecialCaseHandler handler_code; |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 559 | }; |
| 560 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 561 | static const CodePattern special_patterns[] = { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 562 | {{Instruction::RETURN_VOID}, kNullMethod}, |
| 563 | {{Instruction::CONST, Instruction::RETURN}, kConstFunction}, |
| 564 | {{Instruction::CONST_4, Instruction::RETURN}, kConstFunction}, |
| 565 | {{Instruction::CONST_4, Instruction::RETURN_OBJECT}, kConstFunction}, |
| 566 | {{Instruction::CONST_16, Instruction::RETURN}, kConstFunction}, |
| 567 | {{Instruction::IGET, Instruction:: RETURN}, kIGet}, |
| 568 | {{Instruction::IGET_BOOLEAN, Instruction::RETURN}, kIGetBoolean}, |
| 569 | {{Instruction::IGET_OBJECT, Instruction::RETURN_OBJECT}, kIGetObject}, |
| 570 | {{Instruction::IGET_BYTE, Instruction::RETURN}, kIGetByte}, |
| 571 | {{Instruction::IGET_CHAR, Instruction::RETURN}, kIGetChar}, |
| 572 | {{Instruction::IGET_SHORT, Instruction::RETURN}, kIGetShort}, |
| 573 | {{Instruction::IGET_WIDE, Instruction::RETURN_WIDE}, kIGetWide}, |
| 574 | {{Instruction::IPUT, Instruction::RETURN_VOID}, kIPut}, |
| 575 | {{Instruction::IPUT_BOOLEAN, Instruction::RETURN_VOID}, kIPutBoolean}, |
| 576 | {{Instruction::IPUT_OBJECT, Instruction::RETURN_VOID}, kIPutObject}, |
| 577 | {{Instruction::IPUT_BYTE, Instruction::RETURN_VOID}, kIPutByte}, |
| 578 | {{Instruction::IPUT_CHAR, Instruction::RETURN_VOID}, kIPutChar}, |
| 579 | {{Instruction::IPUT_SHORT, Instruction::RETURN_VOID}, kIPutShort}, |
| 580 | {{Instruction::IPUT_WIDE, Instruction::RETURN_VOID}, kIPutWide}, |
| 581 | {{Instruction::RETURN}, kIdentity}, |
| 582 | {{Instruction::RETURN_OBJECT}, kIdentity}, |
| 583 | {{Instruction::RETURN_WIDE}, kIdentity}, |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 584 | }; |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 585 | |
buzbee | 4ef3e45 | 2012-12-14 13:35:28 -0800 | [diff] [blame] | 586 | static inline bool IsConst(const CompilationUnit* cu, int32_t s_reg) |
| 587 | { |
| 588 | return (IsBitSet(cu->is_constant_v, s_reg)); |
| 589 | } |
| 590 | |
| 591 | static inline bool IsConst(const CompilationUnit* cu, RegLocation loc) |
| 592 | { |
| 593 | return (IsConst(cu, loc.orig_sreg)); |
| 594 | } |
| 595 | |
| 596 | static inline int32_t ConstantValue(const CompilationUnit* cu, RegLocation loc) |
| 597 | { |
| 598 | DCHECK(IsConst(cu, loc)); |
| 599 | return cu->constant_values[loc.orig_sreg]; |
| 600 | } |
| 601 | |
buzbee | f662a7c | 2013-02-12 16:19:43 -0800 | [diff] [blame] | 602 | static inline int32_t ConstantValue(const CompilationUnit* cu, int32_t s_reg) |
| 603 | { |
| 604 | DCHECK(IsConst(cu, s_reg)); |
| 605 | return cu->constant_values[s_reg]; |
| 606 | } |
| 607 | |
buzbee | 4ef3e45 | 2012-12-14 13:35:28 -0800 | [diff] [blame] | 608 | static inline int64_t ConstantValueWide(const CompilationUnit* cu, RegLocation loc) |
| 609 | { |
| 610 | DCHECK(IsConst(cu, loc)); |
| 611 | return (static_cast<int64_t>(cu->constant_values[loc.orig_sreg + 1]) << 32) | |
| 612 | Low32Bits(static_cast<int64_t>(cu->constant_values[loc.orig_sreg])); |
| 613 | } |
| 614 | |
buzbee | 6a791b2 | 2013-02-07 05:35:08 -0800 | [diff] [blame] | 615 | static inline bool IsConstantNullRef(const CompilationUnit* cu, RegLocation loc) |
| 616 | { |
| 617 | return loc.ref && loc.is_const && (ConstantValue(cu, loc) == 0); |
| 618 | } |
| 619 | |
buzbee | 4ef3e45 | 2012-12-14 13:35:28 -0800 | [diff] [blame] | 620 | static inline bool MustFlushConstant(const CompilationUnit* cu, RegLocation loc) |
| 621 | { |
| 622 | DCHECK(IsConst(cu, loc)); |
| 623 | return IsBitSet(cu->must_flush_constant_v, loc.orig_sreg); |
| 624 | } |
| 625 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 626 | } // namespace art |
| 627 | |
buzbee | 395116c | 2013-02-27 14:30:25 -0800 | [diff] [blame] | 628 | #endif // ART_SRC_COMPILER_DEX_COMPILER_IR_H_ |