blob: 027290f9b1bdf49f86cc65acd2dbc1338b8f2b5b [file] [log] [blame]
Andreas Gampe53c913b2014-08-12 23:19:23 -07001/*
2 * Copyright (C) 2014 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 "quick_compiler.h"
18
19#include <cstdint>
20
Mathieu Chartiere401d142015-04-22 13:56:20 -070021#include "art_method-inl.h"
Andreas Gampe0e92f4f2015-01-26 17:37:27 -080022#include "base/dumpable.h"
Andreas Gampe0b9203e2015-01-22 20:39:27 -080023#include "base/logging.h"
Andreas Gampe0e92f4f2015-01-26 17:37:27 -080024#include "base/macros.h"
25#include "base/timing_logger.h"
Andreas Gampe53c913b2014-08-12 23:19:23 -070026#include "compiler.h"
Elliott Hughes956af0f2014-12-11 14:34:28 -080027#include "dex_file-inl.h"
Andreas Gampe0e92f4f2015-01-26 17:37:27 -080028#include "dex_file_to_method_inliner_map.h"
Andreas Gampe0b9203e2015-01-22 20:39:27 -080029#include "dex/compiler_ir.h"
Andreas Gampe0e92f4f2015-01-26 17:37:27 -080030#include "dex/dex_flags.h"
Andreas Gampe53c913b2014-08-12 23:19:23 -070031#include "dex/mir_graph.h"
Andreas Gampe0e92f4f2015-01-26 17:37:27 -080032#include "dex/pass_driver_me_opts.h"
Mathieu Chartier5bdab122015-01-26 18:30:19 -080033#include "dex/pass_driver_me_post_opt.h"
34#include "dex/pass_manager.h"
Andreas Gampe53c913b2014-08-12 23:19:23 -070035#include "dex/quick/mir_to_lir.h"
Nicolas Geoffray4824c272015-06-24 15:53:03 +010036#include "dex/verified_method.h"
Andreas Gampe53c913b2014-08-12 23:19:23 -070037#include "driver/compiler_driver.h"
Andreas Gampe0e92f4f2015-01-26 17:37:27 -080038#include "driver/compiler_options.h"
Andreas Gampe53c913b2014-08-12 23:19:23 -070039#include "elf_writer_quick.h"
Alex Lighteb7c1442015-08-31 13:17:42 -070040#include "experimental_flags.h"
Andreas Gampe53c913b2014-08-12 23:19:23 -070041#include "jni/quick/jni_compiler.h"
Andreas Gampe9c462082015-01-27 14:31:40 -080042#include "mir_to_lir.h"
Andreas Gampe0e92f4f2015-01-26 17:37:27 -080043#include "mirror/object.h"
44#include "runtime.h"
Andreas Gampe53c913b2014-08-12 23:19:23 -070045
46// Specific compiler backends.
Alex Light50fa9932015-08-10 15:30:07 -070047#ifdef ART_ENABLE_CODEGEN_arm
Andreas Gampe53c913b2014-08-12 23:19:23 -070048#include "dex/quick/arm/backend_arm.h"
Alex Light50fa9932015-08-10 15:30:07 -070049#endif
50
51#ifdef ART_ENABLE_CODEGEN_arm64
Andreas Gampe53c913b2014-08-12 23:19:23 -070052#include "dex/quick/arm64/backend_arm64.h"
Alex Light50fa9932015-08-10 15:30:07 -070053#endif
54
55#if defined(ART_ENABLE_CODEGEN_mips) || defined(ART_ENABLE_CODEGEN_mips64)
Andreas Gampe53c913b2014-08-12 23:19:23 -070056#include "dex/quick/mips/backend_mips.h"
Alex Light50fa9932015-08-10 15:30:07 -070057#endif
58
59#if defined(ART_ENABLE_CODEGEN_x86) || defined(ART_ENABLE_CODEGEN_x86_64)
Andreas Gampe53c913b2014-08-12 23:19:23 -070060#include "dex/quick/x86/backend_x86.h"
Alex Light50fa9932015-08-10 15:30:07 -070061#endif
Andreas Gampe53c913b2014-08-12 23:19:23 -070062
63namespace art {
64
Andreas Gampe785d2f22014-11-03 22:57:30 -080065static_assert(0U == static_cast<size_t>(kNone), "kNone not 0");
66static_assert(1U == static_cast<size_t>(kArm), "kArm not 1");
67static_assert(2U == static_cast<size_t>(kArm64), "kArm64 not 2");
68static_assert(3U == static_cast<size_t>(kThumb2), "kThumb2 not 3");
69static_assert(4U == static_cast<size_t>(kX86), "kX86 not 4");
70static_assert(5U == static_cast<size_t>(kX86_64), "kX86_64 not 5");
71static_assert(6U == static_cast<size_t>(kMips), "kMips not 6");
72static_assert(7U == static_cast<size_t>(kMips64), "kMips64 not 7");
Andreas Gampe53c913b2014-08-12 23:19:23 -070073
74// Additional disabled optimizations (over generally disabled) per instruction set.
75static constexpr uint32_t kDisabledOptimizationsPerISA[] = {
76 // 0 = kNone.
77 ~0U,
78 // 1 = kArm, unused (will use kThumb2).
79 ~0U,
80 // 2 = kArm64.
81 0,
82 // 3 = kThumb2.
83 0,
84 // 4 = kX86.
85 (1 << kLoadStoreElimination) |
86 0,
87 // 5 = kX86_64.
88 (1 << kLoadStoreElimination) |
89 0,
90 // 6 = kMips.
91 (1 << kLoadStoreElimination) |
92 (1 << kLoadHoisting) |
93 (1 << kSuppressLoads) |
94 (1 << kNullCheckElimination) |
95 (1 << kPromoteRegs) |
96 (1 << kTrackLiveTemps) |
97 (1 << kSafeOptimizations) |
98 (1 << kBBOpt) |
99 (1 << kMatch) |
100 (1 << kPromoteCompilerTemps) |
101 0,
102 // 7 = kMips64.
Maja Gagic6ea651f2015-02-24 16:55:04 +0100103 (1 << kLoadStoreElimination) |
104 (1 << kLoadHoisting) |
105 (1 << kSuppressLoads) |
106 (1 << kNullCheckElimination) |
107 (1 << kPromoteRegs) |
108 (1 << kTrackLiveTemps) |
109 (1 << kSafeOptimizations) |
110 (1 << kBBOpt) |
111 (1 << kMatch) |
112 (1 << kPromoteCompilerTemps) |
113 0
Andreas Gampe53c913b2014-08-12 23:19:23 -0700114};
Andreas Gampe785d2f22014-11-03 22:57:30 -0800115static_assert(sizeof(kDisabledOptimizationsPerISA) == 8 * sizeof(uint32_t),
116 "kDisabledOpts unexpected");
Andreas Gampe53c913b2014-08-12 23:19:23 -0700117
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700118// Supported shorty types per instruction set. null means that all are available.
Andreas Gampe53c913b2014-08-12 23:19:23 -0700119// Z : boolean
120// B : byte
121// S : short
122// C : char
123// I : int
124// J : long
125// F : float
126// D : double
127// L : reference(object, array)
128// V : void
129static const char* kSupportedTypes[] = {
130 // 0 = kNone.
131 "",
132 // 1 = kArm, unused (will use kThumb2).
133 "",
134 // 2 = kArm64.
135 nullptr,
136 // 3 = kThumb2.
137 nullptr,
138 // 4 = kX86.
139 nullptr,
140 // 5 = kX86_64.
141 nullptr,
142 // 6 = kMips.
143 nullptr,
144 // 7 = kMips64.
Maja Gagic6ea651f2015-02-24 16:55:04 +0100145 nullptr
Andreas Gampe53c913b2014-08-12 23:19:23 -0700146};
Andreas Gampe785d2f22014-11-03 22:57:30 -0800147static_assert(sizeof(kSupportedTypes) == 8 * sizeof(char*), "kSupportedTypes unexpected");
Andreas Gampe53c913b2014-08-12 23:19:23 -0700148
149static int kAllOpcodes[] = {
150 Instruction::NOP,
151 Instruction::MOVE,
152 Instruction::MOVE_FROM16,
153 Instruction::MOVE_16,
154 Instruction::MOVE_WIDE,
155 Instruction::MOVE_WIDE_FROM16,
156 Instruction::MOVE_WIDE_16,
157 Instruction::MOVE_OBJECT,
158 Instruction::MOVE_OBJECT_FROM16,
159 Instruction::MOVE_OBJECT_16,
160 Instruction::MOVE_RESULT,
161 Instruction::MOVE_RESULT_WIDE,
162 Instruction::MOVE_RESULT_OBJECT,
163 Instruction::MOVE_EXCEPTION,
164 Instruction::RETURN_VOID,
165 Instruction::RETURN,
166 Instruction::RETURN_WIDE,
167 Instruction::RETURN_OBJECT,
168 Instruction::CONST_4,
169 Instruction::CONST_16,
170 Instruction::CONST,
171 Instruction::CONST_HIGH16,
172 Instruction::CONST_WIDE_16,
173 Instruction::CONST_WIDE_32,
174 Instruction::CONST_WIDE,
175 Instruction::CONST_WIDE_HIGH16,
176 Instruction::CONST_STRING,
177 Instruction::CONST_STRING_JUMBO,
178 Instruction::CONST_CLASS,
179 Instruction::MONITOR_ENTER,
180 Instruction::MONITOR_EXIT,
181 Instruction::CHECK_CAST,
182 Instruction::INSTANCE_OF,
183 Instruction::ARRAY_LENGTH,
184 Instruction::NEW_INSTANCE,
185 Instruction::NEW_ARRAY,
186 Instruction::FILLED_NEW_ARRAY,
187 Instruction::FILLED_NEW_ARRAY_RANGE,
188 Instruction::FILL_ARRAY_DATA,
189 Instruction::THROW,
190 Instruction::GOTO,
191 Instruction::GOTO_16,
192 Instruction::GOTO_32,
193 Instruction::PACKED_SWITCH,
194 Instruction::SPARSE_SWITCH,
195 Instruction::CMPL_FLOAT,
196 Instruction::CMPG_FLOAT,
197 Instruction::CMPL_DOUBLE,
198 Instruction::CMPG_DOUBLE,
199 Instruction::CMP_LONG,
200 Instruction::IF_EQ,
201 Instruction::IF_NE,
202 Instruction::IF_LT,
203 Instruction::IF_GE,
204 Instruction::IF_GT,
205 Instruction::IF_LE,
206 Instruction::IF_EQZ,
207 Instruction::IF_NEZ,
208 Instruction::IF_LTZ,
209 Instruction::IF_GEZ,
210 Instruction::IF_GTZ,
211 Instruction::IF_LEZ,
212 Instruction::UNUSED_3E,
213 Instruction::UNUSED_3F,
214 Instruction::UNUSED_40,
215 Instruction::UNUSED_41,
216 Instruction::UNUSED_42,
217 Instruction::UNUSED_43,
218 Instruction::AGET,
219 Instruction::AGET_WIDE,
220 Instruction::AGET_OBJECT,
221 Instruction::AGET_BOOLEAN,
222 Instruction::AGET_BYTE,
223 Instruction::AGET_CHAR,
224 Instruction::AGET_SHORT,
225 Instruction::APUT,
226 Instruction::APUT_WIDE,
227 Instruction::APUT_OBJECT,
228 Instruction::APUT_BOOLEAN,
229 Instruction::APUT_BYTE,
230 Instruction::APUT_CHAR,
231 Instruction::APUT_SHORT,
232 Instruction::IGET,
233 Instruction::IGET_WIDE,
234 Instruction::IGET_OBJECT,
235 Instruction::IGET_BOOLEAN,
236 Instruction::IGET_BYTE,
237 Instruction::IGET_CHAR,
238 Instruction::IGET_SHORT,
239 Instruction::IPUT,
240 Instruction::IPUT_WIDE,
241 Instruction::IPUT_OBJECT,
242 Instruction::IPUT_BOOLEAN,
243 Instruction::IPUT_BYTE,
244 Instruction::IPUT_CHAR,
245 Instruction::IPUT_SHORT,
246 Instruction::SGET,
247 Instruction::SGET_WIDE,
248 Instruction::SGET_OBJECT,
249 Instruction::SGET_BOOLEAN,
250 Instruction::SGET_BYTE,
251 Instruction::SGET_CHAR,
252 Instruction::SGET_SHORT,
253 Instruction::SPUT,
254 Instruction::SPUT_WIDE,
255 Instruction::SPUT_OBJECT,
256 Instruction::SPUT_BOOLEAN,
257 Instruction::SPUT_BYTE,
258 Instruction::SPUT_CHAR,
259 Instruction::SPUT_SHORT,
260 Instruction::INVOKE_VIRTUAL,
261 Instruction::INVOKE_SUPER,
262 Instruction::INVOKE_DIRECT,
263 Instruction::INVOKE_STATIC,
264 Instruction::INVOKE_INTERFACE,
Mathieu Chartierd7cbf8a2015-03-19 12:43:20 -0700265 Instruction::RETURN_VOID_NO_BARRIER,
Andreas Gampe53c913b2014-08-12 23:19:23 -0700266 Instruction::INVOKE_VIRTUAL_RANGE,
267 Instruction::INVOKE_SUPER_RANGE,
268 Instruction::INVOKE_DIRECT_RANGE,
269 Instruction::INVOKE_STATIC_RANGE,
270 Instruction::INVOKE_INTERFACE_RANGE,
271 Instruction::UNUSED_79,
272 Instruction::UNUSED_7A,
273 Instruction::NEG_INT,
274 Instruction::NOT_INT,
275 Instruction::NEG_LONG,
276 Instruction::NOT_LONG,
277 Instruction::NEG_FLOAT,
278 Instruction::NEG_DOUBLE,
279 Instruction::INT_TO_LONG,
280 Instruction::INT_TO_FLOAT,
281 Instruction::INT_TO_DOUBLE,
282 Instruction::LONG_TO_INT,
283 Instruction::LONG_TO_FLOAT,
284 Instruction::LONG_TO_DOUBLE,
285 Instruction::FLOAT_TO_INT,
286 Instruction::FLOAT_TO_LONG,
287 Instruction::FLOAT_TO_DOUBLE,
288 Instruction::DOUBLE_TO_INT,
289 Instruction::DOUBLE_TO_LONG,
290 Instruction::DOUBLE_TO_FLOAT,
291 Instruction::INT_TO_BYTE,
292 Instruction::INT_TO_CHAR,
293 Instruction::INT_TO_SHORT,
294 Instruction::ADD_INT,
295 Instruction::SUB_INT,
296 Instruction::MUL_INT,
297 Instruction::DIV_INT,
298 Instruction::REM_INT,
299 Instruction::AND_INT,
300 Instruction::OR_INT,
301 Instruction::XOR_INT,
302 Instruction::SHL_INT,
303 Instruction::SHR_INT,
304 Instruction::USHR_INT,
305 Instruction::ADD_LONG,
306 Instruction::SUB_LONG,
307 Instruction::MUL_LONG,
308 Instruction::DIV_LONG,
309 Instruction::REM_LONG,
310 Instruction::AND_LONG,
311 Instruction::OR_LONG,
312 Instruction::XOR_LONG,
313 Instruction::SHL_LONG,
314 Instruction::SHR_LONG,
315 Instruction::USHR_LONG,
316 Instruction::ADD_FLOAT,
317 Instruction::SUB_FLOAT,
318 Instruction::MUL_FLOAT,
319 Instruction::DIV_FLOAT,
320 Instruction::REM_FLOAT,
321 Instruction::ADD_DOUBLE,
322 Instruction::SUB_DOUBLE,
323 Instruction::MUL_DOUBLE,
324 Instruction::DIV_DOUBLE,
325 Instruction::REM_DOUBLE,
326 Instruction::ADD_INT_2ADDR,
327 Instruction::SUB_INT_2ADDR,
328 Instruction::MUL_INT_2ADDR,
329 Instruction::DIV_INT_2ADDR,
330 Instruction::REM_INT_2ADDR,
331 Instruction::AND_INT_2ADDR,
332 Instruction::OR_INT_2ADDR,
333 Instruction::XOR_INT_2ADDR,
334 Instruction::SHL_INT_2ADDR,
335 Instruction::SHR_INT_2ADDR,
336 Instruction::USHR_INT_2ADDR,
337 Instruction::ADD_LONG_2ADDR,
338 Instruction::SUB_LONG_2ADDR,
339 Instruction::MUL_LONG_2ADDR,
340 Instruction::DIV_LONG_2ADDR,
341 Instruction::REM_LONG_2ADDR,
342 Instruction::AND_LONG_2ADDR,
343 Instruction::OR_LONG_2ADDR,
344 Instruction::XOR_LONG_2ADDR,
345 Instruction::SHL_LONG_2ADDR,
346 Instruction::SHR_LONG_2ADDR,
347 Instruction::USHR_LONG_2ADDR,
348 Instruction::ADD_FLOAT_2ADDR,
349 Instruction::SUB_FLOAT_2ADDR,
350 Instruction::MUL_FLOAT_2ADDR,
351 Instruction::DIV_FLOAT_2ADDR,
352 Instruction::REM_FLOAT_2ADDR,
353 Instruction::ADD_DOUBLE_2ADDR,
354 Instruction::SUB_DOUBLE_2ADDR,
355 Instruction::MUL_DOUBLE_2ADDR,
356 Instruction::DIV_DOUBLE_2ADDR,
357 Instruction::REM_DOUBLE_2ADDR,
358 Instruction::ADD_INT_LIT16,
359 Instruction::RSUB_INT,
360 Instruction::MUL_INT_LIT16,
361 Instruction::DIV_INT_LIT16,
362 Instruction::REM_INT_LIT16,
363 Instruction::AND_INT_LIT16,
364 Instruction::OR_INT_LIT16,
365 Instruction::XOR_INT_LIT16,
366 Instruction::ADD_INT_LIT8,
367 Instruction::RSUB_INT_LIT8,
368 Instruction::MUL_INT_LIT8,
369 Instruction::DIV_INT_LIT8,
370 Instruction::REM_INT_LIT8,
371 Instruction::AND_INT_LIT8,
372 Instruction::OR_INT_LIT8,
373 Instruction::XOR_INT_LIT8,
374 Instruction::SHL_INT_LIT8,
375 Instruction::SHR_INT_LIT8,
376 Instruction::USHR_INT_LIT8,
377 Instruction::IGET_QUICK,
378 Instruction::IGET_WIDE_QUICK,
379 Instruction::IGET_OBJECT_QUICK,
380 Instruction::IPUT_QUICK,
381 Instruction::IPUT_WIDE_QUICK,
382 Instruction::IPUT_OBJECT_QUICK,
383 Instruction::INVOKE_VIRTUAL_QUICK,
384 Instruction::INVOKE_VIRTUAL_RANGE_QUICK,
Fred Shih37f05ef2014-07-16 18:38:08 -0700385 Instruction::IPUT_BOOLEAN_QUICK,
386 Instruction::IPUT_BYTE_QUICK,
387 Instruction::IPUT_CHAR_QUICK,
388 Instruction::IPUT_SHORT_QUICK,
Mathieu Chartierffc605c2014-12-10 10:35:44 -0800389 Instruction::IGET_BOOLEAN_QUICK,
390 Instruction::IGET_BYTE_QUICK,
391 Instruction::IGET_CHAR_QUICK,
392 Instruction::IGET_SHORT_QUICK,
Igor Murashkin158f35c2015-06-10 15:55:30 -0700393 Instruction::INVOKE_LAMBDA,
Andreas Gampe53c913b2014-08-12 23:19:23 -0700394 Instruction::UNUSED_F4,
Igor Murashkin6918bf12015-09-27 19:19:06 -0700395 Instruction::CAPTURE_VARIABLE,
Igor Murashkin158f35c2015-06-10 15:55:30 -0700396 Instruction::CREATE_LAMBDA,
Igor Murashkin6918bf12015-09-27 19:19:06 -0700397 Instruction::LIBERATE_VARIABLE,
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700398 Instruction::BOX_LAMBDA,
399 Instruction::UNBOX_LAMBDA,
Andreas Gampe53c913b2014-08-12 23:19:23 -0700400 Instruction::UNUSED_FA,
401 Instruction::UNUSED_FB,
402 Instruction::UNUSED_FC,
403 Instruction::UNUSED_FD,
404 Instruction::UNUSED_FE,
405 Instruction::UNUSED_FF,
406 // ----- ExtendedMIROpcode -----
407 kMirOpPhi,
408 kMirOpCopy,
409 kMirOpFusedCmplFloat,
410 kMirOpFusedCmpgFloat,
411 kMirOpFusedCmplDouble,
412 kMirOpFusedCmpgDouble,
413 kMirOpFusedCmpLong,
414 kMirOpNop,
415 kMirOpNullCheck,
416 kMirOpRangeCheck,
417 kMirOpDivZeroCheck,
418 kMirOpCheck,
Andreas Gampe53c913b2014-08-12 23:19:23 -0700419 kMirOpSelect,
420};
421
Zheng Xu5667fdb2014-10-23 18:29:55 +0800422static int kInvokeOpcodes[] = {
423 Instruction::INVOKE_VIRTUAL,
424 Instruction::INVOKE_SUPER,
425 Instruction::INVOKE_DIRECT,
426 Instruction::INVOKE_STATIC,
427 Instruction::INVOKE_INTERFACE,
428 Instruction::INVOKE_VIRTUAL_RANGE,
429 Instruction::INVOKE_SUPER_RANGE,
430 Instruction::INVOKE_DIRECT_RANGE,
431 Instruction::INVOKE_STATIC_RANGE,
432 Instruction::INVOKE_INTERFACE_RANGE,
433 Instruction::INVOKE_VIRTUAL_QUICK,
434 Instruction::INVOKE_VIRTUAL_RANGE_QUICK,
435};
436
Igor Murashkin158f35c2015-06-10 15:55:30 -0700437// TODO: Add support for lambda opcodes to the quick compiler.
438static const int kUnsupportedLambdaOpcodes[] = {
439 Instruction::INVOKE_LAMBDA,
440 Instruction::CREATE_LAMBDA,
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700441 Instruction::BOX_LAMBDA,
442 Instruction::UNBOX_LAMBDA,
Igor Murashkin158f35c2015-06-10 15:55:30 -0700443};
444
445// Unsupported opcodes. Null can be used when everything is supported. Size of the lists is
Andreas Gampe53c913b2014-08-12 23:19:23 -0700446// recorded below.
447static const int* kUnsupportedOpcodes[] = {
448 // 0 = kNone.
449 kAllOpcodes,
450 // 1 = kArm, unused (will use kThumb2).
451 kAllOpcodes,
452 // 2 = kArm64.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700453 kUnsupportedLambdaOpcodes,
Andreas Gampe53c913b2014-08-12 23:19:23 -0700454 // 3 = kThumb2.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700455 kUnsupportedLambdaOpcodes,
Andreas Gampe53c913b2014-08-12 23:19:23 -0700456 // 4 = kX86.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700457 kUnsupportedLambdaOpcodes,
Andreas Gampe53c913b2014-08-12 23:19:23 -0700458 // 5 = kX86_64.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700459 kUnsupportedLambdaOpcodes,
Andreas Gampe53c913b2014-08-12 23:19:23 -0700460 // 6 = kMips.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700461 kUnsupportedLambdaOpcodes,
Andreas Gampe53c913b2014-08-12 23:19:23 -0700462 // 7 = kMips64.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700463 kUnsupportedLambdaOpcodes,
Andreas Gampe53c913b2014-08-12 23:19:23 -0700464};
Andreas Gampe785d2f22014-11-03 22:57:30 -0800465static_assert(sizeof(kUnsupportedOpcodes) == 8 * sizeof(int*), "kUnsupportedOpcodes unexpected");
Andreas Gampe53c913b2014-08-12 23:19:23 -0700466
467// Size of the arrays stored above.
468static const size_t kUnsupportedOpcodesSize[] = {
469 // 0 = kNone.
470 arraysize(kAllOpcodes),
471 // 1 = kArm, unused (will use kThumb2).
472 arraysize(kAllOpcodes),
473 // 2 = kArm64.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700474 arraysize(kUnsupportedLambdaOpcodes),
Andreas Gampe53c913b2014-08-12 23:19:23 -0700475 // 3 = kThumb2.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700476 arraysize(kUnsupportedLambdaOpcodes),
Andreas Gampe53c913b2014-08-12 23:19:23 -0700477 // 4 = kX86.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700478 arraysize(kUnsupportedLambdaOpcodes),
Andreas Gampe53c913b2014-08-12 23:19:23 -0700479 // 5 = kX86_64.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700480 arraysize(kUnsupportedLambdaOpcodes),
Andreas Gampe53c913b2014-08-12 23:19:23 -0700481 // 6 = kMips.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700482 arraysize(kUnsupportedLambdaOpcodes),
Andreas Gampe53c913b2014-08-12 23:19:23 -0700483 // 7 = kMips64.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700484 arraysize(kUnsupportedLambdaOpcodes),
Andreas Gampe53c913b2014-08-12 23:19:23 -0700485};
Andreas Gampe785d2f22014-11-03 22:57:30 -0800486static_assert(sizeof(kUnsupportedOpcodesSize) == 8 * sizeof(size_t),
487 "kUnsupportedOpcodesSize unexpected");
Andreas Gampe53c913b2014-08-12 23:19:23 -0700488
489// The maximum amount of Dalvik register in a method for which we will start compiling. Tries to
490// avoid an abort when we need to manage more SSA registers than we can.
491static constexpr size_t kMaxAllowedDalvikRegisters = INT16_MAX / 2;
492
493static bool CanCompileShorty(const char* shorty, InstructionSet instruction_set) {
494 const char* supported_types = kSupportedTypes[instruction_set];
495 if (supported_types == nullptr) {
496 // Everything available.
497 return true;
498 }
499
500 uint32_t shorty_size = strlen(shorty);
501 CHECK_GE(shorty_size, 1u);
502
503 for (uint32_t i = 0; i < shorty_size; i++) {
504 if (strchr(supported_types, shorty[i]) == nullptr) {
505 return false;
506 }
507 }
508 return true;
Andreas Gampec8ccf682014-09-29 20:07:43 -0700509}
Andreas Gampe53c913b2014-08-12 23:19:23 -0700510
Alex Light705ad492015-09-21 11:36:30 -0700511bool QuickCompiler::CanCompileInstruction(const MIR* mir,
512 const DexFile& dex_file) const {
513 switch (mir->dalvikInsn.opcode) {
514 // Quick compiler won't support new instruction semantics to invoke-super into an interface
515 // method
516 case Instruction::INVOKE_SUPER: // Fall-through
517 case Instruction::INVOKE_SUPER_RANGE: {
518 DCHECK(mir->dalvikInsn.IsInvoke());
519 uint32_t invoke_method_idx = mir->dalvikInsn.vB;
520 const DexFile::MethodId& method_id = dex_file.GetMethodId(invoke_method_idx);
521 const DexFile::ClassDef* class_def = dex_file.FindClassDef(method_id.class_idx_);
522 // False if we are an interface i.e. !(java_access_flags & kAccInterface)
523 return class_def != nullptr && ((class_def->GetJavaAccessFlags() & kAccInterface) == 0);
524 }
525 default:
526 return true;
527 }
528}
529
Andreas Gampe53c913b2014-08-12 23:19:23 -0700530// Skip the method that we do not support currently.
Alex Light705ad492015-09-21 11:36:30 -0700531bool QuickCompiler::CanCompileMethod(uint32_t method_idx,
532 const DexFile& dex_file,
Andreas Gampe53c913b2014-08-12 23:19:23 -0700533 CompilationUnit* cu) const {
534 // This is a limitation in mir_graph. See MirGraph::SetNumSSARegs.
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700535 if (cu->mir_graph->GetNumOfCodeAndTempVRs() > kMaxAllowedDalvikRegisters) {
536 VLOG(compiler) << "Too many dalvik registers : " << cu->mir_graph->GetNumOfCodeAndTempVRs();
Andreas Gampe53c913b2014-08-12 23:19:23 -0700537 return false;
538 }
539
Neil Fuller9724c632016-01-07 15:42:47 +0000540 // Since the quick compiler doesn't (and never will) support default methods we always need to
541 // scan opcodes.
Andreas Gampe53c913b2014-08-12 23:19:23 -0700542
543 // Check if we can compile the prototype.
544 const char* shorty = dex_file.GetMethodShorty(dex_file.GetMethodId(method_idx));
545 if (!CanCompileShorty(shorty, cu->instruction_set)) {
546 VLOG(compiler) << "Unsupported shorty : " << shorty;
547 return false;
548 }
549
550 const int *unsupport_list = kUnsupportedOpcodes[cu->instruction_set];
551 int unsupport_list_size = kUnsupportedOpcodesSize[cu->instruction_set];
552
553 for (unsigned int idx = 0; idx < cu->mir_graph->GetNumBlocks(); idx++) {
554 BasicBlock* bb = cu->mir_graph->GetBasicBlock(idx);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700555 if (bb == nullptr) continue;
Andreas Gampe53c913b2014-08-12 23:19:23 -0700556 if (bb->block_type == kDead) continue;
557 for (MIR* mir = bb->first_mir_insn; mir != nullptr; mir = mir->next) {
558 int opcode = mir->dalvikInsn.opcode;
559 // Check if we support the byte code.
Zheng Xu5667fdb2014-10-23 18:29:55 +0800560 if (std::find(unsupport_list, unsupport_list + unsupport_list_size, opcode)
561 != unsupport_list + unsupport_list_size) {
Andreas Gampe53c913b2014-08-12 23:19:23 -0700562 if (!MIR::DecodedInstruction::IsPseudoMirOp(opcode)) {
563 VLOG(compiler) << "Unsupported dalvik byte code : "
564 << mir->dalvikInsn.opcode;
565 } else {
566 VLOG(compiler) << "Unsupported extended MIR opcode : "
567 << MIRGraph::extended_mir_op_names_[opcode - kMirOpFirst];
568 }
569 return false;
Alex Light705ad492015-09-21 11:36:30 -0700570 } else if (!CanCompileInstruction(mir, dex_file)) {
571 VLOG(compiler) << "Cannot compile dalvik opcode : " << mir->dalvikInsn.opcode;
572 return false;
Andreas Gampe53c913b2014-08-12 23:19:23 -0700573 }
574 // Check if it invokes a prototype that we cannot support.
Zheng Xu5667fdb2014-10-23 18:29:55 +0800575 if (std::find(kInvokeOpcodes, kInvokeOpcodes + arraysize(kInvokeOpcodes), opcode)
576 != kInvokeOpcodes + arraysize(kInvokeOpcodes)) {
Andreas Gampe53c913b2014-08-12 23:19:23 -0700577 uint32_t invoke_method_idx = mir->dalvikInsn.vB;
578 const char* invoke_method_shorty = dex_file.GetMethodShorty(
579 dex_file.GetMethodId(invoke_method_idx));
580 if (!CanCompileShorty(invoke_method_shorty, cu->instruction_set)) {
581 VLOG(compiler) << "Unsupported to invoke '"
582 << PrettyMethod(invoke_method_idx, dex_file)
583 << "' with shorty : " << invoke_method_shorty;
584 return false;
585 }
586 }
587 }
588 }
589 return true;
590}
591
592void QuickCompiler::InitCompilationUnit(CompilationUnit& cu) const {
593 // Disable optimizations according to instruction set.
594 cu.disable_opt |= kDisabledOptimizationsPerISA[cu.instruction_set];
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800595 if (Runtime::Current()->UseJit()) {
596 // Disable these optimizations for JIT until quickened byte codes are done being implemented.
597 // TODO: Find a cleaner way to do this.
598 cu.disable_opt |= 1u << kLocalValueNumbering;
599 }
Andreas Gampe53c913b2014-08-12 23:19:23 -0700600}
601
David Brazdilee690a32014-12-01 17:04:16 +0000602void QuickCompiler::Init() {
Andreas Gampe53c913b2014-08-12 23:19:23 -0700603 CHECK(GetCompilerDriver()->GetCompilerContext() == nullptr);
604}
605
606void QuickCompiler::UnInit() const {
607 CHECK(GetCompilerDriver()->GetCompilerContext() == nullptr);
608}
609
Andreas Gampe0e92f4f2015-01-26 17:37:27 -0800610/* Default optimizer/debug setting for the compiler. */
611static uint32_t kCompilerOptimizerDisableFlags = 0 | // Disable specific optimizations
612 // (1 << kLoadStoreElimination) |
613 // (1 << kLoadHoisting) |
614 // (1 << kSuppressLoads) |
615 // (1 << kNullCheckElimination) |
616 // (1 << kClassInitCheckElimination) |
617 // (1 << kGlobalValueNumbering) |
Vladimir Markoa5e69e82015-04-24 19:03:51 +0100618 // (1 << kGvnDeadCodeElimination) |
Andreas Gampe0e92f4f2015-01-26 17:37:27 -0800619 // (1 << kLocalValueNumbering) |
620 // (1 << kPromoteRegs) |
621 // (1 << kTrackLiveTemps) |
622 // (1 << kSafeOptimizations) |
623 // (1 << kBBOpt) |
624 // (1 << kSuspendCheckElimination) |
625 // (1 << kMatch) |
626 // (1 << kPromoteCompilerTemps) |
627 // (1 << kSuppressExceptionEdges) |
628 // (1 << kSuppressMethodInlining) |
629 0;
630
631static uint32_t kCompilerDebugFlags = 0 | // Enable debug/testing modes
632 // (1 << kDebugDisplayMissingTargets) |
633 // (1 << kDebugVerbose) |
634 // (1 << kDebugDumpCFG) |
635 // (1 << kDebugSlowFieldPath) |
636 // (1 << kDebugSlowInvokePath) |
637 // (1 << kDebugSlowStringPath) |
638 // (1 << kDebugSlowestFieldPath) |
639 // (1 << kDebugSlowestStringPath) |
640 // (1 << kDebugExerciseResolveMethod) |
641 // (1 << kDebugVerifyDataflow) |
642 // (1 << kDebugShowMemoryUsage) |
643 // (1 << kDebugShowNops) |
644 // (1 << kDebugCountOpcodes) |
645 // (1 << kDebugDumpCheckStats) |
646 // (1 << kDebugShowSummaryMemoryUsage) |
647 // (1 << kDebugShowFilterStats) |
648 // (1 << kDebugTimings) |
649 // (1 << kDebugCodegenDump) |
650 0;
651
Andreas Gampe53c913b2014-08-12 23:19:23 -0700652CompiledMethod* QuickCompiler::Compile(const DexFile::CodeItem* code_item,
653 uint32_t access_flags,
654 InvokeType invoke_type,
655 uint16_t class_def_idx,
656 uint32_t method_idx,
657 jobject class_loader,
Mathieu Chartier736b5602015-09-02 14:54:11 -0700658 const DexFile& dex_file,
659 Handle<mirror::DexCache> dex_cache) const {
Roland Levillain4d027112015-07-01 15:41:14 +0100660 if (kPoisonHeapReferences) {
661 VLOG(compiler) << "Skipping method : " << PrettyMethod(method_idx, dex_file)
662 << " Reason = Quick does not support heap poisoning.";
663 return nullptr;
664 }
665
Roland Levillain0d5a2812015-11-13 10:07:31 +0000666 if (kEmitCompilerReadBarrier) {
667 VLOG(compiler) << "Skipping method : " << PrettyMethod(method_idx, dex_file)
668 << " Reason = Quick does not support read barrier.";
669 return nullptr;
670 }
671
Andreas Gampe53c913b2014-08-12 23:19:23 -0700672 // TODO: check method fingerprint here to determine appropriate backend type. Until then, use
673 // build default.
674 CompilerDriver* driver = GetCompilerDriver();
Andreas Gampe0e92f4f2015-01-26 17:37:27 -0800675
676 VLOG(compiler) << "Compiling " << PrettyMethod(method_idx, dex_file) << "...";
677 if (Compiler::IsPathologicalCase(*code_item, method_idx, dex_file)) {
678 return nullptr;
679 }
680
681 DCHECK(driver->GetCompilerOptions().IsCompilationEnabled());
Andreas Gampe0760a812015-08-26 17:12:51 -0700682 DCHECK(!driver->GetVerifiedMethod(&dex_file, method_idx)->HasRuntimeThrow());
Andreas Gampe0e92f4f2015-01-26 17:37:27 -0800683
Mathieu Chartier9b34b242015-03-09 11:30:17 -0700684 Runtime* const runtime = Runtime::Current();
685 ClassLinker* const class_linker = runtime->GetClassLinker();
Andreas Gampe0e92f4f2015-01-26 17:37:27 -0800686 InstructionSet instruction_set = driver->GetInstructionSet();
687 if (instruction_set == kArm) {
688 instruction_set = kThumb2;
689 }
Mathieu Chartier9b34b242015-03-09 11:30:17 -0700690 CompilationUnit cu(runtime->GetArenaPool(), instruction_set, driver, class_linker);
Vladimir Marko20f85592015-03-19 10:07:02 +0000691 cu.dex_file = &dex_file;
692 cu.class_def_idx = class_def_idx;
693 cu.method_idx = method_idx;
694 cu.access_flags = access_flags;
695 cu.invoke_type = invoke_type;
696 cu.shorty = dex_file.GetMethodShorty(dex_file.GetMethodId(method_idx));
Andreas Gampe0e92f4f2015-01-26 17:37:27 -0800697
Andreas Gampe0e92f4f2015-01-26 17:37:27 -0800698 CHECK((cu.instruction_set == kThumb2) ||
699 (cu.instruction_set == kArm64) ||
700 (cu.instruction_set == kX86) ||
701 (cu.instruction_set == kX86_64) ||
Maja Gagic6ea651f2015-02-24 16:55:04 +0100702 (cu.instruction_set == kMips) ||
703 (cu.instruction_set == kMips64));
Andreas Gampe0e92f4f2015-01-26 17:37:27 -0800704
705 // TODO: set this from command line
706 constexpr bool compiler_flip_match = false;
707 const std::string compiler_method_match = "";
708
709 bool use_match = !compiler_method_match.empty();
710 bool match = use_match && (compiler_flip_match ^
711 (PrettyMethod(method_idx, dex_file).find(compiler_method_match) != std::string::npos));
712 if (!use_match || match) {
713 cu.disable_opt = kCompilerOptimizerDisableFlags;
714 cu.enable_debug = kCompilerDebugFlags;
715 cu.verbose = VLOG_IS_ON(compiler) ||
716 (cu.enable_debug & (1 << kDebugVerbose));
717 }
718
719 if (driver->GetCompilerOptions().HasVerboseMethods()) {
720 cu.verbose = driver->GetCompilerOptions().IsVerboseMethod(PrettyMethod(method_idx, dex_file));
721 }
722
723 if (cu.verbose) {
724 cu.enable_debug |= (1 << kDebugCodegenDump);
725 }
726
727 /*
728 * TODO: rework handling of optimization and debug flags. Should we split out
729 * MIR and backend flags? Need command-line setting as well.
730 */
731
732 InitCompilationUnit(cu);
733
734 cu.StartTimingSplit("BuildMIRGraph");
735 cu.mir_graph.reset(new MIRGraph(&cu, &cu.arena));
736
737 /*
738 * After creation of the MIR graph, also create the code generator.
739 * The reason we do this is that optimizations on the MIR graph may need to get information
740 * that is only available if a CG exists.
741 */
742 cu.cg.reset(GetCodeGenerator(&cu, nullptr));
743
744 /* Gathering opcode stats? */
745 if (kCompilerDebugFlags & (1 << kDebugCountOpcodes)) {
746 cu.mir_graph->EnableOpcodeCounting();
747 }
748
749 /* Build the raw MIR graph */
750 cu.mir_graph->InlineMethod(code_item, access_flags, invoke_type, class_def_idx, method_idx,
Mathieu Chartier736b5602015-09-02 14:54:11 -0700751 class_loader, dex_file, dex_cache);
Andreas Gampe0e92f4f2015-01-26 17:37:27 -0800752
753 if (!CanCompileMethod(method_idx, dex_file, &cu)) {
754 VLOG(compiler) << cu.instruction_set << ": Cannot compile method : "
755 << PrettyMethod(method_idx, dex_file);
756 cu.EndTiming();
757 return nullptr;
758 }
759
760 cu.NewTimingSplit("MIROpt:CheckFilters");
761 std::string skip_message;
762 if (cu.mir_graph->SkipCompilation(&skip_message)) {
763 VLOG(compiler) << cu.instruction_set << ": Skipping method : "
764 << PrettyMethod(method_idx, dex_file) << " Reason = " << skip_message;
765 cu.EndTiming();
766 return nullptr;
767 }
768
769 /* Create the pass driver and launch it */
Nicolas Geoffray216eaa22015-03-17 17:09:30 +0000770 PassDriverMEOpts pass_driver(GetPreOptPassManager(), GetPostOptPassManager(), &cu);
Andreas Gampe0e92f4f2015-01-26 17:37:27 -0800771 pass_driver.Launch();
772
Andreas Gampe0e92f4f2015-01-26 17:37:27 -0800773 if (cu.enable_debug & (1 << kDebugDumpCheckStats)) {
774 cu.mir_graph->DumpCheckStats();
775 }
776
777 if (kCompilerDebugFlags & (1 << kDebugCountOpcodes)) {
778 cu.mir_graph->ShowOpcodeStats();
779 }
780
781 /* Reassociate sreg names with original Dalvik vreg names. */
782 cu.mir_graph->RemapRegLocations();
783
784 /* Free Arenas from the cu.arena_stack for reuse by the cu.arena in the codegen. */
785 if (cu.enable_debug & (1 << kDebugShowMemoryUsage)) {
786 if (cu.arena_stack.PeakBytesAllocated() > 1 * 1024 * 1024) {
787 MemStats stack_stats(cu.arena_stack.GetPeakStats());
788 LOG(INFO) << PrettyMethod(method_idx, dex_file) << " " << Dumpable<MemStats>(stack_stats);
789 }
790 }
791 cu.arena_stack.Reset();
792
793 CompiledMethod* result = nullptr;
794
795 if (cu.mir_graph->PuntToInterpreter()) {
796 VLOG(compiler) << cu.instruction_set << ": Punted method to interpreter: "
797 << PrettyMethod(method_idx, dex_file);
798 cu.EndTiming();
799 return nullptr;
800 }
801
802 cu.cg->Materialize();
803
804 cu.NewTimingSplit("Dedupe"); /* deduping takes up the vast majority of time in GetCompiledMethod(). */
805 result = cu.cg->GetCompiledMethod();
806 cu.NewTimingSplit("Cleanup");
807
808 if (result) {
809 VLOG(compiler) << cu.instruction_set << ": Compiled " << PrettyMethod(method_idx, dex_file);
810 } else {
811 VLOG(compiler) << cu.instruction_set << ": Deferred " << PrettyMethod(method_idx, dex_file);
812 }
813
814 if (cu.enable_debug & (1 << kDebugShowMemoryUsage)) {
815 if (cu.arena.BytesAllocated() > (1 * 1024 *1024)) {
816 MemStats mem_stats(cu.arena.GetMemStats());
817 LOG(INFO) << PrettyMethod(method_idx, dex_file) << " " << Dumpable<MemStats>(mem_stats);
818 }
819 }
820
821 if (cu.enable_debug & (1 << kDebugShowSummaryMemoryUsage)) {
822 LOG(INFO) << "MEMINFO " << cu.arena.BytesAllocated() << " " << cu.mir_graph->GetNumBlocks()
823 << " " << PrettyMethod(method_idx, dex_file);
824 }
825
826 cu.EndTiming();
827 driver->GetTimingsLogger()->AddLogger(cu.timings);
828 return result;
Andreas Gampe53c913b2014-08-12 23:19:23 -0700829}
830
831CompiledMethod* QuickCompiler::JniCompile(uint32_t access_flags,
832 uint32_t method_idx,
833 const DexFile& dex_file) const {
834 return ArtQuickJniCompileMethod(GetCompilerDriver(), access_flags, method_idx, dex_file);
835}
836
Mathieu Chartiere401d142015-04-22 13:56:20 -0700837uintptr_t QuickCompiler::GetEntryPointOf(ArtMethod* method) const {
Mathieu Chartier130914e2014-11-18 15:34:09 -0800838 return reinterpret_cast<uintptr_t>(method->GetEntryPointFromQuickCompiledCodePtrSize(
839 InstructionSetPointerSize(GetCompilerDriver()->GetInstructionSet())));
Andreas Gampe53c913b2014-08-12 23:19:23 -0700840}
841
Roland Levillain4b8f1ec2015-08-26 18:34:03 +0100842Mir2Lir* QuickCompiler::GetCodeGenerator(CompilationUnit* cu,
843 void* compilation_unit ATTRIBUTE_UNUSED) {
Andreas Gampe53c913b2014-08-12 23:19:23 -0700844 Mir2Lir* mir_to_lir = nullptr;
845 switch (cu->instruction_set) {
Alex Light50fa9932015-08-10 15:30:07 -0700846#ifdef ART_ENABLE_CODEGEN_arm
Andreas Gampe53c913b2014-08-12 23:19:23 -0700847 case kThumb2:
848 mir_to_lir = ArmCodeGenerator(cu, cu->mir_graph.get(), &cu->arena);
849 break;
Alex Light50fa9932015-08-10 15:30:07 -0700850#endif // ART_ENABLE_CODEGEN_arm
851#ifdef ART_ENABLE_CODEGEN_arm64
Andreas Gampe53c913b2014-08-12 23:19:23 -0700852 case kArm64:
853 mir_to_lir = Arm64CodeGenerator(cu, cu->mir_graph.get(), &cu->arena);
854 break;
Alex Light50fa9932015-08-10 15:30:07 -0700855#endif // ART_ENABLE_CODEGEN_arm64
856#if defined(ART_ENABLE_CODEGEN_mips) || defined(ART_ENABLE_CODEGEN_mips64)
857 // Intentional 2 level ifdef. Want to fail on mips64 if it is not enabled, even if mips is
858 // and vice versa.
859#ifdef ART_ENABLE_CODEGEN_mips
Andreas Gampe53c913b2014-08-12 23:19:23 -0700860 case kMips:
Goran Jakovljevic10957932015-03-24 18:42:56 +0100861 // Fall-through.
Alex Light50fa9932015-08-10 15:30:07 -0700862#endif // ART_ENABLE_CODEGEN_mips
863#ifdef ART_ENABLE_CODEGEN_mips64
Maja Gagic6ea651f2015-02-24 16:55:04 +0100864 case kMips64:
Alex Light50fa9932015-08-10 15:30:07 -0700865#endif // ART_ENABLE_CODEGEN_mips64
Goran Jakovljevic10957932015-03-24 18:42:56 +0100866 mir_to_lir = MipsCodeGenerator(cu, cu->mir_graph.get(), &cu->arena);
Maja Gagic6ea651f2015-02-24 16:55:04 +0100867 break;
Alex Light50fa9932015-08-10 15:30:07 -0700868#endif // ART_ENABLE_CODEGEN_mips || ART_ENABLE_CODEGEN_mips64
869#if defined(ART_ENABLE_CODEGEN_x86) || defined(ART_ENABLE_CODEGEN_x86_64)
870 // Intentional 2 level ifdef. Want to fail on x86_64 if it is not enabled, even if x86 is
871 // and vice versa.
872#ifdef ART_ENABLE_CODEGEN_x86
Andreas Gampe53c913b2014-08-12 23:19:23 -0700873 case kX86:
874 // Fall-through.
Alex Light50fa9932015-08-10 15:30:07 -0700875#endif // ART_ENABLE_CODEGEN_x86
876#ifdef ART_ENABLE_CODEGEN_x86_64
Andreas Gampe53c913b2014-08-12 23:19:23 -0700877 case kX86_64:
Alex Light50fa9932015-08-10 15:30:07 -0700878#endif // ART_ENABLE_CODEGEN_x86_64
Andreas Gampe53c913b2014-08-12 23:19:23 -0700879 mir_to_lir = X86CodeGenerator(cu, cu->mir_graph.get(), &cu->arena);
880 break;
Alex Light50fa9932015-08-10 15:30:07 -0700881#endif // ART_ENABLE_CODEGEN_x86 || ART_ENABLE_CODEGEN_x86_64
Andreas Gampe53c913b2014-08-12 23:19:23 -0700882 default:
883 LOG(FATAL) << "Unexpected instruction set: " << cu->instruction_set;
884 }
885
886 /* The number of compiler temporaries depends on backend so set it up now if possible */
887 if (mir_to_lir) {
888 size_t max_temps = mir_to_lir->GetMaxPossibleCompilerTemps();
889 bool set_max = cu->mir_graph->SetMaxAvailableNonSpecialCompilerTemps(max_temps);
890 CHECK(set_max);
891 }
892 return mir_to_lir;
893}
894
Mathieu Chartier5bdab122015-01-26 18:30:19 -0800895QuickCompiler::QuickCompiler(CompilerDriver* driver) : Compiler(driver, 100) {
896 const auto& compiler_options = driver->GetCompilerOptions();
897 auto* pass_manager_options = compiler_options.GetPassManagerOptions();
898 pre_opt_pass_manager_.reset(new PassManager(*pass_manager_options));
899 CHECK(pre_opt_pass_manager_.get() != nullptr);
900 PassDriverMEOpts::SetupPasses(pre_opt_pass_manager_.get());
901 pre_opt_pass_manager_->CreateDefaultPassList();
902 if (pass_manager_options->GetPrintPassOptions()) {
903 PassDriverMEOpts::PrintPassOptions(pre_opt_pass_manager_.get());
904 }
905 // TODO: Different options for pre vs post opts?
906 post_opt_pass_manager_.reset(new PassManager(PassManagerOptions()));
907 CHECK(post_opt_pass_manager_.get() != nullptr);
908 PassDriverMEPostOpt::SetupPasses(post_opt_pass_manager_.get());
909 post_opt_pass_manager_->CreateDefaultPassList();
910 if (pass_manager_options->GetPrintPassOptions()) {
911 PassDriverMEPostOpt::PrintPassOptions(post_opt_pass_manager_.get());
912 }
913}
914
915QuickCompiler::~QuickCompiler() {
916}
Andreas Gampe53c913b2014-08-12 23:19:23 -0700917
918Compiler* CreateQuickCompiler(CompilerDriver* driver) {
Mathieu Chartier5bdab122015-01-26 18:30:19 -0800919 return QuickCompiler::Create(driver);
920}
921
922Compiler* QuickCompiler::Create(CompilerDriver* driver) {
Andreas Gampe53c913b2014-08-12 23:19:23 -0700923 return new QuickCompiler(driver);
924}
925
926} // namespace art