1 /*
2  * Copyright (c) 2014, 2019, 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_OPAQUENODE_HPP
26 #define SHARE_OPTO_OPAQUENODE_HPP
27 
28 #include "opto/node.hpp"
29 #include "opto/opcodes.hpp"
30 
31 //------------------------------Opaque1Node------------------------------------
32 // A node to prevent unwanted optimizations.  Allows constant folding.
33 // Stops value-numbering, Ideal calls or Identity functions.
34 class Opaque1Node : public Node {
35   virtual uint hash() const ;                  // { return NO_HASH; }
36   virtual bool cmp( const Node &n ) const;
37   public:
Opaque1Node(Compile * C,Node * n)38   Opaque1Node(Compile* C, Node *n) : Node(NULL, n) {
39     // Put it on the Macro nodes list to removed during macro nodes expansion.
40     init_flags(Flag_is_macro);
41     init_class_id(Class_Opaque1);
42     C->add_macro_node(this);
43   }
44   // Special version for the pre-loop to hold the original loop limit
45   // which is consumed by range check elimination.
Opaque1Node(Compile * C,Node * n,Node * orig_limit)46   Opaque1Node(Compile* C, Node *n, Node* orig_limit) : Node(NULL, n, orig_limit) {
47     // Put it on the Macro nodes list to removed during macro nodes expansion.
48     init_flags(Flag_is_macro);
49     init_class_id(Class_Opaque1);
50     C->add_macro_node(this);
51   }
original_loop_limit()52   Node* original_loop_limit() { return req()==3 ? in(2) : NULL; }
53   virtual int Opcode() const;
bottom_type() const54   virtual const Type *bottom_type() const { return TypeInt::INT; }
55   virtual Node* Identity(PhaseGVN* phase);
56 };
57 
58 // Opaque nodes specific to range check elimination handling
59 class OpaqueLoopInitNode : public Opaque1Node {
60   public:
OpaqueLoopInitNode(Compile * C,Node * n)61   OpaqueLoopInitNode(Compile* C, Node *n) : Opaque1Node(C, n) {
62   }
63   virtual int Opcode() const;
64 };
65 
66 class OpaqueLoopStrideNode : public Opaque1Node {
67   public:
OpaqueLoopStrideNode(Compile * C,Node * n)68   OpaqueLoopStrideNode(Compile* C, Node *n) : Opaque1Node(C, n) {
69   }
70   virtual int Opcode() const;
71 };
72 
73 //------------------------------Opaque2Node------------------------------------
74 // A node to prevent unwanted optimizations.  Allows constant folding.  Stops
75 // value-numbering, most Ideal calls or Identity functions.  This Node is
76 // specifically designed to prevent the pre-increment value of a loop trip
77 // counter from being live out of the bottom of the loop (hence causing the
78 // pre- and post-increment values both being live and thus requiring an extra
79 // temp register and an extra move).  If we "accidentally" optimize through
80 // this kind of a Node, we'll get slightly pessimal, but correct, code.  Thus
81 // it's OK to be slightly sloppy on optimizations here.
82 class Opaque2Node : public Node {
83   virtual uint hash() const ;                  // { return NO_HASH; }
84   virtual bool cmp( const Node &n ) const;
85   public:
Opaque2Node(Compile * C,Node * n)86   Opaque2Node( Compile* C, Node *n ) : Node(0,n) {
87     // Put it on the Macro nodes list to removed during macro nodes expansion.
88     init_flags(Flag_is_macro);
89     C->add_macro_node(this);
90   }
91   virtual int Opcode() const;
bottom_type() const92   virtual const Type *bottom_type() const { return TypeInt::INT; }
93 };
94 
95 //------------------------------Opaque3Node------------------------------------
96 // A node to prevent unwanted optimizations. Will be optimized only during
97 // macro nodes expansion.
98 class Opaque3Node : public Opaque2Node {
99   int _opt; // what optimization it was used for
100   public:
101   enum { RTM_OPT };
Opaque3Node(Compile * C,Node * n,int opt)102   Opaque3Node(Compile* C, Node *n, int opt) : Opaque2Node(C, n), _opt(opt) {}
103   virtual int Opcode() const;
rtm_opt() const104   bool rtm_opt() const { return (_opt == RTM_OPT); }
105 };
106 
107 // Input 1 is a check that we know implicitly is always true or false
108 // but the compiler has no way to prove. If during optimizations, that
109 // check becomes true or false, the Opaque4 node is replaced by that
110 // constant true or false. Input 2 is the constant value we know the
111 // test takes. After loop optimizations, we replace input 1 by input 2
112 // so the control that depends on that test can be removed and there's
113 // no overhead at runtime. Used for instance by
114 // GraphKit::must_be_not_null().
115 class Opaque4Node : public Node {
116   public:
Opaque4Node(Compile * C,Node * tst,Node * final_tst)117   Opaque4Node(Compile* C, Node *tst, Node* final_tst) : Node(NULL, tst, final_tst) {}
118 
119   virtual int Opcode() const;
bottom_type() const120   virtual const Type *bottom_type() const { return TypeInt::BOOL; }
121   virtual Node* Identity(PhaseGVN* phase);
122   virtual const Type* Value(PhaseGVN* phase) const;
123 };
124 
125 
126 //------------------------------ProfileBooleanNode-------------------------------
127 // A node represents value profile for a boolean during parsing.
128 // Once parsing is over, the node goes away (during IGVN).
129 // It is used to override branch frequencies from MDO (see has_injected_profile in parse2.cpp).
130 class ProfileBooleanNode : public Node {
131   uint _false_cnt;
132   uint _true_cnt;
133   bool _consumed;
134   bool _delay_removal;
135   virtual uint hash() const ;                  // { return NO_HASH; }
136   virtual bool cmp( const Node &n ) const;
137   public:
ProfileBooleanNode(Node * n,uint false_cnt,uint true_cnt)138   ProfileBooleanNode(Node *n, uint false_cnt, uint true_cnt) : Node(0, n),
139           _false_cnt(false_cnt), _true_cnt(true_cnt), _consumed(false), _delay_removal(true) {}
140 
false_count() const141   uint false_count() const { return _false_cnt; }
true_count() const142   uint  true_count() const { return  _true_cnt; }
143 
consume()144   void consume() { _consumed = true;  }
145 
146   virtual int Opcode() const;
147   virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
148   virtual Node* Identity(PhaseGVN* phase);
bottom_type() const149   virtual const Type *bottom_type() const { return TypeInt::BOOL; }
150 };
151 
152 #endif // SHARE_OPTO_OPAQUENODE_HPP
153