blob: 3136e4692d4edb4d074a018976d722f9e1c7ae0f [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
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000017#include "compiler.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070018#include "compiler_internals.h"
19#include "driver/compiler_driver.h"
Dave Allison39c3bfb2014-01-28 18:33:52 -080020#include "driver/compiler_options.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070021#include "dataflow_iterator-inl.h"
22#include "leb128.h"
23#include "mirror/object.h"
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -080024#include "pass_driver.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070025#include "runtime.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070026#include "base/logging.h"
buzbeea61f4952013-08-23 14:27:06 -070027#include "base/timing_logger.h"
Dave Allison39c3bfb2014-01-28 18:33:52 -080028#include "driver/compiler_options.h"
Vladimir Marko5c96e6b2013-11-14 15:34:17 +000029#include "dex/quick/dex_file_to_method_inliner_map.h"
30
Brian Carlstrom7940e442013-07-12 13:46:57 -070031namespace art {
Brian Carlstrom7940e442013-07-12 13:46:57 -070032
Ian Rogers72d32622014-05-06 16:20:11 -070033extern "C" void ArtInitQuickCompilerContext(art::CompilerDriver* driver) {
34 CHECK(driver->GetCompilerContext() == nullptr);
Brian Carlstrom7940e442013-07-12 13:46:57 -070035}
36
Ian Rogers72d32622014-05-06 16:20:11 -070037extern "C" void ArtUnInitQuickCompilerContext(art::CompilerDriver* driver) {
38 CHECK(driver->GetCompilerContext() == nullptr);
Brian Carlstrom7940e442013-07-12 13:46:57 -070039}
40
41/* Default optimizer/debug setting for the compiler. */
Brian Carlstrom7934ac22013-07-26 10:54:15 -070042static uint32_t kCompilerOptimizerDisableFlags = 0 | // Disable specific optimizations
buzbee091cc402014-03-31 10:14:40 -070043 (1 << kLoadStoreElimination) | // TODO: this pass has been broken for awhile - fix or delete.
Brian Carlstrom7934ac22013-07-26 10:54:15 -070044 // (1 << kLoadHoisting) |
45 // (1 << kSuppressLoads) |
46 // (1 << kNullCheckElimination) |
Vladimir Markobfea9c22014-01-17 17:49:33 +000047 // (1 << kClassInitCheckElimination) |
Brian Carlstrom7934ac22013-07-26 10:54:15 -070048 // (1 << kPromoteRegs) |
buzbee30adc732014-05-09 15:10:18 -070049 // (1 << kTrackLiveTemps) |
Brian Carlstrom7934ac22013-07-26 10:54:15 -070050 // (1 << kSafeOptimizations) |
51 // (1 << kBBOpt) |
52 // (1 << kMatch) |
53 // (1 << kPromoteCompilerTemps) |
buzbee17189ac2013-11-08 11:07:02 -080054 // (1 << kSuppressExceptionEdges) |
Vladimir Marko9820b7c2014-01-02 16:40:37 +000055 // (1 << kSuppressMethodInlining) |
Brian Carlstrom7940e442013-07-12 13:46:57 -070056 0;
57
58static uint32_t kCompilerDebugFlags = 0 | // Enable debug/testing modes
Brian Carlstrom7934ac22013-07-26 10:54:15 -070059 // (1 << kDebugDisplayMissingTargets) |
60 // (1 << kDebugVerbose) |
61 // (1 << kDebugDumpCFG) |
62 // (1 << kDebugSlowFieldPath) |
63 // (1 << kDebugSlowInvokePath) |
64 // (1 << kDebugSlowStringPath) |
65 // (1 << kDebugSlowestFieldPath) |
66 // (1 << kDebugSlowestStringPath) |
67 // (1 << kDebugExerciseResolveMethod) |
68 // (1 << kDebugVerifyDataflow) |
69 // (1 << kDebugShowMemoryUsage) |
70 // (1 << kDebugShowNops) |
71 // (1 << kDebugCountOpcodes) |
72 // (1 << kDebugDumpCheckStats) |
73 // (1 << kDebugDumpBitcodeFile) |
74 // (1 << kDebugVerifyBitcode) |
75 // (1 << kDebugShowSummaryMemoryUsage) |
buzbeeee17e0a2013-07-31 10:47:37 -070076 // (1 << kDebugShowFilterStats) |
buzbeea61f4952013-08-23 14:27:06 -070077 // (1 << kDebugTimings) |
Brian Carlstrom7940e442013-07-12 13:46:57 -070078 0;
79
Vladimir Marko25724ef2013-11-12 15:09:20 +000080CompilationUnit::CompilationUnit(ArenaPool* pool)
81 : compiler_driver(NULL),
82 class_linker(NULL),
83 dex_file(NULL),
84 class_loader(NULL),
85 class_def_idx(0),
86 method_idx(0),
87 code_item(NULL),
88 access_flags(0),
89 invoke_type(kDirect),
90 shorty(NULL),
91 disable_opt(0),
92 enable_debug(0),
93 verbose(false),
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +000094 compiler(NULL),
Vladimir Marko25724ef2013-11-12 15:09:20 +000095 instruction_set(kNone),
96 num_dalvik_registers(0),
97 insns(NULL),
98 num_ins(0),
99 num_outs(0),
100 num_regs(0),
Vladimir Marko25724ef2013-11-12 15:09:20 +0000101 compiler_flip_match(false),
102 arena(pool),
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000103 arena_stack(pool),
Vladimir Marko25724ef2013-11-12 15:09:20 +0000104 mir_graph(NULL),
105 cg(NULL),
106 timings("QuickCompiler", true, false) {
107}
108
109CompilationUnit::~CompilationUnit() {
110}
111
buzbeea61f4952013-08-23 14:27:06 -0700112void CompilationUnit::StartTimingSplit(const char* label) {
Nicolas Geoffrayea3fa0b2014-02-10 11:59:41 +0000113 if (compiler_driver->GetDumpPasses()) {
buzbeea61f4952013-08-23 14:27:06 -0700114 timings.StartSplit(label);
115 }
116}
117
118void CompilationUnit::NewTimingSplit(const char* label) {
Nicolas Geoffrayea3fa0b2014-02-10 11:59:41 +0000119 if (compiler_driver->GetDumpPasses()) {
buzbeea61f4952013-08-23 14:27:06 -0700120 timings.NewSplit(label);
121 }
122}
123
124void CompilationUnit::EndTiming() {
Nicolas Geoffrayea3fa0b2014-02-10 11:59:41 +0000125 if (compiler_driver->GetDumpPasses()) {
buzbeea61f4952013-08-23 14:27:06 -0700126 timings.EndSplit();
Nicolas Geoffrayea3fa0b2014-02-10 11:59:41 +0000127 if (enable_debug & (1 << kDebugTimings)) {
128 LOG(INFO) << "TIMINGS " << PrettyMethod(method_idx, *dex_file);
129 LOG(INFO) << Dumpable<TimingLogger>(timings);
130 }
buzbeea61f4952013-08-23 14:27:06 -0700131 }
132}
133
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100134// TODO: Remove this when we are able to compile everything.
135int arm64_support_list[] = {
136 Instruction::NOP,
137 // Instruction::MOVE,
138 // Instruction::MOVE_FROM16,
139 // Instruction::MOVE_16,
140 // Instruction::MOVE_WIDE,
141 // Instruction::MOVE_WIDE_FROM16,
142 // Instruction::MOVE_WIDE_16,
143 // Instruction::MOVE_OBJECT,
144 // Instruction::MOVE_OBJECT_FROM16,
145 // Instruction::MOVE_OBJECT_16,
146 // Instruction::MOVE_RESULT,
147 // Instruction::MOVE_RESULT_WIDE,
148 // Instruction::MOVE_RESULT_OBJECT,
149 // Instruction::MOVE_EXCEPTION,
150 // Instruction::RETURN_VOID,
151 // Instruction::RETURN,
152 // Instruction::RETURN_WIDE,
153 // Instruction::RETURN_OBJECT,
154 // Instruction::CONST_4,
155 // Instruction::CONST_16,
156 // Instruction::CONST,
157 // Instruction::CONST_HIGH16,
158 // Instruction::CONST_WIDE_16,
159 // Instruction::CONST_WIDE_32,
160 // Instruction::CONST_WIDE,
161 // Instruction::CONST_WIDE_HIGH16,
162 // Instruction::CONST_STRING,
163 // Instruction::CONST_STRING_JUMBO,
164 // Instruction::CONST_CLASS,
165 // Instruction::MONITOR_ENTER,
166 // Instruction::MONITOR_EXIT,
167 // Instruction::CHECK_CAST,
168 // Instruction::INSTANCE_OF,
169 // Instruction::ARRAY_LENGTH,
170 // Instruction::NEW_INSTANCE,
171 // Instruction::NEW_ARRAY,
172 // Instruction::FILLED_NEW_ARRAY,
173 // Instruction::FILLED_NEW_ARRAY_RANGE,
174 // Instruction::FILL_ARRAY_DATA,
175 // Instruction::THROW,
176 // Instruction::GOTO,
177 // Instruction::GOTO_16,
178 // Instruction::GOTO_32,
179 // Instruction::PACKED_SWITCH,
180 // Instruction::SPARSE_SWITCH,
181 // Instruction::CMPL_FLOAT,
182 // Instruction::CMPG_FLOAT,
183 // Instruction::CMPL_DOUBLE,
184 // Instruction::CMPG_DOUBLE,
185 // Instruction::CMP_LONG,
186 // Instruction::IF_EQ,
187 // Instruction::IF_NE,
188 // Instruction::IF_LT,
189 // Instruction::IF_GE,
190 // Instruction::IF_GT,
191 // Instruction::IF_LE,
192 // Instruction::IF_EQZ,
193 // Instruction::IF_NEZ,
194 // Instruction::IF_LTZ,
195 // Instruction::IF_GEZ,
196 // Instruction::IF_GTZ,
197 // Instruction::IF_LEZ,
198 // Instruction::UNUSED_3E,
199 // Instruction::UNUSED_3F,
200 // Instruction::UNUSED_40,
201 // Instruction::UNUSED_41,
202 // Instruction::UNUSED_42,
203 // Instruction::UNUSED_43,
204 // Instruction::AGET,
205 // Instruction::AGET_WIDE,
206 // Instruction::AGET_OBJECT,
207 // Instruction::AGET_BOOLEAN,
208 // Instruction::AGET_BYTE,
209 // Instruction::AGET_CHAR,
210 // Instruction::AGET_SHORT,
211 // Instruction::APUT,
212 // Instruction::APUT_WIDE,
213 // Instruction::APUT_OBJECT,
214 // Instruction::APUT_BOOLEAN,
215 // Instruction::APUT_BYTE,
216 // Instruction::APUT_CHAR,
217 // Instruction::APUT_SHORT,
218 // Instruction::IGET,
219 // Instruction::IGET_WIDE,
220 // Instruction::IGET_OBJECT,
221 // Instruction::IGET_BOOLEAN,
222 // Instruction::IGET_BYTE,
223 // Instruction::IGET_CHAR,
224 // Instruction::IGET_SHORT,
225 // Instruction::IPUT,
226 // Instruction::IPUT_WIDE,
227 // Instruction::IPUT_OBJECT,
228 // Instruction::IPUT_BOOLEAN,
229 // Instruction::IPUT_BYTE,
230 // Instruction::IPUT_CHAR,
231 // Instruction::IPUT_SHORT,
232 // Instruction::SGET,
233 // Instruction::SGET_WIDE,
234 // Instruction::SGET_OBJECT,
235 // Instruction::SGET_BOOLEAN,
236 // Instruction::SGET_BYTE,
237 // Instruction::SGET_CHAR,
238 // Instruction::SGET_SHORT,
239 // Instruction::SPUT,
240 // Instruction::SPUT_WIDE,
241 // Instruction::SPUT_OBJECT,
242 // Instruction::SPUT_BOOLEAN,
243 // Instruction::SPUT_BYTE,
244 // Instruction::SPUT_CHAR,
245 // Instruction::SPUT_SHORT,
246 Instruction::INVOKE_VIRTUAL,
247 Instruction::INVOKE_SUPER,
248 Instruction::INVOKE_DIRECT,
249 Instruction::INVOKE_STATIC,
250 Instruction::INVOKE_INTERFACE,
251 // Instruction::RETURN_VOID_BARRIER,
252 // Instruction::INVOKE_VIRTUAL_RANGE,
253 // Instruction::INVOKE_SUPER_RANGE,
254 // Instruction::INVOKE_DIRECT_RANGE,
255 // Instruction::INVOKE_STATIC_RANGE,
256 // Instruction::INVOKE_INTERFACE_RANGE,
257 // Instruction::UNUSED_79,
258 // Instruction::UNUSED_7A,
259 // Instruction::NEG_INT,
260 // Instruction::NOT_INT,
261 // Instruction::NEG_LONG,
262 // Instruction::NOT_LONG,
263 // Instruction::NEG_FLOAT,
264 // Instruction::NEG_DOUBLE,
265 // Instruction::INT_TO_LONG,
266 // Instruction::INT_TO_FLOAT,
267 // Instruction::INT_TO_DOUBLE,
268 // Instruction::LONG_TO_INT,
269 // Instruction::LONG_TO_FLOAT,
270 // Instruction::LONG_TO_DOUBLE,
271 // Instruction::FLOAT_TO_INT,
272 // Instruction::FLOAT_TO_LONG,
273 // Instruction::FLOAT_TO_DOUBLE,
274 // Instruction::DOUBLE_TO_INT,
275 // Instruction::DOUBLE_TO_LONG,
276 // Instruction::DOUBLE_TO_FLOAT,
277 // Instruction::INT_TO_BYTE,
278 // Instruction::INT_TO_CHAR,
279 // Instruction::INT_TO_SHORT,
280 // Instruction::ADD_INT,
281 // Instruction::SUB_INT,
282 // Instruction::MUL_INT,
283 // Instruction::DIV_INT,
284 // Instruction::REM_INT,
285 // Instruction::AND_INT,
286 // Instruction::OR_INT,
287 // Instruction::XOR_INT,
288 // Instruction::SHL_INT,
289 // Instruction::SHR_INT,
290 // Instruction::USHR_INT,
291 // Instruction::ADD_LONG,
292 // Instruction::SUB_LONG,
293 // Instruction::MUL_LONG,
294 // Instruction::DIV_LONG,
295 // Instruction::REM_LONG,
296 // Instruction::AND_LONG,
297 // Instruction::OR_LONG,
298 // Instruction::XOR_LONG,
299 // Instruction::SHL_LONG,
300 // Instruction::SHR_LONG,
301 // Instruction::USHR_LONG,
302 // Instruction::ADD_FLOAT,
303 // Instruction::SUB_FLOAT,
304 // Instruction::MUL_FLOAT,
305 // Instruction::DIV_FLOAT,
306 // Instruction::REM_FLOAT,
307 // Instruction::ADD_DOUBLE,
308 // Instruction::SUB_DOUBLE,
309 // Instruction::MUL_DOUBLE,
310 // Instruction::DIV_DOUBLE,
311 // Instruction::REM_DOUBLE,
312 // Instruction::ADD_INT_2ADDR,
313 // Instruction::SUB_INT_2ADDR,
314 // Instruction::MUL_INT_2ADDR,
315 // Instruction::DIV_INT_2ADDR,
316 // Instruction::REM_INT_2ADDR,
317 // Instruction::AND_INT_2ADDR,
318 // Instruction::OR_INT_2ADDR,
319 // Instruction::XOR_INT_2ADDR,
320 // Instruction::SHL_INT_2ADDR,
321 // Instruction::SHR_INT_2ADDR,
322 // Instruction::USHR_INT_2ADDR,
323 // Instruction::ADD_LONG_2ADDR,
324 // Instruction::SUB_LONG_2ADDR,
325 // Instruction::MUL_LONG_2ADDR,
326 // Instruction::DIV_LONG_2ADDR,
327 // Instruction::REM_LONG_2ADDR,
328 // Instruction::AND_LONG_2ADDR,
329 // Instruction::OR_LONG_2ADDR,
330 // Instruction::XOR_LONG_2ADDR,
331 // Instruction::SHL_LONG_2ADDR,
332 // Instruction::SHR_LONG_2ADDR,
333 // Instruction::USHR_LONG_2ADDR,
334 // Instruction::ADD_FLOAT_2ADDR,
335 // Instruction::SUB_FLOAT_2ADDR,
336 // Instruction::MUL_FLOAT_2ADDR,
337 // Instruction::DIV_FLOAT_2ADDR,
338 // Instruction::REM_FLOAT_2ADDR,
339 // Instruction::ADD_DOUBLE_2ADDR,
340 // Instruction::SUB_DOUBLE_2ADDR,
341 // Instruction::MUL_DOUBLE_2ADDR,
342 // Instruction::DIV_DOUBLE_2ADDR,
343 // Instruction::REM_DOUBLE_2ADDR,
344 // Instruction::ADD_INT_LIT16,
345 // Instruction::RSUB_INT,
346 // Instruction::MUL_INT_LIT16,
347 // Instruction::DIV_INT_LIT16,
348 // Instruction::REM_INT_LIT16,
349 // Instruction::AND_INT_LIT16,
350 // Instruction::OR_INT_LIT16,
351 // Instruction::XOR_INT_LIT16,
352 // Instruction::ADD_INT_LIT8,
353 // Instruction::RSUB_INT_LIT8,
354 // Instruction::MUL_INT_LIT8,
355 // Instruction::DIV_INT_LIT8,
356 // Instruction::REM_INT_LIT8,
357 // Instruction::AND_INT_LIT8,
358 // Instruction::OR_INT_LIT8,
359 // Instruction::XOR_INT_LIT8,
360 // Instruction::SHL_INT_LIT8,
361 // Instruction::SHR_INT_LIT8,
362 // Instruction::USHR_INT_LIT8,
363 // Instruction::IGET_QUICK,
364 // Instruction::IGET_WIDE_QUICK,
365 // Instruction::IGET_OBJECT_QUICK,
366 // Instruction::IPUT_QUICK,
367 // Instruction::IPUT_WIDE_QUICK,
368 // Instruction::IPUT_OBJECT_QUICK,
369 // Instruction::INVOKE_VIRTUAL_QUICK,
370 // Instruction::INVOKE_VIRTUAL_RANGE_QUICK,
371 // Instruction::UNUSED_EB,
372 // Instruction::UNUSED_EC,
373 // Instruction::UNUSED_ED,
374 // Instruction::UNUSED_EE,
375 // Instruction::UNUSED_EF,
376 // Instruction::UNUSED_F0,
377 // Instruction::UNUSED_F1,
378 // Instruction::UNUSED_F2,
379 // Instruction::UNUSED_F3,
380 // Instruction::UNUSED_F4,
381 // Instruction::UNUSED_F5,
382 // Instruction::UNUSED_F6,
383 // Instruction::UNUSED_F7,
384 // Instruction::UNUSED_F8,
385 // Instruction::UNUSED_F9,
386 // Instruction::UNUSED_FA,
387 // Instruction::UNUSED_FB,
388 // Instruction::UNUSED_FC,
389 // Instruction::UNUSED_FD,
390 // Instruction::UNUSED_FE,
391 // Instruction::UNUSED_FF,
392
393 // ----- ExtendedMIROpcode -----
394 // kMirOpPhi,
395 // kMirOpCopy,
396 // kMirOpFusedCmplFloat,
397 // kMirOpFusedCmpgFloat,
398 // kMirOpFusedCmplDouble,
399 // kMirOpFusedCmpgDouble,
400 // kMirOpFusedCmpLong,
401 // kMirOpNop,
402 // kMirOpNullCheck,
403 // kMirOpRangeCheck,
404 // kMirOpDivZeroCheck,
405 // kMirOpCheck,
406 // kMirOpCheckPart2,
407 // kMirOpSelect,
408 // kMirOpLast,
409};
410
411// TODO: Remove this when we are able to compile everything.
Vladimir Kostyukov56784552014-05-13 12:12:00 +0700412int x86_64_support_list[] = {
413 Instruction::NOP,
414 // Instruction::MOVE,
415 // Instruction::MOVE_FROM16,
416 // Instruction::MOVE_16,
417 // Instruction::MOVE_WIDE,
418 // Instruction::MOVE_WIDE_FROM16,
419 // Instruction::MOVE_WIDE_16,
420 // Instruction::MOVE_OBJECT,
421 // Instruction::MOVE_OBJECT_FROM16,
422 // Instruction::MOVE_OBJECT_16,
423 // Instruction::MOVE_RESULT,
424 // Instruction::MOVE_RESULT_WIDE,
425 // Instruction::MOVE_RESULT_OBJECT,
426 // Instruction::MOVE_EXCEPTION,
427 Instruction::RETURN_VOID,
428 Instruction::RETURN,
429 // Instruction::RETURN_WIDE,
430 Instruction::RETURN_OBJECT,
431 // Instruction::CONST_4,
432 // Instruction::CONST_16,
433 // Instruction::CONST,
434 // Instruction::CONST_HIGH16,
435 // Instruction::CONST_WIDE_16,
436 // Instruction::CONST_WIDE_32,
437 // Instruction::CONST_WIDE,
438 // Instruction::CONST_WIDE_HIGH16,
439 // Instruction::CONST_STRING,
440 // Instruction::CONST_STRING_JUMBO,
441 // Instruction::CONST_CLASS,
442 // Instruction::MONITOR_ENTER,
443 // Instruction::MONITOR_EXIT,
444 // Instruction::CHECK_CAST,
445 // Instruction::INSTANCE_OF,
446 // Instruction::ARRAY_LENGTH,
447 // Instruction::NEW_INSTANCE,
448 // Instruction::NEW_ARRAY,
449 // Instruction::FILLED_NEW_ARRAY,
450 // Instruction::FILLED_NEW_ARRAY_RANGE,
451 // Instruction::FILL_ARRAY_DATA,
452 // Instruction::THROW,
453 // Instruction::GOTO,
454 // Instruction::GOTO_16,
455 // Instruction::GOTO_32,
456 // Instruction::PACKED_SWITCH,
457 // Instruction::SPARSE_SWITCH,
458 // Instruction::CMPL_FLOAT,
459 // Instruction::CMPG_FLOAT,
460 // Instruction::CMPL_DOUBLE,
461 // Instruction::CMPG_DOUBLE,
462 // Instruction::CMP_LONG,
463 // Instruction::IF_EQ,
464 // Instruction::IF_NE,
465 // Instruction::IF_LT,
466 // Instruction::IF_GE,
467 // Instruction::IF_GT,
468 // Instruction::IF_LE,
469 // Instruction::IF_EQZ,
470 // Instruction::IF_NEZ,
471 // Instruction::IF_LTZ,
472 // Instruction::IF_GEZ,
473 // Instruction::IF_GTZ,
474 // Instruction::IF_LEZ,
475 // Instruction::UNUSED_3E,
476 // Instruction::UNUSED_3F,
477 // Instruction::UNUSED_40,
478 // Instruction::UNUSED_41,
479 // Instruction::UNUSED_42,
480 // Instruction::UNUSED_43,
481 // Instruction::AGET,
482 // Instruction::AGET_WIDE,
483 // Instruction::AGET_OBJECT,
484 // Instruction::AGET_BOOLEAN,
485 // Instruction::AGET_BYTE,
486 // Instruction::AGET_CHAR,
487 // Instruction::AGET_SHORT,
488 // Instruction::APUT,
489 // Instruction::APUT_WIDE,
490 // Instruction::APUT_OBJECT,
491 // Instruction::APUT_BOOLEAN,
492 // Instruction::APUT_BYTE,
493 // Instruction::APUT_CHAR,
494 // Instruction::APUT_SHORT,
495 // Instruction::IGET,
496 // Instruction::IGET_WIDE,
497 // Instruction::IGET_OBJECT,
498 // Instruction::IGET_BOOLEAN,
499 // Instruction::IGET_BYTE,
500 // Instruction::IGET_CHAR,
501 // Instruction::IGET_SHORT,
502 // Instruction::IPUT,
503 // Instruction::IPUT_WIDE,
504 // Instruction::IPUT_OBJECT,
505 // Instruction::IPUT_BOOLEAN,
506 // Instruction::IPUT_BYTE,
507 // Instruction::IPUT_CHAR,
508 // Instruction::IPUT_SHORT,
509 Instruction::SGET,
510 // Instruction::SGET_WIDE,
511 Instruction::SGET_OBJECT,
512 Instruction::SGET_BOOLEAN,
513 Instruction::SGET_BYTE,
514 Instruction::SGET_CHAR,
515 Instruction::SGET_SHORT,
516 Instruction::SPUT,
517 // Instruction::SPUT_WIDE,
518 Instruction::SPUT_OBJECT,
519 Instruction::SPUT_BOOLEAN,
520 Instruction::SPUT_BYTE,
521 Instruction::SPUT_CHAR,
522 Instruction::SPUT_SHORT,
523 Instruction::INVOKE_VIRTUAL,
524 Instruction::INVOKE_SUPER,
525 Instruction::INVOKE_DIRECT,
526 Instruction::INVOKE_STATIC,
527 Instruction::INVOKE_INTERFACE,
528 // Instruction::RETURN_VOID_BARRIER,
529 // Instruction::INVOKE_VIRTUAL_RANGE,
530 // Instruction::INVOKE_SUPER_RANGE,
531 // Instruction::INVOKE_DIRECT_RANGE,
532 // Instruction::INVOKE_STATIC_RANGE,
533 // Instruction::INVOKE_INTERFACE_RANGE,
534 // Instruction::UNUSED_79,
535 // Instruction::UNUSED_7A,
536 // Instruction::NEG_INT,
537 // Instruction::NOT_INT,
538 // Instruction::NEG_LONG,
539 // Instruction::NOT_LONG,
540 // Instruction::NEG_FLOAT,
541 // Instruction::NEG_DOUBLE,
542 // Instruction::INT_TO_LONG,
543 // Instruction::INT_TO_FLOAT,
544 // Instruction::INT_TO_DOUBLE,
545 // Instruction::LONG_TO_INT,
546 // Instruction::LONG_TO_FLOAT,
547 // Instruction::LONG_TO_DOUBLE,
548 // Instruction::FLOAT_TO_INT,
549 // Instruction::FLOAT_TO_LONG,
550 // Instruction::FLOAT_TO_DOUBLE,
551 // Instruction::DOUBLE_TO_INT,
552 // Instruction::DOUBLE_TO_LONG,
553 // Instruction::DOUBLE_TO_FLOAT,
554 // Instruction::INT_TO_BYTE,
555 // Instruction::INT_TO_CHAR,
556 // Instruction::INT_TO_SHORT,
557 // Instruction::ADD_INT,
558 // Instruction::SUB_INT,
559 // Instruction::MUL_INT,
560 // Instruction::DIV_INT,
561 // Instruction::REM_INT,
562 // Instruction::AND_INT,
563 // Instruction::OR_INT,
564 // Instruction::XOR_INT,
565 // Instruction::SHL_INT,
566 // Instruction::SHR_INT,
567 // Instruction::USHR_INT,
568 // Instruction::ADD_LONG,
569 // Instruction::SUB_LONG,
570 // Instruction::MUL_LONG,
571 // Instruction::DIV_LONG,
572 // Instruction::REM_LONG,
573 // Instruction::AND_LONG,
574 // Instruction::OR_LONG,
575 // Instruction::XOR_LONG,
576 // Instruction::SHL_LONG,
577 // Instruction::SHR_LONG,
578 // Instruction::USHR_LONG,
579 // Instruction::ADD_FLOAT,
580 // Instruction::SUB_FLOAT,
581 // Instruction::MUL_FLOAT,
582 // Instruction::DIV_FLOAT,
583 // Instruction::REM_FLOAT,
584 // Instruction::ADD_DOUBLE,
585 // Instruction::SUB_DOUBLE,
586 // Instruction::MUL_DOUBLE,
587 // Instruction::DIV_DOUBLE,
588 // Instruction::REM_DOUBLE,
589 // Instruction::ADD_INT_2ADDR,
590 // Instruction::SUB_INT_2ADDR,
591 // Instruction::MUL_INT_2ADDR,
592 // Instruction::DIV_INT_2ADDR,
593 // Instruction::REM_INT_2ADDR,
594 // Instruction::AND_INT_2ADDR,
595 // Instruction::OR_INT_2ADDR,
596 // Instruction::XOR_INT_2ADDR,
597 // Instruction::SHL_INT_2ADDR,
598 // Instruction::SHR_INT_2ADDR,
599 // Instruction::USHR_INT_2ADDR,
600 // Instruction::ADD_LONG_2ADDR,
601 // Instruction::SUB_LONG_2ADDR,
602 // Instruction::MUL_LONG_2ADDR,
603 // Instruction::DIV_LONG_2ADDR,
604 // Instruction::REM_LONG_2ADDR,
605 // Instruction::AND_LONG_2ADDR,
606 // Instruction::OR_LONG_2ADDR,
607 // Instruction::XOR_LONG_2ADDR,
608 // Instruction::SHL_LONG_2ADDR,
609 // Instruction::SHR_LONG_2ADDR,
610 // Instruction::USHR_LONG_2ADDR,
611 // Instruction::ADD_FLOAT_2ADDR,
612 // Instruction::SUB_FLOAT_2ADDR,
613 // Instruction::MUL_FLOAT_2ADDR,
614 // Instruction::DIV_FLOAT_2ADDR,
615 // Instruction::REM_FLOAT_2ADDR,
616 // Instruction::ADD_DOUBLE_2ADDR,
617 // Instruction::SUB_DOUBLE_2ADDR,
618 // Instruction::MUL_DOUBLE_2ADDR,
619 // Instruction::DIV_DOUBLE_2ADDR,
620 // Instruction::REM_DOUBLE_2ADDR,
621 // Instruction::ADD_INT_LIT16,
622 // Instruction::RSUB_INT,
623 // Instruction::MUL_INT_LIT16,
624 // Instruction::DIV_INT_LIT16,
625 // Instruction::REM_INT_LIT16,
626 // Instruction::AND_INT_LIT16,
627 // Instruction::OR_INT_LIT16,
628 // Instruction::XOR_INT_LIT16,
629 // Instruction::ADD_INT_LIT8,
630 // Instruction::RSUB_INT_LIT8,
631 // Instruction::MUL_INT_LIT8,
632 // Instruction::DIV_INT_LIT8,
633 // Instruction::REM_INT_LIT8,
634 // Instruction::AND_INT_LIT8,
635 // Instruction::OR_INT_LIT8,
636 // Instruction::XOR_INT_LIT8,
637 // Instruction::SHL_INT_LIT8,
638 // Instruction::SHR_INT_LIT8,
639 // Instruction::USHR_INT_LIT8,
640 // Instruction::IGET_QUICK,
641 // Instruction::IGET_WIDE_QUICK,
642 // Instruction::IGET_OBJECT_QUICK,
643 // Instruction::IPUT_QUICK,
644 // Instruction::IPUT_WIDE_QUICK,
645 // Instruction::IPUT_OBJECT_QUICK,
646 // Instruction::INVOKE_VIRTUAL_QUICK,
647 // Instruction::INVOKE_VIRTUAL_RANGE_QUICK,
648 // Instruction::UNUSED_EB,
649 // Instruction::UNUSED_EC,
650 // Instruction::UNUSED_ED,
651 // Instruction::UNUSED_EE,
652 // Instruction::UNUSED_EF,
653 // Instruction::UNUSED_F0,
654 // Instruction::UNUSED_F1,
655 // Instruction::UNUSED_F2,
656 // Instruction::UNUSED_F3,
657 // Instruction::UNUSED_F4,
658 // Instruction::UNUSED_F5,
659 // Instruction::UNUSED_F6,
660 // Instruction::UNUSED_F7,
661 // Instruction::UNUSED_F8,
662 // Instruction::UNUSED_F9,
663 // Instruction::UNUSED_FA,
664 // Instruction::UNUSED_FB,
665 // Instruction::UNUSED_FC,
666 // Instruction::UNUSED_FD,
667 // Instruction::UNUSED_FE,
668 // Instruction::UNUSED_FF,
669
670 // ----- ExtendedMIROpcode -----
671 // kMirOpPhi,
672 // kMirOpCopy,
673 // kMirOpFusedCmplFloat,
674 // kMirOpFusedCmpgFloat,
675 // kMirOpFusedCmplDouble,
676 // kMirOpFusedCmpgDouble,
677 // kMirOpFusedCmpLong,
678 // kMirOpNop,
679 // kMirOpNullCheck,
680 // kMirOpRangeCheck,
681 // kMirOpDivZeroCheck,
682 // kMirOpCheck,
683 // kMirOpCheckPart2,
684 // kMirOpSelect,
685 // kMirOpLast,
686};
687
688// Z : boolean
689// B : byte
690// S : short
691// C : char
692// I : int
693// L : long
694// F : float
695// D : double
696// L : reference(object, array)
697// V : void
698// (ARM64) Current calling conversion only support 32bit softfp
699// which has problems with long, float, double
700constexpr char arm64_supported_types[] = "ZBSCILV";
701// (x84_64) We still have troubles with compiling longs/doubles/floats
702constexpr char x86_64_supported_types[] = "ZBSCILV";
703
704// TODO: Remove this when we are able to compile everything.
705static bool CanCompileShorty(const char* shorty, InstructionSet instruction_set) {
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100706 uint32_t shorty_size = strlen(shorty);
707 CHECK_GE(shorty_size, 1u);
708 // Set a limitation on maximum number of parameters.
709 // Note : there is an implied "method*" parameter, and probably "this" as well.
710 // 1 is for the return type. Currently, we only accept 2 parameters at the most.
Vladimir Kostyukov56784552014-05-13 12:12:00 +0700711 // (x86_64): For now we have the same limitation. But we might want to split this
712 // check in future into two separate cases for arm64 and x86_64.
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100713 if (shorty_size > (1 + 2)) {
714 return false;
715 }
Vladimir Kostyukov56784552014-05-13 12:12:00 +0700716
717 const char* supported_types = arm64_supported_types;
718 if (instruction_set == kX86_64) {
719 supported_types = x86_64_supported_types;
720 }
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100721 for (uint32_t i = 0; i < shorty_size; i++) {
722 if (strchr(supported_types, shorty[i]) == nullptr) {
723 return false;
724 }
725 }
726 return true;
727};
728
729// TODO: Remove this when we are able to compile everything.
730// Skip the method that we do not support currently.
731static bool CanCompileMethod(uint32_t method_idx, const DexFile& dex_file,
732 CompilationUnit& cu) {
733 // There is some limitation with current ARM 64 backend.
Vladimir Kostyukov56784552014-05-13 12:12:00 +0700734 if (cu.instruction_set == kArm64 || cu.instruction_set == kX86_64) {
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100735 // Check if we can compile the prototype.
736 const char* shorty = dex_file.GetMethodShorty(dex_file.GetMethodId(method_idx));
Vladimir Kostyukov56784552014-05-13 12:12:00 +0700737 if (!CanCompileShorty(shorty, cu.instruction_set)) {
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100738 VLOG(compiler) << "Unsupported shorty : " << shorty;
739 return false;
740 }
741
Vladimir Kostyukov56784552014-05-13 12:12:00 +0700742 const int *support_list = arm64_support_list;
743 int support_list_size = arraysize(arm64_support_list);
744 if (cu.instruction_set == kX86_64) {
745 support_list = x86_64_support_list;
746 support_list_size = arraysize(x86_64_support_list);
747 }
748
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100749 for (int idx = 0; idx < cu.mir_graph->GetNumBlocks(); idx++) {
750 BasicBlock *bb = cu.mir_graph->GetBasicBlock(idx);
751 if (bb == NULL) continue;
752 if (bb->block_type == kDead) continue;
753 for (MIR* mir = bb->first_mir_insn; mir != nullptr; mir = mir->next) {
754 int opcode = mir->dalvikInsn.opcode;
755 // Check if we support the byte code.
Vladimir Kostyukov56784552014-05-13 12:12:00 +0700756 if (std::find(support_list, support_list + support_list_size,
757 opcode) == support_list + support_list_size) {
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100758 if (opcode < kMirOpFirst) {
759 VLOG(compiler) << "Unsupported dalvik byte code : "
760 << mir->dalvikInsn.opcode;
761 } else {
762 VLOG(compiler) << "Unsupported extended MIR opcode : "
763 << MIRGraph::extended_mir_op_names_[opcode - kMirOpFirst];
764 }
765 return false;
766 }
767 // Check if it invokes a prototype that we cannot support.
768 if (Instruction::INVOKE_VIRTUAL == opcode ||
769 Instruction::INVOKE_SUPER == opcode ||
770 Instruction::INVOKE_DIRECT == opcode ||
771 Instruction::INVOKE_STATIC == opcode ||
772 Instruction::INVOKE_INTERFACE == opcode) {
773 uint32_t invoke_method_idx = mir->dalvikInsn.vB;
774 const char* invoke_method_shorty = dex_file.GetMethodShorty(
775 dex_file.GetMethodId(invoke_method_idx));
Vladimir Kostyukov56784552014-05-13 12:12:00 +0700776 if (!CanCompileShorty(invoke_method_shorty, cu.instruction_set)) {
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100777 VLOG(compiler) << "Unsupported to invoke '"
778 << PrettyMethod(invoke_method_idx, dex_file)
779 << "' with shorty : " << invoke_method_shorty;
780 return false;
781 }
782 }
783 }
784 }
785
786 LOG(INFO) << "Using experimental instruction set A64 for "
787 << PrettyMethod(method_idx, dex_file);
788 }
789 return true;
790}
791
Ian Rogers3d504072014-03-01 09:16:49 -0800792static CompiledMethod* CompileMethod(CompilerDriver& driver,
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000793 Compiler* compiler,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700794 const DexFile::CodeItem* code_item,
795 uint32_t access_flags, InvokeType invoke_type,
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700796 uint16_t class_def_idx, uint32_t method_idx,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000797 jobject class_loader, const DexFile& dex_file,
798 void* llvm_compilation_unit) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700799 VLOG(compiler) << "Compiling " << PrettyMethod(method_idx, dex_file) << "...";
buzbeeb48819d2013-09-14 16:15:25 -0700800 if (code_item->insns_size_in_code_units_ >= 0x10000) {
801 LOG(INFO) << "Method size exceeds compiler limits: " << code_item->insns_size_in_code_units_
802 << " in " << PrettyMethod(method_idx, dex_file);
803 return NULL;
804 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700805
Jeff Hao4a200f52014-04-01 14:58:49 -0700806 if (!driver.GetCompilerOptions().IsCompilationEnabled()) {
Ian Rogersa03de6d2014-03-08 23:37:07 +0000807 return nullptr;
808 }
809
Brian Carlstrom7940e442013-07-12 13:46:57 -0700810 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Ian Rogers3d504072014-03-01 09:16:49 -0800811 CompilationUnit cu(driver.GetArenaPool());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700812
Ian Rogers3d504072014-03-01 09:16:49 -0800813 cu.compiler_driver = &driver;
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700814 cu.class_linker = class_linker;
Ian Rogers3d504072014-03-01 09:16:49 -0800815 cu.instruction_set = driver.GetInstructionSet();
Mathieu Chartier53bee422014-04-04 16:10:05 -0700816 if (cu.instruction_set == kArm) {
817 cu.instruction_set = kThumb2;
818 }
Andreas Gampeaf13ad92014-04-11 12:07:48 -0700819 cu.target64 = Is64BitInstructionSet(cu.instruction_set);
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000820 cu.compiler = compiler;
Stuart Monteithb95a5342014-03-12 13:32:32 +0000821 // TODO: x86_64 & arm64 are not yet implemented.
Mathieu Chartier53bee422014-04-04 16:10:05 -0700822 CHECK((cu.instruction_set == kThumb2) ||
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100823 (cu.instruction_set == kArm64) ||
Mathieu Chartier53bee422014-04-04 16:10:05 -0700824 (cu.instruction_set == kX86) ||
825 (cu.instruction_set == kX86_64) ||
826 (cu.instruction_set == kMips));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700827
Brian Carlstrom7940e442013-07-12 13:46:57 -0700828 /* Adjust this value accordingly once inlining is performed */
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700829 cu.num_dalvik_registers = code_item->registers_size_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700830 // TODO: set this from command line
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700831 cu.compiler_flip_match = false;
832 bool use_match = !cu.compiler_method_match.empty();
833 bool match = use_match && (cu.compiler_flip_match ^
834 (PrettyMethod(method_idx, dex_file).find(cu.compiler_method_match) !=
Brian Carlstrom7940e442013-07-12 13:46:57 -0700835 std::string::npos));
836 if (!use_match || match) {
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700837 cu.disable_opt = kCompilerOptimizerDisableFlags;
838 cu.enable_debug = kCompilerDebugFlags;
839 cu.verbose = VLOG_IS_ON(compiler) ||
840 (cu.enable_debug & (1 << kDebugVerbose));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700841 }
842
Mingyao Yang42d65c52014-04-18 16:49:39 -0700843 if (gVerboseMethods.size() != 0) {
844 cu.verbose = false;
845 for (size_t i = 0; i < gVerboseMethods.size(); ++i) {
846 if (PrettyMethod(method_idx, dex_file).find(gVerboseMethods[i])
847 != std::string::npos) {
848 cu.verbose = true;
849 break;
850 }
851 }
852 }
853
Brian Carlstrom7940e442013-07-12 13:46:57 -0700854 /*
855 * TODO: rework handling of optimization and debug flags. Should we split out
856 * MIR and backend flags? Need command-line setting as well.
857 */
858
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000859 compiler->InitCompilationUnit(cu);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700860
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700861 if (cu.instruction_set == kMips) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700862 // Disable some optimizations for mips for now
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700863 cu.disable_opt |= (
Brian Carlstrom7940e442013-07-12 13:46:57 -0700864 (1 << kLoadStoreElimination) |
865 (1 << kLoadHoisting) |
866 (1 << kSuppressLoads) |
867 (1 << kNullCheckElimination) |
868 (1 << kPromoteRegs) |
869 (1 << kTrackLiveTemps) |
870 (1 << kSafeOptimizations) |
871 (1 << kBBOpt) |
872 (1 << kMatch) |
873 (1 << kPromoteCompilerTemps));
874 }
875
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100876 if (cu.instruction_set == kArm64) {
877 // TODO(Arm64): enable optimizations once backend is mature enough.
878 cu.disable_opt = ~(uint32_t)0;
879 }
880
buzbeea61f4952013-08-23 14:27:06 -0700881 cu.StartTimingSplit("BuildMIRGraph");
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700882 cu.mir_graph.reset(new MIRGraph(&cu, &cu.arena));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700883
Razvan A Lupusoruda7a69b2014-01-08 15:09:50 -0800884 /*
885 * After creation of the MIR graph, also create the code generator.
886 * The reason we do this is that optimizations on the MIR graph may need to get information
887 * that is only available if a CG exists.
888 */
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000889 cu.cg.reset(compiler->GetCodeGenerator(&cu, llvm_compilation_unit));
Razvan A Lupusoruda7a69b2014-01-08 15:09:50 -0800890
Brian Carlstrom7940e442013-07-12 13:46:57 -0700891 /* Gathering opcode stats? */
892 if (kCompilerDebugFlags & (1 << kDebugCountOpcodes)) {
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700893 cu.mir_graph->EnableOpcodeCounting();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700894 }
895
Dave Allison39c3bfb2014-01-28 18:33:52 -0800896 // Check early if we should skip this compilation if using the profiled filter.
897 if (cu.compiler_driver->ProfilePresent()) {
898 std::string methodname = PrettyMethod(method_idx, dex_file);
899 if (cu.mir_graph->SkipCompilation(methodname)) {
900 return NULL;
901 }
902 }
903
Brian Carlstrom7940e442013-07-12 13:46:57 -0700904 /* Build the raw MIR graph */
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700905 cu.mir_graph->InlineMethod(code_item, access_flags, invoke_type, class_def_idx, method_idx,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700906 class_loader, dex_file);
907
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100908 // TODO(Arm64): Remove this when we are able to compile everything.
909 if (!CanCompileMethod(method_idx, dex_file, cu)) {
910 VLOG(compiler) << "Cannot compile method : " << PrettyMethod(method_idx, dex_file);
911 return nullptr;
912 }
913
buzbee1da1e2f2013-11-15 13:37:01 -0800914 cu.NewTimingSplit("MIROpt:CheckFilters");
Jeff Hao4a200f52014-04-01 14:58:49 -0700915 if (cu.mir_graph->SkipCompilation()) {
916 return NULL;
buzbeeee17e0a2013-07-31 10:47:37 -0700917 }
918
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800919 /* Create the pass driver and launch it */
Ian Rogers3d504072014-03-01 09:16:49 -0800920 PassDriver pass_driver(&cu);
921 pass_driver.Launch();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700922
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700923 if (cu.enable_debug & (1 << kDebugDumpCheckStats)) {
924 cu.mir_graph->DumpCheckStats();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700925 }
926
927 if (kCompilerDebugFlags & (1 << kDebugCountOpcodes)) {
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700928 cu.mir_graph->ShowOpcodeStats();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700929 }
930
buzbee1da1e2f2013-11-15 13:37:01 -0800931 /* Reassociate sreg names with original Dalvik vreg names. */
932 cu.mir_graph->RemapRegLocations();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700933
Vladimir Marko53b6afc2014-03-21 14:21:20 +0000934 /* Free Arenas from the cu.arena_stack for reuse by the cu.arena in the codegen. */
935 if (cu.enable_debug & (1 << kDebugShowMemoryUsage)) {
936 if (cu.arena_stack.PeakBytesAllocated() > 256 * 1024) {
937 MemStats stack_stats(cu.arena_stack.GetPeakStats());
938 LOG(INFO) << PrettyMethod(method_idx, dex_file) << " " << Dumpable<MemStats>(stack_stats);
939 }
940 }
941 cu.arena_stack.Reset();
942
Brian Carlstrom7940e442013-07-12 13:46:57 -0700943 CompiledMethod* result = NULL;
944
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700945 cu.cg->Materialize();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700946
buzbee1da1e2f2013-11-15 13:37:01 -0800947 cu.NewTimingSplit("Dedupe"); /* deduping takes up the vast majority of time in GetCompiledMethod(). */
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700948 result = cu.cg->GetCompiledMethod();
buzbee1da1e2f2013-11-15 13:37:01 -0800949 cu.NewTimingSplit("Cleanup");
Brian Carlstrom7940e442013-07-12 13:46:57 -0700950
951 if (result) {
952 VLOG(compiler) << "Compiled " << PrettyMethod(method_idx, dex_file);
953 } else {
954 VLOG(compiler) << "Deferred " << PrettyMethod(method_idx, dex_file);
955 }
956
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700957 if (cu.enable_debug & (1 << kDebugShowMemoryUsage)) {
Vladimir Marko53b6afc2014-03-21 14:21:20 +0000958 if (cu.arena.BytesAllocated() > (1 * 1024 *1024)) {
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000959 MemStats mem_stats(cu.arena.GetMemStats());
Vladimir Marko53b6afc2014-03-21 14:21:20 +0000960 LOG(INFO) << PrettyMethod(method_idx, dex_file) << " " << Dumpable<MemStats>(mem_stats);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700961 }
962 }
963
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700964 if (cu.enable_debug & (1 << kDebugShowSummaryMemoryUsage)) {
965 LOG(INFO) << "MEMINFO " << cu.arena.BytesAllocated() << " " << cu.mir_graph->GetNumBlocks()
Brian Carlstrom7940e442013-07-12 13:46:57 -0700966 << " " << PrettyMethod(method_idx, dex_file);
967 }
968
buzbeea61f4952013-08-23 14:27:06 -0700969 cu.EndTiming();
Ian Rogers3d504072014-03-01 09:16:49 -0800970 driver.GetTimingsLogger()->AddLogger(cu.timings);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700971 return result;
972}
973
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000974CompiledMethod* CompileOneMethod(CompilerDriver& driver,
975 Compiler* compiler,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700976 const DexFile::CodeItem* code_item,
977 uint32_t access_flags,
978 InvokeType invoke_type,
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700979 uint16_t class_def_idx,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700980 uint32_t method_idx,
981 jobject class_loader,
982 const DexFile& dex_file,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000983 void* compilation_unit) {
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000984 return CompileMethod(driver, compiler, code_item, access_flags, invoke_type, class_def_idx,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000985 method_idx, class_loader, dex_file, compilation_unit);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700986}
987
988} // namespace art
989
990extern "C" art::CompiledMethod*
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000991 ArtQuickCompileMethod(art::CompilerDriver& driver,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700992 const art::DexFile::CodeItem* code_item,
993 uint32_t access_flags, art::InvokeType invoke_type,
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700994 uint16_t class_def_idx, uint32_t method_idx, jobject class_loader,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700995 const art::DexFile& dex_file) {
996 // TODO: check method fingerprint here to determine appropriate backend type. Until then, use build default
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000997 art::Compiler* compiler = driver.GetCompiler();
998 return art::CompileOneMethod(driver, compiler, code_item, access_flags, invoke_type,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700999 class_def_idx, method_idx, class_loader, dex_file,
1000 NULL /* use thread llvm_info */);
1001}