Path: blob/master/src/hotspot/share/opto/addnode.hpp
40930 views
/*1* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_OPTO_ADDNODE_HPP25#define SHARE_OPTO_ADDNODE_HPP2627#include "opto/node.hpp"28#include "opto/opcodes.hpp"29#include "opto/type.hpp"3031// Portions of code courtesy of Clifford Click3233class PhaseTransform;3435//------------------------------AddNode----------------------------------------36// Classic Add functionality. This covers all the usual 'add' behaviors for37// an algebraic ring. Add-integer, add-float, add-double, and binary-or are38// all inherited from this class. The various identity values are supplied39// by virtual functions.40class AddNode : public Node {41virtual uint hash() const;42public:43AddNode( Node *in1, Node *in2 ) : Node(0,in1,in2) {44init_class_id(Class_Add);45}4647// Handle algebraic identities here. If we have an identity, return the Node48// we are equivalent to. We look for "add of zero" as an identity.49virtual Node* Identity(PhaseGVN* phase);5051// We also canonicalize the Node, moving constants to the right input,52// and flatten expressions (so that 1+x+2 becomes x+3).53virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);5455// Compute a new Type for this node. Basically we just do the pre-check,56// then call the virtual add() to set the type.57virtual const Type* Value(PhaseGVN* phase) const;5859// Check if this addition involves the additive identity60virtual const Type *add_of_identity( const Type *t1, const Type *t2 ) const;6162// Supplied function returns the sum of the inputs.63// This also type-checks the inputs for sanity. Guaranteed never to64// be passed a TOP or BOTTOM type, these are filtered out by a pre-check.65virtual const Type *add_ring( const Type *, const Type * ) const = 0;6667// Supplied function to return the additive identity type68virtual const Type *add_id() const = 0;6970// Supplied function to return the additive opcode71virtual int max_opcode() const = 0;7273// Supplied function to return the multiplicative opcode74virtual int min_opcode() const = 0;7576virtual bool operates_on(BasicType bt, bool signed_int) const {77assert(bt == T_INT || bt == T_LONG, "unsupported");78return false;79}80static AddNode* make(Node* in1, Node* in2, BasicType bt);81};8283//------------------------------AddINode---------------------------------------84// Add 2 integers85class AddINode : public AddNode {86public:87AddINode( Node *in1, Node *in2 ) : AddNode(in1,in2) {}88virtual int Opcode() const;89virtual const Type *add_ring( const Type *, const Type * ) const;90virtual const Type *add_id() const { return TypeInt::ZERO; }91virtual const Type *bottom_type() const { return TypeInt::INT; }92int max_opcode() const { return Op_MaxI; }93int min_opcode() const { return Op_MinI; }94virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);95virtual Node* Identity(PhaseGVN* phase);96virtual bool operates_on(BasicType bt, bool signed_int) const {97assert(bt == T_INT || bt == T_LONG, "unsupported");98return bt == T_INT;99}100virtual uint ideal_reg() const { return Op_RegI; }101};102103//------------------------------AddLNode---------------------------------------104// Add 2 longs105class AddLNode : public AddNode {106public:107AddLNode( Node *in1, Node *in2 ) : AddNode(in1,in2) {}108virtual int Opcode() const;109virtual const Type *add_ring( const Type *, const Type * ) const;110virtual const Type *add_id() const { return TypeLong::ZERO; }111virtual const Type *bottom_type() const { return TypeLong::LONG; }112int max_opcode() const { return Op_MaxL; }113int min_opcode() const { return Op_MinL; }114virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);115virtual Node* Identity(PhaseGVN* phase);116virtual bool operates_on(BasicType bt, bool signed_int) const {117assert(bt == T_INT || bt == T_LONG, "unsupported");118return bt == T_LONG;119}120virtual uint ideal_reg() const { return Op_RegL; }121};122123//------------------------------AddFNode---------------------------------------124// Add 2 floats125class AddFNode : public AddNode {126public:127AddFNode( Node *in1, Node *in2 ) : AddNode(in1,in2) {}128virtual int Opcode() const;129virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);130virtual const Type *add_of_identity( const Type *t1, const Type *t2 ) const;131virtual const Type *add_ring( const Type *, const Type * ) const;132virtual const Type *add_id() const { return TypeF::ZERO; }133virtual const Type *bottom_type() const { return Type::FLOAT; }134int max_opcode() const { return Op_MaxF; }135int min_opcode() const { return Op_MinF; }136virtual Node* Identity(PhaseGVN* phase) { return this; }137virtual uint ideal_reg() const { return Op_RegF; }138};139140//------------------------------AddDNode---------------------------------------141// Add 2 doubles142class AddDNode : public AddNode {143public:144AddDNode( Node *in1, Node *in2 ) : AddNode(in1,in2) {}145virtual int Opcode() const;146virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);147virtual const Type *add_of_identity( const Type *t1, const Type *t2 ) const;148virtual const Type *add_ring( const Type *, const Type * ) const;149virtual const Type *add_id() const { return TypeD::ZERO; }150virtual const Type *bottom_type() const { return Type::DOUBLE; }151int max_opcode() const { return Op_MaxD; }152int min_opcode() const { return Op_MinD; }153virtual Node* Identity(PhaseGVN* phase) { return this; }154virtual uint ideal_reg() const { return Op_RegD; }155};156157//------------------------------AddPNode---------------------------------------158// Add pointer plus integer to get pointer. NOT commutative, really.159// So not really an AddNode. Lives here, because people associate it with160// an add.161class AddPNode : public Node {162public:163enum { Control, // When is it safe to do this add?164Base, // Base oop, for GC purposes165Address, // Actually address, derived from base166Offset } ; // Offset added to address167AddPNode( Node *base, Node *ptr, Node *off ) : Node(0,base,ptr,off) {168init_class_id(Class_AddP);169}170virtual int Opcode() const;171virtual Node* Identity(PhaseGVN* phase);172virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);173virtual const Type* Value(PhaseGVN* phase) const;174virtual const Type *bottom_type() const;175virtual uint ideal_reg() const { return Op_RegP; }176Node *base_node() { assert( req() > Base, "Missing base"); return in(Base); }177static Node* Ideal_base_and_offset(Node* ptr, PhaseTransform* phase,178// second return value:179intptr_t& offset);180181// Collect the AddP offset values into the elements array, giving up182// if there are more than length.183int unpack_offsets(Node* elements[], int length);184185// Do not match base-ptr edge186virtual uint match_edge(uint idx) const;187};188189//------------------------------OrINode----------------------------------------190// Logically OR 2 integers. Included with the ADD nodes because it inherits191// all the behavior of addition on a ring.192class OrINode : public AddNode {193public:194OrINode( Node *in1, Node *in2 ) : AddNode(in1,in2) {}195virtual int Opcode() const;196virtual const Type *add_ring( const Type *, const Type * ) const;197virtual const Type *add_id() const { return TypeInt::ZERO; }198virtual const Type *bottom_type() const { return TypeInt::INT; }199int max_opcode() const { return Op_MaxI; }200int min_opcode() const { return Op_MinI; }201virtual Node* Identity(PhaseGVN* phase);202virtual uint ideal_reg() const { return Op_RegI; }203virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);204};205206//------------------------------OrLNode----------------------------------------207// Logically OR 2 longs. Included with the ADD nodes because it inherits208// all the behavior of addition on a ring.209class OrLNode : public AddNode {210public:211OrLNode( Node *in1, Node *in2 ) : AddNode(in1,in2) {}212virtual int Opcode() const;213virtual const Type *add_ring( const Type *, const Type * ) const;214virtual const Type *add_id() const { return TypeLong::ZERO; }215virtual const Type *bottom_type() const { return TypeLong::LONG; }216int max_opcode() const { return Op_MaxL; }217int min_opcode() const { return Op_MinL; }218virtual Node* Identity(PhaseGVN* phase);219virtual uint ideal_reg() const { return Op_RegL; }220virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);221};222223//------------------------------XorINode---------------------------------------224// XOR'ing 2 integers225class XorINode : public AddNode {226public:227XorINode( Node *in1, Node *in2 ) : AddNode(in1,in2) {}228virtual int Opcode() const;229virtual const Type *add_ring( const Type *, const Type * ) const;230virtual const Type *add_id() const { return TypeInt::ZERO; }231virtual const Type *bottom_type() const { return TypeInt::INT; }232int max_opcode() const { return Op_MaxI; }233int min_opcode() const { return Op_MinI; }234virtual const Type *Value(PhaseGVN *phase) const;235virtual uint ideal_reg() const { return Op_RegI; }236};237238//------------------------------XorINode---------------------------------------239// XOR'ing 2 longs240class XorLNode : public AddNode {241public:242XorLNode( Node *in1, Node *in2 ) : AddNode(in1,in2) {}243virtual int Opcode() const;244virtual const Type *add_ring( const Type *, const Type * ) const;245virtual const Type *add_id() const { return TypeLong::ZERO; }246virtual const Type *bottom_type() const { return TypeLong::LONG; }247int max_opcode() const { return Op_MaxL; }248int min_opcode() const { return Op_MinL; }249virtual const Type *Value(PhaseGVN *phase) const;250virtual uint ideal_reg() const { return Op_RegL; }251};252253//------------------------------MaxNode----------------------------------------254// Max (or min) of 2 values. Included with the ADD nodes because it inherits255// all the behavior of addition on a ring. Only new thing is that we allow256// 2 equal inputs to be equal.257class MaxNode : public AddNode {258private:259static Node* build_min_max(Node* a, Node* b, bool is_max, bool is_unsigned, const Type* t, PhaseGVN& gvn);260static Node* build_min_max_diff_with_zero(Node* a, Node* b, bool is_max, const Type* t, PhaseGVN& gvn);261262public:263MaxNode( Node *in1, Node *in2 ) : AddNode(in1,in2) {}264virtual int Opcode() const = 0;265virtual int max_opcode() const = 0;266virtual int min_opcode() const = 0;267268static Node* unsigned_max(Node* a, Node* b, const Type* t, PhaseGVN& gvn) {269return build_min_max(a, b, true, true, t, gvn);270}271272static Node* unsigned_min(Node* a, Node* b, const Type* t, PhaseGVN& gvn) {273return build_min_max(a, b, false, true, t, gvn);274}275276static Node* signed_max(Node* a, Node* b, const Type* t, PhaseGVN& gvn) {277return build_min_max(a, b, true, false, t, gvn);278}279280static Node* signed_min(Node* a, Node* b, const Type* t, PhaseGVN& gvn) {281return build_min_max(a, b, false, false, t, gvn);282}283284// max(a-b, 0)285static Node* max_diff_with_zero(Node* a, Node* b, const Type* t, PhaseGVN& gvn) {286return build_min_max_diff_with_zero(a, b, true, t, gvn);287}288289// min(a-b, 0)290static Node* min_diff_with_zero(Node* a, Node* b, const Type* t, PhaseGVN& gvn) {291return build_min_max_diff_with_zero(a, b, false, t, gvn);292}293};294295//------------------------------MaxINode---------------------------------------296// Maximum of 2 integers. Included with the ADD nodes because it inherits297// all the behavior of addition on a ring.298class MaxINode : public MaxNode {299public:300MaxINode( Node *in1, Node *in2 ) : MaxNode(in1,in2) {}301virtual int Opcode() const;302virtual const Type *add_ring( const Type *, const Type * ) const;303virtual const Type *add_id() const { return TypeInt::make(min_jint); }304virtual const Type *bottom_type() const { return TypeInt::INT; }305virtual uint ideal_reg() const { return Op_RegI; }306int max_opcode() const { return Op_MaxI; }307int min_opcode() const { return Op_MinI; }308};309310//------------------------------MinINode---------------------------------------311// MINimum of 2 integers. Included with the ADD nodes because it inherits312// all the behavior of addition on a ring.313class MinINode : public MaxNode {314public:315MinINode( Node *in1, Node *in2 ) : MaxNode(in1,in2) {}316virtual int Opcode() const;317virtual const Type *add_ring( const Type *, const Type * ) const;318virtual const Type *add_id() const { return TypeInt::make(max_jint); }319virtual const Type *bottom_type() const { return TypeInt::INT; }320virtual uint ideal_reg() const { return Op_RegI; }321int max_opcode() const { return Op_MaxI; }322int min_opcode() const { return Op_MinI; }323virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);324};325326//------------------------------MaxLNode---------------------------------------327// MAXimum of 2 longs.328class MaxLNode : public MaxNode {329public:330MaxLNode(Node *in1, Node *in2) : MaxNode(in1, in2) {}331virtual int Opcode() const;332virtual const Type *add_ring(const Type*, const Type*) const { return TypeLong::LONG; }333virtual const Type *add_id() const { return TypeLong::make(min_jlong); }334virtual const Type *bottom_type() const { return TypeLong::LONG; }335virtual uint ideal_reg() const { return Op_RegL; }336int max_opcode() const { return Op_MaxL; }337int min_opcode() const { return Op_MinL; }338};339340//------------------------------MinLNode---------------------------------------341// MINimum of 2 longs.342class MinLNode : public MaxNode {343public:344MinLNode(Node *in1, Node *in2) : MaxNode(in1, in2) {}345virtual int Opcode() const;346virtual const Type *add_ring(const Type*, const Type*) const { return TypeLong::LONG; }347virtual const Type *add_id() const { return TypeLong::make(max_jlong); }348virtual const Type *bottom_type() const { return TypeLong::LONG; }349virtual uint ideal_reg() const { return Op_RegL; }350int max_opcode() const { return Op_MaxL; }351int min_opcode() const { return Op_MinL; }352};353354//------------------------------MaxFNode---------------------------------------355// Maximum of 2 floats.356class MaxFNode : public MaxNode {357public:358MaxFNode(Node *in1, Node *in2) : MaxNode(in1, in2) {}359virtual int Opcode() const;360virtual const Type *add_ring(const Type*, const Type*) const;361virtual const Type *add_id() const { return TypeF::NEG_INF; }362virtual const Type *bottom_type() const { return Type::FLOAT; }363virtual uint ideal_reg() const { return Op_RegF; }364int max_opcode() const { return Op_MaxF; }365int min_opcode() const { return Op_MinF; }366};367368//------------------------------MinFNode---------------------------------------369// Minimum of 2 floats.370class MinFNode : public MaxNode {371public:372MinFNode(Node *in1, Node *in2) : MaxNode(in1, in2) {}373virtual int Opcode() const;374virtual const Type *add_ring(const Type*, const Type*) const;375virtual const Type *add_id() const { return TypeF::POS_INF; }376virtual const Type *bottom_type() const { return Type::FLOAT; }377virtual uint ideal_reg() const { return Op_RegF; }378int max_opcode() const { return Op_MaxF; }379int min_opcode() const { return Op_MinF; }380};381382//------------------------------MaxDNode---------------------------------------383// Maximum of 2 doubles.384class MaxDNode : public MaxNode {385public:386MaxDNode(Node *in1, Node *in2) : MaxNode(in1, in2) {}387virtual int Opcode() const;388virtual const Type *add_ring(const Type*, const Type*) const;389virtual const Type *add_id() const { return TypeD::NEG_INF; }390virtual const Type *bottom_type() const { return Type::DOUBLE; }391virtual uint ideal_reg() const { return Op_RegD; }392int max_opcode() const { return Op_MaxD; }393int min_opcode() const { return Op_MinD; }394};395396//------------------------------MinDNode---------------------------------------397// Minimum of 2 doubles.398class MinDNode : public MaxNode {399public:400MinDNode(Node *in1, Node *in2) : MaxNode(in1, in2) {}401virtual int Opcode() const;402virtual const Type *add_ring(const Type*, const Type*) const;403virtual const Type *add_id() const { return TypeD::POS_INF; }404virtual const Type *bottom_type() const { return Type::DOUBLE; }405virtual uint ideal_reg() const { return Op_RegD; }406int max_opcode() const { return Op_MaxD; }407int min_opcode() const { return Op_MinD; }408};409410#endif // SHARE_OPTO_ADDNODE_HPP411412413