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_node_value(Node* n);
498 #endif
499
500 #ifndef PRODUCT
501 void trace_PhaseIterGVN(Node* n, Node* nn, const Type* old_type);
502 void init_verifyPhaseIterGVN();
503 void verify_PhaseIterGVN();
504 #endif
505
506 #ifdef ASSERT
522
523 // Kill all inputs to a dead node, recursively making more dead nodes.
524 // The Node must be dead locally, i.e., have no uses.
525 void remove_dead_node( Node *dead ) {
526 assert(dead->outcnt() == 0 && !dead->is_top(), "node must be dead");
527 remove_globally_dead_node(dead);
528 }
529
530 // Add users of 'n' to worklist
531 static void add_users_to_worklist0(Node* n, Unique_Node_List& worklist);
532 static void add_users_of_use_to_worklist(Node* n, Node* use, Unique_Node_List& worklist);
533 void add_users_to_worklist(Node* n);
534
535 // Replace old node with new one.
536 void replace_node( Node *old, Node *nn ) {
537 add_users_to_worklist(old);
538 hash_delete(old); // Yank from hash before hacking edges
539 subsume_node(old, nn);
540 }
541
542 // Delayed node rehash: remove a node from the hash table and rehash it during
543 // next optimizing pass
544 void rehash_node_delayed(Node* n) {
545 hash_delete(n);
546 _worklist.push(n);
547 }
548
549 // Replace ith edge of "n" with "in"
550 void replace_input_of(Node* n, uint i, Node* in) {
551 rehash_node_delayed(n);
552 n->set_req_X(i, in, this);
553 }
554
555 // Add "in" as input (req) of "n"
556 void add_input_to(Node* n, Node* in) {
557 rehash_node_delayed(n);
558 n->add_req(in);
559 }
560
561 // Delete ith edge of "n"
604 };
605
606 //------------------------------PhaseCCP---------------------------------------
607 // Phase for performing global Conditional Constant Propagation.
608 // Should be replaced with combined CCP & GVN someday.
609 class PhaseCCP : public PhaseIterGVN {
610 Unique_Node_List _root_and_safepoints;
611 // Non-recursive. Use analysis to transform single Node.
612 virtual Node* transform_once(Node* n);
613
614 Node* fetch_next_node(Unique_Node_List& worklist);
615 static void dump_type_and_node(const Node* n, const Type* t) PRODUCT_RETURN;
616
617 void push_child_nodes_to_worklist(Unique_Node_List& worklist, Node* n) const;
618 void push_if_not_bottom_type(Unique_Node_List& worklist, Node* n) const;
619 void push_more_uses(Unique_Node_List& worklist, Node* parent, const Node* use) const;
620 void push_phis(Unique_Node_List& worklist, const Node* use) const;
621 static void push_catch(Unique_Node_List& worklist, const Node* use);
622 void push_cmpu(Unique_Node_List& worklist, const Node* use) const;
623 static void push_counted_loop_phi(Unique_Node_List& worklist, Node* parent, const Node* use);
624 void push_loadp(Unique_Node_List& worklist, const Node* use) const;
625 static void push_load_barrier(Unique_Node_List& worklist, const BarrierSetC2* barrier_set, const Node* use);
626 void push_and(Unique_Node_List& worklist, const Node* parent, const Node* use) const;
627 void push_cast_ii(Unique_Node_List& worklist, const Node* parent, const Node* use) const;
628 void push_opaque_zero_trip_guard(Unique_Node_List& worklist, const Node* use) const;
629
630 public:
631 PhaseCCP( PhaseIterGVN *igvn ); // Compute conditional constants
632 NOT_PRODUCT( ~PhaseCCP(); )
633
634 // Worklist algorithm identifies constants
635 void analyze();
636 #ifdef ASSERT
637 void verify_type(Node* n, const Type* tnew, const Type* told);
638 // For every node n on verify list, check if type(n) == n->Value()
639 void verify_analyze(Unique_Node_List& worklist_verify);
640 #endif
641 // Recursive traversal of program. Used analysis to modify program.
642 virtual Node *transform( Node *n );
643 // 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_node_value(Node* n);
498 #endif
499
500 #ifndef PRODUCT
501 void trace_PhaseIterGVN(Node* n, Node* nn, const Type* old_type);
502 void init_verifyPhaseIterGVN();
503 void verify_PhaseIterGVN();
504 #endif
505
506 #ifdef ASSERT
522
523 // Kill all inputs to a dead node, recursively making more dead nodes.
524 // The Node must be dead locally, i.e., have no uses.
525 void remove_dead_node( Node *dead ) {
526 assert(dead->outcnt() == 0 && !dead->is_top(), "node must be dead");
527 remove_globally_dead_node(dead);
528 }
529
530 // Add users of 'n' to worklist
531 static void add_users_to_worklist0(Node* n, Unique_Node_List& worklist);
532 static void add_users_of_use_to_worklist(Node* n, Node* use, Unique_Node_List& worklist);
533 void add_users_to_worklist(Node* n);
534
535 // Replace old node with new one.
536 void replace_node( Node *old, Node *nn ) {
537 add_users_to_worklist(old);
538 hash_delete(old); // Yank from hash before hacking edges
539 subsume_node(old, nn);
540 }
541
542 void replace_in_uses(Node* n, Node* m);
543
544 // Delayed node rehash: remove a node from the hash table and rehash it during
545 // next optimizing pass
546 void rehash_node_delayed(Node* n) {
547 hash_delete(n);
548 _worklist.push(n);
549 }
550
551 // Replace ith edge of "n" with "in"
552 void replace_input_of(Node* n, uint i, Node* in) {
553 rehash_node_delayed(n);
554 n->set_req_X(i, in, this);
555 }
556
557 // Add "in" as input (req) of "n"
558 void add_input_to(Node* n, Node* in) {
559 rehash_node_delayed(n);
560 n->add_req(in);
561 }
562
563 // Delete ith edge of "n"
606 };
607
608 //------------------------------PhaseCCP---------------------------------------
609 // Phase for performing global Conditional Constant Propagation.
610 // Should be replaced with combined CCP & GVN someday.
611 class PhaseCCP : public PhaseIterGVN {
612 Unique_Node_List _root_and_safepoints;
613 // Non-recursive. Use analysis to transform single Node.
614 virtual Node* transform_once(Node* n);
615
616 Node* fetch_next_node(Unique_Node_List& worklist);
617 static void dump_type_and_node(const Node* n, const Type* t) PRODUCT_RETURN;
618
619 void push_child_nodes_to_worklist(Unique_Node_List& worklist, Node* n) const;
620 void push_if_not_bottom_type(Unique_Node_List& worklist, Node* n) const;
621 void push_more_uses(Unique_Node_List& worklist, Node* parent, const Node* use) const;
622 void push_phis(Unique_Node_List& worklist, const Node* use) const;
623 static void push_catch(Unique_Node_List& worklist, const Node* use);
624 void push_cmpu(Unique_Node_List& worklist, const Node* use) const;
625 static void push_counted_loop_phi(Unique_Node_List& worklist, Node* parent, const Node* use);
626 static void push_cast(Unique_Node_List& worklist, const Node* use);
627 void push_loadp(Unique_Node_List& worklist, const Node* use) const;
628 static void push_load_barrier(Unique_Node_List& worklist, const BarrierSetC2* barrier_set, const Node* use);
629 void push_and(Unique_Node_List& worklist, const Node* parent, const Node* use) const;
630 void push_cast_ii(Unique_Node_List& worklist, const Node* parent, const Node* use) const;
631 void push_opaque_zero_trip_guard(Unique_Node_List& worklist, const Node* use) const;
632
633 public:
634 PhaseCCP( PhaseIterGVN *igvn ); // Compute conditional constants
635 NOT_PRODUCT( ~PhaseCCP(); )
636
637 // Worklist algorithm identifies constants
638 void analyze();
639 #ifdef ASSERT
640 void verify_type(Node* n, const Type* tnew, const Type* told);
641 // For every node n on verify list, check if type(n) == n->Value()
642 void verify_analyze(Unique_Node_List& worklist_verify);
643 #endif
644 // Recursive traversal of program. Used analysis to modify program.
645 virtual Node *transform( Node *n );
646 // Do any transformation after analysis
|