Path: blob/master/src/hotspot/cpu/x86/c1_LIRGenerator_x86.cpp
41144 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);194addr = new LIR_Address(array_opr,195offset_in_bytes + (intx)(index_opr->as_jint()) * elem_size, type);196} else {197#ifdef _LP64198if (index_opr->type() == T_INT) {199LIR_Opr tmp = new_register(T_LONG);200__ convert(Bytecodes::_i2l, index_opr, tmp);201index_opr = tmp;202}203#endif // _LP64204addr = new LIR_Address(array_opr,205index_opr,206LIR_Address::scale(type),207offset_in_bytes, type);208}209return addr;210}211212213LIR_Opr LIRGenerator::load_immediate(int x, BasicType type) {214LIR_Opr r = NULL;215if (type == T_LONG) {216r = LIR_OprFact::longConst(x);217} else if (type == T_INT) {218r = LIR_OprFact::intConst(x);219} else {220ShouldNotReachHere();221}222return r;223}224225void LIRGenerator::increment_counter(address counter, BasicType type, int step) {226LIR_Opr pointer = new_pointer_register();227__ move(LIR_OprFact::intptrConst(counter), pointer);228LIR_Address* addr = new LIR_Address(pointer, type);229increment_counter(addr, step);230}231232233void LIRGenerator::increment_counter(LIR_Address* addr, int step) {234__ add((LIR_Opr)addr, LIR_OprFact::intConst(step), (LIR_Opr)addr);235}236237void LIRGenerator::cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info) {238__ cmp_mem_int(condition, base, disp, c, info);239}240241242void LIRGenerator::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, int disp, BasicType type, CodeEmitInfo* info) {243__ cmp_reg_mem(condition, reg, new LIR_Address(base, disp, type), info);244}245246247bool LIRGenerator::strength_reduce_multiply(LIR_Opr left, jint c, LIR_Opr result, LIR_Opr tmp) {248if (tmp->is_valid() && c > 0 && c < max_jint) {249if (is_power_of_2(c + 1)) {250__ move(left, tmp);251__ shift_left(left, log2i_exact(c + 1), left);252__ sub(left, tmp, result);253return true;254} else if (is_power_of_2(c - 1)) {255__ move(left, tmp);256__ shift_left(left, log2i_exact(c - 1), left);257__ add(left, tmp, result);258return true;259}260}261return false;262}263264265void LIRGenerator::store_stack_parameter (LIR_Opr item, ByteSize offset_from_sp) {266BasicType type = item->type();267__ store(item, new LIR_Address(FrameMap::rsp_opr, in_bytes(offset_from_sp), type));268}269270void LIRGenerator::array_store_check(LIR_Opr value, LIR_Opr array, CodeEmitInfo* store_check_info, ciMethod* profiled_method, int profiled_bci) {271LIR_Opr tmp1 = new_register(objectType);272LIR_Opr tmp2 = new_register(objectType);273LIR_Opr tmp3 = new_register(objectType);274__ store_check(value, array, tmp1, tmp2, tmp3, store_check_info, profiled_method, profiled_bci);275}276277//----------------------------------------------------------------------278// visitor functions279//----------------------------------------------------------------------280281void LIRGenerator::do_MonitorEnter(MonitorEnter* x) {282assert(x->is_pinned(),"");283LIRItem obj(x->obj(), this);284obj.load_item();285286set_no_result(x);287288// "lock" stores the address of the monitor stack slot, so this is not an oop289LIR_Opr lock = new_register(T_INT);290// Need a scratch register for biased locking on x86291LIR_Opr scratch = LIR_OprFact::illegalOpr;292if (UseBiasedLocking) {293scratch = new_register(T_INT);294}295296CodeEmitInfo* info_for_exception = NULL;297if (x->needs_null_check()) {298info_for_exception = state_for(x);299}300// this CodeEmitInfo must not have the xhandlers because here the301// object is already locked (xhandlers expect object to be unlocked)302CodeEmitInfo* info = state_for(x, x->state(), true);303monitor_enter(obj.result(), lock, syncTempOpr(), scratch,304x->monitor_no(), info_for_exception, info);305}306307308void LIRGenerator::do_MonitorExit(MonitorExit* x) {309assert(x->is_pinned(),"");310311LIRItem obj(x->obj(), this);312obj.dont_load_item();313314LIR_Opr lock = new_register(T_INT);315LIR_Opr obj_temp = new_register(T_INT);316set_no_result(x);317monitor_exit(obj_temp, lock, syncTempOpr(), LIR_OprFact::illegalOpr, x->monitor_no());318}319320321// _ineg, _lneg, _fneg, _dneg322void LIRGenerator::do_NegateOp(NegateOp* x) {323LIRItem value(x->x(), this);324value.set_destroys_register();325value.load_item();326LIR_Opr reg = rlock(x);327328LIR_Opr tmp = LIR_OprFact::illegalOpr;329#ifdef _LP64330if (UseAVX > 2 && !VM_Version::supports_avx512vl()) {331if (x->type()->tag() == doubleTag) {332tmp = new_register(T_DOUBLE);333__ move(LIR_OprFact::doubleConst(-0.0), tmp);334}335else if (x->type()->tag() == floatTag) {336tmp = new_register(T_FLOAT);337__ move(LIR_OprFact::floatConst(-0.0), tmp);338}339}340#endif341__ negate(value.result(), reg, tmp);342343set_result(x, round_item(reg));344}345346347// for _fadd, _fmul, _fsub, _fdiv, _frem348// _dadd, _dmul, _dsub, _ddiv, _drem349void LIRGenerator::do_ArithmeticOp_FPU(ArithmeticOp* x) {350LIRItem left(x->x(), this);351LIRItem right(x->y(), this);352LIRItem* left_arg = &left;353LIRItem* right_arg = &right;354assert(!left.is_stack() || !right.is_stack(), "can't both be memory operands");355bool must_load_both = (x->op() == Bytecodes::_frem || x->op() == Bytecodes::_drem);356if (left.is_register() || x->x()->type()->is_constant() || must_load_both) {357left.load_item();358} else {359left.dont_load_item();360}361362#ifndef _LP64363// do not load right operand if it is a constant. only 0 and 1 are364// loaded because there are special instructions for loading them365// without memory access (not needed for SSE2 instructions)366bool must_load_right = false;367if (right.is_constant()) {368LIR_Const* c = right.result()->as_constant_ptr();369assert(c != NULL, "invalid constant");370assert(c->type() == T_FLOAT || c->type() == T_DOUBLE, "invalid type");371372if (c->type() == T_FLOAT) {373must_load_right = UseSSE < 1 && (c->is_one_float() || c->is_zero_float());374} else {375must_load_right = UseSSE < 2 && (c->is_one_double() || c->is_zero_double());376}377}378#endif // !LP64379380if (must_load_both) {381// frem and drem destroy also right operand, so move it to a new register382right.set_destroys_register();383right.load_item();384} else if (right.is_register()) {385right.load_item();386#ifndef _LP64387} else if (must_load_right) {388right.load_item();389#endif // !LP64390} else {391right.dont_load_item();392}393LIR_Opr reg = rlock(x);394LIR_Opr tmp = LIR_OprFact::illegalOpr;395if (x->op() == Bytecodes::_dmul || x->op() == Bytecodes::_ddiv) {396tmp = new_register(T_DOUBLE);397}398399#ifdef _LP64400if (x->op() == Bytecodes::_frem || x->op() == Bytecodes::_drem) {401// frem and drem are implemented as a direct call into the runtime.402LIRItem left(x->x(), this);403LIRItem right(x->y(), this);404405BasicType bt = as_BasicType(x->type());406BasicTypeList signature(2);407signature.append(bt);408signature.append(bt);409CallingConvention* cc = frame_map()->c_calling_convention(&signature);410411const LIR_Opr result_reg = result_register_for(x->type());412left.load_item_force(cc->at(0));413right.load_item_force(cc->at(1));414415address entry = NULL;416switch (x->op()) {417case Bytecodes::_frem:418entry = CAST_FROM_FN_PTR(address, SharedRuntime::frem);419break;420case Bytecodes::_drem:421entry = CAST_FROM_FN_PTR(address, SharedRuntime::drem);422break;423default:424ShouldNotReachHere();425}426427LIR_Opr result = rlock_result(x);428__ call_runtime_leaf(entry, getThreadTemp(), result_reg, cc->args());429__ move(result_reg, result);430} else {431arithmetic_op_fpu(x->op(), reg, left.result(), right.result(), tmp);432set_result(x, round_item(reg));433}434#else435if ((UseSSE >= 1 && x->op() == Bytecodes::_frem) || (UseSSE >= 2 && x->op() == Bytecodes::_drem)) {436// special handling for frem and drem: no SSE instruction, so must use FPU with temporary fpu stack slots437LIR_Opr fpu0, fpu1;438if (x->op() == Bytecodes::_frem) {439fpu0 = LIR_OprFact::single_fpu(0);440fpu1 = LIR_OprFact::single_fpu(1);441} else {442fpu0 = LIR_OprFact::double_fpu(0);443fpu1 = LIR_OprFact::double_fpu(1);444}445__ move(right.result(), fpu1); // order of left and right operand is important!446__ move(left.result(), fpu0);447__ rem (fpu0, fpu1, fpu0);448__ move(fpu0, reg);449450} else {451arithmetic_op_fpu(x->op(), reg, left.result(), right.result(), tmp);452}453set_result(x, round_item(reg));454#endif // _LP64455}456457458// for _ladd, _lmul, _lsub, _ldiv, _lrem459void LIRGenerator::do_ArithmeticOp_Long(ArithmeticOp* x) {460if (x->op() == Bytecodes::_ldiv || x->op() == Bytecodes::_lrem ) {461// long division is implemented as a direct call into the runtime462LIRItem left(x->x(), this);463LIRItem right(x->y(), this);464465// the check for division by zero destroys the right operand466right.set_destroys_register();467468BasicTypeList signature(2);469signature.append(T_LONG);470signature.append(T_LONG);471CallingConvention* cc = frame_map()->c_calling_convention(&signature);472473// check for division by zero (destroys registers of right operand!)474CodeEmitInfo* info = state_for(x);475476const LIR_Opr result_reg = result_register_for(x->type());477left.load_item_force(cc->at(1));478right.load_item();479480__ move(right.result(), cc->at(0));481482__ cmp(lir_cond_equal, right.result(), LIR_OprFact::longConst(0));483__ branch(lir_cond_equal, new DivByZeroStub(info));484485address entry = NULL;486switch (x->op()) {487case Bytecodes::_lrem:488entry = CAST_FROM_FN_PTR(address, SharedRuntime::lrem);489break; // check if dividend is 0 is done elsewhere490case Bytecodes::_ldiv:491entry = CAST_FROM_FN_PTR(address, SharedRuntime::ldiv);492break; // check if dividend is 0 is done elsewhere493default:494ShouldNotReachHere();495}496497LIR_Opr result = rlock_result(x);498__ call_runtime_leaf(entry, getThreadTemp(), result_reg, cc->args());499__ move(result_reg, result);500} else if (x->op() == Bytecodes::_lmul) {501// missing test if instr is commutative and if we should swap502LIRItem left(x->x(), this);503LIRItem right(x->y(), this);504505// right register is destroyed by the long mul, so it must be506// copied to a new register.507right.set_destroys_register();508509left.load_item();510right.load_item();511512LIR_Opr reg = FrameMap::long0_opr;513arithmetic_op_long(x->op(), reg, left.result(), right.result(), NULL);514LIR_Opr result = rlock_result(x);515__ move(reg, result);516} else {517// missing test if instr is commutative and if we should swap518LIRItem left(x->x(), this);519LIRItem right(x->y(), this);520521left.load_item();522// don't load constants to save register523right.load_nonconstant();524rlock_result(x);525arithmetic_op_long(x->op(), x->operand(), left.result(), right.result(), NULL);526}527}528529530531// for: _iadd, _imul, _isub, _idiv, _irem532void LIRGenerator::do_ArithmeticOp_Int(ArithmeticOp* x) {533if (x->op() == Bytecodes::_idiv || x->op() == Bytecodes::_irem) {534// The requirements for division and modulo535// input : rax,: dividend min_int536// reg: divisor (may not be rax,/rdx) -1537//538// output: rax,: quotient (= rax, idiv reg) min_int539// rdx: remainder (= rax, irem reg) 0540541// rax, and rdx will be destroyed542543// Note: does this invalidate the spec ???544LIRItem right(x->y(), this);545LIRItem left(x->x() , this); // visit left second, so that the is_register test is valid546547// call state_for before load_item_force because state_for may548// force the evaluation of other instructions that are needed for549// correct debug info. Otherwise the live range of the fix550// register might be too long.551CodeEmitInfo* info = state_for(x);552553left.load_item_force(divInOpr());554555right.load_item();556557LIR_Opr result = rlock_result(x);558LIR_Opr result_reg;559if (x->op() == Bytecodes::_idiv) {560result_reg = divOutOpr();561} else {562result_reg = remOutOpr();563}564565if (!ImplicitDiv0Checks) {566__ cmp(lir_cond_equal, right.result(), LIR_OprFact::intConst(0));567__ branch(lir_cond_equal, new DivByZeroStub(info));568// Idiv/irem cannot trap (passing info would generate an assertion).569info = NULL;570}571LIR_Opr tmp = FrameMap::rdx_opr; // idiv and irem use rdx in their implementation572if (x->op() == Bytecodes::_irem) {573__ irem(left.result(), right.result(), result_reg, tmp, info);574} else if (x->op() == Bytecodes::_idiv) {575__ idiv(left.result(), right.result(), result_reg, tmp, info);576} else {577ShouldNotReachHere();578}579580__ move(result_reg, result);581} else {582// missing test if instr is commutative and if we should swap583LIRItem left(x->x(), this);584LIRItem right(x->y(), this);585LIRItem* left_arg = &left;586LIRItem* right_arg = &right;587if (x->is_commutative() && left.is_stack() && right.is_register()) {588// swap them if left is real stack (or cached) and right is real register(not cached)589left_arg = &right;590right_arg = &left;591}592593left_arg->load_item();594595// do not need to load right, as we can handle stack and constants596if (x->op() == Bytecodes::_imul ) {597// check if we can use shift instead598bool use_constant = false;599bool use_tmp = false;600if (right_arg->is_constant()) {601jint iconst = right_arg->get_jint_constant();602if (iconst > 0 && iconst < max_jint) {603if (is_power_of_2(iconst)) {604use_constant = true;605} else if (is_power_of_2(iconst - 1) || is_power_of_2(iconst + 1)) {606use_constant = true;607use_tmp = true;608}609}610}611if (use_constant) {612right_arg->dont_load_item();613} else {614right_arg->load_item();615}616LIR_Opr tmp = LIR_OprFact::illegalOpr;617if (use_tmp) {618tmp = new_register(T_INT);619}620rlock_result(x);621622arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), tmp);623} else {624right_arg->dont_load_item();625rlock_result(x);626LIR_Opr tmp = LIR_OprFact::illegalOpr;627arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), tmp);628}629}630}631632633void LIRGenerator::do_ArithmeticOp(ArithmeticOp* x) {634// when an operand with use count 1 is the left operand, then it is635// likely that no move for 2-operand-LIR-form is necessary636if (x->is_commutative() && x->y()->as_Constant() == NULL && x->x()->use_count() > x->y()->use_count()) {637x->swap_operands();638}639640ValueTag tag = x->type()->tag();641assert(x->x()->type()->tag() == tag && x->y()->type()->tag() == tag, "wrong parameters");642switch (tag) {643case floatTag:644case doubleTag: do_ArithmeticOp_FPU(x); return;645case longTag: do_ArithmeticOp_Long(x); return;646case intTag: do_ArithmeticOp_Int(x); return;647default: ShouldNotReachHere(); return;648}649}650651652// _ishl, _lshl, _ishr, _lshr, _iushr, _lushr653void LIRGenerator::do_ShiftOp(ShiftOp* x) {654// count must always be in rcx655LIRItem value(x->x(), this);656LIRItem count(x->y(), this);657658ValueTag elemType = x->type()->tag();659bool must_load_count = !count.is_constant() || elemType == longTag;660if (must_load_count) {661// count for long must be in register662count.load_item_force(shiftCountOpr());663} else {664count.dont_load_item();665}666value.load_item();667LIR_Opr reg = rlock_result(x);668669shift_op(x->op(), reg, value.result(), count.result(), LIR_OprFact::illegalOpr);670}671672673// _iand, _land, _ior, _lor, _ixor, _lxor674void LIRGenerator::do_LogicOp(LogicOp* x) {675// when an operand with use count 1 is the left operand, then it is676// likely that no move for 2-operand-LIR-form is necessary677if (x->is_commutative() && x->y()->as_Constant() == NULL && x->x()->use_count() > x->y()->use_count()) {678x->swap_operands();679}680681LIRItem left(x->x(), this);682LIRItem right(x->y(), this);683684left.load_item();685right.load_nonconstant();686LIR_Opr reg = rlock_result(x);687688logic_op(x->op(), reg, left.result(), right.result());689}690691692693// _lcmp, _fcmpl, _fcmpg, _dcmpl, _dcmpg694void LIRGenerator::do_CompareOp(CompareOp* x) {695LIRItem left(x->x(), this);696LIRItem right(x->y(), this);697ValueTag tag = x->x()->type()->tag();698if (tag == longTag) {699left.set_destroys_register();700}701left.load_item();702right.load_item();703LIR_Opr reg = rlock_result(x);704705if (x->x()->type()->is_float_kind()) {706Bytecodes::Code code = x->op();707__ fcmp2int(left.result(), right.result(), reg, (code == Bytecodes::_fcmpl || code == Bytecodes::_dcmpl));708} else if (x->x()->type()->tag() == longTag) {709__ lcmp2int(left.result(), right.result(), reg);710} else {711Unimplemented();712}713}714715LIR_Opr LIRGenerator::atomic_cmpxchg(BasicType type, LIR_Opr addr, LIRItem& cmp_value, LIRItem& new_value) {716LIR_Opr ill = LIR_OprFact::illegalOpr; // for convenience717if (is_reference_type(type)) {718cmp_value.load_item_force(FrameMap::rax_oop_opr);719new_value.load_item();720__ cas_obj(addr->as_address_ptr()->base(), cmp_value.result(), new_value.result(), ill, ill);721} else if (type == T_INT) {722cmp_value.load_item_force(FrameMap::rax_opr);723new_value.load_item();724__ cas_int(addr->as_address_ptr()->base(), cmp_value.result(), new_value.result(), ill, ill);725} else if (type == T_LONG) {726cmp_value.load_item_force(FrameMap::long0_opr);727new_value.load_item_force(FrameMap::long1_opr);728__ cas_long(addr->as_address_ptr()->base(), cmp_value.result(), new_value.result(), ill, ill);729} else {730Unimplemented();731}732LIR_Opr result = new_register(T_INT);733__ cmove(lir_cond_equal, LIR_OprFact::intConst(1), LIR_OprFact::intConst(0),734result, T_INT);735return result;736}737738LIR_Opr LIRGenerator::atomic_xchg(BasicType type, LIR_Opr addr, LIRItem& value) {739bool is_oop = is_reference_type(type);740LIR_Opr result = new_register(type);741value.load_item();742// Because we want a 2-arg form of xchg and xadd743__ move(value.result(), result);744assert(type == T_INT || is_oop LP64_ONLY( || type == T_LONG ), "unexpected type");745__ xchg(addr, result, result, LIR_OprFact::illegalOpr);746return result;747}748749LIR_Opr LIRGenerator::atomic_add(BasicType type, LIR_Opr addr, LIRItem& value) {750LIR_Opr result = new_register(type);751value.load_item();752// Because we want a 2-arg form of xchg and xadd753__ move(value.result(), result);754assert(type == T_INT LP64_ONLY( || type == T_LONG ), "unexpected type");755__ xadd(addr, result, result, LIR_OprFact::illegalOpr);756return result;757}758759void LIRGenerator::do_FmaIntrinsic(Intrinsic* x) {760assert(x->number_of_arguments() == 3, "wrong type");761assert(UseFMA, "Needs FMA instructions support.");762LIRItem value(x->argument_at(0), this);763LIRItem value1(x->argument_at(1), this);764LIRItem value2(x->argument_at(2), this);765766value2.set_destroys_register();767768value.load_item();769value1.load_item();770value2.load_item();771772LIR_Opr calc_input = value.result();773LIR_Opr calc_input1 = value1.result();774LIR_Opr calc_input2 = value2.result();775LIR_Opr calc_result = rlock_result(x);776777switch (x->id()) {778case vmIntrinsics::_fmaD: __ fmad(calc_input, calc_input1, calc_input2, calc_result); break;779case vmIntrinsics::_fmaF: __ fmaf(calc_input, calc_input1, calc_input2, calc_result); break;780default: ShouldNotReachHere();781}782783}784785786void LIRGenerator::do_MathIntrinsic(Intrinsic* x) {787assert(x->number_of_arguments() == 1 || (x->number_of_arguments() == 2 && x->id() == vmIntrinsics::_dpow), "wrong type");788789if (x->id() == vmIntrinsics::_dexp || x->id() == vmIntrinsics::_dlog ||790x->id() == vmIntrinsics::_dpow || x->id() == vmIntrinsics::_dcos ||791x->id() == vmIntrinsics::_dsin || x->id() == vmIntrinsics::_dtan ||792x->id() == vmIntrinsics::_dlog10) {793do_LibmIntrinsic(x);794return;795}796797LIRItem value(x->argument_at(0), this);798799bool use_fpu = false;800#ifndef _LP64801if (UseSSE < 2) {802value.set_destroys_register();803}804#endif // !LP64805value.load_item();806807LIR_Opr calc_input = value.result();808LIR_Opr calc_result = rlock_result(x);809810LIR_Opr tmp = LIR_OprFact::illegalOpr;811#ifdef _LP64812if (UseAVX > 2 && (!VM_Version::supports_avx512vl()) &&813(x->id() == vmIntrinsics::_dabs)) {814tmp = new_register(T_DOUBLE);815__ move(LIR_OprFact::doubleConst(-0.0), tmp);816}817#endif818819switch(x->id()) {820case vmIntrinsics::_dabs: __ abs (calc_input, calc_result, tmp); break;821case vmIntrinsics::_dsqrt: __ sqrt (calc_input, calc_result, LIR_OprFact::illegalOpr); break;822default: ShouldNotReachHere();823}824825if (use_fpu) {826__ move(calc_result, x->operand());827}828}829830void LIRGenerator::do_LibmIntrinsic(Intrinsic* x) {831LIRItem value(x->argument_at(0), this);832value.set_destroys_register();833834LIR_Opr calc_result = rlock_result(x);835LIR_Opr result_reg = result_register_for(x->type());836837CallingConvention* cc = NULL;838839if (x->id() == vmIntrinsics::_dpow) {840LIRItem value1(x->argument_at(1), this);841842value1.set_destroys_register();843844BasicTypeList signature(2);845signature.append(T_DOUBLE);846signature.append(T_DOUBLE);847cc = frame_map()->c_calling_convention(&signature);848value.load_item_force(cc->at(0));849value1.load_item_force(cc->at(1));850} else {851BasicTypeList signature(1);852signature.append(T_DOUBLE);853cc = frame_map()->c_calling_convention(&signature);854value.load_item_force(cc->at(0));855}856857#ifndef _LP64858LIR_Opr tmp = FrameMap::fpu0_double_opr;859result_reg = tmp;860switch(x->id()) {861case vmIntrinsics::_dexp:862if (StubRoutines::dexp() != NULL) {863__ call_runtime_leaf(StubRoutines::dexp(), getThreadTemp(), result_reg, cc->args());864} else {865__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dexp), getThreadTemp(), result_reg, cc->args());866}867break;868case vmIntrinsics::_dlog:869if (StubRoutines::dlog() != NULL) {870__ call_runtime_leaf(StubRoutines::dlog(), getThreadTemp(), result_reg, cc->args());871} else {872__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dlog), getThreadTemp(), result_reg, cc->args());873}874break;875case vmIntrinsics::_dlog10:876if (StubRoutines::dlog10() != NULL) {877__ call_runtime_leaf(StubRoutines::dlog10(), getThreadTemp(), result_reg, cc->args());878} else {879__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dlog10), getThreadTemp(), result_reg, cc->args());880}881break;882case vmIntrinsics::_dpow:883if (StubRoutines::dpow() != NULL) {884__ call_runtime_leaf(StubRoutines::dpow(), getThreadTemp(), result_reg, cc->args());885} else {886__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dpow), getThreadTemp(), result_reg, cc->args());887}888break;889case vmIntrinsics::_dsin:890if (VM_Version::supports_sse2() && StubRoutines::dsin() != NULL) {891__ call_runtime_leaf(StubRoutines::dsin(), getThreadTemp(), result_reg, cc->args());892} else {893__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dsin), getThreadTemp(), result_reg, cc->args());894}895break;896case vmIntrinsics::_dcos:897if (VM_Version::supports_sse2() && StubRoutines::dcos() != NULL) {898__ call_runtime_leaf(StubRoutines::dcos(), getThreadTemp(), result_reg, cc->args());899} else {900__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dcos), getThreadTemp(), result_reg, cc->args());901}902break;903case vmIntrinsics::_dtan:904if (StubRoutines::dtan() != NULL) {905__ call_runtime_leaf(StubRoutines::dtan(), getThreadTemp(), result_reg, cc->args());906} else {907__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtan), getThreadTemp(), result_reg, cc->args());908}909break;910default: ShouldNotReachHere();911}912#else913switch (x->id()) {914case vmIntrinsics::_dexp:915if (StubRoutines::dexp() != NULL) {916__ call_runtime_leaf(StubRoutines::dexp(), getThreadTemp(), result_reg, cc->args());917} else {918__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dexp), getThreadTemp(), result_reg, cc->args());919}920break;921case vmIntrinsics::_dlog:922if (StubRoutines::dlog() != NULL) {923__ call_runtime_leaf(StubRoutines::dlog(), getThreadTemp(), result_reg, cc->args());924} else {925__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dlog), getThreadTemp(), result_reg, cc->args());926}927break;928case vmIntrinsics::_dlog10:929if (StubRoutines::dlog10() != NULL) {930__ call_runtime_leaf(StubRoutines::dlog10(), getThreadTemp(), result_reg, cc->args());931} else {932__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dlog10), getThreadTemp(), result_reg, cc->args());933}934break;935case vmIntrinsics::_dpow:936if (StubRoutines::dpow() != NULL) {937__ call_runtime_leaf(StubRoutines::dpow(), getThreadTemp(), result_reg, cc->args());938} else {939__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dpow), getThreadTemp(), result_reg, cc->args());940}941break;942case vmIntrinsics::_dsin:943if (StubRoutines::dsin() != NULL) {944__ call_runtime_leaf(StubRoutines::dsin(), getThreadTemp(), result_reg, cc->args());945} else {946__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dsin), getThreadTemp(), result_reg, cc->args());947}948break;949case vmIntrinsics::_dcos:950if (StubRoutines::dcos() != NULL) {951__ call_runtime_leaf(StubRoutines::dcos(), getThreadTemp(), result_reg, cc->args());952} else {953__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dcos), getThreadTemp(), result_reg, cc->args());954}955break;956case vmIntrinsics::_dtan:957if (StubRoutines::dtan() != NULL) {958__ call_runtime_leaf(StubRoutines::dtan(), getThreadTemp(), result_reg, cc->args());959} else {960__ call_runtime_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtan), getThreadTemp(), result_reg, cc->args());961}962break;963default: ShouldNotReachHere();964}965#endif // _LP64966__ move(result_reg, calc_result);967}968969void LIRGenerator::do_ArrayCopy(Intrinsic* x) {970assert(x->number_of_arguments() == 5, "wrong type");971972// Make all state_for calls early since they can emit code973CodeEmitInfo* info = state_for(x, x->state());974975LIRItem src(x->argument_at(0), this);976LIRItem src_pos(x->argument_at(1), this);977LIRItem dst(x->argument_at(2), this);978LIRItem dst_pos(x->argument_at(3), this);979LIRItem length(x->argument_at(4), this);980981// operands for arraycopy must use fixed registers, otherwise982// LinearScan will fail allocation (because arraycopy always needs a983// call)984985#ifndef _LP64986src.load_item_force (FrameMap::rcx_oop_opr);987src_pos.load_item_force (FrameMap::rdx_opr);988dst.load_item_force (FrameMap::rax_oop_opr);989dst_pos.load_item_force (FrameMap::rbx_opr);990length.load_item_force (FrameMap::rdi_opr);991LIR_Opr tmp = (FrameMap::rsi_opr);992#else993994// The java calling convention will give us enough registers995// so that on the stub side the args will be perfect already.996// On the other slow/special case side we call C and the arg997// positions are not similar enough to pick one as the best.998// Also because the java calling convention is a "shifted" version999// of the C convention we can process the java args trivially into C1000// args without worry of overwriting during the xfer10011002src.load_item_force (FrameMap::as_oop_opr(j_rarg0));1003src_pos.load_item_force (FrameMap::as_opr(j_rarg1));1004dst.load_item_force (FrameMap::as_oop_opr(j_rarg2));1005dst_pos.load_item_force (FrameMap::as_opr(j_rarg3));1006length.load_item_force (FrameMap::as_opr(j_rarg4));10071008LIR_Opr tmp = FrameMap::as_opr(j_rarg5);1009#endif // LP6410101011set_no_result(x);10121013int flags;1014ciArrayKlass* expected_type;1015arraycopy_helper(x, &flags, &expected_type);10161017__ arraycopy(src.result(), src_pos.result(), dst.result(), dst_pos.result(), length.result(), tmp, expected_type, flags, info); // does add_safepoint1018}10191020void LIRGenerator::do_update_CRC32(Intrinsic* x) {1021assert(UseCRC32Intrinsics, "need AVX and LCMUL instructions support");1022// Make all state_for calls early since they can emit code1023LIR_Opr result = rlock_result(x);1024int flags = 0;1025switch (x->id()) {1026case vmIntrinsics::_updateCRC32: {1027LIRItem crc(x->argument_at(0), this);1028LIRItem val(x->argument_at(1), this);1029// val is destroyed by update_crc321030val.set_destroys_register();1031crc.load_item();1032val.load_item();1033__ update_crc32(crc.result(), val.result(), result);1034break;1035}1036case vmIntrinsics::_updateBytesCRC32:1037case vmIntrinsics::_updateByteBufferCRC32: {1038bool is_updateBytes = (x->id() == vmIntrinsics::_updateBytesCRC32);10391040LIRItem crc(x->argument_at(0), this);1041LIRItem buf(x->argument_at(1), this);1042LIRItem off(x->argument_at(2), this);1043LIRItem len(x->argument_at(3), this);1044buf.load_item();1045off.load_nonconstant();10461047LIR_Opr index = off.result();1048int offset = is_updateBytes ? arrayOopDesc::base_offset_in_bytes(T_BYTE) : 0;1049if(off.result()->is_constant()) {1050index = LIR_OprFact::illegalOpr;1051offset += off.result()->as_jint();1052}1053LIR_Opr base_op = buf.result();10541055#ifndef _LP641056if (!is_updateBytes) { // long b raw address1057base_op = new_register(T_INT);1058__ convert(Bytecodes::_l2i, buf.result(), base_op);1059}1060#else1061if (index->is_valid()) {1062LIR_Opr tmp = new_register(T_LONG);1063__ convert(Bytecodes::_i2l, index, tmp);1064index = tmp;1065}1066#endif10671068LIR_Address* a = new LIR_Address(base_op,1069index,1070offset,1071T_BYTE);1072BasicTypeList signature(3);1073signature.append(T_INT);1074signature.append(T_ADDRESS);1075signature.append(T_INT);1076CallingConvention* cc = frame_map()->c_calling_convention(&signature);1077const LIR_Opr result_reg = result_register_for(x->type());10781079LIR_Opr addr = new_pointer_register();1080__ leal(LIR_OprFact::address(a), addr);10811082crc.load_item_force(cc->at(0));1083__ move(addr, cc->at(1));1084len.load_item_force(cc->at(2));10851086__ call_runtime_leaf(StubRoutines::updateBytesCRC32(), getThreadTemp(), result_reg, cc->args());1087__ move(result_reg, result);10881089break;1090}1091default: {1092ShouldNotReachHere();1093}1094}1095}10961097void LIRGenerator::do_update_CRC32C(Intrinsic* x) {1098Unimplemented();1099}11001101void LIRGenerator::do_vectorizedMismatch(Intrinsic* x) {1102assert(UseVectorizedMismatchIntrinsic, "need AVX instruction support");11031104// Make all state_for calls early since they can emit code1105LIR_Opr result = rlock_result(x);11061107LIRItem a(x->argument_at(0), this); // Object1108LIRItem aOffset(x->argument_at(1), this); // long1109LIRItem b(x->argument_at(2), this); // Object1110LIRItem bOffset(x->argument_at(3), this); // long1111LIRItem length(x->argument_at(4), this); // int1112LIRItem log2ArrayIndexScale(x->argument_at(5), this); // int11131114a.load_item();1115aOffset.load_nonconstant();1116b.load_item();1117bOffset.load_nonconstant();11181119long constant_aOffset = 0;1120LIR_Opr result_aOffset = aOffset.result();1121if (result_aOffset->is_constant()) {1122constant_aOffset = result_aOffset->as_jlong();1123result_aOffset = LIR_OprFact::illegalOpr;1124}1125LIR_Opr result_a = a.result();11261127long constant_bOffset = 0;1128LIR_Opr result_bOffset = bOffset.result();1129if (result_bOffset->is_constant()) {1130constant_bOffset = result_bOffset->as_jlong();1131result_bOffset = LIR_OprFact::illegalOpr;1132}1133LIR_Opr result_b = b.result();11341135#ifndef _LP641136result_a = new_register(T_INT);1137__ convert(Bytecodes::_l2i, a.result(), result_a);1138result_b = new_register(T_INT);1139__ convert(Bytecodes::_l2i, b.result(), result_b);1140#endif114111421143LIR_Address* addr_a = new LIR_Address(result_a,1144result_aOffset,1145constant_aOffset,1146T_BYTE);11471148LIR_Address* addr_b = new LIR_Address(result_b,1149result_bOffset,1150constant_bOffset,1151T_BYTE);11521153BasicTypeList signature(4);1154signature.append(T_ADDRESS);1155signature.append(T_ADDRESS);1156signature.append(T_INT);1157signature.append(T_INT);1158CallingConvention* cc = frame_map()->c_calling_convention(&signature);1159const LIR_Opr result_reg = result_register_for(x->type());11601161LIR_Opr ptr_addr_a = new_pointer_register();1162__ leal(LIR_OprFact::address(addr_a), ptr_addr_a);11631164LIR_Opr ptr_addr_b = new_pointer_register();1165__ leal(LIR_OprFact::address(addr_b), ptr_addr_b);11661167__ move(ptr_addr_a, cc->at(0));1168__ move(ptr_addr_b, cc->at(1));1169length.load_item_force(cc->at(2));1170log2ArrayIndexScale.load_item_force(cc->at(3));11711172__ call_runtime_leaf(StubRoutines::vectorizedMismatch(), getThreadTemp(), result_reg, cc->args());1173__ move(result_reg, result);1174}11751176// _i2l, _i2f, _i2d, _l2i, _l2f, _l2d, _f2i, _f2l, _f2d, _d2i, _d2l, _d2f1177// _i2b, _i2c, _i2s1178LIR_Opr fixed_register_for(BasicType type) {1179switch (type) {1180case T_FLOAT: return FrameMap::fpu0_float_opr;1181case T_DOUBLE: return FrameMap::fpu0_double_opr;1182case T_INT: return FrameMap::rax_opr;1183case T_LONG: return FrameMap::long0_opr;1184default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr;1185}1186}11871188void LIRGenerator::do_Convert(Convert* x) {1189#ifdef _LP641190LIRItem value(x->value(), this);1191value.load_item();1192LIR_Opr input = value.result();1193LIR_Opr result = rlock(x);1194__ convert(x->op(), input, result);1195assert(result->is_virtual(), "result must be virtual register");1196set_result(x, result);1197#else1198// flags that vary for the different operations and different SSE-settings1199bool fixed_input = false, fixed_result = false, round_result = false, needs_stub = false;12001201switch (x->op()) {1202case Bytecodes::_i2l: // fall through1203case Bytecodes::_l2i: // fall through1204case Bytecodes::_i2b: // fall through1205case Bytecodes::_i2c: // fall through1206case Bytecodes::_i2s: fixed_input = false; fixed_result = false; round_result = false; needs_stub = false; break;12071208case Bytecodes::_f2d: fixed_input = UseSSE == 1; fixed_result = false; round_result = false; needs_stub = false; break;1209case Bytecodes::_d2f: fixed_input = false; fixed_result = UseSSE == 1; round_result = UseSSE < 1; needs_stub = false; break;1210case Bytecodes::_i2f: fixed_input = false; fixed_result = false; round_result = UseSSE < 1; needs_stub = false; break;1211case Bytecodes::_i2d: fixed_input = false; fixed_result = false; round_result = false; needs_stub = false; break;1212case Bytecodes::_f2i: fixed_input = false; fixed_result = false; round_result = false; needs_stub = true; break;1213case Bytecodes::_d2i: fixed_input = false; fixed_result = false; round_result = false; needs_stub = true; break;1214case Bytecodes::_l2f: fixed_input = false; fixed_result = UseSSE >= 1; round_result = UseSSE < 1; needs_stub = false; break;1215case Bytecodes::_l2d: fixed_input = false; fixed_result = UseSSE >= 2; round_result = UseSSE < 2; needs_stub = false; break;1216case Bytecodes::_f2l: fixed_input = true; fixed_result = true; round_result = false; needs_stub = false; break;1217case Bytecodes::_d2l: fixed_input = true; fixed_result = true; round_result = false; needs_stub = false; break;1218default: ShouldNotReachHere();1219}12201221LIRItem value(x->value(), this);1222value.load_item();1223LIR_Opr input = value.result();1224LIR_Opr result = rlock(x);12251226// arguments of lir_convert1227LIR_Opr conv_input = input;1228LIR_Opr conv_result = result;1229ConversionStub* stub = NULL;12301231if (fixed_input) {1232conv_input = fixed_register_for(input->type());1233__ move(input, conv_input);1234}12351236assert(fixed_result == false || round_result == false, "cannot set both");1237if (fixed_result) {1238conv_result = fixed_register_for(result->type());1239} else if (round_result) {1240result = new_register(result->type());1241set_vreg_flag(result, must_start_in_memory);1242}12431244if (needs_stub) {1245stub = new ConversionStub(x->op(), conv_input, conv_result);1246}12471248__ convert(x->op(), conv_input, conv_result, stub);12491250if (result != conv_result) {1251__ move(conv_result, result);1252}12531254assert(result->is_virtual(), "result must be virtual register");1255set_result(x, result);1256#endif // _LP641257}125812591260void LIRGenerator::do_NewInstance(NewInstance* x) {1261print_if_not_loaded(x);12621263CodeEmitInfo* info = state_for(x, x->state());1264LIR_Opr reg = result_register_for(x->type());1265new_instance(reg, x->klass(), x->is_unresolved(),1266FrameMap::rcx_oop_opr,1267FrameMap::rdi_oop_opr,1268FrameMap::rsi_oop_opr,1269LIR_OprFact::illegalOpr,1270FrameMap::rdx_metadata_opr, info);1271LIR_Opr result = rlock_result(x);1272__ move(reg, result);1273}127412751276void LIRGenerator::do_NewTypeArray(NewTypeArray* x) {1277CodeEmitInfo* info = state_for(x, x->state());12781279LIRItem length(x->length(), this);1280length.load_item_force(FrameMap::rbx_opr);12811282LIR_Opr reg = result_register_for(x->type());1283LIR_Opr tmp1 = FrameMap::rcx_oop_opr;1284LIR_Opr tmp2 = FrameMap::rsi_oop_opr;1285LIR_Opr tmp3 = FrameMap::rdi_oop_opr;1286LIR_Opr tmp4 = reg;1287LIR_Opr klass_reg = FrameMap::rdx_metadata_opr;1288LIR_Opr len = length.result();1289BasicType elem_type = x->elt_type();12901291__ metadata2reg(ciTypeArrayKlass::make(elem_type)->constant_encoding(), klass_reg);12921293CodeStub* slow_path = new NewTypeArrayStub(klass_reg, len, reg, info);1294__ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, elem_type, klass_reg, slow_path);12951296LIR_Opr result = rlock_result(x);1297__ move(reg, result);1298}129913001301void LIRGenerator::do_NewObjectArray(NewObjectArray* x) {1302LIRItem length(x->length(), this);1303// in case of patching (i.e., object class is not yet loaded), we need to reexecute the instruction1304// and therefore provide the state before the parameters have been consumed1305CodeEmitInfo* patching_info = NULL;1306if (!x->klass()->is_loaded() || PatchALot) {1307patching_info = state_for(x, x->state_before());1308}13091310CodeEmitInfo* info = state_for(x, x->state());13111312const LIR_Opr reg = result_register_for(x->type());1313LIR_Opr tmp1 = FrameMap::rcx_oop_opr;1314LIR_Opr tmp2 = FrameMap::rsi_oop_opr;1315LIR_Opr tmp3 = FrameMap::rdi_oop_opr;1316LIR_Opr tmp4 = reg;1317LIR_Opr klass_reg = FrameMap::rdx_metadata_opr;13181319length.load_item_force(FrameMap::rbx_opr);1320LIR_Opr len = length.result();13211322CodeStub* slow_path = new NewObjectArrayStub(klass_reg, len, reg, info);1323ciKlass* obj = (ciKlass*) ciObjArrayKlass::make(x->klass());1324if (obj == ciEnv::unloaded_ciobjarrayklass()) {1325BAILOUT("encountered unloaded_ciobjarrayklass due to out of memory error");1326}1327klass2reg_with_patching(klass_reg, obj, patching_info);1328__ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, T_OBJECT, klass_reg, slow_path);13291330LIR_Opr result = rlock_result(x);1331__ move(reg, result);1332}133313341335void LIRGenerator::do_NewMultiArray(NewMultiArray* x) {1336Values* dims = x->dims();1337int i = dims->length();1338LIRItemList* items = new LIRItemList(i, i, NULL);1339while (i-- > 0) {1340LIRItem* size = new LIRItem(dims->at(i), this);1341items->at_put(i, size);1342}13431344// Evaluate state_for early since it may emit code.1345CodeEmitInfo* patching_info = NULL;1346if (!x->klass()->is_loaded() || PatchALot) {1347patching_info = state_for(x, x->state_before());13481349// Cannot re-use same xhandlers for multiple CodeEmitInfos, so1350// clone all handlers (NOTE: Usually this is handled transparently1351// by the CodeEmitInfo cloning logic in CodeStub constructors but1352// is done explicitly here because a stub isn't being used).1353x->set_exception_handlers(new XHandlers(x->exception_handlers()));1354}1355CodeEmitInfo* info = state_for(x, x->state());13561357i = dims->length();1358while (i-- > 0) {1359LIRItem* size = items->at(i);1360size->load_nonconstant();13611362store_stack_parameter(size->result(), in_ByteSize(i*4));1363}13641365LIR_Opr klass_reg = FrameMap::rax_metadata_opr;1366klass2reg_with_patching(klass_reg, x->klass(), patching_info);13671368LIR_Opr rank = FrameMap::rbx_opr;1369__ move(LIR_OprFact::intConst(x->rank()), rank);1370LIR_Opr varargs = FrameMap::rcx_opr;1371__ move(FrameMap::rsp_opr, varargs);1372LIR_OprList* args = new LIR_OprList(3);1373args->append(klass_reg);1374args->append(rank);1375args->append(varargs);1376LIR_Opr reg = result_register_for(x->type());1377__ call_runtime(Runtime1::entry_for(Runtime1::new_multi_array_id),1378LIR_OprFact::illegalOpr,1379reg, args, info);13801381LIR_Opr result = rlock_result(x);1382__ move(reg, result);1383}138413851386void LIRGenerator::do_BlockBegin(BlockBegin* x) {1387// nothing to do for now1388}138913901391void LIRGenerator::do_CheckCast(CheckCast* x) {1392LIRItem obj(x->obj(), this);13931394CodeEmitInfo* patching_info = NULL;1395if (!x->klass()->is_loaded() || (PatchALot && !x->is_incompatible_class_change_check() && !x->is_invokespecial_receiver_check())) {1396// must do this before locking the destination register as an oop register,1397// and before the obj is loaded (the latter is for deoptimization)1398patching_info = state_for(x, x->state_before());1399}1400obj.load_item();14011402// info for exceptions1403CodeEmitInfo* info_for_exception =1404(x->needs_exception_state() ? state_for(x) :1405state_for(x, x->state_before(), true /*ignore_xhandler*/));14061407CodeStub* stub;1408if (x->is_incompatible_class_change_check()) {1409assert(patching_info == NULL, "can't patch this");1410stub = new SimpleExceptionStub(Runtime1::throw_incompatible_class_change_error_id, LIR_OprFact::illegalOpr, info_for_exception);1411} else if (x->is_invokespecial_receiver_check()) {1412assert(patching_info == NULL, "can't patch this");1413stub = new DeoptimizeStub(info_for_exception, Deoptimization::Reason_class_check, Deoptimization::Action_none);1414} else {1415stub = new SimpleExceptionStub(Runtime1::throw_class_cast_exception_id, obj.result(), info_for_exception);1416}1417LIR_Opr reg = rlock_result(x);1418LIR_Opr tmp3 = LIR_OprFact::illegalOpr;1419if (!x->klass()->is_loaded() || UseCompressedClassPointers) {1420tmp3 = new_register(objectType);1421}1422__ checkcast(reg, obj.result(), x->klass(),1423new_register(objectType), new_register(objectType), tmp3,1424x->direct_compare(), info_for_exception, patching_info, stub,1425x->profiled_method(), x->profiled_bci());1426}142714281429void LIRGenerator::do_InstanceOf(InstanceOf* x) {1430LIRItem obj(x->obj(), this);14311432// result and test object may not be in same register1433LIR_Opr reg = rlock_result(x);1434CodeEmitInfo* patching_info = NULL;1435if ((!x->klass()->is_loaded() || PatchALot)) {1436// must do this before locking the destination register as an oop register1437patching_info = state_for(x, x->state_before());1438}1439obj.load_item();1440LIR_Opr tmp3 = LIR_OprFact::illegalOpr;1441if (!x->klass()->is_loaded() || UseCompressedClassPointers) {1442tmp3 = new_register(objectType);1443}1444__ instanceof(reg, obj.result(), x->klass(),1445new_register(objectType), new_register(objectType), tmp3,1446x->direct_compare(), patching_info, x->profiled_method(), x->profiled_bci());1447}144814491450void LIRGenerator::do_If(If* x) {1451assert(x->number_of_sux() == 2, "inconsistency");1452ValueTag tag = x->x()->type()->tag();1453bool is_safepoint = x->is_safepoint();14541455If::Condition cond = x->cond();14561457LIRItem xitem(x->x(), this);1458LIRItem yitem(x->y(), this);1459LIRItem* xin = &xitem;1460LIRItem* yin = &yitem;14611462if (tag == longTag) {1463// for longs, only conditions "eql", "neq", "lss", "geq" are valid;1464// mirror for other conditions1465if (cond == If::gtr || cond == If::leq) {1466cond = Instruction::mirror(cond);1467xin = &yitem;1468yin = &xitem;1469}1470xin->set_destroys_register();1471}1472xin->load_item();1473if (tag == longTag && yin->is_constant() && yin->get_jlong_constant() == 0 && (cond == If::eql || cond == If::neq)) {1474// inline long zero1475yin->dont_load_item();1476} else if (tag == longTag || tag == floatTag || tag == doubleTag) {1477// longs cannot handle constants at right side1478yin->load_item();1479} else {1480yin->dont_load_item();1481}14821483LIR_Opr left = xin->result();1484LIR_Opr right = yin->result();14851486set_no_result(x);14871488// add safepoint before generating condition code so it can be recomputed1489if (x->is_safepoint()) {1490// increment backedge counter if needed1491increment_backedge_counter_conditionally(lir_cond(cond), left, right, state_for(x, x->state_before()),1492x->tsux()->bci(), x->fsux()->bci(), x->profiled_bci());1493__ safepoint(safepoint_poll_register(), state_for(x, x->state_before()));1494}14951496__ cmp(lir_cond(cond), left, right);1497// Generate branch profiling. Profiling code doesn't kill flags.1498profile_branch(x, cond);1499move_to_phi(x->state());1500if (x->x()->type()->is_float_kind()) {1501__ branch(lir_cond(cond), x->tsux(), x->usux());1502} else {1503__ branch(lir_cond(cond), x->tsux());1504}1505assert(x->default_sux() == x->fsux(), "wrong destination above");1506__ jump(x->default_sux());1507}150815091510LIR_Opr LIRGenerator::getThreadPointer() {1511#ifdef _LP641512return FrameMap::as_pointer_opr(r15_thread);1513#else1514LIR_Opr result = new_register(T_INT);1515__ get_thread(result);1516return result;1517#endif //1518}15191520void LIRGenerator::trace_block_entry(BlockBegin* block) {1521store_stack_parameter(LIR_OprFact::intConst(block->block_id()), in_ByteSize(0));1522LIR_OprList* args = new LIR_OprList();1523address func = CAST_FROM_FN_PTR(address, Runtime1::trace_block_entry);1524__ call_runtime_leaf(func, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, args);1525}152615271528void LIRGenerator::volatile_field_store(LIR_Opr value, LIR_Address* address,1529CodeEmitInfo* info) {1530if (address->type() == T_LONG) {1531address = new LIR_Address(address->base(),1532address->index(), address->scale(),1533address->disp(), T_DOUBLE);1534// Transfer the value atomically by using FP moves. This means1535// the value has to be moved between CPU and FPU registers. It1536// always has to be moved through spill slot since there's no1537// quick way to pack the value into an SSE register.1538LIR_Opr temp_double = new_register(T_DOUBLE);1539LIR_Opr spill = new_register(T_LONG);1540set_vreg_flag(spill, must_start_in_memory);1541__ move(value, spill);1542__ volatile_move(spill, temp_double, T_LONG);1543__ volatile_move(temp_double, LIR_OprFact::address(address), T_LONG, info);1544} else {1545__ store(value, address, info);1546}1547}15481549void LIRGenerator::volatile_field_load(LIR_Address* address, LIR_Opr result,1550CodeEmitInfo* info) {1551if (address->type() == T_LONG) {1552address = new LIR_Address(address->base(),1553address->index(), address->scale(),1554address->disp(), T_DOUBLE);1555// Transfer the value atomically by using FP moves. This means1556// the value has to be moved between CPU and FPU registers. In1557// SSE0 and SSE1 mode it has to be moved through spill slot but in1558// SSE2+ mode it can be moved directly.1559LIR_Opr temp_double = new_register(T_DOUBLE);1560__ volatile_move(LIR_OprFact::address(address), temp_double, T_LONG, info);1561__ volatile_move(temp_double, result, T_LONG);1562#ifndef _LP641563if (UseSSE < 2) {1564// no spill slot needed in SSE2 mode because xmm->cpu register move is possible1565set_vreg_flag(result, must_start_in_memory);1566}1567#endif // !LP641568} else {1569__ load(address, result, info);1570}1571}157215731574