1 /*
2 * Copyright (c) 2008, 2026, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "asm/macroAssembler.inline.hpp"
26 #include "c1/c1_Compilation.hpp"
27 #include "c1/c1_FrameMap.hpp"
28 #include "c1/c1_Instruction.hpp"
29 #include "c1/c1_LIRAssembler.hpp"
30 #include "c1/c1_LIRGenerator.hpp"
31 #include "c1/c1_Runtime1.hpp"
32 #include "c1/c1_ValueStack.hpp"
33 #include "ci/ciArray.hpp"
34 #include "ci/ciObjArrayKlass.hpp"
35 #include "ci/ciTypeArrayKlass.hpp"
36 #include "ci/ciUtilities.hpp"
37 #include "gc/shared/c1/barrierSetC1.hpp"
38 #include "gc/shared/cardTable.hpp"
39 #include "gc/shared/cardTableBarrierSet.hpp"
40 #include "runtime/sharedRuntime.hpp"
41 #include "runtime/stubRoutines.hpp"
42 #include "utilities/powerOfTwo.hpp"
43 #include "vmreg_arm.inline.hpp"
44
45 #ifdef ASSERT
46 #define __ gen()->lir(__FILE__, __LINE__)->
47 #else
48 #define __ gen()->lir()->
49 #endif
50
51 void LIRItem::load_byte_item() {
52 load_item();
53 }
54
55 void LIRItem::load_nonconstant() {
56 LIR_Opr r = value()->operand();
57 if (_gen->can_inline_as_constant(value())) {
58 if (!r->is_constant()) {
59 r = LIR_OprFact::value_type(value()->type());
60 }
61 _result = r;
62 } else {
63 load_item();
64 }
65 }
66
67 //--------------------------------------------------------------
68 // LIRGenerator
69 //--------------------------------------------------------------
70
71
72 LIR_Opr LIRGenerator::exceptionOopOpr() {
73 return FrameMap::Exception_oop_opr;
74 }
75
76 LIR_Opr LIRGenerator::exceptionPcOpr() {
77 return FrameMap::Exception_pc_opr;
78 }
79
80 LIR_Opr LIRGenerator::syncLockOpr() {
81 return new_register(T_INT);
82 }
83
84 LIR_Opr LIRGenerator::syncTempOpr() {
85 return new_register(T_OBJECT);
86 }
87
88 LIR_Opr LIRGenerator::getThreadTemp() {
89 return LIR_OprFact::illegalOpr;
90 }
91
92 LIR_Opr LIRGenerator::atomicLockOpr() {
93 return LIR_OprFact::illegalOpr;
94 }
95
96 LIR_Opr LIRGenerator::result_register_for(ValueType* type, bool callee) {
97 LIR_Opr opr;
98 switch (type->tag()) {
99 case intTag: opr = FrameMap::Int_result_opr; break;
100 case objectTag: opr = FrameMap::Object_result_opr; break;
101 case longTag: opr = FrameMap::Long_result_opr; break;
102 case floatTag: opr = FrameMap::Float_result_opr; break;
103 case doubleTag: opr = FrameMap::Double_result_opr; break;
104 case addressTag:
105 default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr;
106 }
107 assert(opr->type_field() == as_OprType(as_BasicType(type)), "type mismatch");
108 return opr;
109 }
110
111
112 LIR_Opr LIRGenerator::rlock_byte(BasicType type) {
113 return new_register(T_INT);
114 }
115
116
117 //--------- loading items into registers --------------------------------
118
119
120 bool LIRGenerator::can_store_as_constant(Value v, BasicType type) const {
121 return false;
122 }
123
124
125 bool LIRGenerator::can_inline_as_constant(Value v) const {
126 if (v->type()->as_IntConstant() != nullptr) {
127 return Assembler::is_arith_imm_in_range(v->type()->as_IntConstant()->value());
128 } else if (v->type()->as_ObjectConstant() != nullptr) {
129 return v->type()->as_ObjectConstant()->value()->is_null_object();
130 } else if (v->type()->as_FloatConstant() != nullptr) {
131 return v->type()->as_FloatConstant()->value() == 0.0f;
132 } else if (v->type()->as_DoubleConstant() != nullptr) {
133 return v->type()->as_DoubleConstant()->value() == 0.0;
134 }
135 return false;
136 }
137
138
139 bool LIRGenerator::can_inline_as_constant(LIR_Const* c) const {
140 ShouldNotCallThis(); // Not used on ARM
141 return false;
142 }
143
144
145
146
147 LIR_Opr LIRGenerator::safepoint_poll_register() {
148 return LIR_OprFact::illegalOpr;
149 }
150
151
152 static LIR_Opr make_constant(BasicType type, jlong c) {
153 switch (type) {
154 case T_ADDRESS:
155 case T_OBJECT: return LIR_OprFact::intptrConst(c);
156 case T_LONG: return LIR_OprFact::longConst(c);
157 case T_INT: return LIR_OprFact::intConst(c);
158 default: ShouldNotReachHere();
159 return LIR_OprFact::intConst(-1);
160 }
161 }
162
163
164
165 void LIRGenerator::add_large_constant(LIR_Opr src, int c, LIR_Opr dest) {
166 assert(c != 0, "must be");
167 // Find first non-zero bit
168 int shift = 0;
169 while ((c & (3 << shift)) == 0) {
170 shift += 2;
171 }
172 // Add the least significant part of the constant
173 int mask = 0xff << shift;
174 __ add(src, LIR_OprFact::intConst(c & mask), dest);
175 // Add up to 3 other parts of the constant;
176 // each of them can be represented as rotated_imm
177 if (c & (mask << 8)) {
178 __ add(dest, LIR_OprFact::intConst(c & (mask << 8)), dest);
179 }
180 if (c & (mask << 16)) {
181 __ add(dest, LIR_OprFact::intConst(c & (mask << 16)), dest);
182 }
183 if (c & (mask << 24)) {
184 __ add(dest, LIR_OprFact::intConst(c & (mask << 24)), dest);
185 }
186 }
187
188 static LIR_Address* make_address(LIR_Opr base, LIR_Opr index, LIR_Address::Scale scale, BasicType type) {
189 return new LIR_Address(base, index, scale, 0, type);
190 }
191
192 LIR_Address* LIRGenerator::generate_address(LIR_Opr base, LIR_Opr index,
193 int shift, int disp, BasicType type) {
194 assert(base->is_register(), "must be");
195
196 if (index->is_constant()) {
197 disp += index->as_constant_ptr()->as_jint() << shift;
198 index = LIR_OprFact::illegalOpr;
199 }
200
201 if (base->type() == T_LONG) {
202 LIR_Opr tmp = new_register(T_INT);
203 __ convert(Bytecodes::_l2i, base, tmp);
204 base = tmp;
205 }
206 if (index != LIR_OprFact::illegalOpr && index->type() == T_LONG) {
207 LIR_Opr tmp = new_register(T_INT);
208 __ convert(Bytecodes::_l2i, index, tmp);
209 index = tmp;
210 }
211 // At this point base and index should be all ints and not constants
212 assert(base->is_single_cpu() && !base->is_constant(), "base should be an non-constant int");
213 assert(index->is_illegal() || (index->type() == T_INT && !index->is_constant()), "index should be an non-constant int");
214
215 int max_disp;
216 bool disp_is_in_range;
217 bool embedded_shift;
218
219 switch (type) {
220 case T_BYTE:
221 case T_SHORT:
222 case T_CHAR:
223 max_disp = 256; // ldrh, ldrsb encoding has 8-bit offset
224 embedded_shift = false;
225 break;
226 case T_FLOAT:
227 case T_DOUBLE:
228 max_disp = 1024; // flds, fldd have 8-bit offset multiplied by 4
229 embedded_shift = false;
230 break;
231 case T_LONG:
232 max_disp = 4096;
233 embedded_shift = false;
234 break;
235 default:
236 max_disp = 4096; // ldr, ldrb allow 12-bit offset
237 embedded_shift = true;
238 }
239
240 disp_is_in_range = (-max_disp < disp && disp < max_disp);
241
242 if (index->is_register()) {
243 LIR_Opr tmp = new_pointer_register();
244 if (!disp_is_in_range) {
245 add_large_constant(base, disp, tmp);
246 base = tmp;
247 disp = 0;
248 }
249 LIR_Address* addr = make_address(base, index, (LIR_Address::Scale)shift, type);
250 if (disp == 0 && embedded_shift) {
251 // can use ldr/str instruction with register index
252 return addr;
253 } else {
254 LIR_Opr tmp = new_pointer_register();
255 __ add(base, LIR_OprFact::address(addr), tmp); // add with shifted/extended register
256 return new LIR_Address(tmp, disp, type);
257 }
258 }
259
260 // If the displacement is too large to be inlined into LDR instruction,
261 // generate large constant with additional sequence of ADD instructions
262 int excess_disp = disp & ~(max_disp - 1);
263 if (excess_disp != 0) {
264 LIR_Opr tmp = new_pointer_register();
265 add_large_constant(base, excess_disp, tmp);
266 base = tmp;
267 }
268 return new LIR_Address(base, disp & (max_disp - 1), type);
269 }
270
271
272 LIR_Address* LIRGenerator::emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr, BasicType type) {
273 int base_offset = arrayOopDesc::base_offset_in_bytes(type);
274 int elem_size = type2aelembytes(type);
275
276 if (index_opr->is_constant()) {
277 int offset = base_offset + index_opr->as_constant_ptr()->as_jint() * elem_size;
278 return generate_address(array_opr, offset, type);
279 } else {
280 assert(index_opr->is_register(), "must be");
281 int scale = exact_log2(elem_size);
282 return generate_address(array_opr, index_opr, scale, base_offset, type);
283 }
284 }
285
286
287 LIR_Opr LIRGenerator::load_immediate(jlong x, BasicType type) {
288 assert(type == T_LONG || type == T_INT, "should be");
289 LIR_Opr r = make_constant(type, x);
290 bool imm_in_range = AsmOperand::is_rotated_imm((unsigned int)(x));
291 if (!imm_in_range) {
292 LIR_Opr tmp = new_register(type);
293 __ move(r, tmp);
294 return tmp;
295 }
296 return r;
297 }
298
299
300 void LIRGenerator::increment_counter(address counter, BasicType type, int step) {
301 LIR_Opr pointer = new_pointer_register();
302 __ move(LIR_OprFact::intptrConst(counter), pointer);
303 LIR_Address* addr = new LIR_Address(pointer, type);
304 increment_counter(addr, step);
305 }
306
307
308 void LIRGenerator::increment_counter(LIR_Address* addr, int step) {
309 LIR_Opr temp = new_register(addr->type());
310 __ move(addr, temp);
311 __ add(temp, make_constant(addr->type(), step), temp);
312 __ move(temp, addr);
313 }
314
315
316 void LIRGenerator::cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info) {
317 __ load(new LIR_Address(base, disp, T_INT), FrameMap::LR_opr, info);
318 __ cmp(condition, FrameMap::LR_opr, c);
319 }
320
321
322 void LIRGenerator::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, int disp, BasicType type, CodeEmitInfo* info) {
323 __ load(new LIR_Address(base, disp, type), FrameMap::LR_opr, info);
324 __ cmp(condition, reg, FrameMap::LR_opr);
325 }
326
327
328 bool LIRGenerator::strength_reduce_multiply(LIR_Opr left, jint c, LIR_Opr result, LIR_Opr tmp) {
329 assert(left != result, "should be different registers");
330 juint u_value = (juint)c;
331 if (is_power_of_2(u_value + 1)) {
332 LIR_Address::Scale scale = (LIR_Address::Scale) log2i_exact(u_value + 1);
333 LIR_Address* addr = new LIR_Address(left, left, scale, 0, T_INT);
334 __ sub(LIR_OprFact::address(addr), left, result); // rsb with shifted register
335 return true;
336 } else if (is_power_of_2(u_value - 1)) {
337 LIR_Address::Scale scale = (LIR_Address::Scale) log2i_exact(u_value - 1);
338 LIR_Address* addr = new LIR_Address(left, left, scale, 0, T_INT);
339 __ add(left, LIR_OprFact::address(addr), result); // add with shifted register
340 return true;
341 } else if (c == -1) {
342 __ negate(left, result);
343 return true;
344 }
345 return false;
346 }
347
348
349 void LIRGenerator::store_stack_parameter(LIR_Opr item, ByteSize offset_from_sp) {
350 assert(item->type() == T_INT, "other types are not expected");
351 __ store(item, new LIR_Address(FrameMap::SP_opr, in_bytes(offset_from_sp), item->type()));
352 }
353
354 void LIRGenerator::set_card(LIR_Opr value, LIR_Address* card_addr) {
355 assert(CardTable::dirty_card_val() == 0,
356 "Cannot use the register containing the card table base address directly");
357 if((ci_card_table_address_as<intx>() & 0xff) == 0) {
358 // If the card table base address is aligned to 256 bytes, we can use the register
359 // that contains the card_table_base_address.
360 __ move(value, card_addr);
361 } else {
362 // Otherwise we need to create a register containing that value.
363 LIR_Opr tmp_zero = new_register(T_INT);
364 __ move(LIR_OprFact::intConst(CardTable::dirty_card_val()), tmp_zero);
365 __ move(tmp_zero, card_addr);
366 }
367 }
368
369 void LIRGenerator::CardTableBarrierSet_post_barrier_helper(LIR_Opr addr, LIR_Const* card_table_base) {
370 assert(addr->is_register(), "must be a register at this point");
371
372 LIR_Opr tmp = FrameMap::LR_ptr_opr;
373
374 bool load_card_table_base_const = VM_Version::supports_movw();
375 if (load_card_table_base_const) {
376 __ move((LIR_Opr)card_table_base, tmp);
377 } else {
378 __ move(new LIR_Address(FrameMap::Rthread_opr, in_bytes(JavaThread::card_table_base_offset()), T_ADDRESS), tmp);
379 }
380
381 // Use unsigned type T_BOOLEAN here rather than (signed) T_BYTE since signed load
382 // byte instruction does not support the addressing mode we need.
383 LIR_Address* card_addr = new LIR_Address(tmp, addr, (LIR_Address::Scale) -CardTable::card_shift(), 0, T_BOOLEAN);
384 if (UseCondCardMark) {
385 LIR_Opr cur_value = new_register(T_INT);
386 __ move(card_addr, cur_value);
387
388 LabelObj* L_already_dirty = new LabelObj();
389 __ cmp(lir_cond_equal, cur_value, LIR_OprFact::intConst(CardTable::dirty_card_val()));
390 __ branch(lir_cond_equal, L_already_dirty->label());
391 set_card(tmp, card_addr);
392 __ branch_destination(L_already_dirty->label());
393 } else {
394 set_card(tmp, card_addr);
395 }
396 }
397
398 void LIRGenerator::array_store_check(LIR_Opr value, LIR_Opr array, CodeEmitInfo* store_check_info, ciMethod* profiled_method, int profiled_bci) {
399 LIR_Opr tmp1 = FrameMap::R0_oop_opr;
400 LIR_Opr tmp2 = FrameMap::R1_oop_opr;
401 LIR_Opr tmp3 = LIR_OprFact::illegalOpr;
402 __ store_check(value, array, tmp1, tmp2, tmp3, store_check_info, profiled_method, profiled_bci);
403 }
404
405 //----------------------------------------------------------------------
406 // visitor functions
407 //----------------------------------------------------------------------
408
409 void LIRGenerator::do_MonitorEnter(MonitorEnter* x) {
410 assert(x->is_pinned(),"");
411 LIRItem obj(x->obj(), this);
412 obj.load_item();
413 set_no_result(x);
414
415 LIR_Opr lock = new_pointer_register();
416 LIR_Opr hdr = new_pointer_register();
417
418 CodeEmitInfo* info_for_exception = nullptr;
419 if (x->needs_null_check()) {
420 info_for_exception = state_for(x);
421 }
422
423 CodeEmitInfo* info = state_for(x, x->state(), true);
424 monitor_enter(obj.result(), lock, hdr, LIR_OprFact::illegalOpr,
425 x->monitor_no(), info_for_exception, info);
426 }
427
428
429 void LIRGenerator::do_MonitorExit(MonitorExit* x) {
430 assert(x->is_pinned(),"");
431 LIRItem obj(x->obj(), this);
432 obj.dont_load_item();
433 set_no_result(x);
434
435 LIR_Opr obj_temp = new_pointer_register();
436 LIR_Opr lock = new_pointer_register();
437 LIR_Opr hdr = new_pointer_register();
438
439 monitor_exit(obj_temp, lock, hdr, atomicLockOpr(), x->monitor_no());
440 }
441
442
443 // _ineg, _lneg, _fneg, _dneg
444 void LIRGenerator::do_NegateOp(NegateOp* x) {
445 #ifdef __SOFTFP__
446 address runtime_func = nullptr;
447 ValueTag tag = x->type()->tag();
448 if (tag == floatTag) {
449 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::fneg);
450 } else if (tag == doubleTag) {
451 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::dneg);
452 }
453 if (runtime_func != nullptr) {
454 set_result(x, call_runtime(x->x(), runtime_func, x->type(), nullptr));
455 return;
456 }
457 #endif // __SOFTFP__
458 LIRItem value(x->x(), this);
459 value.load_item();
460 LIR_Opr reg = rlock_result(x);
461 __ negate(value.result(), reg);
462 }
463
464
465 // for _fadd, _fmul, _fsub, _fdiv, _frem
466 // _dadd, _dmul, _dsub, _ddiv, _drem
467 void LIRGenerator::do_ArithmeticOp_FPU(ArithmeticOp* x) {
468 address runtime_func;
469 switch (x->op()) {
470 case Bytecodes::_frem:
471 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::frem);
472 break;
473 case Bytecodes::_drem:
474 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::drem);
475 break;
476 #ifdef __SOFTFP__
477 // Call function compiled with -msoft-float.
478
479 // __aeabi_XXXX_glibc: Imported code from glibc soft-fp bundle for calculation accuracy improvement. See CR 6757269.
480
481 case Bytecodes::_fadd:
482 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_fadd_glibc);
483 break;
484 case Bytecodes::_fmul:
485 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_fmul);
486 break;
487 case Bytecodes::_fsub:
488 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_fsub_glibc);
489 break;
490 case Bytecodes::_fdiv:
491 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_fdiv);
492 break;
493 case Bytecodes::_dadd:
494 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_dadd_glibc);
495 break;
496 case Bytecodes::_dmul:
497 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_dmul);
498 break;
499 case Bytecodes::_dsub:
500 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_dsub_glibc);
501 break;
502 case Bytecodes::_ddiv:
503 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_ddiv);
504 break;
505 default:
506 ShouldNotReachHere();
507 #else // __SOFTFP__
508 default: {
509 LIRItem left(x->x(), this);
510 LIRItem right(x->y(), this);
511 left.load_item();
512 right.load_item();
513 rlock_result(x);
514 arithmetic_op_fpu(x->op(), x->operand(), left.result(), right.result());
515 return;
516 }
517 #endif // __SOFTFP__
518 }
519
520 LIR_Opr result = call_runtime(x->x(), x->y(), runtime_func, x->type(), nullptr);
521 set_result(x, result);
522 }
523
524
525 void LIRGenerator::make_div_by_zero_check(LIR_Opr right_arg, BasicType type, CodeEmitInfo* info) {
526 assert(right_arg->is_register(), "must be");
527 __ cmp(lir_cond_equal, right_arg, make_constant(type, 0));
528 __ branch(lir_cond_equal, new DivByZeroStub(info));
529 }
530
531
532 // for _ladd, _lmul, _lsub, _ldiv, _lrem
533 void LIRGenerator::do_ArithmeticOp_Long(ArithmeticOp* x) {
534 CodeEmitInfo* info = nullptr;
535 if (x->op() == Bytecodes::_ldiv || x->op() == Bytecodes::_lrem) {
536 info = state_for(x);
537 }
538
539 switch (x->op()) {
540 case Bytecodes::_ldiv:
541 case Bytecodes::_lrem: {
542 LIRItem right(x->y(), this);
543 right.load_item();
544 make_div_by_zero_check(right.result(), T_LONG, info);
545 }
546 // Fall through
547 case Bytecodes::_lmul: {
548 address entry;
549 switch (x->op()) {
550 case Bytecodes::_lrem:
551 entry = CAST_FROM_FN_PTR(address, SharedRuntime::lrem);
552 break;
553 case Bytecodes::_ldiv:
554 entry = CAST_FROM_FN_PTR(address, SharedRuntime::ldiv);
555 break;
556 case Bytecodes::_lmul:
557 entry = CAST_FROM_FN_PTR(address, SharedRuntime::lmul);
558 break;
559 default:
560 ShouldNotReachHere();
561 return;
562 }
563 LIR_Opr result = call_runtime(x->y(), x->x(), entry, x->type(), nullptr);
564 set_result(x, result);
565 break;
566 }
567 case Bytecodes::_ladd:
568 case Bytecodes::_lsub: {
569 LIRItem left(x->x(), this);
570 LIRItem right(x->y(), this);
571 left.load_item();
572 right.load_item();
573 rlock_result(x);
574 arithmetic_op_long(x->op(), x->operand(), left.result(), right.result(), nullptr);
575 break;
576 }
577 default:
578 ShouldNotReachHere();
579 }
580 }
581
582
583 // for: _iadd, _imul, _isub, _idiv, _irem
584 void LIRGenerator::do_ArithmeticOp_Int(ArithmeticOp* x) {
585 bool is_div_rem = x->op() == Bytecodes::_idiv || x->op() == Bytecodes::_irem;
586 LIRItem left(x->x(), this);
587 LIRItem right(x->y(), this);
588 LIRItem* left_arg = &left;
589 LIRItem* right_arg = &right;
590
591 // Test if instr is commutative and if we should swap
592 if (x->is_commutative() && left.is_constant()) {
593 left_arg = &right;
594 right_arg = &left;
595 }
596
597 if (is_div_rem) {
598 CodeEmitInfo* info = state_for(x);
599 if (x->op() == Bytecodes::_idiv && right_arg->is_constant() && is_power_of_2(right_arg->get_jint_constant())) {
600 left_arg->load_item();
601 right_arg->dont_load_item();
602 LIR_Opr tmp = LIR_OprFact::illegalOpr;
603 LIR_Opr result = rlock_result(x);
604 __ idiv(left_arg->result(), right_arg->result(), result, tmp, info);
605 } else {
606 left_arg->load_item_force(FrameMap::R0_opr);
607 right_arg->load_item_force(FrameMap::R2_opr);
608 LIR_Opr tmp = FrameMap::R1_opr;
609 LIR_Opr result = rlock_result(x);
610 LIR_Opr out_reg;
611 if (x->op() == Bytecodes::_irem) {
612 out_reg = FrameMap::R0_opr;
613 __ irem(left_arg->result(), right_arg->result(), out_reg, tmp, info);
614 } else { // (x->op() == Bytecodes::_idiv)
615 out_reg = FrameMap::R1_opr;
616 __ idiv(left_arg->result(), right_arg->result(), out_reg, tmp, info);
617 }
618 __ move(out_reg, result);
619 }
620
621
622 } else {
623 left_arg->load_item();
624 if (x->op() == Bytecodes::_imul && right_arg->is_constant()) {
625 jint c = right_arg->get_jint_constant();
626 if (c > 0 && c < max_jint && (is_power_of_2(c) || is_power_of_2(c - 1) || is_power_of_2(c + 1))) {
627 right_arg->dont_load_item();
628 } else {
629 right_arg->load_item();
630 }
631 } else {
632 right_arg->load_nonconstant();
633 }
634 rlock_result(x);
635 assert(right_arg->is_constant() || right_arg->is_register(), "wrong state of right");
636 arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), LIR_OprFact::nullOpr);
637 }
638 }
639
640
641 void LIRGenerator::do_ArithmeticOp(ArithmeticOp* x) {
642 ValueTag tag = x->type()->tag();
643 assert(x->x()->type()->tag() == tag && x->y()->type()->tag() == tag, "wrong parameters");
644 switch (tag) {
645 case floatTag:
646 case doubleTag: do_ArithmeticOp_FPU(x); return;
647 case longTag: do_ArithmeticOp_Long(x); return;
648 case intTag: do_ArithmeticOp_Int(x); return;
649 default: ShouldNotReachHere(); return;
650 }
651 }
652
653
654 // _ishl, _lshl, _ishr, _lshr, _iushr, _lushr
655 void LIRGenerator::do_ShiftOp(ShiftOp* x) {
656 LIRItem value(x->x(), this);
657 LIRItem count(x->y(), this);
658
659 if (value.type()->is_long()) {
660 count.set_destroys_register();
661 }
662
663 if (count.is_constant()) {
664 assert(count.type()->as_IntConstant() != nullptr, "should be");
665 count.dont_load_item();
666 } else {
667 count.load_item();
668 }
669 value.load_item();
670
671 LIR_Opr res = rlock_result(x);
672 shift_op(x->op(), res, value.result(), count.result(), LIR_OprFact::illegalOpr);
673 }
674
675
676 // _iand, _land, _ior, _lor, _ixor, _lxor
677 void LIRGenerator::do_LogicOp(LogicOp* x) {
678 LIRItem left(x->x(), this);
679 LIRItem right(x->y(), this);
680
681 left.load_item();
682
683 right.load_nonconstant();
684
685 logic_op(x->op(), rlock_result(x), left.result(), right.result());
686 }
687
688
689 // _lcmp, _fcmpl, _fcmpg, _dcmpl, _dcmpg
690 void LIRGenerator::do_CompareOp(CompareOp* x) {
691 #ifdef __SOFTFP__
692 address runtime_func;
693 switch (x->op()) {
694 case Bytecodes::_fcmpl:
695 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::fcmpl);
696 break;
697 case Bytecodes::_fcmpg:
698 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::fcmpg);
699 break;
700 case Bytecodes::_dcmpl:
701 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::dcmpl);
702 break;
703 case Bytecodes::_dcmpg:
704 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::dcmpg);
705 break;
706 case Bytecodes::_lcmp: {
707 LIRItem left(x->x(), this);
708 LIRItem right(x->y(), this);
709 left.load_item();
710 right.load_nonconstant();
711 LIR_Opr reg = rlock_result(x);
712 __ lcmp2int(left.result(), right.result(), reg);
713 return;
714 }
715 default:
716 ShouldNotReachHere();
717 }
718 LIR_Opr result = call_runtime(x->x(), x->y(), runtime_func, x->type(), nullptr);
719 set_result(x, result);
720 #else // __SOFTFP__
721 LIRItem left(x->x(), this);
722 LIRItem right(x->y(), this);
723 left.load_item();
724
725 right.load_nonconstant();
726
727 LIR_Opr reg = rlock_result(x);
728
729 if (x->x()->type()->is_float_kind()) {
730 Bytecodes::Code code = x->op();
731 __ fcmp2int(left.result(), right.result(), reg, (code == Bytecodes::_fcmpl || code == Bytecodes::_dcmpl));
732 } else if (x->x()->type()->tag() == longTag) {
733 __ lcmp2int(left.result(), right.result(), reg);
734 } else {
735 ShouldNotReachHere();
736 }
737 #endif // __SOFTFP__
738 }
739
740 LIR_Opr LIRGenerator::atomic_cmpxchg(BasicType type, LIR_Opr addr, LIRItem& cmp_value, LIRItem& new_value) {
741 LIR_Opr ill = LIR_OprFact::illegalOpr; // for convenience
742 LIR_Opr tmp1 = LIR_OprFact::illegalOpr;
743 LIR_Opr tmp2 = LIR_OprFact::illegalOpr;
744 new_value.load_item();
745 cmp_value.load_item();
746 LIR_Opr result = new_register(T_INT);
747 if (type == T_OBJECT || type == T_ARRAY) {
748 __ cas_obj(addr, cmp_value.result(), new_value.result(), new_register(T_INT), new_register(T_INT), result);
749 } else if (type == T_INT) {
750 __ cas_int(addr->as_address_ptr()->base(), cmp_value.result(), new_value.result(), tmp1, tmp1, result);
751 } else if (type == T_LONG) {
752 tmp1 = new_register(T_LONG);
753 __ cas_long(addr->as_address_ptr()->base(), cmp_value.result(), new_value.result(), tmp1, tmp2, result);
754 } else {
755 ShouldNotReachHere();
756 }
757 return result;
758 }
759
760 LIR_Opr LIRGenerator::atomic_xchg(BasicType type, LIR_Opr addr, LIRItem& value) {
761 bool is_oop = type == T_OBJECT || type == T_ARRAY;
762 LIR_Opr result = new_register(type);
763 value.load_item();
764 assert(type == T_INT || is_oop || (type == T_LONG && VM_Version::supports_ldrexd()), "unexpected type");
765 LIR_Opr tmp = (UseCompressedOops && is_oop) ? new_pointer_register() : LIR_OprFact::illegalOpr;
766 __ xchg(addr, value.result(), result, tmp);
767 return result;
768 }
769
770 LIR_Opr LIRGenerator::atomic_add(BasicType type, LIR_Opr addr, LIRItem& value) {
771 LIR_Opr result = new_register(type);
772 value.load_item();
773 assert(type == T_INT || (type == T_LONG && VM_Version::supports_ldrexd ()), "unexpected type");
774 LIR_Opr tmp = new_register(type);
775 __ xadd(addr, value.result(), result, tmp);
776 return result;
777 }
778
779 void LIRGenerator::do_MathIntrinsic(Intrinsic* x) {
780 address runtime_func;
781 switch (x->id()) {
782 case vmIntrinsics::_dabs: {
783 #ifdef __SOFTFP__
784 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::dabs);
785 break;
786 #else
787 assert(x->number_of_arguments() == 1, "wrong type");
788 LIRItem value(x->argument_at(0), this);
789 value.load_item();
790 __ abs(value.result(), rlock_result(x), LIR_OprFact::illegalOpr);
791 return;
792 #endif // __SOFTFP__
793 }
794 case vmIntrinsics::_dsqrt:
795 case vmIntrinsics::_dsqrt_strict: {
796 #ifdef __SOFTFP__
797 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::dsqrt);
798 break;
799 #else
800 assert(x->number_of_arguments() == 1, "wrong type");
801 LIRItem value(x->argument_at(0), this);
802 value.load_item();
803 __ sqrt(value.result(), rlock_result(x), LIR_OprFact::illegalOpr);
804 return;
805 #endif // __SOFTFP__
806 }
807 case vmIntrinsics::_dsin:
808 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::dsin);
809 break;
810 case vmIntrinsics::_dcos:
811 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::dcos);
812 break;
813 case vmIntrinsics::_dtan:
814 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::dtan);
815 break;
816 case vmIntrinsics::_dlog:
817 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::dlog);
818 break;
819 case vmIntrinsics::_dlog10:
820 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::dlog10);
821 break;
822 case vmIntrinsics::_dexp:
823 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::dexp);
824 break;
825 case vmIntrinsics::_dpow:
826 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::dpow);
827 break;
828 default:
829 ShouldNotReachHere();
830 return;
831 }
832
833 LIR_Opr result;
834 if (x->number_of_arguments() == 1) {
835 result = call_runtime(x->argument_at(0), runtime_func, x->type(), nullptr);
836 } else {
837 assert(x->number_of_arguments() == 2 && x->id() == vmIntrinsics::_dpow, "unexpected intrinsic");
838 result = call_runtime(x->argument_at(0), x->argument_at(1), runtime_func, x->type(), nullptr);
839 }
840 set_result(x, result);
841 }
842
843 void LIRGenerator::do_FmaIntrinsic(Intrinsic* x) {
844 fatal("FMA intrinsic is not implemented on this platform");
845 }
846
847 void LIRGenerator::do_vectorizedMismatch(Intrinsic* x) {
848 fatal("vectorizedMismatch intrinsic is not implemented on this platform");
849 }
850
851 void LIRGenerator::do_ArrayCopy(Intrinsic* x) {
852 CodeEmitInfo* info = state_for(x, x->state());
853 assert(x->number_of_arguments() == 5, "wrong type");
854 LIRItem src(x->argument_at(0), this);
855 LIRItem src_pos(x->argument_at(1), this);
856 LIRItem dst(x->argument_at(2), this);
857 LIRItem dst_pos(x->argument_at(3), this);
858 LIRItem length(x->argument_at(4), this);
859
860 // We put arguments into the same registers which are used for a Java call.
861 // Note: we used fixed registers for all arguments because all registers
862 // are caller-saved, so register allocator treats them all as used.
863 src.load_item_force (FrameMap::R0_oop_opr);
864 src_pos.load_item_force(FrameMap::R1_opr);
865 dst.load_item_force (FrameMap::R2_oop_opr);
866 dst_pos.load_item_force(FrameMap::R3_opr);
867 length.load_item_force (FrameMap::R4_opr);
868 LIR_Opr tmp = (FrameMap::R5_opr);
869 set_no_result(x);
870
871 int flags;
872 ciArrayKlass* expected_type;
873 arraycopy_helper(x, &flags, &expected_type);
874 __ arraycopy(src.result(), src_pos.result(), dst.result(), dst_pos.result(), length.result(),
875 tmp, expected_type, flags, info);
876 }
877
878 void LIRGenerator::do_update_CRC32(Intrinsic* x) {
879 fatal("CRC32 intrinsic is not implemented on this platform");
880 }
881
882 void LIRGenerator::do_update_CRC32C(Intrinsic* x) {
883 Unimplemented();
884 }
885
886 void LIRGenerator::do_Convert(Convert* x) {
887 address runtime_func;
888 switch (x->op()) {
889 case Bytecodes::_l2f:
890 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::l2f);
891 break;
892 case Bytecodes::_l2d:
893 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::l2d);
894 break;
895 case Bytecodes::_f2l:
896 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::f2l);
897 break;
898 case Bytecodes::_d2l:
899 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::d2l);
900 break;
901 #ifdef __SOFTFP__
902 case Bytecodes::_f2d:
903 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_f2d);
904 break;
905 case Bytecodes::_d2f:
906 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_d2f);
907 break;
908 case Bytecodes::_i2f:
909 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_i2f);
910 break;
911 case Bytecodes::_i2d:
912 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_i2d);
913 break;
914 case Bytecodes::_f2i:
915 runtime_func = CAST_FROM_FN_PTR(address, __aeabi_f2iz);
916 break;
917 case Bytecodes::_d2i:
918 // This is implemented in hard float in assembler on arm but a call
919 // on other platforms.
920 runtime_func = CAST_FROM_FN_PTR(address, SharedRuntime::d2i);
921 break;
922 #endif // __SOFTFP__
923 default: {
924 LIRItem value(x->value(), this);
925 value.load_item();
926 LIR_Opr reg = rlock_result(x);
927 __ convert(x->op(), value.result(), reg);
928 return;
929 }
930 }
931
932 LIR_Opr result = call_runtime(x->value(), runtime_func, x->type(), nullptr);
933 set_result(x, result);
934 }
935
936
937 void LIRGenerator::do_NewInstance(NewInstance* x) {
938 print_if_not_loaded(x);
939
940 CodeEmitInfo* info = state_for(x, x->state());
941 LIR_Opr reg = result_register_for(x->type()); // R0 is required by runtime call in NewInstanceStub::emit_code
942 LIR_Opr klass_reg = FrameMap::R1_metadata_opr; // R1 is required by runtime call in NewInstanceStub::emit_code
943 LIR_Opr tmp1 = new_register(objectType);
944 LIR_Opr tmp2 = new_register(objectType);
945 LIR_Opr tmp3 = FrameMap::LR_oop_opr;
946
947 new_instance(reg, x->klass(), x->is_unresolved(), /* allow_inline */ false, tmp1, tmp2, tmp3,
948 LIR_OprFact::illegalOpr, klass_reg, info);
949
950 LIR_Opr result = rlock_result(x);
951 __ move(reg, result);
952 }
953
954
955 void LIRGenerator::do_NewTypeArray(NewTypeArray* x) {
956 // Evaluate state_for() first, because it can emit code
957 // with the same fixed registers that are used here (R1, R2)
958 CodeEmitInfo* info = state_for(x, x->state());
959 LIRItem length(x->length(), this);
960
961 length.load_item_force(FrameMap::R2_opr); // R2 is required by runtime call in NewTypeArrayStub::emit_code
962 LIR_Opr len = length.result();
963
964 LIR_Opr reg = result_register_for(x->type()); // R0 is required by runtime call in NewTypeArrayStub::emit_code
965 LIR_Opr klass_reg = FrameMap::R1_metadata_opr; // R1 is required by runtime call in NewTypeArrayStub::emit_code
966
967 LIR_Opr tmp1 = new_register(objectType);
968 LIR_Opr tmp2 = new_register(objectType);
969 LIR_Opr tmp3 = FrameMap::LR_oop_opr;
970 LIR_Opr tmp4 = LIR_OprFact::illegalOpr;
971
972 BasicType elem_type = x->elt_type();
973 __ metadata2reg(ciTypeArrayKlass::make(elem_type)->constant_encoding(), klass_reg);
974
975 CodeStub* slow_path = new NewTypeArrayStub(klass_reg, len, reg, info);
976 __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, elem_type, klass_reg, slow_path);
977
978 LIR_Opr result = rlock_result(x);
979 __ move(reg, result);
980 }
981
982
983 void LIRGenerator::do_NewObjectArray(NewObjectArray* x) {
984 // Evaluate state_for() first, because it can emit code
985 // with the same fixed registers that are used here (R1, R2)
986 CodeEmitInfo* info = state_for(x, x->state());
987 LIRItem length(x->length(), this);
988
989 length.load_item_force(FrameMap::R2_opr); // R2 is required by runtime call in NewObjectArrayStub::emit_code
990 LIR_Opr len = length.result();
991
992 CodeEmitInfo* patching_info = nullptr;
993 if (!x->klass()->is_loaded() || PatchALot) {
994 patching_info = state_for(x, x->state_before());
995 }
996
997 LIR_Opr reg = result_register_for(x->type()); // R0 is required by runtime call in NewObjectArrayStub::emit_code
998 LIR_Opr klass_reg = FrameMap::R1_metadata_opr; // R1 is required by runtime call in NewObjectArrayStub::emit_code
999
1000 LIR_Opr tmp1 = new_register(objectType);
1001 LIR_Opr tmp2 = new_register(objectType);
1002 LIR_Opr tmp3 = FrameMap::LR_oop_opr;
1003 LIR_Opr tmp4 = LIR_OprFact::illegalOpr;
1004
1005 CodeStub* slow_path = new NewObjectArrayStub(klass_reg, len, reg, info);
1006 ciMetadata* obj = ciObjArrayKlass::make(x->klass());
1007 if (obj == ciEnv::unloaded_ciobjarrayklass()) {
1008 BAILOUT("encountered unloaded_ciobjarrayklass due to out of memory error");
1009 }
1010 klass2reg_with_patching(klass_reg, obj, patching_info);
1011 __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, T_OBJECT, klass_reg, slow_path);
1012
1013 LIR_Opr result = rlock_result(x);
1014 __ move(reg, result);
1015 }
1016
1017
1018 void LIRGenerator::do_NewMultiArray(NewMultiArray* x) {
1019 Values* dims = x->dims();
1020 int i = dims->length();
1021 LIRItemList* items = new LIRItemList(i, i, nullptr);
1022 while (i-- > 0) {
1023 LIRItem* size = new LIRItem(dims->at(i), this);
1024 items->at_put(i, size);
1025 }
1026
1027 // Need to get the info before, as the items may become invalid through item_free
1028 CodeEmitInfo* patching_info = nullptr;
1029 if (!x->klass()->is_loaded() || PatchALot) {
1030 patching_info = state_for(x, x->state_before());
1031
1032 // Cannot re-use same xhandlers for multiple CodeEmitInfos, so
1033 // clone all handlers (NOTE: Usually this is handled transparently
1034 // by the CodeEmitInfo cloning logic in CodeStub constructors but
1035 // is done explicitly here because a stub isn't being used).
1036 x->set_exception_handlers(new XHandlers(x->exception_handlers()));
1037 }
1038
1039 i = dims->length();
1040 while (i-- > 0) {
1041 LIRItem* size = items->at(i);
1042 size->load_item();
1043 LIR_Opr sz = size->result();
1044 assert(sz->type() == T_INT, "should be");
1045 store_stack_parameter(sz, in_ByteSize(i * BytesPerInt));
1046 }
1047
1048 CodeEmitInfo* info = state_for(x, x->state());
1049 LIR_Opr klass_reg = FrameMap::R0_metadata_opr;
1050 klass2reg_with_patching(klass_reg, x->klass(), patching_info);
1051
1052 LIR_Opr rank = FrameMap::R2_opr;
1053 __ move(LIR_OprFact::intConst(x->rank()), rank);
1054 LIR_Opr varargs = FrameMap::SP_opr;
1055 LIR_OprList* args = new LIR_OprList(3);
1056 args->append(klass_reg);
1057 args->append(rank);
1058 args->append(varargs);
1059 LIR_Opr reg = result_register_for(x->type());
1060 __ call_runtime(Runtime1::entry_for(StubId::c1_new_multi_array_id),
1061 LIR_OprFact::illegalOpr, reg, args, info);
1062
1063 LIR_Opr result = rlock_result(x);
1064 __ move(reg, result);
1065 }
1066
1067
1068 void LIRGenerator::do_BlockBegin(BlockBegin* x) {
1069 // nothing to do for now
1070 }
1071
1072
1073 void LIRGenerator::do_CheckCast(CheckCast* x) {
1074 LIRItem obj(x->obj(), this);
1075 CodeEmitInfo* patching_info = nullptr;
1076 if (!x->klass()->is_loaded() || (PatchALot && !x->is_incompatible_class_change_check() && !x->is_invokespecial_receiver_check())) {
1077 patching_info = state_for(x, x->state_before());
1078 }
1079
1080 obj.load_item();
1081
1082 CodeEmitInfo* info_for_exception =
1083 (x->needs_exception_state() ? state_for(x) :
1084 state_for(x, x->state_before(), true /*ignore_xhandler*/));
1085
1086 CodeStub* stub;
1087 if (x->is_incompatible_class_change_check()) {
1088 assert(patching_info == nullptr, "can't patch this");
1089 stub = new SimpleExceptionStub(StubId::c1_throw_incompatible_class_change_error_id,
1090 LIR_OprFact::illegalOpr, info_for_exception);
1091 } else if (x->is_invokespecial_receiver_check()) {
1092 assert(patching_info == nullptr, "can't patch this");
1093 stub = new DeoptimizeStub(info_for_exception,
1094 Deoptimization::Reason_class_check,
1095 Deoptimization::Action_none);
1096 } else {
1097 stub = new SimpleExceptionStub(StubId::c1_throw_class_cast_exception_id,
1098 LIR_OprFact::illegalOpr, info_for_exception);
1099 }
1100
1101 LIR_Opr out_reg = rlock_result(x);
1102 LIR_Opr tmp1 = FrameMap::R0_oop_opr;
1103 LIR_Opr tmp2 = FrameMap::R1_oop_opr;
1104 LIR_Opr tmp3 = LIR_OprFact::illegalOpr;
1105
1106 __ checkcast(out_reg, obj.result(), x->klass(), tmp1, tmp2, tmp3, x->direct_compare(),
1107 info_for_exception, patching_info, stub,
1108 x->profiled_method(), x->profiled_bci(), /*is_null_free*/ false);
1109 }
1110
1111
1112 void LIRGenerator::do_InstanceOf(InstanceOf* x) {
1113 LIRItem obj(x->obj(), this);
1114 CodeEmitInfo* patching_info = nullptr;
1115 if (!x->klass()->is_loaded() || PatchALot) {
1116 patching_info = state_for(x, x->state_before());
1117 }
1118
1119 obj.load_item();
1120 LIR_Opr out_reg = rlock_result(x);
1121 LIR_Opr tmp1 = FrameMap::R0_oop_opr;
1122 LIR_Opr tmp2 = FrameMap::R1_oop_opr;
1123 LIR_Opr tmp3 = LIR_OprFact::illegalOpr;
1124
1125 __ instanceof(out_reg, obj.result(), x->klass(), tmp1, tmp2, tmp3,
1126 x->direct_compare(), patching_info, x->profiled_method(), x->profiled_bci());
1127 }
1128
1129 // Intrinsic for Class::isInstance
1130 address LIRGenerator::isInstance_entry() {
1131 return CAST_FROM_FN_PTR(address, Runtime1::is_instance_of);
1132 }
1133
1134
1135 #ifdef __SOFTFP__
1136 // Turn operator if (f <op> g) into runtime call:
1137 // call _aeabi_fcmp<op>(f, g)
1138 // cmp(eq, 1)
1139 // branch(eq, true path).
1140 void LIRGenerator::do_soft_float_compare(If* x) {
1141 assert(x->number_of_sux() == 2, "inconsistency");
1142 ValueTag tag = x->x()->type()->tag();
1143 If::Condition cond = x->cond();
1144 address runtime_func;
1145 // unordered comparison gets the wrong answer because aeabi functions
1146 // return false.
1147 bool unordered_is_true = x->unordered_is_true();
1148 // reverse of condition for ne
1149 bool compare_to_zero = false;
1150 switch (lir_cond(cond)) {
1151 case lir_cond_notEqual:
1152 compare_to_zero = true; // fall through
1153 case lir_cond_equal:
1154 runtime_func = tag == floatTag ?
1155 CAST_FROM_FN_PTR(address, __aeabi_fcmpeq):
1156 CAST_FROM_FN_PTR(address, __aeabi_dcmpeq);
1157 break;
1158 case lir_cond_less:
1159 if (unordered_is_true) {
1160 runtime_func = tag == floatTag ?
1161 CAST_FROM_FN_PTR(address, SharedRuntime::unordered_fcmplt):
1162 CAST_FROM_FN_PTR(address, SharedRuntime::unordered_dcmplt);
1163 } else {
1164 runtime_func = tag == floatTag ?
1165 CAST_FROM_FN_PTR(address, __aeabi_fcmplt):
1166 CAST_FROM_FN_PTR(address, __aeabi_dcmplt);
1167 }
1168 break;
1169 case lir_cond_lessEqual:
1170 if (unordered_is_true) {
1171 runtime_func = tag == floatTag ?
1172 CAST_FROM_FN_PTR(address, SharedRuntime::unordered_fcmple):
1173 CAST_FROM_FN_PTR(address, SharedRuntime::unordered_dcmple);
1174 } else {
1175 runtime_func = tag == floatTag ?
1176 CAST_FROM_FN_PTR(address, __aeabi_fcmple):
1177 CAST_FROM_FN_PTR(address, __aeabi_dcmple);
1178 }
1179 break;
1180 case lir_cond_greaterEqual:
1181 if (unordered_is_true) {
1182 runtime_func = tag == floatTag ?
1183 CAST_FROM_FN_PTR(address, SharedRuntime::unordered_fcmpge):
1184 CAST_FROM_FN_PTR(address, SharedRuntime::unordered_dcmpge);
1185 } else {
1186 runtime_func = tag == floatTag ?
1187 CAST_FROM_FN_PTR(address, __aeabi_fcmpge):
1188 CAST_FROM_FN_PTR(address, __aeabi_dcmpge);
1189 }
1190 break;
1191 case lir_cond_greater:
1192 if (unordered_is_true) {
1193 runtime_func = tag == floatTag ?
1194 CAST_FROM_FN_PTR(address, SharedRuntime::unordered_fcmpgt):
1195 CAST_FROM_FN_PTR(address, SharedRuntime::unordered_dcmpgt);
1196 } else {
1197 runtime_func = tag == floatTag ?
1198 CAST_FROM_FN_PTR(address, __aeabi_fcmpgt):
1199 CAST_FROM_FN_PTR(address, __aeabi_dcmpgt);
1200 }
1201 break;
1202 case lir_cond_aboveEqual:
1203 case lir_cond_belowEqual:
1204 ShouldNotReachHere(); // We're not going to get these.
1205 default:
1206 assert(lir_cond(cond) == lir_cond_always, "must be");
1207 ShouldNotReachHere();
1208 }
1209 set_no_result(x);
1210
1211 // add safepoint before generating condition code so it can be recomputed
1212 if (x->is_safepoint()) {
1213 increment_backedge_counter(state_for(x, x->state_before()), x->profiled_bci());
1214 __ safepoint(LIR_OprFact::illegalOpr, state_for(x, x->state_before()));
1215 }
1216 // Call float compare function, returns (1,0) if true or false.
1217 LIR_Opr result = call_runtime(x->x(), x->y(), runtime_func, intType, nullptr);
1218 __ cmp(lir_cond_equal, result,
1219 compare_to_zero ?
1220 LIR_OprFact::intConst(0) : LIR_OprFact::intConst(1));
1221 profile_branch(x, cond);
1222 move_to_phi(x->state());
1223 __ branch(lir_cond_equal, x->tsux());
1224 }
1225 #endif // __SOFTFP__
1226
1227 void LIRGenerator::do_If(If* x) {
1228 assert(x->number_of_sux() == 2, "inconsistency");
1229 ValueTag tag = x->x()->type()->tag();
1230
1231 #ifdef __SOFTFP__
1232 if (tag == floatTag || tag == doubleTag) {
1233 do_soft_float_compare(x);
1234 assert(x->default_sux() == x->fsux(), "wrong destination above");
1235 __ jump(x->default_sux());
1236 return;
1237 }
1238 #endif // __SOFTFP__
1239
1240 LIRItem xitem(x->x(), this);
1241 LIRItem yitem(x->y(), this);
1242 LIRItem* xin = &xitem;
1243 LIRItem* yin = &yitem;
1244 If::Condition cond = x->cond();
1245
1246 if (tag == longTag) {
1247 if (cond == If::gtr || cond == If::leq) {
1248 cond = Instruction::mirror(cond);
1249 xin = &yitem;
1250 yin = &xitem;
1251 }
1252 xin->set_destroys_register();
1253 }
1254
1255 xin->load_item();
1256 LIR_Opr left = xin->result();
1257 LIR_Opr right;
1258
1259 if (tag == longTag && yin->is_constant() && yin->get_jlong_constant() == 0 &&
1260 (cond == If::eql || cond == If::neq)) {
1261 // inline long zero
1262 right = LIR_OprFact::value_type(yin->value()->type());
1263 } else {
1264 yin->load_nonconstant();
1265 right = yin->result();
1266 }
1267
1268 set_no_result(x);
1269
1270 // add safepoint before generating condition code so it can be recomputed
1271 if (x->is_safepoint()) {
1272 increment_backedge_counter_conditionally(lir_cond(cond), left, right, state_for(x, x->state_before()),
1273 x->tsux()->bci(), x->fsux()->bci(), x->profiled_bci());
1274 __ safepoint(LIR_OprFact::illegalOpr, state_for(x, x->state_before()));
1275 }
1276
1277 __ cmp(lir_cond(cond), left, right);
1278 profile_branch(x, cond);
1279 move_to_phi(x->state());
1280 if (x->x()->type()->is_float_kind()) {
1281 __ branch(lir_cond(cond), x->tsux(), x->usux());
1282 } else {
1283 __ branch(lir_cond(cond), x->tsux());
1284 }
1285 assert(x->default_sux() == x->fsux(), "wrong destination above");
1286 __ jump(x->default_sux());
1287 }
1288
1289
1290 LIR_Opr LIRGenerator::getThreadPointer() {
1291 return FrameMap::Rthread_opr;
1292 }
1293
1294 void LIRGenerator::trace_block_entry(BlockBegin* block) {
1295 __ move(LIR_OprFact::intConst(block->block_id()), FrameMap::R0_opr);
1296 LIR_OprList* args = new LIR_OprList(1);
1297 args->append(FrameMap::R0_opr);
1298 address func = CAST_FROM_FN_PTR(address, Runtime1::trace_block_entry);
1299 __ call_runtime_leaf(func, getThreadTemp(), LIR_OprFact::illegalOpr, args);
1300 }
1301
1302
1303 void LIRGenerator::volatile_field_store(LIR_Opr value, LIR_Address* address,
1304 CodeEmitInfo* info) {
1305 if (value->is_double_cpu()) {
1306 assert(address->index()->is_illegal(), "should have a constant displacement");
1307 LIR_Address* store_addr = nullptr;
1308 if (address->disp() != 0) {
1309 LIR_Opr tmp = new_pointer_register();
1310 add_large_constant(address->base(), address->disp(), tmp);
1311 store_addr = new LIR_Address(tmp, (intx)0, address->type());
1312 } else {
1313 // address->disp() can be 0, if the address is referenced using the unsafe intrinsic
1314 store_addr = address;
1315 }
1316 __ volatile_store_mem_reg(value, store_addr, info);
1317 return;
1318 }
1319 __ store(value, address, info, lir_patch_none);
1320 }
1321
1322 void LIRGenerator::volatile_field_load(LIR_Address* address, LIR_Opr result,
1323 CodeEmitInfo* info) {
1324 if (result->is_double_cpu()) {
1325 assert(address->index()->is_illegal(), "should have a constant displacement");
1326 LIR_Address* load_addr = nullptr;
1327 if (address->disp() != 0) {
1328 LIR_Opr tmp = new_pointer_register();
1329 add_large_constant(address->base(), address->disp(), tmp);
1330 load_addr = new LIR_Address(tmp, (intx)0, address->type());
1331 } else {
1332 // address->disp() can be 0, if the address is referenced using the unsafe intrinsic
1333 load_addr = address;
1334 }
1335 __ volatile_load_mem_reg(load_addr, result, info);
1336 } else {
1337 __ load(address, result, info, lir_patch_none);
1338 }
1339 __ membar_acquire();
1340 }