blob: 3642b8236a3d91d93054606f668cceeec07532e7 [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"
40#include "jni/quick/jni_compiler.h"
Andreas Gampe9c462082015-01-27 14:31:40 -080041#include "mir_to_lir.h"
Andreas Gampe0e92f4f2015-01-26 17:37:27 -080042#include "mirror/object.h"
43#include "runtime.h"
Andreas Gampe53c913b2014-08-12 23:19:23 -070044
45// Specific compiler backends.
Alex Light50fa9932015-08-10 15:30:07 -070046#ifdef ART_ENABLE_CODEGEN_arm
Andreas Gampe53c913b2014-08-12 23:19:23 -070047#include "dex/quick/arm/backend_arm.h"
Alex Light50fa9932015-08-10 15:30:07 -070048#endif
49
50#ifdef ART_ENABLE_CODEGEN_arm64
Andreas Gampe53c913b2014-08-12 23:19:23 -070051#include "dex/quick/arm64/backend_arm64.h"
Alex Light50fa9932015-08-10 15:30:07 -070052#endif
53
54#if defined(ART_ENABLE_CODEGEN_mips) || defined(ART_ENABLE_CODEGEN_mips64)
Andreas Gampe53c913b2014-08-12 23:19:23 -070055#include "dex/quick/mips/backend_mips.h"
Alex Light50fa9932015-08-10 15:30:07 -070056#endif
57
58#if defined(ART_ENABLE_CODEGEN_x86) || defined(ART_ENABLE_CODEGEN_x86_64)
Andreas Gampe53c913b2014-08-12 23:19:23 -070059#include "dex/quick/x86/backend_x86.h"
Alex Light50fa9932015-08-10 15:30:07 -070060#endif
Andreas Gampe53c913b2014-08-12 23:19:23 -070061
62namespace art {
63
Andreas Gampe785d2f22014-11-03 22:57:30 -080064static_assert(0U == static_cast<size_t>(kNone), "kNone not 0");
65static_assert(1U == static_cast<size_t>(kArm), "kArm not 1");
66static_assert(2U == static_cast<size_t>(kArm64), "kArm64 not 2");
67static_assert(3U == static_cast<size_t>(kThumb2), "kThumb2 not 3");
68static_assert(4U == static_cast<size_t>(kX86), "kX86 not 4");
69static_assert(5U == static_cast<size_t>(kX86_64), "kX86_64 not 5");
70static_assert(6U == static_cast<size_t>(kMips), "kMips not 6");
71static_assert(7U == static_cast<size_t>(kMips64), "kMips64 not 7");
Andreas Gampe53c913b2014-08-12 23:19:23 -070072
73// Additional disabled optimizations (over generally disabled) per instruction set.
74static constexpr uint32_t kDisabledOptimizationsPerISA[] = {
75 // 0 = kNone.
76 ~0U,
77 // 1 = kArm, unused (will use kThumb2).
78 ~0U,
79 // 2 = kArm64.
80 0,
81 // 3 = kThumb2.
82 0,
83 // 4 = kX86.
84 (1 << kLoadStoreElimination) |
85 0,
86 // 5 = kX86_64.
87 (1 << kLoadStoreElimination) |
88 0,
89 // 6 = kMips.
90 (1 << kLoadStoreElimination) |
91 (1 << kLoadHoisting) |
92 (1 << kSuppressLoads) |
93 (1 << kNullCheckElimination) |
94 (1 << kPromoteRegs) |
95 (1 << kTrackLiveTemps) |
96 (1 << kSafeOptimizations) |
97 (1 << kBBOpt) |
98 (1 << kMatch) |
99 (1 << kPromoteCompilerTemps) |
100 0,
101 // 7 = kMips64.
Maja Gagic6ea651f2015-02-24 16:55:04 +0100102 (1 << kLoadStoreElimination) |
103 (1 << kLoadHoisting) |
104 (1 << kSuppressLoads) |
105 (1 << kNullCheckElimination) |
106 (1 << kPromoteRegs) |
107 (1 << kTrackLiveTemps) |
108 (1 << kSafeOptimizations) |
109 (1 << kBBOpt) |
110 (1 << kMatch) |
111 (1 << kPromoteCompilerTemps) |
112 0
Andreas Gampe53c913b2014-08-12 23:19:23 -0700113};
Andreas Gampe785d2f22014-11-03 22:57:30 -0800114static_assert(sizeof(kDisabledOptimizationsPerISA) == 8 * sizeof(uint32_t),
115 "kDisabledOpts unexpected");
Andreas Gampe53c913b2014-08-12 23:19:23 -0700116
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700117// Supported shorty types per instruction set. null means that all are available.
Andreas Gampe53c913b2014-08-12 23:19:23 -0700118// Z : boolean
119// B : byte
120// S : short
121// C : char
122// I : int
123// J : long
124// F : float
125// D : double
126// L : reference(object, array)
127// V : void
128static const char* kSupportedTypes[] = {
129 // 0 = kNone.
130 "",
131 // 1 = kArm, unused (will use kThumb2).
132 "",
133 // 2 = kArm64.
134 nullptr,
135 // 3 = kThumb2.
136 nullptr,
137 // 4 = kX86.
138 nullptr,
139 // 5 = kX86_64.
140 nullptr,
141 // 6 = kMips.
142 nullptr,
143 // 7 = kMips64.
Maja Gagic6ea651f2015-02-24 16:55:04 +0100144 nullptr
Andreas Gampe53c913b2014-08-12 23:19:23 -0700145};
Andreas Gampe785d2f22014-11-03 22:57:30 -0800146static_assert(sizeof(kSupportedTypes) == 8 * sizeof(char*), "kSupportedTypes unexpected");
Andreas Gampe53c913b2014-08-12 23:19:23 -0700147
148static int kAllOpcodes[] = {
149 Instruction::NOP,
150 Instruction::MOVE,
151 Instruction::MOVE_FROM16,
152 Instruction::MOVE_16,
153 Instruction::MOVE_WIDE,
154 Instruction::MOVE_WIDE_FROM16,
155 Instruction::MOVE_WIDE_16,
156 Instruction::MOVE_OBJECT,
157 Instruction::MOVE_OBJECT_FROM16,
158 Instruction::MOVE_OBJECT_16,
159 Instruction::MOVE_RESULT,
160 Instruction::MOVE_RESULT_WIDE,
161 Instruction::MOVE_RESULT_OBJECT,
162 Instruction::MOVE_EXCEPTION,
163 Instruction::RETURN_VOID,
164 Instruction::RETURN,
165 Instruction::RETURN_WIDE,
166 Instruction::RETURN_OBJECT,
167 Instruction::CONST_4,
168 Instruction::CONST_16,
169 Instruction::CONST,
170 Instruction::CONST_HIGH16,
171 Instruction::CONST_WIDE_16,
172 Instruction::CONST_WIDE_32,
173 Instruction::CONST_WIDE,
174 Instruction::CONST_WIDE_HIGH16,
175 Instruction::CONST_STRING,
176 Instruction::CONST_STRING_JUMBO,
177 Instruction::CONST_CLASS,
178 Instruction::MONITOR_ENTER,
179 Instruction::MONITOR_EXIT,
180 Instruction::CHECK_CAST,
181 Instruction::INSTANCE_OF,
182 Instruction::ARRAY_LENGTH,
183 Instruction::NEW_INSTANCE,
184 Instruction::NEW_ARRAY,
185 Instruction::FILLED_NEW_ARRAY,
186 Instruction::FILLED_NEW_ARRAY_RANGE,
187 Instruction::FILL_ARRAY_DATA,
188 Instruction::THROW,
189 Instruction::GOTO,
190 Instruction::GOTO_16,
191 Instruction::GOTO_32,
192 Instruction::PACKED_SWITCH,
193 Instruction::SPARSE_SWITCH,
194 Instruction::CMPL_FLOAT,
195 Instruction::CMPG_FLOAT,
196 Instruction::CMPL_DOUBLE,
197 Instruction::CMPG_DOUBLE,
198 Instruction::CMP_LONG,
199 Instruction::IF_EQ,
200 Instruction::IF_NE,
201 Instruction::IF_LT,
202 Instruction::IF_GE,
203 Instruction::IF_GT,
204 Instruction::IF_LE,
205 Instruction::IF_EQZ,
206 Instruction::IF_NEZ,
207 Instruction::IF_LTZ,
208 Instruction::IF_GEZ,
209 Instruction::IF_GTZ,
210 Instruction::IF_LEZ,
211 Instruction::UNUSED_3E,
212 Instruction::UNUSED_3F,
213 Instruction::UNUSED_40,
214 Instruction::UNUSED_41,
215 Instruction::UNUSED_42,
216 Instruction::UNUSED_43,
217 Instruction::AGET,
218 Instruction::AGET_WIDE,
219 Instruction::AGET_OBJECT,
220 Instruction::AGET_BOOLEAN,
221 Instruction::AGET_BYTE,
222 Instruction::AGET_CHAR,
223 Instruction::AGET_SHORT,
224 Instruction::APUT,
225 Instruction::APUT_WIDE,
226 Instruction::APUT_OBJECT,
227 Instruction::APUT_BOOLEAN,
228 Instruction::APUT_BYTE,
229 Instruction::APUT_CHAR,
230 Instruction::APUT_SHORT,
231 Instruction::IGET,
232 Instruction::IGET_WIDE,
233 Instruction::IGET_OBJECT,
234 Instruction::IGET_BOOLEAN,
235 Instruction::IGET_BYTE,
236 Instruction::IGET_CHAR,
237 Instruction::IGET_SHORT,
238 Instruction::IPUT,
239 Instruction::IPUT_WIDE,
240 Instruction::IPUT_OBJECT,
241 Instruction::IPUT_BOOLEAN,
242 Instruction::IPUT_BYTE,
243 Instruction::IPUT_CHAR,
244 Instruction::IPUT_SHORT,
245 Instruction::SGET,
246 Instruction::SGET_WIDE,
247 Instruction::SGET_OBJECT,
248 Instruction::SGET_BOOLEAN,
249 Instruction::SGET_BYTE,
250 Instruction::SGET_CHAR,
251 Instruction::SGET_SHORT,
252 Instruction::SPUT,
253 Instruction::SPUT_WIDE,
254 Instruction::SPUT_OBJECT,
255 Instruction::SPUT_BOOLEAN,
256 Instruction::SPUT_BYTE,
257 Instruction::SPUT_CHAR,
258 Instruction::SPUT_SHORT,
259 Instruction::INVOKE_VIRTUAL,
260 Instruction::INVOKE_SUPER,
261 Instruction::INVOKE_DIRECT,
262 Instruction::INVOKE_STATIC,
263 Instruction::INVOKE_INTERFACE,
Mathieu Chartierd7cbf8a2015-03-19 12:43:20 -0700264 Instruction::RETURN_VOID_NO_BARRIER,
Andreas Gampe53c913b2014-08-12 23:19:23 -0700265 Instruction::INVOKE_VIRTUAL_RANGE,
266 Instruction::INVOKE_SUPER_RANGE,
267 Instruction::INVOKE_DIRECT_RANGE,
268 Instruction::INVOKE_STATIC_RANGE,
269 Instruction::INVOKE_INTERFACE_RANGE,
270 Instruction::UNUSED_79,
271 Instruction::UNUSED_7A,
272 Instruction::NEG_INT,
273 Instruction::NOT_INT,
274 Instruction::NEG_LONG,
275 Instruction::NOT_LONG,
276 Instruction::NEG_FLOAT,
277 Instruction::NEG_DOUBLE,
278 Instruction::INT_TO_LONG,
279 Instruction::INT_TO_FLOAT,
280 Instruction::INT_TO_DOUBLE,
281 Instruction::LONG_TO_INT,
282 Instruction::LONG_TO_FLOAT,
283 Instruction::LONG_TO_DOUBLE,
284 Instruction::FLOAT_TO_INT,
285 Instruction::FLOAT_TO_LONG,
286 Instruction::FLOAT_TO_DOUBLE,
287 Instruction::DOUBLE_TO_INT,
288 Instruction::DOUBLE_TO_LONG,
289 Instruction::DOUBLE_TO_FLOAT,
290 Instruction::INT_TO_BYTE,
291 Instruction::INT_TO_CHAR,
292 Instruction::INT_TO_SHORT,
293 Instruction::ADD_INT,
294 Instruction::SUB_INT,
295 Instruction::MUL_INT,
296 Instruction::DIV_INT,
297 Instruction::REM_INT,
298 Instruction::AND_INT,
299 Instruction::OR_INT,
300 Instruction::XOR_INT,
301 Instruction::SHL_INT,
302 Instruction::SHR_INT,
303 Instruction::USHR_INT,
304 Instruction::ADD_LONG,
305 Instruction::SUB_LONG,
306 Instruction::MUL_LONG,
307 Instruction::DIV_LONG,
308 Instruction::REM_LONG,
309 Instruction::AND_LONG,
310 Instruction::OR_LONG,
311 Instruction::XOR_LONG,
312 Instruction::SHL_LONG,
313 Instruction::SHR_LONG,
314 Instruction::USHR_LONG,
315 Instruction::ADD_FLOAT,
316 Instruction::SUB_FLOAT,
317 Instruction::MUL_FLOAT,
318 Instruction::DIV_FLOAT,
319 Instruction::REM_FLOAT,
320 Instruction::ADD_DOUBLE,
321 Instruction::SUB_DOUBLE,
322 Instruction::MUL_DOUBLE,
323 Instruction::DIV_DOUBLE,
324 Instruction::REM_DOUBLE,
325 Instruction::ADD_INT_2ADDR,
326 Instruction::SUB_INT_2ADDR,
327 Instruction::MUL_INT_2ADDR,
328 Instruction::DIV_INT_2ADDR,
329 Instruction::REM_INT_2ADDR,
330 Instruction::AND_INT_2ADDR,
331 Instruction::OR_INT_2ADDR,
332 Instruction::XOR_INT_2ADDR,
333 Instruction::SHL_INT_2ADDR,
334 Instruction::SHR_INT_2ADDR,
335 Instruction::USHR_INT_2ADDR,
336 Instruction::ADD_LONG_2ADDR,
337 Instruction::SUB_LONG_2ADDR,
338 Instruction::MUL_LONG_2ADDR,
339 Instruction::DIV_LONG_2ADDR,
340 Instruction::REM_LONG_2ADDR,
341 Instruction::AND_LONG_2ADDR,
342 Instruction::OR_LONG_2ADDR,
343 Instruction::XOR_LONG_2ADDR,
344 Instruction::SHL_LONG_2ADDR,
345 Instruction::SHR_LONG_2ADDR,
346 Instruction::USHR_LONG_2ADDR,
347 Instruction::ADD_FLOAT_2ADDR,
348 Instruction::SUB_FLOAT_2ADDR,
349 Instruction::MUL_FLOAT_2ADDR,
350 Instruction::DIV_FLOAT_2ADDR,
351 Instruction::REM_FLOAT_2ADDR,
352 Instruction::ADD_DOUBLE_2ADDR,
353 Instruction::SUB_DOUBLE_2ADDR,
354 Instruction::MUL_DOUBLE_2ADDR,
355 Instruction::DIV_DOUBLE_2ADDR,
356 Instruction::REM_DOUBLE_2ADDR,
357 Instruction::ADD_INT_LIT16,
358 Instruction::RSUB_INT,
359 Instruction::MUL_INT_LIT16,
360 Instruction::DIV_INT_LIT16,
361 Instruction::REM_INT_LIT16,
362 Instruction::AND_INT_LIT16,
363 Instruction::OR_INT_LIT16,
364 Instruction::XOR_INT_LIT16,
365 Instruction::ADD_INT_LIT8,
366 Instruction::RSUB_INT_LIT8,
367 Instruction::MUL_INT_LIT8,
368 Instruction::DIV_INT_LIT8,
369 Instruction::REM_INT_LIT8,
370 Instruction::AND_INT_LIT8,
371 Instruction::OR_INT_LIT8,
372 Instruction::XOR_INT_LIT8,
373 Instruction::SHL_INT_LIT8,
374 Instruction::SHR_INT_LIT8,
375 Instruction::USHR_INT_LIT8,
376 Instruction::IGET_QUICK,
377 Instruction::IGET_WIDE_QUICK,
378 Instruction::IGET_OBJECT_QUICK,
379 Instruction::IPUT_QUICK,
380 Instruction::IPUT_WIDE_QUICK,
381 Instruction::IPUT_OBJECT_QUICK,
382 Instruction::INVOKE_VIRTUAL_QUICK,
383 Instruction::INVOKE_VIRTUAL_RANGE_QUICK,
Fred Shih37f05ef2014-07-16 18:38:08 -0700384 Instruction::IPUT_BOOLEAN_QUICK,
385 Instruction::IPUT_BYTE_QUICK,
386 Instruction::IPUT_CHAR_QUICK,
387 Instruction::IPUT_SHORT_QUICK,
Mathieu Chartierffc605c2014-12-10 10:35:44 -0800388 Instruction::IGET_BOOLEAN_QUICK,
389 Instruction::IGET_BYTE_QUICK,
390 Instruction::IGET_CHAR_QUICK,
391 Instruction::IGET_SHORT_QUICK,
Igor Murashkin158f35c2015-06-10 15:55:30 -0700392 Instruction::INVOKE_LAMBDA,
Andreas Gampe53c913b2014-08-12 23:19:23 -0700393 Instruction::UNUSED_F4,
394 Instruction::UNUSED_F5,
Igor Murashkin158f35c2015-06-10 15:55:30 -0700395 Instruction::CREATE_LAMBDA,
Andreas Gampe53c913b2014-08-12 23:19:23 -0700396 Instruction::UNUSED_F7,
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700397 Instruction::BOX_LAMBDA,
398 Instruction::UNBOX_LAMBDA,
Andreas Gampe53c913b2014-08-12 23:19:23 -0700399 Instruction::UNUSED_FA,
400 Instruction::UNUSED_FB,
401 Instruction::UNUSED_FC,
402 Instruction::UNUSED_FD,
403 Instruction::UNUSED_FE,
404 Instruction::UNUSED_FF,
405 // ----- ExtendedMIROpcode -----
406 kMirOpPhi,
407 kMirOpCopy,
408 kMirOpFusedCmplFloat,
409 kMirOpFusedCmpgFloat,
410 kMirOpFusedCmplDouble,
411 kMirOpFusedCmpgDouble,
412 kMirOpFusedCmpLong,
413 kMirOpNop,
414 kMirOpNullCheck,
415 kMirOpRangeCheck,
416 kMirOpDivZeroCheck,
417 kMirOpCheck,
Andreas Gampe53c913b2014-08-12 23:19:23 -0700418 kMirOpSelect,
419};
420
Zheng Xu5667fdb2014-10-23 18:29:55 +0800421static int kInvokeOpcodes[] = {
422 Instruction::INVOKE_VIRTUAL,
423 Instruction::INVOKE_SUPER,
424 Instruction::INVOKE_DIRECT,
425 Instruction::INVOKE_STATIC,
426 Instruction::INVOKE_INTERFACE,
427 Instruction::INVOKE_VIRTUAL_RANGE,
428 Instruction::INVOKE_SUPER_RANGE,
429 Instruction::INVOKE_DIRECT_RANGE,
430 Instruction::INVOKE_STATIC_RANGE,
431 Instruction::INVOKE_INTERFACE_RANGE,
432 Instruction::INVOKE_VIRTUAL_QUICK,
433 Instruction::INVOKE_VIRTUAL_RANGE_QUICK,
434};
435
Igor Murashkin158f35c2015-06-10 15:55:30 -0700436// TODO: Add support for lambda opcodes to the quick compiler.
437static const int kUnsupportedLambdaOpcodes[] = {
438 Instruction::INVOKE_LAMBDA,
439 Instruction::CREATE_LAMBDA,
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700440 Instruction::BOX_LAMBDA,
441 Instruction::UNBOX_LAMBDA,
Igor Murashkin158f35c2015-06-10 15:55:30 -0700442};
443
444// Unsupported opcodes. Null can be used when everything is supported. Size of the lists is
Andreas Gampe53c913b2014-08-12 23:19:23 -0700445// recorded below.
446static const int* kUnsupportedOpcodes[] = {
447 // 0 = kNone.
448 kAllOpcodes,
449 // 1 = kArm, unused (will use kThumb2).
450 kAllOpcodes,
451 // 2 = kArm64.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700452 kUnsupportedLambdaOpcodes,
Andreas Gampe53c913b2014-08-12 23:19:23 -0700453 // 3 = kThumb2.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700454 kUnsupportedLambdaOpcodes,
Andreas Gampe53c913b2014-08-12 23:19:23 -0700455 // 4 = kX86.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700456 kUnsupportedLambdaOpcodes,
Andreas Gampe53c913b2014-08-12 23:19:23 -0700457 // 5 = kX86_64.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700458 kUnsupportedLambdaOpcodes,
Andreas Gampe53c913b2014-08-12 23:19:23 -0700459 // 6 = kMips.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700460 kUnsupportedLambdaOpcodes,
Andreas Gampe53c913b2014-08-12 23:19:23 -0700461 // 7 = kMips64.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700462 kUnsupportedLambdaOpcodes,
Andreas Gampe53c913b2014-08-12 23:19:23 -0700463};
Andreas Gampe785d2f22014-11-03 22:57:30 -0800464static_assert(sizeof(kUnsupportedOpcodes) == 8 * sizeof(int*), "kUnsupportedOpcodes unexpected");
Andreas Gampe53c913b2014-08-12 23:19:23 -0700465
466// Size of the arrays stored above.
467static const size_t kUnsupportedOpcodesSize[] = {
468 // 0 = kNone.
469 arraysize(kAllOpcodes),
470 // 1 = kArm, unused (will use kThumb2).
471 arraysize(kAllOpcodes),
472 // 2 = kArm64.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700473 arraysize(kUnsupportedLambdaOpcodes),
Andreas Gampe53c913b2014-08-12 23:19:23 -0700474 // 3 = kThumb2.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700475 arraysize(kUnsupportedLambdaOpcodes),
Andreas Gampe53c913b2014-08-12 23:19:23 -0700476 // 4 = kX86.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700477 arraysize(kUnsupportedLambdaOpcodes),
Andreas Gampe53c913b2014-08-12 23:19:23 -0700478 // 5 = kX86_64.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700479 arraysize(kUnsupportedLambdaOpcodes),
Andreas Gampe53c913b2014-08-12 23:19:23 -0700480 // 6 = kMips.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700481 arraysize(kUnsupportedLambdaOpcodes),
Andreas Gampe53c913b2014-08-12 23:19:23 -0700482 // 7 = kMips64.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700483 arraysize(kUnsupportedLambdaOpcodes),
Andreas Gampe53c913b2014-08-12 23:19:23 -0700484};
Andreas Gampe785d2f22014-11-03 22:57:30 -0800485static_assert(sizeof(kUnsupportedOpcodesSize) == 8 * sizeof(size_t),
486 "kUnsupportedOpcodesSize unexpected");
Andreas Gampe53c913b2014-08-12 23:19:23 -0700487
Igor Murashkin158f35c2015-06-10 15:55:30 -0700488static bool IsUnsupportedExperimentalLambdasOnly(size_t i) {
489 DCHECK_LE(i, arraysize(kUnsupportedOpcodes));
490 return kUnsupportedOpcodes[i] == kUnsupportedLambdaOpcodes;
491}
492
Andreas Gampe53c913b2014-08-12 23:19:23 -0700493// The maximum amount of Dalvik register in a method for which we will start compiling. Tries to
494// avoid an abort when we need to manage more SSA registers than we can.
495static constexpr size_t kMaxAllowedDalvikRegisters = INT16_MAX / 2;
496
497static bool CanCompileShorty(const char* shorty, InstructionSet instruction_set) {
498 const char* supported_types = kSupportedTypes[instruction_set];
499 if (supported_types == nullptr) {
500 // Everything available.
501 return true;
502 }
503
504 uint32_t shorty_size = strlen(shorty);
505 CHECK_GE(shorty_size, 1u);
506
507 for (uint32_t i = 0; i < shorty_size; i++) {
508 if (strchr(supported_types, shorty[i]) == nullptr) {
509 return false;
510 }
511 }
512 return true;
Andreas Gampec8ccf682014-09-29 20:07:43 -0700513}
Andreas Gampe53c913b2014-08-12 23:19:23 -0700514
Igor Murashkin158f35c2015-06-10 15:55:30 -0700515// If the ISA has unsupported opcodes, should we skip scanning over them?
516//
517// Most of the time we're compiling non-experimental files, so scanning just slows
518// performance down by as much as 6% with 4 threads.
519// In the rare cases we compile experimental opcodes, the runtime has an option to enable it,
520// which will force scanning for any unsupported opcodes.
521static bool SkipScanningUnsupportedOpcodes(InstructionSet instruction_set) {
522 if (UNLIKELY(kUnsupportedOpcodesSize[instruction_set] == 0U)) {
523 // All opcodes are supported no matter what. Usually not the case
524 // since experimental opcodes are not implemented in the quick compiler.
525 return true;
526 } else if (LIKELY(!Runtime::Current()->AreExperimentalLambdasEnabled())) {
527 // Experimental opcodes are disabled.
528 //
529 // If all unsupported opcodes are experimental we don't need to do scanning.
530 return IsUnsupportedExperimentalLambdasOnly(instruction_set);
531 } else {
532 // Experimental opcodes are enabled.
533 //
534 // Do the opcode scanning if the ISA has any unsupported opcodes.
535 return false;
536 }
537}
538
Andreas Gampe53c913b2014-08-12 23:19:23 -0700539// Skip the method that we do not support currently.
540bool QuickCompiler::CanCompileMethod(uint32_t method_idx, const DexFile& dex_file,
541 CompilationUnit* cu) const {
542 // This is a limitation in mir_graph. See MirGraph::SetNumSSARegs.
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700543 if (cu->mir_graph->GetNumOfCodeAndTempVRs() > kMaxAllowedDalvikRegisters) {
544 VLOG(compiler) << "Too many dalvik registers : " << cu->mir_graph->GetNumOfCodeAndTempVRs();
Andreas Gampe53c913b2014-08-12 23:19:23 -0700545 return false;
546 }
547
548 // Check whether we do have limitations at all.
549 if (kSupportedTypes[cu->instruction_set] == nullptr &&
Igor Murashkin158f35c2015-06-10 15:55:30 -0700550 SkipScanningUnsupportedOpcodes(cu->instruction_set)) {
Andreas Gampe53c913b2014-08-12 23:19:23 -0700551 return true;
552 }
553
554 // Check if we can compile the prototype.
555 const char* shorty = dex_file.GetMethodShorty(dex_file.GetMethodId(method_idx));
556 if (!CanCompileShorty(shorty, cu->instruction_set)) {
557 VLOG(compiler) << "Unsupported shorty : " << shorty;
558 return false;
559 }
560
561 const int *unsupport_list = kUnsupportedOpcodes[cu->instruction_set];
562 int unsupport_list_size = kUnsupportedOpcodesSize[cu->instruction_set];
563
564 for (unsigned int idx = 0; idx < cu->mir_graph->GetNumBlocks(); idx++) {
565 BasicBlock* bb = cu->mir_graph->GetBasicBlock(idx);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700566 if (bb == nullptr) continue;
Andreas Gampe53c913b2014-08-12 23:19:23 -0700567 if (bb->block_type == kDead) continue;
568 for (MIR* mir = bb->first_mir_insn; mir != nullptr; mir = mir->next) {
569 int opcode = mir->dalvikInsn.opcode;
570 // Check if we support the byte code.
Zheng Xu5667fdb2014-10-23 18:29:55 +0800571 if (std::find(unsupport_list, unsupport_list + unsupport_list_size, opcode)
572 != unsupport_list + unsupport_list_size) {
Andreas Gampe53c913b2014-08-12 23:19:23 -0700573 if (!MIR::DecodedInstruction::IsPseudoMirOp(opcode)) {
574 VLOG(compiler) << "Unsupported dalvik byte code : "
575 << mir->dalvikInsn.opcode;
576 } else {
577 VLOG(compiler) << "Unsupported extended MIR opcode : "
578 << MIRGraph::extended_mir_op_names_[opcode - kMirOpFirst];
579 }
580 return false;
581 }
582 // Check if it invokes a prototype that we cannot support.
Zheng Xu5667fdb2014-10-23 18:29:55 +0800583 if (std::find(kInvokeOpcodes, kInvokeOpcodes + arraysize(kInvokeOpcodes), opcode)
584 != kInvokeOpcodes + arraysize(kInvokeOpcodes)) {
Andreas Gampe53c913b2014-08-12 23:19:23 -0700585 uint32_t invoke_method_idx = mir->dalvikInsn.vB;
586 const char* invoke_method_shorty = dex_file.GetMethodShorty(
587 dex_file.GetMethodId(invoke_method_idx));
588 if (!CanCompileShorty(invoke_method_shorty, cu->instruction_set)) {
589 VLOG(compiler) << "Unsupported to invoke '"
590 << PrettyMethod(invoke_method_idx, dex_file)
591 << "' with shorty : " << invoke_method_shorty;
592 return false;
593 }
594 }
595 }
596 }
597 return true;
598}
599
600void QuickCompiler::InitCompilationUnit(CompilationUnit& cu) const {
601 // Disable optimizations according to instruction set.
602 cu.disable_opt |= kDisabledOptimizationsPerISA[cu.instruction_set];
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800603 if (Runtime::Current()->UseJit()) {
604 // Disable these optimizations for JIT until quickened byte codes are done being implemented.
605 // TODO: Find a cleaner way to do this.
606 cu.disable_opt |= 1u << kLocalValueNumbering;
607 }
Andreas Gampe53c913b2014-08-12 23:19:23 -0700608}
609
David Brazdilee690a32014-12-01 17:04:16 +0000610void QuickCompiler::Init() {
Andreas Gampe53c913b2014-08-12 23:19:23 -0700611 CHECK(GetCompilerDriver()->GetCompilerContext() == nullptr);
612}
613
614void QuickCompiler::UnInit() const {
615 CHECK(GetCompilerDriver()->GetCompilerContext() == nullptr);
616}
617
Andreas Gampe0e92f4f2015-01-26 17:37:27 -0800618/* Default optimizer/debug setting for the compiler. */
619static uint32_t kCompilerOptimizerDisableFlags = 0 | // Disable specific optimizations
620 // (1 << kLoadStoreElimination) |
621 // (1 << kLoadHoisting) |
622 // (1 << kSuppressLoads) |
623 // (1 << kNullCheckElimination) |
624 // (1 << kClassInitCheckElimination) |
625 // (1 << kGlobalValueNumbering) |
Vladimir Markoa5e69e82015-04-24 19:03:51 +0100626 // (1 << kGvnDeadCodeElimination) |
Andreas Gampe0e92f4f2015-01-26 17:37:27 -0800627 // (1 << kLocalValueNumbering) |
628 // (1 << kPromoteRegs) |
629 // (1 << kTrackLiveTemps) |
630 // (1 << kSafeOptimizations) |
631 // (1 << kBBOpt) |
632 // (1 << kSuspendCheckElimination) |
633 // (1 << kMatch) |
634 // (1 << kPromoteCompilerTemps) |
635 // (1 << kSuppressExceptionEdges) |
636 // (1 << kSuppressMethodInlining) |
637 0;
638
639static uint32_t kCompilerDebugFlags = 0 | // Enable debug/testing modes
640 // (1 << kDebugDisplayMissingTargets) |
641 // (1 << kDebugVerbose) |
642 // (1 << kDebugDumpCFG) |
643 // (1 << kDebugSlowFieldPath) |
644 // (1 << kDebugSlowInvokePath) |
645 // (1 << kDebugSlowStringPath) |
646 // (1 << kDebugSlowestFieldPath) |
647 // (1 << kDebugSlowestStringPath) |
648 // (1 << kDebugExerciseResolveMethod) |
649 // (1 << kDebugVerifyDataflow) |
650 // (1 << kDebugShowMemoryUsage) |
651 // (1 << kDebugShowNops) |
652 // (1 << kDebugCountOpcodes) |
653 // (1 << kDebugDumpCheckStats) |
654 // (1 << kDebugShowSummaryMemoryUsage) |
655 // (1 << kDebugShowFilterStats) |
656 // (1 << kDebugTimings) |
657 // (1 << kDebugCodegenDump) |
658 0;
659
Andreas Gampe53c913b2014-08-12 23:19:23 -0700660CompiledMethod* QuickCompiler::Compile(const DexFile::CodeItem* code_item,
661 uint32_t access_flags,
662 InvokeType invoke_type,
663 uint16_t class_def_idx,
664 uint32_t method_idx,
665 jobject class_loader,
666 const DexFile& dex_file) const {
Roland Levillain4d027112015-07-01 15:41:14 +0100667 if (kPoisonHeapReferences) {
668 VLOG(compiler) << "Skipping method : " << PrettyMethod(method_idx, dex_file)
669 << " Reason = Quick does not support heap poisoning.";
670 return nullptr;
671 }
672
Andreas Gampe53c913b2014-08-12 23:19:23 -0700673 // TODO: check method fingerprint here to determine appropriate backend type. Until then, use
674 // build default.
675 CompilerDriver* driver = GetCompilerDriver();
Andreas Gampe0e92f4f2015-01-26 17:37:27 -0800676
677 VLOG(compiler) << "Compiling " << PrettyMethod(method_idx, dex_file) << "...";
678 if (Compiler::IsPathologicalCase(*code_item, method_idx, dex_file)) {
679 return nullptr;
680 }
681
682 DCHECK(driver->GetCompilerOptions().IsCompilationEnabled());
Andreas Gampe0760a812015-08-26 17:12:51 -0700683 DCHECK(!driver->GetVerifiedMethod(&dex_file, method_idx)->HasRuntimeThrow());
Andreas Gampe0e92f4f2015-01-26 17:37:27 -0800684
Mathieu Chartier9b34b242015-03-09 11:30:17 -0700685 Runtime* const runtime = Runtime::Current();
686 ClassLinker* const class_linker = runtime->GetClassLinker();
Andreas Gampe0e92f4f2015-01-26 17:37:27 -0800687 InstructionSet instruction_set = driver->GetInstructionSet();
688 if (instruction_set == kArm) {
689 instruction_set = kThumb2;
690 }
Mathieu Chartier9b34b242015-03-09 11:30:17 -0700691 CompilationUnit cu(runtime->GetArenaPool(), instruction_set, driver, class_linker);
Vladimir Marko20f85592015-03-19 10:07:02 +0000692 cu.dex_file = &dex_file;
693 cu.class_def_idx = class_def_idx;
694 cu.method_idx = method_idx;
695 cu.access_flags = access_flags;
696 cu.invoke_type = invoke_type;
697 cu.shorty = dex_file.GetMethodShorty(dex_file.GetMethodId(method_idx));
Andreas Gampe0e92f4f2015-01-26 17:37:27 -0800698
Andreas Gampe0e92f4f2015-01-26 17:37:27 -0800699 CHECK((cu.instruction_set == kThumb2) ||
700 (cu.instruction_set == kArm64) ||
701 (cu.instruction_set == kX86) ||
702 (cu.instruction_set == kX86_64) ||
Maja Gagic6ea651f2015-02-24 16:55:04 +0100703 (cu.instruction_set == kMips) ||
704 (cu.instruction_set == kMips64));
Andreas Gampe0e92f4f2015-01-26 17:37:27 -0800705
706 // TODO: set this from command line
707 constexpr bool compiler_flip_match = false;
708 const std::string compiler_method_match = "";
709
710 bool use_match = !compiler_method_match.empty();
711 bool match = use_match && (compiler_flip_match ^
712 (PrettyMethod(method_idx, dex_file).find(compiler_method_match) != std::string::npos));
713 if (!use_match || match) {
714 cu.disable_opt = kCompilerOptimizerDisableFlags;
715 cu.enable_debug = kCompilerDebugFlags;
716 cu.verbose = VLOG_IS_ON(compiler) ||
717 (cu.enable_debug & (1 << kDebugVerbose));
718 }
719
720 if (driver->GetCompilerOptions().HasVerboseMethods()) {
721 cu.verbose = driver->GetCompilerOptions().IsVerboseMethod(PrettyMethod(method_idx, dex_file));
722 }
723
724 if (cu.verbose) {
725 cu.enable_debug |= (1 << kDebugCodegenDump);
726 }
727
728 /*
729 * TODO: rework handling of optimization and debug flags. Should we split out
730 * MIR and backend flags? Need command-line setting as well.
731 */
732
733 InitCompilationUnit(cu);
734
735 cu.StartTimingSplit("BuildMIRGraph");
736 cu.mir_graph.reset(new MIRGraph(&cu, &cu.arena));
737
738 /*
739 * After creation of the MIR graph, also create the code generator.
740 * The reason we do this is that optimizations on the MIR graph may need to get information
741 * that is only available if a CG exists.
742 */
743 cu.cg.reset(GetCodeGenerator(&cu, nullptr));
744
745 /* Gathering opcode stats? */
746 if (kCompilerDebugFlags & (1 << kDebugCountOpcodes)) {
747 cu.mir_graph->EnableOpcodeCounting();
748 }
749
750 /* Build the raw MIR graph */
751 cu.mir_graph->InlineMethod(code_item, access_flags, invoke_type, class_def_idx, method_idx,
752 class_loader, dex_file);
753
754 if (!CanCompileMethod(method_idx, dex_file, &cu)) {
755 VLOG(compiler) << cu.instruction_set << ": Cannot compile method : "
756 << PrettyMethod(method_idx, dex_file);
757 cu.EndTiming();
758 return nullptr;
759 }
760
761 cu.NewTimingSplit("MIROpt:CheckFilters");
762 std::string skip_message;
763 if (cu.mir_graph->SkipCompilation(&skip_message)) {
764 VLOG(compiler) << cu.instruction_set << ": Skipping method : "
765 << PrettyMethod(method_idx, dex_file) << " Reason = " << skip_message;
766 cu.EndTiming();
767 return nullptr;
768 }
769
770 /* Create the pass driver and launch it */
Nicolas Geoffray216eaa22015-03-17 17:09:30 +0000771 PassDriverMEOpts pass_driver(GetPreOptPassManager(), GetPostOptPassManager(), &cu);
Andreas Gampe0e92f4f2015-01-26 17:37:27 -0800772 pass_driver.Launch();
773
774 /* For non-leaf methods check if we should skip compilation when the profiler is enabled. */
775 if (cu.compiler_driver->ProfilePresent()
776 && !cu.mir_graph->MethodIsLeaf()
777 && cu.mir_graph->SkipCompilationByName(PrettyMethod(method_idx, dex_file))) {
778 cu.EndTiming();
779 return nullptr;
780 }
781
782 if (cu.enable_debug & (1 << kDebugDumpCheckStats)) {
783 cu.mir_graph->DumpCheckStats();
784 }
785
786 if (kCompilerDebugFlags & (1 << kDebugCountOpcodes)) {
787 cu.mir_graph->ShowOpcodeStats();
788 }
789
790 /* Reassociate sreg names with original Dalvik vreg names. */
791 cu.mir_graph->RemapRegLocations();
792
793 /* Free Arenas from the cu.arena_stack for reuse by the cu.arena in the codegen. */
794 if (cu.enable_debug & (1 << kDebugShowMemoryUsage)) {
795 if (cu.arena_stack.PeakBytesAllocated() > 1 * 1024 * 1024) {
796 MemStats stack_stats(cu.arena_stack.GetPeakStats());
797 LOG(INFO) << PrettyMethod(method_idx, dex_file) << " " << Dumpable<MemStats>(stack_stats);
798 }
799 }
800 cu.arena_stack.Reset();
801
802 CompiledMethod* result = nullptr;
803
804 if (cu.mir_graph->PuntToInterpreter()) {
805 VLOG(compiler) << cu.instruction_set << ": Punted method to interpreter: "
806 << PrettyMethod(method_idx, dex_file);
807 cu.EndTiming();
808 return nullptr;
809 }
810
811 cu.cg->Materialize();
812
813 cu.NewTimingSplit("Dedupe"); /* deduping takes up the vast majority of time in GetCompiledMethod(). */
814 result = cu.cg->GetCompiledMethod();
815 cu.NewTimingSplit("Cleanup");
816
817 if (result) {
818 VLOG(compiler) << cu.instruction_set << ": Compiled " << PrettyMethod(method_idx, dex_file);
819 } else {
820 VLOG(compiler) << cu.instruction_set << ": Deferred " << PrettyMethod(method_idx, dex_file);
821 }
822
823 if (cu.enable_debug & (1 << kDebugShowMemoryUsage)) {
824 if (cu.arena.BytesAllocated() > (1 * 1024 *1024)) {
825 MemStats mem_stats(cu.arena.GetMemStats());
826 LOG(INFO) << PrettyMethod(method_idx, dex_file) << " " << Dumpable<MemStats>(mem_stats);
827 }
828 }
829
830 if (cu.enable_debug & (1 << kDebugShowSummaryMemoryUsage)) {
831 LOG(INFO) << "MEMINFO " << cu.arena.BytesAllocated() << " " << cu.mir_graph->GetNumBlocks()
832 << " " << PrettyMethod(method_idx, dex_file);
833 }
834
835 cu.EndTiming();
836 driver->GetTimingsLogger()->AddLogger(cu.timings);
837 return result;
Andreas Gampe53c913b2014-08-12 23:19:23 -0700838}
839
840CompiledMethod* QuickCompiler::JniCompile(uint32_t access_flags,
841 uint32_t method_idx,
842 const DexFile& dex_file) const {
843 return ArtQuickJniCompileMethod(GetCompilerDriver(), access_flags, method_idx, dex_file);
844}
845
Mathieu Chartiere401d142015-04-22 13:56:20 -0700846uintptr_t QuickCompiler::GetEntryPointOf(ArtMethod* method) const {
Mathieu Chartier130914e2014-11-18 15:34:09 -0800847 return reinterpret_cast<uintptr_t>(method->GetEntryPointFromQuickCompiledCodePtrSize(
848 InstructionSetPointerSize(GetCompilerDriver()->GetInstructionSet())));
Andreas Gampe53c913b2014-08-12 23:19:23 -0700849}
850
David Srbecky1109fb32015-04-07 20:21:06 +0100851Mir2Lir* QuickCompiler::GetCodeGenerator(CompilationUnit* cu, void* compilation_unit) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700852 UNUSED(compilation_unit);
Andreas Gampe53c913b2014-08-12 23:19:23 -0700853 Mir2Lir* mir_to_lir = nullptr;
854 switch (cu->instruction_set) {
Alex Light50fa9932015-08-10 15:30:07 -0700855#ifdef ART_ENABLE_CODEGEN_arm
Andreas Gampe53c913b2014-08-12 23:19:23 -0700856 case kThumb2:
857 mir_to_lir = ArmCodeGenerator(cu, cu->mir_graph.get(), &cu->arena);
858 break;
Alex Light50fa9932015-08-10 15:30:07 -0700859#endif // ART_ENABLE_CODEGEN_arm
860#ifdef ART_ENABLE_CODEGEN_arm64
Andreas Gampe53c913b2014-08-12 23:19:23 -0700861 case kArm64:
862 mir_to_lir = Arm64CodeGenerator(cu, cu->mir_graph.get(), &cu->arena);
863 break;
Alex Light50fa9932015-08-10 15:30:07 -0700864#endif // ART_ENABLE_CODEGEN_arm64
865#if defined(ART_ENABLE_CODEGEN_mips) || defined(ART_ENABLE_CODEGEN_mips64)
866 // Intentional 2 level ifdef. Want to fail on mips64 if it is not enabled, even if mips is
867 // and vice versa.
868#ifdef ART_ENABLE_CODEGEN_mips
Andreas Gampe53c913b2014-08-12 23:19:23 -0700869 case kMips:
Goran Jakovljevic10957932015-03-24 18:42:56 +0100870 // Fall-through.
Alex Light50fa9932015-08-10 15:30:07 -0700871#endif // ART_ENABLE_CODEGEN_mips
872#ifdef ART_ENABLE_CODEGEN_mips64
Maja Gagic6ea651f2015-02-24 16:55:04 +0100873 case kMips64:
Alex Light50fa9932015-08-10 15:30:07 -0700874#endif // ART_ENABLE_CODEGEN_mips64
Goran Jakovljevic10957932015-03-24 18:42:56 +0100875 mir_to_lir = MipsCodeGenerator(cu, cu->mir_graph.get(), &cu->arena);
Maja Gagic6ea651f2015-02-24 16:55:04 +0100876 break;
Alex Light50fa9932015-08-10 15:30:07 -0700877#endif // ART_ENABLE_CODEGEN_mips || ART_ENABLE_CODEGEN_mips64
878#if defined(ART_ENABLE_CODEGEN_x86) || defined(ART_ENABLE_CODEGEN_x86_64)
879 // Intentional 2 level ifdef. Want to fail on x86_64 if it is not enabled, even if x86 is
880 // and vice versa.
881#ifdef ART_ENABLE_CODEGEN_x86
Andreas Gampe53c913b2014-08-12 23:19:23 -0700882 case kX86:
883 // Fall-through.
Alex Light50fa9932015-08-10 15:30:07 -0700884#endif // ART_ENABLE_CODEGEN_x86
885#ifdef ART_ENABLE_CODEGEN_x86_64
Andreas Gampe53c913b2014-08-12 23:19:23 -0700886 case kX86_64:
Alex Light50fa9932015-08-10 15:30:07 -0700887#endif // ART_ENABLE_CODEGEN_x86_64
Andreas Gampe53c913b2014-08-12 23:19:23 -0700888 mir_to_lir = X86CodeGenerator(cu, cu->mir_graph.get(), &cu->arena);
889 break;
Alex Light50fa9932015-08-10 15:30:07 -0700890#endif // ART_ENABLE_CODEGEN_x86 || ART_ENABLE_CODEGEN_x86_64
Andreas Gampe53c913b2014-08-12 23:19:23 -0700891 default:
892 LOG(FATAL) << "Unexpected instruction set: " << cu->instruction_set;
893 }
894
895 /* The number of compiler temporaries depends on backend so set it up now if possible */
896 if (mir_to_lir) {
897 size_t max_temps = mir_to_lir->GetMaxPossibleCompilerTemps();
898 bool set_max = cu->mir_graph->SetMaxAvailableNonSpecialCompilerTemps(max_temps);
899 CHECK(set_max);
900 }
901 return mir_to_lir;
902}
903
Mathieu Chartier5bdab122015-01-26 18:30:19 -0800904QuickCompiler::QuickCompiler(CompilerDriver* driver) : Compiler(driver, 100) {
905 const auto& compiler_options = driver->GetCompilerOptions();
906 auto* pass_manager_options = compiler_options.GetPassManagerOptions();
907 pre_opt_pass_manager_.reset(new PassManager(*pass_manager_options));
908 CHECK(pre_opt_pass_manager_.get() != nullptr);
909 PassDriverMEOpts::SetupPasses(pre_opt_pass_manager_.get());
910 pre_opt_pass_manager_->CreateDefaultPassList();
911 if (pass_manager_options->GetPrintPassOptions()) {
912 PassDriverMEOpts::PrintPassOptions(pre_opt_pass_manager_.get());
913 }
914 // TODO: Different options for pre vs post opts?
915 post_opt_pass_manager_.reset(new PassManager(PassManagerOptions()));
916 CHECK(post_opt_pass_manager_.get() != nullptr);
917 PassDriverMEPostOpt::SetupPasses(post_opt_pass_manager_.get());
918 post_opt_pass_manager_->CreateDefaultPassList();
919 if (pass_manager_options->GetPrintPassOptions()) {
920 PassDriverMEPostOpt::PrintPassOptions(post_opt_pass_manager_.get());
921 }
922}
923
924QuickCompiler::~QuickCompiler() {
925}
Andreas Gampe53c913b2014-08-12 23:19:23 -0700926
927Compiler* CreateQuickCompiler(CompilerDriver* driver) {
Mathieu Chartier5bdab122015-01-26 18:30:19 -0800928 return QuickCompiler::Create(driver);
929}
930
931Compiler* QuickCompiler::Create(CompilerDriver* driver) {
Andreas Gampe53c913b2014-08-12 23:19:23 -0700932 return new QuickCompiler(driver);
933}
934
935} // namespace art