Path: blob/master/src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp
64440 views
/*1* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "c1/c1_Compilation.hpp"26#include "c1/c1_FrameMap.hpp"27#include "c1/c1_Instruction.hpp"28#include "c1/c1_LIRAssembler.hpp"29#include "c1/c1_LIRGenerator.hpp"30#include "c1/c1_Runtime1.hpp"31#include "c1/c1_ValueStack.hpp"32#include "ci/ciArray.hpp"33#include "ci/ciObjArrayKlass.hpp"34#include "ci/ciTypeArrayKlass.hpp"35#include "gc/shared/c1/barrierSetC1.hpp"36#include "runtime/sharedRuntime.hpp"37#include "runtime/stubRoutines.hpp"38#include "utilities/powerOfTwo.hpp"39#include "vmreg_x86.inline.hpp"4041#ifdef ASSERT42#define __ gen()->lir(__FILE__, __LINE__)->43#else44#define __ gen()->lir()->45#endif4647// Item will be loaded into a byte register; Intel only48void LIRItem::load_byte_item() {49load_item();50LIR_Opr res = result();5152if (!res->is_virtual() || !_gen->is_vreg_flag_set(res, LIRGenerator::byte_reg)) {53// make sure that it is a byte register54assert(!value()->type()->is_float() && !value()->type()->is_double(),55"can't load floats in byte register");56LIR_Opr reg = _gen->rlock_byte(T_BYTE);57__ move(res, reg);5859_result = reg;60}61}626364void LIRItem::load_nonconstant() {65LIR_Opr r = value()->operand();66if (r->is_constant()) {67_result = r;68} else {69load_item();70}71}7273//--------------------------------------------------------------74// LIRGenerator75//--------------------------------------------------------------767778LIR_Opr LIRGenerator::exceptionOopOpr() { return FrameMap::rax_oop_opr; }79LIR_Opr LIRGenerator::exceptionPcOpr() { return FrameMap::rdx_opr; }80LIR_Opr LIRGenerator::divInOpr() { return FrameMap::rax_opr; }81LIR_Opr LIRGenerator::divOutOpr() { return FrameMap::rax_opr; }82LIR_Opr LIRGenerator::remOutOpr() { return FrameMap::rdx_opr; }83LIR_Opr LIRGenerator::shiftCountOpr() { return FrameMap::rcx_opr; }84LIR_Opr LIRGenerator::syncLockOpr() { return new_register(T_INT); }85LIR_Opr LIRGenerator::syncTempOpr() { return FrameMap::rax_opr; }86LIR_Opr LIRGenerator::getThreadTemp() { return LIR_OprFact::illegalOpr; }878889LIR_Opr LIRGenerator::result_register_for(ValueType* type, bool callee) {90LIR_Opr opr;91switch (type->tag()) {92case intTag: opr = FrameMap::rax_opr; break;93case objectTag: opr = FrameMap::rax_oop_opr; break;94case longTag: opr = FrameMap::long0_opr; break;95#ifdef _LP6496case floatTag: opr = FrameMap::xmm0_float_opr; break;97case doubleTag: opr = FrameMap::xmm0_double_opr; break;98#else99case floatTag: opr = UseSSE >= 1 ? FrameMap::xmm0_float_opr : FrameMap::fpu0_float_opr; break;100case doubleTag: opr = UseSSE >= 2 ? FrameMap::xmm0_double_opr : FrameMap::fpu0_double_opr; break;101#endif // _LP64102case addressTag:103default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr;104}105106assert(opr->type_field() == as_OprType(as_BasicType(type)), "type mismatch");107return opr;108}109110111LIR_Opr LIRGenerator::rlock_byte(BasicType type) {112LIR_Opr reg = new_register(T_INT);113set_vreg_flag(reg, LIRGenerator::byte_reg);114return reg;115}116117118//--------- loading items into registers --------------------------------119120121// i486 instructions can inline constants122bool LIRGenerator::can_store_as_constant(Value v, BasicType type) const {123if (type == T_SHORT || type == T_CHAR) {124// there is no immediate move of word values in asembler_i486.?pp125return false;126}127Constant* c = v->as_Constant();128if (c && c->state_before() == NULL) {129// constants of any type can be stored directly, except for130// unloaded object constants.131return true;132}133return false;134}135136137bool LIRGenerator::can_inline_as_constant(Value v) const {138if (v->type()->tag() == longTag) return false;139return v->type()->tag() != objectTag ||140(v->type()->is_constant() && v->type()->as_ObjectType()->constant_value()->is_null_object());141}142143144bool LIRGenerator::can_inline_as_constant(LIR_Const* c) const {145if (c->type() == T_LONG) return false;146return c->type() != T_OBJECT || c->as_jobject() == NULL;147}148149150LIR_Opr LIRGenerator::safepoint_poll_register() {151NOT_LP64( return new_register(T_ADDRESS); )152return LIR_OprFact::illegalOpr;153}154155156LIR_Address* LIRGenerator::generate_address(LIR_Opr base, LIR_Opr index,157int shift, int disp, BasicType type) {158assert(base->is_register(), "must be");159if (index->is_constant()) {160LIR_Const *constant = index->as_constant_ptr();161#ifdef _LP64162jlong c;163if (constant->type() == T_INT) {164c = (jlong(index->as_jint()) << shift) + disp;165} else {166assert(constant->type() == T_LONG, "should be");167c = (index->as_jlong() << shift) + disp;168}169if ((jlong)((jint)c) == c) {170return new LIR_Address(base, (jint)c, type);171} else {172LIR_Opr tmp = new_register(T_LONG);173__ move(index, tmp);174return new LIR_Address(base, tmp, type);175}176#else177return new LIR_Address(base,178((intx)(constant->as_jint()) << shift) + disp,179type);180#endif181} else {182return new LIR_Address(base, index, (LIR_Address::Scale)shift, disp, type);183}184}185186187LIR_Address* LIRGenerator::emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr,188BasicType type) {189int offset_in_bytes = arrayOopDesc::base_offset_in_bytes(type);190191LIR_Address* addr;192if (index_opr->is_constant()) {193int elem_size = type2aelembytes(type);194#ifdef _LP64195jint index = index_opr->as_jint();196jlong disp = offset_in_bytes + (jlong)(index) * elem_size;197if (disp > max_jint) {198// Displacement overflow. Cannot directly use instruction with 32-bit displacement for 64-bit addresses.199// Convert array index to long to do array offset computation with 64-bit values.200index_opr = new_register(T_LONG);201__ move(LIR_OprFact::longConst(index), index_opr);202addr = new LIR_Address(array_opr, index_opr, LIR_Address::scale(type), offset_in_bytes, type);203} else {204addr = new LIR_Address(array_opr, (intx)disp, type);205}206#else207// A displacement overflow can also occur for x86 but that is not a problem due to the 32-bit address range!208// Let's assume an array 'a' and an access with displacement 'disp'. When disp overflows, then "a + disp" will209// always be negative (i.e. underflows the 32-bit address range):210// Let N = 2^32: a + signed_overflow(disp) = a + disp - N.211// "a + disp" is always smaller than N. If an index was chosen which would point to an address beyond N, then212// range checks would catch that and throw an exception. Thus, a + disp < 0 holds which means that it always213// underflows the 32-bit address range:214// unsigned_underflow(a + signed_overflow(disp)) = unsigned_underflow(a + disp - N)215// = (a + disp - N) + N = a + disp216// This shows that we still end up at the correct address with a displacement overflow due to the 32-bit address217// range limitation. This overflow only needs to be handled if addresses can be larger as on 64-bit platforms.218addr = new LIR_Address(array_opr, offset_in_bytes + (intx)(index_opr->as_jint()) * elem_size, type);219#endif // _LP64220} else {221#ifdef _LP64222if (index_opr->type() == T_INT) {223LIR_Opr tmp = new_register(T_LONG);224__ convert(Bytecodes::_i2l, index_opr, tmp);225index_opr = tmp;226}227#endif // _LP64228addr = new LIR_Address(array_opr,229index_opr,230LIR_Address::scale(type),231offset_in_bytes, type);232}233return addr;234}235236237LIR_Opr LIRGenerator::load_immediate(int x, BasicType type) {238LIR_Opr r = NULL;239if (type == T_LONG) {240r = LIR_OprFact::longConst(x);241} else if (type == T_INT) {242r = LIR_OprFact::intConst(x);243} else {244ShouldNotReachHere();245}246return r;247}248249void LIRGenerator::increment_counter(address counter, BasicType type, int step) {250LIR_Opr pointer = new_pointer_register();251__ move(LIR_OprFact::intptrConst(counter), pointer);252LIR_Address* addr = new LIR_Address(pointer, type);253increment_counter(addr, step);254}255256257void LIRGenerator::increment_counter(LIR_Address* addr, int step) {258__ add((LIR_Opr)addr, LIR_OprFact::intConst(step), (LIR_Opr)addr);259}260261void LIRGenerator::cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info) {262__ cmp_mem_int(condition, base, disp, c, info);263}264265266void LIRGenerator::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, int disp, BasicType type, CodeEmitInfo* info) {267__ cmp_reg_mem(condition, reg, new LIR_Address(base, disp, type), info);268}269270271bool LIRGenerator::strength_reduce_multiply(LIR_Opr left, jint c, LIR_Opr result, LIR_Opr tmp) {272if (tmp->is_valid() && c > 0 && c < max_jint) {273if (is_power_of_2(c + 1)) {274__ move(left, tmp);275__ shift_left(left, log2i_exact(c + 1), left);276__ sub(left, tmp, result);277return true;278} else if (is_power_of_2(c - 1)) {279__ move(left, tmp);280__ shift_left(left, log2i_exact(c - 1), left);281__ add(left, tmp, result);282return true;283}284}285return false;286}287288289void LIRGenerator::store_stack_parameter (LIR_Opr item, ByteSize offset_from_sp) {290BasicType type = item->type();291__ store(item, new LIR_Address(FrameMap::rsp_opr, in_bytes(offset_from_sp), type));292}293294void LIRGenerator::array_store_check(LIR_Opr value, LIR_Opr array, CodeEmitInfo* store_check_info, ciMethod* profiled_method, int profiled_bci) {295LIR_Opr tmp1 = new_register(objectType);296LIR_Opr tmp2 = new_register(objectType);297LIR_Opr tmp3 = new_register(objectType);298__ store_check(value, array, tmp1, tmp2, tmp3, store_check_info, profiled_method, profiled_bci);299}300301//----------------------------------------------------------------------302// visitor functions303//----------------------------------------------------------------------304305void LIRGenerator::do_MonitorEnter(MonitorEnter* x) {306assert(x->is_pinned(),"");307LIRItem obj(x->obj(), this);308obj.load_item();309310set_no_result(x);311312// "lock" stores the address of the monitor stack slot, so this is not an oop313LIR_Opr lock = new_register(T_INT);314// Need a scratch register for biased locking on x86315LIR_Opr scratch = LIR_OprFact::illegalOpr;316if (UseBiasedLocking) {317scratch = new_register(T_INT);318}319320CodeEmitInfo* info_for_exception = NULL;321if (x->needs_null_check()) {322info_for_exception = state_for(x);323}324// this CodeEmitInfo must not have the xhandlers because here the325// object is already locked (xhandlers expect object to be unlocked)326CodeEmitInfo* info = state_for(x, x->state(), true);327monitor_enter(obj.result(), lock, syncTempOpr(), scratch,328x->monitor_no(), info_for_exception, info);329}330331332void LIRGenerator::do_MonitorExit(MonitorExit* x) {333assert(x->is_pinned(),"");334335LIRItem obj(x->obj(), this);336obj.dont_load_item();337338LIR_Opr lock = new_register(T_INT);339LIR_Opr obj_temp = new_register(T_INT);340set_no_result(x);341monitor_exit(obj_temp, lock, syncTempOpr(), LIR_OprFact::illegalOpr, x->monitor_no());342}343344345// _ineg, _lneg, _fneg, _dneg346void LIRGenerator::do_NegateOp(NegateOp* x) {347LIRItem value(x->x(), this);348value.set_destroys_register();349value.load_item();350LIR_Opr reg = rlock(x);351352LIR_Opr tmp = LIR_OprFact::illegalOpr;353#ifdef _LP64354if (UseAVX > 2 && !VM_Version::supports_avx512vl()) {355if (x->type()->tag() == doubleTag) {356tmp = new_register(T_DOUBLE);357__ move(LIR_OprFact::doubleConst(-0.0), tmp);358}359else if (x->type()->tag() == floatTag) {360tmp = new_register(T_FLOAT);361__ move(LIR_OprFact::floatConst(-0.0), tmp);362}363}364#endif365__ negate(value.result(), reg, tmp);366367set_result(x, round_item(reg));368}369370371// for _fadd, _fmul, _fsub, _fdiv, _frem372// _dadd, _dmul, _dsub, _ddiv, _drem373void LIRGenerator::do_ArithmeticOp_FPU(ArithmeticOp* x) {374LIRItem left(x->x(), this);375LIRItem right(x->y(), this);376LIRItem* left_arg = &left;377LIRItem* right_arg = &right;378assert(!left.is_stack() || !right.is_stack(), "can't both be memory operands");379bool must_load_both = (x->op() == Bytecodes::_frem || x->op() == Bytecodes::_drem);380if (left.is_register() || x->x()->type()->is_constant() || must_load_both) {381left.load_item();382} else {383left.dont_load_item();384}385386#ifndef _LP64387// do not load right operand if it is a constant. only 0 and 1 are388// loaded because there are special instructions for loading them389// without memory access (not needed for SSE2 instructions)390bool must_load_right = false;391if (right.is_constant()) {392LIR_Const* c = right.result()->as_constant_ptr();393assert(c != NULL, "invalid constant");394assert(c->type() == T_FLOAT || c->type() == T_DOUBLE, "invalid type");395396if (c->type() == T_FLOAT) {397must_load_right = UseSSE < 1 && (c->is_one_float() || c->is_zero_float());398} else {399must_load_right = UseSSE < 2 && (c->is_one_double() || c->is_zero_double());400}401}402#endif // !LP64403404if (must_load_both) {405// frem and drem destroy also right operand, so move it to a new register406right.set_destroys_register();407right.load_item();408} else if (right.is_register()) {409right.load_item();410#ifndef _LP64411} else if (must_load_right) {412right.load_item();413#endif // !LP64414} else {415right.dont_load_item();416}417LIR_Opr reg = rlock(x);418LIR_Opr tmp = LIR_OprFact::illegalOpr;419if (x->op() == Bytecodes::_dmul || x->op() == Bytecodes::_ddiv) {420tmp = new_register(T_DOUBLE);421}422423#ifdef _LP64424if (x->op() == Bytecodes::_frem || x->op() == Bytecodes::_drem) {425// frem and drem are implemented as a direct call into the runtime.426LIRItem left(x->x(), this);427LIRItem right(x->y(), this);428429BasicType bt = as_BasicType(x->type());430BasicTypeList signature(2);431signature.append(bt);432signature.append(bt);433CallingConvention* cc = frame_map()->c_calling_convention(&signature);434435const LIR_Opr result_reg = result_register_for(x->type());436left.load_item_force(cc->at(0));437right.load_item_force(cc->at(1));438439address entry = NULL;440switch (x->op()) {441case Bytecodes::_frem:442entry = CAST_FROM_FN_PTR(address, SharedRuntime::frem);443break;444case Bytecodes::_drem:445entry = CAST_FROM_FN_PTR(address, SharedRuntime::drem);446break;447default:448ShouldNotReachHere();449}450451LIR_Opr result = rlock_result(x);452__ call_runtime_leaf(entry, getThreadTemp(), result_reg, cc->args());453__ move(result_reg, result);454} else {455arithmetic_op_fpu(x->op(), reg, left.result(), right.result(), tmp);456set_result(x, round_item(reg));457}458#else459if ((UseSSE >= 1 && x->op() == Bytecodes::_frem) || (UseSSE >= 2 && x->op() == Bytecodes::_drem)) {460// special handling for frem and drem: no SSE instruction, so must use FPU with temporary fpu stack slots461LIR_Opr fpu0, fpu1;462if (x->op() == Bytecodes::_frem) {463fpu0 = LIR_OprFact::single_fpu(0);464fpu1 = LIR_OprFact::single_fpu(1);465} else {466fpu0 = LIR_OprFact::double_fpu(0);467fpu1 = LIR_OprFact::double_fpu(1);468}469__ move(right.result(), fpu1); // order of left and right operand is important!470__ move(left.result(), fpu0);471__ rem (fpu0, fpu1, fpu0);472__ move(fpu0, reg);473474} else {475arithmetic_op_fpu(x->op(), reg, left.result(), right.result(), tmp);476}477set_result(x, round_item(reg));478#endif // _LP64479}480481482// for _ladd, _lmul, _lsub, _ldiv, _lrem483void LIRGenerator::do_ArithmeticOp_Long(ArithmeticOp* x) {484if (x->op() == Bytecodes::_ldiv || x->op() == Bytecodes::_lrem ) {485// long division is implemented as a direct call into the runtime486LIRItem left(x->x(), this);487LIRItem right(x->y(), this);488489// the check for division by zero destroys the right operand490right.set_destroys_register();491492BasicTypeList signature(2);493signature.append(T_LONG);494signature.append(T_LONG);495CallingConvention* cc = frame_map()->c_calling_convention(&signature);496497// check for division by zero (destroys registers of right operand!)498CodeEmitInfo* info = state_for(x);499500const LIR_Opr result_reg = result_register_for(x->type());501left.load_item_force(cc->at(1));502right.load_item();503504__ move(right.result(), cc->at(0));505506__ cmp(lir_cond_equal, right.result(), LIR_OprFact::longConst(0));507__ branch(lir_cond_equal, new DivByZeroStub(info));508509address entry = NULL;510switch (x->op()) {511case Bytecodes::_lrem:512entry = CAST_FROM_FN_PTR(address, SharedRuntime::lrem);513break; // check if dividend is 0 is done elsewhere514case Bytecodes::_ldiv:515entry = CAST_FROM_FN_PTR(address, SharedRuntime::ldiv);516break; // check if dividend is 0 is done elsewhere517default:518ShouldNotReachHere();519}520521LIR_Opr result = rlock_result(x);522__ call_runtime_leaf(entry, getThreadTemp(), result_reg, cc->args());523__ move(result_reg, result);524} else if (x->op() == Bytecodes::_lmul) {525// missing test if instr is commutative and if we should swap526LIRItem left(x->x(), this);527LIRItem right(x->y(), this);528529// right register is destroyed by the long mul, so it must be530// copied to a new register.531right.set_destroys_register();532533left.load_item();534right.load_item();535536LIR_Opr reg = FrameMap::long0_opr;537arithmetic_op_long(x->op(), reg, left.result(), right.result(), NULL);538LIR_Opr result = rlock_result(x);539__ move(reg, result);540} else {541// missing test if instr is commutative and if we should swap542LIRItem left(x->x(), this);543LIRItem right(x->y(), this);544545left.load_item();546// don't load constants to save register547right.load_nonconstant();548rlock_result(x);549arithmetic_op_long(x->op(), x->operand(), left.result(), right.result(), NULL);550}551}552553554555// for: _iadd, _imul, _isub, _idiv, _irem556void LIRGenerator::do_ArithmeticOp_Int(ArithmeticOp* x) {557if (x->op() == Bytecodes::_idiv || x->op() == Bytecodes::_irem) {558// The requirements for division and modulo559// input : rax,: dividend min_int560// reg: divisor (may not be rax,/rdx) -1561//562// output: rax,: quotient (= rax, idiv reg) min_int563// rdx: remainder (= rax, irem reg) 0564565// rax, and rdx will be destroyed566567// Note: does this invalidate the spec ???568LIRItem right(x->y(), this);569LIRItem left(x->x() , this); // visit left second, so that the is_register test is valid570571// call state_for before load_item_force because state_for may572// force the evaluation of other instructions that are needed for573// correct debug info. Otherwise the live range of the fix574// register might be too long.575CodeEmitInfo* info = state_for(x);576577left.load_item_force(divInOpr());578579right.load_item();580581LIR_Opr result = rlock_result(x);582LIR_Opr result_reg;583if (x->op() == Bytecodes::_idiv) {584result_reg = divOutOpr();585} else {586result_reg = remOutOpr();587}588589if (!ImplicitDiv0Checks) {590__ cmp(lir_cond_equal, right.result(), LIR_OprFact::intConst(0));591__ branch(lir_cond_equal, new DivByZeroStub(info));592// Idiv/irem cannot trap (passing info would generate an assertion).593info = NULL;594}595LIR_Opr tmp = FrameMap::rdx_opr; // idiv and irem use rdx in their implementation596if (x->op() == Bytecodes::_irem) {597__ irem(left.result(), right.result(), result_reg, tmp, info);598} else if (x->op() == Bytecodes::_idiv) {599__ idiv(left.result(), right.result(), result_reg, tmp, info);600} else {601ShouldNotReachHere();602}603604__ move(result_reg, result);605} else {606// missing test if instr is commutative and if we should swap607LIRItem left(x->x(), this);608LIRItem right(x->y(), this);609LIRItem* left_arg = &left;610LIRItem* right_arg = &right;611if (x->is_commutative() && left.is_stack() && right.is_register()) {612// swap them if left is real stack (or cached) and right is real register(not cached)613left_arg = &right;614right_arg = &left;615}616617left_arg->load_item();618619// do not need to load right, as we can handle stack and constants620if (x->op() == Bytecodes::_imul ) {621// check if we can use shift instead622bool use_constant = false;623bool use_tmp = false;624if (right_arg->is_constant()) {625jint iconst = right_arg->get_jint_constant();626if (iconst > 0 && iconst < max_jint) {627if (is_power_of_2(iconst)) {628use_constant = true;629} else if (is_power_of_2(iconst - 1) || is_power_of_2(iconst + 1)) {630use_constant = true;631use_tmp = true;632}633}634}635if (use_constant) {636right_arg->dont_load_item();637} else {638right_arg->load_item();639}640LIR_Opr tmp = LIR_OprFact::illegalOpr;641if (use_tmp) {642tmp = new_register(T_INT);643}644rlock_result(x);645646arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), tmp);647} else {648right_arg->dont_load_item();649rlock_result(x);650LIR_Opr tmp = LIR_OprFact::illegalOpr;651arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), tmp);652}653}654}655656657void LIRGenerator::do_ArithmeticOp(ArithmeticOp* x) {658// when an operand with use count 1 is the left operand, then it is659// likely that no move for 2-operand-LIR-form is necessary660if (x->is_commutative() && x->y()->as_Constant() == NULL && x->x()->use_count() > x->y()->use_count()) {661x->swap_operands();662}663664ValueTag tag = x->type()->tag();665assert(x->x()->type()->tag() == tag && x->y()->type()->tag() == tag, "wrong parameters");666switch (tag) {667case floatTag:668case doubleTag: do_ArithmeticOp_FPU(x); return;669case longTag: do_ArithmeticOp_Long(x); return;670case intTag: do_ArithmeticOp_Int(x); return;671default: ShouldNotReachHere(); return;672}673}674675676// _ishl, _lshl, _ishr, _lshr, _iushr, _lushr677void LIRGenerator::do_ShiftOp(ShiftOp* x) {678// count must always be in rcx679LIRItem value(x->x(), this);680LIRItem count(x->y(), this);681682ValueTag elemType = x->type()->tag();683bool must_load_count = !count.is_constant() || elemType == longTag;684if (must_load_count) {685// count for long must be in register686count.load_item_force(shiftCountOpr());687} else {688count.dont_load_item();689}690value.load_item();691LIR_Opr reg = rlock_result(x);692693shift_op(x->op(), reg, value.result(), count.result(), LIR_OprFact::illegalOpr);694}695696697// _iand, _land, _ior, _lor, _ixor, _lxor698void LIRGenerator::do_LogicOp(LogicOp* x) {699// when an operand with use count 1 is the left operand, then it is700// likely that no move for 2-operand-LIR-form is necessary701if (x->is_commutative() && x->y()->as_Constant() == NULL && x->x()->use_count() > x->y()->use_count()) {702x->swap_operands();703}704705LIRItem left(x->x(), this);706LIRItem right(x->y(), this);707708left.load_item();709right.load_nonconstant();710LIR_Opr reg = rlock_result(x);711712logic_op(x->op(), reg, left.result(), right.result());713}714715716717// _lcmp, _fcmpl, _fcmpg, _dcmpl, _dcmpg718void LIRGenerator::do_CompareOp(CompareOp* x) {719LIRItem left(x->x(), this);720LIRItem right(x->y(), this);721ValueTag tag = x->x()->type()->tag();722if (tag == longTag) {723left.set_destroys_register();724}725left.load_item();726right.load_item();727LIR_Opr reg = rlock_result(x);728729if (x->x()->type()->is_float_kind()) {730Bytecodes::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 {735Unimplemented();736}737}738739LIR_Opr LIRGenerator::atomic_cmpxchg(BasicType type, LIR_Opr addr, LIRItem& cmp_value, LIRItem& new_value) {740LIR_Opr ill = LIR_OprFact::illegalOpr; // for convenience741if (is_reference_type(type)) {742cmp_value.load_item_force(FrameMap::rax_oop_opr);743new_value.load_item();744__ cas_obj(addr->as_address_ptr()->base(), cmp_value.result(), new_value.result(), ill, ill);745} else if (type == T_INT) {746cmp_value.load_item_force(FrameMap::rax_opr);747new_value.load_item();748__ cas_int(addr->as_address_ptr()->base(), cmp_value.result(), new_value.result(), ill, ill);749} else if (type == T_LONG) {750cmp_value.load_item_force(FrameMap::long0_opr);751new_value.load_item_force(FrameMap::long1_opr);752__ cas_long(addr->as_address_ptr()->base(), cmp_value.result(), new_value.result(), ill, ill);753} else {754Unimplemented();755}756LIR_Opr result = new_register(T_INT);757__ cmove(lir_cond_equal, LIR_OprFact::intConst(1), LIR_OprFact::intConst(0),758result, T_INT);759return result;760}761762LIR_Opr LIRGenerator::atomic_xchg(BasicType type, LIR_Opr addr, LIRItem& value) {763bool is_oop = is_reference_type(type);764LIR_Opr result = new_register(type);765value.load_item();766// Because we want a 2-arg form of xchg and xadd767__ move(value.result(), result);768assert(type == T_INT || is_oop LP64_ONLY( || type == T_LONG ), "unexpected type");769__ xchg(addr, result, result, LIR_OprFact::illegalOpr);770return result;771}772773LIR_Opr LIRGenerator::atomic_add(BasicType type, LIR_Opr addr, LIRItem& value) {774LIR_Opr result = new_register(type);775value.load_item();776// Because we want a 2-arg form of xchg and xadd777__ move(value.result(), result);778assert(type == T_INT LP64_ONLY( || type == T_LONG ), "unexpected type");779__ xadd(addr, result, result, LIR_OprFact::illegalOpr);780return result;781}782783void LIRGenerator::do_FmaIntrinsic(Intrinsic* x) {784assert(x->number_of_arguments() == 3, "wrong type");785assert(UseFMA, "Needs FMA instructions support.");786LIRItem value(x->argument_at(0), this);787LIRItem value1(x->argument_at(1), this);788LIRItem value2(x->argument_at(2), this);789790value2.set_destroys_register();791792value.load_item();793value1.load_item();794value2.load_item();795796LIR_Opr calc_input = value.result();797LIR_Opr calc_input1 = value1.result();798LIR_Opr calc_input2 = value2.result();799LIR_Opr calc_result = rlock_result(x);800801switch (x->id()) {802case vmIntrinsics::_fmaD: __ fmad(calc_input, calc_input1, calc_input2, calc_result); break;803case vmIntrinsics::_fmaF: __ fmaf(calc_input, calc_input1, calc_input2, calc_result); break;804default: ShouldNotReachHere();805}806807}808809810void LIRGenerator::do_MathIntrinsic(Intrinsic* x) {811assert(x->number_of_arguments() == 1 || (x->number_of_arguments() == 2 && x->id() == vmIntrinsics::_dpow), "wrong type");812813if (x->id() == vmIntrinsics::_dexp || x->id() == vmIntrinsics::_dlog ||814x->id() == vmIntrinsics::_dpow || x->id() == vmIntrinsics::_dcos ||815x->id() == vmIntrinsics::_dsin || x->id() == vmIntrinsics::_dtan ||816x->id() == vmIntrinsics::_dlog10) {817do_LibmIntrinsic(x);818return;819}820821LIRItem value(x->argument_at(0), this);822823bool use_fpu = false;824#ifndef _LP64825if (UseSSE < 2) {826value.set_destroys_register();827}828#endif // !LP64829value.load_item();830831LIR_Opr calc_input = value.result();832LIR_Opr calc_result = rlock_result(x);833834LIR_Opr tmp = LIR_OprFact::illegalOpr;835#ifdef _LP64836if (UseAVX > 2 && (!VM_Version::supports_avx512vl()) &&837(x->id() == vmIntrinsics::_dabs)) {838tmp = new_register(T_DOUBLE);839__ move(LIR_OprFact::doubleConst(-0.0), tmp);840}841#endif842843switch(x->id()) {844case vmIntrinsics::_dabs: __ abs (calc_input, calc_result, tmp); break;845case vmIntrinsics::_dsqrt: __ sqrt (calc_input, calc_result, LIR_OprFact::illegalOpr); break;846default: ShouldNotReachHere();847}848849if (use_fpu) {850__ move(calc_result, x->operand());851}852}853854void LIRGenerator::do_LibmIntrinsic(Intrinsic* x) {855LIRItem value(x->argument_at(0), this);856value.set_destroys_register();857858LIR_Opr calc_result = rlock_result(x);859LIR_Opr result_reg = result_register_for(x->type());860861CallingConvention* cc = NULL;862863if (x->id() == vmIntrinsics::_dpow) {864LIRItem value1(x->argument_at(1), this);865866value1.set_destroys_register();867868BasicTypeList signature(2);869signature.append(T_DOUBLE);870signature.append(T_DOUBLE);871cc = frame_map()->c_calling_convention(&signature);872value.load_item_force(cc->at(0));873value1.load_item_force(cc->at(1));874} else {875BasicTypeList signature(1);876signature.append(T_DOUBLE);877cc = frame_map()->c_calling_convention(&signature);878value.load_item_force(cc->at(0));879}880881#ifndef _LP64882LIR_Opr tmp = FrameMap::fpu0_double_opr;883result_reg = tmp;884switch(x->id()) {885case vmIntrinsics::_dexp:886if (StubRoutines::dexp() != NULL) {887__ call_runtime_leaf(StubRoutines::dexp(), getThreadTemp(), result_reg, cc->args());888} else {889__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dexp), getThreadTemp(), result_reg, cc->args());890}891break;892case vmIntrinsics::_dlog:893if (StubRoutines::dlog() != NULL) {894__ call_runtime_leaf(StubRoutines::dlog(), getThreadTemp(), result_reg, cc->args());895} else {896__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dlog), getThreadTemp(), result_reg, cc->args());897}898break;899case vmIntrinsics::_dlog10:900if (StubRoutines::dlog10() != NULL) {901__ call_runtime_leaf(StubRoutines::dlog10(), getThreadTemp(), result_reg, cc->args());902} else {903__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dlog10), getThreadTemp(), result_reg, cc->args());904}905break;906case vmIntrinsics::_dpow:907if (StubRoutines::dpow() != NULL) {908__ call_runtime_leaf(StubRoutines::dpow(), getThreadTemp(), result_reg, cc->args());909} else {910__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dpow), getThreadTemp(), result_reg, cc->args());911}912break;913case vmIntrinsics::_dsin:914if (VM_Version::supports_sse2() && StubRoutines::dsin() != NULL) {915__ call_runtime_leaf(StubRoutines::dsin(), getThreadTemp(), result_reg, cc->args());916} else {917__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dsin), getThreadTemp(), result_reg, cc->args());918}919break;920case vmIntrinsics::_dcos:921if (VM_Version::supports_sse2() && StubRoutines::dcos() != NULL) {922__ call_runtime_leaf(StubRoutines::dcos(), getThreadTemp(), result_reg, cc->args());923} else {924__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dcos), getThreadTemp(), result_reg, cc->args());925}926break;927case vmIntrinsics::_dtan:928if (StubRoutines::dtan() != NULL) {929__ call_runtime_leaf(StubRoutines::dtan(), getThreadTemp(), result_reg, cc->args());930} else {931__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtan), getThreadTemp(), result_reg, cc->args());932}933break;934default: ShouldNotReachHere();935}936#else937switch (x->id()) {938case vmIntrinsics::_dexp:939if (StubRoutines::dexp() != NULL) {940__ call_runtime_leaf(StubRoutines::dexp(), getThreadTemp(), result_reg, cc->args());941} else {942__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dexp), getThreadTemp(), result_reg, cc->args());943}944break;945case vmIntrinsics::_dlog:946if (StubRoutines::dlog() != NULL) {947__ call_runtime_leaf(StubRoutines::dlog(), getThreadTemp(), result_reg, cc->args());948} else {949__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dlog), getThreadTemp(), result_reg, cc->args());950}951break;952case vmIntrinsics::_dlog10:953if (StubRoutines::dlog10() != NULL) {954__ call_runtime_leaf(StubRoutines::dlog10(), getThreadTemp(), result_reg, cc->args());955} else {956__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dlog10), getThreadTemp(), result_reg, cc->args());957}958break;959case vmIntrinsics::_dpow:960if (StubRoutines::dpow() != NULL) {961__ call_runtime_leaf(StubRoutines::dpow(), getThreadTemp(), result_reg, cc->args());962} else {963__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dpow), getThreadTemp(), result_reg, cc->args());964}965break;966case vmIntrinsics::_dsin:967if (StubRoutines::dsin() != NULL) {968__ call_runtime_leaf(StubRoutines::dsin(), getThreadTemp(), result_reg, cc->args());969} else {970__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dsin), getThreadTemp(), result_reg, cc->args());971}972break;973case vmIntrinsics::_dcos:974if (StubRoutines::dcos() != NULL) {975__ call_runtime_leaf(StubRoutines::dcos(), getThreadTemp(), result_reg, cc->args());976} else {977__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dcos), getThreadTemp(), result_reg, cc->args());978}979break;980case vmIntrinsics::_dtan:981if (StubRoutines::dtan() != NULL) {982__ call_runtime_leaf(StubRoutines::dtan(), getThreadTemp(), result_reg, cc->args());983} else {984__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtan), getThreadTemp(), result_reg, cc->args());985}986break;987default: ShouldNotReachHere();988}989#endif // _LP64990__ move(result_reg, calc_result);991}992993void LIRGenerator::do_ArrayCopy(Intrinsic* x) {994assert(x->number_of_arguments() == 5, "wrong type");995996// Make all state_for calls early since they can emit code997CodeEmitInfo* info = state_for(x, x->state());998999LIRItem src(x->argument_at(0), this);1000LIRItem src_pos(x->argument_at(1), this);1001LIRItem dst(x->argument_at(2), this);1002LIRItem dst_pos(x->argument_at(3), this);1003LIRItem length(x->argument_at(4), this);10041005// operands for arraycopy must use fixed registers, otherwise1006// LinearScan will fail allocation (because arraycopy always needs a1007// call)10081009#ifndef _LP641010src.load_item_force (FrameMap::rcx_oop_opr);1011src_pos.load_item_force (FrameMap::rdx_opr);1012dst.load_item_force (FrameMap::rax_oop_opr);1013dst_pos.load_item_force (FrameMap::rbx_opr);1014length.load_item_force (FrameMap::rdi_opr);1015LIR_Opr tmp = (FrameMap::rsi_opr);1016#else10171018// The java calling convention will give us enough registers1019// so that on the stub side the args will be perfect already.1020// On the other slow/special case side we call C and the arg1021// positions are not similar enough to pick one as the best.1022// Also because the java calling convention is a "shifted" version1023// of the C convention we can process the java args trivially into C1024// args without worry of overwriting during the xfer10251026src.load_item_force (FrameMap::as_oop_opr(j_rarg0));1027src_pos.load_item_force (FrameMap::as_opr(j_rarg1));1028dst.load_item_force (FrameMap::as_oop_opr(j_rarg2));1029dst_pos.load_item_force (FrameMap::as_opr(j_rarg3));1030length.load_item_force (FrameMap::as_opr(j_rarg4));10311032LIR_Opr tmp = FrameMap::as_opr(j_rarg5);1033#endif // LP6410341035set_no_result(x);10361037int flags;1038ciArrayKlass* expected_type;1039arraycopy_helper(x, &flags, &expected_type);10401041__ arraycopy(src.result(), src_pos.result(), dst.result(), dst_pos.result(), length.result(), tmp, expected_type, flags, info); // does add_safepoint1042}10431044void LIRGenerator::do_update_CRC32(Intrinsic* x) {1045assert(UseCRC32Intrinsics, "need AVX and LCMUL instructions support");1046// Make all state_for calls early since they can emit code1047LIR_Opr result = rlock_result(x);1048int flags = 0;1049switch (x->id()) {1050case vmIntrinsics::_updateCRC32: {1051LIRItem crc(x->argument_at(0), this);1052LIRItem val(x->argument_at(1), this);1053// val is destroyed by update_crc321054val.set_destroys_register();1055crc.load_item();1056val.load_item();1057__ update_crc32(crc.result(), val.result(), result);1058break;1059}1060case vmIntrinsics::_updateBytesCRC32:1061case vmIntrinsics::_updateByteBufferCRC32: {1062bool is_updateBytes = (x->id() == vmIntrinsics::_updateBytesCRC32);10631064LIRItem crc(x->argument_at(0), this);1065LIRItem buf(x->argument_at(1), this);1066LIRItem off(x->argument_at(2), this);1067LIRItem len(x->argument_at(3), this);1068buf.load_item();1069off.load_nonconstant();10701071LIR_Opr index = off.result();1072int offset = is_updateBytes ? arrayOopDesc::base_offset_in_bytes(T_BYTE) : 0;1073if(off.result()->is_constant()) {1074index = LIR_OprFact::illegalOpr;1075offset += off.result()->as_jint();1076}1077LIR_Opr base_op = buf.result();10781079#ifndef _LP641080if (!is_updateBytes) { // long b raw address1081base_op = new_register(T_INT);1082__ convert(Bytecodes::_l2i, buf.result(), base_op);1083}1084#else1085if (index->is_valid()) {1086LIR_Opr tmp = new_register(T_LONG);1087__ convert(Bytecodes::_i2l, index, tmp);1088index = tmp;1089}1090#endif10911092LIR_Address* a = new LIR_Address(base_op,1093index,1094offset,1095T_BYTE);1096BasicTypeList signature(3);1097signature.append(T_INT);1098signature.append(T_ADDRESS);1099signature.append(T_INT);1100CallingConvention* cc = frame_map()->c_calling_convention(&signature);1101const LIR_Opr result_reg = result_register_for(x->type());11021103LIR_Opr addr = new_pointer_register();1104__ leal(LIR_OprFact::address(a), addr);11051106crc.load_item_force(cc->at(0));1107__ move(addr, cc->at(1));1108len.load_item_force(cc->at(2));11091110__ call_runtime_leaf(StubRoutines::updateBytesCRC32(), getThreadTemp(), result_reg, cc->args());1111__ move(result_reg, result);11121113break;1114}1115default: {1116ShouldNotReachHere();1117}1118}1119}11201121void LIRGenerator::do_update_CRC32C(Intrinsic* x) {1122Unimplemented();1123}11241125void LIRGenerator::do_vectorizedMismatch(Intrinsic* x) {1126assert(UseVectorizedMismatchIntrinsic, "need AVX instruction support");11271128// Make all state_for calls early since they can emit code1129LIR_Opr result = rlock_result(x);11301131LIRItem a(x->argument_at(0), this); // Object1132LIRItem aOffset(x->argument_at(1), this); // long1133LIRItem b(x->argument_at(2), this); // Object1134LIRItem bOffset(x->argument_at(3), this); // long1135LIRItem length(x->argument_at(4), this); // int1136LIRItem log2ArrayIndexScale(x->argument_at(5), this); // int11371138a.load_item();1139aOffset.load_nonconstant();1140b.load_item();1141bOffset.load_nonconstant();11421143long constant_aOffset = 0;1144LIR_Opr result_aOffset = aOffset.result();1145if (result_aOffset->is_constant()) {1146constant_aOffset = result_aOffset->as_jlong();1147result_aOffset = LIR_OprFact::illegalOpr;1148}1149LIR_Opr result_a = a.result();11501151long constant_bOffset = 0;1152LIR_Opr result_bOffset = bOffset.result();1153if (result_bOffset->is_constant()) {1154constant_bOffset = result_bOffset->as_jlong();1155result_bOffset = LIR_OprFact::illegalOpr;1156}1157LIR_Opr result_b = b.result();11581159#ifndef _LP641160result_a = new_register(T_INT);1161__ convert(Bytecodes::_l2i, a.result(), result_a);1162result_b = new_register(T_INT);1163__ convert(Bytecodes::_l2i, b.result(), result_b);1164#endif116511661167LIR_Address* addr_a = new LIR_Address(result_a,1168result_aOffset,1169constant_aOffset,1170T_BYTE);11711172LIR_Address* addr_b = new LIR_Address(result_b,1173result_bOffset,1174constant_bOffset,1175T_BYTE);11761177BasicTypeList signature(4);1178signature.append(T_ADDRESS);1179signature.append(T_ADDRESS);1180signature.append(T_INT);1181signature.append(T_INT);1182CallingConvention* cc = frame_map()->c_calling_convention(&signature);1183const LIR_Opr result_reg = result_register_for(x->type());11841185LIR_Opr ptr_addr_a = new_pointer_register();1186__ leal(LIR_OprFact::address(addr_a), ptr_addr_a);11871188LIR_Opr ptr_addr_b = new_pointer_register();1189__ leal(LIR_OprFact::address(addr_b), ptr_addr_b);11901191__ move(ptr_addr_a, cc->at(0));1192__ move(ptr_addr_b, cc->at(1));1193length.load_item_force(cc->at(2));1194log2ArrayIndexScale.load_item_force(cc->at(3));11951196__ call_runtime_leaf(StubRoutines::vectorizedMismatch(), getThreadTemp(), result_reg, cc->args());1197__ move(result_reg, result);1198}11991200// _i2l, _i2f, _i2d, _l2i, _l2f, _l2d, _f2i, _f2l, _f2d, _d2i, _d2l, _d2f1201// _i2b, _i2c, _i2s1202LIR_Opr fixed_register_for(BasicType type) {1203switch (type) {1204case T_FLOAT: return FrameMap::fpu0_float_opr;1205case T_DOUBLE: return FrameMap::fpu0_double_opr;1206case T_INT: return FrameMap::rax_opr;1207case T_LONG: return FrameMap::long0_opr;1208default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr;1209}1210}12111212void LIRGenerator::do_Convert(Convert* x) {1213#ifdef _LP641214LIRItem value(x->value(), this);1215value.load_item();1216LIR_Opr input = value.result();1217LIR_Opr result = rlock(x);1218__ convert(x->op(), input, result);1219assert(result->is_virtual(), "result must be virtual register");1220set_result(x, result);1221#else1222// flags that vary for the different operations and different SSE-settings1223bool fixed_input = false, fixed_result = false, round_result = false, needs_stub = false;12241225switch (x->op()) {1226case Bytecodes::_i2l: // fall through1227case Bytecodes::_l2i: // fall through1228case Bytecodes::_i2b: // fall through1229case Bytecodes::_i2c: // fall through1230case Bytecodes::_i2s: fixed_input = false; fixed_result = false; round_result = false; needs_stub = false; break;12311232case Bytecodes::_f2d: fixed_input = UseSSE == 1; fixed_result = false; round_result = false; needs_stub = false; break;1233case Bytecodes::_d2f: fixed_input = false; fixed_result = UseSSE == 1; round_result = UseSSE < 1; needs_stub = false; break;1234case Bytecodes::_i2f: fixed_input = false; fixed_result = false; round_result = UseSSE < 1; needs_stub = false; break;1235case Bytecodes::_i2d: fixed_input = false; fixed_result = false; round_result = false; needs_stub = false; break;1236case Bytecodes::_f2i: fixed_input = false; fixed_result = false; round_result = false; needs_stub = true; break;1237case Bytecodes::_d2i: fixed_input = false; fixed_result = false; round_result = false; needs_stub = true; break;1238case Bytecodes::_l2f: fixed_input = false; fixed_result = UseSSE >= 1; round_result = UseSSE < 1; needs_stub = false; break;1239case Bytecodes::_l2d: fixed_input = false; fixed_result = UseSSE >= 2; round_result = UseSSE < 2; needs_stub = false; break;1240case Bytecodes::_f2l: fixed_input = true; fixed_result = true; round_result = false; needs_stub = false; break;1241case Bytecodes::_d2l: fixed_input = true; fixed_result = true; round_result = false; needs_stub = false; break;1242default: ShouldNotReachHere();1243}12441245LIRItem value(x->value(), this);1246value.load_item();1247LIR_Opr input = value.result();1248LIR_Opr result = rlock(x);12491250// arguments of lir_convert1251LIR_Opr conv_input = input;1252LIR_Opr conv_result = result;1253ConversionStub* stub = NULL;12541255if (fixed_input) {1256conv_input = fixed_register_for(input->type());1257__ move(input, conv_input);1258}12591260assert(fixed_result == false || round_result == false, "cannot set both");1261if (fixed_result) {1262conv_result = fixed_register_for(result->type());1263} else if (round_result) {1264result = new_register(result->type());1265set_vreg_flag(result, must_start_in_memory);1266}12671268if (needs_stub) {1269stub = new ConversionStub(x->op(), conv_input, conv_result);1270}12711272__ convert(x->op(), conv_input, conv_result, stub);12731274if (result != conv_result) {1275__ move(conv_result, result);1276}12771278assert(result->is_virtual(), "result must be virtual register");1279set_result(x, result);1280#endif // _LP641281}128212831284void LIRGenerator::do_NewInstance(NewInstance* x) {1285print_if_not_loaded(x);12861287CodeEmitInfo* info = state_for(x, x->state());1288LIR_Opr reg = result_register_for(x->type());1289new_instance(reg, x->klass(), x->is_unresolved(),1290FrameMap::rcx_oop_opr,1291FrameMap::rdi_oop_opr,1292FrameMap::rsi_oop_opr,1293LIR_OprFact::illegalOpr,1294FrameMap::rdx_metadata_opr, info);1295LIR_Opr result = rlock_result(x);1296__ move(reg, result);1297}129812991300void LIRGenerator::do_NewTypeArray(NewTypeArray* x) {1301CodeEmitInfo* info = state_for(x, x->state());13021303LIRItem length(x->length(), this);1304length.load_item_force(FrameMap::rbx_opr);13051306LIR_Opr reg = result_register_for(x->type());1307LIR_Opr tmp1 = FrameMap::rcx_oop_opr;1308LIR_Opr tmp2 = FrameMap::rsi_oop_opr;1309LIR_Opr tmp3 = FrameMap::rdi_oop_opr;1310LIR_Opr tmp4 = reg;1311LIR_Opr klass_reg = FrameMap::rdx_metadata_opr;1312LIR_Opr len = length.result();1313BasicType elem_type = x->elt_type();13141315__ metadata2reg(ciTypeArrayKlass::make(elem_type)->constant_encoding(), klass_reg);13161317CodeStub* slow_path = new NewTypeArrayStub(klass_reg, len, reg, info);1318__ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, elem_type, klass_reg, slow_path);13191320LIR_Opr result = rlock_result(x);1321__ move(reg, result);1322}132313241325void LIRGenerator::do_NewObjectArray(NewObjectArray* x) {1326LIRItem length(x->length(), this);1327// in case of patching (i.e., object class is not yet loaded), we need to reexecute the instruction1328// and therefore provide the state before the parameters have been consumed1329CodeEmitInfo* patching_info = NULL;1330if (!x->klass()->is_loaded() || PatchALot) {1331patching_info = state_for(x, x->state_before());1332}13331334CodeEmitInfo* info = state_for(x, x->state());13351336const LIR_Opr reg = result_register_for(x->type());1337LIR_Opr tmp1 = FrameMap::rcx_oop_opr;1338LIR_Opr tmp2 = FrameMap::rsi_oop_opr;1339LIR_Opr tmp3 = FrameMap::rdi_oop_opr;1340LIR_Opr tmp4 = reg;1341LIR_Opr klass_reg = FrameMap::rdx_metadata_opr;13421343length.load_item_force(FrameMap::rbx_opr);1344LIR_Opr len = length.result();13451346CodeStub* slow_path = new NewObjectArrayStub(klass_reg, len, reg, info);1347ciKlass* obj = (ciKlass*) ciObjArrayKlass::make(x->klass());1348if (obj == ciEnv::unloaded_ciobjarrayklass()) {1349BAILOUT("encountered unloaded_ciobjarrayklass due to out of memory error");1350}1351klass2reg_with_patching(klass_reg, obj, patching_info);1352__ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, T_OBJECT, klass_reg, slow_path);13531354LIR_Opr result = rlock_result(x);1355__ move(reg, result);1356}135713581359void LIRGenerator::do_NewMultiArray(NewMultiArray* x) {1360Values* dims = x->dims();1361int i = dims->length();1362LIRItemList* items = new LIRItemList(i, i, NULL);1363while (i-- > 0) {1364LIRItem* size = new LIRItem(dims->at(i), this);1365items->at_put(i, size);1366}13671368// Evaluate state_for early since it may emit code.1369CodeEmitInfo* patching_info = NULL;1370if (!x->klass()->is_loaded() || PatchALot) {1371patching_info = state_for(x, x->state_before());13721373// Cannot re-use same xhandlers for multiple CodeEmitInfos, so1374// clone all handlers (NOTE: Usually this is handled transparently1375// by the CodeEmitInfo cloning logic in CodeStub constructors but1376// is done explicitly here because a stub isn't being used).1377x->set_exception_handlers(new XHandlers(x->exception_handlers()));1378}1379CodeEmitInfo* info = state_for(x, x->state());13801381i = dims->length();1382while (i-- > 0) {1383LIRItem* size = items->at(i);1384size->load_nonconstant();13851386store_stack_parameter(size->result(), in_ByteSize(i*4));1387}13881389LIR_Opr klass_reg = FrameMap::rax_metadata_opr;1390klass2reg_with_patching(klass_reg, x->klass(), patching_info);13911392LIR_Opr rank = FrameMap::rbx_opr;1393__ move(LIR_OprFact::intConst(x->rank()), rank);1394LIR_Opr varargs = FrameMap::rcx_opr;1395__ move(FrameMap::rsp_opr, varargs);1396LIR_OprList* args = new LIR_OprList(3);1397args->append(klass_reg);1398args->append(rank);1399args->append(varargs);1400LIR_Opr reg = result_register_for(x->type());1401__ call_runtime(Runtime1::entry_for(Runtime1::new_multi_array_id),1402LIR_OprFact::illegalOpr,1403reg, args, info);14041405LIR_Opr result = rlock_result(x);1406__ move(reg, result);1407}140814091410void LIRGenerator::do_BlockBegin(BlockBegin* x) {1411// nothing to do for now1412}141314141415void LIRGenerator::do_CheckCast(CheckCast* x) {1416LIRItem obj(x->obj(), this);14171418CodeEmitInfo* patching_info = NULL;1419if (!x->klass()->is_loaded() || (PatchALot && !x->is_incompatible_class_change_check() && !x->is_invokespecial_receiver_check())) {1420// must do this before locking the destination register as an oop register,1421// and before the obj is loaded (the latter is for deoptimization)1422patching_info = state_for(x, x->state_before());1423}1424obj.load_item();14251426// info for exceptions1427CodeEmitInfo* info_for_exception =1428(x->needs_exception_state() ? state_for(x) :1429state_for(x, x->state_before(), true /*ignore_xhandler*/));14301431CodeStub* stub;1432if (x->is_incompatible_class_change_check()) {1433assert(patching_info == NULL, "can't patch this");1434stub = new SimpleExceptionStub(Runtime1::throw_incompatible_class_change_error_id, LIR_OprFact::illegalOpr, info_for_exception);1435} else if (x->is_invokespecial_receiver_check()) {1436assert(patching_info == NULL, "can't patch this");1437stub = new DeoptimizeStub(info_for_exception, Deoptimization::Reason_class_check, Deoptimization::Action_none);1438} else {1439stub = new SimpleExceptionStub(Runtime1::throw_class_cast_exception_id, obj.result(), info_for_exception);1440}1441LIR_Opr reg = rlock_result(x);1442LIR_Opr tmp3 = LIR_OprFact::illegalOpr;1443if (!x->klass()->is_loaded() || UseCompressedClassPointers) {1444tmp3 = new_register(objectType);1445}1446__ checkcast(reg, obj.result(), x->klass(),1447new_register(objectType), new_register(objectType), tmp3,1448x->direct_compare(), info_for_exception, patching_info, stub,1449x->profiled_method(), x->profiled_bci());1450}145114521453void LIRGenerator::do_InstanceOf(InstanceOf* x) {1454LIRItem obj(x->obj(), this);14551456// result and test object may not be in same register1457LIR_Opr reg = rlock_result(x);1458CodeEmitInfo* patching_info = NULL;1459if ((!x->klass()->is_loaded() || PatchALot)) {1460// must do this before locking the destination register as an oop register1461patching_info = state_for(x, x->state_before());1462}1463obj.load_item();1464LIR_Opr tmp3 = LIR_OprFact::illegalOpr;1465if (!x->klass()->is_loaded() || UseCompressedClassPointers) {1466tmp3 = new_register(objectType);1467}1468__ instanceof(reg, obj.result(), x->klass(),1469new_register(objectType), new_register(objectType), tmp3,1470x->direct_compare(), patching_info, x->profiled_method(), x->profiled_bci());1471}147214731474void LIRGenerator::do_If(If* x) {1475assert(x->number_of_sux() == 2, "inconsistency");1476ValueTag tag = x->x()->type()->tag();1477bool is_safepoint = x->is_safepoint();14781479If::Condition cond = x->cond();14801481LIRItem xitem(x->x(), this);1482LIRItem yitem(x->y(), this);1483LIRItem* xin = &xitem;1484LIRItem* yin = &yitem;14851486if (tag == longTag) {1487// for longs, only conditions "eql", "neq", "lss", "geq" are valid;1488// mirror for other conditions1489if (cond == If::gtr || cond == If::leq) {1490cond = Instruction::mirror(cond);1491xin = &yitem;1492yin = &xitem;1493}1494xin->set_destroys_register();1495}1496xin->load_item();1497if (tag == longTag && yin->is_constant() && yin->get_jlong_constant() == 0 && (cond == If::eql || cond == If::neq)) {1498// inline long zero1499yin->dont_load_item();1500} else if (tag == longTag || tag == floatTag || tag == doubleTag) {1501// longs cannot handle constants at right side1502yin->load_item();1503} else {1504yin->dont_load_item();1505}15061507LIR_Opr left = xin->result();1508LIR_Opr right = yin->result();15091510set_no_result(x);15111512// add safepoint before generating condition code so it can be recomputed1513if (x->is_safepoint()) {1514// increment backedge counter if needed1515increment_backedge_counter_conditionally(lir_cond(cond), left, right, state_for(x, x->state_before()),1516x->tsux()->bci(), x->fsux()->bci(), x->profiled_bci());1517__ safepoint(safepoint_poll_register(), state_for(x, x->state_before()));1518}15191520__ cmp(lir_cond(cond), left, right);1521// Generate branch profiling. Profiling code doesn't kill flags.1522profile_branch(x, cond);1523move_to_phi(x->state());1524if (x->x()->type()->is_float_kind()) {1525__ branch(lir_cond(cond), x->tsux(), x->usux());1526} else {1527__ branch(lir_cond(cond), x->tsux());1528}1529assert(x->default_sux() == x->fsux(), "wrong destination above");1530__ jump(x->default_sux());1531}153215331534LIR_Opr LIRGenerator::getThreadPointer() {1535#ifdef _LP641536return FrameMap::as_pointer_opr(r15_thread);1537#else1538LIR_Opr result = new_register(T_INT);1539__ get_thread(result);1540return result;1541#endif //1542}15431544void LIRGenerator::trace_block_entry(BlockBegin* block) {1545store_stack_parameter(LIR_OprFact::intConst(block->block_id()), in_ByteSize(0));1546LIR_OprList* args = new LIR_OprList();1547address func = CAST_FROM_FN_PTR(address, Runtime1::trace_block_entry);1548__ call_runtime_leaf(func, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, args);1549}155015511552void LIRGenerator::volatile_field_store(LIR_Opr value, LIR_Address* address,1553CodeEmitInfo* info) {1554if (address->type() == T_LONG) {1555address = new LIR_Address(address->base(),1556address->index(), address->scale(),1557address->disp(), T_DOUBLE);1558// Transfer the value atomically by using FP moves. This means1559// the value has to be moved between CPU and FPU registers. It1560// always has to be moved through spill slot since there's no1561// quick way to pack the value into an SSE register.1562LIR_Opr temp_double = new_register(T_DOUBLE);1563LIR_Opr spill = new_register(T_LONG);1564set_vreg_flag(spill, must_start_in_memory);1565__ move(value, spill);1566__ volatile_move(spill, temp_double, T_LONG);1567__ volatile_move(temp_double, LIR_OprFact::address(address), T_LONG, info);1568} else {1569__ store(value, address, info);1570}1571}15721573void LIRGenerator::volatile_field_load(LIR_Address* address, LIR_Opr result,1574CodeEmitInfo* info) {1575if (address->type() == T_LONG) {1576address = new LIR_Address(address->base(),1577address->index(), address->scale(),1578address->disp(), T_DOUBLE);1579// Transfer the value atomically by using FP moves. This means1580// the value has to be moved between CPU and FPU registers. In1581// SSE0 and SSE1 mode it has to be moved through spill slot but in1582// SSE2+ mode it can be moved directly.1583LIR_Opr temp_double = new_register(T_DOUBLE);1584__ volatile_move(LIR_OprFact::address(address), temp_double, T_LONG, info);1585__ volatile_move(temp_double, result, T_LONG);1586#ifndef _LP641587if (UseSSE < 2) {1588// no spill slot needed in SSE2 mode because xmm->cpu register move is possible1589set_vreg_flag(result, must_start_in_memory);1590}1591#endif // !LP641592} else {1593__ load(address, result, info);1594}1595}159615971598