Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_COMPILER_DEX_QUICK_MIR_TO_LIR_H_ |
| 18 | #define ART_COMPILER_DEX_QUICK_MIR_TO_LIR_H_ |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 19 | |
| 20 | #include "invoke_type.h" |
| 21 | #include "compiled_method.h" |
| 22 | #include "dex/compiler_enums.h" |
| 23 | #include "dex/compiler_ir.h" |
| 24 | #include "dex/backend.h" |
| 25 | #include "dex/growable_array.h" |
| 26 | #include "dex/arena_allocator.h" |
| 27 | #include "driver/compiler_driver.h" |
Ian Rogers | 96faf5b | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 28 | #include "leb128_encoder.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 29 | #include "safe_map.h" |
| 30 | |
| 31 | namespace art { |
| 32 | |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 33 | /* |
| 34 | * TODO: refactoring pass to move these (and other) typdefs towards usage style of runtime to |
| 35 | * add type safety (see runtime/offsets.h). |
| 36 | */ |
| 37 | typedef uint32_t DexOffset; // Dex offset in code units. |
| 38 | typedef uint16_t NarrowDexOffset; // For use in structs, Dex offsets range from 0 .. 0xffff. |
| 39 | typedef uint32_t CodeOffset; // Native code offset in bytes. |
| 40 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 41 | // Set to 1 to measure cost of suspend check. |
| 42 | #define NO_SUSPEND 0 |
| 43 | |
| 44 | #define IS_BINARY_OP (1ULL << kIsBinaryOp) |
| 45 | #define IS_BRANCH (1ULL << kIsBranch) |
| 46 | #define IS_IT (1ULL << kIsIT) |
| 47 | #define IS_LOAD (1ULL << kMemLoad) |
| 48 | #define IS_QUAD_OP (1ULL << kIsQuadOp) |
| 49 | #define IS_QUIN_OP (1ULL << kIsQuinOp) |
| 50 | #define IS_SEXTUPLE_OP (1ULL << kIsSextupleOp) |
| 51 | #define IS_STORE (1ULL << kMemStore) |
| 52 | #define IS_TERTIARY_OP (1ULL << kIsTertiaryOp) |
| 53 | #define IS_UNARY_OP (1ULL << kIsUnaryOp) |
| 54 | #define NEEDS_FIXUP (1ULL << kPCRelFixup) |
| 55 | #define NO_OPERAND (1ULL << kNoOperand) |
| 56 | #define REG_DEF0 (1ULL << kRegDef0) |
| 57 | #define REG_DEF1 (1ULL << kRegDef1) |
| 58 | #define REG_DEFA (1ULL << kRegDefA) |
| 59 | #define REG_DEFD (1ULL << kRegDefD) |
| 60 | #define REG_DEF_FPCS_LIST0 (1ULL << kRegDefFPCSList0) |
| 61 | #define REG_DEF_FPCS_LIST2 (1ULL << kRegDefFPCSList2) |
| 62 | #define REG_DEF_LIST0 (1ULL << kRegDefList0) |
| 63 | #define REG_DEF_LIST1 (1ULL << kRegDefList1) |
| 64 | #define REG_DEF_LR (1ULL << kRegDefLR) |
| 65 | #define REG_DEF_SP (1ULL << kRegDefSP) |
| 66 | #define REG_USE0 (1ULL << kRegUse0) |
| 67 | #define REG_USE1 (1ULL << kRegUse1) |
| 68 | #define REG_USE2 (1ULL << kRegUse2) |
| 69 | #define REG_USE3 (1ULL << kRegUse3) |
| 70 | #define REG_USE4 (1ULL << kRegUse4) |
| 71 | #define REG_USEA (1ULL << kRegUseA) |
| 72 | #define REG_USEC (1ULL << kRegUseC) |
| 73 | #define REG_USED (1ULL << kRegUseD) |
| 74 | #define REG_USE_FPCS_LIST0 (1ULL << kRegUseFPCSList0) |
| 75 | #define REG_USE_FPCS_LIST2 (1ULL << kRegUseFPCSList2) |
| 76 | #define REG_USE_LIST0 (1ULL << kRegUseList0) |
| 77 | #define REG_USE_LIST1 (1ULL << kRegUseList1) |
| 78 | #define REG_USE_LR (1ULL << kRegUseLR) |
| 79 | #define REG_USE_PC (1ULL << kRegUsePC) |
| 80 | #define REG_USE_SP (1ULL << kRegUseSP) |
| 81 | #define SETS_CCODES (1ULL << kSetsCCodes) |
| 82 | #define USES_CCODES (1ULL << kUsesCCodes) |
| 83 | |
| 84 | // Common combo register usage patterns. |
| 85 | #define REG_DEF01 (REG_DEF0 | REG_DEF1) |
| 86 | #define REG_DEF01_USE2 (REG_DEF0 | REG_DEF1 | REG_USE2) |
| 87 | #define REG_DEF0_USE01 (REG_DEF0 | REG_USE01) |
| 88 | #define REG_DEF0_USE0 (REG_DEF0 | REG_USE0) |
| 89 | #define REG_DEF0_USE12 (REG_DEF0 | REG_USE12) |
| 90 | #define REG_DEF0_USE1 (REG_DEF0 | REG_USE1) |
| 91 | #define REG_DEF0_USE2 (REG_DEF0 | REG_USE2) |
| 92 | #define REG_DEFAD_USEAD (REG_DEFAD_USEA | REG_USED) |
| 93 | #define REG_DEFAD_USEA (REG_DEFA_USEA | REG_DEFD) |
| 94 | #define REG_DEFA_USEA (REG_DEFA | REG_USEA) |
| 95 | #define REG_USE012 (REG_USE01 | REG_USE2) |
| 96 | #define REG_USE014 (REG_USE01 | REG_USE4) |
| 97 | #define REG_USE01 (REG_USE0 | REG_USE1) |
| 98 | #define REG_USE02 (REG_USE0 | REG_USE2) |
| 99 | #define REG_USE12 (REG_USE1 | REG_USE2) |
| 100 | #define REG_USE23 (REG_USE2 | REG_USE3) |
| 101 | |
| 102 | struct BasicBlock; |
| 103 | struct CallInfo; |
| 104 | struct CompilationUnit; |
| 105 | struct MIR; |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 106 | struct LIR; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 107 | struct RegLocation; |
| 108 | struct RegisterInfo; |
| 109 | class MIRGraph; |
| 110 | class Mir2Lir; |
| 111 | |
| 112 | typedef int (*NextCallInsn)(CompilationUnit*, CallInfo*, int, |
| 113 | const MethodReference& target_method, |
| 114 | uint32_t method_idx, uintptr_t direct_code, |
| 115 | uintptr_t direct_method, InvokeType type); |
| 116 | |
| 117 | typedef std::vector<uint8_t> CodeBuffer; |
| 118 | |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 119 | struct UseDefMasks { |
| 120 | uint64_t use_mask; // Resource mask for use. |
| 121 | uint64_t def_mask; // Resource mask for def. |
| 122 | }; |
| 123 | |
| 124 | struct AssemblyInfo { |
| 125 | LIR* pcrel_next; // Chain of LIR nodes needing pc relative fixups. |
| 126 | uint8_t bytes[16]; // Encoded instruction bytes. |
| 127 | }; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 128 | |
| 129 | struct LIR { |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 130 | CodeOffset offset; // Offset of this instruction. |
| 131 | NarrowDexOffset dalvik_offset; // Offset of Dalvik opcode in code units (16-bit words). |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 132 | int16_t opcode; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 133 | LIR* next; |
| 134 | LIR* prev; |
| 135 | LIR* target; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 136 | struct { |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 137 | unsigned int alias_info:17; // For Dalvik register disambiguation. |
| 138 | bool is_nop:1; // LIR is optimized away. |
| 139 | unsigned int size:4; // Note: size of encoded instruction is in bytes. |
| 140 | bool use_def_invalid:1; // If true, masks should not be used. |
| 141 | unsigned int generation:1; // Used to track visitation state during fixup pass. |
| 142 | unsigned int fixup:8; // Fixup kind. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 143 | } flags; |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 144 | union { |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 145 | UseDefMasks m; // Use & Def masks used during optimization. |
| 146 | AssemblyInfo a; // Instruction encoding used during assembly phase. |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 147 | } u; |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 148 | int32_t operands[5]; // [0..4] = [dest, src1, src2, extra, extra2]. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | // Target-specific initialization. |
| 152 | Mir2Lir* ArmCodeGenerator(CompilationUnit* const cu, MIRGraph* const mir_graph, |
| 153 | ArenaAllocator* const arena); |
| 154 | Mir2Lir* MipsCodeGenerator(CompilationUnit* const cu, MIRGraph* const mir_graph, |
| 155 | ArenaAllocator* const arena); |
| 156 | Mir2Lir* X86CodeGenerator(CompilationUnit* const cu, MIRGraph* const mir_graph, |
| 157 | ArenaAllocator* const arena); |
| 158 | |
| 159 | // Utility macros to traverse the LIR list. |
| 160 | #define NEXT_LIR(lir) (lir->next) |
| 161 | #define PREV_LIR(lir) (lir->prev) |
| 162 | |
| 163 | // Defines for alias_info (tracks Dalvik register references). |
| 164 | #define DECODE_ALIAS_INFO_REG(X) (X & 0xffff) |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 165 | #define DECODE_ALIAS_INFO_WIDE_FLAG (0x10000) |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 166 | #define DECODE_ALIAS_INFO_WIDE(X) ((X & DECODE_ALIAS_INFO_WIDE_FLAG) ? 1 : 0) |
| 167 | #define ENCODE_ALIAS_INFO(REG, ISWIDE) (REG | (ISWIDE ? DECODE_ALIAS_INFO_WIDE_FLAG : 0)) |
| 168 | |
| 169 | // Common resource macros. |
| 170 | #define ENCODE_CCODE (1ULL << kCCode) |
| 171 | #define ENCODE_FP_STATUS (1ULL << kFPStatus) |
| 172 | |
| 173 | // Abstract memory locations. |
| 174 | #define ENCODE_DALVIK_REG (1ULL << kDalvikReg) |
| 175 | #define ENCODE_LITERAL (1ULL << kLiteral) |
| 176 | #define ENCODE_HEAP_REF (1ULL << kHeapRef) |
| 177 | #define ENCODE_MUST_NOT_ALIAS (1ULL << kMustNotAlias) |
| 178 | |
| 179 | #define ENCODE_ALL (~0ULL) |
| 180 | #define ENCODE_MEM (ENCODE_DALVIK_REG | ENCODE_LITERAL | \ |
| 181 | ENCODE_HEAP_REF | ENCODE_MUST_NOT_ALIAS) |
buzbee | c729a6b | 2013-09-14 16:04:31 -0700 | [diff] [blame] | 182 | |
| 183 | // Mask to denote sreg as the start of a double. Must not interfere with low 16 bits. |
| 184 | #define STARTING_DOUBLE_SREG 0x10000 |
| 185 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 186 | // TODO: replace these macros |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 187 | #define SLOW_FIELD_PATH (cu_->enable_debug & (1 << kDebugSlowFieldPath)) |
| 188 | #define SLOW_INVOKE_PATH (cu_->enable_debug & (1 << kDebugSlowInvokePath)) |
| 189 | #define SLOW_STRING_PATH (cu_->enable_debug & (1 << kDebugSlowStringPath)) |
| 190 | #define SLOW_TYPE_PATH (cu_->enable_debug & (1 << kDebugSlowTypePath)) |
| 191 | #define EXERCISE_SLOWEST_STRING_PATH (cu_->enable_debug & (1 << kDebugSlowestStringPath)) |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 192 | |
| 193 | class Mir2Lir : public Backend { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 194 | public: |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 195 | /* |
| 196 | * Auxiliary information describing the location of data embedded in the Dalvik |
| 197 | * byte code stream. |
| 198 | */ |
| 199 | struct EmbeddedData { |
| 200 | CodeOffset offset; // Code offset of data block. |
| 201 | const uint16_t* table; // Original dex data. |
| 202 | DexOffset vaddr; // Dalvik offset of parent opcode. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 203 | }; |
| 204 | |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 205 | struct FillArrayData : EmbeddedData { |
| 206 | int32_t size; |
| 207 | }; |
| 208 | |
| 209 | struct SwitchTable : EmbeddedData { |
| 210 | LIR* anchor; // Reference instruction for relative offsets. |
| 211 | LIR** targets; // Array of case targets. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 212 | }; |
| 213 | |
| 214 | /* Static register use counts */ |
| 215 | struct RefCounts { |
| 216 | int count; |
| 217 | int s_reg; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 218 | }; |
| 219 | |
| 220 | /* |
| 221 | * Data structure tracking the mapping between a Dalvik register (pair) and a |
| 222 | * native register (pair). The idea is to reuse the previously loaded value |
| 223 | * if possible, otherwise to keep the value in a native register as long as |
| 224 | * possible. |
| 225 | */ |
| 226 | struct RegisterInfo { |
| 227 | int reg; // Reg number |
| 228 | bool in_use; // Has it been allocated? |
| 229 | bool is_temp; // Can allocate as temp? |
| 230 | bool pair; // Part of a register pair? |
| 231 | int partner; // If pair, other reg of pair. |
| 232 | bool live; // Is there an associated SSA name? |
| 233 | bool dirty; // If live, is it dirty? |
| 234 | int s_reg; // Name of live value. |
| 235 | LIR *def_start; // Starting inst in last def sequence. |
| 236 | LIR *def_end; // Ending inst in last def sequence. |
| 237 | }; |
| 238 | |
Brian Carlstrom | 6f485c6 | 2013-07-18 15:35:35 -0700 | [diff] [blame] | 239 | struct RegisterPool { |
| 240 | int num_core_regs; |
| 241 | RegisterInfo *core_regs; |
| 242 | int next_core_reg; |
| 243 | int num_fp_regs; |
| 244 | RegisterInfo *FPRegs; |
| 245 | int next_fp_reg; |
| 246 | }; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 247 | |
| 248 | struct PromotionMap { |
| 249 | RegLocationType core_location:3; |
| 250 | uint8_t core_reg; |
| 251 | RegLocationType fp_location:3; |
| 252 | uint8_t FpReg; |
| 253 | bool first_in_pair; |
| 254 | }; |
| 255 | |
Brian Carlstrom | 9b7085a | 2013-07-18 15:15:21 -0700 | [diff] [blame] | 256 | virtual ~Mir2Lir() {} |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 257 | |
| 258 | int32_t s4FromSwitchData(const void* switch_data) { |
| 259 | return *reinterpret_cast<const int32_t*>(switch_data); |
| 260 | } |
| 261 | |
| 262 | RegisterClass oat_reg_class_by_size(OpSize size) { |
| 263 | return (size == kUnsignedHalf || size == kSignedHalf || size == kUnsignedByte || |
Brian Carlstrom | df62950 | 2013-07-17 22:39:56 -0700 | [diff] [blame] | 264 | size == kSignedByte) ? kCoreReg : kAnyReg; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | size_t CodeBufferSizeInBytes() { |
| 268 | return code_buffer_.size() / sizeof(code_buffer_[0]); |
| 269 | } |
| 270 | |
buzbee | 409fe94 | 2013-10-11 10:49:56 -0700 | [diff] [blame] | 271 | bool IsPseudoLirOp(int opcode) { |
| 272 | return (opcode < 0); |
| 273 | } |
| 274 | |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 275 | /* |
| 276 | * LIR operands are 32-bit integers. Sometimes, (especially for managing |
| 277 | * instructions which require PC-relative fixups), we need the operands to carry |
| 278 | * pointers. To do this, we assign these pointers an index in pointer_storage_, and |
| 279 | * hold that index in the operand array. |
| 280 | * TUNING: If use of these utilities becomes more common on 32-bit builds, it |
| 281 | * may be worth conditionally-compiling a set of identity functions here. |
| 282 | */ |
| 283 | uint32_t WrapPointer(void* pointer) { |
| 284 | uint32_t res = pointer_storage_.Size(); |
| 285 | pointer_storage_.Insert(pointer); |
| 286 | return res; |
| 287 | } |
| 288 | |
| 289 | void* UnwrapPointer(size_t index) { |
| 290 | return pointer_storage_.Get(index); |
| 291 | } |
| 292 | |
| 293 | // strdup(), but allocates from the arena. |
| 294 | char* ArenaStrdup(const char* str) { |
| 295 | size_t len = strlen(str) + 1; |
| 296 | char* res = reinterpret_cast<char*>(arena_->Alloc(len, ArenaAllocator::kAllocMisc)); |
| 297 | if (res != NULL) { |
| 298 | strncpy(res, str, len); |
| 299 | } |
| 300 | return res; |
| 301 | } |
| 302 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 303 | // Shared by all targets - implemented in codegen_util.cc |
| 304 | void AppendLIR(LIR* lir); |
| 305 | void InsertLIRBefore(LIR* current_lir, LIR* new_lir); |
| 306 | void InsertLIRAfter(LIR* current_lir, LIR* new_lir); |
| 307 | |
| 308 | int ComputeFrameSize(); |
| 309 | virtual void Materialize(); |
| 310 | virtual CompiledMethod* GetCompiledMethod(); |
| 311 | void MarkSafepointPC(LIR* inst); |
Ian Rogers | 9b297bf | 2013-09-06 11:11:25 -0700 | [diff] [blame] | 312 | bool FastInstance(uint32_t field_idx, bool is_put, int* field_offset, bool* is_volatile); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 313 | void SetupResourceMasks(LIR* lir); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 314 | void SetMemRefType(LIR* lir, bool is_load, int mem_type); |
| 315 | void AnnotateDalvikRegAccess(LIR* lir, int reg_id, bool is_load, bool is64bit); |
| 316 | void SetupRegMask(uint64_t* mask, int reg); |
| 317 | void DumpLIRInsn(LIR* arg, unsigned char* base_addr); |
| 318 | void DumpPromotionMap(); |
| 319 | void CodegenDump(); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 320 | LIR* RawLIR(DexOffset dalvik_offset, int opcode, int op0 = 0, int op1 = 0, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 321 | int op2 = 0, int op3 = 0, int op4 = 0, LIR* target = NULL); |
| 322 | LIR* NewLIR0(int opcode); |
| 323 | LIR* NewLIR1(int opcode, int dest); |
| 324 | LIR* NewLIR2(int opcode, int dest, int src1); |
| 325 | LIR* NewLIR3(int opcode, int dest, int src1, int src2); |
| 326 | LIR* NewLIR4(int opcode, int dest, int src1, int src2, int info); |
| 327 | LIR* NewLIR5(int opcode, int dest, int src1, int src2, int info1, int info2); |
| 328 | LIR* ScanLiteralPool(LIR* data_target, int value, unsigned int delta); |
| 329 | LIR* ScanLiteralPoolWide(LIR* data_target, int val_lo, int val_hi); |
| 330 | LIR* AddWordData(LIR* *constant_list_p, int value); |
| 331 | LIR* AddWideData(LIR* *constant_list_p, int val_lo, int val_hi); |
| 332 | void ProcessSwitchTables(); |
| 333 | void DumpSparseSwitchTable(const uint16_t* table); |
| 334 | void DumpPackedSwitchTable(const uint16_t* table); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 335 | void MarkBoundary(DexOffset offset, const char* inst_str); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 336 | void NopLIR(LIR* lir); |
buzbee | 252254b | 2013-09-08 16:20:53 -0700 | [diff] [blame] | 337 | void UnlinkLIR(LIR* lir); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 338 | bool EvaluateBranch(Instruction::Code opcode, int src1, int src2); |
| 339 | bool IsInexpensiveConstant(RegLocation rl_src); |
| 340 | ConditionCode FlipComparisonOrder(ConditionCode before); |
Ian Rogers | d91d6d6 | 2013-09-25 20:26:14 -0700 | [diff] [blame] | 341 | void DumpMappingTable(const char* table_name, const char* descriptor, |
| 342 | const char* name, const Signature& signature, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 343 | const std::vector<uint32_t>& v); |
| 344 | void InstallLiteralPools(); |
| 345 | void InstallSwitchTables(); |
| 346 | void InstallFillArrayData(); |
| 347 | bool VerifyCatchEntries(); |
| 348 | void CreateMappingTables(); |
| 349 | void CreateNativeGcMap(); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 350 | int AssignLiteralOffset(CodeOffset offset); |
| 351 | int AssignSwitchTablesOffset(CodeOffset offset); |
| 352 | int AssignFillArrayDataOffset(CodeOffset offset); |
| 353 | LIR* InsertCaseLabel(DexOffset vaddr, int keyVal); |
| 354 | void MarkPackedCaseLabels(Mir2Lir::SwitchTable* tab_rec); |
| 355 | void MarkSparseCaseLabels(Mir2Lir::SwitchTable* tab_rec); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 356 | |
| 357 | // Shared by all targets - implemented in local_optimizations.cc |
| 358 | void ConvertMemOpIntoMove(LIR* orig_lir, int dest, int src); |
| 359 | void ApplyLoadStoreElimination(LIR* head_lir, LIR* tail_lir); |
| 360 | void ApplyLoadHoisting(LIR* head_lir, LIR* tail_lir); |
| 361 | void ApplyLocalOptimizations(LIR* head_lir, LIR* tail_lir); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 362 | |
| 363 | // Shared by all targets - implemented in ralloc_util.cc |
| 364 | int GetSRegHi(int lowSreg); |
| 365 | bool oat_live_out(int s_reg); |
| 366 | int oatSSASrc(MIR* mir, int num); |
| 367 | void SimpleRegAlloc(); |
| 368 | void ResetRegPool(); |
| 369 | void CompilerInitPool(RegisterInfo* regs, int* reg_nums, int num); |
| 370 | void DumpRegPool(RegisterInfo* p, int num_regs); |
| 371 | void DumpCoreRegPool(); |
| 372 | void DumpFpRegPool(); |
| 373 | /* Mark a temp register as dead. Does not affect allocation state. */ |
| 374 | void Clobber(int reg) { |
| 375 | ClobberBody(GetRegInfo(reg)); |
| 376 | } |
| 377 | void ClobberSRegBody(RegisterInfo* p, int num_regs, int s_reg); |
| 378 | void ClobberSReg(int s_reg); |
| 379 | int SRegToPMap(int s_reg); |
| 380 | void RecordCorePromotion(int reg, int s_reg); |
| 381 | int AllocPreservedCoreReg(int s_reg); |
| 382 | void RecordFpPromotion(int reg, int s_reg); |
buzbee | c729a6b | 2013-09-14 16:04:31 -0700 | [diff] [blame] | 383 | int AllocPreservedSingle(int s_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 384 | int AllocPreservedDouble(int s_reg); |
buzbee | c729a6b | 2013-09-14 16:04:31 -0700 | [diff] [blame] | 385 | int AllocTempBody(RegisterInfo* p, int num_regs, int* next_temp, bool required); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 386 | int AllocTempDouble(); |
| 387 | int AllocFreeTemp(); |
| 388 | int AllocTemp(); |
| 389 | int AllocTempFloat(); |
| 390 | RegisterInfo* AllocLiveBody(RegisterInfo* p, int num_regs, int s_reg); |
| 391 | RegisterInfo* AllocLive(int s_reg, int reg_class); |
| 392 | void FreeTemp(int reg); |
| 393 | RegisterInfo* IsLive(int reg); |
| 394 | RegisterInfo* IsTemp(int reg); |
| 395 | RegisterInfo* IsPromoted(int reg); |
| 396 | bool IsDirty(int reg); |
| 397 | void LockTemp(int reg); |
| 398 | void ResetDef(int reg); |
| 399 | void NullifyRange(LIR *start, LIR *finish, int s_reg1, int s_reg2); |
| 400 | void MarkDef(RegLocation rl, LIR *start, LIR *finish); |
| 401 | void MarkDefWide(RegLocation rl, LIR *start, LIR *finish); |
| 402 | RegLocation WideToNarrow(RegLocation rl); |
| 403 | void ResetDefLoc(RegLocation rl); |
| 404 | void ResetDefLocWide(RegLocation rl); |
| 405 | void ResetDefTracking(); |
| 406 | void ClobberAllRegs(); |
| 407 | void FlushAllRegsBody(RegisterInfo* info, int num_regs); |
| 408 | void FlushAllRegs(); |
| 409 | bool RegClassMatches(int reg_class, int reg); |
| 410 | void MarkLive(int reg, int s_reg); |
| 411 | void MarkTemp(int reg); |
| 412 | void UnmarkTemp(int reg); |
| 413 | void MarkPair(int low_reg, int high_reg); |
| 414 | void MarkClean(RegLocation loc); |
| 415 | void MarkDirty(RegLocation loc); |
| 416 | void MarkInUse(int reg); |
| 417 | void CopyRegInfo(int new_reg, int old_reg); |
| 418 | bool CheckCorePoolSanity(); |
| 419 | RegLocation UpdateLoc(RegLocation loc); |
| 420 | RegLocation UpdateLocWide(RegLocation loc); |
| 421 | RegLocation UpdateRawLoc(RegLocation loc); |
| 422 | RegLocation EvalLocWide(RegLocation loc, int reg_class, bool update); |
| 423 | RegLocation EvalLoc(RegLocation loc, int reg_class, bool update); |
buzbee | c729a6b | 2013-09-14 16:04:31 -0700 | [diff] [blame] | 424 | void CountRefs(RefCounts* core_counts, RefCounts* fp_counts, size_t num_regs); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 425 | void DumpCounts(const RefCounts* arr, int size, const char* msg); |
| 426 | void DoPromotion(); |
| 427 | int VRegOffset(int v_reg); |
| 428 | int SRegOffset(int s_reg); |
| 429 | RegLocation GetReturnWide(bool is_double); |
| 430 | RegLocation GetReturn(bool is_float); |
buzbee | bd663de | 2013-09-10 15:41:31 -0700 | [diff] [blame] | 431 | RegisterInfo* GetRegInfo(int reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 432 | |
| 433 | // Shared by all targets - implemented in gen_common.cc. |
buzbee | 11b63d1 | 2013-08-27 07:34:17 -0700 | [diff] [blame] | 434 | bool HandleEasyDivRem(Instruction::Code dalvik_opcode, bool is_div, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 435 | RegLocation rl_src, RegLocation rl_dest, int lit); |
| 436 | bool HandleEasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit); |
| 437 | void HandleSuspendLaunchPads(); |
| 438 | void HandleIntrinsicLaunchPads(); |
| 439 | void HandleThrowLaunchPads(); |
| 440 | void GenBarrier(); |
| 441 | LIR* GenCheck(ConditionCode c_code, ThrowKind kind); |
| 442 | LIR* GenImmedCheck(ConditionCode c_code, int reg, int imm_val, |
| 443 | ThrowKind kind); |
| 444 | LIR* GenNullCheck(int s_reg, int m_reg, int opt_flags); |
| 445 | LIR* GenRegRegCheck(ConditionCode c_code, int reg1, int reg2, |
| 446 | ThrowKind kind); |
| 447 | void GenCompareAndBranch(Instruction::Code opcode, RegLocation rl_src1, |
| 448 | RegLocation rl_src2, LIR* taken, LIR* fall_through); |
| 449 | void GenCompareZeroAndBranch(Instruction::Code opcode, RegLocation rl_src, |
| 450 | LIR* taken, LIR* fall_through); |
| 451 | void GenIntToLong(RegLocation rl_dest, RegLocation rl_src); |
| 452 | void GenIntNarrowing(Instruction::Code opcode, RegLocation rl_dest, |
| 453 | RegLocation rl_src); |
| 454 | void GenNewArray(uint32_t type_idx, RegLocation rl_dest, |
| 455 | RegLocation rl_src); |
| 456 | void GenFilledNewArray(CallInfo* info); |
| 457 | void GenSput(uint32_t field_idx, RegLocation rl_src, |
| 458 | bool is_long_or_double, bool is_object); |
| 459 | void GenSget(uint32_t field_idx, RegLocation rl_dest, |
| 460 | bool is_long_or_double, bool is_object); |
| 461 | void GenIGet(uint32_t field_idx, int opt_flags, OpSize size, |
| 462 | RegLocation rl_dest, RegLocation rl_obj, bool is_long_or_double, bool is_object); |
| 463 | void GenIPut(uint32_t field_idx, int opt_flags, OpSize size, |
| 464 | RegLocation rl_src, RegLocation rl_obj, bool is_long_or_double, bool is_object); |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 465 | void GenArrayObjPut(int opt_flags, RegLocation rl_array, RegLocation rl_index, |
| 466 | RegLocation rl_src); |
| 467 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 468 | void GenConstClass(uint32_t type_idx, RegLocation rl_dest); |
| 469 | void GenConstString(uint32_t string_idx, RegLocation rl_dest); |
| 470 | void GenNewInstance(uint32_t type_idx, RegLocation rl_dest); |
| 471 | void GenThrow(RegLocation rl_src); |
| 472 | void GenInstanceof(uint32_t type_idx, RegLocation rl_dest, |
| 473 | RegLocation rl_src); |
| 474 | void GenCheckCast(uint32_t insn_idx, uint32_t type_idx, |
| 475 | RegLocation rl_src); |
| 476 | void GenLong3Addr(OpKind first_op, OpKind second_op, RegLocation rl_dest, |
| 477 | RegLocation rl_src1, RegLocation rl_src2); |
| 478 | void GenShiftOpLong(Instruction::Code opcode, RegLocation rl_dest, |
| 479 | RegLocation rl_src1, RegLocation rl_shift); |
| 480 | void GenArithOpInt(Instruction::Code opcode, RegLocation rl_dest, |
| 481 | RegLocation rl_src1, RegLocation rl_src2); |
| 482 | void GenArithOpIntLit(Instruction::Code opcode, RegLocation rl_dest, |
| 483 | RegLocation rl_src, int lit); |
| 484 | void GenArithOpLong(Instruction::Code opcode, RegLocation rl_dest, |
| 485 | RegLocation rl_src1, RegLocation rl_src2); |
Ian Rogers | 468532e | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 486 | void GenConversionCall(ThreadOffset func_offset, RegLocation rl_dest, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 487 | RegLocation rl_src); |
| 488 | void GenSuspendTest(int opt_flags); |
| 489 | void GenSuspendTestAndBranch(int opt_flags, LIR* target); |
| 490 | |
| 491 | // Shared by all targets - implemented in gen_invoke.cc. |
Ian Rogers | 468532e | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 492 | int CallHelperSetup(ThreadOffset helper_offset); |
| 493 | LIR* CallHelper(int r_tgt, ThreadOffset helper_offset, bool safepoint_pc); |
| 494 | void CallRuntimeHelperImm(ThreadOffset helper_offset, int arg0, bool safepoint_pc); |
| 495 | void CallRuntimeHelperReg(ThreadOffset helper_offset, int arg0, bool safepoint_pc); |
| 496 | void CallRuntimeHelperRegLocation(ThreadOffset helper_offset, RegLocation arg0, |
| 497 | bool safepoint_pc); |
| 498 | void CallRuntimeHelperImmImm(ThreadOffset helper_offset, int arg0, int arg1, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 499 | bool safepoint_pc); |
Ian Rogers | 468532e | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 500 | void CallRuntimeHelperImmRegLocation(ThreadOffset helper_offset, int arg0, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 501 | RegLocation arg1, bool safepoint_pc); |
Ian Rogers | 468532e | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 502 | void CallRuntimeHelperRegLocationImm(ThreadOffset helper_offset, RegLocation arg0, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 503 | int arg1, bool safepoint_pc); |
Ian Rogers | 468532e | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 504 | void CallRuntimeHelperImmReg(ThreadOffset helper_offset, int arg0, int arg1, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 505 | bool safepoint_pc); |
Ian Rogers | 468532e | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 506 | void CallRuntimeHelperRegImm(ThreadOffset helper_offset, int arg0, int arg1, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 507 | bool safepoint_pc); |
Ian Rogers | 468532e | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 508 | void CallRuntimeHelperImmMethod(ThreadOffset helper_offset, int arg0, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 509 | bool safepoint_pc); |
Ian Rogers | 468532e | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 510 | void CallRuntimeHelperRegLocationRegLocation(ThreadOffset helper_offset, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 511 | RegLocation arg0, RegLocation arg1, |
| 512 | bool safepoint_pc); |
Ian Rogers | 468532e | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 513 | void CallRuntimeHelperRegReg(ThreadOffset helper_offset, int arg0, int arg1, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 514 | bool safepoint_pc); |
Ian Rogers | 468532e | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 515 | void CallRuntimeHelperRegRegImm(ThreadOffset helper_offset, int arg0, int arg1, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 516 | int arg2, bool safepoint_pc); |
Ian Rogers | 468532e | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 517 | void CallRuntimeHelperImmMethodRegLocation(ThreadOffset helper_offset, int arg0, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 518 | RegLocation arg2, bool safepoint_pc); |
Ian Rogers | 468532e | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 519 | void CallRuntimeHelperImmMethodImm(ThreadOffset helper_offset, int arg0, int arg2, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 520 | bool safepoint_pc); |
Ian Rogers | 468532e | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 521 | void CallRuntimeHelperImmRegLocationRegLocation(ThreadOffset helper_offset, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 522 | int arg0, RegLocation arg1, RegLocation arg2, |
| 523 | bool safepoint_pc); |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 524 | void CallRuntimeHelperRegLocationRegLocationRegLocation(ThreadOffset helper_offset, |
| 525 | RegLocation arg0, RegLocation arg1, |
| 526 | RegLocation arg2, |
| 527 | bool safepoint_pc); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 528 | void GenInvoke(CallInfo* info); |
| 529 | void FlushIns(RegLocation* ArgLocs, RegLocation rl_method); |
| 530 | int GenDalvikArgsNoRange(CallInfo* info, int call_state, LIR** pcrLabel, |
| 531 | NextCallInsn next_call_insn, |
| 532 | const MethodReference& target_method, |
| 533 | uint32_t vtable_idx, |
| 534 | uintptr_t direct_code, uintptr_t direct_method, InvokeType type, |
| 535 | bool skip_this); |
| 536 | int GenDalvikArgsRange(CallInfo* info, int call_state, LIR** pcrLabel, |
| 537 | NextCallInsn next_call_insn, |
| 538 | const MethodReference& target_method, |
| 539 | uint32_t vtable_idx, |
| 540 | uintptr_t direct_code, uintptr_t direct_method, InvokeType type, |
| 541 | bool skip_this); |
| 542 | RegLocation InlineTarget(CallInfo* info); |
| 543 | RegLocation InlineTargetWide(CallInfo* info); |
| 544 | |
| 545 | bool GenInlinedCharAt(CallInfo* info); |
| 546 | bool GenInlinedStringIsEmptyOrLength(CallInfo* info, bool is_empty); |
Vladimir Marko | 6bdf1ff | 2013-10-29 17:40:46 +0000 | [diff] [blame^] | 547 | bool GenInlinedReverseBytes(CallInfo* info, OpSize size); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 548 | bool GenInlinedAbsInt(CallInfo* info); |
| 549 | bool GenInlinedAbsLong(CallInfo* info); |
| 550 | bool GenInlinedFloatCvt(CallInfo* info); |
| 551 | bool GenInlinedDoubleCvt(CallInfo* info); |
| 552 | bool GenInlinedIndexOf(CallInfo* info, bool zero_based); |
| 553 | bool GenInlinedStringCompareTo(CallInfo* info); |
| 554 | bool GenInlinedCurrentThread(CallInfo* info); |
| 555 | bool GenInlinedUnsafeGet(CallInfo* info, bool is_long, bool is_volatile); |
| 556 | bool GenInlinedUnsafePut(CallInfo* info, bool is_long, bool is_object, |
| 557 | bool is_volatile, bool is_ordered); |
| 558 | bool GenIntrinsic(CallInfo* info); |
| 559 | int LoadArgRegs(CallInfo* info, int call_state, |
| 560 | NextCallInsn next_call_insn, |
| 561 | const MethodReference& target_method, |
| 562 | uint32_t vtable_idx, |
| 563 | uintptr_t direct_code, uintptr_t direct_method, InvokeType type, |
| 564 | bool skip_this); |
| 565 | |
| 566 | // Shared by all targets - implemented in gen_loadstore.cc. |
| 567 | RegLocation LoadCurrMethod(); |
| 568 | void LoadCurrMethodDirect(int r_tgt); |
| 569 | LIR* LoadConstant(int r_dest, int value); |
| 570 | LIR* LoadWordDisp(int rBase, int displacement, int r_dest); |
| 571 | RegLocation LoadValue(RegLocation rl_src, RegisterClass op_kind); |
| 572 | RegLocation LoadValueWide(RegLocation rl_src, RegisterClass op_kind); |
| 573 | void LoadValueDirect(RegLocation rl_src, int r_dest); |
| 574 | void LoadValueDirectFixed(RegLocation rl_src, int r_dest); |
| 575 | void LoadValueDirectWide(RegLocation rl_src, int reg_lo, int reg_hi); |
| 576 | void LoadValueDirectWideFixed(RegLocation rl_src, int reg_lo, int reg_hi); |
| 577 | LIR* StoreWordDisp(int rBase, int displacement, int r_src); |
| 578 | void StoreValue(RegLocation rl_dest, RegLocation rl_src); |
| 579 | void StoreValueWide(RegLocation rl_dest, RegLocation rl_src); |
| 580 | |
| 581 | // Shared by all targets - implemented in mir_to_lir.cc. |
| 582 | void CompileDalvikInstruction(MIR* mir, BasicBlock* bb, LIR* label_list); |
| 583 | void HandleExtendedMethodMIR(BasicBlock* bb, MIR* mir); |
| 584 | bool MethodBlockCodeGen(BasicBlock* bb); |
| 585 | void SpecialMIR2LIR(SpecialCaseHandler special_case); |
| 586 | void MethodMIR2LIR(); |
| 587 | |
| 588 | |
| 589 | |
| 590 | // Required for target - codegen helpers. |
buzbee | 11b63d1 | 2013-08-27 07:34:17 -0700 | [diff] [blame] | 591 | virtual bool SmallLiteralDivRem(Instruction::Code dalvik_opcode, bool is_div, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 592 | RegLocation rl_src, RegLocation rl_dest, int lit) = 0; |
Ian Rogers | 468532e | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 593 | virtual int LoadHelper(ThreadOffset offset) = 0; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 594 | virtual LIR* LoadBaseDisp(int rBase, int displacement, int r_dest, OpSize size, int s_reg) = 0; |
| 595 | virtual LIR* LoadBaseDispWide(int rBase, int displacement, int r_dest_lo, int r_dest_hi, |
| 596 | int s_reg) = 0; |
| 597 | virtual LIR* LoadBaseIndexed(int rBase, int r_index, int r_dest, int scale, OpSize size) = 0; |
| 598 | virtual LIR* LoadBaseIndexedDisp(int rBase, int r_index, int scale, int displacement, |
| 599 | int r_dest, int r_dest_hi, OpSize size, int s_reg) = 0; |
| 600 | virtual LIR* LoadConstantNoClobber(int r_dest, int value) = 0; |
| 601 | virtual LIR* LoadConstantWide(int r_dest_lo, int r_dest_hi, int64_t value) = 0; |
| 602 | virtual LIR* StoreBaseDisp(int rBase, int displacement, int r_src, OpSize size) = 0; |
| 603 | virtual LIR* StoreBaseDispWide(int rBase, int displacement, int r_src_lo, int r_src_hi) = 0; |
| 604 | virtual LIR* StoreBaseIndexed(int rBase, int r_index, int r_src, int scale, OpSize size) = 0; |
| 605 | virtual LIR* StoreBaseIndexedDisp(int rBase, int r_index, int scale, int displacement, |
| 606 | int r_src, int r_src_hi, OpSize size, int s_reg) = 0; |
| 607 | virtual void MarkGCCard(int val_reg, int tgt_addr_reg) = 0; |
| 608 | |
| 609 | // Required for target - register utilities. |
| 610 | virtual bool IsFpReg(int reg) = 0; |
| 611 | virtual bool SameRegType(int reg1, int reg2) = 0; |
| 612 | virtual int AllocTypedTemp(bool fp_hint, int reg_class) = 0; |
| 613 | virtual int AllocTypedTempPair(bool fp_hint, int reg_class) = 0; |
| 614 | virtual int S2d(int low_reg, int high_reg) = 0; |
| 615 | virtual int TargetReg(SpecialTargetRegister reg) = 0; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 616 | virtual RegLocation GetReturnAlt() = 0; |
| 617 | virtual RegLocation GetReturnWideAlt() = 0; |
| 618 | virtual RegLocation LocCReturn() = 0; |
| 619 | virtual RegLocation LocCReturnDouble() = 0; |
| 620 | virtual RegLocation LocCReturnFloat() = 0; |
| 621 | virtual RegLocation LocCReturnWide() = 0; |
| 622 | virtual uint32_t FpRegMask() = 0; |
| 623 | virtual uint64_t GetRegMaskCommon(int reg) = 0; |
| 624 | virtual void AdjustSpillMask() = 0; |
| 625 | virtual void ClobberCalleeSave() = 0; |
| 626 | virtual void FlushReg(int reg) = 0; |
| 627 | virtual void FlushRegWide(int reg1, int reg2) = 0; |
| 628 | virtual void FreeCallTemps() = 0; |
| 629 | virtual void FreeRegLocTemps(RegLocation rl_keep, RegLocation rl_free) = 0; |
| 630 | virtual void LockCallTemps() = 0; |
| 631 | virtual void MarkPreservedSingle(int v_reg, int reg) = 0; |
| 632 | virtual void CompilerInitializeRegAlloc() = 0; |
| 633 | |
| 634 | // Required for target - miscellaneous. |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 635 | virtual void AssembleLIR() = 0; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 636 | virtual void DumpResourceMask(LIR* lir, uint64_t mask, const char* prefix) = 0; |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 637 | virtual void SetupTargetResourceMasks(LIR* lir, uint64_t flags) = 0; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 638 | virtual const char* GetTargetInstFmt(int opcode) = 0; |
| 639 | virtual const char* GetTargetInstName(int opcode) = 0; |
| 640 | virtual std::string BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr) = 0; |
| 641 | virtual uint64_t GetPCUseDefEncoding() = 0; |
| 642 | virtual uint64_t GetTargetInstFlags(int opcode) = 0; |
| 643 | virtual int GetInsnSize(LIR* lir) = 0; |
| 644 | virtual bool IsUnconditionalBranch(LIR* lir) = 0; |
| 645 | |
| 646 | // Required for target - Dalvik-level generators. |
| 647 | virtual void GenArithImmOpLong(Instruction::Code opcode, RegLocation rl_dest, |
| 648 | RegLocation rl_src1, RegLocation rl_src2) = 0; |
| 649 | virtual void GenMulLong(RegLocation rl_dest, RegLocation rl_src1, |
| 650 | RegLocation rl_src2) = 0; |
| 651 | virtual void GenAddLong(RegLocation rl_dest, RegLocation rl_src1, |
| 652 | RegLocation rl_src2) = 0; |
| 653 | virtual void GenAndLong(RegLocation rl_dest, RegLocation rl_src1, |
| 654 | RegLocation rl_src2) = 0; |
| 655 | virtual void GenArithOpDouble(Instruction::Code opcode, |
| 656 | RegLocation rl_dest, RegLocation rl_src1, |
| 657 | RegLocation rl_src2) = 0; |
| 658 | virtual void GenArithOpFloat(Instruction::Code opcode, RegLocation rl_dest, |
| 659 | RegLocation rl_src1, RegLocation rl_src2) = 0; |
| 660 | virtual void GenCmpFP(Instruction::Code opcode, RegLocation rl_dest, |
| 661 | RegLocation rl_src1, RegLocation rl_src2) = 0; |
| 662 | virtual void GenConversion(Instruction::Code opcode, RegLocation rl_dest, |
| 663 | RegLocation rl_src) = 0; |
| 664 | virtual bool GenInlinedCas32(CallInfo* info, bool need_write_barrier) = 0; |
| 665 | virtual bool GenInlinedMinMaxInt(CallInfo* info, bool is_min) = 0; |
| 666 | virtual bool GenInlinedSqrt(CallInfo* info) = 0; |
| 667 | virtual void GenNegLong(RegLocation rl_dest, RegLocation rl_src) = 0; |
| 668 | virtual void GenOrLong(RegLocation rl_dest, RegLocation rl_src1, |
| 669 | RegLocation rl_src2) = 0; |
| 670 | virtual void GenSubLong(RegLocation rl_dest, RegLocation rl_src1, |
| 671 | RegLocation rl_src2) = 0; |
| 672 | virtual void GenXorLong(RegLocation rl_dest, RegLocation rl_src1, |
| 673 | RegLocation rl_src2) = 0; |
| 674 | virtual LIR* GenRegMemCheck(ConditionCode c_code, int reg1, int base, |
| 675 | int offset, ThrowKind kind) = 0; |
| 676 | virtual RegLocation GenDivRem(RegLocation rl_dest, int reg_lo, int reg_hi, |
| 677 | bool is_div) = 0; |
| 678 | virtual RegLocation GenDivRemLit(RegLocation rl_dest, int reg_lo, int lit, |
| 679 | bool is_div) = 0; |
| 680 | virtual void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1, |
| 681 | RegLocation rl_src2) = 0; |
| 682 | virtual void GenDivZeroCheck(int reg_lo, int reg_hi) = 0; |
| 683 | virtual void GenEntrySequence(RegLocation* ArgLocs, |
| 684 | RegLocation rl_method) = 0; |
| 685 | virtual void GenExitSequence() = 0; |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 686 | virtual void GenFillArrayData(DexOffset table_offset, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 687 | RegLocation rl_src) = 0; |
| 688 | virtual void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias, |
| 689 | bool is_double) = 0; |
| 690 | virtual void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir) = 0; |
| 691 | virtual void GenSelect(BasicBlock* bb, MIR* mir) = 0; |
| 692 | virtual void GenMemBarrier(MemBarrierKind barrier_kind) = 0; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 693 | virtual void GenMoveException(RegLocation rl_dest) = 0; |
| 694 | virtual void GenMultiplyByTwoBitMultiplier(RegLocation rl_src, |
| 695 | RegLocation rl_result, int lit, int first_bit, |
| 696 | int second_bit) = 0; |
| 697 | virtual void GenNegDouble(RegLocation rl_dest, RegLocation rl_src) = 0; |
| 698 | virtual void GenNegFloat(RegLocation rl_dest, RegLocation rl_src) = 0; |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 699 | virtual void GenPackedSwitch(MIR* mir, DexOffset table_offset, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 700 | RegLocation rl_src) = 0; |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 701 | virtual void GenSparseSwitch(MIR* mir, DexOffset table_offset, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 702 | RegLocation rl_src) = 0; |
| 703 | virtual void GenSpecialCase(BasicBlock* bb, MIR* mir, |
| 704 | SpecialCaseHandler special_case) = 0; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 705 | virtual void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array, |
| 706 | RegLocation rl_index, RegLocation rl_dest, int scale) = 0; |
| 707 | virtual void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array, |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 708 | RegLocation rl_index, RegLocation rl_src, int scale, |
| 709 | bool card_mark) = 0; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 710 | virtual void GenShiftImmOpLong(Instruction::Code opcode, |
| 711 | RegLocation rl_dest, RegLocation rl_src1, |
| 712 | RegLocation rl_shift) = 0; |
| 713 | |
| 714 | // Required for target - single operation generators. |
| 715 | virtual LIR* OpUnconditionalBranch(LIR* target) = 0; |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 716 | virtual LIR* OpCmpBranch(ConditionCode cond, int src1, int src2, LIR* target) = 0; |
| 717 | virtual LIR* OpCmpImmBranch(ConditionCode cond, int reg, int check_value, LIR* target) = 0; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 718 | virtual LIR* OpCondBranch(ConditionCode cc, LIR* target) = 0; |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 719 | virtual LIR* OpDecAndBranch(ConditionCode c_code, int reg, LIR* target) = 0; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 720 | virtual LIR* OpFpRegCopy(int r_dest, int r_src) = 0; |
| 721 | virtual LIR* OpIT(ConditionCode cond, const char* guide) = 0; |
| 722 | virtual LIR* OpMem(OpKind op, int rBase, int disp) = 0; |
| 723 | virtual LIR* OpPcRelLoad(int reg, LIR* target) = 0; |
| 724 | virtual LIR* OpReg(OpKind op, int r_dest_src) = 0; |
| 725 | virtual LIR* OpRegCopy(int r_dest, int r_src) = 0; |
| 726 | virtual LIR* OpRegCopyNoInsert(int r_dest, int r_src) = 0; |
| 727 | virtual LIR* OpRegImm(OpKind op, int r_dest_src1, int value) = 0; |
| 728 | virtual LIR* OpRegMem(OpKind op, int r_dest, int rBase, int offset) = 0; |
| 729 | virtual LIR* OpRegReg(OpKind op, int r_dest_src1, int r_src2) = 0; |
| 730 | virtual LIR* OpRegRegImm(OpKind op, int r_dest, int r_src1, int value) = 0; |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 731 | virtual LIR* OpRegRegReg(OpKind op, int r_dest, int r_src1, int r_src2) = 0; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 732 | virtual LIR* OpTestSuspend(LIR* target) = 0; |
Ian Rogers | 468532e | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 733 | virtual LIR* OpThreadMem(OpKind op, ThreadOffset thread_offset) = 0; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 734 | virtual LIR* OpVldm(int rBase, int count) = 0; |
| 735 | virtual LIR* OpVstm(int rBase, int count) = 0; |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 736 | virtual void OpLea(int rBase, int reg1, int reg2, int scale, int offset) = 0; |
| 737 | virtual void OpRegCopyWide(int dest_lo, int dest_hi, int src_lo, int src_hi) = 0; |
Ian Rogers | 468532e | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 738 | virtual void OpTlsCmp(ThreadOffset offset, int val) = 0; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 739 | virtual bool InexpensiveConstantInt(int32_t value) = 0; |
| 740 | virtual bool InexpensiveConstantFloat(int32_t value) = 0; |
| 741 | virtual bool InexpensiveConstantLong(int64_t value) = 0; |
| 742 | virtual bool InexpensiveConstantDouble(int64_t value) = 0; |
| 743 | |
Ian Rogers | d9c4fc9 | 2013-10-01 19:45:43 -0700 | [diff] [blame] | 744 | // May be optimized by targets. |
| 745 | virtual void GenMonitorEnter(int opt_flags, RegLocation rl_src); |
| 746 | virtual void GenMonitorExit(int opt_flags, RegLocation rl_src); |
| 747 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 748 | // Temp workaround |
| 749 | void Workaround7250540(RegLocation rl_dest, int value); |
| 750 | |
| 751 | protected: |
| 752 | Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena); |
| 753 | |
| 754 | CompilationUnit* GetCompilationUnit() { |
| 755 | return cu_; |
| 756 | } |
| 757 | |
| 758 | private: |
| 759 | void GenInstanceofFinal(bool use_declaring_class, uint32_t type_idx, RegLocation rl_dest, |
| 760 | RegLocation rl_src); |
| 761 | void GenInstanceofCallingHelper(bool needs_access_check, bool type_known_final, |
| 762 | bool type_known_abstract, bool use_declaring_class, |
| 763 | bool can_assume_type_is_in_dex_cache, |
| 764 | uint32_t type_idx, RegLocation rl_dest, |
| 765 | RegLocation rl_src); |
| 766 | |
| 767 | void ClobberBody(RegisterInfo* p); |
| 768 | void ResetDefBody(RegisterInfo* p) { |
| 769 | p->def_start = NULL; |
| 770 | p->def_end = NULL; |
| 771 | } |
| 772 | |
| 773 | public: |
| 774 | // TODO: add accessors for these. |
| 775 | LIR* literal_list_; // Constants. |
| 776 | LIR* method_literal_list_; // Method literals requiring patching. |
| 777 | LIR* code_literal_list_; // Code literals requiring patching. |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 778 | LIR* first_fixup_; // Doubly-linked list of LIR nodes requiring fixups. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 779 | |
| 780 | protected: |
| 781 | CompilationUnit* const cu_; |
| 782 | MIRGraph* const mir_graph_; |
| 783 | GrowableArray<SwitchTable*> switch_tables_; |
| 784 | GrowableArray<FillArrayData*> fill_array_data_; |
| 785 | GrowableArray<LIR*> throw_launchpads_; |
| 786 | GrowableArray<LIR*> suspend_launchpads_; |
| 787 | GrowableArray<LIR*> intrinsic_launchpads_; |
buzbee | bd663de | 2013-09-10 15:41:31 -0700 | [diff] [blame] | 788 | GrowableArray<RegisterInfo*> tempreg_info_; |
| 789 | GrowableArray<RegisterInfo*> reginfo_map_; |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 790 | GrowableArray<void*> pointer_storage_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 791 | /* |
| 792 | * Holds mapping from native PC to dex PC for safepoints where we may deoptimize. |
| 793 | * Native PC is on the return address of the safepointed operation. Dex PC is for |
| 794 | * the instruction being executed at the safepoint. |
| 795 | */ |
| 796 | std::vector<uint32_t> pc2dex_mapping_table_; |
| 797 | /* |
| 798 | * Holds mapping from Dex PC to native PC for catch entry points. Native PC and Dex PC |
| 799 | * immediately preceed the instruction. |
| 800 | */ |
| 801 | std::vector<uint32_t> dex2pc_mapping_table_; |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 802 | CodeOffset current_code_offset_; // Working byte offset of machine instructons. |
| 803 | CodeOffset data_offset_; // starting offset of literal pool. |
| 804 | size_t total_size_; // header + code size. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 805 | LIR* block_label_list_; |
| 806 | PromotionMap* promotion_map_; |
| 807 | /* |
| 808 | * TODO: The code generation utilities don't have a built-in |
| 809 | * mechanism to propagate the original Dalvik opcode address to the |
| 810 | * associated generated instructions. For the trace compiler, this wasn't |
| 811 | * necessary because the interpreter handled all throws and debugging |
| 812 | * requests. For now we'll handle this by placing the Dalvik offset |
| 813 | * in the CompilationUnit struct before codegen for each instruction. |
| 814 | * The low-level LIR creation utilites will pull it from here. Rework this. |
| 815 | */ |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 816 | DexOffset current_dalvik_offset_; |
| 817 | size_t estimated_native_code_size_; // Just an estimate; used to reserve code_buffer_ size. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 818 | RegisterPool* reg_pool_; |
| 819 | /* |
| 820 | * Sanity checking for the register temp tracking. The same ssa |
| 821 | * name should never be associated with one temp register per |
| 822 | * instruction compilation. |
| 823 | */ |
| 824 | int live_sreg_; |
| 825 | CodeBuffer code_buffer_; |
Ian Rogers | 96faf5b | 2013-08-09 22:05:32 -0700 | [diff] [blame] | 826 | // The encoding mapping table data (dex -> pc offset and pc offset -> dex) with a size prefix. |
| 827 | UnsignedLeb128EncodingVector encoded_mapping_table_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 828 | std::vector<uint32_t> core_vmap_table_; |
| 829 | std::vector<uint32_t> fp_vmap_table_; |
| 830 | std::vector<uint8_t> native_gc_map_; |
| 831 | int num_core_spills_; |
| 832 | int num_fp_spills_; |
| 833 | int frame_size_; |
| 834 | unsigned int core_spill_mask_; |
| 835 | unsigned int fp_spill_mask_; |
| 836 | LIR* first_lir_insn_; |
| 837 | LIR* last_lir_insn_; |
| 838 | }; // Class Mir2Lir |
| 839 | |
| 840 | } // namespace art |
| 841 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 842 | #endif // ART_COMPILER_DEX_QUICK_MIR_TO_LIR_H_ |