1 /*
  2  * Copyright (c) 1997, 2021, 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 
 25 #ifndef SHARE_OPTO_MULNODE_HPP
 26 #define SHARE_OPTO_MULNODE_HPP
 27 
 28 #include "opto/node.hpp"
 29 #include "opto/opcodes.hpp"
 30 #include "opto/type.hpp"
 31 
 32 // Portions of code courtesy of Clifford Click
 33 
 34 class PhaseTransform;
 35 
 36 //------------------------------MulNode----------------------------------------
 37 // Classic MULTIPLY functionality.  This covers all the usual 'multiply'
 38 // behaviors for an algebraic ring.  Multiply-integer, multiply-float,
 39 // multiply-double, and binary-and are all inherited from this class.  The
 40 // various identity values are supplied by virtual functions.
 41 class MulNode : public Node {
 42   virtual uint hash() const;
 43 public:
 44   MulNode(Node *in1, Node *in2): Node(NULL,in1,in2) {
 45     init_class_id(Class_Mul);
 46   }
 47 
 48   // Handle algebraic identities here.  If we have an identity, return the Node
 49   // we are equivalent to.  We look for "add of zero" as an identity.
 50   virtual Node* Identity(PhaseGVN* phase);
 51 
 52   // We also canonicalize the Node, moving constants to the right input,
 53   // and flatten expressions (so that 1+x+2 becomes x+3).
 54   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
 55 
 56   // Compute a new Type for this node.  Basically we just do the pre-check,
 57   // then call the virtual add() to set the type.
 58   virtual const Type* Value(PhaseGVN* phase) const;
 59 
 60   // Supplied function returns the product of the inputs.
 61   // This also type-checks the inputs for sanity.  Guaranteed never to
 62   // be passed a TOP or BOTTOM type, these are filtered out by a pre-check.
 63   // This call recognizes the multiplicative zero type.
 64   virtual const Type *mul_ring( const Type *, const Type * ) const = 0;
 65 
 66   // Supplied function to return the multiplicative identity type
 67   virtual const Type *mul_id() const = 0;
 68 
 69   // Supplied function to return the additive identity type
 70   virtual const Type *add_id() const = 0;
 71 
 72   // Supplied function to return the additive opcode
 73   virtual int add_opcode() const = 0;
 74 
 75   // Supplied function to return the multiplicative opcode
 76   virtual int mul_opcode() const = 0;
 77 
 78   // Supplied function to return the additive opcode
 79   virtual int max_opcode() const = 0;
 80 
 81   // Supplied function to return the multiplicative opcode
 82   virtual int min_opcode() const = 0;
 83 
 84   static MulNode* make(Node* in1, Node* in2, BasicType bt);
 85 
 86   static bool AndIL_shift_and_mask_is_always_zero(PhaseGVN* phase, Node* shift, Node* mask, BasicType bt, bool check_reverse);
 87   Node* AndIL_add_shift_and_mask(PhaseGVN* phase, BasicType bt);
 88 };
 89 
 90 //------------------------------MulINode---------------------------------------
 91 // Multiply 2 integers
 92 class MulINode : public MulNode {
 93 public:
 94   MulINode( Node *in1, Node *in2 ) : MulNode(in1,in2) {}
 95   virtual int Opcode() const;
 96   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
 97   virtual const Type *mul_ring( const Type *, const Type * ) const;
 98   const Type *mul_id() const { return TypeInt::ONE; }
 99   const Type *add_id() const { return TypeInt::ZERO; }
100   int add_opcode() const { return Op_AddI; }
101   int mul_opcode() const { return Op_MulI; }
102   int max_opcode() const { return Op_MaxI; }
103   int min_opcode() const { return Op_MinI; }
104   const Type *bottom_type() const { return TypeInt::INT; }
105   virtual uint ideal_reg() const { return Op_RegI; }
106 };
107 
108 //------------------------------MulLNode---------------------------------------
109 // Multiply 2 longs
110 class MulLNode : public MulNode {
111 public:
112   MulLNode( Node *in1, Node *in2 ) : MulNode(in1,in2) {}
113   virtual int Opcode() const;
114   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
115   virtual const Type *mul_ring( const Type *, const Type * ) const;
116   const Type *mul_id() const { return TypeLong::ONE; }
117   const Type *add_id() const { return TypeLong::ZERO; }
118   int add_opcode() const { return Op_AddL; }
119   int mul_opcode() const { return Op_MulL; }
120   int max_opcode() const { return Op_MaxL; }
121   int min_opcode() const { return Op_MinL; }
122   const Type *bottom_type() const { return TypeLong::LONG; }
123   virtual uint ideal_reg() const { return Op_RegL; }
124 };
125 
126 
127 //------------------------------MulFNode---------------------------------------
128 // Multiply 2 floats
129 class MulFNode : public MulNode {
130 public:
131   MulFNode( Node *in1, Node *in2 ) : MulNode(in1,in2) {}
132   virtual int Opcode() const;
133   virtual const Type *mul_ring( const Type *, const Type * ) const;
134   const Type *mul_id() const { return TypeF::ONE; }
135   const Type *add_id() const { return TypeF::ZERO; }
136   int add_opcode() const { return Op_AddF; }
137   int mul_opcode() const { return Op_MulF; }
138   int max_opcode() const { return Op_MaxF; }
139   int min_opcode() const { return Op_MinF; }
140   const Type *bottom_type() const { return Type::FLOAT; }
141   virtual uint ideal_reg() const { return Op_RegF; }
142 };
143 
144 //------------------------------MulDNode---------------------------------------
145 // Multiply 2 doubles
146 class MulDNode : public MulNode {
147 public:
148   MulDNode( Node *in1, Node *in2 ) : MulNode(in1,in2) {}
149   virtual int Opcode() const;
150   virtual const Type *mul_ring( const Type *, const Type * ) const;
151   const Type *mul_id() const { return TypeD::ONE; }
152   const Type *add_id() const { return TypeD::ZERO; }
153   int add_opcode() const { return Op_AddD; }
154   int mul_opcode() const { return Op_MulD; }
155   int max_opcode() const { return Op_MaxD; }
156   int min_opcode() const { return Op_MinD; }
157   const Type *bottom_type() const { return Type::DOUBLE; }
158   virtual uint ideal_reg() const { return Op_RegD; }
159 };
160 
161 //-------------------------------MulHiLNode------------------------------------
162 const Type* MulHiValue(const Type *t1, const Type *t2, const Type *bot);
163 
164 // Upper 64 bits of a 64 bit by 64 bit multiply
165 class MulHiLNode : public Node {
166 public:
167   MulHiLNode( Node *in1, Node *in2 ) : Node(0,in1,in2) {}
168   virtual int Opcode() const;
169   virtual const Type* Value(PhaseGVN* phase) const;
170   const Type *bottom_type() const { return TypeLong::LONG; }
171   virtual uint ideal_reg() const { return Op_RegL; }
172   friend const Type* MulHiValue(const Type *t1, const Type *t2, const Type *bot);
173 };
174 
175 // Upper 64 bits of a 64 bit by 64 bit unsigned multiply
176 class UMulHiLNode : public Node {
177 public:
178   UMulHiLNode( Node *in1, Node *in2 ) : Node(0,in1,in2) {}
179   virtual int Opcode() const;
180   virtual const Type* Value(PhaseGVN* phase) const;
181   const Type *bottom_type() const { return TypeLong::LONG; }
182   virtual uint ideal_reg() const { return Op_RegL; }
183   friend const Type* MulHiValue(const Type *t1, const Type *t2, const Type *bot);
184 };
185 
186 //------------------------------AndINode---------------------------------------
187 // Logically AND 2 integers.  Included with the MUL nodes because it inherits
188 // all the behavior of multiplication on a ring.
189 class AndINode : public MulINode {
190 public:
191   AndINode( Node *in1, Node *in2 ) : MulINode(in1,in2) {}
192   virtual int Opcode() const;
193   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
194   virtual Node* Identity(PhaseGVN* phase);
195   virtual const Type* Value(PhaseGVN* phase) const;
196   virtual const Type *mul_ring( const Type *, const Type * ) const;
197   const Type *mul_id() const { return TypeInt::MINUS_1; }
198   const Type *add_id() const { return TypeInt::ZERO; }
199   int add_opcode() const { return Op_OrI; }
200   int mul_opcode() const { return Op_AndI; }
201   int max_opcode() const { return Op_MaxI; }
202   int min_opcode() const { return Op_MinI; }
203   virtual uint ideal_reg() const { return Op_RegI; }
204 };
205 
206 //------------------------------AndINode---------------------------------------
207 // Logically AND 2 longs.  Included with the MUL nodes because it inherits
208 // all the behavior of multiplication on a ring.
209 class AndLNode : public MulLNode {
210 public:
211   AndLNode( Node *in1, Node *in2 ) : MulLNode(in1,in2) {}
212   virtual int Opcode() const;
213   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
214   virtual Node* Identity(PhaseGVN* phase);
215   virtual const Type* Value(PhaseGVN* phase) const;
216   virtual const Type *mul_ring( const Type *, const Type * ) const;
217   const Type *mul_id() const { return TypeLong::MINUS_1; }
218   const Type *add_id() const { return TypeLong::ZERO; }
219   int add_opcode() const { return Op_OrL; }
220   int mul_opcode() const { return Op_AndL; }
221   int max_opcode() const { return Op_MaxL; }
222   int min_opcode() const { return Op_MinL; }
223   virtual uint ideal_reg() const { return Op_RegL; }
224 };
225 
226 class LShiftNode : public Node {
227 public:
228   LShiftNode(Node *in1, Node *in2) : Node(NULL,in1,in2) {
229     init_class_id(Class_LShift);
230   }
231 
232   static LShiftNode* make(Node* in1, Node* in2, BasicType bt);
233 };
234 
235 //------------------------------LShiftINode------------------------------------
236 // Logical shift left
237 class LShiftINode : public LShiftNode {
238 public:
239   LShiftINode(Node *in1, Node *in2) : LShiftNode(in1,in2) {}
240   virtual int Opcode() const;
241   virtual Node* Identity(PhaseGVN* phase);
242   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
243   virtual const Type* Value(PhaseGVN* phase) const;
244   const Type *bottom_type() const { return TypeInt::INT; }
245   virtual uint ideal_reg() const { return Op_RegI; }
246 };
247 
248 //------------------------------LShiftLNode------------------------------------
249 // Logical shift left
250 class LShiftLNode : public LShiftNode {
251 public:
252   LShiftLNode(Node *in1, Node *in2) : LShiftNode(in1,in2) {}
253   virtual int Opcode() const;
254   virtual Node* Identity(PhaseGVN* phase);
255   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
256   virtual const Type* Value(PhaseGVN* phase) const;
257   const Type *bottom_type() const { return TypeLong::LONG; }
258   virtual uint ideal_reg() const { return Op_RegL; }
259 };
260 
261 
262 //------------------------ RotateLeftNode ----------------------------------
263 class RotateLeftNode : public TypeNode {
264   public:
265   RotateLeftNode(Node* in1, Node* in2, const Type* type) : TypeNode(type, 3) {
266     init_req(1, in1);
267     init_req(2, in2);
268   }
269   virtual int Opcode() const;
270   virtual Node* Identity(PhaseGVN* phase);
271   virtual const Type* Value(PhaseGVN* phase) const;
272   virtual Node* Ideal(PhaseGVN* phase, bool can_reshape);
273 };
274 
275 //----------------------- RotateRightNode ----------------------------------
276 class RotateRightNode : public TypeNode {
277   public:
278   RotateRightNode(Node* in1, Node* in2, const Type* type) : TypeNode(type, 3) {
279     init_req(1, in1);
280     init_req(2, in2);
281   }
282   virtual int Opcode() const;
283   virtual Node* Identity(PhaseGVN* phase);
284   virtual const Type* Value(PhaseGVN* phase) const;
285 };
286 
287 //------------------------------RShiftINode------------------------------------
288 // Signed shift right
289 class RShiftINode : public Node {
290 public:
291   RShiftINode( Node *in1, Node *in2 ) : Node(0,in1,in2) {}
292   virtual int Opcode() const;
293   virtual Node* Identity(PhaseGVN* phase);
294   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
295   virtual const Type* Value(PhaseGVN* phase) const;
296   const Type *bottom_type() const { return TypeInt::INT; }
297   virtual uint ideal_reg() const { return Op_RegI; }
298 };
299 
300 //------------------------------RShiftLNode------------------------------------
301 // Signed shift right
302 class RShiftLNode : public Node {
303 public:
304   RShiftLNode( Node *in1, Node *in2 ) : Node(0,in1,in2) {}
305   virtual int Opcode() const;
306   virtual Node* Identity(PhaseGVN* phase);
307   virtual const Type* Value(PhaseGVN* phase) const;
308   const Type *bottom_type() const { return TypeLong::LONG; }
309   virtual uint ideal_reg() const { return Op_RegL; }
310 };
311 
312 //------------------------------URShiftBNode-----------------------------------
313 // Logical shift right
314 class URShiftBNode : public Node {
315 public:
316   URShiftBNode( Node *in1, Node *in2 ) : Node(0,in1,in2) {
317     ShouldNotReachHere(); // only vector variant is used
318   }
319   virtual int Opcode() const;
320 };
321 
322 //------------------------------URShiftSNode-----------------------------------
323 // Logical shift right
324 class URShiftSNode : public Node {
325 public:
326   URShiftSNode( Node *in1, Node *in2 ) : Node(0,in1,in2) {
327     ShouldNotReachHere(); // only vector variant is used
328   }
329   virtual int Opcode() const;
330 };
331 
332 //------------------------------URShiftINode-----------------------------------
333 // Logical shift right
334 class URShiftINode : public Node {
335 public:
336   URShiftINode( Node *in1, Node *in2 ) : Node(0,in1,in2) {}
337   virtual int Opcode() const;
338   virtual Node* Identity(PhaseGVN* phase);
339   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
340   virtual const Type* Value(PhaseGVN* phase) const;
341   const Type *bottom_type() const { return TypeInt::INT; }
342   virtual uint ideal_reg() const { return Op_RegI; }
343 };
344 
345 //------------------------------URShiftLNode-----------------------------------
346 // Logical shift right
347 class URShiftLNode : public Node {
348 public:
349   URShiftLNode( Node *in1, Node *in2 ) : Node(0,in1,in2) {}
350   virtual int Opcode() const;
351   virtual Node* Identity(PhaseGVN* phase);
352   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
353   virtual const Type* Value(PhaseGVN* phase) const;
354   const Type *bottom_type() const { return TypeLong::LONG; }
355   virtual uint ideal_reg() const { return Op_RegL; }
356 };
357 
358 //------------------------------FmaDNode--------------------------------------
359 // fused-multiply-add double
360 class FmaDNode : public Node {
361 public:
362   FmaDNode(Node *c, Node *in1, Node *in2, Node *in3) : Node(c, in1, in2, in3) {}
363   virtual int Opcode() const;
364   const Type *bottom_type() const { return Type::DOUBLE; }
365   virtual uint ideal_reg() const { return Op_RegD; }
366   virtual const Type* Value(PhaseGVN* phase) const;
367 };
368 
369 //------------------------------FmaFNode--------------------------------------
370 // fused-multiply-add float
371 class FmaFNode : public Node {
372 public:
373   FmaFNode(Node *c, Node *in1, Node *in2, Node *in3) : Node(c, in1, in2, in3) {}
374   virtual int Opcode() const;
375   const Type *bottom_type() const { return Type::FLOAT; }
376   virtual uint ideal_reg() const { return Op_RegF; }
377   virtual const Type* Value(PhaseGVN* phase) const;
378 };
379 
380 //------------------------------MulAddS2INode----------------------------------
381 // Multiply shorts into integers and add them.
382 // Semantics: I_OUT = S1 * S2 + S3 * S4
383 class MulAddS2INode : public Node {
384   virtual uint hash() const;
385 public:
386   MulAddS2INode(Node* in1, Node *in2, Node *in3, Node* in4) : Node(0, in1, in2, in3, in4) {}
387   virtual int Opcode() const;
388   const Type *bottom_type() const { return TypeInt::INT; }
389   virtual uint ideal_reg() const { return Op_RegI; }
390 };
391 
392 //------------------------------CompressBitsNode-------------------------------
393 // CompressBits placeholder node
394 class CompressBitsNode : public Node {
395 public:
396   CompressBitsNode(Node *in1, Node *in2) : Node(0,in1,in2) {}
397   virtual int Opcode() const;
398 };
399 
400 //------------------------------ExpandBitsNode---------------------------------
401 // ExpandBits placeholder node
402 class ExpandBitsNode : public Node {
403 public:
404   ExpandBitsNode(Node *in1, Node *in2) : Node(0,in1,in2) {}
405   virtual int Opcode() const;
406 };
407 
408 #endif // SHARE_OPTO_MULNODE_HPP
--- EOF ---