src/cpu/mips/vm/c1_LIRGenerator_mips.cpp

Thu, 07 Sep 2017 09:12:16 +0800

author
aoqi
date
Thu, 07 Sep 2017 09:12:16 +0800
changeset 6880
52ea28d233d2
parent 1
2d8a650513c2
child 8859
f39c2b3891e2
permissions
-rw-r--r--

#5745 [Code Reorganization] code cleanup and code style fix
This is a huge patch, but only code cleanup, code style fix and useless code deletion are included, for example:
tab -> two spaces, deleted spacees at the end of a line, delete useless comments.

This patch also included:
Declaration and definition of class MacroAssembler is moved from assembler_mips.h/cpp to macroAssembler_mips.h/cpp

aoqi@1 1 /*
aoqi@1 2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@1 3 * Copyright (c) 2015, 2016, Loongson Technology. All rights reserved.
aoqi@1 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@1 5 *
aoqi@1 6 * This code is free software; you can redistribute it and/or modify it
aoqi@1 7 * under the terms of the GNU General Public License version 2 only, as
aoqi@1 8 * published by the Free Software Foundation.
aoqi@1 9 *
aoqi@1 10 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@1 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@1 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@1 13 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@1 14 * accompanied this code).
aoqi@1 15 *
aoqi@1 16 * You should have received a copy of the GNU General Public License version
aoqi@1 17 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@1 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@1 19 *
aoqi@1 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@1 21 * or visit www.oracle.com if you need additional information or have any
aoqi@1 22 * questions.
aoqi@1 23 *
aoqi@1 24 */
aoqi@1 25
aoqi@1 26 #include "precompiled.hpp"
aoqi@1 27 #include "c1/c1_Compilation.hpp"
aoqi@1 28 #include "c1/c1_FrameMap.hpp"
aoqi@1 29 #include "c1/c1_Instruction.hpp"
aoqi@1 30 #include "c1/c1_LIRAssembler.hpp"
aoqi@1 31 #include "c1/c1_LIRGenerator.hpp"
aoqi@1 32 #include "c1/c1_Runtime1.hpp"
aoqi@1 33 #include "c1/c1_ValueStack.hpp"
aoqi@1 34 #include "ci/ciArray.hpp"
aoqi@1 35 #include "ci/ciObjArrayKlass.hpp"
aoqi@1 36 #include "ci/ciTypeArrayKlass.hpp"
aoqi@1 37 #include "runtime/sharedRuntime.hpp"
aoqi@1 38 #include "runtime/stubRoutines.hpp"
aoqi@1 39 #include "vmreg_mips.inline.hpp"
aoqi@1 40
aoqi@1 41 #ifdef ASSERT
aoqi@1 42 #define __ gen()->lir(__FILE__, __LINE__)->
aoqi@1 43 #else
aoqi@1 44 #define __ gen()->lir()->
aoqi@1 45 #endif
aoqi@1 46
aoqi@1 47 // Item will be loaded into a byte register; Intel only
aoqi@1 48 void LIRItem::load_byte_item() {
aoqi@1 49 load_item();
aoqi@1 50 LIR_Opr res = result();
aoqi@1 51
aoqi@1 52 if (!res->is_virtual() || !_gen->is_vreg_flag_set(res, LIRGenerator::byte_reg)) {
aoqi@1 53 // make sure that it is a byte register
aoqi@1 54 assert(!value()->type()->is_float() && !value()->type()->is_double(),
aoqi@1 55 "can't load floats in byte register");
aoqi@1 56 LIR_Opr reg = _gen->rlock_byte(T_BYTE);
aoqi@1 57 __ move(res, reg);
aoqi@1 58
aoqi@1 59 _result = reg;
aoqi@1 60 }
aoqi@1 61 }
aoqi@1 62
aoqi@1 63
aoqi@1 64 void LIRItem::load_nonconstant() {
aoqi@1 65 LIR_Opr r = value()->operand();
aoqi@1 66 if (r->is_constant()) {
aoqi@1 67 _result = r;
aoqi@1 68 } else {
aoqi@1 69 load_item();
aoqi@1 70 }
aoqi@1 71 }
aoqi@1 72
aoqi@1 73 //--------------------------------------------------------------
aoqi@1 74 // LIRGenerator
aoqi@1 75 //--------------------------------------------------------------
aoqi@1 76 LIR_Opr LIRGenerator::exceptionOopOpr() { return FrameMap::_v0_oop_opr; }
aoqi@1 77 LIR_Opr LIRGenerator::exceptionPcOpr() { return FrameMap::_v1_opr; }
aoqi@6880 78 LIR_Opr LIRGenerator::divInOpr() { return FrameMap::_a0_opr; }//FIXME
aoqi@6880 79 LIR_Opr LIRGenerator::divOutOpr() { return FrameMap::_f0_opr; } //FIXME
aoqi@6880 80 LIR_Opr LIRGenerator::remOutOpr() { return FrameMap::_f0_opr; } //FIXME
aoqi@1 81 LIR_Opr LIRGenerator::shiftCountOpr() { return FrameMap::_t3_opr; } //
aoqi@1 82 LIR_Opr LIRGenerator::syncTempOpr() { return FrameMap::_t2_opr; }
aoqi@1 83 LIR_Opr LIRGenerator::getThreadTemp() { return LIR_OprFact::illegalOpr; } //
aoqi@1 84
aoqi@1 85
aoqi@1 86 LIR_Opr LIRGenerator::result_register_for(ValueType* type, bool callee) {
aoqi@6880 87 LIR_Opr opr;
aoqi@6880 88 switch (type->tag()) {
aoqi@6880 89 case intTag: {
aoqi@6880 90 opr = FrameMap::_v0_opr;
aoqi@6880 91 break;
aoqi@6880 92 }
aoqi@6880 93 case objectTag: {
aoqi@6880 94 opr = FrameMap::_v0_oop_opr;
aoqi@6880 95 break;
aoqi@6880 96 }
aoqi@6880 97 case longTag: {
aoqi@6880 98 opr = FrameMap::_v0_v1_long_opr;
aoqi@6880 99 break;
aoqi@6880 100 }
aoqi@6880 101 case floatTag: {
aoqi@6880 102 opr = FrameMap::_f0_float_opr;
aoqi@6880 103 break;
aoqi@6880 104 }
aoqi@6880 105 case doubleTag: {
aoqi@6880 106 opr = FrameMap::_d0_double_opr;
aoqi@6880 107 break;
aoqi@6880 108 }
aoqi@6880 109 case addressTag:
aoqi@6880 110 default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr;
aoqi@6880 111 }
aoqi@1 112
aoqi@6880 113 assert(opr->type_field() == as_OprType(as_BasicType(type)), "type mismatch");
aoqi@6880 114 return opr;
aoqi@1 115 }
aoqi@1 116
aoqi@1 117 LIR_Opr LIRGenerator::rlock_callee_saved(BasicType type) {
aoqi@6880 118 LIR_Opr reg = new_register(type);
aoqi@6880 119 set_vreg_flag(reg, callee_saved);
aoqi@6880 120 return reg;
aoqi@1 121 }
aoqi@1 122
aoqi@1 123
aoqi@1 124 LIR_Opr LIRGenerator::rlock_byte(BasicType type) {
aoqi@6880 125 return new_register(T_INT);
aoqi@1 126 }
aoqi@1 127
aoqi@1 128
aoqi@1 129 //--------- loading items into registers --------------------------------
aoqi@1 130
aoqi@1 131
aoqi@1 132 // i486 instructions can inline constants
aoqi@1 133 bool LIRGenerator::can_store_as_constant(Value v, BasicType type) const {
aoqi@1 134 if (type == T_SHORT || type == T_CHAR) {
aoqi@1 135 // there is no immediate move of word values in asembler_i486.?pp
aoqi@1 136 return false;
aoqi@1 137 }
aoqi@1 138 Constant* c = v->as_Constant();
aoqi@1 139 if (c && c->state_before() == NULL) {
aoqi@1 140 // constants of any type can be stored directly, except for
aoqi@1 141 // unloaded object constants.
aoqi@1 142 return true;
aoqi@1 143 }
aoqi@1 144 return false;
aoqi@1 145 }
aoqi@1 146
aoqi@1 147
aoqi@1 148 bool LIRGenerator::can_inline_as_constant(Value v) const {
aoqi@6880 149 if (v->type()->is_constant() && v->type()->as_IntConstant() != NULL) {
aoqi@6880 150 return Assembler::is_simm16(v->type()->as_IntConstant()->value());
aoqi@6880 151 } else {
aoqi@6880 152 return false;
aoqi@6880 153 }
aoqi@1 154 }
aoqi@1 155
aoqi@1 156
aoqi@1 157 bool LIRGenerator::can_inline_as_constant(LIR_Const* c) const {
aoqi@6880 158 if (c->type() == T_INT && c->as_constant() != NULL) {
aoqi@6880 159 return Assembler::is_simm16(c->as_jint());
aoqi@6880 160 } else {
aoqi@6880 161 return false;
aoqi@6880 162 }
aoqi@1 163 }
aoqi@1 164
aoqi@1 165
aoqi@1 166 LIR_Opr LIRGenerator::safepoint_poll_register() {
aoqi@1 167 return new_register(T_INT);
aoqi@1 168 }
aoqi@1 169
aoqi@6880 170
aoqi@1 171 LIR_Address* LIRGenerator::generate_address(LIR_Opr base, LIR_Opr index,
aoqi@1 172 int shift, int disp, BasicType type) {
aoqi@6880 173 assert(base->is_register(), "must be");
aoqi@6880 174 if (index->is_constant()) {
aoqi@6880 175 disp += index->as_constant_ptr()->as_jint() << shift;
aoqi@6880 176 if (Assembler::is_simm16(disp)) {
aoqi@6880 177 return new LIR_Address(base,disp, type);
aoqi@6880 178 } else {
aoqi@1 179
aoqi@6880 180 if(disp!=0){
aoqi@6880 181 #ifdef _LP64
aoqi@6880 182 LIR_Opr tmp = new_register(T_LONG);
aoqi@6880 183 #else
aoqi@6880 184 LIR_Opr tmp = new_register(T_INT);
aoqi@6880 185 #endif
aoqi@6880 186 __ move(LIR_OprFact::intConst((int)disp), tmp);
aoqi@6880 187 __ add(tmp, base, tmp);
aoqi@6880 188 return new LIR_Address(tmp, 0, type);
aoqi@6880 189 }
aoqi@6880 190 else
aoqi@6880 191 return new LIR_Address(base, 0, type);
aoqi@6880 192 }
aoqi@6880 193 } else if( index->is_register()) {
aoqi@1 194
aoqi@1 195 #ifdef _LP64
aoqi@6880 196 LIR_Opr tmpa = new_register(T_LONG);
aoqi@1 197 #else
aoqi@6880 198 LIR_Opr tmpa = new_register(T_INT);
aoqi@6880 199 #endif
aoqi@6880 200 __ move(index, tmpa);
aoqi@6880 201 __ shift_left(tmpa, shift, tmpa);
aoqi@6880 202 __ add(tmpa,base, tmpa);
aoqi@6880 203 if (Assembler::is_simm16(disp)) {
aoqi@6880 204 return new LIR_Address(tmpa, disp, type);
aoqi@6880 205 } else {
aoqi@6880 206 if (disp!=0) {
aoqi@6880 207 #ifdef _LP64
aoqi@6880 208 LIR_Opr tmp = new_register(T_LONG);
aoqi@6880 209 #else
aoqi@6880 210 LIR_Opr tmp = new_register(T_INT);
aoqi@1 211 #endif
aoqi@1 212
aoqi@6880 213 __ move(LIR_OprFact::intConst((int)disp), tmp);
aoqi@6880 214 __ add(tmp, tmpa, tmp);
aoqi@6880 215 return new LIR_Address(tmp, 0, type);
aoqi@6880 216 } else
aoqi@6880 217 return new LIR_Address(tmpa, 0, type);
aoqi@6880 218 }
aoqi@6880 219 } else {
aoqi@6880 220 if (Assembler::is_simm16(disp)) {
aoqi@6880 221 return new LIR_Address(base,disp, type);
aoqi@6880 222 } else {
aoqi@6880 223 if (disp!=0) {
aoqi@1 224 #ifdef _LP64
aoqi@6880 225 LIR_Opr tmp = new_register(T_LONG);
aoqi@1 226 #else
aoqi@6880 227 LIR_Opr tmp = new_register(T_INT);
aoqi@1 228 #endif
aoqi@6880 229 __ move(LIR_OprFact::intConst((int)disp), tmp);
aoqi@6880 230 __ add(tmp, base, tmp);
aoqi@6880 231 return new LIR_Address(tmp, 0, type);
aoqi@6880 232 } else
aoqi@6880 233 return new LIR_Address(base, 0, type);
aoqi@6880 234 }
aoqi@6880 235 }
aoqi@1 236 }
aoqi@1 237
aoqi@1 238 LIR_Address* LIRGenerator::emit_array_address(LIR_Opr array_opr, LIR_Opr index_opr,BasicType type, bool needs_card_mark) {
aoqi@6880 239 int offset_in_bytes = arrayOopDesc::base_offset_in_bytes(type);
aoqi@1 240
aoqi@6880 241 LIR_Address* addr;
aoqi@6880 242 if (index_opr->is_constant()) {
aoqi@6880 243 int elem_size = _type2aelembytes[type];
aoqi@6880 244 addr = new LIR_Address(array_opr,
aoqi@6880 245 offset_in_bytes + index_opr->as_jint() * elem_size, type);
aoqi@6880 246 } else if( index_opr->is_register()){
aoqi@1 247 #ifdef _LP64
aoqi@6880 248 LIR_Opr tmp = new_register(T_LONG);
aoqi@1 249 #else
aoqi@6880 250 LIR_Opr tmp = new_register(T_INT);
aoqi@1 251 #endif
aoqi@6880 252 __ move(index_opr, tmp);
aoqi@6880 253 __ shift_left(tmp, LIR_Address::scale(type),tmp);
aoqi@6880 254 __ add(tmp, array_opr, tmp);
aoqi@6880 255 addr = new LIR_Address(tmp, offset_in_bytes,type);
aoqi@1 256
aoqi@6880 257 }
aoqi@6880 258 else{
aoqi@6880 259 addr = new LIR_Address(array_opr,
aoqi@6880 260 offset_in_bytes, type);
aoqi@6880 261 }
aoqi@6880 262
aoqi@6880 263 if (needs_card_mark) {
aoqi@6880 264 // This store will need a precise card mark, so go ahead and
aoqi@6880 265 // compute the full adddres instead of computing once for the
aoqi@6880 266 // store and again for the card mark.
aoqi@1 267 #ifdef _LP64
aoqi@6880 268 LIR_Opr tmp = new_register(T_ADDRESS);
aoqi@1 269 #else
aoqi@6880 270 LIR_Opr tmp = new_register(T_INT);
aoqi@1 271 #endif
aoqi@6880 272 __ leal(LIR_OprFact::address(addr), tmp);
aoqi@6880 273 return new LIR_Address(tmp, 0, type);
aoqi@6880 274 } else {
aoqi@6880 275 return addr;
aoqi@6880 276 }
aoqi@1 277
aoqi@6880 278
aoqi@1 279 }
aoqi@1 280
aoqi@6880 281
aoqi@1 282 LIR_Opr LIRGenerator::load_immediate(int x, BasicType type) {
aoqi@1 283 LIR_Opr r;
aoqi@1 284 if (type == T_LONG) {
aoqi@1 285 r = LIR_OprFact::longConst(x);
aoqi@1 286 } else if (type == T_INT) {
aoqi@1 287 r = LIR_OprFact::intConst(x);
aoqi@1 288 } else {
aoqi@1 289 ShouldNotReachHere();
aoqi@1 290 }
aoqi@1 291 return r;
aoqi@1 292 }
aoqi@1 293
aoqi@1 294 void LIRGenerator::increment_counter(address counter, BasicType type, int step) {
aoqi@6880 295 LIR_Opr temp = new_register(T_INT);
aoqi@6880 296 LIR_Opr pointer = new_register(T_INT);
aoqi@1 297 #ifndef _LP64
aoqi@6880 298 __ move(LIR_OprFact::intConst((int)counter), pointer);
aoqi@1 299 #else
aoqi@6880 300 __ move(LIR_OprFact::longConst((long)counter), pointer);
aoqi@1 301 #endif
aoqi@6880 302 LIR_Opr addr = (LIR_Opr)new LIR_Address(pointer, type);
aoqi@6880 303 LIR_Opr c = LIR_OprFact::intConst((int)step);
aoqi@6880 304 __ add(addr, c, addr);
aoqi@1 305 }
aoqi@1 306
aoqi@1 307
aoqi@1 308 void LIRGenerator::increment_counter(LIR_Address* addr, int step) {
aoqi@1 309 Unimplemented();
aoqi@1 310 }
aoqi@1 311
aoqi@6880 312
aoqi@1 313 bool LIRGenerator::strength_reduce_multiply(LIR_Opr left, int c, LIR_Opr result, LIR_Opr tmp) {
aoqi@1 314 if (tmp->is_valid()) {
aoqi@1 315 if (is_power_of_2(c + 1)) {
aoqi@1 316 __ move(left, result);
aoqi@1 317 __ shift_left(result, log2_intptr(c + 1), result);
aoqi@1 318 __ sub(result, left, result);
aoqi@1 319 return true;
aoqi@1 320 } else if (is_power_of_2(c - 1)) {
aoqi@1 321 __ move(left, result);
aoqi@1 322 __ shift_left(result, log2_intptr(c - 1), result);
aoqi@1 323 __ add(result, left, result);
aoqi@1 324 return true;
aoqi@1 325 }
aoqi@1 326 }
aoqi@1 327 return false;
aoqi@1 328 }
aoqi@1 329
aoqi@6880 330
aoqi@1 331 void LIRGenerator::store_stack_parameter (LIR_Opr item, ByteSize offset_from_sp) {
aoqi@6880 332 BasicType type = item->type();
aoqi@6880 333 __ store(item, new LIR_Address(FrameMap::_sp_opr, in_bytes(offset_from_sp), type));
aoqi@1 334 }
aoqi@1 335
aoqi@1 336 //----------------------------------------------------------------------
aoqi@1 337 // visitor functions
aoqi@1 338 //----------------------------------------------------------------------
aoqi@1 339
aoqi@1 340
aoqi@1 341 void LIRGenerator::do_StoreIndexed(StoreIndexed* x) {
aoqi@1 342 assert(x->is_pinned(),"");
aoqi@1 343 bool needs_range_check = true;
aoqi@1 344 bool use_length = x->length() != NULL;
aoqi@1 345 bool obj_store = x->elt_type() == T_ARRAY || x->elt_type() == T_OBJECT;
aoqi@1 346 bool needs_store_check = obj_store && (x->value()->as_Constant() == NULL ||
aoqi@1 347 !get_jobject_constant(x->value())->is_null_object());
aoqi@1 348
aoqi@1 349 LIRItem array(x->array(), this);
aoqi@1 350 LIRItem index(x->index(), this);
aoqi@1 351 LIRItem value(x->value(), this);
aoqi@1 352 LIRItem length(this);
aoqi@1 353
aoqi@1 354 array.load_item();
aoqi@1 355 index.load_nonconstant();
aoqi@1 356
aoqi@1 357 if (use_length) {
aoqi@1 358 needs_range_check = x->compute_needs_range_check();
aoqi@1 359 if (needs_range_check) {
aoqi@1 360 length.set_instruction(x->length());
aoqi@1 361 length.load_item();
aoqi@1 362 }
aoqi@1 363 }
aoqi@1 364 if (needs_store_check) {
aoqi@1 365 value.load_item();
aoqi@1 366 } else {
aoqi@1 367 value.load_for_store(x->elt_type());
aoqi@1 368 }
aoqi@1 369
aoqi@1 370 set_no_result(x);
aoqi@1 371
aoqi@1 372 // the CodeEmitInfo must be duplicated for each different
aoqi@1 373 // LIR-instruction because spilling can occur anywhere between two
aoqi@1 374 // instructions and so the debug information must be different
aoqi@1 375 CodeEmitInfo* range_check_info = state_for(x);
aoqi@1 376 CodeEmitInfo* null_check_info = NULL;
aoqi@1 377 if (x->needs_null_check()) {
aoqi@1 378 null_check_info = new CodeEmitInfo(range_check_info);
aoqi@1 379 }
aoqi@1 380
aoqi@1 381 // emit array address setup early so it schedules better
aoqi@1 382 LIR_Address* array_addr = emit_array_address(array.result(), index.result(), x->elt_type(), obj_store);
aoqi@1 383
aoqi@1 384 if (GenerateRangeChecks && needs_range_check) {
aoqi@1 385 if (use_length) {
aoqi@1 386 __ branch(lir_cond_belowEqual, length.result(),index.result(),T_INT,new RangeCheckStub(range_check_info, index.result()));
aoqi@1 387 } else {
aoqi@1 388 array_range_check(array.result(), index.result(), null_check_info, range_check_info);
aoqi@1 389 // range_check also does the null check
aoqi@1 390 null_check_info = NULL;
aoqi@1 391 }
aoqi@1 392 }
aoqi@1 393
aoqi@1 394 if (GenerateArrayStoreCheck && needs_store_check) {
aoqi@1 395 LIR_Opr tmp1 = new_register(objectType);
aoqi@1 396 LIR_Opr tmp2 = new_register(objectType);
aoqi@1 397 LIR_Opr tmp3 = new_register(objectType);
aoqi@1 398
aoqi@1 399 CodeEmitInfo* store_check_info = new CodeEmitInfo(range_check_info);
aoqi@1 400 __ store_check(value.result(), array.result(), tmp1, tmp2, tmp3, store_check_info, x->profiled_method(), x->profiled_bci());
aoqi@1 401 }
aoqi@1 402
aoqi@1 403 if (obj_store) {
aoqi@1 404 // Needs GC write barriers.
aoqi@1 405 pre_barrier(LIR_OprFact::address(array_addr), LIR_OprFact::illegalOpr, true, false, NULL);
aoqi@1 406 __ move(value.result(), array_addr, null_check_info);
aoqi@1 407 // Seems to be a precise
aoqi@1 408 post_barrier(LIR_OprFact::address(array_addr), value.result());
aoqi@1 409 } else {
aoqi@1 410 __ move(value.result(), array_addr, null_check_info);
aoqi@1 411 }
aoqi@1 412 }
aoqi@1 413
aoqi@1 414
aoqi@1 415 void LIRGenerator::do_MonitorEnter(MonitorEnter* x) {
aoqi@1 416 assert(x->is_pinned(),"");
aoqi@1 417 LIRItem obj(x->obj(), this);
aoqi@1 418 obj.load_item();
aoqi@1 419
aoqi@1 420 set_no_result(x);
aoqi@1 421
aoqi@1 422 // "lock" stores the address of the monitor stack slot, so this is not an oop
aoqi@1 423 #ifdef _LP64
aoqi@1 424 LIR_Opr lock = new_register(T_LONG);
aoqi@1 425 #else
aoqi@1 426 LIR_Opr lock = new_register(T_INT);
aoqi@1 427 #endif
aoqi@1 428 // Need a scratch register for biased locking on mips
aoqi@1 429 LIR_Opr scratch = LIR_OprFact::illegalOpr;
aoqi@1 430 if (UseBiasedLocking) {
aoqi@1 431 scratch = new_register(T_INT);
aoqi@1 432 }
aoqi@1 433
aoqi@1 434 CodeEmitInfo* info_for_exception = NULL;
aoqi@1 435 if (x->needs_null_check()) {
aoqi@1 436 info_for_exception = state_for(x);
aoqi@1 437 }
aoqi@1 438 // this CodeEmitInfo must not have the xhandlers because here the
aoqi@1 439 // object is already locked (xhandlers expect object to be unlocked)
aoqi@1 440 CodeEmitInfo* info = state_for(x, x->state(), true);
aoqi@1 441 monitor_enter(obj.result(), lock, syncTempOpr(), scratch,
aoqi@1 442 x->monitor_no(), info_for_exception, info);
aoqi@1 443 }
aoqi@1 444
aoqi@1 445
aoqi@1 446 void LIRGenerator::do_MonitorExit(MonitorExit* x) {
aoqi@1 447 assert(x->is_pinned(),"");
aoqi@1 448
aoqi@1 449 LIRItem obj(x->obj(), this);
aoqi@1 450 obj.dont_load_item();
aoqi@1 451
aoqi@1 452 LIR_Opr lock = new_register(T_INT);
aoqi@1 453 LIR_Opr obj_temp = new_register(T_INT);
aoqi@1 454 set_no_result(x);
aoqi@1 455 monitor_exit(obj_temp, lock, syncTempOpr(), LIR_OprFact::illegalOpr, x->monitor_no());
aoqi@1 456 }
aoqi@1 457
aoqi@1 458
aoqi@1 459 // _ineg, _lneg, _fneg, _dneg
aoqi@1 460 void LIRGenerator::do_NegateOp(NegateOp* x) {
aoqi@1 461 LIRItem value(x->x(), this);
aoqi@1 462 value.set_destroys_register();
aoqi@1 463 value.load_item();
aoqi@1 464 LIR_Opr reg = rlock(x);
aoqi@1 465 __ negate(value.result(), reg);
aoqi@1 466
aoqi@1 467 set_result(x, round_item(reg));
aoqi@1 468 }
aoqi@1 469
aoqi@1 470
aoqi@1 471
aoqi@1 472 // for _fadd, _fmul, _fsub, _fdiv, _frem
aoqi@1 473 // _dadd, _dmul, _dsub, _ddiv, _drem
aoqi@1 474 void LIRGenerator::do_ArithmeticOp_FPU(ArithmeticOp* x) {
aoqi@1 475 LIR_Opr tmp;
aoqi@1 476 LIRItem left(x->x(), this);
aoqi@1 477 LIRItem right(x->y(), this);
aoqi@1 478 left.load_item();
aoqi@1 479 right.load_item();
aoqi@1 480 rlock_result(x);
aoqi@1 481 switch (x->op()) {
aoqi@6880 482 case Bytecodes::_drem:
aoqi@1 483 tmp = new_register(T_DOUBLE);
aoqi@1 484 __ frem(left.result(), right.result(), x->operand(), tmp);
aoqi@1 485
aoqi@1 486 break;
aoqi@1 487 case Bytecodes::_frem:
aoqi@1 488 tmp = new_register(T_FLOAT);
aoqi@1 489 __ frem(left.result(), right.result(), x->operand(), tmp);
aoqi@1 490 break;
aoqi@1 491 default: arithmetic_op_fpu(x->op(), x->operand(), left.result(), right.result(), x->is_strictfp());
aoqi@6880 492 }
aoqi@1 493 }
aoqi@1 494
aoqi@1 495
aoqi@1 496
aoqi@1 497
aoqi@1 498 // for _ladd, _lmul, _lsub, _ldiv, _lrem
aoqi@1 499 void LIRGenerator::do_ArithmeticOp_Long(ArithmeticOp* x) {
aoqi@1 500 switch (x->op()) {
aoqi@1 501 case Bytecodes::_lrem:
aoqi@1 502 case Bytecodes::_lmul:
aoqi@1 503 case Bytecodes::_ldiv: {
aoqi@1 504
aoqi@1 505 if (x->op() == Bytecodes::_ldiv || x->op() == Bytecodes::_lrem) {
aoqi@1 506 LIRItem right(x->y(), this);
aoqi@1 507 right.load_item();
aoqi@1 508
aoqi@1 509 CodeEmitInfo* info = state_for(x);
aoqi@1 510 LIR_Opr item = right.result();
aoqi@1 511 assert(item->is_register(), "must be");
aoqi@1 512 __ branch(lir_cond_equal,item,LIR_OprFact::longConst(0), T_LONG, new DivByZeroStub(info));
aoqi@1 513 }
aoqi@1 514
aoqi@1 515 address entry;
aoqi@1 516 switch (x->op()) {
aoqi@1 517 case Bytecodes::_lrem:
aoqi@1 518 entry = CAST_FROM_FN_PTR(address, SharedRuntime::lrem);
aoqi@1 519 break; // check if dividend is 0 is done elsewhere
aoqi@1 520 case Bytecodes::_ldiv:
aoqi@1 521 entry = CAST_FROM_FN_PTR(address, SharedRuntime::ldiv);
aoqi@1 522 break; // check if dividend is 0 is done elsewhere
aoqi@1 523 case Bytecodes::_lmul:
aoqi@1 524 entry = CAST_FROM_FN_PTR(address, SharedRuntime::lmul);
aoqi@1 525 break;
aoqi@1 526 default:
aoqi@1 527 ShouldNotReachHere();
aoqi@1 528 }
aoqi@1 529 // order of arguments to runtime call is reversed.
aoqi@1 530 LIR_Opr result = call_runtime(x->y(), x->x(), entry, x->type(), NULL);
aoqi@1 531 set_result(x, result);
aoqi@1 532 break;
aoqi@1 533 }
aoqi@1 534 /* _ladd, _lsub is delete in sharedRuntime.hpp
aoqi@1 535 case Bytecodes::_ladd:
aoqi@1 536 case Bytecodes::_lsub: {
aoqi@1 537 address entry;
aoqi@1 538 switch (x->op()) {
aoqi@1 539 case Bytecodes::_ladd:
aoqi@1 540 entry = CAST_FROM_FN_PTR(address, SharedRuntime::ladd);
aoqi@1 541 break; // check if dividend is 0 is done elsewhere
aoqi@1 542 case Bytecodes::_lsub:
aoqi@1 543 entry = CAST_FROM_FN_PTR(address, SharedRuntime::lsub);
aoqi@1 544 break; // check if dividend is 0 is done elsewhere
aoqi@1 545 default:
aoqi@1 546 ShouldNotReachHere();
aoqi@1 547 }
aoqi@6880 548
aoqi@1 549 // order of arguments to runtime call is reversed.
aoqi@1 550 LIR_Opr result = call_runtime(x->y(), x->x(), entry, x->type(), NULL);
aoqi@1 551 set_result(x, result);
aoqi@1 552 break;
aoqi@1 553 }*/
aoqi@1 554
aoqi@1 555 /* {
aoqi@1 556 LIRItem left(x->x(), this);
aoqi@1 557 LIRItem right(x->y(), this);
aoqi@1 558 left.load_item();
aoqi@1 559 right.load_item();
aoqi@1 560 rlock_result(x);
aoqi@1 561
aoqi@1 562 arithmetic_op_long(x->op(), x->operand(), left.result(), right.result(), NULL);
aoqi@1 563 break;
aoqi@1 564 }
aoqi@1 565 */
aoqi@1 566 default: ShouldNotReachHere();
aoqi@1 567 }
aoqi@1 568 }
aoqi@1 569
aoqi@1 570
aoqi@1 571
aoqi@1 572
aoqi@1 573 // for: _iadd, _imul, _isub, _idiv, _irem
aoqi@1 574 void LIRGenerator::do_ArithmeticOp_Int(ArithmeticOp* x) {
aoqi@1 575 bool is_div_rem = x->op() == Bytecodes::_idiv || x->op() == Bytecodes::_irem;
aoqi@1 576 LIRItem left(x->x(), this);
aoqi@1 577 LIRItem right(x->y(), this);
aoqi@1 578 // missing test if instr is commutative and if we should swap
aoqi@1 579 right.load_nonconstant();
aoqi@1 580 assert(right.is_constant() || right.is_register(), "wrong state of right");
aoqi@1 581 left.load_item();
aoqi@1 582 rlock_result(x);
aoqi@1 583 if (is_div_rem) {
aoqi@1 584 CodeEmitInfo* info = state_for(x);
aoqi@1 585 LIR_Opr tmp =new_register(T_INT);
aoqi@1 586 if (x->op() == Bytecodes::_irem) {
aoqi@1 587 __ irem(left.result(), right.result(), x->operand(), tmp, info);
aoqi@1 588 } else if (x->op() == Bytecodes::_idiv) {
aoqi@1 589 __ idiv(left.result(), right.result(), x->operand(), tmp, info);
aoqi@1 590 }
aoqi@1 591 } else {
aoqi@6880 592 //arithmetic_op_int(x->op(), x->operand(), left.result(),
aoqi@1 593 //right.result(), FrameMap::G1_opr);
aoqi@1 594
aoqi@1 595 LIR_Opr tmp =new_register(T_INT);
aoqi@6880 596 arithmetic_op_int(x->op(), x->operand(), left.result(), right.result(),
aoqi@1 597 tmp);
aoqi@1 598 }
aoqi@1 599 }
aoqi@1 600
aoqi@1 601
aoqi@1 602 void LIRGenerator::do_ArithmeticOp(ArithmeticOp* x) {
aoqi@1 603 // when an operand with use count 1 is the left operand, then it is
aoqi@1 604 // likely that no move for 2-operand-LIR-form is necessary
aoqi@1 605 if (x->is_commutative() && x->y()->as_Constant() == NULL && x->x()->use_count() > x->y()->use_count()) {
aoqi@1 606 x->swap_operands();
aoqi@1 607 }
aoqi@1 608
aoqi@1 609 ValueTag tag = x->type()->tag();
aoqi@1 610 assert(x->x()->type()->tag() == tag && x->y()->type()->tag() == tag, "wrong parameters");
aoqi@1 611 switch (tag) {
aoqi@1 612 case floatTag:
aoqi@1 613 case doubleTag: do_ArithmeticOp_FPU(x); return;
aoqi@1 614 case longTag: do_ArithmeticOp_Long(x); return;
aoqi@1 615 case intTag: do_ArithmeticOp_Int(x); return;
aoqi@1 616 }
aoqi@1 617 ShouldNotReachHere();
aoqi@1 618 }
aoqi@1 619
aoqi@1 620
aoqi@1 621 // _ishl, _lshl, _ishr, _lshr, _iushr, _lushr
aoqi@1 622 void LIRGenerator::do_ShiftOp(ShiftOp* x) {
aoqi@1 623 if(x->op() == Bytecodes::_lshl
aoqi@1 624 || x->op() == Bytecodes::_lshr
aoqi@1 625 || x->op() == Bytecodes::_lushr) {
aoqi@1 626 address entry;
aoqi@1 627 /* lushr, lshr, lshl, is delete in ShredRuntime.hpp
aoqi@1 628 switch (x->op()) {
aoqi@1 629 case Bytecodes::_lshl:
aoqi@1 630 entry = CAST_FROM_FN_PTR(address, SharedRuntime::lshl);
aoqi@1 631 break; // check if dividend is 0 is done elsewhere
aoqi@1 632 case Bytecodes::_lshr:
aoqi@1 633 entry = CAST_FROM_FN_PTR(address, SharedRuntime::lshr);
aoqi@1 634 break; // check if dividend is 0 is done elsewhere
aoqi@1 635 case Bytecodes::_lushr:
aoqi@1 636 entry = CAST_FROM_FN_PTR(address, SharedRuntime::lushr);
aoqi@1 637 break;
aoqi@1 638 default:
aoqi@1 639 ShouldNotReachHere();
aoqi@1 640 }
aoqi@1 641 */
aoqi@1 642 // order of arguments to runtime call is reversed.
aoqi@1 643 LIR_Opr result = call_runtime(x->y(), x->x(), entry, x->type(), NULL);
aoqi@6880 644 set_result(x, result);
aoqi@1 645 return;
aoqi@1 646 }
aoqi@1 647
aoqi@1 648 // count must always be in rcx
aoqi@1 649 LIRItem value(x->x(), this);
aoqi@1 650 LIRItem count(x->y(), this);
aoqi@1 651
aoqi@1 652 ValueTag elemType = x->type()->tag();
aoqi@1 653 bool must_load_count = !count.is_constant() || elemType == longTag;
aoqi@1 654 if (must_load_count) {
aoqi@1 655 // count for long must be in register
aoqi@1 656 count.load_item();
aoqi@1 657 } else {
aoqi@1 658 count.dont_load_item();
aoqi@1 659 }
aoqi@1 660 value.load_item();
aoqi@1 661 LIR_Opr reg = rlock_result(x);
aoqi@1 662
aoqi@1 663 shift_op(x->op(), reg, value.result(), count.result(), LIR_OprFact::illegalOpr);
aoqi@1 664 }
aoqi@1 665
aoqi@1 666
aoqi@1 667 // _iand, _land, _ior, _lor, _ixor, _lxor
aoqi@1 668 void LIRGenerator::do_LogicOp(LogicOp* x) {
aoqi@1 669 // when an operand with use count 1 is the left operand, then it is
aoqi@1 670 // likely that no move for 2-operand-LIR-form is necessary
aoqi@1 671 if (x->is_commutative() && x->y()->as_Constant() == NULL && x->x()->use_count() > x->y()->use_count()) {
aoqi@1 672 x->swap_operands();
aoqi@1 673 }
aoqi@1 674
aoqi@1 675 LIRItem left(x->x(), this);
aoqi@1 676 LIRItem right(x->y(), this);
aoqi@1 677
aoqi@1 678 left.load_item();
aoqi@1 679 right.load_nonconstant();
aoqi@1 680 LIR_Opr reg = rlock_result(x);
aoqi@1 681
aoqi@1 682 logic_op(x->op(), reg, left.result(), right.result());
aoqi@1 683 }
aoqi@1 684
aoqi@1 685
aoqi@1 686
aoqi@1 687 // _lcmp, _fcmpl, _fcmpg, _dcmpl, _dcmpg
aoqi@1 688 void LIRGenerator::do_CompareOp(CompareOp* x) {
aoqi@1 689 LIRItem left(x->x(), this);
aoqi@1 690 LIRItem right(x->y(), this);
aoqi@1 691 ValueTag tag = x->x()->type()->tag();
aoqi@1 692 if (tag == longTag) {
aoqi@1 693 left.set_destroys_register();
aoqi@1 694 }
aoqi@1 695 left.load_item();
aoqi@1 696 right.load_item();
aoqi@1 697 LIR_Opr reg = rlock_result(x);
aoqi@1 698
aoqi@1 699 if (x->x()->type()->is_float_kind()) {
aoqi@1 700 Bytecodes::Code code = x->op();
aoqi@1 701 __ fcmp2int(left.result(), right.result(), reg, (code == Bytecodes::_fcmpl || code == Bytecodes::_dcmpl));
aoqi@1 702 } else if (x->x()->type()->tag() == longTag) {
aoqi@1 703 __ lcmp2int(left.result(), right.result(), reg);
aoqi@1 704 } else {
aoqi@1 705 Unimplemented();
aoqi@1 706 }
aoqi@1 707 }
aoqi@1 708 /*
aoqi@1 709 void LIRGenerator::do_AttemptUpdate(Intrinsic* x) {
aoqi@6880 710 assert(x->number_of_arguments() == 3, "wrong type");
aoqi@6880 711 LIRItem obj (x->argument_at(0), this); // AtomicLong object
aoqi@6880 712 LIRItem cmp_value (x->argument_at(1), this); // value to compare with field
aoqi@6880 713 LIRItem new_value (x->argument_at(2), this);
aoqi@6880 714 // replace field with new_value if it matches cmp_value
aoqi@1 715
aoqi@6880 716 // compare value must be in edx,eax (hi,lo); may be destroyed by cmpxchg8 instruction
aoqi@6880 717 // cmp_value.load_item_force(FrameMap::eax_edx_long_opr);
aoqi@6880 718 cmp_value.load_item_force(FrameMap::_a0_a1_long_opr);
aoqi@1 719
aoqi@6880 720 // new value must be in ecx,ebx (hi,lo)
aoqi@6880 721 // new_value.load_item_force(FrameMap::ebx_ecx_long_opr);
aoqi@6880 722 new_value.load_item_force(FrameMap::_a2_a3_long_opr);
aoqi@6880 723 // object pointer register is overwritten with field address
aoqi@6880 724 obj.load_item();
aoqi@1 725
aoqi@6880 726 // generate compare-and-swap; produces zero condition if swap occurs
aoqi@6880 727 int value_offset = sun_misc_AtomicLongCSImpl::value_offset();
aoqi@6880 728 LIR_Opr addr = obj.result();
aoqi@6880 729 __ add(addr, LIR_OprFact::intConst(value_offset), addr);
aoqi@6880 730 LIR_Opr t1 = LIR_OprFact::illegalOpr; // no temp needed
aoqi@6880 731 LIR_Opr t2 = LIR_OprFact::illegalOpr; // no temp needed
aoqi@6880 732 __ cas_long(addr, cmp_value.result(), new_value.result(), t1, t2, FrameMap::_at_opr);
aoqi@1 733
aoqi@6880 734 // generate conditional move of boolean result
aoqi@6880 735 LIR_Opr result = rlock_result(x);
aoqi@6880 736 //__ cmove(lir_cond_equal, LIR_OprFact::intConst(1), LIR_OprFact::intConst(0), result);
aoqi@6880 737 __ move(FrameMap::_at_opr, result);
aoqi@1 738 }
aoqi@1 739 */
aoqi@1 740 //FIXME, for mips, compareandswap is a bit different
aoqi@1 741 //I have no idea use which register
aoqi@1 742 void LIRGenerator::do_CompareAndSwap(Intrinsic* x, ValueType* type) {
aoqi@6880 743 assert(x->number_of_arguments() == 4, "wrong type");
aoqi@6880 744 LIRItem obj (x->argument_at(0), this); // object
aoqi@6880 745 LIRItem offset(x->argument_at(1), this); // offset of field
aoqi@6880 746 LIRItem cmp (x->argument_at(2), this); // value to compare with field
aoqi@6880 747 LIRItem val (x->argument_at(3), this); // replace field with val if matches cmp
aoqi@1 748
aoqi@6880 749 assert(obj.type()->tag() == objectTag, "invalid type");
aoqi@1 750
aoqi@6880 751 //In 64bit the type can be long, sparc doesn't have this assert
aoqi@6880 752 //assert(offset.type()->tag() == intTag, "invalid type");
aoqi@1 753
aoqi@6880 754 assert(cmp.type()->tag() == type->tag(), "invalid type");
aoqi@6880 755 assert(val.type()->tag() == type->tag(), "invalid type");
aoqi@1 756
aoqi@6880 757 // get address of field
aoqi@6880 758 obj.load_item();
aoqi@6880 759 offset.load_nonconstant();
aoqi@1 760
aoqi@6880 761 if (type == objectType) {
aoqi@6880 762 // cmp.load_item_force(FrameMap::eax_oop_opr);
aoqi@6880 763 cmp.load_item_force(FrameMap::_a0_oop_opr);
aoqi@6880 764 val.load_item();
aoqi@6880 765 } else if (type == intType) {
aoqi@6880 766 // cmp.load_item_force(FrameMap::eax_opr);
aoqi@6880 767 cmp.load_item_force(FrameMap::_a0_opr);
aoqi@6880 768 val.load_item();
aoqi@6880 769 } else if (type == longType) {
aoqi@6880 770 //// cmp.load_item_force(FrameMap::eax_edx_long_opr);
aoqi@6880 771 cmp.load_item_force(FrameMap::_a0_a1_long_opr);
aoqi@6880 772 // val.load_item_force(FrameMap::ebx_ecx_long_opr);
aoqi@6880 773 val.load_item_force(FrameMap::_a2_a3_long_opr);
aoqi@6880 774 } else {
aoqi@6880 775 ShouldNotReachHere();
aoqi@6880 776 }
aoqi@6880 777 LIR_Opr addr = new_pointer_register();
aoqi@6880 778 __ move(obj.result(), addr);
aoqi@6880 779 __ add(addr, offset.result(), addr);
aoqi@1 780
aoqi@6880 781 LIR_Opr ill = LIR_OprFact::illegalOpr; // for convenience
aoqi@6880 782 if (type == objectType)
aoqi@6880 783 __ cas_obj(addr, cmp.result(), val.result(), ill, ill, FrameMap::_at_opr);
aoqi@6880 784 else if (type == intType)
aoqi@6880 785 __ cas_int(addr, cmp.result(), val.result(), ill, ill, FrameMap::_at_opr);
aoqi@6880 786 else if (type == longType)
aoqi@6880 787 __ cas_long(addr, cmp.result(), val.result(), ill, ill, FrameMap::_at_opr);
aoqi@6880 788 else {
aoqi@6880 789 ShouldNotReachHere();
aoqi@6880 790 }
aoqi@6880 791 // generate conditional move of boolean result
aoqi@6880 792 LIR_Opr result = rlock_result(x);
aoqi@6880 793 //cmove not exist on mips,
aoqi@6880 794 // __ cmove(lir_cond_equal, LIR_OprFact::intConst(1), LIR_OprFact::intConst(0), result);
aoqi@6880 795 // our implementation of cmpxchg put result in AT
aoqi@6880 796 // LIR_Opr result = rlock_result_with_hint(x, hint());
aoqi@6880 797 __ move(FrameMap::_at_opr, result);
aoqi@1 798
aoqi@6880 799 if (type == objectType) // Write-barrier needed for Object fields.
aoqi@6880 800 write_barrier(addr);
aoqi@1 801 }
aoqi@1 802
aoqi@1 803
aoqi@1 804 void LIRGenerator::do_MathIntrinsic(Intrinsic* x) {
aoqi@6880 805 switch (x->id()) {
aoqi@6880 806 case vmIntrinsics::_dabs:
aoqi@6880 807 case vmIntrinsics::_dsqrt: {
aoqi@6880 808 assert(x->number_of_arguments() == 1, "wrong type");
aoqi@6880 809 LIRItem value(x->argument_at(0), this);
aoqi@6880 810 value.load_item();
aoqi@6880 811 LIR_Opr dst = rlock_result(x);
aoqi@1 812
aoqi@6880 813 switch (x->id()) {
aoqi@6880 814 case vmIntrinsics::_dsqrt: {
aoqi@6880 815 __ sqrt(value.result(), dst, LIR_OprFact::illegalOpr);
aoqi@6880 816 break;
aoqi@6880 817 }
aoqi@6880 818 case vmIntrinsics::_dabs: {
aoqi@6880 819 __ abs(value.result(), dst, LIR_OprFact::illegalOpr);
aoqi@6880 820 break;
aoqi@6880 821 }
aoqi@6880 822 }
aoqi@6880 823 break;
aoqi@6880 824 }
aoqi@6880 825 case vmIntrinsics::_dlog10: // fall through
aoqi@6880 826 case vmIntrinsics::_dlog: // fall through
aoqi@6880 827 case vmIntrinsics::_dsin: // fall through
aoqi@6880 828 case vmIntrinsics::_dtan: // fall through
aoqi@6880 829 case vmIntrinsics::_dcos: {
aoqi@6880 830 assert(x->number_of_arguments() == 1, "wrong type");
aoqi@1 831
aoqi@6880 832 address runtime_entry = NULL;
aoqi@6880 833 switch (x->id()) {
aoqi@6880 834 case vmIntrinsics::_dsin:
aoqi@6880 835 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dsin);
aoqi@6880 836 break;
aoqi@6880 837 case vmIntrinsics::_dcos:
aoqi@6880 838 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dcos);
aoqi@6880 839 break;
aoqi@6880 840 case vmIntrinsics::_dtan:
aoqi@6880 841 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dtan);
aoqi@6880 842 break;
aoqi@6880 843 case vmIntrinsics::_dlog:
aoqi@6880 844 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog);
aoqi@6880 845 break;
aoqi@6880 846 case vmIntrinsics::_dlog10:
aoqi@6880 847 runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog10);
aoqi@6880 848 break;
aoqi@6880 849 default:
aoqi@6880 850 ShouldNotReachHere();
aoqi@6880 851 }
aoqi@6880 852 LIR_Opr result = call_runtime(x->argument_at(0), runtime_entry, x->type(), NULL);
aoqi@6880 853 set_result(x, result);
aoqi@6880 854 }
aoqi@6880 855 }
aoqi@1 856 }
aoqi@1 857
aoqi@1 858 void LIRGenerator::do_ArrayCopy(Intrinsic* x) {
aoqi@6880 859 assert(x->number_of_arguments() == 5, "wrong type");
aoqi@6880 860 // Note: spill caller save before setting the item
aoqi@6880 861 LIRItem src (x->argument_at(0), this);
aoqi@6880 862 LIRItem src_pos (x->argument_at(1), this);
aoqi@6880 863 LIRItem dst (x->argument_at(2), this);
aoqi@6880 864 LIRItem dst_pos (x->argument_at(3), this);
aoqi@6880 865 LIRItem length (x->argument_at(4), this);
aoqi@6880 866 // load all values in callee_save_registers, as this makes the
aoqi@6880 867 // parameter passing to the fast case simpler
aoqi@6880 868 src.load_item_force (FrameMap::_t0_oop_opr);
aoqi@6880 869 src_pos.load_item_force (FrameMap::_a0_opr);
aoqi@6880 870 dst.load_item_force (FrameMap::_a1_oop_opr);
aoqi@6880 871 dst_pos.load_item_force (FrameMap::_a2_opr);
aoqi@6880 872 length.load_item_force (FrameMap::_a3_opr);
aoqi@1 873
aoqi@6880 874 int flags;
aoqi@6880 875 ciArrayKlass* expected_type;
aoqi@6880 876 arraycopy_helper(x, &flags, &expected_type);
aoqi@1 877
aoqi@6880 878 CodeEmitInfo* info = state_for(x, x->state());
aoqi@6880 879 __ arraycopy(src.result(), src_pos.result(), dst.result(), dst_pos.result(), length.result(), rlock_callee_saved(T_INT), expected_type, flags, info);
aoqi@6880 880 set_no_result(x);
aoqi@1 881 }
aoqi@1 882
aoqi@1 883 void LIRGenerator::do_update_CRC32(Intrinsic* x) { // Fu: 20130832
aoqi@6880 884 tty->print_cr("LIRGenerator::do_update_CRC32 unimplemented yet !");
aoqi@6880 885 Unimplemented();
aoqi@1 886 }
aoqi@1 887
aoqi@1 888 // _i2l, _i2f, _i2d, _l2i, _l2f, _l2d, _f2i, _f2l, _f2d, _d2i, _d2l, _d2f
aoqi@1 889 // _i2b, _i2c, _i2s
aoqi@1 890 LIR_Opr fixed_register_for(BasicType type) {
aoqi@6880 891 switch (type) {
aoqi@6880 892 case T_FLOAT: return FrameMap::_f0_float_opr;
aoqi@6880 893 case T_DOUBLE: return FrameMap::_d0_double_opr;
aoqi@6880 894 case T_INT: return FrameMap::_v0_opr;
aoqi@6880 895 case T_LONG: return FrameMap::_v0_v1_long_opr;
aoqi@6880 896 default: ShouldNotReachHere(); return LIR_OprFact::illegalOpr;
aoqi@6880 897 }
aoqi@1 898 }
aoqi@1 899
aoqi@1 900
aoqi@1 901 void LIRGenerator::do_Convert(Convert* x) {
aoqi@6880 902 // flags that vary for the different operations and different SSE-settings
aoqi@6880 903 bool fixed_input, fixed_result, round_result, needs_stub;
aoqi@1 904
aoqi@6880 905 switch (x->op()) {
aoqi@6880 906 case Bytecodes::_i2l: // fall through
aoqi@6880 907 case Bytecodes::_l2i: // fall through
aoqi@6880 908 case Bytecodes::_i2b: // fall through
aoqi@6880 909 case Bytecodes::_i2c: // fall through
aoqi@6880 910 case Bytecodes::_i2s:
aoqi@6880 911 fixed_input = false;
aoqi@6880 912 fixed_result = false;
aoqi@6880 913 round_result = false;
aoqi@6880 914 needs_stub = false; break;
aoqi@6880 915 case Bytecodes::_f2d:
aoqi@6880 916 fixed_input = UseSSE == 1;
aoqi@6880 917 fixed_result = false;
aoqi@6880 918 round_result = false;
aoqi@6880 919 needs_stub = false; break;
aoqi@6880 920 case Bytecodes::_d2f:
aoqi@6880 921 fixed_input = false;
aoqi@6880 922 fixed_result = UseSSE == 1;
aoqi@6880 923 round_result = UseSSE < 1;
aoqi@6880 924 needs_stub = false; break;
aoqi@6880 925 case Bytecodes::_i2f:
aoqi@6880 926 fixed_input = false;
aoqi@6880 927 fixed_result = false;
aoqi@6880 928 round_result = UseSSE < 1;
aoqi@6880 929 needs_stub = false; break;
aoqi@6880 930 case Bytecodes::_i2d:
aoqi@6880 931 fixed_input = false;
aoqi@6880 932 fixed_result = false;
aoqi@6880 933 round_result = false;
aoqi@6880 934 needs_stub = false; break;
aoqi@6880 935 case Bytecodes::_f2i:
aoqi@6880 936 fixed_input = false;
aoqi@6880 937 fixed_result = false;
aoqi@6880 938 round_result = false;
aoqi@6880 939 needs_stub = true; break;
aoqi@6880 940 case Bytecodes::_d2i:
aoqi@6880 941 fixed_input = false;
aoqi@6880 942 fixed_result = false;
aoqi@6880 943 round_result = false;
aoqi@6880 944 needs_stub = true; break;
aoqi@6880 945 case Bytecodes::_l2f:
aoqi@6880 946 fixed_input = false;
aoqi@6880 947 fixed_result = UseSSE >= 1;
aoqi@6880 948 round_result = UseSSE < 1;
aoqi@6880 949 needs_stub = false; break;
aoqi@6880 950 case Bytecodes::_l2d:
aoqi@6880 951 fixed_input = false;
aoqi@6880 952 fixed_result = UseSSE >= 2;
aoqi@6880 953 round_result = UseSSE < 2;
aoqi@6880 954 needs_stub = false; break;
aoqi@6880 955 case Bytecodes::_f2l:
aoqi@6880 956 fixed_input = true;
aoqi@6880 957 fixed_result = true;
aoqi@6880 958 round_result = false;
aoqi@6880 959 needs_stub = false; break;
aoqi@6880 960 case Bytecodes::_d2l:
aoqi@6880 961 fixed_input = true;
aoqi@6880 962 fixed_result = true;
aoqi@6880 963 round_result = false;
aoqi@6880 964 needs_stub = false; break;
aoqi@6880 965 default: ShouldNotReachHere();
aoqi@6880 966 }
aoqi@1 967
aoqi@6880 968 LIRItem value(x->value(), this);
aoqi@6880 969 value.load_item();
aoqi@6880 970 LIR_Opr input = value.result();
aoqi@6880 971 LIR_Opr result = rlock(x);
aoqi@1 972
aoqi@6880 973 // arguments of lir_convert
aoqi@6880 974 LIR_Opr conv_input = input;
aoqi@6880 975 LIR_Opr conv_result = result;
aoqi@6880 976 ConversionStub* stub = NULL;
aoqi@1 977
aoqi@6880 978 if (fixed_input) {
aoqi@6880 979 conv_input = fixed_register_for(input->type());
aoqi@6880 980 __ move(input, conv_input);
aoqi@6880 981 }
aoqi@1 982
aoqi@6880 983 assert(fixed_result == false || round_result == false, "cannot set both");
aoqi@6880 984 if (fixed_result) {
aoqi@6880 985 conv_result = fixed_register_for(result->type());
aoqi@6880 986 } else if (round_result) {
aoqi@6880 987 result = new_register(result->type());
aoqi@6880 988 set_vreg_flag(result, must_start_in_memory);
aoqi@6880 989 }
aoqi@1 990
aoqi@6880 991 if (needs_stub) {
aoqi@6880 992 stub = new ConversionStub(x->op(), conv_input, conv_result);
aoqi@6880 993 }
aoqi@1 994
aoqi@6880 995 __ convert(x->op(), conv_input, conv_result, stub);
aoqi@1 996
aoqi@6880 997 if (result != conv_result) {
aoqi@6880 998 __ move(conv_result, result);
aoqi@6880 999 }
aoqi@1 1000
aoqi@6880 1001 assert(result->is_virtual(), "result must be virtual register");
aoqi@6880 1002 set_result(x, result);
aoqi@1 1003 }
aoqi@1 1004
aoqi@1 1005 void LIRGenerator::do_NewInstance(NewInstance* x) {
aoqi@6880 1006 const LIR_Opr reg = result_register_for(x->type());
aoqi@1 1007 #ifndef PRODUCT
aoqi@6880 1008 if (PrintNotLoaded && !x->klass()->is_loaded()) {
aoqi@6880 1009 tty->print_cr(" ###class not loaded at new bci %d", x->printable_bci());
aoqi@6880 1010 }
aoqi@1 1011 #endif
aoqi@6880 1012 CodeEmitInfo* info = state_for(x, x->state());
aoqi@6880 1013 // LIR_Opr tmp1 = new_register(T_INT);
aoqi@6880 1014 // LIR_Opr tmp2 = new_register(T_INT);
aoqi@6880 1015 // LIR_Opr tmp3 = new_register(T_INT);
aoqi@6880 1016 // LIR_Opr tmp4 = new_register(T_INT);
aoqi@1 1017 #ifndef _LP64
aoqi@6880 1018 LIR_Opr klass_reg = FrameMap::_t4_oop_opr;
aoqi@1 1019 #else
aoqi@6880 1020 LIR_Opr klass_reg = FrameMap::_a4_oop_opr;
aoqi@1 1021 #endif
aoqi@6880 1022 // new_instance(reg, x->klass(), FrameMap::_t0_oop_opr, FrameMap::_t1_oop_opr,FrameMap::_t2_oop_opr, LIR_OprFact::illegalOpr, klass_reg, info);
aoqi@6880 1023 new_instance(reg,
aoqi@6880 1024 x->klass(),
aoqi@6880 1025 FrameMap::_t0_oop_opr,
aoqi@6880 1026 FrameMap::_t1_oop_opr,
aoqi@6880 1027 FrameMap::_t2_oop_opr,
aoqi@6880 1028 FrameMap::_t3_oop_opr,
aoqi@1 1029 #ifndef _LP64
aoqi@6880 1030 FrameMap::_t5_oop_opr,
aoqi@6880 1031 FrameMap::_t6_oop_opr,
aoqi@1 1032 #else
aoqi@6880 1033 FrameMap::_a5_oop_opr,
aoqi@6880 1034 FrameMap::_a6_oop_opr,
aoqi@1 1035 #endif
aoqi@6880 1036 klass_reg,
aoqi@6880 1037 info);
aoqi@6880 1038 LIR_Opr result = rlock_result(x);
aoqi@6880 1039 __ move(reg, result);
aoqi@1 1040 }
aoqi@1 1041
aoqi@1 1042
aoqi@6880 1043 void LIRGenerator::do_NewTypeArray(NewTypeArray* x) {
aoqi@6880 1044 CodeEmitInfo* info = state_for(x, x->state());
aoqi@6880 1045
aoqi@6880 1046 LIRItem length(x->length(), this);
aoqi@6880 1047 length.load_item_force(FrameMap::_t2_opr);
aoqi@6880 1048
aoqi@6880 1049 LIR_Opr reg = result_register_for(x->type());
aoqi@6880 1050 LIR_Opr tmp1 = FrameMap::_t0_oop_opr;
aoqi@6880 1051 LIR_Opr tmp2 = FrameMap::_t1_oop_opr;
aoqi@6880 1052 LIR_Opr tmp3 = FrameMap::_t3_oop_opr;
aoqi@6880 1053 #ifndef _LP64
aoqi@6880 1054 LIR_Opr tmp4 = FrameMap::_t5_oop_opr;
aoqi@6880 1055 LIR_Opr tmp5 = FrameMap::_t6_oop_opr;
aoqi@6880 1056 LIR_Opr klass_reg = FrameMap::_t4_oop_opr;
aoqi@6880 1057 #else
aoqi@6880 1058 LIR_Opr tmp4 = FrameMap::_a5_oop_opr;
aoqi@6880 1059 LIR_Opr tmp5 = FrameMap::_a6_oop_opr;
aoqi@6880 1060 LIR_Opr klass_reg = FrameMap::_a4_oop_opr;
aoqi@6880 1061 #endif
aoqi@6880 1062 LIR_Opr len = length.result();
aoqi@6880 1063 BasicType elem_type = x->elt_type();
aoqi@6880 1064
aoqi@6880 1065 __ metadata2reg(ciTypeArrayKlass::make(elem_type)->constant_encoding(), klass_reg);
aoqi@6880 1066
aoqi@6880 1067 CodeStub* slow_path = new NewTypeArrayStub(klass_reg, len, reg, info);
aoqi@6880 1068 __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4,tmp5, elem_type, klass_reg, slow_path);
aoqi@6880 1069
aoqi@6880 1070 LIR_Opr result = rlock_result(x);
aoqi@6880 1071 __ move(reg, result);
aoqi@6880 1072 }
aoqi@6880 1073
aoqi@6880 1074
aoqi@1 1075
aoqi@1 1076 void LIRGenerator::do_NewObjectArray(NewObjectArray* x) {
aoqi@6880 1077 LIRItem length(x->length(), this);
aoqi@6880 1078 // in case of patching (i.e., object class is not yet loaded), we
aoqi@6880 1079 // need to reexecute the instruction
aoqi@6880 1080 // and therefore provide the state before the parameters have been consumed
aoqi@6880 1081 CodeEmitInfo* patching_info = NULL;
aoqi@6880 1082 if (!x->klass()->is_loaded() || PatchALot) {
aoqi@6880 1083 patching_info = state_for(x, x->state_before());
aoqi@6880 1084 }
aoqi@6880 1085
aoqi@6880 1086 const LIR_Opr reg = result_register_for(x->type());
aoqi@6880 1087 LIR_Opr tmp1 = FrameMap::_t0_oop_opr;
aoqi@6880 1088 LIR_Opr tmp2 = FrameMap::_t1_oop_opr;
aoqi@6880 1089 LIR_Opr tmp3 = FrameMap::_t3_oop_opr;
aoqi@1 1090 #ifndef _LP64
aoqi@6880 1091 LIR_Opr tmp4 = FrameMap::_t5_oop_opr;
aoqi@6880 1092 LIR_Opr tmp5 = FrameMap::_t6_oop_opr;
aoqi@6880 1093 LIR_Opr klass_reg = FrameMap::_t4_oop_opr;
aoqi@1 1094 #else
aoqi@6880 1095 LIR_Opr tmp4 = FrameMap::_a5_oop_opr;
aoqi@6880 1096 LIR_Opr tmp5 = FrameMap::_a6_oop_opr;
aoqi@6880 1097 LIR_Opr klass_reg = FrameMap::_a4_oop_opr;
aoqi@1 1098 #endif
aoqi@1 1099
aoqi@6880 1100 length.load_item_force(FrameMap::_t2_opr);
aoqi@1 1101
aoqi@6880 1102 LIR_Opr len = length.result();
aoqi@6880 1103 CodeEmitInfo* info = state_for(x, x->state());
aoqi@1 1104
aoqi@6880 1105 CodeStub* slow_path = new NewObjectArrayStub(klass_reg, len, reg, info);
aoqi@6880 1106 ciKlass* obj = (ciKlass*) ciObjArrayKlass::make(x->klass());
aoqi@6880 1107 if (obj == ciEnv::unloaded_ciobjarrayklass()) {
aoqi@6880 1108 BAILOUT("encountered unloaded_ciobjarrayklass due to out of memory error");
aoqi@6880 1109 }
aoqi@6880 1110 klass2reg_with_patching(klass_reg, obj, patching_info);
aoqi@6880 1111 __ allocate_array(reg, len, tmp1, tmp2, tmp3, tmp4, tmp5, T_OBJECT, klass_reg, slow_path);
aoqi@1 1112
aoqi@6880 1113 LIR_Opr result = rlock_result(x);
aoqi@6880 1114 __ move(reg, result);
aoqi@1 1115 }
aoqi@1 1116
aoqi@1 1117
aoqi@1 1118 void LIRGenerator::do_NewMultiArray(NewMultiArray* x) {
aoqi@6880 1119 Values* dims = x->dims();
aoqi@6880 1120 int i = dims->length();
aoqi@6880 1121 LIRItemList* items = new LIRItemList(dims->length(), NULL);
aoqi@6880 1122 while (i-- > 0) {
aoqi@6880 1123 LIRItem* size = new LIRItem(dims->at(i), this);
aoqi@6880 1124 items->at_put(i, size);
aoqi@6880 1125 }
aoqi@1 1126
aoqi@6880 1127 // need to get the info before, as the items may become invalid through item_free
aoqi@6880 1128 CodeEmitInfo* patching_info = NULL;
aoqi@6880 1129 if (!x->klass()->is_loaded() || PatchALot) {
aoqi@6880 1130 patching_info = state_for(x, x->state_before());
aoqi@6880 1131 // cannot re-use same xhandlers for multiple CodeEmitInfos, so
aoqi@6880 1132 // clone all handlers.
aoqi@6880 1133 x->set_exception_handlers(new XHandlers(x->exception_handlers()));
aoqi@6880 1134 }
aoqi@1 1135
aoqi@6880 1136 CodeEmitInfo* info = state_for(x, x->state());
aoqi@1 1137
aoqi@6880 1138 i = dims->length();
aoqi@6880 1139 while (i-- > 0) {
aoqi@6880 1140 LIRItem* size = items->at(i);
aoqi@6880 1141 size->load_nonconstant();
aoqi@6880 1142 store_stack_parameter(size->result(), in_ByteSize(i*4));
aoqi@6880 1143 }
aoqi@1 1144
aoqi@6880 1145 LIR_Opr reg = result_register_for(x->type());
aoqi@6880 1146 klass2reg_with_patching(reg, x->klass(), patching_info);
aoqi@1 1147
aoqi@6880 1148 // LIR_Opr rank = FrameMap::ebx_opr;
aoqi@6880 1149 LIR_Opr rank = FrameMap::_t2_opr;
aoqi@6880 1150 __ move(LIR_OprFact::intConst(x->rank()), rank);
aoqi@6880 1151 // LIR_Opr varargs = FrameMap::ecx_opr;
aoqi@6880 1152 LIR_Opr varargs = FrameMap::_t0_opr;
aoqi@6880 1153 __ move(FrameMap::_sp_opr, varargs);
aoqi@6880 1154 LIR_OprList* args = new LIR_OprList(3);
aoqi@6880 1155 args->append(reg);
aoqi@6880 1156 args->append(rank);
aoqi@6880 1157 args->append(varargs);
aoqi@6880 1158 __ call_runtime(Runtime1::entry_for(Runtime1::new_multi_array_id),
aoqi@6880 1159 LIR_OprFact::illegalOpr,
aoqi@6880 1160 reg, args, info);
aoqi@6880 1161 LIR_Opr result = rlock_result(x);
aoqi@6880 1162 __ move(reg, result);
aoqi@1 1163 }
aoqi@1 1164
aoqi@1 1165 void LIRGenerator::do_BlockBegin(BlockBegin* x) {
aoqi@1 1166 // nothing to do for now
aoqi@1 1167 }
aoqi@1 1168
aoqi@1 1169
aoqi@1 1170 void LIRGenerator::do_CheckCast(CheckCast* x) {
aoqi@6880 1171 LIRItem obj(x->obj(), this);
aoqi@1 1172
aoqi@6880 1173 CodeEmitInfo* patching_info = NULL;
aoqi@6880 1174 if (!x->klass()->is_loaded() || (PatchALot && !x->is_incompatible_class_change_check())) {
aoqi@6880 1175 // must do this before locking the destination register as an oop register,
aoqi@6880 1176 // and before the obj is loaded (the latter is for deoptimization)
aoqi@6880 1177 patching_info = state_for(x, x->state_before());
aoqi@6880 1178 }
aoqi@6880 1179 obj.load_item();
aoqi@1 1180
aoqi@6880 1181 // info for exceptions
aoqi@6880 1182 CodeEmitInfo* info_for_exception = state_for(x);
aoqi@1 1183
aoqi@6880 1184 CodeStub* stub;
aoqi@6880 1185 if (x->is_incompatible_class_change_check()) {
aoqi@6880 1186 assert(patching_info == NULL, "can't patch this");
aoqi@6880 1187 stub = new SimpleExceptionStub(Runtime1::throw_incompatible_class_change_error_id, LIR_OprFact::illegalOpr, info_for_exception);
aoqi@6880 1188 } else {
aoqi@6880 1189 stub = new SimpleExceptionStub(Runtime1::throw_class_cast_exception_id, obj.result(), info_for_exception);
aoqi@6880 1190 }
aoqi@6880 1191 LIR_Opr reg = rlock_result(x);
aoqi@6880 1192 LIR_Opr tmp3 = LIR_OprFact::illegalOpr;
aoqi@6880 1193 if (!x->klass()->is_loaded() || UseCompressedOops) {
aoqi@6880 1194 tmp3 = new_register(objectType);
aoqi@6880 1195 }
aoqi@6880 1196 __ checkcast(reg, obj.result(), x->klass(),
aoqi@6880 1197 new_register(objectType), new_register(objectType), tmp3,
aoqi@6880 1198 x->direct_compare(), info_for_exception, patching_info, stub,
aoqi@6880 1199 x->profiled_method(), x->profiled_bci());
aoqi@1 1200 }
aoqi@1 1201
aoqi@1 1202
aoqi@1 1203 void LIRGenerator::do_InstanceOf(InstanceOf* x) {
aoqi@6880 1204 LIRItem obj(x->obj(), this);
aoqi@1 1205
aoqi@6880 1206 // result and test object may not be in same register
aoqi@6880 1207 LIR_Opr reg = rlock_result(x);
aoqi@6880 1208 CodeEmitInfo* patching_info = NULL;
aoqi@6880 1209 if ((!x->klass()->is_loaded() || PatchALot)) {
aoqi@6880 1210 // must do this before locking the destination register as an oop register
aoqi@6880 1211 patching_info = state_for(x, x->state_before());
aoqi@6880 1212 }
aoqi@6880 1213 obj.load_item();
aoqi@6880 1214 LIR_Opr tmp = new_register(objectType);
aoqi@6880 1215 LIR_Opr tmp3 = LIR_OprFact::illegalOpr;
aoqi@6880 1216 if (!x->klass()->is_loaded() || UseCompressedOops) {
aoqi@6880 1217 tmp3 = new_register(objectType);
aoqi@6880 1218 }
aoqi@1 1219
aoqi@6880 1220 __ instanceof(reg, obj.result(), x->klass(),
aoqi@6880 1221 tmp, new_register(objectType), tmp3,
aoqi@6880 1222 x->direct_compare(), patching_info, x->profiled_method(), x->profiled_bci());
aoqi@1 1223 }
aoqi@1 1224
aoqi@1 1225
aoqi@1 1226 void LIRGenerator::do_If(If* x) {
aoqi@6880 1227 assert(x->number_of_sux() == 2, "inconsistency");
aoqi@6880 1228 ValueTag tag = x->x()->type()->tag();
aoqi@6880 1229 bool is_safepoint = x->is_safepoint();
aoqi@1 1230
aoqi@6880 1231 If::Condition cond = x->cond();
aoqi@1 1232
aoqi@6880 1233 LIRItem xitem(x->x(), this);
aoqi@6880 1234 LIRItem yitem(x->y(), this);
aoqi@6880 1235 LIRItem* xin = &xitem;
aoqi@6880 1236 LIRItem* yin = &yitem;
aoqi@1 1237
aoqi@6880 1238 if (tag == longTag) {
aoqi@6880 1239 // for longs, only conditions "eql", "neq", "lss", "geq" are valid;
aoqi@6880 1240 // mirror for other conditions
aoqi@6880 1241 if (cond == If::gtr || cond == If::leq) {
aoqi@6880 1242 cond = Instruction::mirror(cond);
aoqi@6880 1243 xin = &yitem;
aoqi@6880 1244 yin = &xitem;
aoqi@6880 1245 }
aoqi@6880 1246 xin->set_destroys_register();
aoqi@6880 1247 }
aoqi@6880 1248 xin->load_item();
aoqi@6880 1249 if (tag == longTag && yin->is_constant() && yin->get_jlong_constant() == 0 && (cond == If::eql || cond == If::neq)) {
aoqi@6880 1250 // inline long zero
aoqi@6880 1251 yin->dont_load_item();
aoqi@6880 1252 } else if (tag == longTag || tag == floatTag || tag == doubleTag) {
aoqi@6880 1253 // longs cannot handle constants at right side
aoqi@6880 1254 yin->load_item();
aoqi@6880 1255 } else {
aoqi@6880 1256 yin->dont_load_item();
aoqi@6880 1257 }
aoqi@1 1258
aoqi@6880 1259 // add safepoint before generating condition code so it can be recomputed
aoqi@6880 1260 if (x->is_safepoint()) {
aoqi@6880 1261 // increment backedge counter if needed
aoqi@6880 1262 increment_backedge_counter(state_for(x, x->state_before()), x->profiled_bci());
aoqi@6880 1263 __ safepoint(safepoint_poll_register(), state_for(x, x->state_before()));
aoqi@6880 1264 }
aoqi@6880 1265 set_no_result(x);
aoqi@1 1266
aoqi@6880 1267 LIR_Opr left = xin->result();
aoqi@6880 1268 LIR_Opr right = yin->result();
aoqi@6880 1269 profile_branch(x, cond, left, right);
aoqi@6880 1270 move_to_phi(x->state());
aoqi@6880 1271 if (x->x()->type()->is_float_kind()) {
aoqi@6880 1272 __ branch(lir_cond(cond), left, right, right->type(), x->tsux(), x->usux());
aoqi@6880 1273 } else {
aoqi@6880 1274 __ branch(lir_cond(cond), left, right, right->type(), x->tsux());
aoqi@6880 1275 }
aoqi@6880 1276 assert(x->default_sux() == x->fsux(), "wrong destination above");
aoqi@6880 1277 __ jump(x->default_sux());
aoqi@1 1278 }
aoqi@1 1279
aoqi@1 1280
aoqi@1 1281 LIR_Opr LIRGenerator::getThreadPointer() {
aoqi@1 1282 #ifdef _LP64
aoqi@6880 1283 //FIXME, does as_pointer need to be implemented? or 64bit can use one register. by aoqi
aoqi@6880 1284 //return FrameMap::as_pointer_opr(r15_thread);
aoqi@6880 1285 LIR_Opr result = new_register(T_LONG);
aoqi@6880 1286 __ get_thread(result);
aoqi@6880 1287 return result;
aoqi@1 1288 #else
aoqi@6880 1289 LIR_Opr result = new_register(T_INT);
aoqi@6880 1290 __ get_thread(result);
aoqi@6880 1291 return result;
aoqi@1 1292 #endif //
aoqi@1 1293 }
aoqi@1 1294
aoqi@1 1295 void LIRGenerator::trace_block_entry(BlockBegin* block) {
aoqi@6880 1296 store_stack_parameter(LIR_OprFact::intConst(block->block_id()), in_ByteSize(0));
aoqi@6880 1297 LIR_OprList* args = new LIR_OprList();
aoqi@6880 1298 address func = CAST_FROM_FN_PTR(address, Runtime1::trace_block_entry);
aoqi@6880 1299 __ call_runtime_leaf(func, LIR_OprFact::illegalOpr, LIR_OprFact::illegalOpr, args);
aoqi@1 1300 }
aoqi@1 1301
aoqi@1 1302
aoqi@1 1303 void LIRGenerator::volatile_field_store(LIR_Opr value, LIR_Address* address,
aoqi@6880 1304 CodeEmitInfo* info) {
aoqi@6880 1305 if (address->type() == T_LONG) {
aoqi@6880 1306 __ volatile_store_mem_reg(value, address, info);
aoqi@6880 1307 } else {
aoqi@6880 1308 __ store(value, address, info);
aoqi@6880 1309 }
aoqi@1 1310 }
aoqi@1 1311
aoqi@1 1312 void LIRGenerator::volatile_field_load(LIR_Address* address, LIR_Opr result,
aoqi@6880 1313 CodeEmitInfo* info) {
aoqi@6880 1314
aoqi@6880 1315 if (address->type() == T_LONG) {
aoqi@6880 1316 __ volatile_load_mem_reg(address, result, info);
aoqi@6880 1317 } else {
aoqi@6880 1318 __ load(address, result, info);
aoqi@6880 1319 }
aoqi@1 1320 }
aoqi@1 1321
aoqi@1 1322 void LIRGenerator::get_Object_unsafe(LIR_Opr dst, LIR_Opr src, LIR_Opr offset,
aoqi@6880 1323 BasicType type, bool is_volatile) {
aoqi@6880 1324 __ add(src, offset, FrameMap::_at_opr);
aoqi@6880 1325 if (is_volatile && type == T_LONG) {
aoqi@6880 1326 LIR_Address* addr = new LIR_Address(FrameMap::_at_opr, 0, T_DOUBLE);
aoqi@6880 1327 LIR_Opr tmp = new_register(T_DOUBLE);
aoqi@6880 1328 __ load(addr, tmp);
aoqi@6880 1329 LIR_Opr spill = new_register(T_LONG);
aoqi@6880 1330 set_vreg_flag(spill, must_start_in_memory);
aoqi@6880 1331 __ move(tmp, spill);
aoqi@6880 1332 __ move(spill, dst);
aoqi@6880 1333 } else {
aoqi@6880 1334 LIR_Address* addr = new LIR_Address(FrameMap::_at_opr, 0, type);
aoqi@6880 1335 __ load(addr, dst);
aoqi@6880 1336 }
aoqi@1 1337 }
aoqi@1 1338
aoqi@1 1339
aoqi@1 1340 void LIRGenerator::put_Object_unsafe(LIR_Opr src, LIR_Opr offset, LIR_Opr data,
aoqi@6880 1341 BasicType type, bool is_volatile) {
aoqi@6880 1342 __ add(src, offset, FrameMap::_at_opr);
aoqi@6880 1343 if (is_volatile && type == T_LONG) {
aoqi@6880 1344 LIR_Address* addr = new LIR_Address(FrameMap::_at_opr, 0, T_DOUBLE);
aoqi@6880 1345 LIR_Opr tmp = new_register(T_DOUBLE);
aoqi@6880 1346 LIR_Opr spill = new_register(T_DOUBLE);
aoqi@6880 1347 set_vreg_flag(spill, must_start_in_memory);
aoqi@6880 1348 __ move(data, spill);
aoqi@6880 1349 __ move(spill, tmp);
aoqi@6880 1350 __ move(tmp, addr);
aoqi@6880 1351 } else {
aoqi@6880 1352 LIR_Address* addr = new LIR_Address(FrameMap::_at_opr, 0, type);
aoqi@6880 1353 bool is_obj = (type == T_ARRAY || type == T_OBJECT);
aoqi@6880 1354 if (is_obj) {
aoqi@6880 1355 // Do the pre-write barrier, if any.
aoqi@6880 1356 pre_barrier(LIR_OprFact::address(addr), LIR_OprFact::illegalOpr/* pre_val */,
aoqi@1 1357 true/* do_load */,false /*patch*/, NULL);
aoqi@6880 1358 __ move(data, addr);
aoqi@6880 1359 assert(src->is_register(), "must be register");
aoqi@6880 1360 // Seems to be a precise address
aoqi@6880 1361 post_barrier(LIR_OprFact::address(addr), data);
aoqi@6880 1362 } else {
aoqi@6880 1363 __ move(data, addr);
aoqi@6880 1364 }
aoqi@6880 1365 }
aoqi@1 1366 }
aoqi@1 1367
aoqi@1 1368 void LIRGenerator::do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) {
aoqi@1 1369 BasicType type = x->basic_type();
aoqi@1 1370 LIRItem src(x->object(), this);
aoqi@1 1371 LIRItem off(x->offset(), this);
aoqi@1 1372 LIRItem value(x->value(), this);
aoqi@1 1373
aoqi@1 1374 src.load_item();
aoqi@1 1375 value.load_item();
aoqi@1 1376 off.load_nonconstant();
aoqi@1 1377
aoqi@1 1378 LIR_Opr dst = rlock_result(x, type);
aoqi@1 1379 LIR_Opr data = value.result();
aoqi@1 1380 bool is_obj = (type == T_ARRAY || type == T_OBJECT);
aoqi@1 1381 LIR_Opr offset = off.result();
aoqi@1 1382
aoqi@1 1383 assert (type == T_INT || (!x->is_add() && is_obj) LP64_ONLY( || type == T_LONG ), "unexpected type");
aoqi@1 1384 LIR_Address* addr;
aoqi@1 1385 if (offset->is_constant()) {
aoqi@1 1386 #ifdef _LP64
aoqi@1 1387 jlong c = offset->as_jlong();
aoqi@1 1388 if ((jlong)((jint)c) == c) {
aoqi@1 1389 addr = new LIR_Address(src.result(), (jint)c, type);
aoqi@1 1390 } else {
aoqi@1 1391 LIR_Opr tmp = new_register(T_LONG);
aoqi@1 1392 __ move(offset, tmp);
aoqi@1 1393 addr = new LIR_Address(src.result(), tmp, type);
aoqi@1 1394 }
aoqi@1 1395 #else
aoqi@1 1396 addr = new LIR_Address(src.result(), offset->as_jint(), type);
aoqi@1 1397 #endif
aoqi@1 1398 } else {
aoqi@1 1399 addr = new LIR_Address(src.result(), offset, type);
aoqi@1 1400 }
aoqi@1 1401
aoqi@1 1402 if (data != dst) {
aoqi@1 1403 __ move(data, dst);
aoqi@1 1404 data = dst;
aoqi@1 1405 }
aoqi@1 1406 if (x->is_add()) {
aoqi@1 1407 __ xadd(LIR_OprFact::address(addr), data, dst, LIR_OprFact::illegalOpr);
aoqi@1 1408 } else {
aoqi@1 1409 if (is_obj) {
aoqi@1 1410 // Do the pre-write barrier, if any.
aoqi@6880 1411 pre_barrier(LIR_OprFact::address(addr), LIR_OprFact::illegalOpr /* pre_val */,
aoqi@1 1412 true /* do_load */, false /* patch */, NULL);
aoqi@1 1413 }
aoqi@1 1414 __ xchg(LIR_OprFact::address(addr), data, dst, LIR_OprFact::illegalOpr);
aoqi@1 1415 if (is_obj) {
aoqi@1 1416 // Seems to be a precise address
aoqi@6880 1417 post_barrier(LIR_OprFact::address(addr), data);
aoqi@1 1418 }
aoqi@1 1419 }
aoqi@1 1420 }

mercurial