466 // igvn = PhaseIterGVN(gvn);
467 void reset_from_gvn(PhaseGVN* gvn) {
468 if (this != gvn) {
469 this->~PhaseIterGVN();
470 ::new (static_cast<void*>(this)) PhaseIterGVN(gvn);
471 }
472 }
473
474 // Reset IGVN with another: call deconstructor, and placement new.
475 // Achieves the same as the following (but without move constructors):
476 // igvn = PhaseIterGVN(other);
477 void reset_from_igvn(PhaseIterGVN* other) {
478 if (this != other) {
479 this->~PhaseIterGVN();
480 ::new (static_cast<void*>(this)) PhaseIterGVN(other);
481 }
482 }
483
484 // Idealize new Node 'n' with respect to its inputs and its value
485 virtual Node *transform( Node *a_node );
486 virtual void record_for_igvn(Node *n) { }
487
488 // Iterative worklist. Reference to "C->igvn_worklist()".
489 Unique_Node_List &_worklist;
490
491 // Given def-use info and an initial worklist, apply Node::Ideal,
492 // Node::Value, Node::Identity, hash-based value numbering, Node::Ideal_DU
493 // and dominator info to a fixed point.
494 void optimize();
495 #ifdef ASSERT
496 void verify_optimize();
497 bool verify_Value_for(Node* n);
498 bool verify_Ideal_for(Node* n, bool can_reshape);
499 bool verify_Identity_for(Node* n);
500 void verify_empty_worklist(Node* n);
501 #endif
502
503 #ifndef PRODUCT
504 void trace_PhaseIterGVN(Node* n, Node* nn, const Type* old_type);
505 void init_verifyPhaseIterGVN();
506 void verify_PhaseIterGVN();
525
526 // Kill all inputs to a dead node, recursively making more dead nodes.
527 // The Node must be dead locally, i.e., have no uses.
528 void remove_dead_node( Node *dead ) {
529 assert(dead->outcnt() == 0 && !dead->is_top(), "node must be dead");
530 remove_globally_dead_node(dead);
531 }
532
533 // Add users of 'n' to worklist
534 static void add_users_to_worklist0(Node* n, Unique_Node_List& worklist);
535 static void add_users_of_use_to_worklist(Node* n, Node* use, Unique_Node_List& worklist);
536 void add_users_to_worklist(Node* n);
537
538 // Replace old node with new one.
539 void replace_node( Node *old, Node *nn ) {
540 add_users_to_worklist(old);
541 hash_delete(old); // Yank from hash before hacking edges
542 subsume_node(old, nn);
543 }
544
545 // Delayed node rehash: remove a node from the hash table and rehash it during
546 // next optimizing pass
547 void rehash_node_delayed(Node* n) {
548 hash_delete(n);
549 _worklist.push(n);
550 }
551
552 // Replace ith edge of "n" with "in"
553 void replace_input_of(Node* n, uint i, Node* in) {
554 rehash_node_delayed(n);
555 n->set_req_X(i, in, this);
556 }
557
558 // Add "in" as input (req) of "n"
559 void add_input_to(Node* n, Node* in) {
560 rehash_node_delayed(n);
561 n->add_req(in);
562 }
563
564 // Delete ith edge of "n"
616
617 //------------------------------PhaseCCP---------------------------------------
618 // Phase for performing global Conditional Constant Propagation.
619 // Should be replaced with combined CCP & GVN someday.
620 class PhaseCCP : public PhaseIterGVN {
621 Unique_Node_List _root_and_safepoints;
622 Unique_Node_List _maybe_top_type_nodes;
623 // Non-recursive. Use analysis to transform single Node.
624 virtual Node* transform_once(Node* n);
625
626 Node* fetch_next_node(Unique_Node_List& worklist);
627 static void dump_type_and_node(const Node* n, const Type* t) PRODUCT_RETURN;
628
629 void push_child_nodes_to_worklist(Unique_Node_List& worklist, Node* n) const;
630 void push_if_not_bottom_type(Unique_Node_List& worklist, Node* n) const;
631 void push_more_uses(Unique_Node_List& worklist, Node* parent, const Node* use) const;
632 void push_phis(Unique_Node_List& worklist, const Node* use) const;
633 static void push_catch(Unique_Node_List& worklist, const Node* use);
634 void push_cmpu(Unique_Node_List& worklist, const Node* use) const;
635 static void push_counted_loop_phi(Unique_Node_List& worklist, Node* parent, const Node* use);
636 void push_loadp(Unique_Node_List& worklist, const Node* use) const;
637 static void push_load_barrier(Unique_Node_List& worklist, const BarrierSetC2* barrier_set, const Node* use);
638 void push_and(Unique_Node_List& worklist, const Node* parent, const Node* use) const;
639 void push_cast_ii(Unique_Node_List& worklist, const Node* parent, const Node* use) const;
640 void push_opaque_zero_trip_guard(Unique_Node_List& worklist, const Node* use) const;
641
642 public:
643 PhaseCCP( PhaseIterGVN *igvn ); // Compute conditional constants
644 NOT_PRODUCT( ~PhaseCCP(); )
645
646 // Worklist algorithm identifies constants
647 void analyze();
648 #ifdef ASSERT
649 void verify_type(Node* n, const Type* tnew, const Type* told);
650 // For every node n on verify list, check if type(n) == n->Value()
651 void verify_analyze(Unique_Node_List& worklist_verify);
652 #endif
653 // Recursive traversal of program. Used analysis to modify program.
654 virtual Node *transform( Node *n );
655 // Do any transformation after analysis
|
466 // igvn = PhaseIterGVN(gvn);
467 void reset_from_gvn(PhaseGVN* gvn) {
468 if (this != gvn) {
469 this->~PhaseIterGVN();
470 ::new (static_cast<void*>(this)) PhaseIterGVN(gvn);
471 }
472 }
473
474 // Reset IGVN with another: call deconstructor, and placement new.
475 // Achieves the same as the following (but without move constructors):
476 // igvn = PhaseIterGVN(other);
477 void reset_from_igvn(PhaseIterGVN* other) {
478 if (this != other) {
479 this->~PhaseIterGVN();
480 ::new (static_cast<void*>(this)) PhaseIterGVN(other);
481 }
482 }
483
484 // Idealize new Node 'n' with respect to its inputs and its value
485 virtual Node *transform( Node *a_node );
486 virtual void record_for_igvn(Node *n) { _worklist.push(n); }
487
488 // Iterative worklist. Reference to "C->igvn_worklist()".
489 Unique_Node_List &_worklist;
490
491 // Given def-use info and an initial worklist, apply Node::Ideal,
492 // Node::Value, Node::Identity, hash-based value numbering, Node::Ideal_DU
493 // and dominator info to a fixed point.
494 void optimize();
495 #ifdef ASSERT
496 void verify_optimize();
497 bool verify_Value_for(Node* n);
498 bool verify_Ideal_for(Node* n, bool can_reshape);
499 bool verify_Identity_for(Node* n);
500 void verify_empty_worklist(Node* n);
501 #endif
502
503 #ifndef PRODUCT
504 void trace_PhaseIterGVN(Node* n, Node* nn, const Type* old_type);
505 void init_verifyPhaseIterGVN();
506 void verify_PhaseIterGVN();
525
526 // Kill all inputs to a dead node, recursively making more dead nodes.
527 // The Node must be dead locally, i.e., have no uses.
528 void remove_dead_node( Node *dead ) {
529 assert(dead->outcnt() == 0 && !dead->is_top(), "node must be dead");
530 remove_globally_dead_node(dead);
531 }
532
533 // Add users of 'n' to worklist
534 static void add_users_to_worklist0(Node* n, Unique_Node_List& worklist);
535 static void add_users_of_use_to_worklist(Node* n, Node* use, Unique_Node_List& worklist);
536 void add_users_to_worklist(Node* n);
537
538 // Replace old node with new one.
539 void replace_node( Node *old, Node *nn ) {
540 add_users_to_worklist(old);
541 hash_delete(old); // Yank from hash before hacking edges
542 subsume_node(old, nn);
543 }
544
545 void replace_in_uses(Node* n, Node* m);
546
547 // Delayed node rehash: remove a node from the hash table and rehash it during
548 // next optimizing pass
549 void rehash_node_delayed(Node* n) {
550 hash_delete(n);
551 _worklist.push(n);
552 }
553
554 // Replace ith edge of "n" with "in"
555 void replace_input_of(Node* n, uint i, Node* in) {
556 rehash_node_delayed(n);
557 n->set_req_X(i, in, this);
558 }
559
560 // Add "in" as input (req) of "n"
561 void add_input_to(Node* n, Node* in) {
562 rehash_node_delayed(n);
563 n->add_req(in);
564 }
565
566 // Delete ith edge of "n"
618
619 //------------------------------PhaseCCP---------------------------------------
620 // Phase for performing global Conditional Constant Propagation.
621 // Should be replaced with combined CCP & GVN someday.
622 class PhaseCCP : public PhaseIterGVN {
623 Unique_Node_List _root_and_safepoints;
624 Unique_Node_List _maybe_top_type_nodes;
625 // Non-recursive. Use analysis to transform single Node.
626 virtual Node* transform_once(Node* n);
627
628 Node* fetch_next_node(Unique_Node_List& worklist);
629 static void dump_type_and_node(const Node* n, const Type* t) PRODUCT_RETURN;
630
631 void push_child_nodes_to_worklist(Unique_Node_List& worklist, Node* n) const;
632 void push_if_not_bottom_type(Unique_Node_List& worklist, Node* n) const;
633 void push_more_uses(Unique_Node_List& worklist, Node* parent, const Node* use) const;
634 void push_phis(Unique_Node_List& worklist, const Node* use) const;
635 static void push_catch(Unique_Node_List& worklist, const Node* use);
636 void push_cmpu(Unique_Node_List& worklist, const Node* use) const;
637 static void push_counted_loop_phi(Unique_Node_List& worklist, Node* parent, const Node* use);
638 static void push_cast(Unique_Node_List& worklist, const Node* use);
639 void push_loadp(Unique_Node_List& worklist, const Node* use) const;
640 static void push_load_barrier(Unique_Node_List& worklist, const BarrierSetC2* barrier_set, const Node* use);
641 void push_and(Unique_Node_List& worklist, const Node* parent, const Node* use) const;
642 void push_cast_ii(Unique_Node_List& worklist, const Node* parent, const Node* use) const;
643 void push_opaque_zero_trip_guard(Unique_Node_List& worklist, const Node* use) const;
644
645 public:
646 PhaseCCP( PhaseIterGVN *igvn ); // Compute conditional constants
647 NOT_PRODUCT( ~PhaseCCP(); )
648
649 // Worklist algorithm identifies constants
650 void analyze();
651 #ifdef ASSERT
652 void verify_type(Node* n, const Type* tnew, const Type* told);
653 // For every node n on verify list, check if type(n) == n->Value()
654 void verify_analyze(Unique_Node_List& worklist_verify);
655 #endif
656 // Recursive traversal of program. Used analysis to modify program.
657 virtual Node *transform( Node *n );
658 // Do any transformation after analysis
|