blob: 58a77c7a0a07c1452c5575422cb009c0147e6f07 [file] [log] [blame]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001/*
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 Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_COMPILER_DEX_QUICK_MIR_TO_LIR_H_
18#define ART_COMPILER_DEX_QUICK_MIR_TO_LIR_H_
Brian Carlstrom7940e442013-07-12 13:46:57 -070019
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 Rogers96faf5b2013-08-09 22:05:32 -070028#include "leb128_encoder.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070029#include "safe_map.h"
30
31namespace art {
32
buzbee0d829482013-10-11 15:24:55 -070033/*
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 */
37typedef uint32_t DexOffset; // Dex offset in code units.
38typedef uint16_t NarrowDexOffset; // For use in structs, Dex offsets range from 0 .. 0xffff.
39typedef uint32_t CodeOffset; // Native code offset in bytes.
40
Brian Carlstrom7940e442013-07-12 13:46:57 -070041// 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
102struct BasicBlock;
103struct CallInfo;
104struct CompilationUnit;
105struct MIR;
buzbeeb48819d2013-09-14 16:15:25 -0700106struct LIR;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700107struct RegLocation;
108struct RegisterInfo;
Vladimir Marko5c96e6b2013-11-14 15:34:17 +0000109class DexFileMethodInliner;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700110class MIRGraph;
111class Mir2Lir;
112
113typedef int (*NextCallInsn)(CompilationUnit*, CallInfo*, int,
114 const MethodReference& target_method,
115 uint32_t method_idx, uintptr_t direct_code,
116 uintptr_t direct_method, InvokeType type);
117
118typedef std::vector<uint8_t> CodeBuffer;
119
buzbeeb48819d2013-09-14 16:15:25 -0700120struct UseDefMasks {
121 uint64_t use_mask; // Resource mask for use.
122 uint64_t def_mask; // Resource mask for def.
123};
124
125struct AssemblyInfo {
126 LIR* pcrel_next; // Chain of LIR nodes needing pc relative fixups.
127 uint8_t bytes[16]; // Encoded instruction bytes.
128};
Brian Carlstrom7940e442013-07-12 13:46:57 -0700129
130struct LIR {
buzbee0d829482013-10-11 15:24:55 -0700131 CodeOffset offset; // Offset of this instruction.
132 NarrowDexOffset dalvik_offset; // Offset of Dalvik opcode in code units (16-bit words).
buzbeeb48819d2013-09-14 16:15:25 -0700133 int16_t opcode;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700134 LIR* next;
135 LIR* prev;
136 LIR* target;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700137 struct {
buzbeeb48819d2013-09-14 16:15:25 -0700138 unsigned int alias_info:17; // For Dalvik register disambiguation.
139 bool is_nop:1; // LIR is optimized away.
140 unsigned int size:4; // Note: size of encoded instruction is in bytes.
141 bool use_def_invalid:1; // If true, masks should not be used.
142 unsigned int generation:1; // Used to track visitation state during fixup pass.
143 unsigned int fixup:8; // Fixup kind.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700144 } flags;
buzbeeb48819d2013-09-14 16:15:25 -0700145 union {
buzbee0d829482013-10-11 15:24:55 -0700146 UseDefMasks m; // Use & Def masks used during optimization.
147 AssemblyInfo a; // Instruction encoding used during assembly phase.
buzbeeb48819d2013-09-14 16:15:25 -0700148 } u;
buzbee0d829482013-10-11 15:24:55 -0700149 int32_t operands[5]; // [0..4] = [dest, src1, src2, extra, extra2].
Brian Carlstrom7940e442013-07-12 13:46:57 -0700150};
151
152// Target-specific initialization.
153Mir2Lir* ArmCodeGenerator(CompilationUnit* const cu, MIRGraph* const mir_graph,
154 ArenaAllocator* const arena);
155Mir2Lir* MipsCodeGenerator(CompilationUnit* const cu, MIRGraph* const mir_graph,
156 ArenaAllocator* const arena);
157Mir2Lir* X86CodeGenerator(CompilationUnit* const cu, MIRGraph* const mir_graph,
158 ArenaAllocator* const arena);
159
160// Utility macros to traverse the LIR list.
161#define NEXT_LIR(lir) (lir->next)
162#define PREV_LIR(lir) (lir->prev)
163
164// Defines for alias_info (tracks Dalvik register references).
165#define DECODE_ALIAS_INFO_REG(X) (X & 0xffff)
buzbeeb48819d2013-09-14 16:15:25 -0700166#define DECODE_ALIAS_INFO_WIDE_FLAG (0x10000)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700167#define DECODE_ALIAS_INFO_WIDE(X) ((X & DECODE_ALIAS_INFO_WIDE_FLAG) ? 1 : 0)
168#define ENCODE_ALIAS_INFO(REG, ISWIDE) (REG | (ISWIDE ? DECODE_ALIAS_INFO_WIDE_FLAG : 0))
169
170// Common resource macros.
171#define ENCODE_CCODE (1ULL << kCCode)
172#define ENCODE_FP_STATUS (1ULL << kFPStatus)
173
174// Abstract memory locations.
175#define ENCODE_DALVIK_REG (1ULL << kDalvikReg)
176#define ENCODE_LITERAL (1ULL << kLiteral)
177#define ENCODE_HEAP_REF (1ULL << kHeapRef)
178#define ENCODE_MUST_NOT_ALIAS (1ULL << kMustNotAlias)
179
180#define ENCODE_ALL (~0ULL)
181#define ENCODE_MEM (ENCODE_DALVIK_REG | ENCODE_LITERAL | \
182 ENCODE_HEAP_REF | ENCODE_MUST_NOT_ALIAS)
buzbeec729a6b2013-09-14 16:04:31 -0700183
184// Mask to denote sreg as the start of a double. Must not interfere with low 16 bits.
185#define STARTING_DOUBLE_SREG 0x10000
186
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700187// TODO: replace these macros
Brian Carlstrom7940e442013-07-12 13:46:57 -0700188#define SLOW_FIELD_PATH (cu_->enable_debug & (1 << kDebugSlowFieldPath))
189#define SLOW_INVOKE_PATH (cu_->enable_debug & (1 << kDebugSlowInvokePath))
190#define SLOW_STRING_PATH (cu_->enable_debug & (1 << kDebugSlowStringPath))
191#define SLOW_TYPE_PATH (cu_->enable_debug & (1 << kDebugSlowTypePath))
192#define EXERCISE_SLOWEST_STRING_PATH (cu_->enable_debug & (1 << kDebugSlowestStringPath))
Brian Carlstrom7940e442013-07-12 13:46:57 -0700193
194class Mir2Lir : public Backend {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700195 public:
buzbee0d829482013-10-11 15:24:55 -0700196 /*
197 * Auxiliary information describing the location of data embedded in the Dalvik
198 * byte code stream.
199 */
200 struct EmbeddedData {
201 CodeOffset offset; // Code offset of data block.
202 const uint16_t* table; // Original dex data.
203 DexOffset vaddr; // Dalvik offset of parent opcode.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700204 };
205
buzbee0d829482013-10-11 15:24:55 -0700206 struct FillArrayData : EmbeddedData {
207 int32_t size;
208 };
209
210 struct SwitchTable : EmbeddedData {
211 LIR* anchor; // Reference instruction for relative offsets.
212 LIR** targets; // Array of case targets.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700213 };
214
215 /* Static register use counts */
216 struct RefCounts {
217 int count;
218 int s_reg;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700219 };
220
221 /*
222 * Data structure tracking the mapping between a Dalvik register (pair) and a
223 * native register (pair). The idea is to reuse the previously loaded value
224 * if possible, otherwise to keep the value in a native register as long as
225 * possible.
226 */
227 struct RegisterInfo {
228 int reg; // Reg number
229 bool in_use; // Has it been allocated?
230 bool is_temp; // Can allocate as temp?
231 bool pair; // Part of a register pair?
232 int partner; // If pair, other reg of pair.
233 bool live; // Is there an associated SSA name?
234 bool dirty; // If live, is it dirty?
235 int s_reg; // Name of live value.
236 LIR *def_start; // Starting inst in last def sequence.
237 LIR *def_end; // Ending inst in last def sequence.
238 };
239
Brian Carlstrom6f485c62013-07-18 15:35:35 -0700240 struct RegisterPool {
241 int num_core_regs;
242 RegisterInfo *core_regs;
243 int next_core_reg;
244 int num_fp_regs;
245 RegisterInfo *FPRegs;
246 int next_fp_reg;
247 };
Brian Carlstrom7940e442013-07-12 13:46:57 -0700248
249 struct PromotionMap {
250 RegLocationType core_location:3;
251 uint8_t core_reg;
252 RegLocationType fp_location:3;
253 uint8_t FpReg;
254 bool first_in_pair;
255 };
256
Brian Carlstrom9b7085a2013-07-18 15:15:21 -0700257 virtual ~Mir2Lir() {}
Brian Carlstrom7940e442013-07-12 13:46:57 -0700258
259 int32_t s4FromSwitchData(const void* switch_data) {
260 return *reinterpret_cast<const int32_t*>(switch_data);
261 }
262
263 RegisterClass oat_reg_class_by_size(OpSize size) {
264 return (size == kUnsignedHalf || size == kSignedHalf || size == kUnsignedByte ||
Brian Carlstromdf629502013-07-17 22:39:56 -0700265 size == kSignedByte) ? kCoreReg : kAnyReg;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700266 }
267
268 size_t CodeBufferSizeInBytes() {
269 return code_buffer_.size() / sizeof(code_buffer_[0]);
270 }
271
buzbee409fe942013-10-11 10:49:56 -0700272 bool IsPseudoLirOp(int opcode) {
273 return (opcode < 0);
274 }
275
buzbee0d829482013-10-11 15:24:55 -0700276 /*
277 * LIR operands are 32-bit integers. Sometimes, (especially for managing
278 * instructions which require PC-relative fixups), we need the operands to carry
279 * pointers. To do this, we assign these pointers an index in pointer_storage_, and
280 * hold that index in the operand array.
281 * TUNING: If use of these utilities becomes more common on 32-bit builds, it
282 * may be worth conditionally-compiling a set of identity functions here.
283 */
284 uint32_t WrapPointer(void* pointer) {
285 uint32_t res = pointer_storage_.Size();
286 pointer_storage_.Insert(pointer);
287 return res;
288 }
289
290 void* UnwrapPointer(size_t index) {
291 return pointer_storage_.Get(index);
292 }
293
294 // strdup(), but allocates from the arena.
295 char* ArenaStrdup(const char* str) {
296 size_t len = strlen(str) + 1;
297 char* res = reinterpret_cast<char*>(arena_->Alloc(len, ArenaAllocator::kAllocMisc));
298 if (res != NULL) {
299 strncpy(res, str, len);
300 }
301 return res;
302 }
303
Brian Carlstrom7940e442013-07-12 13:46:57 -0700304 // Shared by all targets - implemented in codegen_util.cc
305 void AppendLIR(LIR* lir);
306 void InsertLIRBefore(LIR* current_lir, LIR* new_lir);
307 void InsertLIRAfter(LIR* current_lir, LIR* new_lir);
308
309 int ComputeFrameSize();
310 virtual void Materialize();
311 virtual CompiledMethod* GetCompiledMethod();
312 void MarkSafepointPC(LIR* inst);
Ian Rogers9b297bf2013-09-06 11:11:25 -0700313 bool FastInstance(uint32_t field_idx, bool is_put, int* field_offset, bool* is_volatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700314 void SetupResourceMasks(LIR* lir);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700315 void SetMemRefType(LIR* lir, bool is_load, int mem_type);
316 void AnnotateDalvikRegAccess(LIR* lir, int reg_id, bool is_load, bool is64bit);
317 void SetupRegMask(uint64_t* mask, int reg);
318 void DumpLIRInsn(LIR* arg, unsigned char* base_addr);
319 void DumpPromotionMap();
320 void CodegenDump();
buzbee0d829482013-10-11 15:24:55 -0700321 LIR* RawLIR(DexOffset dalvik_offset, int opcode, int op0 = 0, int op1 = 0,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700322 int op2 = 0, int op3 = 0, int op4 = 0, LIR* target = NULL);
323 LIR* NewLIR0(int opcode);
324 LIR* NewLIR1(int opcode, int dest);
325 LIR* NewLIR2(int opcode, int dest, int src1);
326 LIR* NewLIR3(int opcode, int dest, int src1, int src2);
327 LIR* NewLIR4(int opcode, int dest, int src1, int src2, int info);
328 LIR* NewLIR5(int opcode, int dest, int src1, int src2, int info1, int info2);
329 LIR* ScanLiteralPool(LIR* data_target, int value, unsigned int delta);
330 LIR* ScanLiteralPoolWide(LIR* data_target, int val_lo, int val_hi);
331 LIR* AddWordData(LIR* *constant_list_p, int value);
332 LIR* AddWideData(LIR* *constant_list_p, int val_lo, int val_hi);
333 void ProcessSwitchTables();
334 void DumpSparseSwitchTable(const uint16_t* table);
335 void DumpPackedSwitchTable(const uint16_t* table);
buzbee0d829482013-10-11 15:24:55 -0700336 void MarkBoundary(DexOffset offset, const char* inst_str);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700337 void NopLIR(LIR* lir);
buzbee252254b2013-09-08 16:20:53 -0700338 void UnlinkLIR(LIR* lir);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700339 bool EvaluateBranch(Instruction::Code opcode, int src1, int src2);
340 bool IsInexpensiveConstant(RegLocation rl_src);
341 ConditionCode FlipComparisonOrder(ConditionCode before);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700342 void DumpMappingTable(const char* table_name, const char* descriptor,
343 const char* name, const Signature& signature,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700344 const std::vector<uint32_t>& v);
345 void InstallLiteralPools();
346 void InstallSwitchTables();
347 void InstallFillArrayData();
348 bool VerifyCatchEntries();
349 void CreateMappingTables();
350 void CreateNativeGcMap();
buzbee0d829482013-10-11 15:24:55 -0700351 int AssignLiteralOffset(CodeOffset offset);
352 int AssignSwitchTablesOffset(CodeOffset offset);
353 int AssignFillArrayDataOffset(CodeOffset offset);
354 LIR* InsertCaseLabel(DexOffset vaddr, int keyVal);
355 void MarkPackedCaseLabels(Mir2Lir::SwitchTable* tab_rec);
356 void MarkSparseCaseLabels(Mir2Lir::SwitchTable* tab_rec);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700357
358 // Shared by all targets - implemented in local_optimizations.cc
359 void ConvertMemOpIntoMove(LIR* orig_lir, int dest, int src);
360 void ApplyLoadStoreElimination(LIR* head_lir, LIR* tail_lir);
361 void ApplyLoadHoisting(LIR* head_lir, LIR* tail_lir);
362 void ApplyLocalOptimizations(LIR* head_lir, LIR* tail_lir);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700363
364 // Shared by all targets - implemented in ralloc_util.cc
365 int GetSRegHi(int lowSreg);
366 bool oat_live_out(int s_reg);
367 int oatSSASrc(MIR* mir, int num);
368 void SimpleRegAlloc();
369 void ResetRegPool();
370 void CompilerInitPool(RegisterInfo* regs, int* reg_nums, int num);
371 void DumpRegPool(RegisterInfo* p, int num_regs);
372 void DumpCoreRegPool();
373 void DumpFpRegPool();
374 /* Mark a temp register as dead. Does not affect allocation state. */
375 void Clobber(int reg) {
376 ClobberBody(GetRegInfo(reg));
377 }
378 void ClobberSRegBody(RegisterInfo* p, int num_regs, int s_reg);
379 void ClobberSReg(int s_reg);
380 int SRegToPMap(int s_reg);
381 void RecordCorePromotion(int reg, int s_reg);
382 int AllocPreservedCoreReg(int s_reg);
383 void RecordFpPromotion(int reg, int s_reg);
buzbeec729a6b2013-09-14 16:04:31 -0700384 int AllocPreservedSingle(int s_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700385 int AllocPreservedDouble(int s_reg);
buzbeec729a6b2013-09-14 16:04:31 -0700386 int AllocTempBody(RegisterInfo* p, int num_regs, int* next_temp, bool required);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700387 int AllocTempDouble();
388 int AllocFreeTemp();
389 int AllocTemp();
390 int AllocTempFloat();
391 RegisterInfo* AllocLiveBody(RegisterInfo* p, int num_regs, int s_reg);
392 RegisterInfo* AllocLive(int s_reg, int reg_class);
393 void FreeTemp(int reg);
394 RegisterInfo* IsLive(int reg);
395 RegisterInfo* IsTemp(int reg);
396 RegisterInfo* IsPromoted(int reg);
397 bool IsDirty(int reg);
398 void LockTemp(int reg);
399 void ResetDef(int reg);
400 void NullifyRange(LIR *start, LIR *finish, int s_reg1, int s_reg2);
401 void MarkDef(RegLocation rl, LIR *start, LIR *finish);
402 void MarkDefWide(RegLocation rl, LIR *start, LIR *finish);
403 RegLocation WideToNarrow(RegLocation rl);
404 void ResetDefLoc(RegLocation rl);
405 void ResetDefLocWide(RegLocation rl);
406 void ResetDefTracking();
407 void ClobberAllRegs();
408 void FlushAllRegsBody(RegisterInfo* info, int num_regs);
409 void FlushAllRegs();
410 bool RegClassMatches(int reg_class, int reg);
411 void MarkLive(int reg, int s_reg);
412 void MarkTemp(int reg);
413 void UnmarkTemp(int reg);
414 void MarkPair(int low_reg, int high_reg);
415 void MarkClean(RegLocation loc);
416 void MarkDirty(RegLocation loc);
417 void MarkInUse(int reg);
418 void CopyRegInfo(int new_reg, int old_reg);
419 bool CheckCorePoolSanity();
420 RegLocation UpdateLoc(RegLocation loc);
421 RegLocation UpdateLocWide(RegLocation loc);
422 RegLocation UpdateRawLoc(RegLocation loc);
423 RegLocation EvalLocWide(RegLocation loc, int reg_class, bool update);
424 RegLocation EvalLoc(RegLocation loc, int reg_class, bool update);
buzbeec729a6b2013-09-14 16:04:31 -0700425 void CountRefs(RefCounts* core_counts, RefCounts* fp_counts, size_t num_regs);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700426 void DumpCounts(const RefCounts* arr, int size, const char* msg);
427 void DoPromotion();
428 int VRegOffset(int v_reg);
429 int SRegOffset(int s_reg);
430 RegLocation GetReturnWide(bool is_double);
431 RegLocation GetReturn(bool is_float);
buzbeebd663de2013-09-10 15:41:31 -0700432 RegisterInfo* GetRegInfo(int reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700433
434 // Shared by all targets - implemented in gen_common.cc.
buzbee11b63d12013-08-27 07:34:17 -0700435 bool HandleEasyDivRem(Instruction::Code dalvik_opcode, bool is_div,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700436 RegLocation rl_src, RegLocation rl_dest, int lit);
437 bool HandleEasyMultiply(RegLocation rl_src, RegLocation rl_dest, int lit);
438 void HandleSuspendLaunchPads();
439 void HandleIntrinsicLaunchPads();
440 void HandleThrowLaunchPads();
441 void GenBarrier();
442 LIR* GenCheck(ConditionCode c_code, ThrowKind kind);
443 LIR* GenImmedCheck(ConditionCode c_code, int reg, int imm_val,
444 ThrowKind kind);
445 LIR* GenNullCheck(int s_reg, int m_reg, int opt_flags);
446 LIR* GenRegRegCheck(ConditionCode c_code, int reg1, int reg2,
447 ThrowKind kind);
448 void GenCompareAndBranch(Instruction::Code opcode, RegLocation rl_src1,
449 RegLocation rl_src2, LIR* taken, LIR* fall_through);
450 void GenCompareZeroAndBranch(Instruction::Code opcode, RegLocation rl_src,
451 LIR* taken, LIR* fall_through);
452 void GenIntToLong(RegLocation rl_dest, RegLocation rl_src);
453 void GenIntNarrowing(Instruction::Code opcode, RegLocation rl_dest,
454 RegLocation rl_src);
455 void GenNewArray(uint32_t type_idx, RegLocation rl_dest,
456 RegLocation rl_src);
457 void GenFilledNewArray(CallInfo* info);
458 void GenSput(uint32_t field_idx, RegLocation rl_src,
459 bool is_long_or_double, bool is_object);
460 void GenSget(uint32_t field_idx, RegLocation rl_dest,
461 bool is_long_or_double, bool is_object);
462 void GenIGet(uint32_t field_idx, int opt_flags, OpSize size,
463 RegLocation rl_dest, RegLocation rl_obj, bool is_long_or_double, bool is_object);
464 void GenIPut(uint32_t field_idx, int opt_flags, OpSize size,
465 RegLocation rl_src, RegLocation rl_obj, bool is_long_or_double, bool is_object);
Ian Rogersa9a82542013-10-04 11:17:26 -0700466 void GenArrayObjPut(int opt_flags, RegLocation rl_array, RegLocation rl_index,
467 RegLocation rl_src);
468
Brian Carlstrom7940e442013-07-12 13:46:57 -0700469 void GenConstClass(uint32_t type_idx, RegLocation rl_dest);
470 void GenConstString(uint32_t string_idx, RegLocation rl_dest);
471 void GenNewInstance(uint32_t type_idx, RegLocation rl_dest);
472 void GenThrow(RegLocation rl_src);
473 void GenInstanceof(uint32_t type_idx, RegLocation rl_dest,
474 RegLocation rl_src);
475 void GenCheckCast(uint32_t insn_idx, uint32_t type_idx,
476 RegLocation rl_src);
477 void GenLong3Addr(OpKind first_op, OpKind second_op, RegLocation rl_dest,
478 RegLocation rl_src1, RegLocation rl_src2);
479 void GenShiftOpLong(Instruction::Code opcode, RegLocation rl_dest,
480 RegLocation rl_src1, RegLocation rl_shift);
481 void GenArithOpInt(Instruction::Code opcode, RegLocation rl_dest,
482 RegLocation rl_src1, RegLocation rl_src2);
483 void GenArithOpIntLit(Instruction::Code opcode, RegLocation rl_dest,
484 RegLocation rl_src, int lit);
485 void GenArithOpLong(Instruction::Code opcode, RegLocation rl_dest,
486 RegLocation rl_src1, RegLocation rl_src2);
Ian Rogers468532e2013-08-05 10:56:33 -0700487 void GenConversionCall(ThreadOffset func_offset, RegLocation rl_dest,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700488 RegLocation rl_src);
489 void GenSuspendTest(int opt_flags);
490 void GenSuspendTestAndBranch(int opt_flags, LIR* target);
491
492 // Shared by all targets - implemented in gen_invoke.cc.
Ian Rogers468532e2013-08-05 10:56:33 -0700493 int CallHelperSetup(ThreadOffset helper_offset);
494 LIR* CallHelper(int r_tgt, ThreadOffset helper_offset, bool safepoint_pc);
495 void CallRuntimeHelperImm(ThreadOffset helper_offset, int arg0, bool safepoint_pc);
496 void CallRuntimeHelperReg(ThreadOffset helper_offset, int arg0, bool safepoint_pc);
497 void CallRuntimeHelperRegLocation(ThreadOffset helper_offset, RegLocation arg0,
498 bool safepoint_pc);
499 void CallRuntimeHelperImmImm(ThreadOffset helper_offset, int arg0, int arg1,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700500 bool safepoint_pc);
Ian Rogers468532e2013-08-05 10:56:33 -0700501 void CallRuntimeHelperImmRegLocation(ThreadOffset helper_offset, int arg0,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700502 RegLocation arg1, bool safepoint_pc);
Ian Rogers468532e2013-08-05 10:56:33 -0700503 void CallRuntimeHelperRegLocationImm(ThreadOffset helper_offset, RegLocation arg0,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700504 int arg1, bool safepoint_pc);
Ian Rogers468532e2013-08-05 10:56:33 -0700505 void CallRuntimeHelperImmReg(ThreadOffset helper_offset, int arg0, int arg1,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700506 bool safepoint_pc);
Ian Rogers468532e2013-08-05 10:56:33 -0700507 void CallRuntimeHelperRegImm(ThreadOffset helper_offset, int arg0, int arg1,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700508 bool safepoint_pc);
Ian Rogers468532e2013-08-05 10:56:33 -0700509 void CallRuntimeHelperImmMethod(ThreadOffset helper_offset, int arg0,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700510 bool safepoint_pc);
Ian Rogers468532e2013-08-05 10:56:33 -0700511 void CallRuntimeHelperRegLocationRegLocation(ThreadOffset helper_offset,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700512 RegLocation arg0, RegLocation arg1,
513 bool safepoint_pc);
Ian Rogers468532e2013-08-05 10:56:33 -0700514 void CallRuntimeHelperRegReg(ThreadOffset helper_offset, int arg0, int arg1,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700515 bool safepoint_pc);
Ian Rogers468532e2013-08-05 10:56:33 -0700516 void CallRuntimeHelperRegRegImm(ThreadOffset helper_offset, int arg0, int arg1,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700517 int arg2, bool safepoint_pc);
Ian Rogers468532e2013-08-05 10:56:33 -0700518 void CallRuntimeHelperImmMethodRegLocation(ThreadOffset helper_offset, int arg0,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700519 RegLocation arg2, bool safepoint_pc);
Ian Rogers468532e2013-08-05 10:56:33 -0700520 void CallRuntimeHelperImmMethodImm(ThreadOffset helper_offset, int arg0, int arg2,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700521 bool safepoint_pc);
Ian Rogers468532e2013-08-05 10:56:33 -0700522 void CallRuntimeHelperImmRegLocationRegLocation(ThreadOffset helper_offset,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700523 int arg0, RegLocation arg1, RegLocation arg2,
524 bool safepoint_pc);
Ian Rogersa9a82542013-10-04 11:17:26 -0700525 void CallRuntimeHelperRegLocationRegLocationRegLocation(ThreadOffset helper_offset,
526 RegLocation arg0, RegLocation arg1,
527 RegLocation arg2,
528 bool safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700529 void GenInvoke(CallInfo* info);
530 void FlushIns(RegLocation* ArgLocs, RegLocation rl_method);
531 int GenDalvikArgsNoRange(CallInfo* info, int call_state, LIR** pcrLabel,
532 NextCallInsn next_call_insn,
533 const MethodReference& target_method,
534 uint32_t vtable_idx,
535 uintptr_t direct_code, uintptr_t direct_method, InvokeType type,
536 bool skip_this);
537 int GenDalvikArgsRange(CallInfo* info, int call_state, LIR** pcrLabel,
538 NextCallInsn next_call_insn,
539 const MethodReference& target_method,
540 uint32_t vtable_idx,
541 uintptr_t direct_code, uintptr_t direct_method, InvokeType type,
542 bool skip_this);
543 RegLocation InlineTarget(CallInfo* info);
544 RegLocation InlineTargetWide(CallInfo* info);
545
546 bool GenInlinedCharAt(CallInfo* info);
547 bool GenInlinedStringIsEmptyOrLength(CallInfo* info, bool is_empty);
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +0000548 bool GenInlinedReverseBytes(CallInfo* info, OpSize size);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700549 bool GenInlinedAbsInt(CallInfo* info);
550 bool GenInlinedAbsLong(CallInfo* info);
551 bool GenInlinedFloatCvt(CallInfo* info);
552 bool GenInlinedDoubleCvt(CallInfo* info);
553 bool GenInlinedIndexOf(CallInfo* info, bool zero_based);
554 bool GenInlinedStringCompareTo(CallInfo* info);
555 bool GenInlinedCurrentThread(CallInfo* info);
556 bool GenInlinedUnsafeGet(CallInfo* info, bool is_long, bool is_volatile);
557 bool GenInlinedUnsafePut(CallInfo* info, bool is_long, bool is_object,
558 bool is_volatile, bool is_ordered);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700559 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.
buzbee11b63d12013-08-27 07:34:17 -0700591 virtual bool SmallLiteralDivRem(Instruction::Code dalvik_opcode, bool is_div,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700592 RegLocation rl_src, RegLocation rl_dest, int lit) = 0;
Ian Rogers468532e2013-08-05 10:56:33 -0700593 virtual int LoadHelper(ThreadOffset offset) = 0;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700594 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 Carlstrom7940e442013-07-12 13:46:57 -0700616 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.
buzbeeb48819d2013-09-14 16:15:25 -0700635 virtual void AssembleLIR() = 0;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700636 virtual void DumpResourceMask(LIR* lir, uint64_t mask, const char* prefix) = 0;
buzbeeb48819d2013-09-14 16:15:25 -0700637 virtual void SetupTargetResourceMasks(LIR* lir, uint64_t flags) = 0;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700638 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;
Vladimir Markoe508a202013-11-04 15:24:22 +0000667 virtual bool GenInlinedPeek(CallInfo* info, OpSize size) = 0;
668 virtual bool GenInlinedPoke(CallInfo* info, OpSize size) = 0;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700669 virtual void GenNegLong(RegLocation rl_dest, RegLocation rl_src) = 0;
670 virtual void GenOrLong(RegLocation rl_dest, RegLocation rl_src1,
671 RegLocation rl_src2) = 0;
672 virtual void GenSubLong(RegLocation rl_dest, RegLocation rl_src1,
673 RegLocation rl_src2) = 0;
674 virtual void GenXorLong(RegLocation rl_dest, RegLocation rl_src1,
675 RegLocation rl_src2) = 0;
676 virtual LIR* GenRegMemCheck(ConditionCode c_code, int reg1, int base,
677 int offset, ThrowKind kind) = 0;
678 virtual RegLocation GenDivRem(RegLocation rl_dest, int reg_lo, int reg_hi,
679 bool is_div) = 0;
680 virtual RegLocation GenDivRemLit(RegLocation rl_dest, int reg_lo, int lit,
681 bool is_div) = 0;
682 virtual void GenCmpLong(RegLocation rl_dest, RegLocation rl_src1,
683 RegLocation rl_src2) = 0;
684 virtual void GenDivZeroCheck(int reg_lo, int reg_hi) = 0;
685 virtual void GenEntrySequence(RegLocation* ArgLocs,
686 RegLocation rl_method) = 0;
687 virtual void GenExitSequence() = 0;
buzbee0d829482013-10-11 15:24:55 -0700688 virtual void GenFillArrayData(DexOffset table_offset,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700689 RegLocation rl_src) = 0;
690 virtual void GenFusedFPCmpBranch(BasicBlock* bb, MIR* mir, bool gt_bias,
691 bool is_double) = 0;
692 virtual void GenFusedLongCmpBranch(BasicBlock* bb, MIR* mir) = 0;
693 virtual void GenSelect(BasicBlock* bb, MIR* mir) = 0;
694 virtual void GenMemBarrier(MemBarrierKind barrier_kind) = 0;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700695 virtual void GenMoveException(RegLocation rl_dest) = 0;
696 virtual void GenMultiplyByTwoBitMultiplier(RegLocation rl_src,
697 RegLocation rl_result, int lit, int first_bit,
698 int second_bit) = 0;
699 virtual void GenNegDouble(RegLocation rl_dest, RegLocation rl_src) = 0;
700 virtual void GenNegFloat(RegLocation rl_dest, RegLocation rl_src) = 0;
buzbee0d829482013-10-11 15:24:55 -0700701 virtual void GenPackedSwitch(MIR* mir, DexOffset table_offset,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700702 RegLocation rl_src) = 0;
buzbee0d829482013-10-11 15:24:55 -0700703 virtual void GenSparseSwitch(MIR* mir, DexOffset table_offset,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700704 RegLocation rl_src) = 0;
705 virtual void GenSpecialCase(BasicBlock* bb, MIR* mir,
706 SpecialCaseHandler special_case) = 0;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700707 virtual void GenArrayGet(int opt_flags, OpSize size, RegLocation rl_array,
708 RegLocation rl_index, RegLocation rl_dest, int scale) = 0;
709 virtual void GenArrayPut(int opt_flags, OpSize size, RegLocation rl_array,
Ian Rogersa9a82542013-10-04 11:17:26 -0700710 RegLocation rl_index, RegLocation rl_src, int scale,
711 bool card_mark) = 0;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700712 virtual void GenShiftImmOpLong(Instruction::Code opcode,
713 RegLocation rl_dest, RegLocation rl_src1,
714 RegLocation rl_shift) = 0;
715
716 // Required for target - single operation generators.
717 virtual LIR* OpUnconditionalBranch(LIR* target) = 0;
buzbee0d829482013-10-11 15:24:55 -0700718 virtual LIR* OpCmpBranch(ConditionCode cond, int src1, int src2, LIR* target) = 0;
719 virtual LIR* OpCmpImmBranch(ConditionCode cond, int reg, int check_value, LIR* target) = 0;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700720 virtual LIR* OpCondBranch(ConditionCode cc, LIR* target) = 0;
buzbee0d829482013-10-11 15:24:55 -0700721 virtual LIR* OpDecAndBranch(ConditionCode c_code, int reg, LIR* target) = 0;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700722 virtual LIR* OpFpRegCopy(int r_dest, int r_src) = 0;
723 virtual LIR* OpIT(ConditionCode cond, const char* guide) = 0;
724 virtual LIR* OpMem(OpKind op, int rBase, int disp) = 0;
725 virtual LIR* OpPcRelLoad(int reg, LIR* target) = 0;
726 virtual LIR* OpReg(OpKind op, int r_dest_src) = 0;
727 virtual LIR* OpRegCopy(int r_dest, int r_src) = 0;
728 virtual LIR* OpRegCopyNoInsert(int r_dest, int r_src) = 0;
729 virtual LIR* OpRegImm(OpKind op, int r_dest_src1, int value) = 0;
730 virtual LIR* OpRegMem(OpKind op, int r_dest, int rBase, int offset) = 0;
731 virtual LIR* OpRegReg(OpKind op, int r_dest_src1, int r_src2) = 0;
732 virtual LIR* OpRegRegImm(OpKind op, int r_dest, int r_src1, int value) = 0;
buzbee0d829482013-10-11 15:24:55 -0700733 virtual LIR* OpRegRegReg(OpKind op, int r_dest, int r_src1, int r_src2) = 0;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700734 virtual LIR* OpTestSuspend(LIR* target) = 0;
Ian Rogers468532e2013-08-05 10:56:33 -0700735 virtual LIR* OpThreadMem(OpKind op, ThreadOffset thread_offset) = 0;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700736 virtual LIR* OpVldm(int rBase, int count) = 0;
737 virtual LIR* OpVstm(int rBase, int count) = 0;
buzbee0d829482013-10-11 15:24:55 -0700738 virtual void OpLea(int rBase, int reg1, int reg2, int scale, int offset) = 0;
739 virtual void OpRegCopyWide(int dest_lo, int dest_hi, int src_lo, int src_hi) = 0;
Ian Rogers468532e2013-08-05 10:56:33 -0700740 virtual void OpTlsCmp(ThreadOffset offset, int val) = 0;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700741 virtual bool InexpensiveConstantInt(int32_t value) = 0;
742 virtual bool InexpensiveConstantFloat(int32_t value) = 0;
743 virtual bool InexpensiveConstantLong(int64_t value) = 0;
744 virtual bool InexpensiveConstantDouble(int64_t value) = 0;
745
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700746 // May be optimized by targets.
747 virtual void GenMonitorEnter(int opt_flags, RegLocation rl_src);
748 virtual void GenMonitorExit(int opt_flags, RegLocation rl_src);
749
Brian Carlstrom7940e442013-07-12 13:46:57 -0700750 // Temp workaround
751 void Workaround7250540(RegLocation rl_dest, int value);
752
753 protected:
754 Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena);
755
756 CompilationUnit* GetCompilationUnit() {
757 return cu_;
758 }
759
760 private:
761 void GenInstanceofFinal(bool use_declaring_class, uint32_t type_idx, RegLocation rl_dest,
762 RegLocation rl_src);
763 void GenInstanceofCallingHelper(bool needs_access_check, bool type_known_final,
764 bool type_known_abstract, bool use_declaring_class,
765 bool can_assume_type_is_in_dex_cache,
766 uint32_t type_idx, RegLocation rl_dest,
767 RegLocation rl_src);
768
769 void ClobberBody(RegisterInfo* p);
770 void ResetDefBody(RegisterInfo* p) {
771 p->def_start = NULL;
772 p->def_end = NULL;
773 }
774
775 public:
776 // TODO: add accessors for these.
777 LIR* literal_list_; // Constants.
778 LIR* method_literal_list_; // Method literals requiring patching.
779 LIR* code_literal_list_; // Code literals requiring patching.
buzbeeb48819d2013-09-14 16:15:25 -0700780 LIR* first_fixup_; // Doubly-linked list of LIR nodes requiring fixups.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700781
782 protected:
783 CompilationUnit* const cu_;
784 MIRGraph* const mir_graph_;
785 GrowableArray<SwitchTable*> switch_tables_;
786 GrowableArray<FillArrayData*> fill_array_data_;
787 GrowableArray<LIR*> throw_launchpads_;
788 GrowableArray<LIR*> suspend_launchpads_;
789 GrowableArray<LIR*> intrinsic_launchpads_;
buzbeebd663de2013-09-10 15:41:31 -0700790 GrowableArray<RegisterInfo*> tempreg_info_;
791 GrowableArray<RegisterInfo*> reginfo_map_;
buzbee0d829482013-10-11 15:24:55 -0700792 GrowableArray<void*> pointer_storage_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700793 /*
794 * Holds mapping from native PC to dex PC for safepoints where we may deoptimize.
795 * Native PC is on the return address of the safepointed operation. Dex PC is for
796 * the instruction being executed at the safepoint.
797 */
798 std::vector<uint32_t> pc2dex_mapping_table_;
799 /*
800 * Holds mapping from Dex PC to native PC for catch entry points. Native PC and Dex PC
801 * immediately preceed the instruction.
802 */
803 std::vector<uint32_t> dex2pc_mapping_table_;
buzbee0d829482013-10-11 15:24:55 -0700804 CodeOffset current_code_offset_; // Working byte offset of machine instructons.
805 CodeOffset data_offset_; // starting offset of literal pool.
806 size_t total_size_; // header + code size.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700807 LIR* block_label_list_;
808 PromotionMap* promotion_map_;
809 /*
810 * TODO: The code generation utilities don't have a built-in
811 * mechanism to propagate the original Dalvik opcode address to the
812 * associated generated instructions. For the trace compiler, this wasn't
813 * necessary because the interpreter handled all throws and debugging
814 * requests. For now we'll handle this by placing the Dalvik offset
815 * in the CompilationUnit struct before codegen for each instruction.
816 * The low-level LIR creation utilites will pull it from here. Rework this.
817 */
buzbee0d829482013-10-11 15:24:55 -0700818 DexOffset current_dalvik_offset_;
819 size_t estimated_native_code_size_; // Just an estimate; used to reserve code_buffer_ size.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700820 RegisterPool* reg_pool_;
821 /*
822 * Sanity checking for the register temp tracking. The same ssa
823 * name should never be associated with one temp register per
824 * instruction compilation.
825 */
826 int live_sreg_;
827 CodeBuffer code_buffer_;
Ian Rogers96faf5b2013-08-09 22:05:32 -0700828 // The encoding mapping table data (dex -> pc offset and pc offset -> dex) with a size prefix.
829 UnsignedLeb128EncodingVector encoded_mapping_table_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700830 std::vector<uint32_t> core_vmap_table_;
831 std::vector<uint32_t> fp_vmap_table_;
832 std::vector<uint8_t> native_gc_map_;
833 int num_core_spills_;
834 int num_fp_spills_;
835 int frame_size_;
836 unsigned int core_spill_mask_;
837 unsigned int fp_spill_mask_;
838 LIR* first_lir_insn_;
839 LIR* last_lir_insn_;
Vladimir Marko5c96e6b2013-11-14 15:34:17 +0000840 // Lazily retrieved method inliner for intrinsics.
841 const DexFileMethodInliner* inliner_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700842}; // Class Mir2Lir
843
844} // namespace art
845
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700846#endif // ART_COMPILER_DEX_QUICK_MIR_TO_LIR_H_