blob: efae1f568a5eb6127b238f89c66a2ae637e015ec [file] [log] [blame]
buzbee67bf8852011-08-17 17:51:35 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
buzbee395116c2013-02-27 14:30:25 -080017#ifndef ART_SRC_COMPILER_DEX_COMPILER_IR_H_
18#define ART_SRC_COMPILER_DEX_COMPILER_IR_H_
buzbee67bf8852011-08-17 17:51:35 -070019
Elliott Hughesa0e18062012-04-13 15:59:59 -070020#include <vector>
Brian Carlstrom265091e2013-01-30 14:08:26 -080021
Brian Carlstrom37d48792013-03-22 14:14:45 -070022#include <llvm/IR/Module.h>
Brian Carlstrom265091e2013-01-30 14:08:26 -080023
24#include "compiler/dex/quick/codegen.h"
Ian Rogers1212a022013-03-04 10:48:41 -080025#include "compiler/driver/compiler_driver.h"
Ian Rogers89756f22013-03-04 16:40:02 -080026#include "compiler/driver/dex_compilation_unit.h"
Ian Rogers4c1c2832013-03-04 18:30:13 -080027#include "compiler/llvm/intrinsic_helper.h"
Brian Carlstrom265091e2013-01-30 14:08:26 -080028#include "compiler/llvm/ir_builder.h"
buzbeecbd6d442012-11-17 14:11:25 -080029#include "compiler_enums.h"
Brian Carlstrom265091e2013-01-30 14:08:26 -080030#include "compiler_utility.h"
31#include "dex_instruction.h"
32#include "safe_map.h"
buzbee67bf8852011-08-17 17:51:35 -070033
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080034namespace art {
35
buzbee311ca162013-02-28 15:56:43 -080036//TODO: replace these macros
buzbeefa57c472012-11-21 12:06:18 -080037#define SLOW_FIELD_PATH (cu->enable_debug & (1 << kDebugSlowFieldPath))
38#define SLOW_INVOKE_PATH (cu->enable_debug & (1 << kDebugSlowInvokePath))
39#define SLOW_STRING_PATH (cu->enable_debug & (1 << kDebugSlowStringPath))
40#define SLOW_TYPE_PATH (cu->enable_debug & (1 << kDebugSlowTypePath))
41#define EXERCISE_SLOWEST_STRING_PATH (cu->enable_debug & \
Bill Buzbeea114add2012-05-03 15:00:40 -070042 (1 << kDebugSlowestStringPath))
buzbee31a4a6f2012-02-28 15:36:15 -080043
buzbee02031b12012-11-23 09:41:35 -080044// Minimum field size to contain Dalvik v_reg number.
buzbeeca7a5e42012-08-20 11:12:18 -070045#define VREG_NUM_WIDTH 16
46
buzbeeeaf09bc2012-11-15 14:51:41 -080047struct ArenaBitVector;
48struct LIR;
49class LLVMInfo;
Brian Carlstrom265091e2013-01-30 14:08:26 -080050namespace llvm {
51class LlvmCompilationUnit;
52} // namespace llvm
buzbeeeaf09bc2012-11-15 14:51:41 -080053
Elliott Hughes719ace42012-03-09 18:06:03 -080054struct PromotionMap {
buzbeefa57c472012-11-21 12:06:18 -080055 RegLocationType core_location:3;
56 uint8_t core_reg;
57 RegLocationType fp_location:3;
buzbee52a77fc2012-11-20 19:50:46 -080058 uint8_t FpReg;
buzbeefa57c472012-11-21 12:06:18 -080059 bool first_in_pair;
Elliott Hughes719ace42012-03-09 18:06:03 -080060};
buzbee67bc2362011-10-11 18:08:40 -070061
Elliott Hughes719ace42012-03-09 18:06:03 -080062struct RegLocation {
Bill Buzbeea114add2012-05-03 15:00:40 -070063 RegLocationType location:3;
64 unsigned wide:1;
65 unsigned defined:1; // Do we know the type?
buzbee311ca162013-02-28 15:56:43 -080066 unsigned is_const:1; // Constant, value in mir_graph->constant_values[].
Bill Buzbeea114add2012-05-03 15:00:40 -070067 unsigned fp:1; // Floating point?
68 unsigned core:1; // Non-floating point?
buzbee02031b12012-11-23 09:41:35 -080069 unsigned ref:1; // Something GC cares about.
70 unsigned high_word:1; // High word of pair?
Bill Buzbeea114add2012-05-03 15:00:40 -070071 unsigned home:1; // Does this represent the home location?
buzbee02031b12012-11-23 09:41:35 -080072 uint8_t low_reg; // First physical register.
73 uint8_t high_reg; // 2nd physical register (if wide).
74 int32_t s_reg_low; // SSA name for low Dalvik word.
75 int32_t orig_sreg; // TODO: remove after Bitcode gen complete
76 // and consolodate usage w/ s_reg_low.
buzbeee1965672012-03-11 18:39:19 -070077};
78
79struct CompilerTemp {
buzbeefa57c472012-11-21 12:06:18 -080080 int s_reg;
Bill Buzbeea114add2012-05-03 15:00:40 -070081 ArenaBitVector* bv;
Elliott Hughes719ace42012-03-09 18:06:03 -080082};
buzbee67bf8852011-08-17 17:51:35 -070083
buzbee3b3dbdd2012-06-13 13:39:34 -070084struct CallInfo {
buzbee02031b12012-11-23 09:41:35 -080085 int num_arg_words; // Note: word count, not arg count.
86 RegLocation* args; // One for each word of arguments.
87 RegLocation result; // Eventual target of MOVE_RESULT.
buzbeefa57c472012-11-21 12:06:18 -080088 int opt_flags;
buzbee15bf9802012-06-12 17:49:27 -070089 InvokeType type;
buzbeefa57c472012-11-21 12:06:18 -080090 uint32_t dex_idx;
buzbee02031b12012-11-23 09:41:35 -080091 uint32_t index; // Method idx for invokes, type idx for FilledNewArray.
buzbeefa57c472012-11-21 12:06:18 -080092 uintptr_t direct_code;
93 uintptr_t direct_method;
buzbee02031b12012-11-23 09:41:35 -080094 RegLocation target; // Target of following move_result.
buzbeefa57c472012-11-21 12:06:18 -080095 bool skip_this;
96 bool is_range;
buzbee02031b12012-11-23 09:41:35 -080097 int offset; // Dalvik offset.
buzbee15bf9802012-06-12 17:49:27 -070098};
99
buzbeee3acd072012-02-25 17:03:10 -0800100 /*
101 * Data structure tracking the mapping between a Dalvik register (pair) and a
102 * native register (pair). The idea is to reuse the previously loaded value
103 * if possible, otherwise to keep the value in a native register as long as
104 * possible.
105 */
Elliott Hughes719ace42012-03-09 18:06:03 -0800106struct RegisterInfo {
Bill Buzbeea114add2012-05-03 15:00:40 -0700107 int reg; // Reg number
buzbee02031b12012-11-23 09:41:35 -0800108 bool in_use; // Has it been allocated?
109 bool is_temp; // Can allocate as temp?
Bill Buzbeea114add2012-05-03 15:00:40 -0700110 bool pair; // Part of a register pair?
buzbee02031b12012-11-23 09:41:35 -0800111 int partner; // If pair, other reg of pair.
Bill Buzbeea114add2012-05-03 15:00:40 -0700112 bool live; // Is there an associated SSA name?
113 bool dirty; // If live, is it dirty?
buzbee02031b12012-11-23 09:41:35 -0800114 int s_reg; // Name of live value.
115 LIR *def_start; // Starting inst in last def sequence.
116 LIR *def_end; // Ending inst in last def sequence.
Elliott Hughes719ace42012-03-09 18:06:03 -0800117};
buzbeee3acd072012-02-25 17:03:10 -0800118
Elliott Hughes719ace42012-03-09 18:06:03 -0800119struct RegisterPool {
buzbeefa57c472012-11-21 12:06:18 -0800120 int num_core_regs;
121 RegisterInfo *core_regs;
122 int next_core_reg;
123 int num_fp_regs;
Bill Buzbeea114add2012-05-03 15:00:40 -0700124 RegisterInfo *FPRegs;
buzbeefa57c472012-11-21 12:06:18 -0800125 int next_fp_reg;
Elliott Hughes719ace42012-03-09 18:06:03 -0800126};
buzbeee3acd072012-02-25 17:03:10 -0800127
buzbee67bf8852011-08-17 17:51:35 -0700128#define INVALID_SREG (-1)
buzbee3ddc0d12011-10-05 10:36:21 -0700129#define INVALID_VREG (0xFFFFU)
buzbee67bc2362011-10-11 18:08:40 -0700130#define INVALID_REG (0xFF)
buzbeeb046e162012-10-30 15:48:42 -0700131#define INVALID_OFFSET (0xDEADF00FU)
buzbee67bf8852011-08-17 17:51:35 -0700132
buzbeee1965672012-03-11 18:39:19 -0700133/* SSA encodings for special registers */
buzbee9c044ce2012-03-18 13:24:07 -0700134#define SSA_METHOD_BASEREG (-2)
buzbeee1965672012-03-11 18:39:19 -0700135/* First compiler temp basereg, grows smaller */
buzbee9c044ce2012-03-18 13:24:07 -0700136#define SSA_CTEMP_BASEREG (SSA_METHOD_BASEREG - 1)
buzbeee1965672012-03-11 18:39:19 -0700137
buzbee99ba9642012-01-25 14:23:14 -0800138/*
139 * Some code patterns cause the generation of excessively large
140 * methods - in particular initialization sequences. There isn't much
141 * benefit in optimizing these methods, and the cost can be very high.
142 * We attempt to identify these cases, and avoid performing most dataflow
143 * analysis. Two thresholds are used - one for known initializers and one
buzbee5abfa3e2012-01-31 17:01:43 -0800144 * for everything else.
buzbee99ba9642012-01-25 14:23:14 -0800145 */
buzbee5abfa3e2012-01-31 17:01:43 -0800146#define MANY_BLOCKS_INITIALIZER 1000 /* Threshold for switching dataflow off */
147#define MANY_BLOCKS 4000 /* Non-initializer threshold */
buzbee99ba9642012-01-25 14:23:14 -0800148
buzbee02031b12012-11-23 09:41:35 -0800149// Utility macros to traverse the LIR list.
buzbee31a4a6f2012-02-28 15:36:15 -0800150#define NEXT_LIR(lir) (lir->next)
151#define PREV_LIR(lir) (lir->prev)
152
buzbee02031b12012-11-23 09:41:35 -0800153// Defines for alias_info (tracks Dalvik register references).
buzbeeec137432012-11-13 12:13:16 -0800154#define DECODE_ALIAS_INFO_REG(X) (X & 0xffff)
155#define DECODE_ALIAS_INFO_WIDE_FLAG (0x80000000)
156#define DECODE_ALIAS_INFO_WIDE(X) ((X & DECODE_ALIAS_INFO_WIDE_FLAG) ? 1 : 0)
157#define ENCODE_ALIAS_INFO(REG, ISWIDE) (REG | (ISWIDE ? DECODE_ALIAS_INFO_WIDE_FLAG : 0))
158
buzbee02031b12012-11-23 09:41:35 -0800159// Common resource macros.
buzbeeec137432012-11-13 12:13:16 -0800160#define ENCODE_CCODE (1ULL << kCCode)
161#define ENCODE_FP_STATUS (1ULL << kFPStatus)
162
buzbee02031b12012-11-23 09:41:35 -0800163// Abstract memory locations.
buzbeeec137432012-11-13 12:13:16 -0800164#define ENCODE_DALVIK_REG (1ULL << kDalvikReg)
165#define ENCODE_LITERAL (1ULL << kLiteral)
166#define ENCODE_HEAP_REF (1ULL << kHeapRef)
167#define ENCODE_MUST_NOT_ALIAS (1ULL << kMustNotAlias)
168
169#define ENCODE_ALL (~0ULL)
170#define ENCODE_MEM (ENCODE_DALVIK_REG | ENCODE_LITERAL | \
171 ENCODE_HEAP_REF | ENCODE_MUST_NOT_ALIAS)
172
buzbeefa57c472012-11-21 12:06:18 -0800173#define is_pseudo_opcode(opcode) (static_cast<int>(opcode) < 0)
buzbee1bc37c62012-11-20 13:35:41 -0800174
Elliott Hughes719ace42012-03-09 18:06:03 -0800175struct LIR {
buzbee02031b12012-11-23 09:41:35 -0800176 int offset; // Offset of this instruction.
177 int dalvik_offset; // Offset of Dalvik opcode.
Bill Buzbeea114add2012-05-03 15:00:40 -0700178 LIR* next;
179 LIR* prev;
180 LIR* target;
181 int opcode;
buzbee02031b12012-11-23 09:41:35 -0800182 int operands[5]; // [0..4] = [dest, src1, src2, extra, extra2].
Bill Buzbeea114add2012-05-03 15:00:40 -0700183 struct {
buzbee02031b12012-11-23 09:41:35 -0800184 bool is_nop:1; // LIR is optimized away.
185 bool pcRelFixup:1; // May need pc-relative fixup.
186 unsigned int size:5; // Note: size is in bytes.
buzbeef5f5a122012-09-21 13:57:36 -0700187 unsigned int unused:25;
Bill Buzbeea114add2012-05-03 15:00:40 -0700188 } flags;
buzbee02031b12012-11-23 09:41:35 -0800189 int alias_info; // For Dalvik register & litpool disambiguation.
190 uint64_t use_mask; // Resource mask for use.
191 uint64_t def_mask; // Resource mask for def.
Elliott Hughes719ace42012-03-09 18:06:03 -0800192};
buzbee67bf8852011-08-17 17:51:35 -0700193
buzbeefa57c472012-11-21 12:06:18 -0800194extern const char* extended_mir_op_names[kMirOpLast - kMirOpFirst];
buzbee67bf8852011-08-17 17:51:35 -0700195
196struct SSARepresentation;
197
buzbee67bf8852011-08-17 17:51:35 -0700198#define MIR_IGNORE_NULL_CHECK (1 << kMIRIgnoreNullCheck)
199#define MIR_NULL_CHECK_ONLY (1 << kMIRNullCheckOnly)
200#define MIR_IGNORE_RANGE_CHECK (1 << kMIRIgnoreRangeCheck)
201#define MIR_RANGE_CHECK_ONLY (1 << kMIRRangeCheckOnly)
202#define MIR_INLINED (1 << kMIRInlined)
203#define MIR_INLINED_PRED (1 << kMIRInlinedPred)
204#define MIR_CALLEE (1 << kMIRCallee)
buzbeec1f45042011-09-21 16:03:19 -0700205#define MIR_IGNORE_SUSPEND_CHECK (1 << kMIRIgnoreSuspendCheck)
buzbeee1965672012-03-11 18:39:19 -0700206#define MIR_DUP (1 << kMIRDup)
buzbee67bf8852011-08-17 17:51:35 -0700207
buzbeed1643e42012-09-05 14:06:51 -0700208struct Checkstats {
buzbeefa57c472012-11-21 12:06:18 -0800209 int null_checks;
210 int null_checks_eliminated;
211 int range_checks;
212 int range_checks_eliminated;
buzbeed1643e42012-09-05 14:06:51 -0700213};
214
Elliott Hughes719ace42012-03-09 18:06:03 -0800215struct MIR {
Bill Buzbeea114add2012-05-03 15:00:40 -0700216 DecodedInstruction dalvikInsn;
217 unsigned int width;
218 unsigned int offset;
buzbee311ca162013-02-28 15:56:43 -0800219 int m_unit_index; // From which method was this MIR included
Bill Buzbeea114add2012-05-03 15:00:40 -0700220 MIR* prev;
221 MIR* next;
buzbeefa57c472012-11-21 12:06:18 -0800222 SSARepresentation* ssa_rep;
223 int optimization_flags;
Bill Buzbeea114add2012-05-03 15:00:40 -0700224 union {
buzbee02031b12012-11-23 09:41:35 -0800225 // Establish link between two halves of throwing instructions.
buzbeefa57c472012-11-21 12:06:18 -0800226 MIR* throw_insn;
buzbeea169e1d2012-12-05 14:26:44 -0800227 // Saved opcode for NOP'd MIRs
228 Instruction::Code original_opcode;
Bill Buzbeea114add2012-05-03 15:00:40 -0700229 } meta;
Elliott Hughes719ace42012-03-09 18:06:03 -0800230};
buzbee67bf8852011-08-17 17:51:35 -0700231
buzbee311ca162013-02-28 15:56:43 -0800232struct BasicBlockDataFlow {
233 ArenaBitVector* use_v;
234 ArenaBitVector* def_v;
235 ArenaBitVector* live_in_v;
236 ArenaBitVector* phi_v;
237 int* vreg_to_ssa_map;
238 ArenaBitVector* ending_null_check_v;
239};
240
241struct SSARepresentation {
242 int num_uses;
243 int* uses;
244 bool* fp_use;
245 int num_defs;
246 int* defs;
247 bool* fp_def;
248};
buzbee67bf8852011-08-17 17:51:35 -0700249
Elliott Hughes719ace42012-03-09 18:06:03 -0800250struct BasicBlock {
Bill Buzbeea114add2012-05-03 15:00:40 -0700251 int id;
buzbeefa57c472012-11-21 12:06:18 -0800252 int dfs_id;
Bill Buzbeea114add2012-05-03 15:00:40 -0700253 bool visited;
254 bool hidden;
buzbeefa57c472012-11-21 12:06:18 -0800255 bool catch_entry;
256 bool explicit_throw;
257 bool conditional_branch;
buzbeebbdd0532013-02-07 09:33:02 -0800258 bool terminated_by_return; // Block ends with a Dalvik return opcode.
259 bool dominates_return; // Is a member of return extended basic block.
buzbeefa57c472012-11-21 12:06:18 -0800260 uint16_t start_offset;
261 uint16_t nesting_depth;
262 BBType block_type;
263 MIR* first_mir_insn;
264 MIR* last_mir_insn;
265 BasicBlock* fall_through;
Bill Buzbeea114add2012-05-03 15:00:40 -0700266 BasicBlock* taken;
buzbee02031b12012-11-23 09:41:35 -0800267 BasicBlock* i_dom; // Immediate dominator.
buzbeefa57c472012-11-21 12:06:18 -0800268 BasicBlockDataFlow* data_flow_info;
Bill Buzbeea114add2012-05-03 15:00:40 -0700269 GrowableList* predecessors;
270 ArenaBitVector* dominators;
buzbee02031b12012-11-23 09:41:35 -0800271 ArenaBitVector* i_dominated; // Set nodes being immediately dominated.
272 ArenaBitVector* dom_frontier; // Dominance frontier.
273 struct { // For one-to-many successors like.
274 BlockListType block_list_type; // switch and exception handling.
Bill Buzbeea114add2012-05-03 15:00:40 -0700275 GrowableList blocks;
buzbeefa57c472012-11-21 12:06:18 -0800276 } successor_block_list;
Elliott Hughes719ace42012-03-09 18:06:03 -0800277};
buzbee67bf8852011-08-17 17:51:35 -0700278
279/*
buzbeefa57c472012-11-21 12:06:18 -0800280 * The "blocks" field in "successor_block_list" points to an array of
buzbee67bf8852011-08-17 17:51:35 -0700281 * elements with the type "SuccessorBlockInfo".
282 * For catch blocks, key is type index for the exception.
283 * For swtich blocks, key is the case value.
284 */
Elliott Hughes719ace42012-03-09 18:06:03 -0800285struct SuccessorBlockInfo {
Bill Buzbeea114add2012-05-03 15:00:40 -0700286 BasicBlock* block;
287 int key;
Elliott Hughes719ace42012-03-09 18:06:03 -0800288};
buzbee67bf8852011-08-17 17:51:35 -0700289
290struct LoopAnalysis;
291struct RegisterPool;
buzbeeba938cb2012-02-03 14:47:55 -0800292struct ArenaMemBlock;
293struct Memstats;
buzbee311ca162013-02-28 15:56:43 -0800294class MIRGraph;
buzbee02031b12012-11-23 09:41:35 -0800295class Codegen;
buzbee67bf8852011-08-17 17:51:35 -0700296
buzbee5b537102012-01-17 17:33:47 -0800297#define NOTVISITED (-1)
298
Elliott Hughes719ace42012-03-09 18:06:03 -0800299struct CompilationUnit {
Elliott Hughese52e49b2012-04-02 16:05:44 -0700300 CompilationUnit()
buzbee311ca162013-02-28 15:56:43 -0800301 : compiler_driver(NULL),
Bill Buzbeea114add2012-05-03 15:00:40 -0700302 class_linker(NULL),
303 dex_file(NULL),
Bill Buzbeea114add2012-05-03 15:00:40 -0700304 class_loader(NULL),
Ian Rogersfffdb022013-01-04 15:14:08 -0800305 class_def_idx(0),
Bill Buzbeea114add2012-05-03 15:00:40 -0700306 method_idx(0),
307 code_item(NULL),
308 access_flags(0),
Ian Rogers08f753d2012-08-24 14:35:25 -0700309 invoke_type(kDirect),
Bill Buzbeea114add2012-05-03 15:00:40 -0700310 shorty(NULL),
buzbeefa57c472012-11-21 12:06:18 -0800311 disable_opt(0),
312 enable_debug(0),
buzbeefa57c472012-11-21 12:06:18 -0800313 verbose(false),
buzbee311ca162013-02-28 15:56:43 -0800314 gen_bitcode(false),
315 disable_dataflow(false),
buzbeefa57c472012-11-21 12:06:18 -0800316 instruction_set(kNone),
buzbeefa57c472012-11-21 12:06:18 -0800317 num_dalvik_registers(0),
buzbee311ca162013-02-28 15:56:43 -0800318 insns(NULL),
buzbeefa57c472012-11-21 12:06:18 -0800319 num_ins(0),
320 num_outs(0),
321 num_regs(0),
322 num_core_spills(0),
323 num_fp_spills(0),
324 num_compiler_temps(0),
325 frame_size(0),
buzbee311ca162013-02-28 15:56:43 -0800326 core_spill_mask(0),
327 fp_spill_mask(0),
328 attributes(0),
buzbeefa57c472012-11-21 12:06:18 -0800329 compiler_flip_match(false),
330 arena_head(NULL),
331 current_arena(NULL),
332 num_arena_blocks(0),
Bill Buzbeea114add2012-05-03 15:00:40 -0700333 mstats(NULL),
buzbeed1643e42012-09-05 14:06:51 -0700334 checkstats(NULL),
buzbee311ca162013-02-28 15:56:43 -0800335 mir_graph(NULL),
336 cg(NULL),
337 live_sreg(0),
Ian Rogersfffdb022013-01-04 15:14:08 -0800338 llvm_info(NULL),
buzbee2cfc6392012-05-07 14:51:40 -0700339 context(NULL),
340 module(NULL),
341 func(NULL),
342 intrinsic_helper(NULL),
343 irb(NULL),
buzbeefa57c472012-11-21 12:06:18 -0800344 placeholder_bb(NULL),
345 entry_bb(NULL),
346 entryTarget_bb(NULL),
347 temp_name(0),
buzbee311ca162013-02-28 15:56:43 -0800348 first_lir_insn(NULL),
349 last_lir_insn(NULL),
350 literal_list(NULL),
351 method_literal_list(NULL),
352 code_literal_list(NULL),
353 data_offset(0),
354 total_size(0),
355 reg_pool(NULL),
356 reg_location(NULL),
357 promotion_map(NULL),
358 method_sreg(0),
359 block_label_list(NULL),
360 current_dalvik_offset(0)
361 {}
362 /*
363 * Fields needed/generated by common frontend and generally used throughout
364 * the compiler.
365 */
Ian Rogers1212a022013-03-04 10:48:41 -0800366 CompilerDriver* compiler_driver;
buzbee02031b12012-11-23 09:41:35 -0800367 ClassLinker* class_linker; // Linker to resolve fields and methods.
368 const DexFile* dex_file; // DexFile containing the method being compiled.
369 jobject class_loader; // compiling method's class loader.
Ian Rogersfffdb022013-01-04 15:14:08 -0800370 uint32_t class_def_idx; // compiling method's defining class definition index.
buzbee02031b12012-11-23 09:41:35 -0800371 uint32_t method_idx; // compiling method's index into method_ids of DexFile.
372 const DexFile::CodeItem* code_item; // compiling method's DexFile code_item.
373 uint32_t access_flags; // compiling method's access flags.
374 InvokeType invoke_type; // compiling method's invocation type.
375 const char* shorty; // compiling method's shorty.
buzbee02031b12012-11-23 09:41:35 -0800376 uint32_t disable_opt; // opt_control_vector flags.
377 uint32_t enable_debug; // debugControlVector flags.
buzbeefa57c472012-11-21 12:06:18 -0800378 std::vector<uint8_t> code_buffer;
buzbee311ca162013-02-28 15:56:43 -0800379 bool verbose;
buzbeefa57c472012-11-21 12:06:18 -0800380 std::vector<uint32_t> combined_mapping_table;
381 std::vector<uint32_t> core_vmap_table;
382 std::vector<uint32_t> fp_vmap_table;
383 std::vector<uint8_t> native_gc_map;
buzbee311ca162013-02-28 15:56:43 -0800384 bool gen_bitcode;
385 bool disable_dataflow; // Skip dataflow analysis if possible
buzbeefa57c472012-11-21 12:06:18 -0800386 InstructionSet instruction_set;
buzbee67bf8852011-08-17 17:51:35 -0700387
buzbee311ca162013-02-28 15:56:43 -0800388 // CLEANUP: much of this info available elsewhere. Go to the original source?
buzbee02031b12012-11-23 09:41:35 -0800389 int num_dalvik_registers; // method->registers_size.
buzbee311ca162013-02-28 15:56:43 -0800390 const uint16_t* insns;
Bill Buzbeea114add2012-05-03 15:00:40 -0700391 /*
392 * Frame layout details.
393 * NOTE: for debug support it will be necessary to add a structure
394 * to map the Dalvik virtual registers to the promoted registers.
395 * NOTE: "num" fields are in 4-byte words, "Size" and "Offset" in bytes.
396 */
buzbeefa57c472012-11-21 12:06:18 -0800397 int num_ins;
398 int num_outs;
buzbee02031b12012-11-23 09:41:35 -0800399 int num_regs; // Unlike num_dalvik_registers, does not include ins.
buzbeefa57c472012-11-21 12:06:18 -0800400 int num_core_spills;
401 int num_fp_spills;
402 int num_compiler_temps;
403 int frame_size;
404 unsigned int core_spill_mask;
405 unsigned int fp_spill_mask;
buzbee311ca162013-02-28 15:56:43 -0800406 unsigned int attributes;
Bill Buzbeea114add2012-05-03 15:00:40 -0700407 // If non-empty, apply optimizer/debug flags only to matching methods.
buzbeefa57c472012-11-21 12:06:18 -0800408 std::string compiler_method_match;
409 // Flips sense of compiler_method_match - apply flags if doesn't match.
410 bool compiler_flip_match;
411 ArenaMemBlock* arena_head;
412 ArenaMemBlock* current_arena;
413 int num_arena_blocks;
Bill Buzbeea114add2012-05-03 15:00:40 -0700414 Memstats* mstats;
buzbeed1643e42012-09-05 14:06:51 -0700415 Checkstats* checkstats;
buzbee311ca162013-02-28 15:56:43 -0800416 UniquePtr<MIRGraph> mir_graph; // MIR container.
417 UniquePtr<Codegen> cg; // Target-specific codegen.
418 /*
419 * Sanity checking for the register temp tracking. The same ssa
420 * name should never be associated with one temp register per
421 * instruction compilation.
422 */
423 int live_sreg;
Brian Carlstrom265091e2013-01-30 14:08:26 -0800424
425 // Fields for Portable
426 llvm::LlvmCompilationUnit* llvm_compilation_unit;
buzbee311ca162013-02-28 15:56:43 -0800427 /*
428 * Fields needed by GBC creation. Candidates for moving to a new MIR to
429 * llvm bitcode class.
430 */
buzbee4df2bbd2012-10-11 14:46:06 -0700431 LLVMInfo* llvm_info;
Brian Carlstrom265091e2013-01-30 14:08:26 -0800432 std::string symbol;
Ian Rogers4c1c2832013-03-04 18:30:13 -0800433 ::llvm::LLVMContext* context;
434 ::llvm::Module* module;
435 ::llvm::Function* func;
436 art::llvm::IntrinsicHelper* intrinsic_helper;
437 art::llvm::IRBuilder* irb;
438 ::llvm::BasicBlock* placeholder_bb;
439 ::llvm::BasicBlock* entry_bb;
440 ::llvm::BasicBlock* entryTarget_bb;
Brian Carlstrom265091e2013-01-30 14:08:26 -0800441
buzbee2cfc6392012-05-07 14:51:40 -0700442 std::string bitcode_filename;
buzbeefa57c472012-11-21 12:06:18 -0800443 GrowableList llvm_values;
444 int32_t temp_name;
buzbee311ca162013-02-28 15:56:43 -0800445 SafeMap<int32_t, ::llvm::BasicBlock*> id_to_block_map; // block id -> llvm bb.
446
447 /*
448 * Fields needed by the Quick backend. Candidates for moving to a new
449 * QuickBackend class.
450 */
451 LIR* first_lir_insn;
452 LIR* last_lir_insn;
453 LIR* literal_list; // Constants.
454 LIR* method_literal_list; // Method literals requiring patching.
455 LIR* code_literal_list; // Code literals requiring patching.
456 int data_offset; // starting offset of literal pool.
457 int total_size; // header + code size.
458 RegisterPool* reg_pool;
459 // Map SSA names to location.
460 RegLocation* reg_location;
461 // Keep track of Dalvik v_reg to physical register mappings.
462 PromotionMap* promotion_map;
463 // SSA name for Method*.
464 int method_sreg;
465 RegLocation method_loc; // Describes location of method*.
466 GrowableList throw_launchpads;
467 GrowableList suspend_launchpads;
468 GrowableList intrinsic_launchpads;
469 GrowableList compiler_temps;
470 LIR* block_label_list;
Bill Buzbeea114add2012-05-03 15:00:40 -0700471 /*
buzbee311ca162013-02-28 15:56:43 -0800472 * TODO: The code generation utilities don't have a built-in
473 * mechanism to propagate the original Dalvik opcode address to the
474 * associated generated instructions. For the trace compiler, this wasn't
475 * necessary because the interpreter handled all throws and debugging
476 * requests. For now we'll handle this by placing the Dalvik offset
477 * in the CompilationUnit struct before codegen for each instruction.
478 * The low-level LIR creation utilites will pull it from here. Rework this.
Bill Buzbeea114add2012-05-03 15:00:40 -0700479 */
buzbee311ca162013-02-28 15:56:43 -0800480 int current_dalvik_offset;
481 GrowableList switch_tables;
482 GrowableList fill_array_data;
483 SafeMap<unsigned int, unsigned int> block_id_map; // Block collapse lookup cache.
484 SafeMap<unsigned int, LIR*> boundary_map; // boundary lookup cache.
485 /*
486 * Holds mapping from native PC to dex PC for safepoints where we may deoptimize.
487 * Native PC is on the return address of the safepointed operation. Dex PC is for
488 * the instruction being executed at the safepoint.
489 */
490 std::vector<uint32_t> pc2dexMappingTable;
491 /*
492 * Holds mapping from Dex PC to native PC for catch entry points. Native PC and Dex PC
493 * immediately preceed the instruction.
494 */
495 std::vector<uint32_t> dex2pcMappingTable;
Elliott Hughes719ace42012-03-09 18:06:03 -0800496};
buzbee67bf8852011-08-17 17:51:35 -0700497
buzbee311ca162013-02-28 15:56:43 -0800498// TODO: move this
499int SRegToVReg(const CompilationUnit* cu, int ssa_reg);
buzbee5de34942012-03-01 14:51:57 -0800500
buzbee4ef3e452012-12-14 13:35:28 -0800501
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800502} // namespace art
503
buzbee395116c2013-02-27 14:30:25 -0800504#endif // ART_SRC_COMPILER_DEX_COMPILER_IR_H_