1 /*
  2  * Copyright (c) 2014, 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_CONVERTNODE_HPP
 26 #define SHARE_OPTO_CONVERTNODE_HPP
 27 
 28 #include "opto/node.hpp"
 29 #include "opto/opcodes.hpp"
 30 
 31 
 32 //------------------------------Conv2BNode-------------------------------------
 33 // Convert int/pointer to a Boolean.  Map zero to zero, all else to 1.
 34 class Conv2BNode : public Node {
 35   public:
 36   Conv2BNode( Node *i ) : Node(0,i) {}
 37   virtual int Opcode() const;
 38   virtual const Type *bottom_type() const { return TypeInt::BOOL; }
 39   virtual Node* Identity(PhaseGVN* phase);
 40   virtual const Type* Value(PhaseGVN* phase) const;
 41   virtual Node* Ideal(PhaseGVN* phase, bool can_reshape);
 42   virtual uint  ideal_reg() const { return Op_RegI; }
 43 };
 44 
 45 // The conversions operations are all Alpha sorted.  Please keep it that way!
 46 //------------------------------ConvD2FNode------------------------------------
 47 // Convert double to float
 48 class ConvD2FNode : public Node {
 49   public:
 50   ConvD2FNode( Node *in1 ) : Node(0,in1) {}
 51   virtual int Opcode() const;
 52   virtual const Type *bottom_type() const { return Type::FLOAT; }
 53   virtual const Type* Value(PhaseGVN* phase) const;
 54   virtual Node* Identity(PhaseGVN* phase);
 55   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
 56   virtual uint  ideal_reg() const { return Op_RegF; }
 57 };
 58 
 59 //------------------------------ConvD2INode------------------------------------
 60 // Convert Double to Integer
 61 class ConvD2INode : public Node {
 62   public:
 63   ConvD2INode( Node *in1 ) : Node(0,in1) {}
 64   virtual int Opcode() const;
 65   virtual const Type *bottom_type() const { return TypeInt::INT; }
 66   virtual const Type* Value(PhaseGVN* phase) const;
 67   virtual Node* Identity(PhaseGVN* phase);
 68   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
 69   virtual uint  ideal_reg() const { return Op_RegI; }
 70 };
 71 
 72 //------------------------------ConvD2LNode------------------------------------
 73 // Convert Double to Long
 74 class ConvD2LNode : public Node {
 75   public:
 76   ConvD2LNode( Node *dbl ) : Node(0,dbl) {}
 77   virtual int Opcode() const;
 78   virtual const Type *bottom_type() const { return TypeLong::LONG; }
 79   virtual const Type* Value(PhaseGVN* phase) const;
 80   virtual Node* Identity(PhaseGVN* phase);
 81   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
 82   virtual uint ideal_reg() const { return Op_RegL; }
 83 };
 84 
 85 //------------------------------ConvF2DNode------------------------------------
 86 // Convert Float to a Double.
 87 class ConvF2DNode : public Node {
 88   public:
 89   ConvF2DNode( Node *in1 ) : Node(0,in1) {}
 90   virtual int Opcode() const;
 91   virtual const Type *bottom_type() const { return Type::DOUBLE; }
 92   virtual const Type* Value(PhaseGVN* phase) const;
 93   virtual uint  ideal_reg() const { return Op_RegD; }
 94 };
 95 
 96 //------------------------------ConvF2INode------------------------------------
 97 // Convert float to integer
 98 class ConvF2INode : public Node {
 99   public:
100   ConvF2INode( Node *in1 ) : Node(0,in1) {}
101   virtual int Opcode() const;
102   virtual const Type *bottom_type() const { return TypeInt::INT; }
103   virtual const Type* Value(PhaseGVN* phase) const;
104   virtual Node* Identity(PhaseGVN* phase);
105   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
106   virtual uint  ideal_reg() const { return Op_RegI; }
107 };
108 
109 //------------------------------ConvF2LNode------------------------------------
110 // Convert float to long
111 class ConvF2LNode : public Node {
112   public:
113   ConvF2LNode( Node *in1 ) : Node(0,in1) {}
114   virtual int Opcode() const;
115   virtual const Type *bottom_type() const { return TypeLong::LONG; }
116   virtual const Type* Value(PhaseGVN* phase) const;
117   virtual Node* Identity(PhaseGVN* phase);
118   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
119   virtual uint  ideal_reg() const { return Op_RegL; }
120 };
121 
122 //------------------------------ConvI2DNode------------------------------------
123 // Convert Integer to Double
124 class ConvI2DNode : public Node {
125   public:
126   ConvI2DNode( Node *in1 ) : Node(0,in1) {}
127   virtual int Opcode() const;
128   virtual const Type *bottom_type() const { return Type::DOUBLE; }
129   virtual const Type* Value(PhaseGVN* phase) const;
130   virtual uint  ideal_reg() const { return Op_RegD; }
131 };
132 
133 //------------------------------ConvI2FNode------------------------------------
134 // Convert Integer to Float
135 class ConvI2FNode : public Node {
136   public:
137   ConvI2FNode( Node *in1 ) : Node(0,in1) {}
138   virtual int Opcode() const;
139   virtual const Type *bottom_type() const { return Type::FLOAT; }
140   virtual const Type* Value(PhaseGVN* phase) const;
141   virtual Node* Identity(PhaseGVN* phase);
142   virtual uint  ideal_reg() const { return Op_RegF; }
143 };
144 
145 //------------------------------ConvI2LNode------------------------------------
146 // Convert integer to long
147 class ConvI2LNode : public TypeNode {
148   public:
149   ConvI2LNode(Node *in1, const TypeLong* t = TypeLong::INT)
150   : TypeNode(t, 2)
151   { init_req(1, in1); }
152   virtual int Opcode() const;
153   virtual const Type* Value(PhaseGVN* phase) const;
154   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
155   virtual uint  ideal_reg() const { return Op_RegL; }
156 };
157 
158 //------------------------------ConvL2DNode------------------------------------
159 // Convert Long to Double
160 class ConvL2DNode : public Node {
161   public:
162   ConvL2DNode( Node *in1 ) : Node(0,in1) {}
163   virtual int Opcode() const;
164   virtual const Type *bottom_type() const { return Type::DOUBLE; }
165   virtual const Type* Value(PhaseGVN* phase) const;
166   virtual uint ideal_reg() const { return Op_RegD; }
167 };
168 
169 //------------------------------ConvL2FNode------------------------------------
170 // Convert Long to Float
171 class ConvL2FNode : public Node {
172   public:
173   ConvL2FNode( Node *in1 ) : Node(0,in1) {}
174   virtual int Opcode() const;
175   virtual const Type *bottom_type() const { return Type::FLOAT; }
176   virtual const Type* Value(PhaseGVN* phase) const;
177   virtual uint  ideal_reg() const { return Op_RegF; }
178 };
179 
180 //------------------------------ConvL2INode------------------------------------
181 // Convert long to integer
182 class ConvL2INode : public TypeNode {
183   public:
184   ConvL2INode(Node *in1, const TypeInt* t = TypeInt::INT)
185   : TypeNode(t, 2) {
186     init_req(1, in1);
187   }
188   virtual int Opcode() const;
189   virtual Node* Identity(PhaseGVN* phase);
190   virtual const Type* Value(PhaseGVN* phase) const;
191   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
192   virtual uint  ideal_reg() const { return Op_RegI; }
193 };
194 
195 //-----------------------------RoundFloatNode----------------------------------
196 class RoundFloatNode: public Node {
197   public:
198   RoundFloatNode(Node* c, Node *in1): Node(c, in1) {}
199   virtual int   Opcode() const;
200   virtual const Type *bottom_type() const { return Type::FLOAT; }
201   virtual uint  ideal_reg() const { return Op_RegF; }
202   virtual Node* Identity(PhaseGVN* phase);
203   virtual const Type* Value(PhaseGVN* phase) const;
204 };
205 
206 
207 //-----------------------------RoundDoubleNode---------------------------------
208 class RoundDoubleNode: public Node {
209   public:
210   RoundDoubleNode(Node* c, Node *in1): Node(c, in1) {}
211   virtual int   Opcode() const;
212   virtual const Type *bottom_type() const { return Type::DOUBLE; }
213   virtual uint  ideal_reg() const { return Op_RegD; }
214   virtual Node* Identity(PhaseGVN* phase);
215   virtual const Type* Value(PhaseGVN* phase) const;
216 };
217 
218 //-----------------------------RoundDoubleModeNode-----------------------------
219 class RoundDoubleModeNode: public Node {
220   public:
221   enum RoundingMode {
222     rmode_rint  = 0,
223     rmode_floor = 1,
224     rmode_ceil  = 2
225   };
226   RoundDoubleModeNode(Node *in1, Node * rmode): Node(0, in1, rmode) {}
227   static RoundDoubleModeNode* make(PhaseGVN& gvn, Node* arg, RoundDoubleModeNode::RoundingMode rmode);
228   virtual int   Opcode() const;
229   virtual const Type *bottom_type() const { return Type::DOUBLE; }
230   virtual uint  ideal_reg() const { return Op_RegD; }
231   virtual Node* Identity(PhaseGVN* phase);
232   virtual const Type* Value(PhaseGVN* phase) const;
233 };
234 
235 
236 #endif // SHARE_OPTO_CONVERTNODE_HPP