Mercurial > hg > graal-jvmci-8
comparison src/share/vm/opto/gcm.cpp @ 12167:650868c062a9
8023691: Create interface for nodes in class Block
Summary: Create public methods for accessing the nodes in a block
Reviewed-by: kvn, roland
author | adlertz |
---|---|
date | Mon, 26 Aug 2013 12:50:23 +0200 |
parents | adb9a7d94cb5 |
children | 4b078f877b56 |
comparison
equal
deleted
inserted
replaced
12161:e1fbb86b47e4 | 12167:650868c062a9 |
---|---|
100 // Find trailing Region | 100 // Find trailing Region |
101 Block *pb = get_block_for_node(in0); // Block-projection already has basic block | 101 Block *pb = get_block_for_node(in0); // Block-projection already has basic block |
102 uint j = 0; | 102 uint j = 0; |
103 if (pb->_num_succs != 1) { // More then 1 successor? | 103 if (pb->_num_succs != 1) { // More then 1 successor? |
104 // Search for successor | 104 // Search for successor |
105 uint max = pb->_nodes.size(); | 105 uint max = pb->number_of_nodes(); |
106 assert( max > 1, "" ); | 106 assert( max > 1, "" ); |
107 uint start = max - pb->_num_succs; | 107 uint start = max - pb->_num_succs; |
108 // Find which output path belongs to projection | 108 // Find which output path belongs to projection |
109 for (j = start; j < max; j++) { | 109 for (j = start; j < max; j++) { |
110 if( pb->_nodes[j] == in0 ) | 110 if( pb->get_node(j) == in0 ) |
111 break; | 111 break; |
112 } | 112 } |
113 assert( j < max, "must find" ); | 113 assert( j < max, "must find" ); |
114 // Change control to match head of successor basic block | 114 // Change control to match head of successor basic block |
115 j -= start; | 115 j -= start; |
1025 Block* PhaseCFG::hoist_to_cheaper_block(Block* LCA, Block* early, Node* self) { | 1025 Block* PhaseCFG::hoist_to_cheaper_block(Block* LCA, Block* early, Node* self) { |
1026 const double delta = 1+PROB_UNLIKELY_MAG(4); | 1026 const double delta = 1+PROB_UNLIKELY_MAG(4); |
1027 Block* least = LCA; | 1027 Block* least = LCA; |
1028 double least_freq = least->_freq; | 1028 double least_freq = least->_freq; |
1029 uint target = get_latency_for_node(self); | 1029 uint target = get_latency_for_node(self); |
1030 uint start_latency = get_latency_for_node(LCA->_nodes[0]); | 1030 uint start_latency = get_latency_for_node(LCA->head()); |
1031 uint end_latency = get_latency_for_node(LCA->_nodes[LCA->end_idx()]); | 1031 uint end_latency = get_latency_for_node(LCA->get_node(LCA->end_idx())); |
1032 bool in_latency = (target <= start_latency); | 1032 bool in_latency = (target <= start_latency); |
1033 const Block* root_block = get_block_for_node(_root); | 1033 const Block* root_block = get_block_for_node(_root); |
1034 | 1034 |
1035 // Turn off latency scheduling if scheduling is just plain off | 1035 // Turn off latency scheduling if scheduling is just plain off |
1036 if (!C->do_scheduling()) | 1036 if (!C->do_scheduling()) |
1047 if (trace_opto_pipelining()) { | 1047 if (trace_opto_pipelining()) { |
1048 tty->print("# Find cheaper block for latency %d: ", get_latency_for_node(self)); | 1048 tty->print("# Find cheaper block for latency %d: ", get_latency_for_node(self)); |
1049 self->dump(); | 1049 self->dump(); |
1050 tty->print_cr("# B%d: start latency for [%4d]=%d, end latency for [%4d]=%d, freq=%g", | 1050 tty->print_cr("# B%d: start latency for [%4d]=%d, end latency for [%4d]=%d, freq=%g", |
1051 LCA->_pre_order, | 1051 LCA->_pre_order, |
1052 LCA->_nodes[0]->_idx, | 1052 LCA->head()->_idx, |
1053 start_latency, | 1053 start_latency, |
1054 LCA->_nodes[LCA->end_idx()]->_idx, | 1054 LCA->get_node(LCA->end_idx())->_idx, |
1055 end_latency, | 1055 end_latency, |
1056 least_freq); | 1056 least_freq); |
1057 } | 1057 } |
1058 #endif | 1058 #endif |
1059 | 1059 |
1072 | 1072 |
1073 // Don't hoist machine instructions to the root basic block | 1073 // Don't hoist machine instructions to the root basic block |
1074 if (mach && LCA == root_block) | 1074 if (mach && LCA == root_block) |
1075 break; | 1075 break; |
1076 | 1076 |
1077 uint start_lat = get_latency_for_node(LCA->_nodes[0]); | 1077 uint start_lat = get_latency_for_node(LCA->head()); |
1078 uint end_idx = LCA->end_idx(); | 1078 uint end_idx = LCA->end_idx(); |
1079 uint end_lat = get_latency_for_node(LCA->_nodes[end_idx]); | 1079 uint end_lat = get_latency_for_node(LCA->get_node(end_idx)); |
1080 double LCA_freq = LCA->_freq; | 1080 double LCA_freq = LCA->_freq; |
1081 #ifndef PRODUCT | 1081 #ifndef PRODUCT |
1082 if (trace_opto_pipelining()) { | 1082 if (trace_opto_pipelining()) { |
1083 tty->print_cr("# B%d: start latency for [%4d]=%d, end latency for [%4d]=%d, freq=%g", | 1083 tty->print_cr("# B%d: start latency for [%4d]=%d, end latency for [%4d]=%d, freq=%g", |
1084 LCA->_pre_order, LCA->_nodes[0]->_idx, start_lat, end_idx, end_lat, LCA_freq); | 1084 LCA->_pre_order, LCA->head()->_idx, start_lat, end_idx, end_lat, LCA_freq); |
1085 } | 1085 } |
1086 #endif | 1086 #endif |
1087 cand_cnt++; | 1087 cand_cnt++; |
1088 if (LCA_freq < least_freq || // Better Frequency | 1088 if (LCA_freq < least_freq || // Better Frequency |
1089 (StressGCM && Compile::randomized_select(cand_cnt)) || // Should be randomly accepted in stress mode | 1089 (StressGCM && Compile::randomized_select(cand_cnt)) || // Should be randomly accepted in stress mode |
1724 | 1724 |
1725 //------------------------------succ_prob------------------------------------- | 1725 //------------------------------succ_prob------------------------------------- |
1726 // Determine the probability of reaching successor 'i' from the receiver block. | 1726 // Determine the probability of reaching successor 'i' from the receiver block. |
1727 float Block::succ_prob(uint i) { | 1727 float Block::succ_prob(uint i) { |
1728 int eidx = end_idx(); | 1728 int eidx = end_idx(); |
1729 Node *n = _nodes[eidx]; // Get ending Node | 1729 Node *n = get_node(eidx); // Get ending Node |
1730 | 1730 |
1731 int op = n->Opcode(); | 1731 int op = n->Opcode(); |
1732 if (n->is_Mach()) { | 1732 if (n->is_Mach()) { |
1733 if (n->is_MachNullCheck()) { | 1733 if (n->is_MachNullCheck()) { |
1734 // Can only reach here if called after lcm. The original Op_If is gone, | 1734 // Can only reach here if called after lcm. The original Op_If is gone, |
1759 assert (i < 2, "just checking"); | 1759 assert (i < 2, "just checking"); |
1760 // Conditionals pass on only part of their frequency | 1760 // Conditionals pass on only part of their frequency |
1761 float prob = n->as_MachIf()->_prob; | 1761 float prob = n->as_MachIf()->_prob; |
1762 assert(prob >= 0.0 && prob <= 1.0, "out of range probability"); | 1762 assert(prob >= 0.0 && prob <= 1.0, "out of range probability"); |
1763 // If succ[i] is the FALSE branch, invert path info | 1763 // If succ[i] is the FALSE branch, invert path info |
1764 if( _nodes[i + eidx + 1]->Opcode() == Op_IfFalse ) { | 1764 if( get_node(i + eidx + 1)->Opcode() == Op_IfFalse ) { |
1765 return 1.0f - prob; // not taken | 1765 return 1.0f - prob; // not taken |
1766 } else { | 1766 } else { |
1767 return prob; // taken | 1767 return prob; // taken |
1768 } | 1768 } |
1769 } | 1769 } |
1771 case Op_Jump: | 1771 case Op_Jump: |
1772 // Divide the frequency between all successors evenly | 1772 // Divide the frequency between all successors evenly |
1773 return 1.0f/_num_succs; | 1773 return 1.0f/_num_succs; |
1774 | 1774 |
1775 case Op_Catch: { | 1775 case Op_Catch: { |
1776 const CatchProjNode *ci = _nodes[i + eidx + 1]->as_CatchProj(); | 1776 const CatchProjNode *ci = get_node(i + eidx + 1)->as_CatchProj(); |
1777 if (ci->_con == CatchProjNode::fall_through_index) { | 1777 if (ci->_con == CatchProjNode::fall_through_index) { |
1778 // Fall-thru path gets the lion's share. | 1778 // Fall-thru path gets the lion's share. |
1779 return 1.0f - PROB_UNLIKELY_MAG(5)*_num_succs; | 1779 return 1.0f - PROB_UNLIKELY_MAG(5)*_num_succs; |
1780 } else { | 1780 } else { |
1781 // Presume exceptional paths are equally unlikely | 1781 // Presume exceptional paths are equally unlikely |
1808 | 1808 |
1809 //------------------------------num_fall_throughs----------------------------- | 1809 //------------------------------num_fall_throughs----------------------------- |
1810 // Return the number of fall-through candidates for a block | 1810 // Return the number of fall-through candidates for a block |
1811 int Block::num_fall_throughs() { | 1811 int Block::num_fall_throughs() { |
1812 int eidx = end_idx(); | 1812 int eidx = end_idx(); |
1813 Node *n = _nodes[eidx]; // Get ending Node | 1813 Node *n = get_node(eidx); // Get ending Node |
1814 | 1814 |
1815 int op = n->Opcode(); | 1815 int op = n->Opcode(); |
1816 if (n->is_Mach()) { | 1816 if (n->is_Mach()) { |
1817 if (n->is_MachNullCheck()) { | 1817 if (n->is_MachNullCheck()) { |
1818 // In theory, either side can fall-thru, for simplicity sake, | 1818 // In theory, either side can fall-thru, for simplicity sake, |
1832 case Op_Goto: | 1832 case Op_Goto: |
1833 return 1; | 1833 return 1; |
1834 | 1834 |
1835 case Op_Catch: { | 1835 case Op_Catch: { |
1836 for (uint i = 0; i < _num_succs; i++) { | 1836 for (uint i = 0; i < _num_succs; i++) { |
1837 const CatchProjNode *ci = _nodes[i + eidx + 1]->as_CatchProj(); | 1837 const CatchProjNode *ci = get_node(i + eidx + 1)->as_CatchProj(); |
1838 if (ci->_con == CatchProjNode::fall_through_index) { | 1838 if (ci->_con == CatchProjNode::fall_through_index) { |
1839 return 1; | 1839 return 1; |
1840 } | 1840 } |
1841 } | 1841 } |
1842 return 0; | 1842 return 0; |
1860 | 1860 |
1861 //------------------------------succ_fall_through----------------------------- | 1861 //------------------------------succ_fall_through----------------------------- |
1862 // Return true if a specific successor could be fall-through target. | 1862 // Return true if a specific successor could be fall-through target. |
1863 bool Block::succ_fall_through(uint i) { | 1863 bool Block::succ_fall_through(uint i) { |
1864 int eidx = end_idx(); | 1864 int eidx = end_idx(); |
1865 Node *n = _nodes[eidx]; // Get ending Node | 1865 Node *n = get_node(eidx); // Get ending Node |
1866 | 1866 |
1867 int op = n->Opcode(); | 1867 int op = n->Opcode(); |
1868 if (n->is_Mach()) { | 1868 if (n->is_Mach()) { |
1869 if (n->is_MachNullCheck()) { | 1869 if (n->is_MachNullCheck()) { |
1870 // In theory, either side can fall-thru, for simplicity sake, | 1870 // In theory, either side can fall-thru, for simplicity sake, |
1871 // let's say only the false branch can now. | 1871 // let's say only the false branch can now. |
1872 return _nodes[i + eidx + 1]->Opcode() == Op_IfFalse; | 1872 return get_node(i + eidx + 1)->Opcode() == Op_IfFalse; |
1873 } | 1873 } |
1874 op = n->as_Mach()->ideal_Opcode(); | 1874 op = n->as_Mach()->ideal_Opcode(); |
1875 } | 1875 } |
1876 | 1876 |
1877 // Switch on branch type | 1877 // Switch on branch type |
1881 case Op_Root: | 1881 case Op_Root: |
1882 case Op_Goto: | 1882 case Op_Goto: |
1883 return true; | 1883 return true; |
1884 | 1884 |
1885 case Op_Catch: { | 1885 case Op_Catch: { |
1886 const CatchProjNode *ci = _nodes[i + eidx + 1]->as_CatchProj(); | 1886 const CatchProjNode *ci = get_node(i + eidx + 1)->as_CatchProj(); |
1887 return ci->_con == CatchProjNode::fall_through_index; | 1887 return ci->_con == CatchProjNode::fall_through_index; |
1888 } | 1888 } |
1889 | 1889 |
1890 case Op_Jump: | 1890 case Op_Jump: |
1891 case Op_NeverBranch: | 1891 case Op_NeverBranch: |
1905 | 1905 |
1906 //------------------------------update_uncommon_branch------------------------ | 1906 //------------------------------update_uncommon_branch------------------------ |
1907 // Update the probability of a two-branch to be uncommon | 1907 // Update the probability of a two-branch to be uncommon |
1908 void Block::update_uncommon_branch(Block* ub) { | 1908 void Block::update_uncommon_branch(Block* ub) { |
1909 int eidx = end_idx(); | 1909 int eidx = end_idx(); |
1910 Node *n = _nodes[eidx]; // Get ending Node | 1910 Node *n = get_node(eidx); // Get ending Node |
1911 | 1911 |
1912 int op = n->as_Mach()->ideal_Opcode(); | 1912 int op = n->as_Mach()->ideal_Opcode(); |
1913 | 1913 |
1914 assert(op == Op_CountedLoopEnd || op == Op_If, "must be a If"); | 1914 assert(op == Op_CountedLoopEnd || op == Op_If, "must be a If"); |
1915 assert(num_fall_throughs() == 2, "must be a two way branch block"); | 1915 assert(num_fall_throughs() == 2, "must be a two way branch block"); |
1921 } | 1921 } |
1922 assert(s < 2, "uncommon successor must be found"); | 1922 assert(s < 2, "uncommon successor must be found"); |
1923 | 1923 |
1924 // If ub is the true path, make the proability small, else | 1924 // If ub is the true path, make the proability small, else |
1925 // ub is the false path, and make the probability large | 1925 // ub is the false path, and make the probability large |
1926 bool invert = (_nodes[s + eidx + 1]->Opcode() == Op_IfFalse); | 1926 bool invert = (get_node(s + eidx + 1)->Opcode() == Op_IfFalse); |
1927 | 1927 |
1928 // Get existing probability | 1928 // Get existing probability |
1929 float p = n->as_MachIf()->_prob; | 1929 float p = n->as_MachIf()->_prob; |
1930 | 1930 |
1931 if (invert) p = 1.0 - p; | 1931 if (invert) p = 1.0 - p; |