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_CFGNODE_HPP
26 #define SHARE_OPTO_CFGNODE_HPP
27
28 #include "opto/multnode.hpp"
29 #include "opto/node.hpp"
30 #include "opto/opcodes.hpp"
31 #include "opto/predicates_enums.hpp"
32 #include "opto/type.hpp"
33
34 // Portions of code courtesy of Clifford Click
35
36 // Optimization - Graph Style
37
38 class Matcher;
39 class Node;
40 class RegionNode;
41 class TypeNode;
42 class PhiNode;
43 class GotoNode;
44 class MultiNode;
45 class MultiBranchNode;
46 class IfNode;
47 class PCTableNode;
48 class JumpNode;
49 class CatchNode;
50 class NeverBranchNode;
51 class BlackholeNode;
52 class ProjNode;
163 int _inst_mem_id; // Instance memory id (node index of the memory Phi)
164 int _inst_id; // Instance id of the memory slice.
165 const int _inst_index; // Alias index of the instance memory slice.
166 // Array elements references have the same alias_idx but different offset.
167 const int _inst_offset; // Offset of the instance memory slice.
168 // Size is bigger to hold the _adr_type field.
169 virtual uint hash() const; // Check the type
170 virtual bool cmp( const Node &n ) const;
171 virtual uint size_of() const { return sizeof(*this); }
172
173 // Determine if CMoveNode::is_cmove_id can be used at this join point.
174 Node* is_cmove_id(PhaseTransform* phase, int true_path);
175 bool wait_for_region_igvn(PhaseGVN* phase);
176 bool is_data_loop(RegionNode* r, Node* uin, const PhaseGVN* phase);
177
178 static Node* clone_through_phi(Node* root_phi, const Type* t, uint c, PhaseIterGVN* igvn);
179 static Node* merge_through_phi(Node* root_phi, PhaseIterGVN* igvn);
180
181 bool must_wait_for_region_in_irreducible_loop(PhaseGVN* phase) const;
182
183 bool is_split_through_mergemem_terminating() const;
184
185 void verify_type_stability(const PhaseGVN* phase, const Type* union_of_input_types, const Type* new_type) const NOT_DEBUG_RETURN;
186 bool wait_for_cast_input_igvn(const PhaseIterGVN* igvn) const;
187
188 public:
189 // Node layout (parallels RegionNode):
190 enum { Region, // Control input is the Phi's region.
191 Input // Input values are [1..len)
192 };
193
194 PhiNode( Node *r, const Type *t, const TypePtr* at = nullptr,
195 const int imid = -1,
196 const int iid = TypeOopPtr::InstanceTop,
197 const int iidx = Compile::AliasIdxTop,
198 const int ioffs = Type::OffsetTop )
199 : TypeNode(t,r->req()),
200 _adr_type(at),
201 _inst_mem_id(imid),
202 _inst_id(iid),
215 PhiNode* slice_memory(const TypePtr* adr_type) const;
216 PhiNode* split_out_instance(const TypePtr* at, PhaseIterGVN *igvn) const;
217 // like make(r, x), but does not initialize the in edges to x
218 static PhiNode* make_blank( Node* r, Node* x );
219
220 // Accessors
221 RegionNode* region() const { Node* r = in(Region); assert(!r || r->is_Region(), ""); return (RegionNode*)r; }
222
223 bool is_tripcount(BasicType bt) const;
224
225 // Determine a unique non-trivial input, if any.
226 // Ignore casts if it helps. Return null on failure.
227 Node* unique_input(PhaseValues* phase, bool uncast);
228 Node* unique_input(PhaseValues* phase) {
229 Node* uin = unique_input(phase, false);
230 if (uin == nullptr) {
231 uin = unique_input(phase, true);
232 }
233 return uin;
234 }
235
236 // Check for a simple dead loop.
237 enum LoopSafety { Safe = 0, Unsafe, UnsafeLoop };
238 LoopSafety simple_data_loop_check(Node *in) const;
239 // Is it unsafe data loop? It becomes a dead loop if this phi node removed.
240 bool is_unsafe_data_reference(Node *in) const;
241 int is_diamond_phi() const;
242 bool try_clean_memory_phi(PhaseIterGVN* igvn);
243 virtual int Opcode() const;
244 virtual bool pinned() const { return in(0) != nullptr; }
245 virtual const TypePtr *adr_type() const { verify_adr_type(true); return _adr_type; }
246
247 void set_inst_mem_id(int inst_mem_id) { _inst_mem_id = inst_mem_id; }
248 int inst_mem_id() const { return _inst_mem_id; }
249 int inst_id() const { return _inst_id; }
250 int inst_index() const { return _inst_index; }
251 int inst_offset() const { return _inst_offset; }
252 bool is_same_inst_field(const Type* tp, int mem_id, int id, int index, int offset) {
253 return type()->basic_type() == tp->basic_type() &&
254 inst_mem_id() == mem_id &&
255 inst_id() == id &&
256 inst_index() == index &&
257 inst_offset() == offset &&
258 type()->higher_equal(tp);
259 }
260
261 virtual const Type* Value(PhaseGVN* phase) const;
262 virtual Node* Identity(PhaseGVN* phase);
263 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
264 virtual const RegMask &out_RegMask() const;
265 virtual const RegMask &in_RegMask(uint) const;
266 #ifndef PRODUCT
267 virtual void dump_spec(outputStream *st) const;
268 #endif
269 #ifdef ASSERT
270 void verify_adr_type(VectorSet& visited, const TypePtr* at) const;
271 void verify_adr_type(bool recursive = false) const;
272 #else //ASSERT
273 void verify_adr_type(bool recursive = false) const {}
274 #endif //ASSERT
275
276 const TypeTuple* collect_types(PhaseGVN* phase) const;
277 };
278
279 //------------------------------GotoNode---------------------------------------
280 // GotoNodes perform direct branches.
452 }
453
454 virtual int Opcode() const;
455 virtual bool pinned() const { return true; }
456 virtual const Type *bottom_type() const { return TypeTuple::IFBOTH; }
457 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
458 virtual const Type* Value(PhaseGVN* phase) const;
459 virtual uint required_outcnt() const { return 2; }
460 virtual const RegMask &out_RegMask() const;
461 Node* fold_compares(PhaseIterGVN* phase);
462 static Node* up_one_dom(Node* curr, bool linear_only = false);
463 bool is_zero_trip_guard() const;
464 Node* dominated_by(Node* prev_dom, PhaseIterGVN* igvn, bool pin_array_access_nodes);
465 ProjNode* uncommon_trap_proj(CallStaticJavaNode*& call, Deoptimization::DeoptReason reason = Deoptimization::Reason_none) const;
466
467 // Takes the type of val and filters it through the test represented
468 // by if_proj and returns a more refined type if one is produced.
469 // Returns null is it couldn't improve the type.
470 static const TypeInt* filtered_int_type(PhaseGVN* phase, Node* val, Node* if_proj);
471
472 AssertionPredicateType assertion_predicate_type() const {
473 return _assertion_predicate_type;
474 }
475
476 #ifndef PRODUCT
477 virtual void dump_spec(outputStream *st) const;
478 #endif
479
480 bool same_condition(const Node* dom, PhaseIterGVN* igvn) const;
481 };
482
483 class RangeCheckNode : public IfNode {
484 private:
485 int is_range_check(Node*& range, Node*& index, jint& offset);
486
487 public:
488 RangeCheckNode(Node* control, Node* bol, float p, float fcnt) : IfNode(control, bol, p, fcnt) {
489 init_class_id(Class_RangeCheck);
490 }
491
740 virtual int Opcode() const;
741 virtual bool pinned() const { return true; };
742 virtual const Type *bottom_type() const { return TypeTuple::IFBOTH; }
743 virtual const Type* Value(PhaseGVN* phase) const;
744 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
745 virtual uint required_outcnt() const { return 2; }
746 virtual void emit(C2_MacroAssembler *masm, PhaseRegAlloc *ra_) const { }
747 virtual uint size(PhaseRegAlloc *ra_) const { return 0; }
748 #ifndef PRODUCT
749 virtual void format( PhaseRegAlloc *, outputStream *st ) const;
750 #endif
751 };
752
753 //------------------------------BlackholeNode----------------------------
754 // Blackhole all arguments. This node would survive through the compiler
755 // the effects on its arguments, and would be finally matched to nothing.
756 class BlackholeNode : public MultiNode {
757 public:
758 BlackholeNode(Node* ctrl) : MultiNode(1) {
759 init_req(TypeFunc::Control, ctrl);
760 }
761 virtual int Opcode() const;
762 virtual uint ideal_reg() const { return 0; } // not matched in the AD file
763 virtual const Type* bottom_type() const { return TypeTuple::MEMBAR; }
764 virtual Node* Ideal(PhaseGVN* phase, bool can_reshape);
765
766 const RegMask &in_RegMask(uint idx) const {
767 // Fake the incoming arguments mask for blackholes: accept all registers
768 // and all stack slots. This would avoid any redundant register moves
769 // for blackhole inputs.
770 return RegMask::ALL;
771 }
772 #ifndef PRODUCT
773 virtual void format(PhaseRegAlloc* ra, outputStream* st) const;
774 #endif
775 };
776
777
778 #endif // SHARE_OPTO_CFGNODE_HPP
|
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_CFGNODE_HPP
26 #define SHARE_OPTO_CFGNODE_HPP
27
28 #include "opto/multnode.hpp"
29 #include "opto/node.hpp"
30 #include "opto/opcodes.hpp"
31 #include "opto/predicates_enums.hpp"
32 #include "opto/type.hpp"
33 #include "runtime/arguments.hpp"
34
35 // Portions of code courtesy of Clifford Click
36
37 // Optimization - Graph Style
38
39 class Matcher;
40 class Node;
41 class RegionNode;
42 class TypeNode;
43 class PhiNode;
44 class GotoNode;
45 class MultiNode;
46 class MultiBranchNode;
47 class IfNode;
48 class PCTableNode;
49 class JumpNode;
50 class CatchNode;
51 class NeverBranchNode;
52 class BlackholeNode;
53 class ProjNode;
164 int _inst_mem_id; // Instance memory id (node index of the memory Phi)
165 int _inst_id; // Instance id of the memory slice.
166 const int _inst_index; // Alias index of the instance memory slice.
167 // Array elements references have the same alias_idx but different offset.
168 const int _inst_offset; // Offset of the instance memory slice.
169 // Size is bigger to hold the _adr_type field.
170 virtual uint hash() const; // Check the type
171 virtual bool cmp( const Node &n ) const;
172 virtual uint size_of() const { return sizeof(*this); }
173
174 // Determine if CMoveNode::is_cmove_id can be used at this join point.
175 Node* is_cmove_id(PhaseTransform* phase, int true_path);
176 bool wait_for_region_igvn(PhaseGVN* phase);
177 bool is_data_loop(RegionNode* r, Node* uin, const PhaseGVN* phase);
178
179 static Node* clone_through_phi(Node* root_phi, const Type* t, uint c, PhaseIterGVN* igvn);
180 static Node* merge_through_phi(Node* root_phi, PhaseIterGVN* igvn);
181
182 bool must_wait_for_region_in_irreducible_loop(PhaseGVN* phase) const;
183
184 bool can_push_inline_types_down(PhaseGVN* phase, bool can_reshape, ciInlineKlass*& inline_klass);
185 InlineTypeNode* push_inline_types_down(PhaseGVN* phase, bool can_reshape, ciInlineKlass* inline_klass);
186
187 bool is_split_through_mergemem_terminating() const;
188
189 void verify_type_stability(const PhaseGVN* phase, const Type* union_of_input_types, const Type* new_type) const NOT_DEBUG_RETURN;
190 bool wait_for_cast_input_igvn(const PhaseIterGVN* igvn) const;
191
192 public:
193 // Node layout (parallels RegionNode):
194 enum { Region, // Control input is the Phi's region.
195 Input // Input values are [1..len)
196 };
197
198 PhiNode( Node *r, const Type *t, const TypePtr* at = nullptr,
199 const int imid = -1,
200 const int iid = TypeOopPtr::InstanceTop,
201 const int iidx = Compile::AliasIdxTop,
202 const int ioffs = Type::OffsetTop )
203 : TypeNode(t,r->req()),
204 _adr_type(at),
205 _inst_mem_id(imid),
206 _inst_id(iid),
219 PhiNode* slice_memory(const TypePtr* adr_type) const;
220 PhiNode* split_out_instance(const TypePtr* at, PhaseIterGVN *igvn) const;
221 // like make(r, x), but does not initialize the in edges to x
222 static PhiNode* make_blank( Node* r, Node* x );
223
224 // Accessors
225 RegionNode* region() const { Node* r = in(Region); assert(!r || r->is_Region(), ""); return (RegionNode*)r; }
226
227 bool is_tripcount(BasicType bt) const;
228
229 // Determine a unique non-trivial input, if any.
230 // Ignore casts if it helps. Return null on failure.
231 Node* unique_input(PhaseValues* phase, bool uncast);
232 Node* unique_input(PhaseValues* phase) {
233 Node* uin = unique_input(phase, false);
234 if (uin == nullptr) {
235 uin = unique_input(phase, true);
236 }
237 return uin;
238 }
239 Node* unique_constant_input_recursive(PhaseGVN* phase);
240
241 // Check for a simple dead loop.
242 enum LoopSafety { Safe = 0, Unsafe, UnsafeLoop };
243 LoopSafety simple_data_loop_check(Node *in) const;
244 // Is it unsafe data loop? It becomes a dead loop if this phi node removed.
245 bool is_unsafe_data_reference(Node *in) const;
246 int is_diamond_phi() const;
247 bool try_clean_memory_phi(PhaseIterGVN* igvn);
248 virtual int Opcode() const;
249 virtual bool pinned() const { return in(0) != nullptr; }
250 virtual const TypePtr *adr_type() const { verify_adr_type(true); return _adr_type; }
251
252 void set_inst_mem_id(int inst_mem_id) { _inst_mem_id = inst_mem_id; }
253 int inst_mem_id() const { return _inst_mem_id; }
254 int inst_id() const { return _inst_id; }
255 int inst_index() const { return _inst_index; }
256 int inst_offset() const { return _inst_offset; }
257 bool is_same_inst_field(const Type* tp, int mem_id, int id, int index, int offset) {
258 return type()->basic_type() == tp->basic_type() &&
259 inst_mem_id() == mem_id &&
260 inst_id() == id &&
261 inst_index() == index &&
262 inst_offset() == offset &&
263 type()->higher_equal(tp);
264 }
265
266 bool can_be_inline_type() const {
267 return Arguments::is_valhalla_enabled() && _type->isa_instptr() && _type->is_instptr()->can_be_inline_type();
268 }
269
270 Node* try_push_inline_types_down(PhaseGVN* phase, bool can_reshape);
271 DEBUG_ONLY(bool can_push_inline_types_down(PhaseGVN* phase);)
272
273 virtual const Type* Value(PhaseGVN* phase) const;
274 virtual Node* Identity(PhaseGVN* phase);
275 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
276 virtual const RegMask &out_RegMask() const;
277 virtual const RegMask &in_RegMask(uint) const;
278 #ifndef PRODUCT
279 virtual void dump_spec(outputStream *st) const;
280 #endif
281 #ifdef ASSERT
282 void verify_adr_type(VectorSet& visited, const TypePtr* at) const;
283 void verify_adr_type(bool recursive = false) const;
284 #else //ASSERT
285 void verify_adr_type(bool recursive = false) const {}
286 #endif //ASSERT
287
288 const TypeTuple* collect_types(PhaseGVN* phase) const;
289 };
290
291 //------------------------------GotoNode---------------------------------------
292 // GotoNodes perform direct branches.
464 }
465
466 virtual int Opcode() const;
467 virtual bool pinned() const { return true; }
468 virtual const Type *bottom_type() const { return TypeTuple::IFBOTH; }
469 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
470 virtual const Type* Value(PhaseGVN* phase) const;
471 virtual uint required_outcnt() const { return 2; }
472 virtual const RegMask &out_RegMask() const;
473 Node* fold_compares(PhaseIterGVN* phase);
474 static Node* up_one_dom(Node* curr, bool linear_only = false);
475 bool is_zero_trip_guard() const;
476 Node* dominated_by(Node* prev_dom, PhaseIterGVN* igvn, bool pin_array_access_nodes);
477 ProjNode* uncommon_trap_proj(CallStaticJavaNode*& call, Deoptimization::DeoptReason reason = Deoptimization::Reason_none) const;
478
479 // Takes the type of val and filters it through the test represented
480 // by if_proj and returns a more refined type if one is produced.
481 // Returns null is it couldn't improve the type.
482 static const TypeInt* filtered_int_type(PhaseGVN* phase, Node* val, Node* if_proj);
483
484 bool is_flat_array_check(PhaseTransform* phase, Node** array = nullptr);
485
486 AssertionPredicateType assertion_predicate_type() const {
487 return _assertion_predicate_type;
488 }
489
490 #ifndef PRODUCT
491 virtual void dump_spec(outputStream *st) const;
492 #endif
493
494 bool same_condition(const Node* dom, PhaseIterGVN* igvn) const;
495 };
496
497 class RangeCheckNode : public IfNode {
498 private:
499 int is_range_check(Node*& range, Node*& index, jint& offset);
500
501 public:
502 RangeCheckNode(Node* control, Node* bol, float p, float fcnt) : IfNode(control, bol, p, fcnt) {
503 init_class_id(Class_RangeCheck);
504 }
505
754 virtual int Opcode() const;
755 virtual bool pinned() const { return true; };
756 virtual const Type *bottom_type() const { return TypeTuple::IFBOTH; }
757 virtual const Type* Value(PhaseGVN* phase) const;
758 virtual Node *Ideal(PhaseGVN *phase, bool can_reshape);
759 virtual uint required_outcnt() const { return 2; }
760 virtual void emit(C2_MacroAssembler *masm, PhaseRegAlloc *ra_) const { }
761 virtual uint size(PhaseRegAlloc *ra_) const { return 0; }
762 #ifndef PRODUCT
763 virtual void format( PhaseRegAlloc *, outputStream *st ) const;
764 #endif
765 };
766
767 //------------------------------BlackholeNode----------------------------
768 // Blackhole all arguments. This node would survive through the compiler
769 // the effects on its arguments, and would be finally matched to nothing.
770 class BlackholeNode : public MultiNode {
771 public:
772 BlackholeNode(Node* ctrl) : MultiNode(1) {
773 init_req(TypeFunc::Control, ctrl);
774 init_class_id(Class_Blackhole);
775 }
776 virtual int Opcode() const;
777 virtual uint ideal_reg() const { return 0; } // not matched in the AD file
778 virtual const Type* bottom_type() const { return TypeTuple::MEMBAR; }
779 virtual Node* Ideal(PhaseGVN* phase, bool can_reshape);
780
781 const RegMask &in_RegMask(uint idx) const {
782 // Fake the incoming arguments mask for blackholes: accept all registers
783 // and all stack slots. This would avoid any redundant register moves
784 // for blackhole inputs.
785 return RegMask::ALL;
786 }
787 #ifndef PRODUCT
788 virtual void format(PhaseRegAlloc* ra, outputStream* st) const;
789 #endif
790 };
791
792
793 #endif // SHARE_OPTO_CFGNODE_HPP
|