blob: d0ac8aa349314b511fed53adf052bfe447a3ec5c [file] [log] [blame]
Brian Carlstrom7940e442013-07-12 13:46:57 -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
17#include "dex/compiler_internals.h"
18#include "dex_file-inl.h"
19#include "gc_map.h"
Ian Rogers96faf5b2013-08-09 22:05:32 -070020#include "mapping_table.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070021#include "mir_to_lir-inl.h"
Vladimir Marko5816ed42013-11-27 17:04:20 +000022#include "dex/quick/dex_file_method_inliner.h"
23#include "dex/quick/dex_file_to_method_inliner_map.h"
Vladimir Markoc7f83202014-01-24 17:55:18 +000024#include "dex/verification_results.h"
Vladimir Marko2730db02014-01-27 11:15:17 +000025#include "dex/verified_method.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070026#include "verifier/dex_gc_map.h"
27#include "verifier/method_verifier.h"
Vladimir Marko2e589aa2014-02-25 17:53:53 +000028#include "vmap_table.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070029
30namespace art {
31
Vladimir Marko06606b92013-12-02 15:31:08 +000032namespace {
33
34/* Dump a mapping table */
35template <typename It>
36void DumpMappingTable(const char* table_name, const char* descriptor, const char* name,
37 const Signature& signature, uint32_t size, It first) {
38 if (size != 0) {
Ian Rogers107c31e2014-01-23 20:55:29 -080039 std::string line(StringPrintf("\n %s %s%s_%s_table[%u] = {", table_name,
Vladimir Marko06606b92013-12-02 15:31:08 +000040 descriptor, name, signature.ToString().c_str(), size));
41 std::replace(line.begin(), line.end(), ';', '_');
42 LOG(INFO) << line;
43 for (uint32_t i = 0; i != size; ++i) {
44 line = StringPrintf(" {0x%05x, 0x%04x},", first.NativePcOffset(), first.DexPc());
45 ++first;
46 LOG(INFO) << line;
47 }
48 LOG(INFO) <<" };\n\n";
49 }
50}
51
52} // anonymous namespace
53
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070054bool Mir2Lir::IsInexpensiveConstant(RegLocation rl_src) {
Brian Carlstrom7940e442013-07-12 13:46:57 -070055 bool res = false;
56 if (rl_src.is_const) {
57 if (rl_src.wide) {
58 if (rl_src.fp) {
59 res = InexpensiveConstantDouble(mir_graph_->ConstantValueWide(rl_src));
60 } else {
61 res = InexpensiveConstantLong(mir_graph_->ConstantValueWide(rl_src));
62 }
63 } else {
64 if (rl_src.fp) {
65 res = InexpensiveConstantFloat(mir_graph_->ConstantValue(rl_src));
66 } else {
67 res = InexpensiveConstantInt(mir_graph_->ConstantValue(rl_src));
68 }
69 }
70 }
71 return res;
72}
73
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070074void Mir2Lir::MarkSafepointPC(LIR* inst) {
buzbeeb48819d2013-09-14 16:15:25 -070075 DCHECK(!inst->flags.use_def_invalid);
76 inst->u.m.def_mask = ENCODE_ALL;
Brian Carlstrom7940e442013-07-12 13:46:57 -070077 LIR* safepoint_pc = NewLIR0(kPseudoSafepointPC);
buzbeeb48819d2013-09-14 16:15:25 -070078 DCHECK_EQ(safepoint_pc->u.m.def_mask, ENCODE_ALL);
Brian Carlstrom7940e442013-07-12 13:46:57 -070079}
80
buzbee252254b2013-09-08 16:20:53 -070081/* Remove a LIR from the list. */
82void Mir2Lir::UnlinkLIR(LIR* lir) {
83 if (UNLIKELY(lir == first_lir_insn_)) {
84 first_lir_insn_ = lir->next;
85 if (lir->next != NULL) {
86 lir->next->prev = NULL;
87 } else {
88 DCHECK(lir->next == NULL);
89 DCHECK(lir == last_lir_insn_);
90 last_lir_insn_ = NULL;
91 }
92 } else if (lir == last_lir_insn_) {
93 last_lir_insn_ = lir->prev;
94 lir->prev->next = NULL;
95 } else if ((lir->prev != NULL) && (lir->next != NULL)) {
96 lir->prev->next = lir->next;
97 lir->next->prev = lir->prev;
98 }
99}
100
Brian Carlstrom7940e442013-07-12 13:46:57 -0700101/* Convert an instruction to a NOP */
Brian Carlstromdf629502013-07-17 22:39:56 -0700102void Mir2Lir::NopLIR(LIR* lir) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700103 lir->flags.is_nop = true;
buzbee252254b2013-09-08 16:20:53 -0700104 if (!cu_->verbose) {
105 UnlinkLIR(lir);
106 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700107}
108
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700109void Mir2Lir::SetMemRefType(LIR* lir, bool is_load, int mem_type) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700110 uint64_t *mask_ptr;
Brian Carlstromf69863b2013-07-17 21:53:13 -0700111 uint64_t mask = ENCODE_MEM;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700112 DCHECK(GetTargetInstFlags(lir->opcode) & (IS_LOAD | IS_STORE));
buzbeeb48819d2013-09-14 16:15:25 -0700113 DCHECK(!lir->flags.use_def_invalid);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700114 if (is_load) {
buzbeeb48819d2013-09-14 16:15:25 -0700115 mask_ptr = &lir->u.m.use_mask;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700116 } else {
buzbeeb48819d2013-09-14 16:15:25 -0700117 mask_ptr = &lir->u.m.def_mask;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700118 }
119 /* Clear out the memref flags */
120 *mask_ptr &= ~mask;
121 /* ..and then add back the one we need */
122 switch (mem_type) {
123 case kLiteral:
124 DCHECK(is_load);
125 *mask_ptr |= ENCODE_LITERAL;
126 break;
127 case kDalvikReg:
128 *mask_ptr |= ENCODE_DALVIK_REG;
129 break;
130 case kHeapRef:
131 *mask_ptr |= ENCODE_HEAP_REF;
132 break;
133 case kMustNotAlias:
134 /* Currently only loads can be marked as kMustNotAlias */
135 DCHECK(!(GetTargetInstFlags(lir->opcode) & IS_STORE));
136 *mask_ptr |= ENCODE_MUST_NOT_ALIAS;
137 break;
138 default:
139 LOG(FATAL) << "Oat: invalid memref kind - " << mem_type;
140 }
141}
142
143/*
144 * Mark load/store instructions that access Dalvik registers through the stack.
145 */
146void Mir2Lir::AnnotateDalvikRegAccess(LIR* lir, int reg_id, bool is_load,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700147 bool is64bit) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700148 SetMemRefType(lir, is_load, kDalvikReg);
149
150 /*
151 * Store the Dalvik register id in alias_info. Mark the MSB if it is a 64-bit
152 * access.
153 */
buzbeeb48819d2013-09-14 16:15:25 -0700154 lir->flags.alias_info = ENCODE_ALIAS_INFO(reg_id, is64bit);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700155}
156
157/*
158 * Debugging macros
159 */
160#define DUMP_RESOURCE_MASK(X)
161
162/* Pretty-print a LIR instruction */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700163void Mir2Lir::DumpLIRInsn(LIR* lir, unsigned char* base_addr) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700164 int offset = lir->offset;
165 int dest = lir->operands[0];
166 const bool dump_nop = (cu_->enable_debug & (1 << kDebugShowNops));
167
168 /* Handle pseudo-ops individually, and all regular insns as a group */
169 switch (lir->opcode) {
170 case kPseudoMethodEntry:
171 LOG(INFO) << "-------- method entry "
172 << PrettyMethod(cu_->method_idx, *cu_->dex_file);
173 break;
174 case kPseudoMethodExit:
175 LOG(INFO) << "-------- Method_Exit";
176 break;
177 case kPseudoBarrier:
178 LOG(INFO) << "-------- BARRIER";
179 break;
180 case kPseudoEntryBlock:
181 LOG(INFO) << "-------- entry offset: 0x" << std::hex << dest;
182 break;
183 case kPseudoDalvikByteCodeBoundary:
184 if (lir->operands[0] == 0) {
buzbee0d829482013-10-11 15:24:55 -0700185 // NOTE: only used for debug listings.
186 lir->operands[0] = WrapPointer(ArenaStrdup("No instruction string"));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700187 }
188 LOG(INFO) << "-------- dalvik offset: 0x" << std::hex
Bill Buzbee0b1191c2013-10-28 22:11:59 +0000189 << lir->dalvik_offset << " @ "
190 << reinterpret_cast<char*>(UnwrapPointer(lir->operands[0]));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700191 break;
192 case kPseudoExitBlock:
193 LOG(INFO) << "-------- exit offset: 0x" << std::hex << dest;
194 break;
195 case kPseudoPseudoAlign4:
196 LOG(INFO) << reinterpret_cast<uintptr_t>(base_addr) + offset << " (0x" << std::hex
197 << offset << "): .align4";
198 break;
199 case kPseudoEHBlockLabel:
200 LOG(INFO) << "Exception_Handling:";
201 break;
202 case kPseudoTargetLabel:
203 case kPseudoNormalBlockLabel:
204 LOG(INFO) << "L" << reinterpret_cast<void*>(lir) << ":";
205 break;
206 case kPseudoThrowTarget:
207 LOG(INFO) << "LT" << reinterpret_cast<void*>(lir) << ":";
208 break;
209 case kPseudoIntrinsicRetry:
210 LOG(INFO) << "IR" << reinterpret_cast<void*>(lir) << ":";
211 break;
212 case kPseudoSuspendTarget:
213 LOG(INFO) << "LS" << reinterpret_cast<void*>(lir) << ":";
214 break;
215 case kPseudoSafepointPC:
216 LOG(INFO) << "LsafepointPC_0x" << std::hex << lir->offset << "_" << lir->dalvik_offset << ":";
217 break;
218 case kPseudoExportedPC:
219 LOG(INFO) << "LexportedPC_0x" << std::hex << lir->offset << "_" << lir->dalvik_offset << ":";
220 break;
221 case kPseudoCaseLabel:
222 LOG(INFO) << "LC" << reinterpret_cast<void*>(lir) << ": Case target 0x"
223 << std::hex << lir->operands[0] << "|" << std::dec <<
224 lir->operands[0];
225 break;
226 default:
227 if (lir->flags.is_nop && !dump_nop) {
228 break;
229 } else {
230 std::string op_name(BuildInsnString(GetTargetInstName(lir->opcode),
231 lir, base_addr));
232 std::string op_operands(BuildInsnString(GetTargetInstFmt(lir->opcode),
233 lir, base_addr));
Ian Rogers107c31e2014-01-23 20:55:29 -0800234 LOG(INFO) << StringPrintf("%5p: %-9s%s%s",
235 base_addr + offset,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700236 op_name.c_str(), op_operands.c_str(),
237 lir->flags.is_nop ? "(nop)" : "");
238 }
239 break;
240 }
241
buzbeeb48819d2013-09-14 16:15:25 -0700242 if (lir->u.m.use_mask && (!lir->flags.is_nop || dump_nop)) {
243 DUMP_RESOURCE_MASK(DumpResourceMask(lir, lir->u.m.use_mask, "use"));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700244 }
buzbeeb48819d2013-09-14 16:15:25 -0700245 if (lir->u.m.def_mask && (!lir->flags.is_nop || dump_nop)) {
246 DUMP_RESOURCE_MASK(DumpResourceMask(lir, lir->u.m.def_mask, "def"));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700247 }
248}
249
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700250void Mir2Lir::DumpPromotionMap() {
Razvan A Lupusoruda7a69b2014-01-08 15:09:50 -0800251 int num_regs = cu_->num_dalvik_registers + mir_graph_->GetNumUsedCompilerTemps();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700252 for (int i = 0; i < num_regs; i++) {
253 PromotionMap v_reg_map = promotion_map_[i];
254 std::string buf;
255 if (v_reg_map.fp_location == kLocPhysReg) {
256 StringAppendF(&buf, " : s%d", v_reg_map.FpReg & FpRegMask());
257 }
258
259 std::string buf3;
260 if (i < cu_->num_dalvik_registers) {
261 StringAppendF(&buf3, "%02d", i);
262 } else if (i == mir_graph_->GetMethodSReg()) {
263 buf3 = "Method*";
264 } else {
265 StringAppendF(&buf3, "ct%d", i - cu_->num_dalvik_registers);
266 }
267
268 LOG(INFO) << StringPrintf("V[%s] -> %s%d%s", buf3.c_str(),
269 v_reg_map.core_location == kLocPhysReg ?
270 "r" : "SP+", v_reg_map.core_location == kLocPhysReg ?
271 v_reg_map.core_reg : SRegOffset(i),
272 buf.c_str());
273 }
274}
275
Brian Carlstrom7940e442013-07-12 13:46:57 -0700276/* Dump instructions and constant pool contents */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700277void Mir2Lir::CodegenDump() {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700278 LOG(INFO) << "Dumping LIR insns for "
279 << PrettyMethod(cu_->method_idx, *cu_->dex_file);
280 LIR* lir_insn;
281 int insns_size = cu_->code_item->insns_size_in_code_units_;
282
283 LOG(INFO) << "Regs (excluding ins) : " << cu_->num_regs;
284 LOG(INFO) << "Ins : " << cu_->num_ins;
285 LOG(INFO) << "Outs : " << cu_->num_outs;
286 LOG(INFO) << "CoreSpills : " << num_core_spills_;
287 LOG(INFO) << "FPSpills : " << num_fp_spills_;
Razvan A Lupusoruda7a69b2014-01-08 15:09:50 -0800288 LOG(INFO) << "CompilerTemps : " << mir_graph_->GetNumUsedCompilerTemps();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700289 LOG(INFO) << "Frame size : " << frame_size_;
290 LOG(INFO) << "code size is " << total_size_ <<
291 " bytes, Dalvik size is " << insns_size * 2;
292 LOG(INFO) << "expansion factor: "
293 << static_cast<float>(total_size_) / static_cast<float>(insns_size * 2);
294 DumpPromotionMap();
295 for (lir_insn = first_lir_insn_; lir_insn != NULL; lir_insn = lir_insn->next) {
296 DumpLIRInsn(lir_insn, 0);
297 }
298 for (lir_insn = literal_list_; lir_insn != NULL; lir_insn = lir_insn->next) {
299 LOG(INFO) << StringPrintf("%x (%04x): .word (%#x)", lir_insn->offset, lir_insn->offset,
300 lir_insn->operands[0]);
301 }
302
303 const DexFile::MethodId& method_id =
304 cu_->dex_file->GetMethodId(cu_->method_idx);
Ian Rogersd91d6d62013-09-25 20:26:14 -0700305 const Signature signature = cu_->dex_file->GetMethodSignature(method_id);
306 const char* name = cu_->dex_file->GetMethodName(method_id);
307 const char* descriptor(cu_->dex_file->GetMethodDeclaringClassDescriptor(method_id));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700308
309 // Dump mapping tables
Vladimir Marko06606b92013-12-02 15:31:08 +0000310 if (!encoded_mapping_table_.empty()) {
311 MappingTable table(&encoded_mapping_table_[0]);
312 DumpMappingTable("PC2Dex_MappingTable", descriptor, name, signature,
313 table.PcToDexSize(), table.PcToDexBegin());
314 DumpMappingTable("Dex2PC_MappingTable", descriptor, name, signature,
315 table.DexToPcSize(), table.DexToPcBegin());
316 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700317}
318
319/*
320 * Search the existing constants in the literal pool for an exact or close match
321 * within specified delta (greater or equal to 0).
322 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700323LIR* Mir2Lir::ScanLiteralPool(LIR* data_target, int value, unsigned int delta) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700324 while (data_target) {
325 if ((static_cast<unsigned>(value - data_target->operands[0])) <= delta)
326 return data_target;
327 data_target = data_target->next;
328 }
329 return NULL;
330}
331
332/* Search the existing constants in the literal pool for an exact wide match */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700333LIR* Mir2Lir::ScanLiteralPoolWide(LIR* data_target, int val_lo, int val_hi) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700334 bool lo_match = false;
335 LIR* lo_target = NULL;
336 while (data_target) {
337 if (lo_match && (data_target->operands[0] == val_hi)) {
338 // Record high word in case we need to expand this later.
339 lo_target->operands[1] = val_hi;
340 return lo_target;
341 }
342 lo_match = false;
343 if (data_target->operands[0] == val_lo) {
344 lo_match = true;
345 lo_target = data_target;
346 }
347 data_target = data_target->next;
348 }
349 return NULL;
350}
351
352/*
353 * The following are building blocks to insert constants into the pool or
354 * instruction streams.
355 */
356
357/* Add a 32-bit constant to the constant pool */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700358LIR* Mir2Lir::AddWordData(LIR* *constant_list_p, int value) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700359 /* Add the constant to the literal pool */
360 if (constant_list_p) {
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000361 LIR* new_value = static_cast<LIR*>(arena_->Alloc(sizeof(LIR), kArenaAllocData));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700362 new_value->operands[0] = value;
363 new_value->next = *constant_list_p;
364 *constant_list_p = new_value;
buzbeeb48819d2013-09-14 16:15:25 -0700365 estimated_native_code_size_ += sizeof(value);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700366 return new_value;
367 }
368 return NULL;
369}
370
371/* Add a 64-bit constant to the constant pool or mixed with code */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700372LIR* Mir2Lir::AddWideData(LIR* *constant_list_p, int val_lo, int val_hi) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700373 AddWordData(constant_list_p, val_hi);
374 return AddWordData(constant_list_p, val_lo);
375}
376
Andreas Gampe2da88232014-02-27 12:26:20 -0800377static void Push32(std::vector<uint8_t>&buf, int data) {
Brian Carlstromdf629502013-07-17 22:39:56 -0700378 buf.push_back(data & 0xff);
379 buf.push_back((data >> 8) & 0xff);
380 buf.push_back((data >> 16) & 0xff);
381 buf.push_back((data >> 24) & 0xff);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700382}
383
Andreas Gampe2da88232014-02-27 12:26:20 -0800384// Push 8 bytes on 64-bit target systems; 4 on 32-bit target systems.
385static void PushPointer(std::vector<uint8_t>&buf, const void* pointer, bool target64) {
386 uint64_t data = reinterpret_cast<uintptr_t>(pointer);
387 if (target64) {
388 Push32(buf, data & 0xFFFFFFFF);
389 Push32(buf, (data >> 32) & 0xFFFFFFFF);
buzbee0d829482013-10-11 15:24:55 -0700390 } else {
Andreas Gampe2da88232014-02-27 12:26:20 -0800391 Push32(buf, static_cast<uint32_t>(data));
buzbee0d829482013-10-11 15:24:55 -0700392 }
393}
394
Brian Carlstrom7940e442013-07-12 13:46:57 -0700395static void AlignBuffer(std::vector<uint8_t>&buf, size_t offset) {
396 while (buf.size() < offset) {
397 buf.push_back(0);
398 }
399}
400
401/* Write the literal pool to the output stream */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700402void Mir2Lir::InstallLiteralPools() {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700403 AlignBuffer(code_buffer_, data_offset_);
404 LIR* data_lir = literal_list_;
405 while (data_lir != NULL) {
Andreas Gampe2da88232014-02-27 12:26:20 -0800406 Push32(code_buffer_, data_lir->operands[0]);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700407 data_lir = NEXT_LIR(data_lir);
408 }
409 // Push code and method literals, record offsets for the compiler to patch.
410 data_lir = code_literal_list_;
411 while (data_lir != NULL) {
Jeff Hao49161ce2014-03-12 11:05:25 -0700412 uint32_t target_method_idx = data_lir->operands[0];
413 const DexFile* target_dex_file =
414 reinterpret_cast<const DexFile*>(UnwrapPointer(data_lir->operands[1]));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700415 cu_->compiler_driver->AddCodePatch(cu_->dex_file,
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700416 cu_->class_def_idx,
417 cu_->method_idx,
418 cu_->invoke_type,
Jeff Hao49161ce2014-03-12 11:05:25 -0700419 target_method_idx,
420 target_dex_file,
421 static_cast<InvokeType>(data_lir->operands[2]),
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700422 code_buffer_.size());
Jeff Hao49161ce2014-03-12 11:05:25 -0700423 const DexFile::MethodId& target_method_id = target_dex_file->GetMethodId(target_method_idx);
buzbee0d829482013-10-11 15:24:55 -0700424 // unique value based on target to ensure code deduplication works
Jeff Hao49161ce2014-03-12 11:05:25 -0700425 PushPointer(code_buffer_, &target_method_id, cu_->target64);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700426 data_lir = NEXT_LIR(data_lir);
427 }
428 data_lir = method_literal_list_;
429 while (data_lir != NULL) {
Jeff Hao49161ce2014-03-12 11:05:25 -0700430 uint32_t target_method_idx = data_lir->operands[0];
431 const DexFile* target_dex_file =
432 reinterpret_cast<const DexFile*>(UnwrapPointer(data_lir->operands[1]));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700433 cu_->compiler_driver->AddMethodPatch(cu_->dex_file,
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700434 cu_->class_def_idx,
435 cu_->method_idx,
436 cu_->invoke_type,
Jeff Hao49161ce2014-03-12 11:05:25 -0700437 target_method_idx,
438 target_dex_file,
439 static_cast<InvokeType>(data_lir->operands[2]),
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700440 code_buffer_.size());
Jeff Hao49161ce2014-03-12 11:05:25 -0700441 const DexFile::MethodId& target_method_id = target_dex_file->GetMethodId(target_method_idx);
buzbee0d829482013-10-11 15:24:55 -0700442 // unique value based on target to ensure code deduplication works
Jeff Hao49161ce2014-03-12 11:05:25 -0700443 PushPointer(code_buffer_, &target_method_id, cu_->target64);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700444 data_lir = NEXT_LIR(data_lir);
445 }
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800446 // Push class literals.
447 data_lir = class_literal_list_;
448 while (data_lir != NULL) {
Jeff Hao49161ce2014-03-12 11:05:25 -0700449 uint32_t target_method_idx = data_lir->operands[0];
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800450 cu_->compiler_driver->AddClassPatch(cu_->dex_file,
451 cu_->class_def_idx,
452 cu_->method_idx,
Jeff Hao49161ce2014-03-12 11:05:25 -0700453 target_method_idx,
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800454 code_buffer_.size());
Jeff Hao49161ce2014-03-12 11:05:25 -0700455 const DexFile::TypeId& target_method_id = cu_->dex_file->GetTypeId(target_method_idx);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800456 // unique value based on target to ensure code deduplication works
Jeff Hao49161ce2014-03-12 11:05:25 -0700457 PushPointer(code_buffer_, &target_method_id, cu_->target64);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800458 data_lir = NEXT_LIR(data_lir);
459 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700460}
461
462/* Write the switch tables to the output stream */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700463void Mir2Lir::InstallSwitchTables() {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700464 GrowableArray<SwitchTable*>::Iterator iterator(&switch_tables_);
465 while (true) {
466 Mir2Lir::SwitchTable* tab_rec = iterator.Next();
467 if (tab_rec == NULL) break;
468 AlignBuffer(code_buffer_, tab_rec->offset);
469 /*
470 * For Arm, our reference point is the address of the bx
471 * instruction that does the launch, so we have to subtract
472 * the auto pc-advance. For other targets the reference point
473 * is a label, so we can use the offset as-is.
474 */
475 int bx_offset = INVALID_OFFSET;
476 switch (cu_->instruction_set) {
477 case kThumb2:
buzbeeb48819d2013-09-14 16:15:25 -0700478 DCHECK(tab_rec->anchor->flags.fixup != kFixupNone);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700479 bx_offset = tab_rec->anchor->offset + 4;
480 break;
481 case kX86:
482 bx_offset = 0;
483 break;
484 case kMips:
485 bx_offset = tab_rec->anchor->offset;
486 break;
487 default: LOG(FATAL) << "Unexpected instruction set: " << cu_->instruction_set;
488 }
489 if (cu_->verbose) {
490 LOG(INFO) << "Switch table for offset 0x" << std::hex << bx_offset;
491 }
492 if (tab_rec->table[0] == Instruction::kSparseSwitchSignature) {
buzbee0d829482013-10-11 15:24:55 -0700493 const int32_t* keys = reinterpret_cast<const int32_t*>(&(tab_rec->table[2]));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700494 for (int elems = 0; elems < tab_rec->table[1]; elems++) {
495 int disp = tab_rec->targets[elems]->offset - bx_offset;
496 if (cu_->verbose) {
497 LOG(INFO) << " Case[" << elems << "] key: 0x"
498 << std::hex << keys[elems] << ", disp: 0x"
499 << std::hex << disp;
500 }
Andreas Gampe2da88232014-02-27 12:26:20 -0800501 Push32(code_buffer_, keys[elems]);
502 Push32(code_buffer_,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700503 tab_rec->targets[elems]->offset - bx_offset);
504 }
505 } else {
506 DCHECK_EQ(static_cast<int>(tab_rec->table[0]),
507 static_cast<int>(Instruction::kPackedSwitchSignature));
508 for (int elems = 0; elems < tab_rec->table[1]; elems++) {
509 int disp = tab_rec->targets[elems]->offset - bx_offset;
510 if (cu_->verbose) {
511 LOG(INFO) << " Case[" << elems << "] disp: 0x"
512 << std::hex << disp;
513 }
Andreas Gampe2da88232014-02-27 12:26:20 -0800514 Push32(code_buffer_, tab_rec->targets[elems]->offset - bx_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700515 }
516 }
517 }
518}
519
520/* Write the fill array dta to the output stream */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700521void Mir2Lir::InstallFillArrayData() {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700522 GrowableArray<FillArrayData*>::Iterator iterator(&fill_array_data_);
523 while (true) {
524 Mir2Lir::FillArrayData *tab_rec = iterator.Next();
525 if (tab_rec == NULL) break;
526 AlignBuffer(code_buffer_, tab_rec->offset);
527 for (int i = 0; i < (tab_rec->size + 1) / 2; i++) {
Brian Carlstromdf629502013-07-17 22:39:56 -0700528 code_buffer_.push_back(tab_rec->table[i] & 0xFF);
529 code_buffer_.push_back((tab_rec->table[i] >> 8) & 0xFF);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700530 }
531 }
532}
533
buzbee0d829482013-10-11 15:24:55 -0700534static int AssignLiteralOffsetCommon(LIR* lir, CodeOffset offset) {
Brian Carlstrom02c8cc62013-07-18 15:54:44 -0700535 for (; lir != NULL; lir = lir->next) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700536 lir->offset = offset;
537 offset += 4;
538 }
539 return offset;
540}
541
buzbee0d829482013-10-11 15:24:55 -0700542static int AssignLiteralPointerOffsetCommon(LIR* lir, CodeOffset offset) {
543 unsigned int element_size = sizeof(void*);
544 // Align to natural pointer size.
545 offset = (offset + (element_size - 1)) & ~(element_size - 1);
546 for (; lir != NULL; lir = lir->next) {
547 lir->offset = offset;
548 offset += element_size;
549 }
550 return offset;
551}
552
Brian Carlstrom7940e442013-07-12 13:46:57 -0700553// Make sure we have a code address for every declared catch entry
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700554bool Mir2Lir::VerifyCatchEntries() {
Vladimir Marko06606b92013-12-02 15:31:08 +0000555 MappingTable table(&encoded_mapping_table_[0]);
556 std::vector<uint32_t> dex_pcs;
557 dex_pcs.reserve(table.DexToPcSize());
558 for (auto it = table.DexToPcBegin(), end = table.DexToPcEnd(); it != end; ++it) {
559 dex_pcs.push_back(it.DexPc());
560 }
561 // Sort dex_pcs, so that we can quickly check it against the ordered mir_graph_->catches_.
562 std::sort(dex_pcs.begin(), dex_pcs.end());
563
Brian Carlstrom7940e442013-07-12 13:46:57 -0700564 bool success = true;
Vladimir Marko06606b92013-12-02 15:31:08 +0000565 auto it = dex_pcs.begin(), end = dex_pcs.end();
566 for (uint32_t dex_pc : mir_graph_->catches_) {
567 while (it != end && *it < dex_pc) {
568 LOG(INFO) << "Unexpected catch entry @ dex pc 0x" << std::hex << *it;
569 ++it;
570 success = false;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700571 }
Vladimir Marko06606b92013-12-02 15:31:08 +0000572 if (it == end || *it > dex_pc) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700573 LOG(INFO) << "Missing native PC for catch entry @ 0x" << std::hex << dex_pc;
574 success = false;
Vladimir Marko06606b92013-12-02 15:31:08 +0000575 } else {
576 ++it;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700577 }
578 }
579 if (!success) {
580 LOG(INFO) << "Bad dex2pcMapping table in " << PrettyMethod(cu_->method_idx, *cu_->dex_file);
581 LOG(INFO) << "Entries @ decode: " << mir_graph_->catches_.size() << ", Entries in table: "
Vladimir Marko06606b92013-12-02 15:31:08 +0000582 << table.DexToPcSize();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700583 }
584 return success;
585}
586
587
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700588void Mir2Lir::CreateMappingTables() {
Vladimir Marko1e6cb632013-11-28 16:27:29 +0000589 uint32_t pc2dex_data_size = 0u;
590 uint32_t pc2dex_entries = 0u;
591 uint32_t pc2dex_offset = 0u;
592 uint32_t pc2dex_dalvik_offset = 0u;
593 uint32_t dex2pc_data_size = 0u;
594 uint32_t dex2pc_entries = 0u;
595 uint32_t dex2pc_offset = 0u;
596 uint32_t dex2pc_dalvik_offset = 0u;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700597 for (LIR* tgt_lir = first_lir_insn_; tgt_lir != NULL; tgt_lir = NEXT_LIR(tgt_lir)) {
598 if (!tgt_lir->flags.is_nop && (tgt_lir->opcode == kPseudoSafepointPC)) {
Vladimir Marko1e6cb632013-11-28 16:27:29 +0000599 pc2dex_entries += 1;
600 DCHECK(pc2dex_offset <= tgt_lir->offset);
601 pc2dex_data_size += UnsignedLeb128Size(tgt_lir->offset - pc2dex_offset);
602 pc2dex_data_size += SignedLeb128Size(static_cast<int32_t>(tgt_lir->dalvik_offset) -
603 static_cast<int32_t>(pc2dex_dalvik_offset));
604 pc2dex_offset = tgt_lir->offset;
605 pc2dex_dalvik_offset = tgt_lir->dalvik_offset;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700606 }
607 if (!tgt_lir->flags.is_nop && (tgt_lir->opcode == kPseudoExportedPC)) {
Vladimir Marko1e6cb632013-11-28 16:27:29 +0000608 dex2pc_entries += 1;
609 DCHECK(dex2pc_offset <= tgt_lir->offset);
610 dex2pc_data_size += UnsignedLeb128Size(tgt_lir->offset - dex2pc_offset);
611 dex2pc_data_size += SignedLeb128Size(static_cast<int32_t>(tgt_lir->dalvik_offset) -
612 static_cast<int32_t>(dex2pc_dalvik_offset));
613 dex2pc_offset = tgt_lir->offset;
614 dex2pc_dalvik_offset = tgt_lir->dalvik_offset;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700615 }
616 }
Vladimir Marko1e6cb632013-11-28 16:27:29 +0000617
618 uint32_t total_entries = pc2dex_entries + dex2pc_entries;
619 uint32_t hdr_data_size = UnsignedLeb128Size(total_entries) + UnsignedLeb128Size(pc2dex_entries);
620 uint32_t data_size = hdr_data_size + pc2dex_data_size + dex2pc_data_size;
Vladimir Marko06606b92013-12-02 15:31:08 +0000621 encoded_mapping_table_.resize(data_size);
622 uint8_t* write_pos = &encoded_mapping_table_[0];
623 write_pos = EncodeUnsignedLeb128(write_pos, total_entries);
624 write_pos = EncodeUnsignedLeb128(write_pos, pc2dex_entries);
625 DCHECK_EQ(static_cast<size_t>(write_pos - &encoded_mapping_table_[0]), hdr_data_size);
626 uint8_t* write_pos2 = write_pos + pc2dex_data_size;
Vladimir Marko1e6cb632013-11-28 16:27:29 +0000627
Vladimir Marko1e6cb632013-11-28 16:27:29 +0000628 pc2dex_offset = 0u;
629 pc2dex_dalvik_offset = 0u;
Vladimir Marko06606b92013-12-02 15:31:08 +0000630 dex2pc_offset = 0u;
631 dex2pc_dalvik_offset = 0u;
632 for (LIR* tgt_lir = first_lir_insn_; tgt_lir != NULL; tgt_lir = NEXT_LIR(tgt_lir)) {
633 if (!tgt_lir->flags.is_nop && (tgt_lir->opcode == kPseudoSafepointPC)) {
634 DCHECK(pc2dex_offset <= tgt_lir->offset);
635 write_pos = EncodeUnsignedLeb128(write_pos, tgt_lir->offset - pc2dex_offset);
636 write_pos = EncodeSignedLeb128(write_pos, static_cast<int32_t>(tgt_lir->dalvik_offset) -
637 static_cast<int32_t>(pc2dex_dalvik_offset));
638 pc2dex_offset = tgt_lir->offset;
639 pc2dex_dalvik_offset = tgt_lir->dalvik_offset;
640 }
641 if (!tgt_lir->flags.is_nop && (tgt_lir->opcode == kPseudoExportedPC)) {
642 DCHECK(dex2pc_offset <= tgt_lir->offset);
643 write_pos2 = EncodeUnsignedLeb128(write_pos2, tgt_lir->offset - dex2pc_offset);
644 write_pos2 = EncodeSignedLeb128(write_pos2, static_cast<int32_t>(tgt_lir->dalvik_offset) -
645 static_cast<int32_t>(dex2pc_dalvik_offset));
646 dex2pc_offset = tgt_lir->offset;
647 dex2pc_dalvik_offset = tgt_lir->dalvik_offset;
648 }
Vladimir Marko1e6cb632013-11-28 16:27:29 +0000649 }
Vladimir Marko06606b92013-12-02 15:31:08 +0000650 DCHECK_EQ(static_cast<size_t>(write_pos - &encoded_mapping_table_[0]),
651 hdr_data_size + pc2dex_data_size);
652 DCHECK_EQ(static_cast<size_t>(write_pos2 - &encoded_mapping_table_[0]), data_size);
Vladimir Marko1e6cb632013-11-28 16:27:29 +0000653
Ian Rogers96faf5b2013-08-09 22:05:32 -0700654 if (kIsDebugBuild) {
Vladimir Marko06606b92013-12-02 15:31:08 +0000655 CHECK(VerifyCatchEntries());
656
Ian Rogers96faf5b2013-08-09 22:05:32 -0700657 // Verify the encoded table holds the expected data.
Vladimir Marko06606b92013-12-02 15:31:08 +0000658 MappingTable table(&encoded_mapping_table_[0]);
Ian Rogers96faf5b2013-08-09 22:05:32 -0700659 CHECK_EQ(table.TotalSize(), total_entries);
660 CHECK_EQ(table.PcToDexSize(), pc2dex_entries);
Vladimir Marko1e6cb632013-11-28 16:27:29 +0000661 auto it = table.PcToDexBegin();
Vladimir Marko06606b92013-12-02 15:31:08 +0000662 auto it2 = table.DexToPcBegin();
663 for (LIR* tgt_lir = first_lir_insn_; tgt_lir != NULL; tgt_lir = NEXT_LIR(tgt_lir)) {
664 if (!tgt_lir->flags.is_nop && (tgt_lir->opcode == kPseudoSafepointPC)) {
665 CHECK_EQ(tgt_lir->offset, it.NativePcOffset());
666 CHECK_EQ(tgt_lir->dalvik_offset, it.DexPc());
667 ++it;
668 }
669 if (!tgt_lir->flags.is_nop && (tgt_lir->opcode == kPseudoExportedPC)) {
670 CHECK_EQ(tgt_lir->offset, it2.NativePcOffset());
671 CHECK_EQ(tgt_lir->dalvik_offset, it2.DexPc());
672 ++it2;
673 }
Ian Rogers96faf5b2013-08-09 22:05:32 -0700674 }
Vladimir Marko1e6cb632013-11-28 16:27:29 +0000675 CHECK(it == table.PcToDexEnd());
Vladimir Marko1e6cb632013-11-28 16:27:29 +0000676 CHECK(it2 == table.DexToPcEnd());
Ian Rogers96faf5b2013-08-09 22:05:32 -0700677 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700678}
679
680class NativePcToReferenceMapBuilder {
681 public:
682 NativePcToReferenceMapBuilder(std::vector<uint8_t>* table,
683 size_t entries, uint32_t max_native_offset,
684 size_t references_width) : entries_(entries),
685 references_width_(references_width), in_use_(entries),
686 table_(table) {
687 // Compute width in bytes needed to hold max_native_offset.
688 native_offset_width_ = 0;
689 while (max_native_offset != 0) {
690 native_offset_width_++;
691 max_native_offset >>= 8;
692 }
693 // Resize table and set up header.
694 table->resize((EntryWidth() * entries) + sizeof(uint32_t));
695 CHECK_LT(native_offset_width_, 1U << 3);
696 (*table)[0] = native_offset_width_ & 7;
697 CHECK_LT(references_width_, 1U << 13);
698 (*table)[0] |= (references_width_ << 3) & 0xFF;
699 (*table)[1] = (references_width_ >> 5) & 0xFF;
700 CHECK_LT(entries, 1U << 16);
701 (*table)[2] = entries & 0xFF;
702 (*table)[3] = (entries >> 8) & 0xFF;
703 }
704
705 void AddEntry(uint32_t native_offset, const uint8_t* references) {
706 size_t table_index = TableIndex(native_offset);
707 while (in_use_[table_index]) {
708 table_index = (table_index + 1) % entries_;
709 }
710 in_use_[table_index] = true;
buzbee0d829482013-10-11 15:24:55 -0700711 SetCodeOffset(table_index, native_offset);
712 DCHECK_EQ(native_offset, GetCodeOffset(table_index));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700713 SetReferences(table_index, references);
714 }
715
716 private:
717 size_t TableIndex(uint32_t native_offset) {
718 return NativePcOffsetToReferenceMap::Hash(native_offset) % entries_;
719 }
720
buzbee0d829482013-10-11 15:24:55 -0700721 uint32_t GetCodeOffset(size_t table_index) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700722 uint32_t native_offset = 0;
723 size_t table_offset = (table_index * EntryWidth()) + sizeof(uint32_t);
724 for (size_t i = 0; i < native_offset_width_; i++) {
725 native_offset |= (*table_)[table_offset + i] << (i * 8);
726 }
727 return native_offset;
728 }
729
buzbee0d829482013-10-11 15:24:55 -0700730 void SetCodeOffset(size_t table_index, uint32_t native_offset) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700731 size_t table_offset = (table_index * EntryWidth()) + sizeof(uint32_t);
732 for (size_t i = 0; i < native_offset_width_; i++) {
733 (*table_)[table_offset + i] = (native_offset >> (i * 8)) & 0xFF;
734 }
735 }
736
737 void SetReferences(size_t table_index, const uint8_t* references) {
738 size_t table_offset = (table_index * EntryWidth()) + sizeof(uint32_t);
739 memcpy(&(*table_)[table_offset + native_offset_width_], references, references_width_);
740 }
741
742 size_t EntryWidth() const {
743 return native_offset_width_ + references_width_;
744 }
745
746 // Number of entries in the table.
747 const size_t entries_;
748 // Number of bytes used to encode the reference bitmap.
749 const size_t references_width_;
750 // Number of bytes used to encode a native offset.
751 size_t native_offset_width_;
752 // Entries that are in use.
753 std::vector<bool> in_use_;
754 // The table we're building.
755 std::vector<uint8_t>* const table_;
756};
757
758void Mir2Lir::CreateNativeGcMap() {
Vladimir Marko06606b92013-12-02 15:31:08 +0000759 DCHECK(!encoded_mapping_table_.empty());
760 MappingTable mapping_table(&encoded_mapping_table_[0]);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700761 uint32_t max_native_offset = 0;
Vladimir Marko06606b92013-12-02 15:31:08 +0000762 for (auto it = mapping_table.PcToDexBegin(), end = mapping_table.PcToDexEnd(); it != end; ++it) {
763 uint32_t native_offset = it.NativePcOffset();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700764 if (native_offset > max_native_offset) {
765 max_native_offset = native_offset;
766 }
767 }
768 MethodReference method_ref(cu_->dex_file, cu_->method_idx);
Vladimir Marko2730db02014-01-27 11:15:17 +0000769 const std::vector<uint8_t>& gc_map_raw =
770 mir_graph_->GetCurrentDexCompilationUnit()->GetVerifiedMethod()->GetDexGcMap();
771 verifier::DexPcToReferenceMap dex_gc_map(&(gc_map_raw)[0]);
772 DCHECK_EQ(gc_map_raw.size(), dex_gc_map.RawSize());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700773 // Compute native offset to references size.
774 NativePcToReferenceMapBuilder native_gc_map_builder(&native_gc_map_,
Vladimir Marko06606b92013-12-02 15:31:08 +0000775 mapping_table.PcToDexSize(),
776 max_native_offset, dex_gc_map.RegWidth());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700777
Vladimir Marko06606b92013-12-02 15:31:08 +0000778 for (auto it = mapping_table.PcToDexBegin(), end = mapping_table.PcToDexEnd(); it != end; ++it) {
779 uint32_t native_offset = it.NativePcOffset();
780 uint32_t dex_pc = it.DexPc();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700781 const uint8_t* references = dex_gc_map.FindBitMap(dex_pc, false);
782 CHECK(references != NULL) << "Missing ref for dex pc 0x" << std::hex << dex_pc;
783 native_gc_map_builder.AddEntry(native_offset, references);
784 }
785}
786
787/* Determine the offset of each literal field */
buzbee0d829482013-10-11 15:24:55 -0700788int Mir2Lir::AssignLiteralOffset(CodeOffset offset) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700789 offset = AssignLiteralOffsetCommon(literal_list_, offset);
buzbee0d829482013-10-11 15:24:55 -0700790 offset = AssignLiteralPointerOffsetCommon(code_literal_list_, offset);
791 offset = AssignLiteralPointerOffsetCommon(method_literal_list_, offset);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800792 offset = AssignLiteralPointerOffsetCommon(class_literal_list_, offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700793 return offset;
794}
795
buzbee0d829482013-10-11 15:24:55 -0700796int Mir2Lir::AssignSwitchTablesOffset(CodeOffset offset) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700797 GrowableArray<SwitchTable*>::Iterator iterator(&switch_tables_);
798 while (true) {
buzbee0d829482013-10-11 15:24:55 -0700799 Mir2Lir::SwitchTable* tab_rec = iterator.Next();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700800 if (tab_rec == NULL) break;
801 tab_rec->offset = offset;
802 if (tab_rec->table[0] == Instruction::kSparseSwitchSignature) {
803 offset += tab_rec->table[1] * (sizeof(int) * 2);
804 } else {
805 DCHECK_EQ(static_cast<int>(tab_rec->table[0]),
806 static_cast<int>(Instruction::kPackedSwitchSignature));
807 offset += tab_rec->table[1] * sizeof(int);
808 }
809 }
810 return offset;
811}
812
buzbee0d829482013-10-11 15:24:55 -0700813int Mir2Lir::AssignFillArrayDataOffset(CodeOffset offset) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700814 GrowableArray<FillArrayData*>::Iterator iterator(&fill_array_data_);
815 while (true) {
816 Mir2Lir::FillArrayData *tab_rec = iterator.Next();
817 if (tab_rec == NULL) break;
818 tab_rec->offset = offset;
819 offset += tab_rec->size;
820 // word align
821 offset = (offset + 3) & ~3;
822 }
823 return offset;
824}
825
Brian Carlstrom7940e442013-07-12 13:46:57 -0700826/*
827 * Insert a kPseudoCaseLabel at the beginning of the Dalvik
buzbeeb48819d2013-09-14 16:15:25 -0700828 * offset vaddr if pretty-printing, otherise use the standard block
829 * label. The selected label will be used to fix up the case
buzbee252254b2013-09-08 16:20:53 -0700830 * branch table during the assembly phase. All resource flags
831 * are set to prevent code motion. KeyVal is just there for debugging.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700832 */
buzbee0d829482013-10-11 15:24:55 -0700833LIR* Mir2Lir::InsertCaseLabel(DexOffset vaddr, int keyVal) {
buzbee252254b2013-09-08 16:20:53 -0700834 LIR* boundary_lir = &block_label_list_[mir_graph_->FindBlock(vaddr)->id];
buzbeeb48819d2013-09-14 16:15:25 -0700835 LIR* res = boundary_lir;
836 if (cu_->verbose) {
837 // Only pay the expense if we're pretty-printing.
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000838 LIR* new_label = static_cast<LIR*>(arena_->Alloc(sizeof(LIR), kArenaAllocLIR));
buzbeeb48819d2013-09-14 16:15:25 -0700839 new_label->dalvik_offset = vaddr;
840 new_label->opcode = kPseudoCaseLabel;
841 new_label->operands[0] = keyVal;
842 new_label->flags.fixup = kFixupLabel;
843 DCHECK(!new_label->flags.use_def_invalid);
844 new_label->u.m.def_mask = ENCODE_ALL;
845 InsertLIRAfter(boundary_lir, new_label);
846 res = new_label;
847 }
848 return res;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700849}
850
buzbee0d829482013-10-11 15:24:55 -0700851void Mir2Lir::MarkPackedCaseLabels(Mir2Lir::SwitchTable* tab_rec) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700852 const uint16_t* table = tab_rec->table;
buzbee0d829482013-10-11 15:24:55 -0700853 DexOffset base_vaddr = tab_rec->vaddr;
854 const int32_t *targets = reinterpret_cast<const int32_t*>(&table[4]);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700855 int entries = table[1];
856 int low_key = s4FromSwitchData(&table[2]);
857 for (int i = 0; i < entries; i++) {
858 tab_rec->targets[i] = InsertCaseLabel(base_vaddr + targets[i], i + low_key);
859 }
860}
861
buzbee0d829482013-10-11 15:24:55 -0700862void Mir2Lir::MarkSparseCaseLabels(Mir2Lir::SwitchTable* tab_rec) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700863 const uint16_t* table = tab_rec->table;
buzbee0d829482013-10-11 15:24:55 -0700864 DexOffset base_vaddr = tab_rec->vaddr;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700865 int entries = table[1];
buzbee0d829482013-10-11 15:24:55 -0700866 const int32_t* keys = reinterpret_cast<const int32_t*>(&table[2]);
867 const int32_t* targets = &keys[entries];
Brian Carlstrom7940e442013-07-12 13:46:57 -0700868 for (int i = 0; i < entries; i++) {
869 tab_rec->targets[i] = InsertCaseLabel(base_vaddr + targets[i], keys[i]);
870 }
871}
872
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700873void Mir2Lir::ProcessSwitchTables() {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700874 GrowableArray<SwitchTable*>::Iterator iterator(&switch_tables_);
875 while (true) {
876 Mir2Lir::SwitchTable *tab_rec = iterator.Next();
877 if (tab_rec == NULL) break;
878 if (tab_rec->table[0] == Instruction::kPackedSwitchSignature) {
879 MarkPackedCaseLabels(tab_rec);
880 } else if (tab_rec->table[0] == Instruction::kSparseSwitchSignature) {
881 MarkSparseCaseLabels(tab_rec);
882 } else {
883 LOG(FATAL) << "Invalid switch table";
884 }
885 }
886}
887
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700888void Mir2Lir::DumpSparseSwitchTable(const uint16_t* table) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700889 /*
890 * Sparse switch data format:
891 * ushort ident = 0x0200 magic value
892 * ushort size number of entries in the table; > 0
893 * int keys[size] keys, sorted low-to-high; 32-bit aligned
894 * int targets[size] branch targets, relative to switch opcode
895 *
896 * Total size is (2+size*4) 16-bit code units.
897 */
Brian Carlstrom7940e442013-07-12 13:46:57 -0700898 uint16_t ident = table[0];
899 int entries = table[1];
buzbee0d829482013-10-11 15:24:55 -0700900 const int32_t* keys = reinterpret_cast<const int32_t*>(&table[2]);
901 const int32_t* targets = &keys[entries];
Brian Carlstrom7940e442013-07-12 13:46:57 -0700902 LOG(INFO) << "Sparse switch table - ident:0x" << std::hex << ident
903 << ", entries: " << std::dec << entries;
904 for (int i = 0; i < entries; i++) {
905 LOG(INFO) << " Key[" << keys[i] << "] -> 0x" << std::hex << targets[i];
906 }
907}
908
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700909void Mir2Lir::DumpPackedSwitchTable(const uint16_t* table) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700910 /*
911 * Packed switch data format:
912 * ushort ident = 0x0100 magic value
913 * ushort size number of entries in the table
914 * int first_key first (and lowest) switch case value
915 * int targets[size] branch targets, relative to switch opcode
916 *
917 * Total size is (4+size*2) 16-bit code units.
918 */
Brian Carlstrom7940e442013-07-12 13:46:57 -0700919 uint16_t ident = table[0];
buzbee0d829482013-10-11 15:24:55 -0700920 const int32_t* targets = reinterpret_cast<const int32_t*>(&table[4]);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700921 int entries = table[1];
922 int low_key = s4FromSwitchData(&table[2]);
923 LOG(INFO) << "Packed switch table - ident:0x" << std::hex << ident
924 << ", entries: " << std::dec << entries << ", low_key: " << low_key;
925 for (int i = 0; i < entries; i++) {
926 LOG(INFO) << " Key[" << (i + low_key) << "] -> 0x" << std::hex
927 << targets[i];
928 }
929}
930
buzbee252254b2013-09-08 16:20:53 -0700931/* Set up special LIR to mark a Dalvik byte-code instruction start for pretty printing */
buzbee0d829482013-10-11 15:24:55 -0700932void Mir2Lir::MarkBoundary(DexOffset offset, const char* inst_str) {
933 // NOTE: only used for debug listings.
934 NewLIR1(kPseudoDalvikByteCodeBoundary, WrapPointer(ArenaStrdup(inst_str)));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700935}
936
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700937bool Mir2Lir::EvaluateBranch(Instruction::Code opcode, int32_t src1, int32_t src2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700938 bool is_taken;
939 switch (opcode) {
940 case Instruction::IF_EQ: is_taken = (src1 == src2); break;
941 case Instruction::IF_NE: is_taken = (src1 != src2); break;
942 case Instruction::IF_LT: is_taken = (src1 < src2); break;
943 case Instruction::IF_GE: is_taken = (src1 >= src2); break;
944 case Instruction::IF_GT: is_taken = (src1 > src2); break;
945 case Instruction::IF_LE: is_taken = (src1 <= src2); break;
946 case Instruction::IF_EQZ: is_taken = (src1 == 0); break;
947 case Instruction::IF_NEZ: is_taken = (src1 != 0); break;
948 case Instruction::IF_LTZ: is_taken = (src1 < 0); break;
949 case Instruction::IF_GEZ: is_taken = (src1 >= 0); break;
950 case Instruction::IF_GTZ: is_taken = (src1 > 0); break;
951 case Instruction::IF_LEZ: is_taken = (src1 <= 0); break;
952 default:
953 LOG(FATAL) << "Unexpected opcode " << opcode;
954 is_taken = false;
955 }
956 return is_taken;
957}
958
959// Convert relation of src1/src2 to src2/src1
960ConditionCode Mir2Lir::FlipComparisonOrder(ConditionCode before) {
961 ConditionCode res;
962 switch (before) {
963 case kCondEq: res = kCondEq; break;
964 case kCondNe: res = kCondNe; break;
965 case kCondLt: res = kCondGt; break;
966 case kCondGt: res = kCondLt; break;
967 case kCondLe: res = kCondGe; break;
968 case kCondGe: res = kCondLe; break;
969 default:
970 res = static_cast<ConditionCode>(0);
971 LOG(FATAL) << "Unexpected ccode " << before;
972 }
973 return res;
974}
975
Vladimir Markoa1a70742014-03-03 10:28:05 +0000976ConditionCode Mir2Lir::NegateComparison(ConditionCode before) {
977 ConditionCode res;
978 switch (before) {
979 case kCondEq: res = kCondNe; break;
980 case kCondNe: res = kCondEq; break;
981 case kCondLt: res = kCondGe; break;
982 case kCondGt: res = kCondLe; break;
983 case kCondLe: res = kCondGt; break;
984 case kCondGe: res = kCondLt; break;
985 default:
986 res = static_cast<ConditionCode>(0);
987 LOG(FATAL) << "Unexpected ccode " << before;
988 }
989 return res;
990}
991
Brian Carlstrom7940e442013-07-12 13:46:57 -0700992// TODO: move to mir_to_lir.cc
993Mir2Lir::Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena)
994 : Backend(arena),
995 literal_list_(NULL),
996 method_literal_list_(NULL),
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800997 class_literal_list_(NULL),
Brian Carlstrom7940e442013-07-12 13:46:57 -0700998 code_literal_list_(NULL),
buzbeeb48819d2013-09-14 16:15:25 -0700999 first_fixup_(NULL),
Brian Carlstrom7940e442013-07-12 13:46:57 -07001000 cu_(cu),
1001 mir_graph_(mir_graph),
1002 switch_tables_(arena, 4, kGrowableArraySwitchTables),
1003 fill_array_data_(arena, 4, kGrowableArrayFillArrayData),
1004 throw_launchpads_(arena, 2048, kGrowableArrayThrowLaunchPads),
1005 suspend_launchpads_(arena, 4, kGrowableArraySuspendLaunchPads),
1006 intrinsic_launchpads_(arena, 2048, kGrowableArrayMisc),
buzbeebd663de2013-09-10 15:41:31 -07001007 tempreg_info_(arena, 20, kGrowableArrayMisc),
1008 reginfo_map_(arena, 64, kGrowableArrayMisc),
buzbee0d829482013-10-11 15:24:55 -07001009 pointer_storage_(arena, 128, kGrowableArrayMisc),
Brian Carlstrom7940e442013-07-12 13:46:57 -07001010 data_offset_(0),
1011 total_size_(0),
1012 block_label_list_(NULL),
buzbeed69835d2014-02-03 14:40:27 -08001013 promotion_map_(NULL),
Brian Carlstrom7940e442013-07-12 13:46:57 -07001014 current_dalvik_offset_(0),
buzbeeb48819d2013-09-14 16:15:25 -07001015 estimated_native_code_size_(0),
Brian Carlstrom7940e442013-07-12 13:46:57 -07001016 reg_pool_(NULL),
1017 live_sreg_(0),
1018 num_core_spills_(0),
1019 num_fp_spills_(0),
1020 frame_size_(0),
1021 core_spill_mask_(0),
1022 fp_spill_mask_(0),
1023 first_lir_insn_(NULL),
Dave Allisonbcec6fb2014-01-17 12:52:22 -08001024 last_lir_insn_(NULL),
1025 slow_paths_(arena, 32, kGrowableArraySlowPaths) {
buzbee0d829482013-10-11 15:24:55 -07001026 // Reserve pointer id 0 for NULL.
1027 size_t null_idx = WrapPointer(NULL);
1028 DCHECK_EQ(null_idx, 0U);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001029}
1030
1031void Mir2Lir::Materialize() {
buzbeea61f4952013-08-23 14:27:06 -07001032 cu_->NewTimingSplit("RegisterAllocation");
Brian Carlstrom7940e442013-07-12 13:46:57 -07001033 CompilerInitializeRegAlloc(); // Needs to happen after SSA naming
1034
1035 /* Allocate Registers using simple local allocation scheme */
1036 SimpleRegAlloc();
1037
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -08001038 /* First try the custom light codegen for special cases. */
Vladimir Marko5816ed42013-11-27 17:04:20 +00001039 DCHECK(cu_->compiler_driver->GetMethodInlinerMap() != nullptr);
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -08001040 bool special_worked = cu_->compiler_driver->GetMethodInlinerMap()->GetMethodInliner(cu_->dex_file)
Vladimir Marko5816ed42013-11-27 17:04:20 +00001041 ->GenSpecial(this, cu_->method_idx);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001042
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -08001043 /* Take normal path for converting MIR to LIR only if the special codegen did not succeed. */
1044 if (special_worked == false) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001045 MethodMIR2LIR();
1046 }
1047
1048 /* Method is not empty */
1049 if (first_lir_insn_) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001050 // mark the targets of switch statement case labels
1051 ProcessSwitchTables();
1052
1053 /* Convert LIR into machine code. */
1054 AssembleLIR();
1055
1056 if (cu_->verbose) {
1057 CodegenDump();
1058 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001059 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001060}
1061
1062CompiledMethod* Mir2Lir::GetCompiledMethod() {
Vladimir Marko2e589aa2014-02-25 17:53:53 +00001063 // Combine vmap tables - core regs, then fp regs - into vmap_table.
1064 Leb128EncodingVector vmap_encoder;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001065 if (frame_size_ > 0) {
Vladimir Marko2e589aa2014-02-25 17:53:53 +00001066 // Prefix the encoded data with its size.
1067 size_t size = core_vmap_table_.size() + 1 /* marker */ + fp_vmap_table_.size();
1068 vmap_encoder.Reserve(size + 1u); // All values are likely to be one byte in ULEB128 (<128).
1069 vmap_encoder.PushBackUnsigned(size);
1070 // Core regs may have been inserted out of order - sort first.
1071 std::sort(core_vmap_table_.begin(), core_vmap_table_.end());
1072 for (size_t i = 0 ; i < core_vmap_table_.size(); ++i) {
1073 // Copy, stripping out the phys register sort key.
1074 vmap_encoder.PushBackUnsigned(
1075 ~(-1 << VREG_NUM_WIDTH) & (core_vmap_table_[i] + VmapTable::kEntryAdjustment));
1076 }
1077 // Push a marker to take place of lr.
1078 vmap_encoder.PushBackUnsigned(VmapTable::kAdjustedFpMarker);
1079 // fp regs already sorted.
1080 for (uint32_t i = 0; i < fp_vmap_table_.size(); i++) {
1081 vmap_encoder.PushBackUnsigned(fp_vmap_table_[i] + VmapTable::kEntryAdjustment);
1082 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001083 } else {
1084 DCHECK_EQ(__builtin_popcount(core_spill_mask_), 0);
1085 DCHECK_EQ(__builtin_popcount(fp_spill_mask_), 0);
Vladimir Marko2e589aa2014-02-25 17:53:53 +00001086 DCHECK_EQ(core_vmap_table_.size(), 0u);
1087 DCHECK_EQ(fp_vmap_table_.size(), 0u);
1088 vmap_encoder.PushBackUnsigned(0u); // Size is 0.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001089 }
Mark Mendellae9fd932014-02-10 16:14:35 -08001090
1091 UniquePtr<std::vector<uint8_t> > cfi_info(ReturnCallFrameInformation());
Brian Carlstrom7940e442013-07-12 13:46:57 -07001092 CompiledMethod* result =
Mathieu Chartier193bad92013-08-29 18:46:00 -07001093 new CompiledMethod(*cu_->compiler_driver, cu_->instruction_set, code_buffer_, frame_size_,
Vladimir Marko06606b92013-12-02 15:31:08 +00001094 core_spill_mask_, fp_spill_mask_, encoded_mapping_table_,
Mark Mendellae9fd932014-02-10 16:14:35 -08001095 vmap_encoder.GetData(), native_gc_map_, cfi_info.get());
Brian Carlstrom7940e442013-07-12 13:46:57 -07001096 return result;
1097}
1098
Razvan A Lupusoruda7a69b2014-01-08 15:09:50 -08001099size_t Mir2Lir::GetMaxPossibleCompilerTemps() const {
1100 // Chose a reasonably small value in order to contain stack growth.
1101 // Backends that are smarter about spill region can return larger values.
1102 const size_t max_compiler_temps = 10;
1103 return max_compiler_temps;
1104}
1105
1106size_t Mir2Lir::GetNumBytesForCompilerTempSpillRegion() {
1107 // By default assume that the Mir2Lir will need one slot for each temporary.
1108 // If the backend can better determine temps that have non-overlapping ranges and
1109 // temps that do not need spilled, it can actually provide a small region.
1110 return (mir_graph_->GetNumUsedCompilerTemps() * sizeof(uint32_t));
1111}
1112
Brian Carlstrom7940e442013-07-12 13:46:57 -07001113int Mir2Lir::ComputeFrameSize() {
1114 /* Figure out the frame size */
1115 static const uint32_t kAlignMask = kStackAlignment - 1;
Razvan A Lupusoruda7a69b2014-01-08 15:09:50 -08001116 uint32_t size = ((num_core_spills_ + num_fp_spills_ +
1117 1 /* filler word */ + cu_->num_regs + cu_->num_outs)
1118 * sizeof(uint32_t)) +
1119 GetNumBytesForCompilerTempSpillRegion();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001120 /* Align and set */
1121 return (size + kAlignMask) & ~(kAlignMask);
1122}
1123
1124/*
1125 * Append an LIR instruction to the LIR list maintained by a compilation
1126 * unit
1127 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001128void Mir2Lir::AppendLIR(LIR* lir) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001129 if (first_lir_insn_ == NULL) {
1130 DCHECK(last_lir_insn_ == NULL);
1131 last_lir_insn_ = first_lir_insn_ = lir;
1132 lir->prev = lir->next = NULL;
1133 } else {
1134 last_lir_insn_->next = lir;
1135 lir->prev = last_lir_insn_;
1136 lir->next = NULL;
1137 last_lir_insn_ = lir;
1138 }
1139}
1140
1141/*
1142 * Insert an LIR instruction before the current instruction, which cannot be the
1143 * first instruction.
1144 *
1145 * prev_lir <-> new_lir <-> current_lir
1146 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001147void Mir2Lir::InsertLIRBefore(LIR* current_lir, LIR* new_lir) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001148 DCHECK(current_lir->prev != NULL);
1149 LIR *prev_lir = current_lir->prev;
1150
1151 prev_lir->next = new_lir;
1152 new_lir->prev = prev_lir;
1153 new_lir->next = current_lir;
1154 current_lir->prev = new_lir;
1155}
1156
1157/*
1158 * Insert an LIR instruction after the current instruction, which cannot be the
1159 * first instruction.
1160 *
1161 * current_lir -> new_lir -> old_next
1162 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001163void Mir2Lir::InsertLIRAfter(LIR* current_lir, LIR* new_lir) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001164 new_lir->prev = current_lir;
1165 new_lir->next = current_lir->next;
1166 current_lir->next = new_lir;
1167 new_lir->next->prev = new_lir;
1168}
1169
Mark Mendell4708dcd2014-01-22 09:05:18 -08001170bool Mir2Lir::IsPowerOfTwo(uint64_t x) {
1171 return (x & (x - 1)) == 0;
1172}
1173
1174// Returns the index of the lowest set bit in 'x'.
1175int32_t Mir2Lir::LowestSetBit(uint64_t x) {
1176 int bit_posn = 0;
1177 while ((x & 0xf) == 0) {
1178 bit_posn += 4;
1179 x >>= 4;
1180 }
1181 while ((x & 1) == 0) {
1182 bit_posn++;
1183 x >>= 1;
1184 }
1185 return bit_posn;
1186}
1187
1188bool Mir2Lir::BadOverlap(RegLocation rl_src, RegLocation rl_dest) {
1189 DCHECK(rl_src.wide);
1190 DCHECK(rl_dest.wide);
1191 return (abs(mir_graph_->SRegToVReg(rl_src.s_reg_low) - mir_graph_->SRegToVReg(rl_dest.s_reg_low)) == 1);
1192}
1193
Mark Mendell766e9292014-01-27 07:55:47 -08001194LIR *Mir2Lir::OpCmpMemImmBranch(ConditionCode cond, int temp_reg, int base_reg,
1195 int offset, int check_value, LIR* target) {
1196 // Handle this for architectures that can't compare to memory.
1197 LoadWordDisp(base_reg, offset, temp_reg);
1198 LIR* branch = OpCmpImmBranch(cond, temp_reg, check_value, target);
1199 return branch;
1200}
1201
Dave Allisonbcec6fb2014-01-17 12:52:22 -08001202void Mir2Lir::AddSlowPath(LIRSlowPath* slowpath) {
1203 slow_paths_.Insert(slowpath);
1204}
Mark Mendell55d0eac2014-02-06 11:02:52 -08001205
Jeff Hao49161ce2014-03-12 11:05:25 -07001206void Mir2Lir::LoadCodeAddress(const MethodReference& target_method, InvokeType type,
1207 SpecialTargetRegister symbolic_reg) {
1208 int target_method_idx = target_method.dex_method_index;
1209 LIR* data_target = ScanLiteralPool(code_literal_list_, target_method_idx, 0);
Mark Mendell55d0eac2014-02-06 11:02:52 -08001210 if (data_target == NULL) {
Jeff Hao49161ce2014-03-12 11:05:25 -07001211 data_target = AddWordData(&code_literal_list_, target_method_idx);
1212 data_target->operands[1] = WrapPointer(const_cast<DexFile*>(target_method.dex_file));
1213 data_target->operands[2] = type;
Mark Mendell55d0eac2014-02-06 11:02:52 -08001214 }
1215 LIR* load_pc_rel = OpPcRelLoad(TargetReg(symbolic_reg), data_target);
1216 AppendLIR(load_pc_rel);
1217 DCHECK_NE(cu_->instruction_set, kMips) << reinterpret_cast<void*>(data_target);
1218}
1219
Jeff Hao49161ce2014-03-12 11:05:25 -07001220void Mir2Lir::LoadMethodAddress(const MethodReference& target_method, InvokeType type,
1221 SpecialTargetRegister symbolic_reg) {
1222 int target_method_idx = target_method.dex_method_index;
1223 LIR* data_target = ScanLiteralPool(method_literal_list_, target_method_idx, 0);
Mark Mendell55d0eac2014-02-06 11:02:52 -08001224 if (data_target == NULL) {
Jeff Hao49161ce2014-03-12 11:05:25 -07001225 data_target = AddWordData(&method_literal_list_, target_method_idx);
1226 data_target->operands[1] = WrapPointer(const_cast<DexFile*>(target_method.dex_file));
1227 data_target->operands[2] = type;
Mark Mendell55d0eac2014-02-06 11:02:52 -08001228 }
1229 LIR* load_pc_rel = OpPcRelLoad(TargetReg(symbolic_reg), data_target);
1230 AppendLIR(load_pc_rel);
1231 DCHECK_NE(cu_->instruction_set, kMips) << reinterpret_cast<void*>(data_target);
1232}
1233
1234void Mir2Lir::LoadClassType(uint32_t type_idx, SpecialTargetRegister symbolic_reg) {
1235 // Use the literal pool and a PC-relative load from a data word.
1236 LIR* data_target = ScanLiteralPool(class_literal_list_, type_idx, 0);
1237 if (data_target == nullptr) {
1238 data_target = AddWordData(&class_literal_list_, type_idx);
1239 }
1240 LIR* load_pc_rel = OpPcRelLoad(TargetReg(symbolic_reg), data_target);
1241 AppendLIR(load_pc_rel);
1242}
1243
Mark Mendellae9fd932014-02-10 16:14:35 -08001244std::vector<uint8_t>* Mir2Lir::ReturnCallFrameInformation() {
1245 // Default case is to do nothing.
1246 return nullptr;
1247}
1248
Brian Carlstrom7934ac22013-07-26 10:54:15 -07001249} // namespace art