Path: blob/master/src/hotspot/share/opto/castnode.hpp
64440 views
/*1* Copyright (c) 2014, 2019, 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_CASTNODE_HPP25#define SHARE_OPTO_CASTNODE_HPP2627#include "opto/node.hpp"28#include "opto/opcodes.hpp"293031//------------------------------ConstraintCastNode-----------------------------32// cast to a different range33class ConstraintCastNode: public TypeNode {34public:35enum DependencyType {36RegularDependency, // if cast doesn't improve input type, cast can be removed37StrongDependency, // leave cast in even if _type doesn't improve input type, can be replaced by stricter dominating cast if one exist38UnconditionalDependency // leave cast in unconditionally39};4041protected:42const DependencyType _dependency;43virtual bool cmp( const Node &n ) const;44virtual uint size_of() const;4546public:47ConstraintCastNode(Node *n, const Type *t, DependencyType dependency)48: TypeNode(t,2), _dependency(dependency) {49init_class_id(Class_ConstraintCast);50init_req(1, n);51}52virtual Node* Identity(PhaseGVN* phase);53virtual const Type* Value(PhaseGVN* phase) const;54virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);55virtual int Opcode() const;56virtual uint ideal_reg() const = 0;57virtual bool depends_only_on_test() const { return _dependency == RegularDependency; }58bool carry_dependency() const { return _dependency != RegularDependency; }59TypeNode* dominating_cast(PhaseGVN* gvn, PhaseTransform* pt) const;60static Node* make_cast(int opcode, Node* c, Node *n, const Type *t, DependencyType dependency);61static Node* make(Node* c, Node *n, const Type *t, BasicType bt);62virtual bool operates_on(BasicType bt, bool signed_int) const {63assert(bt == T_INT || bt == T_LONG, "unsupported");64return false;65}6667#ifndef PRODUCT68virtual void dump_spec(outputStream *st) const;69#endif7071static Node* make_cast_for_type(Node* c, Node* in, const Type* type, DependencyType dependency);72};7374//------------------------------CastIINode-------------------------------------75// cast integer to integer (different range)76class CastIINode: public ConstraintCastNode {77protected:78// Is this node dependent on a range check?79const bool _range_check_dependency;80virtual bool cmp(const Node &n) const;81virtual uint size_of() const;8283public:84CastIINode(Node* n, const Type* t, DependencyType dependency = RegularDependency, bool range_check_dependency = false)85: ConstraintCastNode(n, t, dependency), _range_check_dependency(range_check_dependency) {86init_class_id(Class_CastII);87}88CastIINode(Node* ctrl, Node* n, const Type* t, DependencyType dependency = RegularDependency, bool range_check_dependency = false)89: ConstraintCastNode(n, t, dependency), _range_check_dependency(range_check_dependency) {90init_class_id(Class_CastII);91init_req(0, ctrl);92}93virtual int Opcode() const;94virtual uint ideal_reg() const { return Op_RegI; }95virtual Node* Identity(PhaseGVN* phase);96virtual const Type* Value(PhaseGVN* phase) const;97virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);98const bool has_range_check() {99#ifdef _LP64100return _range_check_dependency;101#else102assert(!_range_check_dependency, "Should not have range check dependency");103return false;104#endif105}106virtual bool operates_on(BasicType bt, bool signed_int) const {107assert(bt == T_INT || bt == T_LONG, "unsupported");108return bt == T_INT;109}110111#ifndef PRODUCT112virtual void dump_spec(outputStream* st) const;113#endif114};115116class CastLLNode: public ConstraintCastNode {117public:118CastLLNode(Node* ctrl, Node* n, const Type* t, DependencyType dependency = RegularDependency)119: ConstraintCastNode(n, t, dependency) {120init_class_id(Class_CastLL);121init_req(0, ctrl);122}123CastLLNode(Node* n, const Type* t, DependencyType dependency = RegularDependency)124: ConstraintCastNode(n, t, dependency){125init_class_id(Class_CastLL);126}127virtual bool operates_on(BasicType bt, bool signed_int) const {128assert(bt == T_INT || bt == T_LONG, "unsupported");129return bt == T_LONG;130}131virtual int Opcode() const;132virtual uint ideal_reg() const { return Op_RegL; }133};134135class CastFFNode: public ConstraintCastNode {136public:137CastFFNode(Node* n, const Type* t, DependencyType dependency = RegularDependency)138: ConstraintCastNode(n, t, dependency){139init_class_id(Class_CastFF);140}141virtual int Opcode() const;142virtual uint ideal_reg() const { return in(1)->ideal_reg(); }143};144145class CastDDNode: public ConstraintCastNode {146public:147CastDDNode(Node* n, const Type* t, DependencyType dependency = RegularDependency)148: ConstraintCastNode(n, t, dependency){149init_class_id(Class_CastDD);150}151virtual int Opcode() const;152virtual uint ideal_reg() const { return in(1)->ideal_reg(); }153};154155class CastVVNode: public ConstraintCastNode {156public:157CastVVNode(Node* n, const Type* t, DependencyType dependency = RegularDependency)158: ConstraintCastNode(n, t, dependency){159init_class_id(Class_CastVV);160}161virtual int Opcode() const;162virtual uint ideal_reg() const { return in(1)->ideal_reg(); }163};164165166//------------------------------CastPPNode-------------------------------------167// cast pointer to pointer (different type)168class CastPPNode: public ConstraintCastNode {169public:170CastPPNode (Node *n, const Type *t, DependencyType dependency = RegularDependency)171: ConstraintCastNode(n, t, dependency) {172}173virtual int Opcode() const;174virtual uint ideal_reg() const { return Op_RegP; }175};176177//------------------------------CheckCastPPNode--------------------------------178// for _checkcast, cast pointer to pointer (different type), without JOIN,179class CheckCastPPNode: public ConstraintCastNode {180public:181CheckCastPPNode(Node *c, Node *n, const Type *t, DependencyType dependency = RegularDependency)182: ConstraintCastNode(n, t, dependency) {183init_class_id(Class_CheckCastPP);184init_req(0, c);185}186187virtual Node* Identity(PhaseGVN* phase);188virtual const Type* Value(PhaseGVN* phase) const;189virtual int Opcode() const;190virtual uint ideal_reg() const { return Op_RegP; }191bool depends_only_on_test() const { return !type()->isa_rawptr() && ConstraintCastNode::depends_only_on_test(); }192};193194195//------------------------------CastX2PNode-------------------------------------196// convert a machine-pointer-sized integer to a raw pointer197class CastX2PNode : public Node {198public:199CastX2PNode( Node *n ) : Node(NULL, n) {}200virtual int Opcode() const;201virtual const Type* Value(PhaseGVN* phase) const;202virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);203virtual Node* Identity(PhaseGVN* phase);204virtual uint ideal_reg() const { return Op_RegP; }205virtual const Type *bottom_type() const { return TypeRawPtr::BOTTOM; }206};207208//------------------------------CastP2XNode-------------------------------------209// Used in both 32-bit and 64-bit land.210// Used for card-marks and unsafe pointer math.211class CastP2XNode : public Node {212public:213CastP2XNode( Node *ctrl, Node *n ) : Node(ctrl, n) {}214virtual int Opcode() const;215virtual const Type* Value(PhaseGVN* phase) const;216virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);217virtual Node* Identity(PhaseGVN* phase);218virtual uint ideal_reg() const { return Op_RegX; }219virtual const Type *bottom_type() const { return TypeX_X; }220// Return false to keep node from moving away from an associated card mark.221virtual bool depends_only_on_test() const { return false; }222};223224225226#endif // SHARE_OPTO_CASTNODE_HPP227228229