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.
opcode(int sopc,BasicType bt)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:return 0;
74 case T_BYTE: return Op_MulVB;
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_CMoveF:
96 assert(bt == T_FLOAT, "must be");
97 return Op_CMoveVF;
98 case Op_CMoveD:
99 assert(bt == T_DOUBLE, "must be");
100 return Op_CMoveVD;
101 case Op_DivF:
102 assert(bt == T_FLOAT, "must be");
103 return Op_DivVF;
104 case Op_DivD:
105 assert(bt == T_DOUBLE, "must be");
106 return Op_DivVD;
107 case Op_AbsI:
108 switch (bt) {
109 case T_BOOLEAN:
110 case T_CHAR: return 0; // abs does not make sense for unsigned
111 case T_BYTE: return Op_AbsVB;
112 case T_SHORT: return Op_AbsVS;
113 case T_INT: return Op_AbsVI;
114 default: ShouldNotReachHere(); return 0;
115 }
116 case Op_AbsL:
117 assert(bt == T_LONG, "must be");
118 return Op_AbsVL;
119 case Op_AbsF:
120 assert(bt == T_FLOAT, "must be");
121 return Op_AbsVF;
122 case Op_AbsD:
123 assert(bt == T_DOUBLE, "must be");
124 return Op_AbsVD;
125 case Op_NegF:
126 assert(bt == T_FLOAT, "must be");
127 return Op_NegVF;
128 case Op_NegD:
129 assert(bt == T_DOUBLE, "must be");
130 return Op_NegVD;
131 case Op_RoundDoubleMode:
132 assert(bt == T_DOUBLE, "must be");
133 return Op_RoundDoubleModeV;
134 case Op_SqrtF:
135 assert(bt == T_FLOAT, "must be");
136 return Op_SqrtVF;
137 case Op_SqrtD:
138 assert(bt == T_DOUBLE, "must be");
139 return Op_SqrtVD;
140 case Op_PopCountI:
141 if (bt == T_INT) {
142 return Op_PopCountVI;
143 }
144 // Unimplemented for subword types since bit count changes
145 // depending on size of lane (and sign bit).
146 return 0;
147 case Op_LShiftI:
148 switch (bt) {
149 case T_BOOLEAN:
150 case T_BYTE: return Op_LShiftVB;
151 case T_CHAR:
152 case T_SHORT: return Op_LShiftVS;
153 case T_INT: return Op_LShiftVI;
154 default: ShouldNotReachHere(); return 0;
155 }
156 case Op_LShiftL:
157 assert(bt == T_LONG, "must be");
158 return Op_LShiftVL;
159 case Op_RShiftI:
160 switch (bt) {
161 case T_BOOLEAN:return Op_URShiftVB; // boolean is unsigned value
162 case T_CHAR: return Op_URShiftVS; // char is unsigned value
163 case T_BYTE: return Op_RShiftVB;
164 case T_SHORT: return Op_RShiftVS;
165 case T_INT: return Op_RShiftVI;
166 default: ShouldNotReachHere(); return 0;
167 }
168 case Op_RShiftL:
169 assert(bt == T_LONG, "must be");
170 return Op_RShiftVL;
171 case Op_URShiftI:
172 switch (bt) {
173 case T_BOOLEAN:return Op_URShiftVB;
174 case T_CHAR: return Op_URShiftVS;
175 case T_BYTE:
176 case T_SHORT: return 0; // Vector logical right shift for signed short
177 // values produces incorrect Java result for
178 // negative data because java code should convert
179 // a short value into int value with sign
180 // extension before a shift.
181 case T_INT: return Op_URShiftVI;
182 default: ShouldNotReachHere(); return 0;
183 }
184 case Op_URShiftL:
185 assert(bt == T_LONG, "must be");
186 return Op_URShiftVL;
187 case Op_AndI:
188 case Op_AndL:
189 return Op_AndV;
190 case Op_OrI:
191 case Op_OrL:
192 return Op_OrV;
193 case Op_XorI:
194 case Op_XorL:
195 return Op_XorV;
196 case Op_MinF:
197 assert(bt == T_FLOAT, "must be");
198 return Op_MinV;
199 case Op_MinD:
200 assert(bt == T_DOUBLE, "must be");
201 return Op_MinV;
202 case Op_MaxF:
203 assert(bt == T_FLOAT, "must be");
204 return Op_MaxV;
205 case Op_MaxD:
206 assert(bt == T_DOUBLE, "must be");
207 return Op_MaxV;
208
209 case Op_LoadB:
210 case Op_LoadUB:
211 case Op_LoadUS:
212 case Op_LoadS:
213 case Op_LoadI:
214 case Op_LoadL:
215 case Op_LoadF:
216 case Op_LoadD:
217 return Op_LoadVector;
218
219 case Op_StoreB:
220 case Op_StoreC:
221 case Op_StoreI:
222 case Op_StoreL:
223 case Op_StoreF:
224 case Op_StoreD:
225 return Op_StoreVector;
226 case Op_MulAddS2I:
227 return Op_MulAddVS2VI;
228
229 default:
230 return 0; // Unimplemented
231 }
232 }
233
234 // Also used to check if the code generator
235 // supports the vector operation.
implemented(int opc,uint vlen,BasicType bt)236 bool VectorNode::implemented(int opc, uint vlen, BasicType bt) {
237 if (is_java_primitive(bt) &&
238 (vlen > 1) && is_power_of_2(vlen) &&
239 Matcher::vector_size_supported(bt, vlen)) {
240 int vopc = VectorNode::opcode(opc, bt);
241 return vopc > 0 && Matcher::match_rule_supported_vector(vopc, vlen);
242 }
243 return false;
244 }
245
is_type_transition_short_to_int(Node * n)246 bool VectorNode::is_type_transition_short_to_int(Node* n) {
247 switch (n->Opcode()) {
248 case Op_MulAddS2I:
249 return true;
250 }
251 return false;
252 }
253
is_type_transition_to_int(Node * n)254 bool VectorNode::is_type_transition_to_int(Node* n) {
255 return is_type_transition_short_to_int(n);
256 }
257
is_muladds2i(Node * n)258 bool VectorNode::is_muladds2i(Node* n) {
259 if (n->Opcode() == Op_MulAddS2I) {
260 return true;
261 }
262 return false;
263 }
264
is_roundopD(Node * n)265 bool VectorNode::is_roundopD(Node *n) {
266 if (n->Opcode() == Op_RoundDoubleMode) {
267 return true;
268 }
269 return false;
270 }
271
is_shift(Node * n)272 bool VectorNode::is_shift(Node* n) {
273 switch (n->Opcode()) {
274 case Op_LShiftI:
275 case Op_LShiftL:
276 case Op_RShiftI:
277 case Op_RShiftL:
278 case Op_URShiftI:
279 case Op_URShiftL:
280 return true;
281 default:
282 return false;
283 }
284 }
285
286 // Check if input is loop invariant vector.
is_invariant_vector(Node * n)287 bool VectorNode::is_invariant_vector(Node* n) {
288 // Only Replicate vector nodes are loop invariant for now.
289 switch (n->Opcode()) {
290 case Op_ReplicateB:
291 case Op_ReplicateS:
292 case Op_ReplicateI:
293 case Op_ReplicateL:
294 case Op_ReplicateF:
295 case Op_ReplicateD:
296 return true;
297 default:
298 return false;
299 }
300 }
301
302 // [Start, end) half-open range defining which operands are vectors
vector_operands(Node * n,uint * start,uint * end)303 void VectorNode::vector_operands(Node* n, uint* start, uint* end) {
304 switch (n->Opcode()) {
305 case Op_LoadB: case Op_LoadUB:
306 case Op_LoadS: case Op_LoadUS:
307 case Op_LoadI: case Op_LoadL:
308 case Op_LoadF: case Op_LoadD:
309 case Op_LoadP: case Op_LoadN:
310 *start = 0;
311 *end = 0; // no vector operands
312 break;
313 case Op_StoreB: case Op_StoreC:
314 case Op_StoreI: case Op_StoreL:
315 case Op_StoreF: case Op_StoreD:
316 case Op_StoreP: case Op_StoreN:
317 *start = MemNode::ValueIn;
318 *end = MemNode::ValueIn + 1; // 1 vector operand
319 break;
320 case Op_LShiftI: case Op_LShiftL:
321 case Op_RShiftI: case Op_RShiftL:
322 case Op_URShiftI: case Op_URShiftL:
323 *start = 1;
324 *end = 2; // 1 vector operand
325 break;
326 case Op_AddI: case Op_AddL: case Op_AddF: case Op_AddD:
327 case Op_SubI: case Op_SubL: case Op_SubF: case Op_SubD:
328 case Op_MulI: case Op_MulL: case Op_MulF: case Op_MulD:
329 case Op_DivF: case Op_DivD:
330 case Op_AndI: case Op_AndL:
331 case Op_OrI: case Op_OrL:
332 case Op_XorI: case Op_XorL:
333 case Op_MulAddS2I:
334 *start = 1;
335 *end = 3; // 2 vector operands
336 break;
337 case Op_CMoveI: case Op_CMoveL: case Op_CMoveF: case Op_CMoveD:
338 *start = 2;
339 *end = n->req();
340 break;
341 case Op_FmaD:
342 case Op_FmaF:
343 *start = 1;
344 *end = 4; // 3 vector operands
345 break;
346 default:
347 *start = 1;
348 *end = n->req(); // default is all operands
349 }
350 }
351
352 // Return the vector version of a scalar operation node.
make(int opc,Node * n1,Node * n2,uint vlen,BasicType bt)353 VectorNode* VectorNode::make(int opc, Node* n1, Node* n2, uint vlen, BasicType bt) {
354 const TypeVect* vt = TypeVect::make(bt, vlen);
355 int vopc = VectorNode::opcode(opc, bt);
356 // This method should not be called for unimplemented vectors.
357 guarantee(vopc > 0, "Vector for '%s' is not implemented", NodeClassNames[opc]);
358 switch (vopc) {
359 case Op_AddVB: return new AddVBNode(n1, n2, vt);
360 case Op_AddVS: return new AddVSNode(n1, n2, vt);
361 case Op_AddVI: return new AddVINode(n1, n2, vt);
362 case Op_AddVL: return new AddVLNode(n1, n2, vt);
363 case Op_AddVF: return new AddVFNode(n1, n2, vt);
364 case Op_AddVD: return new AddVDNode(n1, n2, vt);
365
366 case Op_SubVB: return new SubVBNode(n1, n2, vt);
367 case Op_SubVS: return new SubVSNode(n1, n2, vt);
368 case Op_SubVI: return new SubVINode(n1, n2, vt);
369 case Op_SubVL: return new SubVLNode(n1, n2, vt);
370 case Op_SubVF: return new SubVFNode(n1, n2, vt);
371 case Op_SubVD: return new SubVDNode(n1, n2, vt);
372
373 case Op_MulVB: return new MulVBNode(n1, n2, vt);
374 case Op_MulVS: return new MulVSNode(n1, n2, vt);
375 case Op_MulVI: return new MulVINode(n1, n2, vt);
376 case Op_MulVL: return new MulVLNode(n1, n2, vt);
377 case Op_MulVF: return new MulVFNode(n1, n2, vt);
378 case Op_MulVD: return new MulVDNode(n1, n2, vt);
379
380 case Op_DivVF: return new DivVFNode(n1, n2, vt);
381 case Op_DivVD: return new DivVDNode(n1, n2, vt);
382
383 case Op_AbsVB: return new AbsVBNode(n1, vt);
384 case Op_AbsVS: return new AbsVSNode(n1, vt);
385 case Op_AbsVI: return new AbsVINode(n1, vt);
386 case Op_AbsVL: return new AbsVLNode(n1, vt);
387 case Op_AbsVF: return new AbsVFNode(n1, vt);
388 case Op_AbsVD: return new AbsVDNode(n1, vt);
389
390 case Op_NegVF: return new NegVFNode(n1, vt);
391 case Op_NegVD: return new NegVDNode(n1, vt);
392
393 case Op_SqrtVF: return new SqrtVFNode(n1, vt);
394 case Op_SqrtVD: return new SqrtVDNode(n1, vt);
395
396 case Op_PopCountVI: return new PopCountVINode(n1, vt);
397
398 case Op_LShiftVB: return new LShiftVBNode(n1, n2, vt);
399 case Op_LShiftVS: return new LShiftVSNode(n1, n2, vt);
400 case Op_LShiftVI: return new LShiftVINode(n1, n2, vt);
401 case Op_LShiftVL: return new LShiftVLNode(n1, n2, vt);
402
403 case Op_RShiftVB: return new RShiftVBNode(n1, n2, vt);
404 case Op_RShiftVS: return new RShiftVSNode(n1, n2, vt);
405 case Op_RShiftVI: return new RShiftVINode(n1, n2, vt);
406 case Op_RShiftVL: return new RShiftVLNode(n1, n2, vt);
407
408 case Op_URShiftVB: return new URShiftVBNode(n1, n2, vt);
409 case Op_URShiftVS: return new URShiftVSNode(n1, n2, vt);
410 case Op_URShiftVI: return new URShiftVINode(n1, n2, vt);
411 case Op_URShiftVL: return new URShiftVLNode(n1, n2, vt);
412
413 case Op_AndV: return new AndVNode(n1, n2, vt);
414 case Op_OrV: return new OrVNode (n1, n2, vt);
415 case Op_XorV: return new XorVNode(n1, n2, vt);
416
417 case Op_MinV: return new MinVNode(n1, n2, vt);
418 case Op_MaxV: return new MaxVNode(n1, n2, vt);
419
420 case Op_RoundDoubleModeV: return new RoundDoubleModeVNode(n1, n2, vt);
421
422 case Op_MulAddVS2VI: return new MulAddVS2VINode(n1, n2, vt);
423 default:
424 fatal("Missed vector creation for '%s'", NodeClassNames[vopc]);
425 return NULL;
426 }
427 }
428
make(int opc,Node * n1,Node * n2,Node * n3,uint vlen,BasicType bt)429 VectorNode* VectorNode::make(int opc, Node* n1, Node* n2, Node* n3, uint vlen, BasicType bt) {
430 const TypeVect* vt = TypeVect::make(bt, vlen);
431 int vopc = VectorNode::opcode(opc, bt);
432 // This method should not be called for unimplemented vectors.
433 guarantee(vopc > 0, "Vector for '%s' is not implemented", NodeClassNames[opc]);
434 switch (vopc) {
435 case Op_FmaVD: return new FmaVDNode(n1, n2, n3, vt);
436 case Op_FmaVF: return new FmaVFNode(n1, n2, n3, vt);
437 default:
438 fatal("Missed vector creation for '%s'", NodeClassNames[vopc]);
439 return NULL;
440 }
441 }
442
443 // Scalar promotion
scalar2vector(Node * s,uint vlen,const Type * opd_t)444 VectorNode* VectorNode::scalar2vector(Node* s, uint vlen, const Type* opd_t) {
445 BasicType bt = opd_t->array_element_basic_type();
446 const TypeVect* vt = opd_t->singleton() ? TypeVect::make(opd_t, vlen)
447 : TypeVect::make(bt, vlen);
448 switch (bt) {
449 case T_BOOLEAN:
450 case T_BYTE:
451 return new ReplicateBNode(s, vt);
452 case T_CHAR:
453 case T_SHORT:
454 return new ReplicateSNode(s, vt);
455 case T_INT:
456 return new ReplicateINode(s, vt);
457 case T_LONG:
458 return new ReplicateLNode(s, vt);
459 case T_FLOAT:
460 return new ReplicateFNode(s, vt);
461 case T_DOUBLE:
462 return new ReplicateDNode(s, vt);
463 default:
464 fatal("Type '%s' is not supported for vectors", type2name(bt));
465 return NULL;
466 }
467 }
468
shift_count(Node * shift,Node * cnt,uint vlen,BasicType bt)469 VectorNode* VectorNode::shift_count(Node* shift, Node* cnt, uint vlen, BasicType bt) {
470 assert(VectorNode::is_shift(shift) && !cnt->is_Con(), "only variable shift count");
471 // Match shift count type with shift vector type.
472 const TypeVect* vt = TypeVect::make(bt, vlen);
473 switch (shift->Opcode()) {
474 case Op_LShiftI:
475 case Op_LShiftL:
476 return new LShiftCntVNode(cnt, vt);
477 case Op_RShiftI:
478 case Op_RShiftL:
479 case Op_URShiftI:
480 case Op_URShiftL:
481 return new RShiftCntVNode(cnt, vt);
482 default:
483 fatal("Missed vector creation for '%s'", NodeClassNames[shift->Opcode()]);
484 return NULL;
485 }
486 }
487
488 // Return initial Pack node. Additional operands added with add_opd() calls.
make(Node * s,uint vlen,BasicType bt)489 PackNode* PackNode::make(Node* s, uint vlen, BasicType bt) {
490 const TypeVect* vt = TypeVect::make(bt, vlen);
491 switch (bt) {
492 case T_BOOLEAN:
493 case T_BYTE:
494 return new PackBNode(s, vt);
495 case T_CHAR:
496 case T_SHORT:
497 return new PackSNode(s, vt);
498 case T_INT:
499 return new PackINode(s, vt);
500 case T_LONG:
501 return new PackLNode(s, vt);
502 case T_FLOAT:
503 return new PackFNode(s, vt);
504 case T_DOUBLE:
505 return new PackDNode(s, vt);
506 default:
507 fatal("Type '%s' is not supported for vectors", type2name(bt));
508 return NULL;
509 }
510 }
511
512 // Create a binary tree form for Packs. [lo, hi) (half-open) range
binary_tree_pack(int lo,int hi)513 PackNode* PackNode::binary_tree_pack(int lo, int hi) {
514 int ct = hi - lo;
515 assert(is_power_of_2(ct), "power of 2");
516 if (ct == 2) {
517 PackNode* pk = PackNode::make(in(lo), 2, vect_type()->element_basic_type());
518 pk->add_opd(in(lo+1));
519 return pk;
520 } else {
521 int mid = lo + ct/2;
522 PackNode* n1 = binary_tree_pack(lo, mid);
523 PackNode* n2 = binary_tree_pack(mid, hi );
524
525 BasicType bt = n1->vect_type()->element_basic_type();
526 assert(bt == n2->vect_type()->element_basic_type(), "should be the same");
527 switch (bt) {
528 case T_BOOLEAN:
529 case T_BYTE:
530 return new PackSNode(n1, n2, TypeVect::make(T_SHORT, 2));
531 case T_CHAR:
532 case T_SHORT:
533 return new PackINode(n1, n2, TypeVect::make(T_INT, 2));
534 case T_INT:
535 return new PackLNode(n1, n2, TypeVect::make(T_LONG, 2));
536 case T_LONG:
537 return new Pack2LNode(n1, n2, TypeVect::make(T_LONG, 2));
538 case T_FLOAT:
539 return new PackDNode(n1, n2, TypeVect::make(T_DOUBLE, 2));
540 case T_DOUBLE:
541 return new Pack2DNode(n1, n2, TypeVect::make(T_DOUBLE, 2));
542 default:
543 fatal("Type '%s' is not supported for vectors", type2name(bt));
544 return NULL;
545 }
546 }
547 }
548
549 // Return the vector version of a scalar load node.
make(int opc,Node * ctl,Node * mem,Node * adr,const TypePtr * atyp,uint vlen,BasicType bt,ControlDependency control_dependency)550 LoadVectorNode* LoadVectorNode::make(int opc, Node* ctl, Node* mem,
551 Node* adr, const TypePtr* atyp,
552 uint vlen, BasicType bt,
553 ControlDependency control_dependency) {
554 const TypeVect* vt = TypeVect::make(bt, vlen);
555 return new LoadVectorNode(ctl, mem, adr, atyp, vt, control_dependency);
556 }
557
558 // Return the vector version of a scalar store node.
make(int opc,Node * ctl,Node * mem,Node * adr,const TypePtr * atyp,Node * val,uint vlen)559 StoreVectorNode* StoreVectorNode::make(int opc, Node* ctl, Node* mem,
560 Node* adr, const TypePtr* atyp, Node* val,
561 uint vlen) {
562 return new StoreVectorNode(ctl, mem, adr, atyp, val);
563 }
564
565 // Extract a scalar element of vector.
make(Node * v,uint position,BasicType bt)566 Node* ExtractNode::make(Node* v, uint position, BasicType bt) {
567 assert((int)position < Matcher::max_vector_size(bt), "pos in range");
568 ConINode* pos = ConINode::make((int)position);
569 switch (bt) {
570 case T_BOOLEAN:
571 return new ExtractUBNode(v, pos);
572 case T_BYTE:
573 return new ExtractBNode(v, pos);
574 case T_CHAR:
575 return new ExtractCNode(v, pos);
576 case T_SHORT:
577 return new ExtractSNode(v, pos);
578 case T_INT:
579 return new ExtractINode(v, pos);
580 case T_LONG:
581 return new ExtractLNode(v, pos);
582 case T_FLOAT:
583 return new ExtractFNode(v, pos);
584 case T_DOUBLE:
585 return new ExtractDNode(v, pos);
586 default:
587 fatal("Type '%s' is not supported for vectors", type2name(bt));
588 return NULL;
589 }
590 }
591
opcode(int opc,BasicType bt)592 int ReductionNode::opcode(int opc, BasicType bt) {
593 int vopc = opc;
594 switch (opc) {
595 case Op_AddI:
596 assert(bt == T_INT, "must be");
597 vopc = Op_AddReductionVI;
598 break;
599 case Op_AddL:
600 assert(bt == T_LONG, "must be");
601 vopc = Op_AddReductionVL;
602 break;
603 case Op_AddF:
604 assert(bt == T_FLOAT, "must be");
605 vopc = Op_AddReductionVF;
606 break;
607 case Op_AddD:
608 assert(bt == T_DOUBLE, "must be");
609 vopc = Op_AddReductionVD;
610 break;
611 case Op_MulI:
612 assert(bt == T_INT, "must be");
613 vopc = Op_MulReductionVI;
614 break;
615 case Op_MulL:
616 assert(bt == T_LONG, "must be");
617 vopc = Op_MulReductionVL;
618 break;
619 case Op_MulF:
620 assert(bt == T_FLOAT, "must be");
621 vopc = Op_MulReductionVF;
622 break;
623 case Op_MulD:
624 assert(bt == T_DOUBLE, "must be");
625 vopc = Op_MulReductionVD;
626 break;
627 case Op_MinF:
628 assert(bt == T_FLOAT, "must be");
629 vopc = Op_MinReductionV;
630 break;
631 case Op_MinD:
632 assert(bt == T_DOUBLE, "must be");
633 vopc = Op_MinReductionV;
634 break;
635 case Op_MaxF:
636 assert(bt == T_FLOAT, "must be");
637 vopc = Op_MaxReductionV;
638 break;
639 case Op_MaxD:
640 assert(bt == T_DOUBLE, "must be");
641 vopc = Op_MaxReductionV;
642 break;
643 // TODO: add MulL for targets that support it
644 default:
645 break;
646 }
647 return vopc;
648 }
649
650 // Return the appropriate reduction node.
make(int opc,Node * ctrl,Node * n1,Node * n2,BasicType bt)651 ReductionNode* ReductionNode::make(int opc, Node *ctrl, Node* n1, Node* n2, BasicType bt) {
652
653 int vopc = opcode(opc, bt);
654
655 // This method should not be called for unimplemented vectors.
656 guarantee(vopc != opc, "Vector for '%s' is not implemented", NodeClassNames[opc]);
657
658 switch (vopc) {
659 case Op_AddReductionVI: return new AddReductionVINode(ctrl, n1, n2);
660 case Op_AddReductionVL: return new AddReductionVLNode(ctrl, n1, n2);
661 case Op_AddReductionVF: return new AddReductionVFNode(ctrl, n1, n2);
662 case Op_AddReductionVD: return new AddReductionVDNode(ctrl, n1, n2);
663 case Op_MulReductionVI: return new MulReductionVINode(ctrl, n1, n2);
664 case Op_MulReductionVL: return new MulReductionVLNode(ctrl, n1, n2);
665 case Op_MulReductionVF: return new MulReductionVFNode(ctrl, n1, n2);
666 case Op_MulReductionVD: return new MulReductionVDNode(ctrl, n1, n2);
667 case Op_MinReductionV: return new MinReductionVNode(ctrl, n1, n2);
668 case Op_MaxReductionV: return new MaxReductionVNode(ctrl, n1, n2);
669 default:
670 fatal("Missed vector creation for '%s'", NodeClassNames[vopc]);
671 return NULL;
672 }
673 }
674
implemented(int opc,uint vlen,BasicType bt)675 bool ReductionNode::implemented(int opc, uint vlen, BasicType bt) {
676 if (is_java_primitive(bt) &&
677 (vlen > 1) && is_power_of_2(vlen) &&
678 Matcher::vector_size_supported(bt, vlen)) {
679 int vopc = ReductionNode::opcode(opc, bt);
680 return vopc != opc && Matcher::match_rule_supported(vopc);
681 }
682 return false;
683 }
684