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