462 PhaseIterGVN();
463
464 // Reset IGVN: call deconstructor, and placement new.
465 void reset() {
466 this->~PhaseIterGVN();
467 ::new (static_cast<void*>(this)) PhaseIterGVN();
468 }
469
470 // Reset IGVN with another: call deconstructor, and placement new.
471 // Achieves the same as the following (but without move constructors):
472 // igvn = PhaseIterGVN(other);
473 void reset_from_igvn(PhaseIterGVN* other) {
474 if (this != other) {
475 this->~PhaseIterGVN();
476 ::new (static_cast<void*>(this)) PhaseIterGVN(other);
477 }
478 }
479
480 // Idealize new Node 'n' with respect to its inputs and its value
481 virtual Node *transform( Node *a_node );
482 virtual void record_for_igvn(Node *n) { }
483
484 // Iterative worklist. Reference to "C->igvn_worklist()".
485 Unique_Node_List &_worklist;
486
487 // Given def-use info and an initial worklist, apply Node::Ideal,
488 // Node::Value, Node::Identity, hash-based value numbering, Node::Ideal_DU
489 // and dominator info to a fixed point.
490 void optimize();
491 #ifdef ASSERT
492 void verify_optimize();
493 bool verify_Value_for(Node* n, bool strict = false);
494 bool verify_Ideal_for(Node* n, bool can_reshape);
495 bool verify_Identity_for(Node* n);
496 bool verify_node_invariants_for(const Node* n);
497 void verify_empty_worklist(Node* n);
498 #endif
499
500 #ifndef PRODUCT
501 void trace_PhaseIterGVN(Node* n, Node* nn, const Type* old_type);
502 void init_verifyPhaseIterGVN();
538 // direct inputs, so it is necessary to ensure the appropriate
539 // notifications are made here.
540 static void add_users_of_use_to_worklist(Node* n, Node* use, Unique_Node_List& worklist);
541
542 // Add users of 'n', and any other nodes that could be directly
543 // affected by changes to 'n', to the worklist.
544 // Node 'n' may be a node that is about to get replaced. In this
545 // case, 'n' should not be considered part of the new graph.
546 // Passing the old node (as 'n'), rather than the new node,
547 // prevents unnecessary notifications when the new node already
548 // has other users.
549 void add_users_to_worklist(Node* n);
550
551 // Replace old node with new one.
552 void replace_node( Node *old, Node *nn ) {
553 add_users_to_worklist(old);
554 hash_delete(old); // Yank from hash before hacking edges
555 subsume_node(old, nn);
556 }
557
558 // Delayed node rehash: remove a node from the hash table and rehash it during
559 // next optimizing pass
560 void rehash_node_delayed(Node* n) {
561 hash_delete(n);
562 _worklist.push(n);
563 }
564
565 // Replace ith edge of "n" with "in"
566 void replace_input_of(Node* n, uint i, Node* in) {
567 rehash_node_delayed(n);
568 n->set_req_X(i, in, this);
569 }
570
571 // Add "in" as input (req) of "n"
572 void add_input_to(Node* n, Node* in) {
573 rehash_node_delayed(n);
574 n->add_req(in);
575 }
576
577 // Delete ith edge of "n"
633
634 //------------------------------PhaseCCP---------------------------------------
635 // Phase for performing global Conditional Constant Propagation.
636 // Should be replaced with combined CCP & GVN someday.
637 class PhaseCCP : public PhaseIterGVN {
638 Unique_Node_List _root_and_safepoints;
639 Unique_Node_List _maybe_top_type_nodes;
640 // Non-recursive. Use analysis to transform single Node.
641 virtual Node* transform_once(Node* n);
642
643 Node* fetch_next_node(Unique_Node_List& worklist);
644 static void dump_type_and_node(const Node* n, const Type* t) PRODUCT_RETURN;
645
646 void push_child_nodes_to_worklist(Unique_Node_List& worklist, Node* n) const;
647 void push_if_not_bottom_type(Unique_Node_List& worklist, Node* n) const;
648 void push_more_uses(Unique_Node_List& worklist, Node* parent, const Node* use) const;
649 void push_phis(Unique_Node_List& worklist, const Node* use) const;
650 static void push_catch(Unique_Node_List& worklist, const Node* use);
651 void push_cmpu(Unique_Node_List& worklist, const Node* use) const;
652 static void push_counted_loop_phi(Unique_Node_List& worklist, Node* parent, const Node* use);
653 void push_loadp(Unique_Node_List& worklist, const Node* use) const;
654 static void push_load_barrier(Unique_Node_List& worklist, const BarrierSetC2* barrier_set, const Node* use);
655 void push_and(Unique_Node_List& worklist, const Node* parent, const Node* use) const;
656 void push_cast_ii(Unique_Node_List& worklist, const Node* parent, const Node* use) const;
657 void push_opaque_zero_trip_guard(Unique_Node_List& worklist, const Node* use) const;
658 void push_bool_with_cmpu_and_mask(Unique_Node_List& worklist, const Node* use) const;
659 void push_bool_matching_case1b(Unique_Node_List& worklist, const Node* cmpu) const;
660
661 public:
662 PhaseCCP( PhaseIterGVN *igvn ); // Compute conditional constants
663 NOT_PRODUCT( ~PhaseCCP(); )
664
665 // Worklist algorithm identifies constants
666 void analyze();
667 void analyze_step(Unique_Node_List& worklist, Node* n);
668 bool needs_revisit(Node* n) const;
669 #ifdef ASSERT
670 void verify_type(Node* n, const Type* tnew, const Type* told);
671 // For every node n on verify list, check if type(n) == n->Value()
672 void verify_analyze(Unique_Node_List& worklist_verify);
|
462 PhaseIterGVN();
463
464 // Reset IGVN: call deconstructor, and placement new.
465 void reset() {
466 this->~PhaseIterGVN();
467 ::new (static_cast<void*>(this)) PhaseIterGVN();
468 }
469
470 // Reset IGVN with another: call deconstructor, and placement new.
471 // Achieves the same as the following (but without move constructors):
472 // igvn = PhaseIterGVN(other);
473 void reset_from_igvn(PhaseIterGVN* other) {
474 if (this != other) {
475 this->~PhaseIterGVN();
476 ::new (static_cast<void*>(this)) PhaseIterGVN(other);
477 }
478 }
479
480 // Idealize new Node 'n' with respect to its inputs and its value
481 virtual Node *transform( Node *a_node );
482 virtual void record_for_igvn(Node *n) { _worklist.push(n); }
483
484 // Iterative worklist. Reference to "C->igvn_worklist()".
485 Unique_Node_List &_worklist;
486
487 // Given def-use info and an initial worklist, apply Node::Ideal,
488 // Node::Value, Node::Identity, hash-based value numbering, Node::Ideal_DU
489 // and dominator info to a fixed point.
490 void optimize();
491 #ifdef ASSERT
492 void verify_optimize();
493 bool verify_Value_for(Node* n, bool strict = false);
494 bool verify_Ideal_for(Node* n, bool can_reshape);
495 bool verify_Identity_for(Node* n);
496 bool verify_node_invariants_for(const Node* n);
497 void verify_empty_worklist(Node* n);
498 #endif
499
500 #ifndef PRODUCT
501 void trace_PhaseIterGVN(Node* n, Node* nn, const Type* old_type);
502 void init_verifyPhaseIterGVN();
538 // direct inputs, so it is necessary to ensure the appropriate
539 // notifications are made here.
540 static void add_users_of_use_to_worklist(Node* n, Node* use, Unique_Node_List& worklist);
541
542 // Add users of 'n', and any other nodes that could be directly
543 // affected by changes to 'n', to the worklist.
544 // Node 'n' may be a node that is about to get replaced. In this
545 // case, 'n' should not be considered part of the new graph.
546 // Passing the old node (as 'n'), rather than the new node,
547 // prevents unnecessary notifications when the new node already
548 // has other users.
549 void add_users_to_worklist(Node* n);
550
551 // Replace old node with new one.
552 void replace_node( Node *old, Node *nn ) {
553 add_users_to_worklist(old);
554 hash_delete(old); // Yank from hash before hacking edges
555 subsume_node(old, nn);
556 }
557
558 void replace_in_uses(Node* n, Node* m);
559
560 // Delayed node rehash: remove a node from the hash table and rehash it during
561 // next optimizing pass
562 void rehash_node_delayed(Node* n) {
563 hash_delete(n);
564 _worklist.push(n);
565 }
566
567 // Replace ith edge of "n" with "in"
568 void replace_input_of(Node* n, uint i, Node* in) {
569 rehash_node_delayed(n);
570 n->set_req_X(i, in, this);
571 }
572
573 // Add "in" as input (req) of "n"
574 void add_input_to(Node* n, Node* in) {
575 rehash_node_delayed(n);
576 n->add_req(in);
577 }
578
579 // Delete ith edge of "n"
635
636 //------------------------------PhaseCCP---------------------------------------
637 // Phase for performing global Conditional Constant Propagation.
638 // Should be replaced with combined CCP & GVN someday.
639 class PhaseCCP : public PhaseIterGVN {
640 Unique_Node_List _root_and_safepoints;
641 Unique_Node_List _maybe_top_type_nodes;
642 // Non-recursive. Use analysis to transform single Node.
643 virtual Node* transform_once(Node* n);
644
645 Node* fetch_next_node(Unique_Node_List& worklist);
646 static void dump_type_and_node(const Node* n, const Type* t) PRODUCT_RETURN;
647
648 void push_child_nodes_to_worklist(Unique_Node_List& worklist, Node* n) const;
649 void push_if_not_bottom_type(Unique_Node_List& worklist, Node* n) const;
650 void push_more_uses(Unique_Node_List& worklist, Node* parent, const Node* use) const;
651 void push_phis(Unique_Node_List& worklist, const Node* use) const;
652 static void push_catch(Unique_Node_List& worklist, const Node* use);
653 void push_cmpu(Unique_Node_List& worklist, const Node* use) const;
654 static void push_counted_loop_phi(Unique_Node_List& worklist, Node* parent, const Node* use);
655 static void push_cast(Unique_Node_List& worklist, const Node* use);
656 void push_loadp(Unique_Node_List& worklist, const Node* use) const;
657 static void push_load_barrier(Unique_Node_List& worklist, const BarrierSetC2* barrier_set, const Node* use);
658 void push_and(Unique_Node_List& worklist, const Node* parent, const Node* use) const;
659 void push_cast_ii(Unique_Node_List& worklist, const Node* parent, const Node* use) const;
660 void push_opaque_zero_trip_guard(Unique_Node_List& worklist, const Node* use) const;
661 void push_bool_with_cmpu_and_mask(Unique_Node_List& worklist, const Node* use) const;
662 void push_bool_matching_case1b(Unique_Node_List& worklist, const Node* cmpu) const;
663
664 public:
665 PhaseCCP( PhaseIterGVN *igvn ); // Compute conditional constants
666 NOT_PRODUCT( ~PhaseCCP(); )
667
668 // Worklist algorithm identifies constants
669 void analyze();
670 void analyze_step(Unique_Node_List& worklist, Node* n);
671 bool needs_revisit(Node* n) const;
672 #ifdef ASSERT
673 void verify_type(Node* n, const Type* tnew, const Type* told);
674 // For every node n on verify list, check if type(n) == n->Value()
675 void verify_analyze(Unique_Node_List& worklist_verify);
|