1 /*
2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
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 *
547
548 // disconnect this block from it's current successors
549 for (int i = 0; i < _successors.length(); i++) {
550 _successors.at(i)->remove_predecessor(this);
551 }
552 _end = NULL;
553 }
554 }
555
556
557 void BlockBegin::disconnect_edge(BlockBegin* from, BlockBegin* to) {
558 // disconnect any edges between from and to
559 #ifndef PRODUCT
560 if (PrintIR && Verbose) {
561 tty->print_cr("Disconnected edge B%d -> B%d", from->block_id(), to->block_id());
562 }
563 #endif
564 for (int s = 0; s < from->number_of_sux();) {
565 BlockBegin* sux = from->sux_at(s);
566 if (sux == to) {
567 int index = sux->_predecessors.index_of(from);
568 if (index >= 0) {
569 sux->_predecessors.remove_at(index);
570 }
571 from->_successors.remove_at(s);
572 } else {
573 s++;
574 }
575 }
576 }
577
578
579 void BlockBegin::disconnect_from_graph() {
580 // disconnect this block from all other blocks
581 for (int p = 0; p < number_of_preds(); p++) {
582 pred_at(p)->remove_successor(this);
583 }
584 for (int s = 0; s < number_of_sux(); s++) {
585 sux_at(s)->remove_predecessor(this);
586 }
587 }
647 if (*b == this) {
648 if (assigned) {
649 list.remove_at(i);
650 // reprocess this index
651 i--;
652 } else {
653 assigned = true;
654 *b = new_sux;
655 }
656 // link the new block back to it's predecessors.
657 new_sux->add_predecessor(this);
658 }
659 }
660 assert(assigned == true, "should have assigned at least once");
661 return new_sux;
662 }
663
664
665 void BlockBegin::remove_successor(BlockBegin* pred) {
666 int idx;
667 while ((idx = _successors.index_of(pred)) >= 0) {
668 _successors.remove_at(idx);
669 }
670 }
671
672
673 void BlockBegin::add_predecessor(BlockBegin* pred) {
674 _predecessors.append(pred);
675 }
676
677
678 void BlockBegin::remove_predecessor(BlockBegin* pred) {
679 int idx;
680 while ((idx = _predecessors.index_of(pred)) >= 0) {
681 _predecessors.remove_at(idx);
682 }
683 }
684
685
686 void BlockBegin::add_exception_handler(BlockBegin* b) {
687 assert(b != NULL && (b->is_set(exception_entry_flag)), "exception handler must exist");
688 // add only if not in the list already
689 if (!_exception_handlers.contains(b)) _exception_handlers.append(b);
690 }
691
692 int BlockBegin::add_exception_state(ValueStack* state) {
693 assert(is_set(exception_entry_flag), "only for xhandlers");
694 if (_exception_states == NULL) {
695 _exception_states = new ValueStackStack(4);
696 }
697 _exception_states->append(state);
698 return _exception_states->length() - 1;
699 }
700
705 closure->block_do(this);
706 BlockEnd* e = end(); // must do this after block_do because block_do may change it!
707 { for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_preorder(mark, closure); }
708 { for (int i = e->number_of_sux () - 1; i >= 0; i--) e->sux_at (i)->iterate_preorder(mark, closure); }
709 }
710 }
711
712
713 void BlockBegin::iterate_postorder(boolArray& mark, BlockClosure* closure) {
714 if (!mark.at(block_id())) {
715 mark.at_put(block_id(), true);
716 BlockEnd* e = end();
717 { for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_postorder(mark, closure); }
718 { for (int i = e->number_of_sux () - 1; i >= 0; i--) e->sux_at (i)->iterate_postorder(mark, closure); }
719 closure->block_do(this);
720 }
721 }
722
723
724 void BlockBegin::iterate_preorder(BlockClosure* closure) {
725 boolArray mark(number_of_blocks(), false);
726 iterate_preorder(mark, closure);
727 }
728
729
730 void BlockBegin::iterate_postorder(BlockClosure* closure) {
731 boolArray mark(number_of_blocks(), false);
732 iterate_postorder(mark, closure);
733 }
734
735
736 void BlockBegin::block_values_do(ValueVisitor* f) {
737 for (Instruction* n = this; n != NULL; n = n->next()) n->values_do(f);
738 }
739
740
741 #ifndef PRODUCT
742 #define TRACE_PHI(code) if (PrintPhiFunctions) { code; }
743 #else
744 #define TRACE_PHI(coce)
745 #endif
746
747
748 bool BlockBegin::try_merge(ValueStack* new_state) {
749 TRACE_PHI(tty->print_cr("********** try_merge for block B%d", block_id()));
750
751 // local variables used for state iteration
|
1 /*
2 * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
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 *
547
548 // disconnect this block from it's current successors
549 for (int i = 0; i < _successors.length(); i++) {
550 _successors.at(i)->remove_predecessor(this);
551 }
552 _end = NULL;
553 }
554 }
555
556
557 void BlockBegin::disconnect_edge(BlockBegin* from, BlockBegin* to) {
558 // disconnect any edges between from and to
559 #ifndef PRODUCT
560 if (PrintIR && Verbose) {
561 tty->print_cr("Disconnected edge B%d -> B%d", from->block_id(), to->block_id());
562 }
563 #endif
564 for (int s = 0; s < from->number_of_sux();) {
565 BlockBegin* sux = from->sux_at(s);
566 if (sux == to) {
567 int index = sux->_predecessors.find(from);
568 if (index >= 0) {
569 sux->_predecessors.remove_at(index);
570 }
571 from->_successors.remove_at(s);
572 } else {
573 s++;
574 }
575 }
576 }
577
578
579 void BlockBegin::disconnect_from_graph() {
580 // disconnect this block from all other blocks
581 for (int p = 0; p < number_of_preds(); p++) {
582 pred_at(p)->remove_successor(this);
583 }
584 for (int s = 0; s < number_of_sux(); s++) {
585 sux_at(s)->remove_predecessor(this);
586 }
587 }
647 if (*b == this) {
648 if (assigned) {
649 list.remove_at(i);
650 // reprocess this index
651 i--;
652 } else {
653 assigned = true;
654 *b = new_sux;
655 }
656 // link the new block back to it's predecessors.
657 new_sux->add_predecessor(this);
658 }
659 }
660 assert(assigned == true, "should have assigned at least once");
661 return new_sux;
662 }
663
664
665 void BlockBegin::remove_successor(BlockBegin* pred) {
666 int idx;
667 while ((idx = _successors.find(pred)) >= 0) {
668 _successors.remove_at(idx);
669 }
670 }
671
672
673 void BlockBegin::add_predecessor(BlockBegin* pred) {
674 _predecessors.append(pred);
675 }
676
677
678 void BlockBegin::remove_predecessor(BlockBegin* pred) {
679 int idx;
680 while ((idx = _predecessors.find(pred)) >= 0) {
681 _predecessors.remove_at(idx);
682 }
683 }
684
685
686 void BlockBegin::add_exception_handler(BlockBegin* b) {
687 assert(b != NULL && (b->is_set(exception_entry_flag)), "exception handler must exist");
688 // add only if not in the list already
689 if (!_exception_handlers.contains(b)) _exception_handlers.append(b);
690 }
691
692 int BlockBegin::add_exception_state(ValueStack* state) {
693 assert(is_set(exception_entry_flag), "only for xhandlers");
694 if (_exception_states == NULL) {
695 _exception_states = new ValueStackStack(4);
696 }
697 _exception_states->append(state);
698 return _exception_states->length() - 1;
699 }
700
705 closure->block_do(this);
706 BlockEnd* e = end(); // must do this after block_do because block_do may change it!
707 { for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_preorder(mark, closure); }
708 { for (int i = e->number_of_sux () - 1; i >= 0; i--) e->sux_at (i)->iterate_preorder(mark, closure); }
709 }
710 }
711
712
713 void BlockBegin::iterate_postorder(boolArray& mark, BlockClosure* closure) {
714 if (!mark.at(block_id())) {
715 mark.at_put(block_id(), true);
716 BlockEnd* e = end();
717 { for (int i = number_of_exception_handlers() - 1; i >= 0; i--) exception_handler_at(i)->iterate_postorder(mark, closure); }
718 { for (int i = e->number_of_sux () - 1; i >= 0; i--) e->sux_at (i)->iterate_postorder(mark, closure); }
719 closure->block_do(this);
720 }
721 }
722
723
724 void BlockBegin::iterate_preorder(BlockClosure* closure) {
725 int mark_len = number_of_blocks();
726 boolArray mark(mark_len, mark_len, false);
727 iterate_preorder(mark, closure);
728 }
729
730
731 void BlockBegin::iterate_postorder(BlockClosure* closure) {
732 int mark_len = number_of_blocks();
733 boolArray mark(mark_len, mark_len, false);
734 iterate_postorder(mark, closure);
735 }
736
737
738 void BlockBegin::block_values_do(ValueVisitor* f) {
739 for (Instruction* n = this; n != NULL; n = n->next()) n->values_do(f);
740 }
741
742
743 #ifndef PRODUCT
744 #define TRACE_PHI(code) if (PrintPhiFunctions) { code; }
745 #else
746 #define TRACE_PHI(coce)
747 #endif
748
749
750 bool BlockBegin::try_merge(ValueStack* new_state) {
751 TRACE_PHI(tty->print_cr("********** try_merge for block B%d", block_id()));
752
753 // local variables used for state iteration
|