Path: blob/master/src/hotspot/cpu/s390/c1_LIRGenerator_s390.cpp
40930 views
/*1* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2016, 2017 SAP SE. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#include "precompiled.hpp"26#include "c1/c1_Compilation.hpp"27#include "c1/c1_FrameMap.hpp"28#include "c1/c1_Instruction.hpp"29#include "c1/c1_LIRAssembler.hpp"30#include "c1/c1_LIRGenerator.hpp"31#include "c1/c1_Runtime1.hpp"32#include "c1/c1_ValueStack.hpp"33#include "ci/ciArray.hpp"34#include "ci/ciObjArrayKlass.hpp"35#include "ci/ciTypeArrayKlass.hpp"36#include "runtime/sharedRuntime.hpp"37#include "runtime/stubRoutines.hpp"38#include "vmreg_s390.inline.hpp"39#include "utilities/powerOfTwo.hpp"4041#ifdef ASSERT42#define __ gen()->lir(__FILE__, __LINE__)->43#else44#define __ gen()->lir()->45#endif4647void LIRItem::load_byte_item() {48// Byte loads use same registers as other loads.49load_item();50}5152void LIRItem::load_nonconstant(int bits) {53LIR_Opr r = value()->operand();54if (_gen->can_inline_as_constant(value(), bits)) {55if (!r->is_constant()) {56r = LIR_OprFact::value_type(value()->type());57}58_result = r;59} else {60load_item();61}62}6364//--------------------------------------------------------------65// LIRGenerator66//--------------------------------------------------------------6768LIR_Opr LIRGenerator::exceptionOopOpr() { return FrameMap::as_oop_opr(Z_EXC_OOP); }69LIR_Opr LIRGenerator::exceptionPcOpr() { return FrameMap::as_opr(Z_EXC_PC); }70LIR_Opr LIRGenerator::divInOpr() { return FrameMap::Z_R11_opr; }71LIR_Opr LIRGenerator::divOutOpr() { return FrameMap::Z_R11_opr; }72LIR_Opr LIRGenerator::remOutOpr() { return FrameMap::Z_R10_opr; }73LIR_Opr LIRGenerator::ldivInOpr() { return FrameMap::Z_R11_long_opr; }74LIR_Opr LIRGenerator::ldivOutOpr() { return FrameMap::Z_R11_long_opr; }75LIR_Opr LIRGenerator::lremOutOpr() { return FrameMap::Z_R10_long_opr; }76LIR_Opr LIRGenerator::syncLockOpr() { return new_register(T_INT); }77LIR_Opr LIRGenerator::syncTempOpr() { return FrameMap::Z_R13_opr; }78LIR_Opr LIRGenerator::getThreadTemp() { return LIR_OprFact::illegalOpr; }7980LIR_Opr LIRGenerator::result_register_for (ValueType* type, bool callee) {81LIR_Opr opr;82switch (type->tag()) {83case intTag: opr = FrameMap::Z_R2_opr; break;84case objectTag: opr = FrameMap::Z_R2_oop_opr; break;85case longTag: opr = FrameMap::Z_R2_long_opr; break;86case floatTag: opr = FrameMap::Z_F0_opr; break;87case doubleTag: opr = FrameMap::Z_F0_double_opr; break;8889case addressTag:90default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr;91}9293assert(opr->type_field() == as_OprType(as_BasicType(type)), "type mismatch");94return opr;95}9697LIR_Opr LIRGenerator::rlock_byte(BasicType type) {98return new_register(T_INT);99}100101//--------- Loading items into registers. --------------------------------102103// z/Architecture cannot inline all constants.104bool LIRGenerator::can_store_as_constant(Value v, BasicType type) const {105if (v->type()->as_IntConstant() != NULL) {106return Immediate::is_simm16(v->type()->as_IntConstant()->value());107} else if (v->type()->as_LongConstant() != NULL) {108return Immediate::is_simm16(v->type()->as_LongConstant()->value());109} else if (v->type()->as_ObjectConstant() != NULL) {110return v->type()->as_ObjectConstant()->value()->is_null_object();111} else {112return false;113}114}115116bool LIRGenerator::can_inline_as_constant(Value i, int bits) const {117if (i->type()->as_IntConstant() != NULL) {118return Assembler::is_simm(i->type()->as_IntConstant()->value(), bits);119} else if (i->type()->as_LongConstant() != NULL) {120return Assembler::is_simm(i->type()->as_LongConstant()->value(), bits);121} else {122return can_store_as_constant(i, as_BasicType(i->type()));123}124}125126bool LIRGenerator::can_inline_as_constant(LIR_Const* c) const {127if (c->type() == T_INT) {128return Immediate::is_simm20(c->as_jint());129} else if (c->type() == T_LONG) {130return Immediate::is_simm20(c->as_jlong());131}132return false;133}134135LIR_Opr LIRGenerator::safepoint_poll_register() {136return new_register(longType);137}138139LIR_Address* LIRGenerator::generate_address(LIR_Opr base, LIR_Opr index,140int shift, int disp, BasicType type) {141assert(base->is_register(), "must be");142if (index->is_constant()) {143intx large_disp = disp;144LIR_Const *constant = index->as_constant_ptr();145if (constant->type() == T_LONG) {146large_disp += constant->as_jlong() << shift;147} else {148large_disp += (intx)(constant->as_jint()) << shift;149}150if (Displacement::is_validDisp(large_disp)) {151return new LIR_Address(base, large_disp, type);152}153// Index is illegal so replace it with the displacement loaded into a register.154index = new_pointer_register();155__ move(LIR_OprFact::intptrConst(large_disp), index);156return new LIR_Address(base, index, type);157} else {158if (shift > 0) {159LIR_Opr tmp = new_pointer_register();160__ shift_left(index, shift, tmp);161index = tmp;162}163return new LIR_Address(base, index, disp, type);164}165}166167LIR_Address* LIRGenerator::emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr,168BasicType type) {169int elem_size = type2aelembytes(type);170int shift = exact_log2(elem_size);171int offset_in_bytes = arrayOopDesc::base_offset_in_bytes(type);172173LIR_Address* addr;174if (index_opr->is_constant()) {175addr = new LIR_Address(array_opr,176offset_in_bytes + (intx)(index_opr->as_jint()) * elem_size, type);177} else {178if (index_opr->type() == T_INT) {179LIR_Opr tmp = new_register(T_LONG);180__ convert(Bytecodes::_i2l, index_opr, tmp);181index_opr = tmp;182}183if (shift > 0) {184__ shift_left(index_opr, shift, index_opr);185}186addr = new LIR_Address(array_opr,187index_opr,188offset_in_bytes, type);189}190return addr;191}192193LIR_Opr LIRGenerator::load_immediate(int x, BasicType type) {194LIR_Opr r = LIR_OprFact::illegalOpr;195if (type == T_LONG) {196r = LIR_OprFact::longConst(x);197} else if (type == T_INT) {198r = LIR_OprFact::intConst(x);199} else {200ShouldNotReachHere();201}202return r;203}204205void LIRGenerator::increment_counter(address counter, BasicType type, int step) {206LIR_Opr pointer = new_pointer_register();207__ move(LIR_OprFact::intptrConst(counter), pointer);208LIR_Address* addr = new LIR_Address(pointer, type);209increment_counter(addr, step);210}211212void LIRGenerator::increment_counter(LIR_Address* addr, int step) {213__ add((LIR_Opr)addr, LIR_OprFact::intConst(step), (LIR_Opr)addr);214}215216void LIRGenerator::cmp_mem_int(LIR_Condition condition, LIR_Opr base, int disp, int c, CodeEmitInfo* info) {217LIR_Opr scratch = FrameMap::Z_R1_opr;218__ load(new LIR_Address(base, disp, T_INT), scratch, info);219__ cmp(condition, scratch, c);220}221222void LIRGenerator::cmp_reg_mem(LIR_Condition condition, LIR_Opr reg, LIR_Opr base, int disp, BasicType type, CodeEmitInfo* info) {223__ cmp_reg_mem(condition, reg, new LIR_Address(base, disp, type), info);224}225226bool LIRGenerator::strength_reduce_multiply(LIR_Opr left, jint c, LIR_Opr result, LIR_Opr tmp) {227if (tmp->is_valid()) {228if (is_power_of_2(c + 1)) {229__ move(left, tmp);230__ shift_left(left, log2i_exact(c + 1), left);231__ sub(left, tmp, result);232return true;233} else if (is_power_of_2(c - 1)) {234__ move(left, tmp);235__ shift_left(left, log2i_exact(c - 1), left);236__ add(left, tmp, result);237return true;238}239}240return false;241}242243void LIRGenerator::store_stack_parameter (LIR_Opr item, ByteSize offset_from_sp) {244BasicType type = item->type();245__ store(item, new LIR_Address(FrameMap::Z_SP_opr, in_bytes(offset_from_sp), type));246}247248//----------------------------------------------------------------------249// visitor functions250//----------------------------------------------------------------------251252void LIRGenerator::array_store_check(LIR_Opr value, LIR_Opr array, CodeEmitInfo* store_check_info, ciMethod* profiled_method, int profiled_bci) {253LIR_Opr tmp1 = new_register(objectType);254LIR_Opr tmp2 = new_register(objectType);255LIR_Opr tmp3 = LIR_OprFact::illegalOpr;256__ store_check(value, array, tmp1, tmp2, tmp3, store_check_info, profiled_method, profiled_bci);257}258259void LIRGenerator::do_MonitorEnter(MonitorEnter* x) {260assert(x->is_pinned(),"");261LIRItem obj(x->obj(), this);262obj.load_item();263264set_no_result(x);265266// "lock" stores the address of the monitor stack slot, so this is not an oop.267LIR_Opr lock = new_register(T_INT);268269CodeEmitInfo* info_for_exception = NULL;270if (x->needs_null_check()) {271info_for_exception = state_for (x);272}273// This CodeEmitInfo must not have the xhandlers because here the274// object is already locked (xhandlers expect object to be unlocked).275CodeEmitInfo* info = state_for (x, x->state(), true);276monitor_enter(obj.result(), lock, syncTempOpr(), LIR_OprFact::illegalOpr,277x->monitor_no(), info_for_exception, info);278}279280void LIRGenerator::do_MonitorExit(MonitorExit* x) {281assert(x->is_pinned(),"");282283LIRItem obj(x->obj(), this);284obj.dont_load_item();285286LIR_Opr lock = new_register(T_INT);287LIR_Opr obj_temp = new_register(T_INT);288set_no_result(x);289monitor_exit(obj_temp, lock, syncTempOpr(), LIR_OprFact::illegalOpr, x->monitor_no());290}291292// _ineg, _lneg, _fneg, _dneg293void LIRGenerator::do_NegateOp(NegateOp* x) {294LIRItem value(x->x(), this);295value.load_item();296LIR_Opr reg = rlock_result(x);297__ negate(value.result(), reg);298}299300// for _fadd, _fmul, _fsub, _fdiv, _frem301// _dadd, _dmul, _dsub, _ddiv, _drem302void LIRGenerator::do_ArithmeticOp_FPU(ArithmeticOp* x) {303LIRItem left(x->x(), this);304LIRItem right(x->y(), this);305LIRItem* left_arg = &left;306LIRItem* right_arg = &right;307assert(!left.is_stack(), "can't both be memory operands");308left.load_item();309310if (right.is_register() || right.is_constant()) {311right.load_item();312} else {313right.dont_load_item();314}315316if ((x->op() == Bytecodes::_frem) || (x->op() == Bytecodes::_drem)) {317address entry;318switch (x->op()) {319case Bytecodes::_frem:320entry = CAST_FROM_FN_PTR(address, SharedRuntime::frem);321break;322case Bytecodes::_drem:323entry = CAST_FROM_FN_PTR(address, SharedRuntime::drem);324break;325default:326ShouldNotReachHere();327}328LIR_Opr result = call_runtime(x->x(), x->y(), entry, x->type(), NULL);329set_result(x, result);330} else {331LIR_Opr reg = rlock(x);332LIR_Opr tmp = LIR_OprFact::illegalOpr;333arithmetic_op_fpu(x->op(), reg, left.result(), right.result(), tmp);334set_result(x, reg);335}336}337338// for _ladd, _lmul, _lsub, _ldiv, _lrem339void LIRGenerator::do_ArithmeticOp_Long(ArithmeticOp* x) {340if (x->op() == Bytecodes::_ldiv || x->op() == Bytecodes::_lrem) {341// Use shifts if divisior is a power of 2 otherwise use DSGR instruction.342// Instruction: DSGR R1, R2343// input : R1+1: dividend (R1, R1+1 designate a register pair, R1 must be even)344// R2: divisor345//346// output: R1+1: quotient347// R1: remainder348//349// Register selection: R1: Z_R10350// R1+1: Z_R11351// R2: to be chosen by register allocator (linear scan)352353// R1, and R1+1 will be destroyed.354355LIRItem right(x->y(), this);356LIRItem left(x->x() , this); // Visit left second, so that the is_register test is valid.357358// Call state_for before load_item_force because state_for may359// force the evaluation of other instructions that are needed for360// correct debug info. Otherwise the live range of the fix361// register might be too long.362CodeEmitInfo* info = state_for (x);363364LIR_Opr result = rlock_result(x);365LIR_Opr result_reg = result;366LIR_Opr tmp = LIR_OprFact::illegalOpr;367LIR_Opr divisor_opr = right.result();368if (divisor_opr->is_constant() && is_power_of_2(divisor_opr->as_jlong())) {369left.load_item();370right.dont_load_item();371} else {372left.load_item_force(ldivInOpr());373right.load_item();374375// DSGR instruction needs register pair.376if (x->op() == Bytecodes::_ldiv) {377result_reg = ldivOutOpr();378tmp = lremOutOpr();379} else {380result_reg = lremOutOpr();381tmp = ldivOutOpr();382}383}384385if (!ImplicitDiv0Checks) {386__ cmp(lir_cond_equal, right.result(), LIR_OprFact::longConst(0));387__ branch(lir_cond_equal, new DivByZeroStub(info));388// Idiv/irem cannot trap (passing info would generate an assertion).389info = NULL;390}391392if (x->op() == Bytecodes::_lrem) {393__ irem(left.result(), right.result(), result_reg, tmp, info);394} else if (x->op() == Bytecodes::_ldiv) {395__ idiv(left.result(), right.result(), result_reg, tmp, info);396} else {397ShouldNotReachHere();398}399400if (result_reg != result) {401__ move(result_reg, result);402}403} else {404LIRItem left(x->x(), this);405LIRItem right(x->y(), this);406407left.load_item();408right.load_nonconstant(32);409rlock_result(x);410arithmetic_op_long(x->op(), x->operand(), left.result(), right.result(), NULL);411}412}413414// for: _iadd, _imul, _isub, _idiv, _irem415void LIRGenerator::do_ArithmeticOp_Int(ArithmeticOp* x) {416if (x->op() == Bytecodes::_idiv || x->op() == Bytecodes::_irem) {417// Use shifts if divisior is a power of 2 otherwise use DSGFR instruction.418// Instruction: DSGFR R1, R2419// input : R1+1: dividend (R1, R1+1 designate a register pair, R1 must be even)420// R2: divisor421//422// output: R1+1: quotient423// R1: remainder424//425// Register selection: R1: Z_R10426// R1+1: Z_R11427// R2: To be chosen by register allocator (linear scan).428429// R1, and R1+1 will be destroyed.430431LIRItem right(x->y(), this);432LIRItem left(x->x() , this); // Visit left second, so that the is_register test is valid.433434// Call state_for before load_item_force because state_for may435// force the evaluation of other instructions that are needed for436// correct debug info. Otherwise the live range of the fix437// register might be too long.438CodeEmitInfo* info = state_for (x);439440LIR_Opr result = rlock_result(x);441LIR_Opr result_reg = result;442LIR_Opr tmp = LIR_OprFact::illegalOpr;443LIR_Opr divisor_opr = right.result();444if (divisor_opr->is_constant() && is_power_of_2(divisor_opr->as_jint())) {445left.load_item();446right.dont_load_item();447} else {448left.load_item_force(divInOpr());449right.load_item();450451// DSGFR instruction needs register pair.452if (x->op() == Bytecodes::_idiv) {453result_reg = divOutOpr();454tmp = remOutOpr();455} else {456result_reg = remOutOpr();457tmp = divOutOpr();458}459}460461if (!ImplicitDiv0Checks) {462__ cmp(lir_cond_equal, right.result(), LIR_OprFact::intConst(0));463__ branch(lir_cond_equal, new DivByZeroStub(info));464// Idiv/irem cannot trap (passing info would generate an assertion).465info = NULL;466}467468if (x->op() == Bytecodes::_irem) {469__ irem(left.result(), right.result(), result_reg, tmp, info);470} else if (x->op() == Bytecodes::_idiv) {471__ idiv(left.result(), right.result(), result_reg, tmp, info);472} else {473ShouldNotReachHere();474}475476if (result_reg != result) {477__ move(result_reg, result);478}479} else {480LIRItem left(x->x(), this);481LIRItem right(x->y(), this);482LIRItem* left_arg = &left;483LIRItem* right_arg = &right;484if (x->is_commutative() && left.is_stack() && right.is_register()) {485// swap them if left is real stack (or cached) and right is real register(not cached)486left_arg = &right;487right_arg = &left;488}489490left_arg->load_item();491492// Do not need to load right, as we can handle stack and constants.493if (x->op() == Bytecodes::_imul) {494bool use_tmp = false;495if (right_arg->is_constant()) {496int iconst = right_arg->get_jint_constant();497if (is_power_of_2(iconst - 1) || is_power_of_2(iconst + 1)) {498use_tmp = true;499}500}501right_arg->dont_load_item();502LIR_Opr tmp = LIR_OprFact::illegalOpr;503if (use_tmp) {504tmp = new_register(T_INT);505}506rlock_result(x);507508arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), tmp);509} else {510right_arg->dont_load_item();511rlock_result(x);512LIR_Opr tmp = LIR_OprFact::illegalOpr;513arithmetic_op_int(x->op(), x->operand(), left_arg->result(), right_arg->result(), tmp);514}515}516}517518void LIRGenerator::do_ArithmeticOp(ArithmeticOp* x) {519// If an operand with use count 1 is the left operand, then it is520// likely that no move for 2-operand-LIR-form is necessary.521if (x->is_commutative() && x->y()->as_Constant() == NULL && x->x()->use_count() > x->y()->use_count()) {522x->swap_operands();523}524525ValueTag tag = x->type()->tag();526assert(x->x()->type()->tag() == tag && x->y()->type()->tag() == tag, "wrong parameters");527switch (tag) {528case floatTag:529case doubleTag: do_ArithmeticOp_FPU(x); return;530case longTag: do_ArithmeticOp_Long(x); return;531case intTag: do_ArithmeticOp_Int(x); return;532default:533ShouldNotReachHere();534}535}536537// _ishl, _lshl, _ishr, _lshr, _iushr, _lushr538void LIRGenerator::do_ShiftOp(ShiftOp* x) {539// count must always be in rcx540LIRItem value(x->x(), this);541LIRItem count(x->y(), this);542543ValueTag elemType = x->type()->tag();544bool must_load_count = !count.is_constant();545if (must_load_count) {546count.load_item();547} else {548count.dont_load_item();549}550value.load_item();551LIR_Opr reg = rlock_result(x);552553shift_op(x->op(), reg, value.result(), count.result(), LIR_OprFact::illegalOpr);554}555556// _iand, _land, _ior, _lor, _ixor, _lxor557void LIRGenerator::do_LogicOp(LogicOp* x) {558// IF an operand with use count 1 is the left operand, then it is559// likely that no move for 2-operand-LIR-form is necessary.560if (x->is_commutative() && x->y()->as_Constant() == NULL && x->x()->use_count() > x->y()->use_count()) {561x->swap_operands();562}563564LIRItem left(x->x(), this);565LIRItem right(x->y(), this);566567left.load_item();568right.load_nonconstant(32);569LIR_Opr reg = rlock_result(x);570571logic_op(x->op(), reg, left.result(), right.result());572}573574// _lcmp, _fcmpl, _fcmpg, _dcmpl, _dcmpg575void LIRGenerator::do_CompareOp(CompareOp* x) {576LIRItem left(x->x(), this);577LIRItem right(x->y(), this);578left.load_item();579right.load_item();580LIR_Opr reg = rlock_result(x);581if (x->x()->type()->is_float_kind()) {582Bytecodes::Code code = x->op();583__ fcmp2int(left.result(), right.result(), reg, (code == Bytecodes::_fcmpl || code == Bytecodes::_dcmpl));584} else if (x->x()->type()->tag() == longTag) {585__ lcmp2int(left.result(), right.result(), reg);586} else {587ShouldNotReachHere();588}589}590591LIR_Opr LIRGenerator::atomic_cmpxchg(BasicType type, LIR_Opr addr, LIRItem& cmp_value, LIRItem& new_value) {592LIR_Opr t1 = LIR_OprFact::illegalOpr;593LIR_Opr t2 = LIR_OprFact::illegalOpr;594cmp_value.load_item();595new_value.load_item();596if (type == T_OBJECT) {597if (UseCompressedOops) {598t1 = new_register(T_OBJECT);599t2 = new_register(T_OBJECT);600}601__ cas_obj(addr->as_address_ptr()->base(), cmp_value.result(), new_value.result(), t1, t2);602} else if (type == T_INT) {603__ cas_int(addr->as_address_ptr()->base(), cmp_value.result(), new_value.result(), t1, t2);604} else if (type == T_LONG) {605__ cas_long(addr->as_address_ptr()->base(), cmp_value.result(), new_value.result(), t1, t2);606} else {607ShouldNotReachHere();608}609// Generate conditional move of boolean result.610LIR_Opr result = new_register(T_INT);611__ cmove(lir_cond_equal, LIR_OprFact::intConst(1), LIR_OprFact::intConst(0),612result, type);613return result;614}615616LIR_Opr LIRGenerator::atomic_xchg(BasicType type, LIR_Opr addr, LIRItem& value) {617Unimplemented(); // Currently not supported on this platform.618return LIR_OprFact::illegalOpr;619}620621LIR_Opr LIRGenerator::atomic_add(BasicType type, LIR_Opr addr, LIRItem& value) {622LIR_Opr result = new_register(type);623value.load_item();624__ xadd(addr, value.result(), result, LIR_OprFact::illegalOpr);625return result;626}627628void LIRGenerator::do_MathIntrinsic(Intrinsic* x) {629switch (x->id()) {630case vmIntrinsics::_dabs:631case vmIntrinsics::_dsqrt: {632assert(x->number_of_arguments() == 1, "wrong type");633LIRItem value(x->argument_at(0), this);634value.load_item();635LIR_Opr dst = rlock_result(x);636637switch (x->id()) {638case vmIntrinsics::_dsqrt: {639__ sqrt(value.result(), dst, LIR_OprFact::illegalOpr);640break;641}642case vmIntrinsics::_dabs: {643__ abs(value.result(), dst, LIR_OprFact::illegalOpr);644break;645}646default:647ShouldNotReachHere();648}649break;650}651case vmIntrinsics::_dsin: // fall through652case vmIntrinsics::_dcos: // fall through653case vmIntrinsics::_dtan: // fall through654case vmIntrinsics::_dlog: // fall through655case vmIntrinsics::_dlog10: // fall through656case vmIntrinsics::_dexp: {657assert(x->number_of_arguments() == 1, "wrong type");658659address runtime_entry = NULL;660switch (x->id()) {661case vmIntrinsics::_dsin:662runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dsin);663break;664case vmIntrinsics::_dcos:665runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dcos);666break;667case vmIntrinsics::_dtan:668runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dtan);669break;670case vmIntrinsics::_dlog:671runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog);672break;673case vmIntrinsics::_dlog10:674runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog10);675break;676case vmIntrinsics::_dexp:677runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dexp);678break;679default:680ShouldNotReachHere();681}682683LIR_Opr result = call_runtime(x->argument_at(0), runtime_entry, x->type(), NULL);684set_result(x, result);685break;686}687case vmIntrinsics::_dpow: {688assert(x->number_of_arguments() == 2, "wrong type");689address runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dpow);690LIR_Opr result = call_runtime(x->argument_at(0), x->argument_at(1), runtime_entry, x->type(), NULL);691set_result(x, result);692break;693}694default:695break;696}697}698699void LIRGenerator::do_ArrayCopy(Intrinsic* x) {700assert(x->number_of_arguments() == 5, "wrong type");701702// Copy stubs possibly call C code, e.g. G1 barriers, so we need to reserve room703// for the C ABI (see frame::z_abi_160).704BasicTypeArray sig; // Empty signature is precise enough.705frame_map()->c_calling_convention(&sig);706707// Make all state_for calls early since they can emit code.708CodeEmitInfo* info = state_for (x, x->state());709710LIRItem src(x->argument_at(0), this);711LIRItem src_pos(x->argument_at(1), this);712LIRItem dst(x->argument_at(2), this);713LIRItem dst_pos(x->argument_at(3), this);714LIRItem length(x->argument_at(4), this);715716// Operands for arraycopy must use fixed registers, otherwise717// LinearScan will fail allocation (because arraycopy always needs a718// call).719720src.load_item_force (FrameMap::as_oop_opr(Z_ARG1));721src_pos.load_item_force (FrameMap::as_opr(Z_ARG2));722dst.load_item_force (FrameMap::as_oop_opr(Z_ARG3));723dst_pos.load_item_force (FrameMap::as_opr(Z_ARG4));724length.load_item_force (FrameMap::as_opr(Z_ARG5));725726LIR_Opr tmp = FrameMap::as_opr(Z_R7);727728set_no_result(x);729730int flags;731ciArrayKlass* expected_type;732arraycopy_helper(x, &flags, &expected_type);733734__ arraycopy(src.result(), src_pos.result(), dst.result(), dst_pos.result(),735length.result(), tmp, expected_type, flags, info); // does add_safepoint736}737738// _i2l, _i2f, _i2d, _l2i, _l2f, _l2d, _f2i, _f2l, _f2d, _d2i, _d2l, _d2f739// _i2b, _i2c, _i2s740void LIRGenerator::do_Convert(Convert* x) {741LIRItem value(x->value(), this);742743value.load_item();744LIR_Opr reg = rlock_result(x);745__ convert(x->op(), value.result(), reg);746}747748void LIRGenerator::do_NewInstance(NewInstance* x) {749print_if_not_loaded(x);750751// This instruction can be deoptimized in the slow path : use752// Z_R2 as result register.753const LIR_Opr reg = result_register_for (x->type());754755CodeEmitInfo* info = state_for (x, x->state());756LIR_Opr tmp1 = FrameMap::Z_R12_oop_opr;757LIR_Opr tmp2 = FrameMap::Z_R13_oop_opr;758LIR_Opr tmp3 = reg;759LIR_Opr tmp4 = LIR_OprFact::illegalOpr;760LIR_Opr klass_reg = FrameMap::Z_R11_metadata_opr;761new_instance(reg, x->klass(), x->is_unresolved(), tmp1, tmp2, tmp3, tmp4, klass_reg, info);762LIR_Opr result = rlock_result(x);763__ move(reg, result);764}765766void LIRGenerator::do_NewTypeArray(NewTypeArray* x) {767CodeEmitInfo* info = state_for (x, x->state());768769LIRItem length(x->length(), this);770length.load_item();771772LIR_Opr reg = result_register_for (x->type());773LIR_Opr tmp1 = FrameMap::Z_R12_oop_opr;774LIR_Opr tmp2 = FrameMap::Z_R13_oop_opr;775LIR_Opr tmp3 = reg;776LIR_Opr tmp4 = LIR_OprFact::illegalOpr;777LIR_Opr klass_reg = FrameMap::Z_R11_metadata_opr;778LIR_Opr len = length.result();779BasicType elem_type = x->elt_type();780781__ metadata2reg(ciTypeArrayKlass::make(elem_type)->constant_encoding(), klass_reg);782783CodeStub* slow_path = new NewTypeArrayStub(klass_reg, len, reg, info);784__ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, elem_type, klass_reg, slow_path);785786LIR_Opr result = rlock_result(x);787__ move(reg, result);788}789790void LIRGenerator::do_NewObjectArray(NewObjectArray* x) {791// Evaluate state_for early since it may emit code.792CodeEmitInfo* info = state_for (x, x->state());793// In case of patching (i.e., object class is not yet loaded), we need to reexecute the instruction794// and therefore provide the state before the parameters have been consumed.795CodeEmitInfo* patching_info = NULL;796if (!x->klass()->is_loaded() || PatchALot) {797patching_info = state_for (x, x->state_before());798}799800LIRItem length(x->length(), this);801length.load_item();802803const LIR_Opr reg = result_register_for (x->type());804LIR_Opr tmp1 = FrameMap::Z_R12_oop_opr;805LIR_Opr tmp2 = FrameMap::Z_R13_oop_opr;806LIR_Opr tmp3 = LIR_OprFact::illegalOpr;807LIR_Opr tmp4 = LIR_OprFact::illegalOpr;808LIR_Opr klass_reg = FrameMap::Z_R11_metadata_opr;809LIR_Opr len = length.result();810811CodeStub* slow_path = new NewObjectArrayStub(klass_reg, len, reg, info);812ciKlass* obj = ciObjArrayKlass::make(x->klass());813if (obj == ciEnv::unloaded_ciobjarrayklass()) {814BAILOUT("encountered unloaded_ciobjarrayklass due to out of memory error");815}816klass2reg_with_patching(klass_reg, obj, patching_info);817__ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, T_OBJECT, klass_reg, slow_path);818819LIR_Opr result = rlock_result(x);820__ move(reg, result);821}822823void LIRGenerator::do_NewMultiArray(NewMultiArray* x) {824Values* dims = x->dims();825int i = dims->length();826LIRItemList* items = new LIRItemList(i, i, NULL);827while (i-- > 0) {828LIRItem* size = new LIRItem(dims->at(i), this);829items->at_put(i, size);830}831832// Evaluate state_for early since it may emit code.833CodeEmitInfo* patching_info = NULL;834if (!x->klass()->is_loaded() || PatchALot) {835patching_info = state_for (x, x->state_before());836837// Cannot re-use same xhandlers for multiple CodeEmitInfos, so838// clone all handlers (NOTE: Usually this is handled transparently839// by the CodeEmitInfo cloning logic in CodeStub constructors but840// is done explicitly here because a stub isn't being used).841x->set_exception_handlers(new XHandlers(x->exception_handlers()));842}843CodeEmitInfo* info = state_for (x, x->state());844845i = dims->length();846while (--i >= 0) {847LIRItem* size = items->at(i);848size->load_nonconstant(32);849// FrameMap::_reserved_argument_area_size includes the dimensions varargs, because850// it's initialized to hir()->max_stack() when the FrameMap is created.851store_stack_parameter(size->result(), in_ByteSize(i*sizeof(jint) + FrameMap::first_available_sp_in_frame));852}853854LIR_Opr klass_reg = FrameMap::Z_R3_metadata_opr;855klass2reg_with_patching(klass_reg, x->klass(), patching_info);856857LIR_Opr rank = FrameMap::Z_R4_opr;858__ move(LIR_OprFact::intConst(x->rank()), rank);859LIR_Opr varargs = FrameMap::Z_R5_opr;860__ leal(LIR_OprFact::address(new LIR_Address(FrameMap::Z_SP_opr, FrameMap::first_available_sp_in_frame, T_INT)),861varargs);862LIR_OprList* args = new LIR_OprList(3);863args->append(klass_reg);864args->append(rank);865args->append(varargs);866LIR_Opr reg = result_register_for (x->type());867__ call_runtime(Runtime1::entry_for (Runtime1::new_multi_array_id),868LIR_OprFact::illegalOpr,869reg, args, info);870871LIR_Opr result = rlock_result(x);872__ move(reg, result);873}874875void LIRGenerator::do_BlockBegin(BlockBegin* x) {876// Nothing to do.877}878879void LIRGenerator::do_CheckCast(CheckCast* x) {880LIRItem obj(x->obj(), this);881882CodeEmitInfo* patching_info = NULL;883if (!x->klass()->is_loaded() || (PatchALot && !x->is_incompatible_class_change_check() && !x->is_invokespecial_receiver_check())) {884// Must do this before locking the destination register as an oop register,885// and before the obj is loaded (the latter is for deoptimization).886patching_info = state_for (x, x->state_before());887}888obj.load_item();889890// info for exceptions891CodeEmitInfo* info_for_exception =892(x->needs_exception_state() ? state_for(x) :893state_for(x, x->state_before(), true /*ignore_xhandler*/));894895CodeStub* stub;896if (x->is_incompatible_class_change_check()) {897assert(patching_info == NULL, "can't patch this");898stub = new SimpleExceptionStub(Runtime1::throw_incompatible_class_change_error_id, LIR_OprFact::illegalOpr, info_for_exception);899} else if (x->is_invokespecial_receiver_check()) {900assert(patching_info == NULL, "can't patch this");901stub = new DeoptimizeStub(info_for_exception,902Deoptimization::Reason_class_check,903Deoptimization::Action_none);904} else {905stub = new SimpleExceptionStub(Runtime1::throw_class_cast_exception_id, obj.result(), info_for_exception);906}907LIR_Opr reg = rlock_result(x);908LIR_Opr tmp1 = new_register(objectType);909LIR_Opr tmp2 = new_register(objectType);910LIR_Opr tmp3 = LIR_OprFact::illegalOpr;911__ checkcast(reg, obj.result(), x->klass(),912tmp1, tmp2, tmp3,913x->direct_compare(), info_for_exception, patching_info, stub,914x->profiled_method(), x->profiled_bci());915}916917918void LIRGenerator::do_InstanceOf(InstanceOf* x) {919LIRItem obj(x->obj(), this);920CodeEmitInfo* patching_info = NULL;921if (!x->klass()->is_loaded() || PatchALot) {922patching_info = state_for (x, x->state_before());923}924// Ensure the result register is not the input register because the925// result is initialized before the patching safepoint.926obj.load_item();927LIR_Opr out_reg = rlock_result(x);928LIR_Opr tmp1 = new_register(objectType);929LIR_Opr tmp2 = new_register(objectType);930LIR_Opr tmp3 = LIR_OprFact::illegalOpr;931__ instanceof(out_reg, obj.result(), x->klass(), tmp1, tmp2, tmp3,932x->direct_compare(), patching_info,933x->profiled_method(), x->profiled_bci());934}935936937void LIRGenerator::do_If (If* x) {938assert(x->number_of_sux() == 2, "inconsistency");939ValueTag tag = x->x()->type()->tag();940bool is_safepoint = x->is_safepoint();941942If::Condition cond = x->cond();943944LIRItem xitem(x->x(), this);945LIRItem yitem(x->y(), this);946LIRItem* xin = &xitem;947LIRItem* yin = &yitem;948949if (tag == longTag) {950// For longs, only conditions "eql", "neq", "lss", "geq" are valid;951// mirror for other conditions.952if (cond == If::gtr || cond == If::leq) {953cond = Instruction::mirror(cond);954xin = &yitem;955yin = &xitem;956}957xin->set_destroys_register();958}959xin->load_item();960// TODO: don't load long constants != 0L961if (tag == longTag && yin->is_constant() && yin->get_jlong_constant() == 0 && (cond == If::eql || cond == If::neq)) {962// inline long zero963yin->dont_load_item();964} else if (tag == longTag || tag == floatTag || tag == doubleTag) {965// Longs cannot handle constants at right side.966yin->load_item();967} else {968yin->dont_load_item();969}970971LIR_Opr left = xin->result();972LIR_Opr right = yin->result();973974set_no_result(x);975976// Add safepoint before generating condition code so it can be recomputed.977if (x->is_safepoint()) {978// Increment backedge counter if needed.979increment_backedge_counter_conditionally(lir_cond(cond), left, right, state_for(x, x->state_before()),980x->tsux()->bci(), x->fsux()->bci(), x->profiled_bci());981// Use safepoint_poll_register() instead of LIR_OprFact::illegalOpr.982__ safepoint(safepoint_poll_register(), state_for (x, x->state_before()));983}984985__ cmp(lir_cond(cond), left, right);986// Generate branch profiling. Profiling code doesn't kill flags.987profile_branch(x, cond);988move_to_phi(x->state());989if (x->x()->type()->is_float_kind()) {990__ branch(lir_cond(cond), x->tsux(), x->usux());991} else {992__ branch(lir_cond(cond), x->tsux());993}994assert(x->default_sux() == x->fsux(), "wrong destination above");995__ jump(x->default_sux());996}997998LIR_Opr LIRGenerator::getThreadPointer() {999return FrameMap::as_pointer_opr(Z_thread);1000}10011002void LIRGenerator::trace_block_entry(BlockBegin* block) {1003__ move(LIR_OprFact::intConst(block->block_id()), FrameMap::Z_R2_opr);1004LIR_OprList* args = new LIR_OprList(1);1005args->append(FrameMap::Z_R2_opr);1006address func = CAST_FROM_FN_PTR(address, Runtime1::trace_block_entry);1007__ call_runtime_leaf(func, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, args);1008}10091010void LIRGenerator::volatile_field_store(LIR_Opr value, LIR_Address* address,1011CodeEmitInfo* info) {1012__ store(value, address, info);1013}10141015void LIRGenerator::volatile_field_load(LIR_Address* address, LIR_Opr result,1016CodeEmitInfo* info) {1017__ load(address, result, info);1018}10191020void LIRGenerator::do_update_CRC32(Intrinsic* x) {1021assert(UseCRC32Intrinsics, "or should not be here");1022LIR_Opr result = rlock_result(x);10231024switch (x->id()) {1025case vmIntrinsics::_updateCRC32: {1026LIRItem crc(x->argument_at(0), this);1027LIRItem val(x->argument_at(1), this);1028// Registers destroyed by update_crc32.1029crc.set_destroys_register();1030val.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();10541055if (index->is_valid()) {1056LIR_Opr tmp = new_register(T_LONG);1057__ convert(Bytecodes::_i2l, index, tmp);1058index = tmp;1059}10601061LIR_Address* a = new LIR_Address(base_op, index, offset, T_BYTE);10621063BasicTypeList signature(3);1064signature.append(T_INT);1065signature.append(T_ADDRESS);1066signature.append(T_INT);1067CallingConvention* cc = frame_map()->c_calling_convention(&signature);1068const LIR_Opr result_reg = result_register_for (x->type());10691070LIR_Opr arg1 = cc->at(0);1071LIR_Opr arg2 = cc->at(1);1072LIR_Opr arg3 = cc->at(2);10731074crc.load_item_force(arg1); // We skip int->long conversion here, because CRC32 stub doesn't care about high bits.1075__ leal(LIR_OprFact::address(a), arg2);1076len.load_item_force(arg3); // We skip int->long conversion here, because CRC32 stub expects int.10771078__ call_runtime_leaf(StubRoutines::updateBytesCRC32(), LIR_OprFact::illegalOpr, result_reg, cc->args());1079__ move(result_reg, result);1080break;1081}1082default: {1083ShouldNotReachHere();1084}1085}1086}10871088void LIRGenerator::do_update_CRC32C(Intrinsic* x) {1089assert(UseCRC32CIntrinsics, "or should not be here");1090LIR_Opr result = rlock_result(x);10911092switch (x->id()) {1093case vmIntrinsics::_updateBytesCRC32C:1094case vmIntrinsics::_updateDirectByteBufferCRC32C: {1095bool is_updateBytes = (x->id() == vmIntrinsics::_updateBytesCRC32C);10961097LIRItem crc(x->argument_at(0), this);1098LIRItem buf(x->argument_at(1), this);1099LIRItem off(x->argument_at(2), this);1100LIRItem end(x->argument_at(3), this);1101buf.load_item();1102off.load_nonconstant();1103end.load_nonconstant();11041105// len = end - off1106LIR_Opr len = end.result();1107LIR_Opr tmpA = new_register(T_INT);1108LIR_Opr tmpB = new_register(T_INT);1109__ move(end.result(), tmpA);1110__ move(off.result(), tmpB);1111__ sub(tmpA, tmpB, tmpA);1112len = tmpA;11131114LIR_Opr index = off.result();1115int offset = is_updateBytes ? arrayOopDesc::base_offset_in_bytes(T_BYTE) : 0;1116if (off.result()->is_constant()) {1117index = LIR_OprFact::illegalOpr;1118offset += off.result()->as_jint();1119}1120LIR_Opr base_op = buf.result();11211122if (index->is_valid()) {1123LIR_Opr tmp = new_register(T_LONG);1124__ convert(Bytecodes::_i2l, index, tmp);1125index = tmp;1126}11271128LIR_Address* a = new LIR_Address(base_op, index, offset, T_BYTE);11291130BasicTypeList signature(3);1131signature.append(T_INT);1132signature.append(T_ADDRESS);1133signature.append(T_INT);1134CallingConvention* cc = frame_map()->c_calling_convention(&signature);1135const LIR_Opr result_reg = result_register_for (x->type());11361137LIR_Opr arg1 = cc->at(0);1138LIR_Opr arg2 = cc->at(1);1139LIR_Opr arg3 = cc->at(2);11401141crc.load_item_force(arg1); // We skip int->long conversion here, because CRC32C stub doesn't care about high bits.1142__ leal(LIR_OprFact::address(a), arg2);1143__ move(len, cc->at(2)); // We skip int->long conversion here, because CRC32C stub expects int.11441145__ call_runtime_leaf(StubRoutines::updateBytesCRC32C(), LIR_OprFact::illegalOpr, result_reg, cc->args());1146__ move(result_reg, result);1147break;1148}1149default: {1150ShouldNotReachHere();1151}1152}1153}11541155void LIRGenerator::do_FmaIntrinsic(Intrinsic* x) {1156assert(x->number_of_arguments() == 3, "wrong type");1157assert(UseFMA, "Needs FMA instructions support.");1158LIRItem value(x->argument_at(0), this);1159LIRItem value1(x->argument_at(1), this);1160LIRItem value2(x->argument_at(2), this);11611162value2.set_destroys_register();11631164value.load_item();1165value1.load_item();1166value2.load_item();11671168LIR_Opr calc_input = value.result();1169LIR_Opr calc_input1 = value1.result();1170LIR_Opr calc_input2 = value2.result();1171LIR_Opr calc_result = rlock_result(x);11721173switch (x->id()) {1174case vmIntrinsics::_fmaD: __ fmad(calc_input, calc_input1, calc_input2, calc_result); break;1175case vmIntrinsics::_fmaF: __ fmaf(calc_input, calc_input1, calc_input2, calc_result); break;1176default: ShouldNotReachHere();1177}1178}11791180void LIRGenerator::do_vectorizedMismatch(Intrinsic* x) {1181fatal("vectorizedMismatch intrinsic is not implemented on this platform");1182}118311841185