1 /* 2 * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 #include "precompiled.hpp" 25 #include "memory/allocation.inline.hpp" 26 #include "opto/connode.hpp" 27 #include "opto/subnode.hpp" 28 #include "opto/vectornode.hpp" 29 #include "utilities/powerOfTwo.hpp" 30 31 //------------------------------VectorNode-------------------------------------- 32 33 // Return the vector operator for the specified scalar operation 34 // and vector length. 35 int VectorNode::opcode(int sopc, BasicType bt) { 36 switch (sopc) { 37 case Op_AddI: 38 switch (bt) { 39 case T_BOOLEAN: 40 case T_BYTE: return Op_AddVB; 41 case T_CHAR: 42 case T_SHORT: return Op_AddVS; 43 case T_INT: return Op_AddVI; 44 default: ShouldNotReachHere(); return 0; 45 } 46 case Op_AddL: 47 assert(bt == T_LONG, "must be"); 48 return Op_AddVL; 49 case Op_AddF: 50 assert(bt == T_FLOAT, "must be"); 51 return Op_AddVF; 52 case Op_AddD: 53 assert(bt == T_DOUBLE, "must be"); 54 return Op_AddVD; 55 case Op_SubI: 56 switch (bt) { 57 case T_BOOLEAN: 58 case T_BYTE: return Op_SubVB; 59 case T_CHAR: 60 case T_SHORT: return Op_SubVS; 61 case T_INT: return Op_SubVI; 62 default: ShouldNotReachHere(); return 0; 63 } 64 case Op_SubL: 65 assert(bt == T_LONG, "must be"); 66 return Op_SubVL; 67 case Op_SubF: 68 assert(bt == T_FLOAT, "must be"); 69 return Op_SubVF; 70 case Op_SubD: 71 assert(bt == T_DOUBLE, "must be"); 72 return Op_SubVD; 73 case Op_MulI: 74 switch (bt) { 75 case T_BOOLEAN:return 0; 76 case T_BYTE: return Op_MulVB; 77 case T_CHAR: 78 case T_SHORT: return Op_MulVS; 79 case T_INT: return Op_MulVI; 80 default: ShouldNotReachHere(); return 0; 81 } 82 case Op_MulL: 83 assert(bt == T_LONG, "must be"); 84 return Op_MulVL; 85 case Op_MulF: 86 assert(bt == T_FLOAT, "must be"); 87 return Op_MulVF; 88 case Op_MulD: 89 assert(bt == T_DOUBLE, "must be"); 90 return Op_MulVD; 91 case Op_FmaD: 92 assert(bt == T_DOUBLE, "must be"); 93 return Op_FmaVD; 94 case Op_FmaF: 95 assert(bt == T_FLOAT, "must be"); 96 return Op_FmaVF; 97 case Op_CMoveF: 98 assert(bt == T_FLOAT, "must be"); 99 return Op_CMoveVF; 100 case Op_CMoveD: 101 assert(bt == T_DOUBLE, "must be"); 102 return Op_CMoveVD; 103 case Op_DivF: 104 assert(bt == T_FLOAT, "must be"); 105 return Op_DivVF; 106 case Op_DivD: 107 assert(bt == T_DOUBLE, "must be"); 108 return Op_DivVD; 109 case Op_AbsI: 110 switch (bt) { 111 case T_BOOLEAN: 112 case T_CHAR: return 0; // abs does not make sense for unsigned 113 case T_BYTE: return Op_AbsVB; 114 case T_SHORT: return Op_AbsVS; 115 case T_INT: return Op_AbsVI; 116 default: ShouldNotReachHere(); return 0; 117 } 118 case Op_AbsL: 119 assert(bt == T_LONG, "must be"); 120 return Op_AbsVL; 121 case Op_MinI: 122 switch (bt) { 123 case T_BOOLEAN: 124 case T_CHAR: return 0; 125 case T_BYTE: 126 case T_SHORT: 127 case T_INT: return Op_MinV; 128 default: ShouldNotReachHere(); return 0; 129 } 130 case Op_MinL: 131 assert(bt == T_LONG, "must be"); 132 return Op_MinV; 133 case Op_MinF: 134 assert(bt == T_FLOAT, "must be"); 135 return Op_MinV; 136 case Op_MinD: 137 assert(bt == T_DOUBLE, "must be"); 138 return Op_MinV; 139 case Op_MaxI: 140 switch (bt) { 141 case T_BOOLEAN: 142 case T_CHAR: return 0; 143 case T_BYTE: 144 case T_SHORT: 145 case T_INT: return Op_MaxV; 146 default: ShouldNotReachHere(); return 0; 147 } 148 case Op_MaxL: 149 assert(bt == T_LONG, "must be"); 150 return Op_MaxV; 151 case Op_MaxF: 152 assert(bt == T_FLOAT, "must be"); 153 return Op_MaxV; 154 case Op_MaxD: 155 assert(bt == T_DOUBLE, "must be"); 156 return Op_MaxV; 157 case Op_AbsF: 158 assert(bt == T_FLOAT, "must be"); 159 return Op_AbsVF; 160 case Op_AbsD: 161 assert(bt == T_DOUBLE, "must be"); 162 return Op_AbsVD; 163 case Op_NegI: 164 assert(bt == T_INT, "must be"); 165 return Op_NegVI; 166 case Op_NegF: 167 assert(bt == T_FLOAT, "must be"); 168 return Op_NegVF; 169 case Op_NegD: 170 assert(bt == T_DOUBLE, "must be"); 171 return Op_NegVD; 172 case Op_RoundDoubleMode: 173 assert(bt == T_DOUBLE, "must be"); 174 return Op_RoundDoubleModeV; 175 case Op_SqrtF: 176 assert(bt == T_FLOAT, "must be"); 177 return Op_SqrtVF; 178 case Op_SqrtD: 179 assert(bt == T_DOUBLE, "must be"); 180 return Op_SqrtVD; 181 case Op_PopCountI: 182 if (bt == T_INT) { 183 return Op_PopCountVI; 184 } 185 // Unimplemented for subword types since bit count changes 186 // depending on size of lane (and sign bit). 187 return 0; 188 case Op_LShiftI: 189 switch (bt) { 190 case T_BOOLEAN: 191 case T_BYTE: return Op_LShiftVB; 192 case T_CHAR: 193 case T_SHORT: return Op_LShiftVS; 194 case T_INT: return Op_LShiftVI; 195 default: ShouldNotReachHere(); return 0; 196 } 197 case Op_LShiftL: 198 assert(bt == T_LONG, "must be"); 199 return Op_LShiftVL; 200 case Op_RShiftI: 201 switch (bt) { 202 case T_BOOLEAN:return Op_URShiftVB; // boolean is unsigned value 203 case T_CHAR: return Op_URShiftVS; // char is unsigned value 204 case T_BYTE: return Op_RShiftVB; 205 case T_SHORT: return Op_RShiftVS; 206 case T_INT: return Op_RShiftVI; 207 default: ShouldNotReachHere(); return 0; 208 } 209 case Op_RShiftL: 210 assert(bt == T_LONG, "must be"); 211 return Op_RShiftVL; 212 case Op_URShiftB: 213 assert(bt == T_BYTE, "must be"); 214 return Op_URShiftVB; 215 case Op_URShiftS: 216 assert(bt == T_SHORT, "must be"); 217 return Op_URShiftVS; 218 case Op_URShiftI: 219 switch (bt) { 220 case T_BOOLEAN:return Op_URShiftVB; 221 case T_CHAR: return Op_URShiftVS; 222 case T_BYTE: 223 case T_SHORT: return 0; // Vector logical right shift for signed short 224 // values produces incorrect Java result for 225 // negative data because java code should convert 226 // a short value into int value with sign 227 // extension before a shift. 228 case T_INT: return Op_URShiftVI; 229 default: ShouldNotReachHere(); return 0; 230 } 231 case Op_URShiftL: 232 assert(bt == T_LONG, "must be"); 233 return Op_URShiftVL; 234 case Op_AndI: 235 case Op_AndL: 236 return Op_AndV; 237 case Op_OrI: 238 case Op_OrL: 239 return Op_OrV; 240 case Op_XorI: 241 case Op_XorL: 242 return Op_XorV; 243 244 case Op_LoadB: 245 case Op_LoadUB: 246 case Op_LoadUS: 247 case Op_LoadS: 248 case Op_LoadI: 249 case Op_LoadL: 250 case Op_LoadF: 251 case Op_LoadD: 252 return Op_LoadVector; 253 254 case Op_StoreB: 255 case Op_StoreC: 256 case Op_StoreI: 257 case Op_StoreL: 258 case Op_StoreF: 259 case Op_StoreD: 260 return Op_StoreVector; 261 case Op_MulAddS2I: 262 return Op_MulAddVS2VI; 263 264 default: 265 return 0; // Unimplemented 266 } 267 } 268 269 int VectorNode::replicate_opcode(BasicType bt) { 270 switch(bt) { 271 case T_BOOLEAN: 272 case T_BYTE: 273 return Op_ReplicateB; 274 case T_SHORT: 275 case T_CHAR: 276 return Op_ReplicateS; 277 case T_INT: 278 return Op_ReplicateI; 279 case T_LONG: 280 return Op_ReplicateL; 281 case T_FLOAT: 282 return Op_ReplicateF; 283 case T_DOUBLE: 284 return Op_ReplicateD; 285 default: 286 assert(false, "wrong type: %s", type2name(bt)); 287 return 0; 288 } 289 } 290 291 // Also used to check if the code generator 292 // supports the vector operation. 293 bool VectorNode::implemented(int opc, uint vlen, BasicType bt) { 294 if (is_java_primitive(bt) && 295 (vlen > 1) && is_power_of_2(vlen) && 296 Matcher::vector_size_supported(bt, vlen)) { 297 int vopc = VectorNode::opcode(opc, bt); 298 return vopc > 0 && Matcher::match_rule_supported_vector(vopc, vlen, bt); 299 } 300 return false; 301 } 302 303 bool VectorNode::is_type_transition_short_to_int(Node* n) { 304 switch (n->Opcode()) { 305 case Op_MulAddS2I: 306 return true; 307 } 308 return false; 309 } 310 311 bool VectorNode::is_type_transition_to_int(Node* n) { 312 return is_type_transition_short_to_int(n); 313 } 314 315 bool VectorNode::is_muladds2i(Node* n) { 316 if (n->Opcode() == Op_MulAddS2I) { 317 return true; 318 } 319 return false; 320 } 321 322 bool VectorNode::is_roundopD(Node *n) { 323 if (n->Opcode() == Op_RoundDoubleMode) { 324 return true; 325 } 326 return false; 327 } 328 329 bool VectorNode::is_shift(Node* n) { 330 switch (n->Opcode()) { 331 case Op_LShiftI: 332 case Op_LShiftL: 333 case Op_RShiftI: 334 case Op_RShiftL: 335 case Op_URShiftI: 336 case Op_URShiftL: 337 return true; 338 default: 339 return false; 340 } 341 } 342 343 bool VectorNode::is_vshift_cnt(Node* n) { 344 switch (n->Opcode()) { 345 case Op_LShiftCntV: 346 case Op_RShiftCntV: 347 return true; 348 default: 349 return false; 350 } 351 } 352 353 // Check if input is loop invariant vector. 354 bool VectorNode::is_invariant_vector(Node* n) { 355 // Only Replicate vector nodes are loop invariant for now. 356 switch (n->Opcode()) { 357 case Op_ReplicateB: 358 case Op_ReplicateS: 359 case Op_ReplicateI: 360 case Op_ReplicateL: 361 case Op_ReplicateF: 362 case Op_ReplicateD: 363 return true; 364 default: 365 return false; 366 } 367 } 368 369 // [Start, end) half-open range defining which operands are vectors 370 void VectorNode::vector_operands(Node* n, uint* start, uint* end) { 371 switch (n->Opcode()) { 372 case Op_LoadB: case Op_LoadUB: 373 case Op_LoadS: case Op_LoadUS: 374 case Op_LoadI: case Op_LoadL: 375 case Op_LoadF: case Op_LoadD: 376 case Op_LoadP: case Op_LoadN: 377 *start = 0; 378 *end = 0; // no vector operands 379 break; 380 case Op_StoreB: case Op_StoreC: 381 case Op_StoreI: case Op_StoreL: 382 case Op_StoreF: case Op_StoreD: 383 case Op_StoreP: case Op_StoreN: 384 *start = MemNode::ValueIn; 385 *end = MemNode::ValueIn + 1; // 1 vector operand 386 break; 387 case Op_LShiftI: case Op_LShiftL: 388 case Op_RShiftI: case Op_RShiftL: 389 case Op_URShiftI: case Op_URShiftL: 390 *start = 1; 391 *end = 2; // 1 vector operand 392 break; 393 case Op_AddI: case Op_AddL: case Op_AddF: case Op_AddD: 394 case Op_SubI: case Op_SubL: case Op_SubF: case Op_SubD: 395 case Op_MulI: case Op_MulL: case Op_MulF: case Op_MulD: 396 case Op_DivF: case Op_DivD: 397 case Op_AndI: case Op_AndL: 398 case Op_OrI: case Op_OrL: 399 case Op_XorI: case Op_XorL: 400 case Op_MulAddS2I: 401 *start = 1; 402 *end = 3; // 2 vector operands 403 break; 404 case Op_CMoveI: case Op_CMoveL: case Op_CMoveF: case Op_CMoveD: 405 *start = 2; 406 *end = n->req(); 407 break; 408 case Op_FmaD: 409 case Op_FmaF: 410 *start = 1; 411 *end = 4; // 3 vector operands 412 break; 413 default: 414 *start = 1; 415 *end = n->req(); // default is all operands 416 } 417 } 418 419 // Make a vector node for binary operation 420 VectorNode* VectorNode::make(int vopc, Node* n1, Node* n2, const TypeVect* vt) { 421 // This method should not be called for unimplemented vectors. 422 guarantee(vopc > 0, "vopc must be > 0"); 423 switch (vopc) { 424 case Op_AddVB: return new AddVBNode(n1, n2, vt); 425 case Op_AddVS: return new AddVSNode(n1, n2, vt); 426 case Op_AddVI: return new AddVINode(n1, n2, vt); 427 case Op_AddVL: return new AddVLNode(n1, n2, vt); 428 case Op_AddVF: return new AddVFNode(n1, n2, vt); 429 case Op_AddVD: return new AddVDNode(n1, n2, vt); 430 431 case Op_SubVB: return new SubVBNode(n1, n2, vt); 432 case Op_SubVS: return new SubVSNode(n1, n2, vt); 433 case Op_SubVI: return new SubVINode(n1, n2, vt); 434 case Op_SubVL: return new SubVLNode(n1, n2, vt); 435 case Op_SubVF: return new SubVFNode(n1, n2, vt); 436 case Op_SubVD: return new SubVDNode(n1, n2, vt); 437 438 case Op_MulVB: return new MulVBNode(n1, n2, vt); 439 case Op_MulVS: return new MulVSNode(n1, n2, vt); 440 case Op_MulVI: return new MulVINode(n1, n2, vt); 441 case Op_MulVL: return new MulVLNode(n1, n2, vt); 442 case Op_MulVF: return new MulVFNode(n1, n2, vt); 443 case Op_MulVD: return new MulVDNode(n1, n2, vt); 444 445 case Op_DivVF: return new DivVFNode(n1, n2, vt); 446 case Op_DivVD: return new DivVDNode(n1, n2, vt); 447 448 case Op_MinV: return new MinVNode(n1, n2, vt); 449 case Op_MaxV: return new MaxVNode(n1, n2, vt); 450 451 case Op_AbsVF: return new AbsVFNode(n1, vt); 452 case Op_AbsVD: return new AbsVDNode(n1, vt); 453 case Op_AbsVB: return new AbsVBNode(n1, vt); 454 case Op_AbsVS: return new AbsVSNode(n1, vt); 455 case Op_AbsVI: return new AbsVINode(n1, vt); 456 case Op_AbsVL: return new AbsVLNode(n1, vt); 457 458 case Op_NegVI: return new NegVINode(n1, vt); 459 case Op_NegVF: return new NegVFNode(n1, vt); 460 case Op_NegVD: return new NegVDNode(n1, vt); 461 462 case Op_SqrtVF: return new SqrtVFNode(n1, vt); 463 case Op_SqrtVD: return new SqrtVDNode(n1, vt); 464 465 case Op_PopCountVI: return new PopCountVINode(n1, vt); 466 467 case Op_LShiftVB: return new LShiftVBNode(n1, n2, vt); 468 case Op_LShiftVS: return new LShiftVSNode(n1, n2, vt); 469 case Op_LShiftVI: return new LShiftVINode(n1, n2, vt); 470 case Op_LShiftVL: return new LShiftVLNode(n1, n2, vt); 471 472 case Op_RShiftVB: return new RShiftVBNode(n1, n2, vt); 473 case Op_RShiftVS: return new RShiftVSNode(n1, n2, vt); 474 case Op_RShiftVI: return new RShiftVINode(n1, n2, vt); 475 case Op_RShiftVL: return new RShiftVLNode(n1, n2, vt); 476 477 case Op_URShiftVB: return new URShiftVBNode(n1, n2, vt); 478 case Op_URShiftVS: return new URShiftVSNode(n1, n2, vt); 479 case Op_URShiftVI: return new URShiftVINode(n1, n2, vt); 480 case Op_URShiftVL: return new URShiftVLNode(n1, n2, vt); 481 482 case Op_AndV: return new AndVNode(n1, n2, vt); 483 case Op_OrV: return new OrVNode (n1, n2, vt); 484 case Op_XorV: return new XorVNode(n1, n2, vt); 485 486 case Op_RoundDoubleModeV: return new RoundDoubleModeVNode(n1, n2, vt); 487 488 case Op_MulAddVS2VI: return new MulAddVS2VINode(n1, n2, vt); 489 default: 490 fatal("Missed vector creation for '%s'", NodeClassNames[vopc]); 491 return NULL; 492 } 493 } 494 495 // Return the vector version of a scalar binary operation node. 496 VectorNode* VectorNode::make(int opc, Node* n1, Node* n2, uint vlen, BasicType bt) { 497 const TypeVect* vt = TypeVect::make(bt, vlen); 498 int vopc = VectorNode::opcode(opc, bt); 499 // This method should not be called for unimplemented vectors. 500 guarantee(vopc > 0, "Vector for '%s' is not implemented", NodeClassNames[opc]); 501 return make(vopc, n1, n2, vt); 502 } 503 504 // Make a vector node for ternary operation 505 VectorNode* VectorNode::make(int vopc, Node* n1, Node* n2, Node* n3, const TypeVect* vt) { 506 // This method should not be called for unimplemented vectors. 507 guarantee(vopc > 0, "vopc must be > 0"); 508 switch (vopc) { 509 case Op_FmaVD: return new FmaVDNode(n1, n2, n3, vt); 510 case Op_FmaVF: return new FmaVFNode(n1, n2, n3, vt); 511 default: 512 fatal("Missed vector creation for '%s'", NodeClassNames[vopc]); 513 return NULL; 514 } 515 } 516 517 // Return the vector version of a scalar ternary operation node. 518 VectorNode* VectorNode::make(int opc, Node* n1, Node* n2, Node* n3, uint vlen, BasicType bt) { 519 const TypeVect* vt = TypeVect::make(bt, vlen); 520 int vopc = VectorNode::opcode(opc, bt); 521 // This method should not be called for unimplemented vectors. 522 guarantee(vopc > 0, "Vector for '%s' is not implemented", NodeClassNames[opc]); 523 return make(vopc, n1, n2, n3, vt); 524 } 525 526 // Scalar promotion 527 VectorNode* VectorNode::scalar2vector(Node* s, uint vlen, const Type* opd_t) { 528 BasicType bt = opd_t->array_element_basic_type(); 529 const TypeVect* vt = opd_t->singleton() ? TypeVect::make(opd_t, vlen) 530 : TypeVect::make(bt, vlen); 531 switch (bt) { 532 case T_BOOLEAN: 533 case T_BYTE: 534 return new ReplicateBNode(s, vt); 535 case T_CHAR: 536 case T_SHORT: 537 return new ReplicateSNode(s, vt); 538 case T_INT: 539 return new ReplicateINode(s, vt); 540 case T_LONG: 541 return new ReplicateLNode(s, vt); 542 case T_FLOAT: 543 return new ReplicateFNode(s, vt); 544 case T_DOUBLE: 545 return new ReplicateDNode(s, vt); 546 default: 547 fatal("Type '%s' is not supported for vectors", type2name(bt)); 548 return NULL; 549 } 550 } 551 552 VectorNode* VectorNode::shift_count(int opc, Node* cnt, uint vlen, BasicType bt) { 553 // Match shift count type with shift vector type. 554 const TypeVect* vt = TypeVect::make(bt, vlen); 555 switch (opc) { 556 case Op_LShiftI: 557 case Op_LShiftL: 558 return new LShiftCntVNode(cnt, vt); 559 case Op_RShiftI: 560 case Op_RShiftL: 561 case Op_URShiftB: 562 case Op_URShiftS: 563 case Op_URShiftI: 564 case Op_URShiftL: 565 return new RShiftCntVNode(cnt, vt); 566 default: 567 fatal("Missed vector creation for '%s'", NodeClassNames[opc]); 568 return NULL; 569 } 570 } 571 572 bool VectorNode::is_vector_shift(int opc) { 573 assert(opc > _last_machine_leaf && opc < _last_opcode, "invalid opcode"); 574 switch (opc) { 575 case Op_LShiftVB: 576 case Op_LShiftVS: 577 case Op_LShiftVI: 578 case Op_LShiftVL: 579 case Op_RShiftVB: 580 case Op_RShiftVS: 581 case Op_RShiftVI: 582 case Op_RShiftVL: 583 case Op_URShiftVB: 584 case Op_URShiftVS: 585 case Op_URShiftVI: 586 case Op_URShiftVL: 587 return true; 588 default: 589 return false; 590 } 591 } 592 593 bool VectorNode::is_vector_shift_count(int opc) { 594 assert(opc > _last_machine_leaf && opc < _last_opcode, "invalid opcode"); 595 switch (opc) { 596 case Op_RShiftCntV: 597 case Op_LShiftCntV: 598 return true; 599 default: 600 return false; 601 } 602 } 603 604 static bool is_con_M1(Node* n) { 605 if (n->is_Con()) { 606 const Type* t = n->bottom_type(); 607 if (t->isa_int() && t->is_int()->get_con() == -1) { 608 return true; 609 } 610 if (t->isa_long() && t->is_long()->get_con() == -1) { 611 return true; 612 } 613 } 614 return false; 615 } 616 617 bool VectorNode::is_all_ones_vector(Node* n) { 618 switch (n->Opcode()) { 619 case Op_ReplicateB: 620 case Op_ReplicateS: 621 case Op_ReplicateI: 622 case Op_ReplicateL: 623 return is_con_M1(n->in(1)); 624 default: 625 return false; 626 } 627 } 628 629 bool VectorNode::is_vector_bitwise_not_pattern(Node* n) { 630 if (n->Opcode() == Op_XorV) { 631 return is_all_ones_vector(n->in(1)) || 632 is_all_ones_vector(n->in(2)); 633 } 634 return false; 635 } 636 637 // Return initial Pack node. Additional operands added with add_opd() calls. 638 PackNode* PackNode::make(Node* s, uint vlen, BasicType bt) { 639 const TypeVect* vt = TypeVect::make(bt, vlen); 640 switch (bt) { 641 case T_BOOLEAN: 642 case T_BYTE: 643 return new PackBNode(s, vt); 644 case T_CHAR: 645 case T_SHORT: 646 return new PackSNode(s, vt); 647 case T_INT: 648 return new PackINode(s, vt); 649 case T_LONG: 650 return new PackLNode(s, vt); 651 case T_FLOAT: 652 return new PackFNode(s, vt); 653 case T_DOUBLE: 654 return new PackDNode(s, vt); 655 default: 656 fatal("Type '%s' is not supported for vectors", type2name(bt)); 657 return NULL; 658 } 659 } 660 661 // Create a binary tree form for Packs. [lo, hi) (half-open) range 662 PackNode* PackNode::binary_tree_pack(int lo, int hi) { 663 int ct = hi - lo; 664 assert(is_power_of_2(ct), "power of 2"); 665 if (ct == 2) { 666 PackNode* pk = PackNode::make(in(lo), 2, vect_type()->element_basic_type()); 667 pk->add_opd(in(lo+1)); 668 return pk; 669 } else { 670 int mid = lo + ct/2; 671 PackNode* n1 = binary_tree_pack(lo, mid); 672 PackNode* n2 = binary_tree_pack(mid, hi ); 673 674 BasicType bt = n1->vect_type()->element_basic_type(); 675 assert(bt == n2->vect_type()->element_basic_type(), "should be the same"); 676 switch (bt) { 677 case T_BOOLEAN: 678 case T_BYTE: 679 return new PackSNode(n1, n2, TypeVect::make(T_SHORT, 2)); 680 case T_CHAR: 681 case T_SHORT: 682 return new PackINode(n1, n2, TypeVect::make(T_INT, 2)); 683 case T_INT: 684 return new PackLNode(n1, n2, TypeVect::make(T_LONG, 2)); 685 case T_LONG: 686 return new Pack2LNode(n1, n2, TypeVect::make(T_LONG, 2)); 687 case T_FLOAT: 688 return new PackDNode(n1, n2, TypeVect::make(T_DOUBLE, 2)); 689 case T_DOUBLE: 690 return new Pack2DNode(n1, n2, TypeVect::make(T_DOUBLE, 2)); 691 default: 692 fatal("Type '%s' is not supported for vectors", type2name(bt)); 693 return NULL; 694 } 695 } 696 } 697 698 // Return the vector version of a scalar load node. 699 LoadVectorNode* LoadVectorNode::make(int opc, Node* ctl, Node* mem, 700 Node* adr, const TypePtr* atyp, 701 uint vlen, BasicType bt, 702 ControlDependency control_dependency) { 703 const TypeVect* vt = TypeVect::make(bt, vlen); 704 return new LoadVectorNode(ctl, mem, adr, atyp, vt, control_dependency); 705 } 706 707 // Return the vector version of a scalar store node. 708 StoreVectorNode* StoreVectorNode::make(int opc, Node* ctl, Node* mem, 709 Node* adr, const TypePtr* atyp, Node* val, 710 uint vlen) { 711 return new StoreVectorNode(ctl, mem, adr, atyp, val); 712 } 713 714 int ExtractNode::opcode(BasicType bt) { 715 switch (bt) { 716 case T_BOOLEAN: return Op_ExtractUB; 717 case T_BYTE: return Op_ExtractB; 718 case T_CHAR: return Op_ExtractC; 719 case T_SHORT: return Op_ExtractS; 720 case T_INT: return Op_ExtractI; 721 case T_LONG: return Op_ExtractL; 722 case T_FLOAT: return Op_ExtractF; 723 case T_DOUBLE: return Op_ExtractD; 724 default: 725 assert(false, "wrong type: %s", type2name(bt)); 726 return 0; 727 } 728 } 729 730 // Extract a scalar element of vector. 731 Node* ExtractNode::make(Node* v, uint position, BasicType bt) { 732 assert((int)position < Matcher::max_vector_size(bt), "pos in range"); 733 ConINode* pos = ConINode::make((int)position); 734 switch (bt) { 735 case T_BOOLEAN: return new ExtractUBNode(v, pos); 736 case T_BYTE: return new ExtractBNode(v, pos); 737 case T_CHAR: return new ExtractCNode(v, pos); 738 case T_SHORT: return new ExtractSNode(v, pos); 739 case T_INT: return new ExtractINode(v, pos); 740 case T_LONG: return new ExtractLNode(v, pos); 741 case T_FLOAT: return new ExtractFNode(v, pos); 742 case T_DOUBLE: return new ExtractDNode(v, pos); 743 default: 744 assert(false, "wrong type: %s", type2name(bt)); 745 return NULL; 746 } 747 } 748 749 int ReductionNode::opcode(int opc, BasicType bt) { 750 int vopc = opc; 751 switch (opc) { 752 case Op_AddI: 753 switch (bt) { 754 case T_BOOLEAN: 755 case T_CHAR: return 0; 756 case T_BYTE: 757 case T_SHORT: 758 case T_INT: 759 vopc = Op_AddReductionVI; 760 break; 761 default: ShouldNotReachHere(); return 0; 762 } 763 break; 764 case Op_AddL: 765 assert(bt == T_LONG, "must be"); 766 vopc = Op_AddReductionVL; 767 break; 768 case Op_AddF: 769 assert(bt == T_FLOAT, "must be"); 770 vopc = Op_AddReductionVF; 771 break; 772 case Op_AddD: 773 assert(bt == T_DOUBLE, "must be"); 774 vopc = Op_AddReductionVD; 775 break; 776 case Op_MulI: 777 switch (bt) { 778 case T_BOOLEAN: 779 case T_CHAR: return 0; 780 case T_BYTE: 781 case T_SHORT: 782 case T_INT: 783 vopc = Op_MulReductionVI; 784 break; 785 default: ShouldNotReachHere(); return 0; 786 } 787 break; 788 case Op_MulL: 789 assert(bt == T_LONG, "must be"); 790 vopc = Op_MulReductionVL; 791 break; 792 case Op_MulF: 793 assert(bt == T_FLOAT, "must be"); 794 vopc = Op_MulReductionVF; 795 break; 796 case Op_MulD: 797 assert(bt == T_DOUBLE, "must be"); 798 vopc = Op_MulReductionVD; 799 break; 800 case Op_MinI: 801 switch (bt) { 802 case T_BOOLEAN: 803 case T_CHAR: return 0; 804 case T_BYTE: 805 case T_SHORT: 806 case T_INT: 807 vopc = Op_MinReductionV; 808 break; 809 default: ShouldNotReachHere(); return 0; 810 } 811 break; 812 case Op_MinL: 813 assert(bt == T_LONG, "must be"); 814 vopc = Op_MinReductionV; 815 break; 816 case Op_MinF: 817 assert(bt == T_FLOAT, "must be"); 818 vopc = Op_MinReductionV; 819 break; 820 case Op_MinD: 821 assert(bt == T_DOUBLE, "must be"); 822 vopc = Op_MinReductionV; 823 break; 824 case Op_MaxI: 825 switch (bt) { 826 case T_BOOLEAN: 827 case T_CHAR: return 0; 828 case T_BYTE: 829 case T_SHORT: 830 case T_INT: 831 vopc = Op_MaxReductionV; 832 break; 833 default: ShouldNotReachHere(); return 0; 834 } 835 break; 836 case Op_MaxL: 837 assert(bt == T_LONG, "must be"); 838 vopc = Op_MaxReductionV; 839 break; 840 case Op_MaxF: 841 assert(bt == T_FLOAT, "must be"); 842 vopc = Op_MaxReductionV; 843 break; 844 case Op_MaxD: 845 assert(bt == T_DOUBLE, "must be"); 846 vopc = Op_MaxReductionV; 847 break; 848 case Op_AndI: 849 switch (bt) { 850 case T_BOOLEAN: 851 case T_CHAR: return 0; 852 case T_BYTE: 853 case T_SHORT: 854 case T_INT: 855 vopc = Op_AndReductionV; 856 break; 857 default: ShouldNotReachHere(); return 0; 858 } 859 break; 860 case Op_AndL: 861 assert(bt == T_LONG, "must be"); 862 vopc = Op_AndReductionV; 863 break; 864 case Op_OrI: 865 switch(bt) { 866 case T_BOOLEAN: 867 case T_CHAR: return 0; 868 case T_BYTE: 869 case T_SHORT: 870 case T_INT: 871 vopc = Op_OrReductionV; 872 break; 873 default: ShouldNotReachHere(); return 0; 874 } 875 break; 876 case Op_OrL: 877 assert(bt == T_LONG, "must be"); 878 vopc = Op_OrReductionV; 879 break; 880 case Op_XorI: 881 switch(bt) { 882 case T_BOOLEAN: 883 case T_CHAR: return 0; 884 case T_BYTE: 885 case T_SHORT: 886 case T_INT: 887 vopc = Op_XorReductionV; 888 break; 889 default: ShouldNotReachHere(); return 0; 890 } 891 break; 892 case Op_XorL: 893 assert(bt == T_LONG, "must be"); 894 vopc = Op_XorReductionV; 895 break; 896 default: 897 break; 898 } 899 return vopc; 900 } 901 902 // Return the appropriate reduction node. 903 ReductionNode* ReductionNode::make(int opc, Node *ctrl, Node* n1, Node* n2, BasicType bt) { 904 905 int vopc = opcode(opc, bt); 906 907 // This method should not be called for unimplemented vectors. 908 guarantee(vopc != opc, "Vector for '%s' is not implemented", NodeClassNames[opc]); 909 910 switch (vopc) { 911 case Op_AddReductionVI: return new AddReductionVINode(ctrl, n1, n2); 912 case Op_AddReductionVL: return new AddReductionVLNode(ctrl, n1, n2); 913 case Op_AddReductionVF: return new AddReductionVFNode(ctrl, n1, n2); 914 case Op_AddReductionVD: return new AddReductionVDNode(ctrl, n1, n2); 915 case Op_MulReductionVI: return new MulReductionVINode(ctrl, n1, n2); 916 case Op_MulReductionVL: return new MulReductionVLNode(ctrl, n1, n2); 917 case Op_MulReductionVF: return new MulReductionVFNode(ctrl, n1, n2); 918 case Op_MulReductionVD: return new MulReductionVDNode(ctrl, n1, n2); 919 case Op_MinReductionV: return new MinReductionVNode(ctrl, n1, n2); 920 case Op_MaxReductionV: return new MaxReductionVNode(ctrl, n1, n2); 921 case Op_AndReductionV: return new AndReductionVNode(ctrl, n1, n2); 922 case Op_OrReductionV: return new OrReductionVNode(ctrl, n1, n2); 923 case Op_XorReductionV: return new XorReductionVNode(ctrl, n1, n2); 924 default: 925 assert(false, "unknown node: %s", NodeClassNames[vopc]); 926 return NULL; 927 } 928 } 929 930 VectorStoreMaskNode* VectorStoreMaskNode::make(PhaseGVN& gvn, Node* in, BasicType in_type, uint num_elem) { 931 assert(in->bottom_type()->isa_vect(), "sanity"); 932 const TypeVect* vt = TypeVect::make(T_BOOLEAN, num_elem); 933 int elem_size = type2aelembytes(in_type); 934 return new VectorStoreMaskNode(in, gvn.intcon(elem_size), vt); 935 } 936 937 VectorCastNode* VectorCastNode::make(int vopc, Node* n1, BasicType bt, uint vlen) { 938 const TypeVect* vt = TypeVect::make(bt, vlen); 939 switch (vopc) { 940 case Op_VectorCastB2X: return new VectorCastB2XNode(n1, vt); 941 case Op_VectorCastS2X: return new VectorCastS2XNode(n1, vt); 942 case Op_VectorCastI2X: return new VectorCastI2XNode(n1, vt); 943 case Op_VectorCastL2X: return new VectorCastL2XNode(n1, vt); 944 case Op_VectorCastF2X: return new VectorCastF2XNode(n1, vt); 945 case Op_VectorCastD2X: return new VectorCastD2XNode(n1, vt); 946 default: 947 assert(false, "unknown node: %s", NodeClassNames[vopc]); 948 return NULL; 949 } 950 } 951 952 int VectorCastNode::opcode(BasicType bt) { 953 switch (bt) { 954 case T_BYTE: return Op_VectorCastB2X; 955 case T_SHORT: return Op_VectorCastS2X; 956 case T_INT: return Op_VectorCastI2X; 957 case T_LONG: return Op_VectorCastL2X; 958 case T_FLOAT: return Op_VectorCastF2X; 959 case T_DOUBLE: return Op_VectorCastD2X; 960 default: 961 assert(false, "unknown type: %s", type2name(bt)); 962 return 0; 963 } 964 } 965 966 Node* ReductionNode::make_reduction_input(PhaseGVN& gvn, int opc, BasicType bt) { 967 int vopc = opcode(opc, bt); 968 guarantee(vopc != opc, "Vector reduction for '%s' is not implemented", NodeClassNames[opc]); 969 970 switch (vopc) { 971 case Op_AndReductionV: 972 switch (bt) { 973 case T_BYTE: 974 case T_SHORT: 975 case T_INT: 976 return gvn.makecon(TypeInt::MINUS_1); 977 case T_LONG: 978 return gvn.makecon(TypeLong::MINUS_1); 979 default: 980 fatal("Missed vector creation for '%s' as the basic type is not correct.", NodeClassNames[vopc]); 981 return NULL; 982 } 983 break; 984 case Op_AddReductionVI: // fallthrough 985 case Op_AddReductionVL: // fallthrough 986 case Op_AddReductionVF: // fallthrough 987 case Op_AddReductionVD: 988 case Op_OrReductionV: 989 case Op_XorReductionV: 990 return gvn.zerocon(bt); 991 case Op_MulReductionVI: 992 return gvn.makecon(TypeInt::ONE); 993 case Op_MulReductionVL: 994 return gvn.makecon(TypeLong::ONE); 995 case Op_MulReductionVF: 996 return gvn.makecon(TypeF::ONE); 997 case Op_MulReductionVD: 998 return gvn.makecon(TypeD::ONE); 999 case Op_MinReductionV: 1000 switch (bt) { 1001 case T_BYTE: 1002 case T_SHORT: 1003 case T_INT: 1004 return gvn.makecon(TypeInt::MAX); 1005 case T_LONG: 1006 return gvn.makecon(TypeLong::MAX); 1007 case T_FLOAT: 1008 return gvn.makecon(TypeF::POS_INF); 1009 case T_DOUBLE: 1010 return gvn.makecon(TypeD::POS_INF); 1011 default: Unimplemented(); return NULL; 1012 } 1013 break; 1014 case Op_MaxReductionV: 1015 switch (bt) { 1016 case T_BYTE: 1017 case T_SHORT: 1018 case T_INT: 1019 return gvn.makecon(TypeInt::MIN); 1020 case T_LONG: 1021 return gvn.makecon(TypeLong::MIN); 1022 case T_FLOAT: 1023 return gvn.makecon(TypeF::NEG_INF); 1024 case T_DOUBLE: 1025 return gvn.makecon(TypeD::NEG_INF); 1026 default: Unimplemented(); return NULL; 1027 } 1028 break; 1029 default: 1030 fatal("Missed vector creation for '%s'", NodeClassNames[vopc]); 1031 return NULL; 1032 } 1033 } 1034 1035 bool ReductionNode::implemented(int opc, uint vlen, BasicType bt) { 1036 if (is_java_primitive(bt) && 1037 (vlen > 1) && is_power_of_2(vlen) && 1038 Matcher::vector_size_supported(bt, vlen)) { 1039 int vopc = ReductionNode::opcode(opc, bt); 1040 return vopc != opc && Matcher::match_rule_supported(vopc); 1041 } 1042 return false; 1043 } 1044 1045 MacroLogicVNode* MacroLogicVNode::make(PhaseGVN& gvn, Node* in1, Node* in2, Node* in3, 1046 uint truth_table, const TypeVect* vt) { 1047 assert(truth_table <= 0xFF, "invalid"); 1048 assert(in1->bottom_type()->is_vect()->length_in_bytes() == vt->length_in_bytes(), "mismatch"); 1049 assert(in2->bottom_type()->is_vect()->length_in_bytes() == vt->length_in_bytes(), "mismatch"); 1050 assert(in3->bottom_type()->is_vect()->length_in_bytes() == vt->length_in_bytes(), "mismatch"); 1051 Node* fn = gvn.intcon(truth_table); 1052 return new MacroLogicVNode(in1, in2, in3, fn, vt); 1053 } 1054 1055 #ifndef PRODUCT 1056 void VectorMaskCmpNode::dump_spec(outputStream *st) const { 1057 st->print(" %d #", _predicate); _type->dump_on(st); 1058 } 1059 #endif // PRODUCT 1060 1061 Node* VectorReinterpretNode::Identity(PhaseGVN *phase) { 1062 Node* n = in(1); 1063 if (n->Opcode() == Op_VectorReinterpret) { 1064 if (Type::cmp(bottom_type(), n->in(1)->bottom_type()) == 0) { 1065 return n->in(1); 1066 } 1067 } 1068 return this; 1069 } 1070 1071 Node* VectorInsertNode::make(Node* vec, Node* new_val, int position) { 1072 assert(position < (int)vec->bottom_type()->is_vect()->length(), "pos in range"); 1073 ConINode* pos = ConINode::make(position); 1074 return new VectorInsertNode(vec, new_val, pos, vec->bottom_type()->is_vect()); 1075 } 1076 1077 Node* VectorUnboxNode::Identity(PhaseGVN *phase) { 1078 Node* n = obj()->uncast(); 1079 if (EnableVectorReboxing && n->Opcode() == Op_VectorBox) { 1080 if (Type::cmp(bottom_type(), n->in(VectorBoxNode::Value)->bottom_type()) == 0) { 1081 return n->in(VectorBoxNode::Value); 1082 } 1083 } 1084 return this; 1085 } 1086 1087 const TypeFunc* VectorBoxNode::vec_box_type(const TypeInstPtr* box_type) { 1088 const Type** fields = TypeTuple::fields(0); 1089 const TypeTuple *domain = TypeTuple::make(TypeFunc::Parms, fields); 1090 1091 fields = TypeTuple::fields(1); 1092 fields[TypeFunc::Parms+0] = box_type; 1093 const TypeTuple *range = TypeTuple::make(TypeFunc::Parms+1, fields); 1094 1095 return TypeFunc::make(domain, range); 1096 } 1097 1098 #ifndef PRODUCT 1099 void VectorBoxAllocateNode::dump_spec(outputStream *st) const { 1100 CallStaticJavaNode::dump_spec(st); 1101 } 1102 #endif // !PRODUCT