1 /*
   2  * Copyright (c) 2013, 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_VM_OPTO_MATHEXACTNODE_HPP
  26 #define SHARE_VM_OPTO_MATHEXACTNODE_HPP
  27 
  28 #include "opto/multnode.hpp"
  29 #include "opto/node.hpp"
  30 #include "opto/subnode.hpp"
  31 #include "opto/type.hpp"
  32 
  33 class BoolNode;
  34 class IfNode;
  35 class Node;
  36 
  37 class PhaseGVN;
  38 class PhaseTransform;
  39 
  40 class MathExactNode : public MultiNode {
  41 public:
  42   MathExactNode(Node* ctrl, Node* n1);
  43   MathExactNode(Node* ctrl, Node* in1, Node* in2);
  44   enum {
  45     result_proj_node = 0,
  46     flags_proj_node = 1
  47   };
  48   virtual int Opcode() const;
  49   virtual Node* Identity(PhaseTransform* phase) { return this; }
  50   virtual Node* Ideal(PhaseGVN* phase, bool can_reshape) { return NULL; }
  51   virtual const Type* Value(PhaseTransform* phase) const { return bottom_type(); }
  52   virtual uint hash() const { return Node::hash(); }
  53   virtual bool is_CFG() const { return false; }
  54   virtual uint ideal_reg() const { return NotAMachineReg; }
  55 
  56   static bool is_MathExactOpcode(int opcode);
  57 
  58   ProjNode* result_node() const { return proj_out(result_proj_node); }
  59   ProjNode* flags_node() const { return proj_out(flags_proj_node); }
  60   Node* control_node() const;
  61   Node* non_throwing_branch() const;
  62 protected:
  63   IfNode* if_node() const;
  64   BoolNode* bool_node() const;
  65   Node* no_overflow(PhaseGVN *phase, Node* new_result);
  66 };
  67 
  68 class MathExactINode : public MathExactNode {
  69  public:
  70   MathExactINode(Node* ctrl, Node* in1) : MathExactNode(ctrl, in1) {}
  71   MathExactINode(Node* ctrl, Node* in1, Node* in2) : MathExactNode(ctrl, in1, in2) {}
  72   virtual int Opcode() const;
  73   virtual Node* match(const ProjNode* proj, const Matcher* m);
  74   virtual const Type* bottom_type() const { return TypeTuple::INT_CC_PAIR; }
  75 };
  76 
  77 class MathExactLNode : public MathExactNode {
  78 public:
  79   MathExactLNode(Node* ctrl, Node* in1) : MathExactNode(ctrl, in1) {}
  80   MathExactLNode(Node* ctrl, Node* in1, Node* in2) : MathExactNode(ctrl, in1, in2) {}
  81   virtual int Opcode() const;
  82   virtual Node* match(const ProjNode* proj, const Matcher* m);
  83   virtual const Type* bottom_type() const { return TypeTuple::LONG_CC_PAIR; }
  84 };
  85 
  86 class AddExactINode : public MathExactINode {
  87 public:
  88   AddExactINode(Node* ctrl, Node* in1, Node* in2) : MathExactINode(ctrl, in1, in2) {}
  89   virtual int Opcode() const;
  90   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
  91 };
  92 
  93 class AddExactLNode : public MathExactLNode {
  94 public:
  95   AddExactLNode(Node* ctrl, Node* in1, Node* in2) : MathExactLNode(ctrl, in1, in2) {}
  96   virtual int Opcode() const;
  97   virtual Node* Ideal(PhaseGVN* phase, bool can_reshape);
  98 };
  99 
 100 class SubExactINode : public MathExactINode {
 101 public:
 102   SubExactINode(Node* ctrl, Node* in1, Node* in2) : MathExactINode(ctrl, in1, in2) {}
 103   virtual int Opcode() const;
 104   virtual Node* Ideal(PhaseGVN* phase, bool can_reshape);
 105 };
 106 
 107 class SubExactLNode : public MathExactLNode {
 108 public:
 109   SubExactLNode(Node* ctrl, Node* in1, Node* in2) : MathExactLNode(ctrl, in1, in2) {}
 110   virtual int Opcode() const;
 111   virtual Node* Ideal(PhaseGVN* phase, bool can_reshape);
 112 };
 113 
 114 class NegExactINode : public MathExactINode {
 115 public:
 116   NegExactINode(Node* ctrl, Node* in1) : MathExactINode(ctrl, in1) {}
 117   virtual int Opcode() const;
 118   virtual Node* Ideal(PhaseGVN* phase, bool can_reshape);
 119 };
 120 
 121 class NegExactLNode : public MathExactLNode {
 122 public:
 123   NegExactLNode(Node* ctrl, Node* in1) : MathExactLNode(ctrl, in1) {}
 124   virtual int Opcode() const;
 125   virtual Node* Ideal(PhaseGVN* phase, bool can_reshape);
 126 };
 127 
 128 class MulExactINode : public MathExactINode {
 129 public:
 130   MulExactINode(Node* ctrl, Node* in1, Node* in2) : MathExactINode(ctrl, in1, in2) {}
 131   virtual int Opcode() const;
 132   virtual Node* Ideal(PhaseGVN* phase, bool can_reshape);
 133 };
 134 
 135 class MulExactLNode : public MathExactLNode {
 136 public:
 137   MulExactLNode(Node* ctrl, Node* in1, Node* in2) : MathExactLNode(ctrl, in1, in2) {}
 138   virtual int Opcode() const;
 139   virtual Node* Ideal(PhaseGVN* phase, bool can_reshape);
 140 };
 141 
 142 class FlagsProjNode : public ProjNode {
 143 public:
 144   FlagsProjNode(Node* src, uint con) : ProjNode(src, con) {
 145     init_class_id(Class_FlagsProj);
 146   }
 147 
 148   virtual int Opcode() const;
 149   virtual bool is_CFG() const { return false; }
 150   virtual const Type* bottom_type() const { return TypeInt::CC; }
 151   virtual uint ideal_reg() const { return Op_RegFlags; }
 152 };
 153 
 154 
 155 #endif
 156