< prev index next >

src/share/vm/opto/vectornode.cpp

Print this page


   1 /*
   2  * Copyright (c) 2007, 2014, 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/vectornode.hpp"
  28 
  29 //------------------------------VectorNode--------------------------------------
  30 
  31 // Return the vector operator for the specified scalar operation
  32 // and vector length.
  33 int VectorNode::opcode(int sopc, BasicType bt) {
  34   switch (sopc) {
  35   case Op_AddI:
  36     switch (bt) {
  37     case T_BOOLEAN:
  38     case T_BYTE:      return Op_AddVB;
  39     case T_CHAR:
  40     case T_SHORT:     return Op_AddVS;
  41     case T_INT:       return Op_AddVI;

  42     }
  43     ShouldNotReachHere();
  44   case Op_AddL:
  45     assert(bt == T_LONG, "must be");
  46     return Op_AddVL;
  47   case Op_AddF:
  48     assert(bt == T_FLOAT, "must be");
  49     return Op_AddVF;
  50   case Op_AddD:
  51     assert(bt == T_DOUBLE, "must be");
  52     return Op_AddVD;
  53   case Op_SubI:
  54     switch (bt) {
  55     case T_BOOLEAN:
  56     case T_BYTE:   return Op_SubVB;
  57     case T_CHAR:
  58     case T_SHORT:  return Op_SubVS;
  59     case T_INT:    return Op_SubVI;

  60     }
  61     ShouldNotReachHere();
  62   case Op_SubL:
  63     assert(bt == T_LONG, "must be");
  64     return Op_SubVL;
  65   case Op_SubF:
  66     assert(bt == T_FLOAT, "must be");
  67     return Op_SubVF;
  68   case Op_SubD:
  69     assert(bt == T_DOUBLE, "must be");
  70     return Op_SubVD;
  71   case Op_MulI:
  72     switch (bt) {
  73     case T_BOOLEAN:
  74     case T_BYTE:   return 0;   // Unimplemented
  75     case T_CHAR:
  76     case T_SHORT:  return Op_MulVS;
  77     case T_INT:    return Op_MulVI;

  78     }
  79     ShouldNotReachHere();
  80   case Op_MulL:
  81     assert(bt == T_LONG, "must be");
  82     return Op_MulVL;
  83   case Op_MulF:
  84     assert(bt == T_FLOAT, "must be");
  85     return Op_MulVF;
  86   case Op_MulD:
  87     assert(bt == T_DOUBLE, "must be");
  88     return Op_MulVD;
  89   case Op_FmaD:
  90     assert(bt == T_DOUBLE, "must be");
  91     return Op_FmaVD;
  92   case Op_FmaF:
  93     assert(bt == T_FLOAT, "must be");
  94     return Op_FmaVF;
  95   case Op_CMoveD:
  96     assert(bt == T_DOUBLE, "must be");
  97     return Op_CMoveVD;
  98   case Op_DivF:
  99     assert(bt == T_FLOAT, "must be");


 106     return Op_AbsVF;
 107   case Op_AbsD:
 108     assert(bt == T_DOUBLE, "must be");
 109     return Op_AbsVD;
 110   case Op_NegF:
 111     assert(bt == T_FLOAT, "must be");
 112     return Op_NegVF;
 113   case Op_NegD:
 114     assert(bt == T_DOUBLE, "must be");
 115     return Op_NegVD;
 116   case Op_SqrtD:
 117     assert(bt == T_DOUBLE, "must be");
 118     return Op_SqrtVD;
 119   case Op_LShiftI:
 120     switch (bt) {
 121     case T_BOOLEAN:
 122     case T_BYTE:   return Op_LShiftVB;
 123     case T_CHAR:
 124     case T_SHORT:  return Op_LShiftVS;
 125     case T_INT:    return Op_LShiftVI;

 126     }
 127     ShouldNotReachHere();
 128   case Op_LShiftL:
 129     assert(bt == T_LONG, "must be");
 130     return Op_LShiftVL;
 131   case Op_RShiftI:
 132     switch (bt) {
 133     case T_BOOLEAN:return Op_URShiftVB; // boolean is unsigned value
 134     case T_CHAR:   return Op_URShiftVS; // char is unsigned value
 135     case T_BYTE:   return Op_RShiftVB;
 136     case T_SHORT:  return Op_RShiftVS;
 137     case T_INT:    return Op_RShiftVI;

 138     }
 139     ShouldNotReachHere();
 140   case Op_RShiftL:
 141     assert(bt == T_LONG, "must be");
 142     return Op_RShiftVL;
 143   case Op_URShiftI:
 144     switch (bt) {
 145     case T_BOOLEAN:return Op_URShiftVB;
 146     case T_CHAR:   return Op_URShiftVS;
 147     case T_BYTE:
 148     case T_SHORT:  return 0; // Vector logical right shift for signed short
 149                              // values produces incorrect Java result for
 150                              // negative data because java code should convert
 151                              // a short value into int value with sign
 152                              // extension before a shift.
 153     case T_INT:    return Op_URShiftVI;

 154     }
 155     ShouldNotReachHere();
 156   case Op_URShiftL:
 157     assert(bt == T_LONG, "must be");
 158     return Op_URShiftVL;
 159   case Op_AndI:
 160   case Op_AndL:
 161     return Op_AndV;
 162   case Op_OrI:
 163   case Op_OrL:
 164     return Op_OrV;
 165   case Op_XorI:
 166   case Op_XorL:
 167     return Op_XorV;
 168 
 169   case Op_LoadB:
 170   case Op_LoadUB:
 171   case Op_LoadUS:
 172   case Op_LoadS:
 173   case Op_LoadI:
 174   case Op_LoadL:
 175   case Op_LoadF:
 176   case Op_LoadD:
 177     return Op_LoadVector;
 178 
 179   case Op_StoreB:
 180   case Op_StoreC:
 181   case Op_StoreI:
 182   case Op_StoreL:
 183   case Op_StoreF:
 184   case Op_StoreD:
 185     return Op_StoreVector;
 186   }

 187   return 0; // Unimplemented

 188 }
 189 
 190 // Also used to check if the code generator
 191 // supports the vector operation.
 192 bool VectorNode::implemented(int opc, uint vlen, BasicType bt) {
 193   if (is_java_primitive(bt) &&
 194       (vlen > 1) && is_power_of_2(vlen) &&
 195       Matcher::vector_size_supported(bt, vlen)) {
 196     int vopc = VectorNode::opcode(opc, bt);
 197     return vopc > 0 && Matcher::match_rule_supported_vector(vopc, vlen);
 198   }
 199   return false;
 200 }
 201 
 202 bool VectorNode::is_shift(Node* n) {
 203   switch (n->Opcode()) {
 204   case Op_LShiftI:
 205   case Op_LShiftL:
 206   case Op_RShiftI:
 207   case Op_RShiftL:
 208   case Op_URShiftI:
 209   case Op_URShiftL:
 210     return true;
 211   }
 212   return false;

 213 }
 214 
 215 // Check if input is loop invariant vector.
 216 bool VectorNode::is_invariant_vector(Node* n) {
 217   // Only Replicate vector nodes are loop invariant for now.
 218   switch (n->Opcode()) {
 219   case Op_ReplicateB:
 220   case Op_ReplicateS:
 221   case Op_ReplicateI:
 222   case Op_ReplicateL:
 223   case Op_ReplicateF:
 224   case Op_ReplicateD:
 225     return true;
 226   }
 227   return false;

 228 }
 229 
 230 // [Start, end) half-open range defining which operands are vectors
 231 void VectorNode::vector_operands(Node* n, uint* start, uint* end) {
 232   switch (n->Opcode()) {
 233   case Op_LoadB:   case Op_LoadUB:
 234   case Op_LoadS:   case Op_LoadUS:
 235   case Op_LoadI:   case Op_LoadL:
 236   case Op_LoadF:   case Op_LoadD:
 237   case Op_LoadP:   case Op_LoadN:
 238     *start = 0;
 239     *end   = 0; // no vector operands
 240     break;
 241   case Op_StoreB:  case Op_StoreC:
 242   case Op_StoreI:  case Op_StoreL:
 243   case Op_StoreF:  case Op_StoreD:
 244   case Op_StoreP:  case Op_StoreN:
 245     *start = MemNode::ValueIn;
 246     *end   = MemNode::ValueIn + 1; // 1 vector operand
 247     break;


 316   case Op_SqrtVD: return new SqrtVDNode(n1, vt);
 317 
 318   case Op_LShiftVB: return new LShiftVBNode(n1, n2, vt);
 319   case Op_LShiftVS: return new LShiftVSNode(n1, n2, vt);
 320   case Op_LShiftVI: return new LShiftVINode(n1, n2, vt);
 321   case Op_LShiftVL: return new LShiftVLNode(n1, n2, vt);
 322 
 323   case Op_RShiftVB: return new RShiftVBNode(n1, n2, vt);
 324   case Op_RShiftVS: return new RShiftVSNode(n1, n2, vt);
 325   case Op_RShiftVI: return new RShiftVINode(n1, n2, vt);
 326   case Op_RShiftVL: return new RShiftVLNode(n1, n2, vt);
 327 
 328   case Op_URShiftVB: return new URShiftVBNode(n1, n2, vt);
 329   case Op_URShiftVS: return new URShiftVSNode(n1, n2, vt);
 330   case Op_URShiftVI: return new URShiftVINode(n1, n2, vt);
 331   case Op_URShiftVL: return new URShiftVLNode(n1, n2, vt);
 332 
 333   case Op_AndV: return new AndVNode(n1, n2, vt);
 334   case Op_OrV:  return new OrVNode (n1, n2, vt);
 335   case Op_XorV: return new XorVNode(n1, n2, vt);
 336   }
 337   fatal("Missed vector creation for '%s'", NodeClassNames[vopc]);
 338   return NULL;
 339 
 340 }
 341 
 342 VectorNode* VectorNode::make(int opc, Node* n1, Node* n2, Node* n3, uint vlen, BasicType bt) {
 343   const TypeVect* vt = TypeVect::make(bt, vlen);
 344   int vopc = VectorNode::opcode(opc, bt);
 345   // This method should not be called for unimplemented vectors.
 346   guarantee(vopc > 0, "Vector for '%s' is not implemented", NodeClassNames[opc]);
 347   switch (vopc) {
 348   case Op_FmaVD: return new FmaVDNode(n1, n2, n3, vt);
 349   case Op_FmaVF: return new FmaVFNode(n1, n2, n3, vt);
 350   }
 351   fatal("Missed vector creation for '%s'", NodeClassNames[vopc]);
 352   return NULL;

 353 }
 354 
 355 // Scalar promotion
 356 VectorNode* VectorNode::scalar2vector(Node* s, uint vlen, const Type* opd_t) {
 357   BasicType bt = opd_t->array_element_basic_type();
 358   const TypeVect* vt = opd_t->singleton() ? TypeVect::make(opd_t, vlen)
 359                                           : TypeVect::make(bt, vlen);
 360   switch (bt) {
 361   case T_BOOLEAN:
 362   case T_BYTE:
 363     return new ReplicateBNode(s, vt);
 364   case T_CHAR:
 365   case T_SHORT:
 366     return new ReplicateSNode(s, vt);
 367   case T_INT:
 368     return new ReplicateINode(s, vt);
 369   case T_LONG:
 370     return new ReplicateLNode(s, vt);
 371   case T_FLOAT:
 372     return new ReplicateFNode(s, vt);
 373   case T_DOUBLE:
 374     return new ReplicateDNode(s, vt);
 375   }
 376   fatal("Type '%s' is not supported for vectors", type2name(bt));
 377   return NULL;

 378 }
 379 
 380 VectorNode* VectorNode::shift_count(Node* shift, Node* cnt, uint vlen, BasicType bt) {
 381   assert(VectorNode::is_shift(shift) && !cnt->is_Con(), "only variable shift count");
 382   // Match shift count type with shift vector type.
 383   const TypeVect* vt = TypeVect::make(bt, vlen);
 384   switch (shift->Opcode()) {
 385   case Op_LShiftI:
 386   case Op_LShiftL:
 387     return new LShiftCntVNode(cnt, vt);
 388   case Op_RShiftI:
 389   case Op_RShiftL:
 390   case Op_URShiftI:
 391   case Op_URShiftL:
 392     return new RShiftCntVNode(cnt, vt);
 393   }
 394   fatal("Missed vector creation for '%s'", NodeClassNames[shift->Opcode()]);
 395   return NULL;

 396 }
 397 
 398 // Return initial Pack node. Additional operands added with add_opd() calls.
 399 PackNode* PackNode::make(Node* s, uint vlen, BasicType bt) {
 400   const TypeVect* vt = TypeVect::make(bt, vlen);
 401   switch (bt) {
 402   case T_BOOLEAN:
 403   case T_BYTE:
 404     return new PackBNode(s, vt);
 405   case T_CHAR:
 406   case T_SHORT:
 407     return new PackSNode(s, vt);
 408   case T_INT:
 409     return new PackINode(s, vt);
 410   case T_LONG:
 411     return new PackLNode(s, vt);
 412   case T_FLOAT:
 413     return new PackFNode(s, vt);
 414   case T_DOUBLE:
 415     return new PackDNode(s, vt);
 416   }
 417   fatal("Type '%s' is not supported for vectors", type2name(bt));
 418   return NULL;

 419 }
 420 
 421 // Create a binary tree form for Packs. [lo, hi) (half-open) range
 422 PackNode* PackNode::binary_tree_pack(int lo, int hi) {
 423   int ct = hi - lo;
 424   assert(is_power_of_2(ct), "power of 2");
 425   if (ct == 2) {
 426     PackNode* pk = PackNode::make(in(lo), 2, vect_type()->element_basic_type());
 427     pk->add_opd(in(lo+1));
 428     return pk;
 429 
 430   } else {
 431     int mid = lo + ct/2;
 432     PackNode* n1 = binary_tree_pack(lo,  mid);
 433     PackNode* n2 = binary_tree_pack(mid, hi );
 434 
 435     BasicType bt = n1->vect_type()->element_basic_type();
 436     assert(bt == n2->vect_type()->element_basic_type(), "should be the same");
 437     switch (bt) {
 438     case T_BOOLEAN:
 439     case T_BYTE:
 440       return new PackSNode(n1, n2, TypeVect::make(T_SHORT, 2));
 441     case T_CHAR:
 442     case T_SHORT:
 443       return new PackINode(n1, n2, TypeVect::make(T_INT, 2));
 444     case T_INT:
 445       return new PackLNode(n1, n2, TypeVect::make(T_LONG, 2));
 446     case T_LONG:
 447       return new Pack2LNode(n1, n2, TypeVect::make(T_LONG, 2));
 448     case T_FLOAT:
 449       return new PackDNode(n1, n2, TypeVect::make(T_DOUBLE, 2));
 450     case T_DOUBLE:
 451       return new Pack2DNode(n1, n2, TypeVect::make(T_DOUBLE, 2));
 452     }
 453     fatal("Type '%s' is not supported for vectors", type2name(bt));
 454   }
 455   return NULL;


 456 }
 457 
 458 // Return the vector version of a scalar load node.
 459 LoadVectorNode* LoadVectorNode::make(int opc, Node* ctl, Node* mem,
 460                                      Node* adr, const TypePtr* atyp,
 461                                      uint vlen, BasicType bt,
 462                                      ControlDependency control_dependency) {
 463   const TypeVect* vt = TypeVect::make(bt, vlen);
 464   return new LoadVectorNode(ctl, mem, adr, atyp, vt, control_dependency);
 465 }
 466 
 467 // Return the vector version of a scalar store node.
 468 StoreVectorNode* StoreVectorNode::make(int opc, Node* ctl, Node* mem,
 469                                        Node* adr, const TypePtr* atyp, Node* val,
 470                                        uint vlen) {
 471   return new StoreVectorNode(ctl, mem, adr, atyp, val);
 472 }
 473 
 474 // Extract a scalar element of vector.
 475 Node* ExtractNode::make(Node* v, uint position, BasicType bt) {
 476   assert((int)position < Matcher::max_vector_size(bt), "pos in range");
 477   ConINode* pos = ConINode::make((int)position);
 478   switch (bt) {
 479   case T_BOOLEAN:
 480     return new ExtractUBNode(v, pos);
 481   case T_BYTE:
 482     return new ExtractBNode(v, pos);
 483   case T_CHAR:
 484     return new ExtractCNode(v, pos);
 485   case T_SHORT:
 486     return new ExtractSNode(v, pos);
 487   case T_INT:
 488     return new ExtractINode(v, pos);
 489   case T_LONG:
 490     return new ExtractLNode(v, pos);
 491   case T_FLOAT:
 492     return new ExtractFNode(v, pos);
 493   case T_DOUBLE:
 494     return new ExtractDNode(v, pos);
 495   }
 496   fatal("Type '%s' is not supported for vectors", type2name(bt));
 497   return NULL;

 498 }
 499 
 500 int ReductionNode::opcode(int opc, BasicType bt) {
 501   int vopc = opc;
 502   switch (opc) {
 503     case Op_AddI:
 504       assert(bt == T_INT, "must be");
 505       vopc = Op_AddReductionVI;
 506       break;
 507     case Op_AddL:
 508       assert(bt == T_LONG, "must be");
 509       vopc = Op_AddReductionVL;
 510       break;
 511     case Op_AddF:
 512       assert(bt == T_FLOAT, "must be");
 513       vopc = Op_AddReductionVF;
 514       break;
 515     case Op_AddD:
 516       assert(bt == T_DOUBLE, "must be");
 517       vopc = Op_AddReductionVD;


 539   return vopc;
 540 }
 541 
 542 // Return the appropriate reduction node.
 543 ReductionNode* ReductionNode::make(int opc, Node *ctrl, Node* n1, Node* n2, BasicType bt) {
 544 
 545   int vopc = opcode(opc, bt);
 546 
 547   // This method should not be called for unimplemented vectors.
 548   guarantee(vopc != opc, "Vector for '%s' is not implemented", NodeClassNames[opc]);
 549 
 550   switch (vopc) {
 551   case Op_AddReductionVI: return new AddReductionVINode(ctrl, n1, n2);
 552   case Op_AddReductionVL: return new AddReductionVLNode(ctrl, n1, n2);
 553   case Op_AddReductionVF: return new AddReductionVFNode(ctrl, n1, n2);
 554   case Op_AddReductionVD: return new AddReductionVDNode(ctrl, n1, n2);
 555   case Op_MulReductionVI: return new MulReductionVINode(ctrl, n1, n2);
 556   case Op_MulReductionVL: return new MulReductionVLNode(ctrl, n1, n2);
 557   case Op_MulReductionVF: return new MulReductionVFNode(ctrl, n1, n2);
 558   case Op_MulReductionVD: return new MulReductionVDNode(ctrl, n1, n2);
 559   }
 560   fatal("Missed vector creation for '%s'", NodeClassNames[vopc]);
 561   return NULL;

 562 }
 563 
 564 bool ReductionNode::implemented(int opc, uint vlen, BasicType bt) {
 565   if (is_java_primitive(bt) &&
 566       (vlen > 1) && is_power_of_2(vlen) &&
 567       Matcher::vector_size_supported(bt, vlen)) {
 568     int vopc = ReductionNode::opcode(opc, bt);
 569     return vopc != opc && Matcher::match_rule_supported(vopc);
 570   }
 571   return false;
 572 }
 573 
   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/vectornode.hpp"
  28 
  29 //------------------------------VectorNode--------------------------------------
  30 
  31 // Return the vector operator for the specified scalar operation
  32 // and vector length.
  33 int VectorNode::opcode(int sopc, BasicType bt) {
  34   switch (sopc) {
  35   case Op_AddI:
  36     switch (bt) {
  37     case T_BOOLEAN:
  38     case T_BYTE:      return Op_AddVB;
  39     case T_CHAR:
  40     case T_SHORT:     return Op_AddVS;
  41     case T_INT:       return Op_AddVI;
  42     default:          ShouldNotReachHere(); return 0;
  43     }

  44   case Op_AddL:
  45     assert(bt == T_LONG, "must be");
  46     return Op_AddVL;
  47   case Op_AddF:
  48     assert(bt == T_FLOAT, "must be");
  49     return Op_AddVF;
  50   case Op_AddD:
  51     assert(bt == T_DOUBLE, "must be");
  52     return Op_AddVD;
  53   case Op_SubI:
  54     switch (bt) {
  55     case T_BOOLEAN:
  56     case T_BYTE:   return Op_SubVB;
  57     case T_CHAR:
  58     case T_SHORT:  return Op_SubVS;
  59     case T_INT:    return Op_SubVI;
  60     default:       ShouldNotReachHere(); return 0;
  61     }

  62   case Op_SubL:
  63     assert(bt == T_LONG, "must be");
  64     return Op_SubVL;
  65   case Op_SubF:
  66     assert(bt == T_FLOAT, "must be");
  67     return Op_SubVF;
  68   case Op_SubD:
  69     assert(bt == T_DOUBLE, "must be");
  70     return Op_SubVD;
  71   case Op_MulI:
  72     switch (bt) {
  73     case T_BOOLEAN:
  74     case T_BYTE:   return 0;   // Unimplemented
  75     case T_CHAR:
  76     case T_SHORT:  return Op_MulVS;
  77     case T_INT:    return Op_MulVI;
  78     default:       ShouldNotReachHere(); return 0;
  79     }

  80   case Op_MulL:
  81     assert(bt == T_LONG, "must be");
  82     return Op_MulVL;
  83   case Op_MulF:
  84     assert(bt == T_FLOAT, "must be");
  85     return Op_MulVF;
  86   case Op_MulD:
  87     assert(bt == T_DOUBLE, "must be");
  88     return Op_MulVD;
  89   case Op_FmaD:
  90     assert(bt == T_DOUBLE, "must be");
  91     return Op_FmaVD;
  92   case Op_FmaF:
  93     assert(bt == T_FLOAT, "must be");
  94     return Op_FmaVF;
  95   case Op_CMoveD:
  96     assert(bt == T_DOUBLE, "must be");
  97     return Op_CMoveVD;
  98   case Op_DivF:
  99     assert(bt == T_FLOAT, "must be");


 106     return Op_AbsVF;
 107   case Op_AbsD:
 108     assert(bt == T_DOUBLE, "must be");
 109     return Op_AbsVD;
 110   case Op_NegF:
 111     assert(bt == T_FLOAT, "must be");
 112     return Op_NegVF;
 113   case Op_NegD:
 114     assert(bt == T_DOUBLE, "must be");
 115     return Op_NegVD;
 116   case Op_SqrtD:
 117     assert(bt == T_DOUBLE, "must be");
 118     return Op_SqrtVD;
 119   case Op_LShiftI:
 120     switch (bt) {
 121     case T_BOOLEAN:
 122     case T_BYTE:   return Op_LShiftVB;
 123     case T_CHAR:
 124     case T_SHORT:  return Op_LShiftVS;
 125     case T_INT:    return Op_LShiftVI;
 126       default:       ShouldNotReachHere(); return 0;
 127     }

 128   case Op_LShiftL:
 129     assert(bt == T_LONG, "must be");
 130     return Op_LShiftVL;
 131   case Op_RShiftI:
 132     switch (bt) {
 133     case T_BOOLEAN:return Op_URShiftVB; // boolean is unsigned value
 134     case T_CHAR:   return Op_URShiftVS; // char is unsigned value
 135     case T_BYTE:   return Op_RShiftVB;
 136     case T_SHORT:  return Op_RShiftVS;
 137     case T_INT:    return Op_RShiftVI;
 138     default:       ShouldNotReachHere(); return 0;
 139     }

 140   case Op_RShiftL:
 141     assert(bt == T_LONG, "must be");
 142     return Op_RShiftVL;
 143   case Op_URShiftI:
 144     switch (bt) {
 145     case T_BOOLEAN:return Op_URShiftVB;
 146     case T_CHAR:   return Op_URShiftVS;
 147     case T_BYTE:
 148     case T_SHORT:  return 0; // Vector logical right shift for signed short
 149                              // values produces incorrect Java result for
 150                              // negative data because java code should convert
 151                              // a short value into int value with sign
 152                              // extension before a shift.
 153     case T_INT:    return Op_URShiftVI;
 154     default:       ShouldNotReachHere(); return 0;
 155     }

 156   case Op_URShiftL:
 157     assert(bt == T_LONG, "must be");
 158     return Op_URShiftVL;
 159   case Op_AndI:
 160   case Op_AndL:
 161     return Op_AndV;
 162   case Op_OrI:
 163   case Op_OrL:
 164     return Op_OrV;
 165   case Op_XorI:
 166   case Op_XorL:
 167     return Op_XorV;
 168 
 169   case Op_LoadB:
 170   case Op_LoadUB:
 171   case Op_LoadUS:
 172   case Op_LoadS:
 173   case Op_LoadI:
 174   case Op_LoadL:
 175   case Op_LoadF:
 176   case Op_LoadD:
 177     return Op_LoadVector;
 178 
 179   case Op_StoreB:
 180   case Op_StoreC:
 181   case Op_StoreI:
 182   case Op_StoreL:
 183   case Op_StoreF:
 184   case Op_StoreD:
 185     return Op_StoreVector;
 186 
 187   default:
 188     return 0; // Unimplemented
 189   }
 190 }
 191 
 192 // Also used to check if the code generator
 193 // supports the vector operation.
 194 bool VectorNode::implemented(int opc, uint vlen, BasicType bt) {
 195   if (is_java_primitive(bt) &&
 196       (vlen > 1) && is_power_of_2(vlen) &&
 197       Matcher::vector_size_supported(bt, vlen)) {
 198     int vopc = VectorNode::opcode(opc, bt);
 199     return vopc > 0 && Matcher::match_rule_supported_vector(vopc, vlen);
 200   }
 201   return false;
 202 }
 203 
 204 bool VectorNode::is_shift(Node* n) {
 205   switch (n->Opcode()) {
 206   case Op_LShiftI:
 207   case Op_LShiftL:
 208   case Op_RShiftI:
 209   case Op_RShiftL:
 210   case Op_URShiftI:
 211   case Op_URShiftL:
 212     return true;
 213   default:
 214     return false;
 215   }
 216 }
 217 
 218 // Check if input is loop invariant vector.
 219 bool VectorNode::is_invariant_vector(Node* n) {
 220   // Only Replicate vector nodes are loop invariant for now.
 221   switch (n->Opcode()) {
 222   case Op_ReplicateB:
 223   case Op_ReplicateS:
 224   case Op_ReplicateI:
 225   case Op_ReplicateL:
 226   case Op_ReplicateF:
 227   case Op_ReplicateD:
 228     return true;
 229   default:
 230     return false;
 231   }
 232 }
 233 
 234 // [Start, end) half-open range defining which operands are vectors
 235 void VectorNode::vector_operands(Node* n, uint* start, uint* end) {
 236   switch (n->Opcode()) {
 237   case Op_LoadB:   case Op_LoadUB:
 238   case Op_LoadS:   case Op_LoadUS:
 239   case Op_LoadI:   case Op_LoadL:
 240   case Op_LoadF:   case Op_LoadD:
 241   case Op_LoadP:   case Op_LoadN:
 242     *start = 0;
 243     *end   = 0; // no vector operands
 244     break;
 245   case Op_StoreB:  case Op_StoreC:
 246   case Op_StoreI:  case Op_StoreL:
 247   case Op_StoreF:  case Op_StoreD:
 248   case Op_StoreP:  case Op_StoreN:
 249     *start = MemNode::ValueIn;
 250     *end   = MemNode::ValueIn + 1; // 1 vector operand
 251     break;


 320   case Op_SqrtVD: return new SqrtVDNode(n1, vt);
 321 
 322   case Op_LShiftVB: return new LShiftVBNode(n1, n2, vt);
 323   case Op_LShiftVS: return new LShiftVSNode(n1, n2, vt);
 324   case Op_LShiftVI: return new LShiftVINode(n1, n2, vt);
 325   case Op_LShiftVL: return new LShiftVLNode(n1, n2, vt);
 326 
 327   case Op_RShiftVB: return new RShiftVBNode(n1, n2, vt);
 328   case Op_RShiftVS: return new RShiftVSNode(n1, n2, vt);
 329   case Op_RShiftVI: return new RShiftVINode(n1, n2, vt);
 330   case Op_RShiftVL: return new RShiftVLNode(n1, n2, vt);
 331 
 332   case Op_URShiftVB: return new URShiftVBNode(n1, n2, vt);
 333   case Op_URShiftVS: return new URShiftVSNode(n1, n2, vt);
 334   case Op_URShiftVI: return new URShiftVINode(n1, n2, vt);
 335   case Op_URShiftVL: return new URShiftVLNode(n1, n2, vt);
 336 
 337   case Op_AndV: return new AndVNode(n1, n2, vt);
 338   case Op_OrV:  return new OrVNode (n1, n2, vt);
 339   case Op_XorV: return new XorVNode(n1, n2, vt);
 340   default:
 341     fatal("Missed vector creation for '%s'", NodeClassNames[vopc]);
 342     return NULL;
 343   }
 344 }
 345 
 346 VectorNode* VectorNode::make(int opc, Node* n1, Node* n2, Node* n3, uint vlen, BasicType bt) {
 347   const TypeVect* vt = TypeVect::make(bt, vlen);
 348   int vopc = VectorNode::opcode(opc, bt);
 349   // This method should not be called for unimplemented vectors.
 350   guarantee(vopc > 0, "Vector for '%s' is not implemented", NodeClassNames[opc]);
 351   switch (vopc) {
 352   case Op_FmaVD: return new FmaVDNode(n1, n2, n3, vt);
 353   case Op_FmaVF: return new FmaVFNode(n1, n2, n3, vt);
 354   default:
 355     fatal("Missed vector creation for '%s'", NodeClassNames[vopc]);
 356     return NULL;
 357   }
 358 }
 359 
 360 // Scalar promotion
 361 VectorNode* VectorNode::scalar2vector(Node* s, uint vlen, const Type* opd_t) {
 362   BasicType bt = opd_t->array_element_basic_type();
 363   const TypeVect* vt = opd_t->singleton() ? TypeVect::make(opd_t, vlen)
 364                                           : TypeVect::make(bt, vlen);
 365   switch (bt) {
 366   case T_BOOLEAN:
 367   case T_BYTE:
 368     return new ReplicateBNode(s, vt);
 369   case T_CHAR:
 370   case T_SHORT:
 371     return new ReplicateSNode(s, vt);
 372   case T_INT:
 373     return new ReplicateINode(s, vt);
 374   case T_LONG:
 375     return new ReplicateLNode(s, vt);
 376   case T_FLOAT:
 377     return new ReplicateFNode(s, vt);
 378   case T_DOUBLE:
 379     return new ReplicateDNode(s, vt);
 380   default:
 381     fatal("Type '%s' is not supported for vectors", type2name(bt));
 382     return NULL;
 383   }
 384 }
 385 
 386 VectorNode* VectorNode::shift_count(Node* shift, Node* cnt, uint vlen, BasicType bt) {
 387   assert(VectorNode::is_shift(shift) && !cnt->is_Con(), "only variable shift count");
 388   // Match shift count type with shift vector type.
 389   const TypeVect* vt = TypeVect::make(bt, vlen);
 390   switch (shift->Opcode()) {
 391   case Op_LShiftI:
 392   case Op_LShiftL:
 393     return new LShiftCntVNode(cnt, vt);
 394   case Op_RShiftI:
 395   case Op_RShiftL:
 396   case Op_URShiftI:
 397   case Op_URShiftL:
 398     return new RShiftCntVNode(cnt, vt);
 399   default:
 400     fatal("Missed vector creation for '%s'", NodeClassNames[shift->Opcode()]);
 401     return NULL;
 402   }
 403 }
 404 
 405 // Return initial Pack node. Additional operands added with add_opd() calls.
 406 PackNode* PackNode::make(Node* s, uint vlen, BasicType bt) {
 407   const TypeVect* vt = TypeVect::make(bt, vlen);
 408   switch (bt) {
 409   case T_BOOLEAN:
 410   case T_BYTE:
 411     return new PackBNode(s, vt);
 412   case T_CHAR:
 413   case T_SHORT:
 414     return new PackSNode(s, vt);
 415   case T_INT:
 416     return new PackINode(s, vt);
 417   case T_LONG:
 418     return new PackLNode(s, vt);
 419   case T_FLOAT:
 420     return new PackFNode(s, vt);
 421   case T_DOUBLE:
 422     return new PackDNode(s, vt);
 423   default:
 424     fatal("Type '%s' is not supported for vectors", type2name(bt));
 425     return NULL;
 426   }
 427 }
 428 
 429 // Create a binary tree form for Packs. [lo, hi) (half-open) range
 430 PackNode* PackNode::binary_tree_pack(int lo, int hi) {
 431   int ct = hi - lo;
 432   assert(is_power_of_2(ct), "power of 2");
 433   if (ct == 2) {
 434     PackNode* pk = PackNode::make(in(lo), 2, vect_type()->element_basic_type());
 435     pk->add_opd(in(lo+1));
 436     return pk;

 437   } else {
 438     int mid = lo + ct/2;
 439     PackNode* n1 = binary_tree_pack(lo,  mid);
 440     PackNode* n2 = binary_tree_pack(mid, hi );
 441 
 442     BasicType bt = n1->vect_type()->element_basic_type();
 443     assert(bt == n2->vect_type()->element_basic_type(), "should be the same");
 444     switch (bt) {
 445     case T_BOOLEAN:
 446     case T_BYTE:
 447       return new PackSNode(n1, n2, TypeVect::make(T_SHORT, 2));
 448     case T_CHAR:
 449     case T_SHORT:
 450       return new PackINode(n1, n2, TypeVect::make(T_INT, 2));
 451     case T_INT:
 452       return new PackLNode(n1, n2, TypeVect::make(T_LONG, 2));
 453     case T_LONG:
 454       return new Pack2LNode(n1, n2, TypeVect::make(T_LONG, 2));
 455     case T_FLOAT:
 456       return new PackDNode(n1, n2, TypeVect::make(T_DOUBLE, 2));
 457     case T_DOUBLE:
 458       return new Pack2DNode(n1, n2, TypeVect::make(T_DOUBLE, 2));
 459     default:
 460       fatal("Type '%s' is not supported for vectors", type2name(bt));

 461       return NULL;
 462     }
 463   }
 464 }
 465 
 466 // Return the vector version of a scalar load node.
 467 LoadVectorNode* LoadVectorNode::make(int opc, Node* ctl, Node* mem,
 468                                      Node* adr, const TypePtr* atyp,
 469                                      uint vlen, BasicType bt,
 470                                      ControlDependency control_dependency) {
 471   const TypeVect* vt = TypeVect::make(bt, vlen);
 472   return new LoadVectorNode(ctl, mem, adr, atyp, vt, control_dependency);
 473 }
 474 
 475 // Return the vector version of a scalar store node.
 476 StoreVectorNode* StoreVectorNode::make(int opc, Node* ctl, Node* mem,
 477                                        Node* adr, const TypePtr* atyp, Node* val,
 478                                        uint vlen) {
 479   return new StoreVectorNode(ctl, mem, adr, atyp, val);
 480 }
 481 
 482 // Extract a scalar element of vector.
 483 Node* ExtractNode::make(Node* v, uint position, BasicType bt) {
 484   assert((int)position < Matcher::max_vector_size(bt), "pos in range");
 485   ConINode* pos = ConINode::make((int)position);
 486   switch (bt) {
 487   case T_BOOLEAN:
 488     return new ExtractUBNode(v, pos);
 489   case T_BYTE:
 490     return new ExtractBNode(v, pos);
 491   case T_CHAR:
 492     return new ExtractCNode(v, pos);
 493   case T_SHORT:
 494     return new ExtractSNode(v, pos);
 495   case T_INT:
 496     return new ExtractINode(v, pos);
 497   case T_LONG:
 498     return new ExtractLNode(v, pos);
 499   case T_FLOAT:
 500     return new ExtractFNode(v, pos);
 501   case T_DOUBLE:
 502     return new ExtractDNode(v, pos);
 503   default:
 504     fatal("Type '%s' is not supported for vectors", type2name(bt));
 505     return NULL;
 506   }
 507 }
 508 
 509 int ReductionNode::opcode(int opc, BasicType bt) {
 510   int vopc = opc;
 511   switch (opc) {
 512     case Op_AddI:
 513       assert(bt == T_INT, "must be");
 514       vopc = Op_AddReductionVI;
 515       break;
 516     case Op_AddL:
 517       assert(bt == T_LONG, "must be");
 518       vopc = Op_AddReductionVL;
 519       break;
 520     case Op_AddF:
 521       assert(bt == T_FLOAT, "must be");
 522       vopc = Op_AddReductionVF;
 523       break;
 524     case Op_AddD:
 525       assert(bt == T_DOUBLE, "must be");
 526       vopc = Op_AddReductionVD;


 548   return vopc;
 549 }
 550 
 551 // Return the appropriate reduction node.
 552 ReductionNode* ReductionNode::make(int opc, Node *ctrl, Node* n1, Node* n2, BasicType bt) {
 553 
 554   int vopc = opcode(opc, bt);
 555 
 556   // This method should not be called for unimplemented vectors.
 557   guarantee(vopc != opc, "Vector for '%s' is not implemented", NodeClassNames[opc]);
 558 
 559   switch (vopc) {
 560   case Op_AddReductionVI: return new AddReductionVINode(ctrl, n1, n2);
 561   case Op_AddReductionVL: return new AddReductionVLNode(ctrl, n1, n2);
 562   case Op_AddReductionVF: return new AddReductionVFNode(ctrl, n1, n2);
 563   case Op_AddReductionVD: return new AddReductionVDNode(ctrl, n1, n2);
 564   case Op_MulReductionVI: return new MulReductionVINode(ctrl, n1, n2);
 565   case Op_MulReductionVL: return new MulReductionVLNode(ctrl, n1, n2);
 566   case Op_MulReductionVF: return new MulReductionVFNode(ctrl, n1, n2);
 567   case Op_MulReductionVD: return new MulReductionVDNode(ctrl, n1, n2);
 568   default:
 569     fatal("Missed vector creation for '%s'", NodeClassNames[vopc]);
 570     return NULL;
 571   }
 572 }
 573 
 574 bool ReductionNode::implemented(int opc, uint vlen, BasicType bt) {
 575   if (is_java_primitive(bt) &&
 576       (vlen > 1) && is_power_of_2(vlen) &&
 577       Matcher::vector_size_supported(bt, vlen)) {
 578     int vopc = ReductionNode::opcode(opc, bt);
 579     return vopc != opc && Matcher::match_rule_supported(vopc);
 580   }
 581   return false;
 582 }

< prev index next >