blob: 7848b065cc4ff8732bd2effead657bcdf9d85e0c [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 Beyler2469e602014-05-06 20:36:55 -070024#include "pass_driver_me_opts.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) |
buzbeeb01bf152014-05-13 15:59:07 -070078 // (1 << kDebugCodegenDump) |
Brian Carlstrom7940e442013-07-12 13:46:57 -070079 0;
80
Vladimir Marko25724ef2013-11-12 15:09:20 +000081CompilationUnit::CompilationUnit(ArenaPool* pool)
Ian Rogers93dcff32014-05-15 09:11:23 -070082 : compiler_driver(nullptr),
83 class_linker(nullptr),
84 dex_file(nullptr),
85 class_loader(nullptr),
Vladimir Marko25724ef2013-11-12 15:09:20 +000086 class_def_idx(0),
87 method_idx(0),
Ian Rogers93dcff32014-05-15 09:11:23 -070088 code_item(nullptr),
Vladimir Marko25724ef2013-11-12 15:09:20 +000089 access_flags(0),
90 invoke_type(kDirect),
Ian Rogers93dcff32014-05-15 09:11:23 -070091 shorty(nullptr),
Vladimir Marko25724ef2013-11-12 15:09:20 +000092 disable_opt(0),
93 enable_debug(0),
94 verbose(false),
Ian Rogers93dcff32014-05-15 09:11:23 -070095 compiler(nullptr),
Vladimir Marko25724ef2013-11-12 15:09:20 +000096 instruction_set(kNone),
Ian Rogers93dcff32014-05-15 09:11:23 -070097 target64(false),
Vladimir Marko25724ef2013-11-12 15:09:20 +000098 num_dalvik_registers(0),
Ian Rogers93dcff32014-05-15 09:11:23 -070099 insns(nullptr),
Vladimir Marko25724ef2013-11-12 15:09:20 +0000100 num_ins(0),
101 num_outs(0),
102 num_regs(0),
Vladimir Marko25724ef2013-11-12 15:09:20 +0000103 compiler_flip_match(false),
104 arena(pool),
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000105 arena_stack(pool),
Ian Rogers93dcff32014-05-15 09:11:23 -0700106 mir_graph(nullptr),
107 cg(nullptr),
Jean Christophe Beyler8bcecce2014-04-29 13:42:08 -0700108 timings("QuickCompiler", true, false),
109 print_pass(false) {
Vladimir Marko25724ef2013-11-12 15:09:20 +0000110}
111
112CompilationUnit::~CompilationUnit() {
113}
114
buzbeea61f4952013-08-23 14:27:06 -0700115void CompilationUnit::StartTimingSplit(const char* label) {
Nicolas Geoffrayea3fa0b2014-02-10 11:59:41 +0000116 if (compiler_driver->GetDumpPasses()) {
buzbeea61f4952013-08-23 14:27:06 -0700117 timings.StartSplit(label);
118 }
119}
120
121void CompilationUnit::NewTimingSplit(const char* label) {
Nicolas Geoffrayea3fa0b2014-02-10 11:59:41 +0000122 if (compiler_driver->GetDumpPasses()) {
buzbeea61f4952013-08-23 14:27:06 -0700123 timings.NewSplit(label);
124 }
125}
126
127void CompilationUnit::EndTiming() {
Nicolas Geoffrayea3fa0b2014-02-10 11:59:41 +0000128 if (compiler_driver->GetDumpPasses()) {
buzbeea61f4952013-08-23 14:27:06 -0700129 timings.EndSplit();
Nicolas Geoffrayea3fa0b2014-02-10 11:59:41 +0000130 if (enable_debug & (1 << kDebugTimings)) {
131 LOG(INFO) << "TIMINGS " << PrettyMethod(method_idx, *dex_file);
132 LOG(INFO) << Dumpable<TimingLogger>(timings);
133 }
buzbeea61f4952013-08-23 14:27:06 -0700134 }
135}
136
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100137// TODO: Remove this when we are able to compile everything.
138int arm64_support_list[] = {
139 Instruction::NOP,
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100140 Instruction::MOVE,
141 Instruction::MOVE_FROM16,
142 Instruction::MOVE_16,
143 Instruction::MOVE_WIDE,
144 Instruction::MOVE_WIDE_FROM16,
145 Instruction::MOVE_WIDE_16,
146 Instruction::MOVE_OBJECT,
147 Instruction::MOVE_OBJECT_FROM16,
148 Instruction::MOVE_OBJECT_16,
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100149 // Instruction::MOVE_RESULT,
150 // Instruction::MOVE_RESULT_WIDE,
151 // Instruction::MOVE_RESULT_OBJECT,
Zheng Xuc8304302014-05-15 17:21:01 +0100152 Instruction::MOVE_EXCEPTION,
153 Instruction::RETURN_VOID,
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100154 Instruction::RETURN,
155 Instruction::RETURN_WIDE,
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100156 // Instruction::RETURN_OBJECT,
157 // Instruction::CONST_4,
158 // Instruction::CONST_16,
159 // Instruction::CONST,
160 // Instruction::CONST_HIGH16,
161 // Instruction::CONST_WIDE_16,
162 // Instruction::CONST_WIDE_32,
163 // Instruction::CONST_WIDE,
164 // Instruction::CONST_WIDE_HIGH16,
165 // Instruction::CONST_STRING,
166 // Instruction::CONST_STRING_JUMBO,
167 // Instruction::CONST_CLASS,
Zheng Xuc8304302014-05-15 17:21:01 +0100168 Instruction::MONITOR_ENTER,
169 Instruction::MONITOR_EXIT,
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100170 // Instruction::CHECK_CAST,
171 // Instruction::INSTANCE_OF,
172 // Instruction::ARRAY_LENGTH,
173 // Instruction::NEW_INSTANCE,
174 // Instruction::NEW_ARRAY,
175 // Instruction::FILLED_NEW_ARRAY,
176 // Instruction::FILLED_NEW_ARRAY_RANGE,
177 // Instruction::FILL_ARRAY_DATA,
Zheng Xuc8304302014-05-15 17:21:01 +0100178 Instruction::THROW,
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100179 // Instruction::GOTO,
180 // Instruction::GOTO_16,
181 // Instruction::GOTO_32,
182 // Instruction::PACKED_SWITCH,
183 // Instruction::SPARSE_SWITCH,
Serban Constantinescu032d3772014-05-23 17:38:18 +0100184 Instruction::CMPL_FLOAT,
185 Instruction::CMPG_FLOAT,
186 Instruction::CMPL_DOUBLE,
187 Instruction::CMPG_DOUBLE,
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100188 Instruction::CMP_LONG,
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100189 // Instruction::IF_EQ,
190 // Instruction::IF_NE,
191 // Instruction::IF_LT,
192 // Instruction::IF_GE,
193 // Instruction::IF_GT,
194 // Instruction::IF_LE,
195 // Instruction::IF_EQZ,
196 // Instruction::IF_NEZ,
197 // Instruction::IF_LTZ,
198 // Instruction::IF_GEZ,
199 // Instruction::IF_GTZ,
200 // Instruction::IF_LEZ,
201 // Instruction::UNUSED_3E,
202 // Instruction::UNUSED_3F,
203 // Instruction::UNUSED_40,
204 // Instruction::UNUSED_41,
205 // Instruction::UNUSED_42,
206 // Instruction::UNUSED_43,
207 // Instruction::AGET,
208 // Instruction::AGET_WIDE,
209 // Instruction::AGET_OBJECT,
210 // Instruction::AGET_BOOLEAN,
211 // Instruction::AGET_BYTE,
212 // Instruction::AGET_CHAR,
213 // Instruction::AGET_SHORT,
214 // Instruction::APUT,
215 // Instruction::APUT_WIDE,
216 // Instruction::APUT_OBJECT,
217 // Instruction::APUT_BOOLEAN,
218 // Instruction::APUT_BYTE,
219 // Instruction::APUT_CHAR,
220 // Instruction::APUT_SHORT,
221 // Instruction::IGET,
222 // Instruction::IGET_WIDE,
223 // Instruction::IGET_OBJECT,
224 // Instruction::IGET_BOOLEAN,
225 // Instruction::IGET_BYTE,
226 // Instruction::IGET_CHAR,
227 // Instruction::IGET_SHORT,
228 // Instruction::IPUT,
229 // Instruction::IPUT_WIDE,
230 // Instruction::IPUT_OBJECT,
231 // Instruction::IPUT_BOOLEAN,
232 // Instruction::IPUT_BYTE,
233 // Instruction::IPUT_CHAR,
234 // Instruction::IPUT_SHORT,
Zheng Xuc8304302014-05-15 17:21:01 +0100235 Instruction::SGET,
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100236 // Instruction::SGET_WIDE,
Zheng Xuc8304302014-05-15 17:21:01 +0100237 Instruction::SGET_OBJECT,
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100238 // Instruction::SGET_BOOLEAN,
239 // Instruction::SGET_BYTE,
240 // Instruction::SGET_CHAR,
241 // Instruction::SGET_SHORT,
Zheng Xuc8304302014-05-15 17:21:01 +0100242 Instruction::SPUT,
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100243 // Instruction::SPUT_WIDE,
244 // Instruction::SPUT_OBJECT,
245 // Instruction::SPUT_BOOLEAN,
246 // Instruction::SPUT_BYTE,
247 // Instruction::SPUT_CHAR,
248 // Instruction::SPUT_SHORT,
249 Instruction::INVOKE_VIRTUAL,
250 Instruction::INVOKE_SUPER,
251 Instruction::INVOKE_DIRECT,
252 Instruction::INVOKE_STATIC,
253 Instruction::INVOKE_INTERFACE,
254 // Instruction::RETURN_VOID_BARRIER,
255 // Instruction::INVOKE_VIRTUAL_RANGE,
256 // Instruction::INVOKE_SUPER_RANGE,
257 // Instruction::INVOKE_DIRECT_RANGE,
258 // Instruction::INVOKE_STATIC_RANGE,
259 // Instruction::INVOKE_INTERFACE_RANGE,
260 // Instruction::UNUSED_79,
261 // Instruction::UNUSED_7A,
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100262 Instruction::NEG_INT,
263 Instruction::NOT_INT,
264 Instruction::NEG_LONG,
265 Instruction::NOT_LONG,
Serban Constantinescu032d3772014-05-23 17:38:18 +0100266 Instruction::NEG_FLOAT,
267 Instruction::NEG_DOUBLE,
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100268 Instruction::INT_TO_LONG,
Serban Constantinescu032d3772014-05-23 17:38:18 +0100269 Instruction::INT_TO_FLOAT,
270 Instruction::INT_TO_DOUBLE,
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100271 Instruction::LONG_TO_INT,
Serban Constantinescu032d3772014-05-23 17:38:18 +0100272 Instruction::LONG_TO_FLOAT,
273 Instruction::LONG_TO_DOUBLE,
274 Instruction::FLOAT_TO_INT,
275 Instruction::FLOAT_TO_LONG,
276 Instruction::FLOAT_TO_DOUBLE,
277 Instruction::DOUBLE_TO_INT,
278 Instruction::DOUBLE_TO_LONG,
279 Instruction::DOUBLE_TO_FLOAT,
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100280 Instruction::INT_TO_BYTE,
281 Instruction::INT_TO_CHAR,
282 Instruction::INT_TO_SHORT,
283 Instruction::ADD_INT,
284 Instruction::SUB_INT,
285 Instruction::MUL_INT,
286 Instruction::DIV_INT,
287 Instruction::REM_INT,
288 Instruction::AND_INT,
289 Instruction::OR_INT,
290 Instruction::XOR_INT,
291 Instruction::SHL_INT,
292 Instruction::SHR_INT,
293 Instruction::USHR_INT,
294 Instruction::ADD_LONG,
295 Instruction::SUB_LONG,
296 Instruction::MUL_LONG,
297 Instruction::DIV_LONG,
298 Instruction::REM_LONG,
299 Instruction::AND_LONG,
300 Instruction::OR_LONG,
301 Instruction::XOR_LONG,
302 Instruction::SHL_LONG,
303 Instruction::SHR_LONG,
304 Instruction::USHR_LONG,
Serban Constantinescu032d3772014-05-23 17:38:18 +0100305 Instruction::ADD_FLOAT,
306 Instruction::SUB_FLOAT,
307 Instruction::MUL_FLOAT,
308 Instruction::DIV_FLOAT,
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100309 // Instruction::REM_FLOAT,
Serban Constantinescu032d3772014-05-23 17:38:18 +0100310 Instruction::ADD_DOUBLE,
311 Instruction::SUB_DOUBLE,
312 Instruction::MUL_DOUBLE,
313 Instruction::DIV_DOUBLE,
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100314 // Instruction::REM_DOUBLE,
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100315 Instruction::ADD_INT_2ADDR,
316 Instruction::SUB_INT_2ADDR,
317 Instruction::MUL_INT_2ADDR,
318 Instruction::DIV_INT_2ADDR,
319 Instruction::REM_INT_2ADDR,
320 Instruction::AND_INT_2ADDR,
321 Instruction::OR_INT_2ADDR,
322 Instruction::XOR_INT_2ADDR,
323 Instruction::SHL_INT_2ADDR,
324 Instruction::SHR_INT_2ADDR,
325 Instruction::USHR_INT_2ADDR,
326 Instruction::ADD_LONG_2ADDR,
327 Instruction::SUB_LONG_2ADDR,
328 Instruction::MUL_LONG_2ADDR,
329 Instruction::DIV_LONG_2ADDR,
330 Instruction::REM_LONG_2ADDR,
331 Instruction::AND_LONG_2ADDR,
332 Instruction::OR_LONG_2ADDR,
333 Instruction::XOR_LONG_2ADDR,
334 Instruction::SHL_LONG_2ADDR,
335 Instruction::SHR_LONG_2ADDR,
336 Instruction::USHR_LONG_2ADDR,
Serban Constantinescu032d3772014-05-23 17:38:18 +0100337 Instruction::ADD_FLOAT_2ADDR,
338 Instruction::SUB_FLOAT_2ADDR,
339 Instruction::MUL_FLOAT_2ADDR,
340 Instruction::DIV_FLOAT_2ADDR,
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100341 // Instruction::REM_FLOAT_2ADDR,
Serban Constantinescu032d3772014-05-23 17:38:18 +0100342 Instruction::ADD_DOUBLE_2ADDR,
343 Instruction::SUB_DOUBLE_2ADDR,
344 Instruction::MUL_DOUBLE_2ADDR,
345 Instruction::DIV_DOUBLE_2ADDR,
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100346 // Instruction::REM_DOUBLE_2ADDR,
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100347 Instruction::ADD_INT_LIT16,
348 Instruction::RSUB_INT,
349 Instruction::MUL_INT_LIT16,
350 Instruction::DIV_INT_LIT16,
351 Instruction::REM_INT_LIT16,
352 Instruction::AND_INT_LIT16,
353 Instruction::OR_INT_LIT16,
354 Instruction::XOR_INT_LIT16,
Zheng Xuc8304302014-05-15 17:21:01 +0100355 Instruction::ADD_INT_LIT8,
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100356 Instruction::RSUB_INT_LIT8,
357 Instruction::MUL_INT_LIT8,
358 Instruction::DIV_INT_LIT8,
359 Instruction::REM_INT_LIT8,
360 Instruction::AND_INT_LIT8,
361 Instruction::OR_INT_LIT8,
362 Instruction::XOR_INT_LIT8,
363 Instruction::SHL_INT_LIT8,
364 Instruction::SHR_INT_LIT8,
365 Instruction::USHR_INT_LIT8,
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100366 // Instruction::IGET_QUICK,
367 // Instruction::IGET_WIDE_QUICK,
368 // Instruction::IGET_OBJECT_QUICK,
369 // Instruction::IPUT_QUICK,
370 // Instruction::IPUT_WIDE_QUICK,
371 // Instruction::IPUT_OBJECT_QUICK,
372 // Instruction::INVOKE_VIRTUAL_QUICK,
373 // Instruction::INVOKE_VIRTUAL_RANGE_QUICK,
374 // Instruction::UNUSED_EB,
375 // Instruction::UNUSED_EC,
376 // Instruction::UNUSED_ED,
377 // Instruction::UNUSED_EE,
378 // Instruction::UNUSED_EF,
379 // Instruction::UNUSED_F0,
380 // Instruction::UNUSED_F1,
381 // Instruction::UNUSED_F2,
382 // Instruction::UNUSED_F3,
383 // Instruction::UNUSED_F4,
384 // Instruction::UNUSED_F5,
385 // Instruction::UNUSED_F6,
386 // Instruction::UNUSED_F7,
387 // Instruction::UNUSED_F8,
388 // Instruction::UNUSED_F9,
389 // Instruction::UNUSED_FA,
390 // Instruction::UNUSED_FB,
391 // Instruction::UNUSED_FC,
392 // Instruction::UNUSED_FD,
393 // Instruction::UNUSED_FE,
394 // Instruction::UNUSED_FF,
395
Serban Constantinescu05e27ff2014-05-28 13:21:45 +0100396 // TODO(Arm64): Enable compiler pass
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100397 // ----- ExtendedMIROpcode -----
Serban Constantinescu05e27ff2014-05-28 13:21:45 +0100398 kMirOpPhi,
399 kMirOpCopy,
400 kMirOpFusedCmplFloat,
401 kMirOpFusedCmpgFloat,
402 kMirOpFusedCmplDouble,
403 kMirOpFusedCmpgDouble,
404 kMirOpFusedCmpLong,
405 kMirOpNop,
406 kMirOpNullCheck,
407 kMirOpRangeCheck,
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100408 kMirOpDivZeroCheck,
Zheng Xuc8304302014-05-15 17:21:01 +0100409 kMirOpCheck,
Serban Constantinescu05e27ff2014-05-28 13:21:45 +0100410 kMirOpCheckPart2,
411 kMirOpSelect,
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100412 // kMirOpLast,
413};
414
415// TODO: Remove this when we are able to compile everything.
Vladimir Kostyukov56784552014-05-13 12:12:00 +0700416int x86_64_support_list[] = {
417 Instruction::NOP,
418 // Instruction::MOVE,
419 // Instruction::MOVE_FROM16,
420 // Instruction::MOVE_16,
421 // Instruction::MOVE_WIDE,
422 // Instruction::MOVE_WIDE_FROM16,
423 // Instruction::MOVE_WIDE_16,
424 // Instruction::MOVE_OBJECT,
425 // Instruction::MOVE_OBJECT_FROM16,
426 // Instruction::MOVE_OBJECT_16,
427 // Instruction::MOVE_RESULT,
428 // Instruction::MOVE_RESULT_WIDE,
429 // Instruction::MOVE_RESULT_OBJECT,
430 // Instruction::MOVE_EXCEPTION,
431 Instruction::RETURN_VOID,
432 Instruction::RETURN,
433 // Instruction::RETURN_WIDE,
434 Instruction::RETURN_OBJECT,
435 // Instruction::CONST_4,
436 // Instruction::CONST_16,
437 // Instruction::CONST,
438 // Instruction::CONST_HIGH16,
439 // Instruction::CONST_WIDE_16,
440 // Instruction::CONST_WIDE_32,
441 // Instruction::CONST_WIDE,
442 // Instruction::CONST_WIDE_HIGH16,
443 // Instruction::CONST_STRING,
444 // Instruction::CONST_STRING_JUMBO,
445 // Instruction::CONST_CLASS,
446 // Instruction::MONITOR_ENTER,
447 // Instruction::MONITOR_EXIT,
448 // Instruction::CHECK_CAST,
449 // Instruction::INSTANCE_OF,
450 // Instruction::ARRAY_LENGTH,
451 // Instruction::NEW_INSTANCE,
452 // Instruction::NEW_ARRAY,
453 // Instruction::FILLED_NEW_ARRAY,
454 // Instruction::FILLED_NEW_ARRAY_RANGE,
455 // Instruction::FILL_ARRAY_DATA,
456 // Instruction::THROW,
457 // Instruction::GOTO,
458 // Instruction::GOTO_16,
459 // Instruction::GOTO_32,
460 // Instruction::PACKED_SWITCH,
461 // Instruction::SPARSE_SWITCH,
462 // Instruction::CMPL_FLOAT,
463 // Instruction::CMPG_FLOAT,
464 // Instruction::CMPL_DOUBLE,
465 // Instruction::CMPG_DOUBLE,
466 // Instruction::CMP_LONG,
467 // Instruction::IF_EQ,
468 // Instruction::IF_NE,
469 // Instruction::IF_LT,
470 // Instruction::IF_GE,
471 // Instruction::IF_GT,
472 // Instruction::IF_LE,
473 // Instruction::IF_EQZ,
474 // Instruction::IF_NEZ,
475 // Instruction::IF_LTZ,
476 // Instruction::IF_GEZ,
477 // Instruction::IF_GTZ,
478 // Instruction::IF_LEZ,
479 // Instruction::UNUSED_3E,
480 // Instruction::UNUSED_3F,
481 // Instruction::UNUSED_40,
482 // Instruction::UNUSED_41,
483 // Instruction::UNUSED_42,
484 // Instruction::UNUSED_43,
485 // Instruction::AGET,
486 // Instruction::AGET_WIDE,
487 // Instruction::AGET_OBJECT,
488 // Instruction::AGET_BOOLEAN,
489 // Instruction::AGET_BYTE,
490 // Instruction::AGET_CHAR,
491 // Instruction::AGET_SHORT,
492 // Instruction::APUT,
493 // Instruction::APUT_WIDE,
494 // Instruction::APUT_OBJECT,
495 // Instruction::APUT_BOOLEAN,
496 // Instruction::APUT_BYTE,
497 // Instruction::APUT_CHAR,
498 // Instruction::APUT_SHORT,
499 // Instruction::IGET,
500 // Instruction::IGET_WIDE,
501 // Instruction::IGET_OBJECT,
502 // Instruction::IGET_BOOLEAN,
503 // Instruction::IGET_BYTE,
504 // Instruction::IGET_CHAR,
505 // Instruction::IGET_SHORT,
506 // Instruction::IPUT,
507 // Instruction::IPUT_WIDE,
508 // Instruction::IPUT_OBJECT,
509 // Instruction::IPUT_BOOLEAN,
510 // Instruction::IPUT_BYTE,
511 // Instruction::IPUT_CHAR,
512 // Instruction::IPUT_SHORT,
513 Instruction::SGET,
514 // Instruction::SGET_WIDE,
515 Instruction::SGET_OBJECT,
516 Instruction::SGET_BOOLEAN,
517 Instruction::SGET_BYTE,
518 Instruction::SGET_CHAR,
519 Instruction::SGET_SHORT,
520 Instruction::SPUT,
521 // Instruction::SPUT_WIDE,
522 Instruction::SPUT_OBJECT,
523 Instruction::SPUT_BOOLEAN,
524 Instruction::SPUT_BYTE,
525 Instruction::SPUT_CHAR,
526 Instruction::SPUT_SHORT,
527 Instruction::INVOKE_VIRTUAL,
528 Instruction::INVOKE_SUPER,
529 Instruction::INVOKE_DIRECT,
530 Instruction::INVOKE_STATIC,
531 Instruction::INVOKE_INTERFACE,
532 // Instruction::RETURN_VOID_BARRIER,
533 // Instruction::INVOKE_VIRTUAL_RANGE,
534 // Instruction::INVOKE_SUPER_RANGE,
535 // Instruction::INVOKE_DIRECT_RANGE,
536 // Instruction::INVOKE_STATIC_RANGE,
537 // Instruction::INVOKE_INTERFACE_RANGE,
538 // Instruction::UNUSED_79,
539 // Instruction::UNUSED_7A,
540 // Instruction::NEG_INT,
541 // Instruction::NOT_INT,
542 // Instruction::NEG_LONG,
543 // Instruction::NOT_LONG,
544 // Instruction::NEG_FLOAT,
545 // Instruction::NEG_DOUBLE,
546 // Instruction::INT_TO_LONG,
547 // Instruction::INT_TO_FLOAT,
548 // Instruction::INT_TO_DOUBLE,
549 // Instruction::LONG_TO_INT,
550 // Instruction::LONG_TO_FLOAT,
551 // Instruction::LONG_TO_DOUBLE,
552 // Instruction::FLOAT_TO_INT,
553 // Instruction::FLOAT_TO_LONG,
554 // Instruction::FLOAT_TO_DOUBLE,
555 // Instruction::DOUBLE_TO_INT,
556 // Instruction::DOUBLE_TO_LONG,
557 // Instruction::DOUBLE_TO_FLOAT,
558 // Instruction::INT_TO_BYTE,
559 // Instruction::INT_TO_CHAR,
560 // Instruction::INT_TO_SHORT,
561 // Instruction::ADD_INT,
562 // Instruction::SUB_INT,
563 // Instruction::MUL_INT,
564 // Instruction::DIV_INT,
565 // Instruction::REM_INT,
566 // Instruction::AND_INT,
567 // Instruction::OR_INT,
568 // Instruction::XOR_INT,
569 // Instruction::SHL_INT,
570 // Instruction::SHR_INT,
571 // Instruction::USHR_INT,
572 // Instruction::ADD_LONG,
573 // Instruction::SUB_LONG,
574 // Instruction::MUL_LONG,
575 // Instruction::DIV_LONG,
576 // Instruction::REM_LONG,
577 // Instruction::AND_LONG,
578 // Instruction::OR_LONG,
579 // Instruction::XOR_LONG,
580 // Instruction::SHL_LONG,
581 // Instruction::SHR_LONG,
582 // Instruction::USHR_LONG,
583 // Instruction::ADD_FLOAT,
584 // Instruction::SUB_FLOAT,
585 // Instruction::MUL_FLOAT,
586 // Instruction::DIV_FLOAT,
587 // Instruction::REM_FLOAT,
588 // Instruction::ADD_DOUBLE,
589 // Instruction::SUB_DOUBLE,
590 // Instruction::MUL_DOUBLE,
591 // Instruction::DIV_DOUBLE,
592 // Instruction::REM_DOUBLE,
593 // Instruction::ADD_INT_2ADDR,
594 // Instruction::SUB_INT_2ADDR,
595 // Instruction::MUL_INT_2ADDR,
596 // Instruction::DIV_INT_2ADDR,
597 // Instruction::REM_INT_2ADDR,
598 // Instruction::AND_INT_2ADDR,
599 // Instruction::OR_INT_2ADDR,
600 // Instruction::XOR_INT_2ADDR,
601 // Instruction::SHL_INT_2ADDR,
602 // Instruction::SHR_INT_2ADDR,
603 // Instruction::USHR_INT_2ADDR,
604 // Instruction::ADD_LONG_2ADDR,
605 // Instruction::SUB_LONG_2ADDR,
606 // Instruction::MUL_LONG_2ADDR,
607 // Instruction::DIV_LONG_2ADDR,
608 // Instruction::REM_LONG_2ADDR,
609 // Instruction::AND_LONG_2ADDR,
610 // Instruction::OR_LONG_2ADDR,
611 // Instruction::XOR_LONG_2ADDR,
612 // Instruction::SHL_LONG_2ADDR,
613 // Instruction::SHR_LONG_2ADDR,
614 // Instruction::USHR_LONG_2ADDR,
615 // Instruction::ADD_FLOAT_2ADDR,
616 // Instruction::SUB_FLOAT_2ADDR,
617 // Instruction::MUL_FLOAT_2ADDR,
618 // Instruction::DIV_FLOAT_2ADDR,
619 // Instruction::REM_FLOAT_2ADDR,
620 // Instruction::ADD_DOUBLE_2ADDR,
621 // Instruction::SUB_DOUBLE_2ADDR,
622 // Instruction::MUL_DOUBLE_2ADDR,
623 // Instruction::DIV_DOUBLE_2ADDR,
624 // Instruction::REM_DOUBLE_2ADDR,
625 // Instruction::ADD_INT_LIT16,
626 // Instruction::RSUB_INT,
627 // Instruction::MUL_INT_LIT16,
628 // Instruction::DIV_INT_LIT16,
629 // Instruction::REM_INT_LIT16,
630 // Instruction::AND_INT_LIT16,
631 // Instruction::OR_INT_LIT16,
632 // Instruction::XOR_INT_LIT16,
633 // Instruction::ADD_INT_LIT8,
634 // Instruction::RSUB_INT_LIT8,
635 // Instruction::MUL_INT_LIT8,
636 // Instruction::DIV_INT_LIT8,
637 // Instruction::REM_INT_LIT8,
638 // Instruction::AND_INT_LIT8,
639 // Instruction::OR_INT_LIT8,
640 // Instruction::XOR_INT_LIT8,
641 // Instruction::SHL_INT_LIT8,
642 // Instruction::SHR_INT_LIT8,
643 // Instruction::USHR_INT_LIT8,
644 // Instruction::IGET_QUICK,
645 // Instruction::IGET_WIDE_QUICK,
646 // Instruction::IGET_OBJECT_QUICK,
647 // Instruction::IPUT_QUICK,
648 // Instruction::IPUT_WIDE_QUICK,
649 // Instruction::IPUT_OBJECT_QUICK,
650 // Instruction::INVOKE_VIRTUAL_QUICK,
651 // Instruction::INVOKE_VIRTUAL_RANGE_QUICK,
652 // Instruction::UNUSED_EB,
653 // Instruction::UNUSED_EC,
654 // Instruction::UNUSED_ED,
655 // Instruction::UNUSED_EE,
656 // Instruction::UNUSED_EF,
657 // Instruction::UNUSED_F0,
658 // Instruction::UNUSED_F1,
659 // Instruction::UNUSED_F2,
660 // Instruction::UNUSED_F3,
661 // Instruction::UNUSED_F4,
662 // Instruction::UNUSED_F5,
663 // Instruction::UNUSED_F6,
664 // Instruction::UNUSED_F7,
665 // Instruction::UNUSED_F8,
666 // Instruction::UNUSED_F9,
667 // Instruction::UNUSED_FA,
668 // Instruction::UNUSED_FB,
669 // Instruction::UNUSED_FC,
670 // Instruction::UNUSED_FD,
671 // Instruction::UNUSED_FE,
672 // Instruction::UNUSED_FF,
673
674 // ----- ExtendedMIROpcode -----
675 // kMirOpPhi,
676 // kMirOpCopy,
677 // kMirOpFusedCmplFloat,
678 // kMirOpFusedCmpgFloat,
679 // kMirOpFusedCmplDouble,
680 // kMirOpFusedCmpgDouble,
681 // kMirOpFusedCmpLong,
682 // kMirOpNop,
683 // kMirOpNullCheck,
684 // kMirOpRangeCheck,
685 // kMirOpDivZeroCheck,
686 // kMirOpCheck,
687 // kMirOpCheckPart2,
688 // kMirOpSelect,
689 // kMirOpLast,
690};
691
692// Z : boolean
693// B : byte
694// S : short
695// C : char
696// I : int
Zheng Xu48241e72014-05-23 11:52:42 +0800697// J : long
Vladimir Kostyukov56784552014-05-13 12:12:00 +0700698// F : float
699// D : double
700// L : reference(object, array)
701// V : void
702// (ARM64) Current calling conversion only support 32bit softfp
703// which has problems with long, float, double
Serban Constantinescu032d3772014-05-23 17:38:18 +0100704constexpr char arm64_supported_types[] = "ZBSCILVJFD";
Vladimir Kostyukov56784552014-05-13 12:12:00 +0700705// (x84_64) We still have troubles with compiling longs/doubles/floats
706constexpr char x86_64_supported_types[] = "ZBSCILV";
707
708// TODO: Remove this when we are able to compile everything.
709static bool CanCompileShorty(const char* shorty, InstructionSet instruction_set) {
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100710 uint32_t shorty_size = strlen(shorty);
711 CHECK_GE(shorty_size, 1u);
712 // Set a limitation on maximum number of parameters.
713 // Note : there is an implied "method*" parameter, and probably "this" as well.
714 // 1 is for the return type. Currently, we only accept 2 parameters at the most.
Vladimir Kostyukov56784552014-05-13 12:12:00 +0700715 // (x86_64): For now we have the same limitation. But we might want to split this
716 // check in future into two separate cases for arm64 and x86_64.
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100717 if (shorty_size > (1 + 2)) {
718 return false;
719 }
Vladimir Kostyukov56784552014-05-13 12:12:00 +0700720
721 const char* supported_types = arm64_supported_types;
722 if (instruction_set == kX86_64) {
723 supported_types = x86_64_supported_types;
724 }
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100725 for (uint32_t i = 0; i < shorty_size; i++) {
726 if (strchr(supported_types, shorty[i]) == nullptr) {
727 return false;
728 }
729 }
730 return true;
731};
732
733// TODO: Remove this when we are able to compile everything.
734// Skip the method that we do not support currently.
735static bool CanCompileMethod(uint32_t method_idx, const DexFile& dex_file,
736 CompilationUnit& cu) {
737 // There is some limitation with current ARM 64 backend.
Vladimir Kostyukov56784552014-05-13 12:12:00 +0700738 if (cu.instruction_set == kArm64 || cu.instruction_set == kX86_64) {
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100739 // Check if we can compile the prototype.
740 const char* shorty = dex_file.GetMethodShorty(dex_file.GetMethodId(method_idx));
Vladimir Kostyukov56784552014-05-13 12:12:00 +0700741 if (!CanCompileShorty(shorty, cu.instruction_set)) {
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100742 VLOG(compiler) << "Unsupported shorty : " << shorty;
743 return false;
744 }
745
Vladimir Kostyukov56784552014-05-13 12:12:00 +0700746 const int *support_list = arm64_support_list;
747 int support_list_size = arraysize(arm64_support_list);
748 if (cu.instruction_set == kX86_64) {
749 support_list = x86_64_support_list;
750 support_list_size = arraysize(x86_64_support_list);
751 }
752
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100753 for (int idx = 0; idx < cu.mir_graph->GetNumBlocks(); idx++) {
Jean Christophe Beyler2469e602014-05-06 20:36:55 -0700754 BasicBlock* bb = cu.mir_graph->GetBasicBlock(idx);
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100755 if (bb == NULL) continue;
756 if (bb->block_type == kDead) continue;
757 for (MIR* mir = bb->first_mir_insn; mir != nullptr; mir = mir->next) {
758 int opcode = mir->dalvikInsn.opcode;
759 // Check if we support the byte code.
Vladimir Kostyukov56784552014-05-13 12:12:00 +0700760 if (std::find(support_list, support_list + support_list_size,
761 opcode) == support_list + support_list_size) {
buzbee35ba7f32014-05-31 08:59:01 -0700762 if (!cu.mir_graph->IsPseudoMirOp(opcode)) {
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100763 VLOG(compiler) << "Unsupported dalvik byte code : "
764 << mir->dalvikInsn.opcode;
765 } else {
766 VLOG(compiler) << "Unsupported extended MIR opcode : "
767 << MIRGraph::extended_mir_op_names_[opcode - kMirOpFirst];
768 }
769 return false;
770 }
771 // Check if it invokes a prototype that we cannot support.
772 if (Instruction::INVOKE_VIRTUAL == opcode ||
773 Instruction::INVOKE_SUPER == opcode ||
774 Instruction::INVOKE_DIRECT == opcode ||
775 Instruction::INVOKE_STATIC == opcode ||
776 Instruction::INVOKE_INTERFACE == opcode) {
777 uint32_t invoke_method_idx = mir->dalvikInsn.vB;
778 const char* invoke_method_shorty = dex_file.GetMethodShorty(
779 dex_file.GetMethodId(invoke_method_idx));
Vladimir Kostyukov56784552014-05-13 12:12:00 +0700780 if (!CanCompileShorty(invoke_method_shorty, cu.instruction_set)) {
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100781 VLOG(compiler) << "Unsupported to invoke '"
782 << PrettyMethod(invoke_method_idx, dex_file)
783 << "' with shorty : " << invoke_method_shorty;
784 return false;
785 }
786 }
787 }
788 }
789
790 LOG(INFO) << "Using experimental instruction set A64 for "
791 << PrettyMethod(method_idx, dex_file);
792 }
793 return true;
794}
795
Ian Rogers3d504072014-03-01 09:16:49 -0800796static CompiledMethod* CompileMethod(CompilerDriver& driver,
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000797 Compiler* compiler,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700798 const DexFile::CodeItem* code_item,
799 uint32_t access_flags, InvokeType invoke_type,
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700800 uint16_t class_def_idx, uint32_t method_idx,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000801 jobject class_loader, const DexFile& dex_file,
802 void* llvm_compilation_unit) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700803 VLOG(compiler) << "Compiling " << PrettyMethod(method_idx, dex_file) << "...";
buzbeeb48819d2013-09-14 16:15:25 -0700804 if (code_item->insns_size_in_code_units_ >= 0x10000) {
805 LOG(INFO) << "Method size exceeds compiler limits: " << code_item->insns_size_in_code_units_
806 << " in " << PrettyMethod(method_idx, dex_file);
807 return NULL;
808 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700809
Jeff Hao4a200f52014-04-01 14:58:49 -0700810 if (!driver.GetCompilerOptions().IsCompilationEnabled()) {
Ian Rogersa03de6d2014-03-08 23:37:07 +0000811 return nullptr;
812 }
813
Brian Carlstrom7940e442013-07-12 13:46:57 -0700814 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Ian Rogers3d504072014-03-01 09:16:49 -0800815 CompilationUnit cu(driver.GetArenaPool());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700816
Ian Rogers3d504072014-03-01 09:16:49 -0800817 cu.compiler_driver = &driver;
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700818 cu.class_linker = class_linker;
Ian Rogers3d504072014-03-01 09:16:49 -0800819 cu.instruction_set = driver.GetInstructionSet();
Mathieu Chartier53bee422014-04-04 16:10:05 -0700820 if (cu.instruction_set == kArm) {
821 cu.instruction_set = kThumb2;
822 }
Andreas Gampeaf13ad92014-04-11 12:07:48 -0700823 cu.target64 = Is64BitInstructionSet(cu.instruction_set);
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000824 cu.compiler = compiler;
Stuart Monteithb95a5342014-03-12 13:32:32 +0000825 // TODO: x86_64 & arm64 are not yet implemented.
Mathieu Chartier53bee422014-04-04 16:10:05 -0700826 CHECK((cu.instruction_set == kThumb2) ||
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100827 (cu.instruction_set == kArm64) ||
Mathieu Chartier53bee422014-04-04 16:10:05 -0700828 (cu.instruction_set == kX86) ||
829 (cu.instruction_set == kX86_64) ||
830 (cu.instruction_set == kMips));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700831
Brian Carlstrom7940e442013-07-12 13:46:57 -0700832 /* Adjust this value accordingly once inlining is performed */
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700833 cu.num_dalvik_registers = code_item->registers_size_;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700834 // TODO: set this from command line
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700835 cu.compiler_flip_match = false;
836 bool use_match = !cu.compiler_method_match.empty();
837 bool match = use_match && (cu.compiler_flip_match ^
838 (PrettyMethod(method_idx, dex_file).find(cu.compiler_method_match) !=
Brian Carlstrom7940e442013-07-12 13:46:57 -0700839 std::string::npos));
840 if (!use_match || match) {
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700841 cu.disable_opt = kCompilerOptimizerDisableFlags;
842 cu.enable_debug = kCompilerDebugFlags;
843 cu.verbose = VLOG_IS_ON(compiler) ||
844 (cu.enable_debug & (1 << kDebugVerbose));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700845 }
846
Mingyao Yang42d65c52014-04-18 16:49:39 -0700847 if (gVerboseMethods.size() != 0) {
848 cu.verbose = false;
849 for (size_t i = 0; i < gVerboseMethods.size(); ++i) {
850 if (PrettyMethod(method_idx, dex_file).find(gVerboseMethods[i])
851 != std::string::npos) {
852 cu.verbose = true;
853 break;
854 }
855 }
856 }
857
buzbeeb01bf152014-05-13 15:59:07 -0700858 if (cu.verbose) {
859 cu.enable_debug |= (1 << kDebugCodegenDump);
860 }
861
Brian Carlstrom7940e442013-07-12 13:46:57 -0700862 /*
863 * TODO: rework handling of optimization and debug flags. Should we split out
864 * MIR and backend flags? Need command-line setting as well.
865 */
866
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000867 compiler->InitCompilationUnit(cu);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700868
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700869 if (cu.instruction_set == kMips) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700870 // Disable some optimizations for mips for now
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700871 cu.disable_opt |= (
Brian Carlstrom7940e442013-07-12 13:46:57 -0700872 (1 << kLoadStoreElimination) |
873 (1 << kLoadHoisting) |
874 (1 << kSuppressLoads) |
875 (1 << kNullCheckElimination) |
876 (1 << kPromoteRegs) |
877 (1 << kTrackLiveTemps) |
878 (1 << kSafeOptimizations) |
879 (1 << kBBOpt) |
880 (1 << kMatch) |
881 (1 << kPromoteCompilerTemps));
882 }
883
Dmitry Petrochenkoba279d92014-05-16 18:36:39 +0700884 if (cu.instruction_set == kArm64 || cu.instruction_set == kX86_64) {
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100885 // TODO(Arm64): enable optimizations once backend is mature enough.
Dmitry Petrochenkoba279d92014-05-16 18:36:39 +0700886 // TODO(X86_64): enable optimizations once backend is mature enough.
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100887 cu.disable_opt = ~(uint32_t)0;
buzbeeb01bf152014-05-13 15:59:07 -0700888 cu.enable_debug |= (1 << kDebugCodegenDump);
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100889 }
890
buzbeea61f4952013-08-23 14:27:06 -0700891 cu.StartTimingSplit("BuildMIRGraph");
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700892 cu.mir_graph.reset(new MIRGraph(&cu, &cu.arena));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700893
Razvan A Lupusoruda7a69b2014-01-08 15:09:50 -0800894 /*
895 * After creation of the MIR graph, also create the code generator.
896 * The reason we do this is that optimizations on the MIR graph may need to get information
897 * that is only available if a CG exists.
898 */
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000899 cu.cg.reset(compiler->GetCodeGenerator(&cu, llvm_compilation_unit));
Razvan A Lupusoruda7a69b2014-01-08 15:09:50 -0800900
Brian Carlstrom7940e442013-07-12 13:46:57 -0700901 /* Gathering opcode stats? */
902 if (kCompilerDebugFlags & (1 << kDebugCountOpcodes)) {
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700903 cu.mir_graph->EnableOpcodeCounting();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700904 }
905
Calin Juravlec1b643c2014-05-30 23:44:11 +0100906 // Check early if we should skip this compilation if the profiler is enabled.
Dave Allison39c3bfb2014-01-28 18:33:52 -0800907 if (cu.compiler_driver->ProfilePresent()) {
908 std::string methodname = PrettyMethod(method_idx, dex_file);
909 if (cu.mir_graph->SkipCompilation(methodname)) {
910 return NULL;
911 }
912 }
913
Brian Carlstrom7940e442013-07-12 13:46:57 -0700914 /* Build the raw MIR graph */
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700915 cu.mir_graph->InlineMethod(code_item, access_flags, invoke_type, class_def_idx, method_idx,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700916 class_loader, dex_file);
917
Zheng Xu9e06c8c2014-05-06 18:06:07 +0100918 // TODO(Arm64): Remove this when we are able to compile everything.
919 if (!CanCompileMethod(method_idx, dex_file, cu)) {
920 VLOG(compiler) << "Cannot compile method : " << PrettyMethod(method_idx, dex_file);
921 return nullptr;
922 }
923
buzbee1da1e2f2013-11-15 13:37:01 -0800924 cu.NewTimingSplit("MIROpt:CheckFilters");
Jeff Hao4a200f52014-04-01 14:58:49 -0700925 if (cu.mir_graph->SkipCompilation()) {
926 return NULL;
buzbeeee17e0a2013-07-31 10:47:37 -0700927 }
928
Jean Christophe Beyler4e97c532014-01-07 10:07:18 -0800929 /* Create the pass driver and launch it */
Jean Christophe Beyler2469e602014-05-06 20:36:55 -0700930 PassDriverMEOpts pass_driver(&cu);
Ian Rogers3d504072014-03-01 09:16:49 -0800931 pass_driver.Launch();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700932
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700933 if (cu.enable_debug & (1 << kDebugDumpCheckStats)) {
934 cu.mir_graph->DumpCheckStats();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700935 }
936
937 if (kCompilerDebugFlags & (1 << kDebugCountOpcodes)) {
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700938 cu.mir_graph->ShowOpcodeStats();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700939 }
940
buzbee1da1e2f2013-11-15 13:37:01 -0800941 /* Reassociate sreg names with original Dalvik vreg names. */
942 cu.mir_graph->RemapRegLocations();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700943
Vladimir Marko53b6afc2014-03-21 14:21:20 +0000944 /* Free Arenas from the cu.arena_stack for reuse by the cu.arena in the codegen. */
945 if (cu.enable_debug & (1 << kDebugShowMemoryUsage)) {
946 if (cu.arena_stack.PeakBytesAllocated() > 256 * 1024) {
947 MemStats stack_stats(cu.arena_stack.GetPeakStats());
948 LOG(INFO) << PrettyMethod(method_idx, dex_file) << " " << Dumpable<MemStats>(stack_stats);
949 }
950 }
951 cu.arena_stack.Reset();
952
Brian Carlstrom7940e442013-07-12 13:46:57 -0700953 CompiledMethod* result = NULL;
954
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700955 cu.cg->Materialize();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700956
buzbee1da1e2f2013-11-15 13:37:01 -0800957 cu.NewTimingSplit("Dedupe"); /* deduping takes up the vast majority of time in GetCompiledMethod(). */
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700958 result = cu.cg->GetCompiledMethod();
buzbee1da1e2f2013-11-15 13:37:01 -0800959 cu.NewTimingSplit("Cleanup");
Brian Carlstrom7940e442013-07-12 13:46:57 -0700960
961 if (result) {
962 VLOG(compiler) << "Compiled " << PrettyMethod(method_idx, dex_file);
963 } else {
964 VLOG(compiler) << "Deferred " << PrettyMethod(method_idx, dex_file);
965 }
966
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700967 if (cu.enable_debug & (1 << kDebugShowMemoryUsage)) {
Vladimir Marko53b6afc2014-03-21 14:21:20 +0000968 if (cu.arena.BytesAllocated() > (1 * 1024 *1024)) {
Vladimir Marko83cc7ae2014-02-12 18:02:05 +0000969 MemStats mem_stats(cu.arena.GetMemStats());
Vladimir Marko53b6afc2014-03-21 14:21:20 +0000970 LOG(INFO) << PrettyMethod(method_idx, dex_file) << " " << Dumpable<MemStats>(mem_stats);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700971 }
972 }
973
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700974 if (cu.enable_debug & (1 << kDebugShowSummaryMemoryUsage)) {
975 LOG(INFO) << "MEMINFO " << cu.arena.BytesAllocated() << " " << cu.mir_graph->GetNumBlocks()
Brian Carlstrom7940e442013-07-12 13:46:57 -0700976 << " " << PrettyMethod(method_idx, dex_file);
977 }
978
buzbeea61f4952013-08-23 14:27:06 -0700979 cu.EndTiming();
Ian Rogers3d504072014-03-01 09:16:49 -0800980 driver.GetTimingsLogger()->AddLogger(cu.timings);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700981 return result;
982}
983
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000984CompiledMethod* CompileOneMethod(CompilerDriver& driver,
985 Compiler* compiler,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700986 const DexFile::CodeItem* code_item,
987 uint32_t access_flags,
988 InvokeType invoke_type,
Ian Rogers8b2c0b92013-09-19 02:56:49 -0700989 uint16_t class_def_idx,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700990 uint32_t method_idx,
991 jobject class_loader,
992 const DexFile& dex_file,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000993 void* compilation_unit) {
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +0000994 return CompileMethod(driver, compiler, code_item, access_flags, invoke_type, class_def_idx,
Nicolas Geoffrayf5df8972014-02-14 18:37:08 +0000995 method_idx, class_loader, dex_file, compilation_unit);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700996}
997
998} // namespace art
999
1000extern "C" art::CompiledMethod*
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +00001001 ArtQuickCompileMethod(art::CompilerDriver& driver,
Brian Carlstrom7940e442013-07-12 13:46:57 -07001002 const art::DexFile::CodeItem* code_item,
1003 uint32_t access_flags, art::InvokeType invoke_type,
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001004 uint16_t class_def_idx, uint32_t method_idx, jobject class_loader,
Brian Carlstrom7940e442013-07-12 13:46:57 -07001005 const art::DexFile& dex_file) {
1006 // TODO: check method fingerprint here to determine appropriate backend type. Until then, use build default
Nicolas Geoffrayb34f69a2014-03-07 15:28:39 +00001007 art::Compiler* compiler = driver.GetCompiler();
1008 return art::CompileOneMethod(driver, compiler, code_item, access_flags, invoke_type,
Brian Carlstrom7940e442013-07-12 13:46:57 -07001009 class_def_idx, method_idx, class_loader, dex_file,
1010 NULL /* use thread llvm_info */);
1011}