1019
1020 //--------------------------find_exact_control---------------------------------
1021 // Skip Proj and CatchProj nodes chains. Check for Null and Top.
1022 Node* Node::find_exact_control(Node* ctrl) {
1023 if (ctrl == NULL && this->is_Region())
1024 ctrl = this->as_Region()->is_copy();
1025
1026 if (ctrl != NULL && ctrl->is_CatchProj()) {
1027 if (ctrl->as_CatchProj()->_con == CatchProjNode::fall_through_index)
1028 ctrl = ctrl->in(0);
1029 if (ctrl != NULL && !ctrl->is_top())
1030 ctrl = ctrl->in(0);
1031 }
1032
1033 if (ctrl != NULL && ctrl->is_Proj())
1034 ctrl = ctrl->in(0);
1035
1036 return ctrl;
1037 }
1038
1039 //--------------------------dominates------------------------------------------
1040 // Helper function for MemNode::all_controls_dominate().
1041 // Check if 'this' control node dominates or equal to 'sub' control node.
1042 bool Node::dominates(Node* sub, Node_List &nlist) {
1043 assert(this->is_CFG(), "expecting control");
1044 assert(sub != NULL && sub->is_CFG(), "expecting control");
1045
1046 Node* orig_sub = sub;
1047 nlist.clear();
1048 bool this_dominates = false;
1049 uint region_input = 0;
1050 while (sub != NULL) { // walk 'sub' up the chain to 'this'
1051 if (sub == this) {
1052 if (nlist.size() == 0) {
1053 // No Region nodes except loops were visited before and the EntryControl
1054 // path was taken for loops: it did not walk in a cycle.
1055 return true;
1056 } else if (!this_dominates) {
1057 // Region nodes were visited. Continue walk up to Start or Root
1058 // to make sure that it did not walk in a cycle.
1059 this_dominates = true; // first time meet
1060 } else {
1061 return false; // already met before: walk in a cycle
1062 }
1063 }
1064 if (sub->is_Start() || sub->is_Root())
1065 return this_dominates;
1066
1067 Node* up = sub->find_exact_control(sub->in(0));
1068 if (up == NULL || up->is_top())
1069 return false; // Conservative answer for dead code
1070
1071 if (sub == up && sub->is_Loop()) {
1072 up = sub->in(0); // in(LoopNode::EntryControl);
1073 } else if (sub == up && sub->is_Region()) {
1074 uint i = 1;
1075 if (nlist.size() == 0) {
1076 // No Region nodes (except Loops) were visited before.
1077 // Take first valid path on the way up to 'this'.
1078 } else if (nlist.at(nlist.size() - 1) == sub) {
1079 // This Region node was just visited. Take other path.
1080 i = region_input + 1;
1081 nlist.pop();
1082 } else {
1083 // Was this Region node visited before?
1084 uint size = nlist.size();
1085 for (uint j = 0; j < size; j++) {
1086 if (nlist.at(j) == sub) {
1087 return false; // The Region node was visited before. Give up.
1088 }
1089 }
1090 // The Region node was not visited before.
1091 // Take first valid path on the way up to 'this'.
1092 }
1093 for (; i < sub->req(); i++) {
1094 Node* in = sub->in(i);
1095 if (in != NULL && !in->is_top() && in != sub) {
1096 break;
1097 }
1098 }
1099 if (i < sub->req()) {
1100 nlist.push(sub);
1101 up = sub->in(i);
1102 region_input = i;
1103 }
1104 }
1105 if (sub == up)
1106 return false; // some kind of tight cycle
1107 if (orig_sub == up)
1108 return false; // walk in a cycle
1109
1110 sub = up;
1111 }
1112 return false;
1113 }
1114
1115 //------------------------------remove_dead_region-----------------------------
1116 // This control node is dead. Follow the subgraph below it making everything
1117 // using it dead as well. This will happen normally via the usual IterGVN
1118 // worklist but this call is more efficient. Do not update use-def info
1119 // inside the dead region, just at the borders.
1120 static bool kill_dead_code( Node *dead, PhaseIterGVN *igvn ) {
1121 // Con's are a popular node to re-hit in the hash table again.
1122 if( dead->is_Con() ) return false;
1123
1124 // Can't put ResourceMark here since igvn->_worklist uses the same arena
1125 // for verify pass with +VerifyOpto and we add/remove elements in it here.
1126 Node_List nstack(Thread::current()->resource_area());
1127
1128 Node *top = igvn->C->top();
1129 bool progress = false;
|
1019
1020 //--------------------------find_exact_control---------------------------------
1021 // Skip Proj and CatchProj nodes chains. Check for Null and Top.
1022 Node* Node::find_exact_control(Node* ctrl) {
1023 if (ctrl == NULL && this->is_Region())
1024 ctrl = this->as_Region()->is_copy();
1025
1026 if (ctrl != NULL && ctrl->is_CatchProj()) {
1027 if (ctrl->as_CatchProj()->_con == CatchProjNode::fall_through_index)
1028 ctrl = ctrl->in(0);
1029 if (ctrl != NULL && !ctrl->is_top())
1030 ctrl = ctrl->in(0);
1031 }
1032
1033 if (ctrl != NULL && ctrl->is_Proj())
1034 ctrl = ctrl->in(0);
1035
1036 return ctrl;
1037 }
1038
1039 #define ITERATIONS_LIMIT 1000
1040
1041 //--------------------------dominates------------------------------------------
1042 // Helper function for MemNode::all_controls_dominate().
1043 // Check if 'this' control node dominates or equal to 'sub' control node.
1044 bool Node::dominates(Node* sub, Node_List &nlist) {
1045 assert(this->is_CFG(), "expecting control");
1046 assert(sub != NULL && sub->is_CFG(), "expecting control");
1047
1048 // detect dead cycle without regions
1049 int iterations_without_region_limit = ITERATIONS_LIMIT;
1050
1051 Node* orig_sub = sub;
1052 nlist.clear();
1053 bool this_dominates = false;
1054 uint region_input = 0;
1055 while (sub != NULL) { // walk 'sub' up the chain to 'this'
1056 if (sub == this) {
1057 if (nlist.size() == 0) {
1058 // No Region nodes except loops were visited before and the EntryControl
1059 // path was taken for loops: it did not walk in a cycle.
1060 return true;
1061 } else if (!this_dominates) {
1062 // Region nodes were visited. Continue walk up to Start or Root
1063 // to make sure that it did not walk in a cycle.
1064 this_dominates = true; // first time meet
1065 iterations_without_region_limit = ITERATIONS_LIMIT; // Reset
1066 } else {
1067 return false; // already met before: walk in a cycle
1068 }
1069 }
1070 if (sub->is_Start() || sub->is_Root())
1071 return this_dominates;
1072
1073 Node* up = sub->find_exact_control(sub->in(0));
1074 if (up == NULL || up->is_top())
1075 return false; // Conservative answer for dead code
1076
1077 if (sub == up && sub->is_Loop()) {
1078 up = sub->in(1); // in(LoopNode::EntryControl);
1079 } else if (sub == up && sub->is_Region() && sub->req() == 3) {
1080 iterations_without_region_limit = ITERATIONS_LIMIT; // Reset
1081 uint i = 1;
1082 uint size = nlist.size();
1083 if (size == 0) {
1084 // No Region nodes (except Loops) were visited before.
1085 // Take first valid path on the way up to 'this'.
1086 } else if (nlist.at(size - 1) == sub) {
1087 // This Region node was just visited. Take other path.
1088 i = region_input + 1;
1089 nlist.pop();
1090 } else {
1091 // Was this Region node visited before?
1092 for (uint j = 0; j < size; j++) {
1093 if (nlist.at(j) == sub) {
1094 return false; // The Region node was visited before. Give up.
1095 }
1096 }
1097 // The Region node was not visited before.
1098 // Take first valid path on the way up to 'this'.
1099 }
1100 for (; i < sub->req(); i++) {
1101 Node* in = sub->in(i);
1102 if (in != NULL && !in->is_top() && in != sub) {
1103 break;
1104 }
1105 }
1106 if (i < sub->req()) {
1107 nlist.push(sub);
1108 up = sub->in(i);
1109 region_input = i;
1110 }
1111 }
1112 if (sub == up)
1113 return false; // some kind of tight cycle
1114
1115 if (--iterations_without_region_limit < 0)
1116 return false; // dead cycle
1117
1118 sub = up;
1119 }
1120 return false;
1121 }
1122
1123 //------------------------------remove_dead_region-----------------------------
1124 // This control node is dead. Follow the subgraph below it making everything
1125 // using it dead as well. This will happen normally via the usual IterGVN
1126 // worklist but this call is more efficient. Do not update use-def info
1127 // inside the dead region, just at the borders.
1128 static bool kill_dead_code( Node *dead, PhaseIterGVN *igvn ) {
1129 // Con's are a popular node to re-hit in the hash table again.
1130 if( dead->is_Con() ) return false;
1131
1132 // Can't put ResourceMark here since igvn->_worklist uses the same arena
1133 // for verify pass with +VerifyOpto and we add/remove elements in it here.
1134 Node_List nstack(Thread::current()->resource_area());
1135
1136 Node *top = igvn->C->top();
1137 bool progress = false;
|