blob: 4c56b74dc4ade7c84bb57eaeb92ef9f59ba87b11 [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;
109class MIRGraph;
110class Mir2Lir;
111
112typedef 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
117typedef std::vector<uint8_t> CodeBuffer;
118
buzbeeb48819d2013-09-14 16:15:25 -0700119struct UseDefMasks {
120 uint64_t use_mask; // Resource mask for use.
121 uint64_t def_mask; // Resource mask for def.
122};
123
124struct AssemblyInfo {
125 LIR* pcrel_next; // Chain of LIR nodes needing pc relative fixups.
126 uint8_t bytes[16]; // Encoded instruction bytes.
127};
Brian Carlstrom7940e442013-07-12 13:46:57 -0700128
129struct LIR {
buzbee0d829482013-10-11 15:24:55 -0700130 CodeOffset offset; // Offset of this instruction.
131 NarrowDexOffset dalvik_offset; // Offset of Dalvik opcode in code units (16-bit words).
buzbeeb48819d2013-09-14 16:15:25 -0700132 int16_t opcode;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700133 LIR* next;
134 LIR* prev;
135 LIR* target;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700136 struct {
buzbeeb48819d2013-09-14 16:15:25 -0700137 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 Carlstrom7940e442013-07-12 13:46:57 -0700143 } flags;
buzbeeb48819d2013-09-14 16:15:25 -0700144 union {
buzbee0d829482013-10-11 15:24:55 -0700145 UseDefMasks m; // Use & Def masks used during optimization.
146 AssemblyInfo a; // Instruction encoding used during assembly phase.
buzbeeb48819d2013-09-14 16:15:25 -0700147 } u;
buzbee0d829482013-10-11 15:24:55 -0700148 int32_t operands[5]; // [0..4] = [dest, src1, src2, extra, extra2].
Brian Carlstrom7940e442013-07-12 13:46:57 -0700149};
150
151// Target-specific initialization.
152Mir2Lir* ArmCodeGenerator(CompilationUnit* const cu, MIRGraph* const mir_graph,
153 ArenaAllocator* const arena);
154Mir2Lir* MipsCodeGenerator(CompilationUnit* const cu, MIRGraph* const mir_graph,
155 ArenaAllocator* const arena);
156Mir2Lir* 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)
buzbeeb48819d2013-09-14 16:15:25 -0700165#define DECODE_ALIAS_INFO_WIDE_FLAG (0x10000)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700166#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)
buzbeec729a6b2013-09-14 16:04:31 -0700182
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 Carlstrom7934ac22013-07-26 10:54:15 -0700186// TODO: replace these macros
Brian Carlstrom7940e442013-07-12 13:46:57 -0700187#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 Carlstrom7940e442013-07-12 13:46:57 -0700192
193class Mir2Lir : public Backend {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700194 public:
buzbee0d829482013-10-11 15:24:55 -0700195 /*
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 Carlstrom7940e442013-07-12 13:46:57 -0700203 };
204
buzbee0d829482013-10-11 15:24:55 -0700205 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 Carlstrom7940e442013-07-12 13:46:57 -0700212 };
213
214 /* Static register use counts */
215 struct RefCounts {
216 int count;
217 int s_reg;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700218 };
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 Carlstrom6f485c62013-07-18 15:35:35 -0700239 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 Carlstrom7940e442013-07-12 13:46:57 -0700247
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 Carlstrom9b7085a2013-07-18 15:15:21 -0700256 virtual ~Mir2Lir() {}
Brian Carlstrom7940e442013-07-12 13:46:57 -0700257
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 Carlstromdf629502013-07-17 22:39:56 -0700264 size == kSignedByte) ? kCoreReg : kAnyReg;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700265 }
266
267 size_t CodeBufferSizeInBytes() {
268 return code_buffer_.size() / sizeof(code_buffer_[0]);
269 }
270
buzbee409fe942013-10-11 10:49:56 -0700271 bool IsPseudoLirOp(int opcode) {
272 return (opcode < 0);
273 }
274
buzbee0d829482013-10-11 15:24:55 -0700275 /*
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 Carlstrom7940e442013-07-12 13:46:57 -0700303 // 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 Rogers9b297bf2013-09-06 11:11:25 -0700312 bool FastInstance(uint32_t field_idx, bool is_put, int* field_offset, bool* is_volatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700313 void SetupResourceMasks(LIR* lir);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700314 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();
buzbee0d829482013-10-11 15:24:55 -0700320 LIR* RawLIR(DexOffset dalvik_offset, int opcode, int op0 = 0, int op1 = 0,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700321 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);
buzbee0d829482013-10-11 15:24:55 -0700335 void MarkBoundary(DexOffset offset, const char* inst_str);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700336 void NopLIR(LIR* lir);
buzbee252254b2013-09-08 16:20:53 -0700337 void UnlinkLIR(LIR* lir);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700338 bool EvaluateBranch(Instruction::Code opcode, int src1, int src2);
339 bool IsInexpensiveConstant(RegLocation rl_src);
340 ConditionCode FlipComparisonOrder(ConditionCode before);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700341 void DumpMappingTable(const char* table_name, const char* descriptor,
342 const char* name, const Signature& signature,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700343 const std::vector<uint32_t>& v);
344 void InstallLiteralPools();
345 void InstallSwitchTables();
346 void InstallFillArrayData();
347 bool VerifyCatchEntries();
348 void CreateMappingTables();
349 void CreateNativeGcMap();
buzbee0d829482013-10-11 15:24:55 -0700350 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 Carlstrom7940e442013-07-12 13:46:57 -0700356
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 Carlstrom7940e442013-07-12 13:46:57 -0700362
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);
buzbeec729a6b2013-09-14 16:04:31 -0700383 int AllocPreservedSingle(int s_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700384 int AllocPreservedDouble(int s_reg);
buzbeec729a6b2013-09-14 16:04:31 -0700385 int AllocTempBody(RegisterInfo* p, int num_regs, int* next_temp, bool required);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700386 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);
buzbeec729a6b2013-09-14 16:04:31 -0700424 void CountRefs(RefCounts* core_counts, RefCounts* fp_counts, size_t num_regs);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700425 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);
buzbeebd663de2013-09-10 15:41:31 -0700431 RegisterInfo* GetRegInfo(int reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700432
433 // Shared by all targets - implemented in gen_common.cc.
buzbee11b63d12013-08-27 07:34:17 -0700434 bool HandleEasyDivRem(Instruction::Code dalvik_opcode, bool is_div,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700435 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 Rogersa9a82542013-10-04 11:17:26 -0700465 void GenArrayObjPut(int opt_flags, RegLocation rl_array, RegLocation rl_index,
466 RegLocation rl_src);
467
Brian Carlstrom7940e442013-07-12 13:46:57 -0700468 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 Rogers468532e2013-08-05 10:56:33 -0700486 void GenConversionCall(ThreadOffset func_offset, RegLocation rl_dest,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700487 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 Rogers468532e2013-08-05 10:56:33 -0700492 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 Carlstrom7940e442013-07-12 13:46:57 -0700499 bool safepoint_pc);
Ian Rogers468532e2013-08-05 10:56:33 -0700500 void CallRuntimeHelperImmRegLocation(ThreadOffset helper_offset, int arg0,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700501 RegLocation arg1, bool safepoint_pc);
Ian Rogers468532e2013-08-05 10:56:33 -0700502 void CallRuntimeHelperRegLocationImm(ThreadOffset helper_offset, RegLocation arg0,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700503 int arg1, bool safepoint_pc);
Ian Rogers468532e2013-08-05 10:56:33 -0700504 void CallRuntimeHelperImmReg(ThreadOffset helper_offset, int arg0, int arg1,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700505 bool safepoint_pc);
Ian Rogers468532e2013-08-05 10:56:33 -0700506 void CallRuntimeHelperRegImm(ThreadOffset helper_offset, int arg0, int arg1,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700507 bool safepoint_pc);
Ian Rogers468532e2013-08-05 10:56:33 -0700508 void CallRuntimeHelperImmMethod(ThreadOffset helper_offset, int arg0,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700509 bool safepoint_pc);
Ian Rogers468532e2013-08-05 10:56:33 -0700510 void CallRuntimeHelperRegLocationRegLocation(ThreadOffset helper_offset,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700511 RegLocation arg0, RegLocation arg1,
512 bool safepoint_pc);
Ian Rogers468532e2013-08-05 10:56:33 -0700513 void CallRuntimeHelperRegReg(ThreadOffset helper_offset, int arg0, int arg1,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700514 bool safepoint_pc);
Ian Rogers468532e2013-08-05 10:56:33 -0700515 void CallRuntimeHelperRegRegImm(ThreadOffset helper_offset, int arg0, int arg1,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700516 int arg2, bool safepoint_pc);
Ian Rogers468532e2013-08-05 10:56:33 -0700517 void CallRuntimeHelperImmMethodRegLocation(ThreadOffset helper_offset, int arg0,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700518 RegLocation arg2, bool safepoint_pc);
Ian Rogers468532e2013-08-05 10:56:33 -0700519 void CallRuntimeHelperImmMethodImm(ThreadOffset helper_offset, int arg0, int arg2,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700520 bool safepoint_pc);
Ian Rogers468532e2013-08-05 10:56:33 -0700521 void CallRuntimeHelperImmRegLocationRegLocation(ThreadOffset helper_offset,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700522 int arg0, RegLocation arg1, RegLocation arg2,
523 bool safepoint_pc);
Ian Rogersa9a82542013-10-04 11:17:26 -0700524 void CallRuntimeHelperRegLocationRegLocationRegLocation(ThreadOffset helper_offset,
525 RegLocation arg0, RegLocation arg1,
526 RegLocation arg2,
527 bool safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700528 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 Marko6bdf1ff2013-10-29 17:40:46 +0000547 bool GenInlinedReverseBytes(CallInfo* info, OpSize size);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700548 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.
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_;
840}; // Class Mir2Lir
841
842} // namespace art
843
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700844#endif // ART_COMPILER_DEX_QUICK_MIR_TO_LIR_H_