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