comparison gcc/predict.c @ 63:b7f97abdc517 gcc-4.6-20100522

update gcc from gcc-4.5.0 to gcc-4.6
author ryoma <e075725@ie.u-ryukyu.ac.jp>
date Mon, 24 May 2010 12:47:05 +0900
parents 77e2b8dfacca
children f6334be47118
comparison
equal deleted inserted replaced
56:3c8a44c06a95 63:b7f97abdc517
111 /* Return TRUE if frequency FREQ is considered to be hot. */ 111 /* Return TRUE if frequency FREQ is considered to be hot. */
112 112
113 static inline bool 113 static inline bool
114 maybe_hot_frequency_p (int freq) 114 maybe_hot_frequency_p (int freq)
115 { 115 {
116 struct cgraph_node *node = cgraph_node (current_function_decl);
116 if (!profile_info || !flag_branch_probabilities) 117 if (!profile_info || !flag_branch_probabilities)
117 { 118 {
118 if (cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED) 119 if (node->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED)
119 return false; 120 return false;
120 if (cfun->function_frequency == FUNCTION_FREQUENCY_HOT) 121 if (node->frequency == NODE_FREQUENCY_HOT)
121 return true; 122 return true;
122 } 123 }
123 if (profile_status == PROFILE_ABSENT) 124 if (profile_status == PROFILE_ABSENT)
124 return true; 125 return true;
126 if (node->frequency == NODE_FREQUENCY_EXECUTED_ONCE
127 && freq <= (ENTRY_BLOCK_PTR->frequency * 2 / 3))
128 return false;
125 if (freq < BB_FREQ_MAX / PARAM_VALUE (HOT_BB_FREQUENCY_FRACTION)) 129 if (freq < BB_FREQ_MAX / PARAM_VALUE (HOT_BB_FREQUENCY_FRACTION))
126 return false; 130 return false;
127 return true; 131 return true;
128 } 132 }
129 133
159 { 163 {
160 if (profile_info && flag_branch_probabilities 164 if (profile_info && flag_branch_probabilities
161 && (edge->count 165 && (edge->count
162 <= profile_info->sum_max / PARAM_VALUE (HOT_BB_COUNT_FRACTION))) 166 <= profile_info->sum_max / PARAM_VALUE (HOT_BB_COUNT_FRACTION)))
163 return false; 167 return false;
164 if (lookup_attribute ("cold", DECL_ATTRIBUTES (edge->callee->decl)) 168 if (edge->caller->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED
165 || lookup_attribute ("cold", DECL_ATTRIBUTES (edge->caller->decl))) 169 || edge->callee->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED)
166 return false; 170 return false;
167 if (lookup_attribute ("hot", DECL_ATTRIBUTES (edge->caller->decl))) 171 if (optimize_size)
172 return false;
173 if (edge->caller->frequency == NODE_FREQUENCY_HOT)
168 return true; 174 return true;
175 if (edge->caller->frequency == NODE_FREQUENCY_EXECUTED_ONCE
176 && edge->frequency < CGRAPH_FREQ_BASE * 3 / 2)
177 return false;
169 if (flag_guess_branch_prob 178 if (flag_guess_branch_prob
170 && edge->frequency <= (CGRAPH_FREQ_BASE 179 && edge->frequency <= (CGRAPH_FREQ_BASE
171 / PARAM_VALUE (HOT_BB_FREQUENCY_FRACTION))) 180 / PARAM_VALUE (HOT_BB_FREQUENCY_FRACTION)))
172 return false; 181 return false;
173 return true; 182 return true;
189 probably_never_executed_bb_p (const_basic_block bb) 198 probably_never_executed_bb_p (const_basic_block bb)
190 { 199 {
191 if (profile_info && flag_branch_probabilities) 200 if (profile_info && flag_branch_probabilities)
192 return ((bb->count + profile_info->runs / 2) / profile_info->runs) == 0; 201 return ((bb->count + profile_info->runs / 2) / profile_info->runs) == 0;
193 if ((!profile_info || !flag_branch_probabilities) 202 if ((!profile_info || !flag_branch_probabilities)
194 && cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED) 203 && cgraph_node (current_function_decl)->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED)
195 return true; 204 return true;
196 return false; 205 return false;
197 } 206 }
198 207
199 /* Return true when current function should always be optimized for size. */ 208 /* Return true when current function should always be optimized for size. */
200 209
201 bool 210 bool
202 optimize_function_for_size_p (struct function *fun) 211 optimize_function_for_size_p (struct function *fun)
203 { 212 {
204 return (optimize_size 213 return (optimize_size
205 || (fun && (fun->function_frequency 214 || (fun && fun->decl
206 == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED))); 215 && (cgraph_node (fun->decl)->frequency
216 == NODE_FREQUENCY_UNLIKELY_EXECUTED)));
207 } 217 }
208 218
209 /* Return true when current function should always be optimized for speed. */ 219 /* Return true when current function should always be optimized for speed. */
210 220
211 bool 221 bool
2146 /* Decide whether function is hot, cold or unlikely executed. */ 2156 /* Decide whether function is hot, cold or unlikely executed. */
2147 void 2157 void
2148 compute_function_frequency (void) 2158 compute_function_frequency (void)
2149 { 2159 {
2150 basic_block bb; 2160 basic_block bb;
2161 struct cgraph_node *node = cgraph_node (current_function_decl);
2151 2162
2152 if (!profile_info || !flag_branch_probabilities) 2163 if (!profile_info || !flag_branch_probabilities)
2153 { 2164 {
2165 int flags = flags_from_decl_or_type (current_function_decl);
2154 if (lookup_attribute ("cold", DECL_ATTRIBUTES (current_function_decl)) 2166 if (lookup_attribute ("cold", DECL_ATTRIBUTES (current_function_decl))
2155 != NULL) 2167 != NULL)
2156 cfun->function_frequency = FUNCTION_FREQUENCY_UNLIKELY_EXECUTED; 2168 node->frequency = NODE_FREQUENCY_UNLIKELY_EXECUTED;
2157 else if (lookup_attribute ("hot", DECL_ATTRIBUTES (current_function_decl)) 2169 else if (lookup_attribute ("hot", DECL_ATTRIBUTES (current_function_decl))
2158 != NULL) 2170 != NULL)
2159 cfun->function_frequency = FUNCTION_FREQUENCY_HOT; 2171 node->frequency = NODE_FREQUENCY_HOT;
2172 else if (flags & ECF_NORETURN)
2173 node->frequency = NODE_FREQUENCY_EXECUTED_ONCE;
2174 else if (MAIN_NAME_P (DECL_NAME (current_function_decl)))
2175 node->frequency = NODE_FREQUENCY_EXECUTED_ONCE;
2176 else if (DECL_STATIC_CONSTRUCTOR (current_function_decl)
2177 || DECL_STATIC_DESTRUCTOR (current_function_decl))
2178 node->frequency = NODE_FREQUENCY_EXECUTED_ONCE;
2160 return; 2179 return;
2161 } 2180 }
2162 cfun->function_frequency = FUNCTION_FREQUENCY_UNLIKELY_EXECUTED; 2181 node->frequency = NODE_FREQUENCY_UNLIKELY_EXECUTED;
2163 FOR_EACH_BB (bb) 2182 FOR_EACH_BB (bb)
2164 { 2183 {
2165 if (maybe_hot_bb_p (bb)) 2184 if (maybe_hot_bb_p (bb))
2166 { 2185 {
2167 cfun->function_frequency = FUNCTION_FREQUENCY_HOT; 2186 node->frequency = NODE_FREQUENCY_HOT;
2168 return; 2187 return;
2169 } 2188 }
2170 if (!probably_never_executed_bb_p (bb)) 2189 if (!probably_never_executed_bb_p (bb))
2171 cfun->function_frequency = FUNCTION_FREQUENCY_NORMAL; 2190 node->frequency = NODE_FREQUENCY_NORMAL;
2172 } 2191 }
2173 } 2192 }
2174 2193
2175 /* Choose appropriate section for the function. */ 2194 /* Choose appropriate section for the function. */
2176 static void 2195 static void
2177 choose_function_section (void) 2196 choose_function_section (void)
2178 { 2197 {
2198 struct cgraph_node *node = cgraph_node (current_function_decl);
2179 if (DECL_SECTION_NAME (current_function_decl) 2199 if (DECL_SECTION_NAME (current_function_decl)
2180 || !targetm.have_named_sections 2200 || !targetm.have_named_sections
2181 /* Theoretically we can split the gnu.linkonce text section too, 2201 /* Theoretically we can split the gnu.linkonce text section too,
2182 but this requires more work as the frequency needs to match 2202 but this requires more work as the frequency needs to match
2183 for all generated objects so we need to merge the frequency 2203 for all generated objects so we need to merge the frequency
2189 choose the correct section into which to put things. */ 2209 choose the correct section into which to put things. */
2190 2210
2191 if (flag_reorder_blocks_and_partition) 2211 if (flag_reorder_blocks_and_partition)
2192 return; 2212 return;
2193 2213
2194 if (cfun->function_frequency == FUNCTION_FREQUENCY_HOT) 2214 if (node->frequency == NODE_FREQUENCY_HOT)
2195 DECL_SECTION_NAME (current_function_decl) = 2215 DECL_SECTION_NAME (current_function_decl) =
2196 build_string (strlen (HOT_TEXT_SECTION_NAME), HOT_TEXT_SECTION_NAME); 2216 build_string (strlen (HOT_TEXT_SECTION_NAME), HOT_TEXT_SECTION_NAME);
2197 if (cfun->function_frequency == FUNCTION_FREQUENCY_UNLIKELY_EXECUTED) 2217 if (node->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED)
2198 DECL_SECTION_NAME (current_function_decl) = 2218 DECL_SECTION_NAME (current_function_decl) =
2199 build_string (strlen (UNLIKELY_EXECUTED_TEXT_SECTION_NAME), 2219 build_string (strlen (UNLIKELY_EXECUTED_TEXT_SECTION_NAME),
2200 UNLIKELY_EXECUTED_TEXT_SECTION_NAME); 2220 UNLIKELY_EXECUTED_TEXT_SECTION_NAME);
2201 } 2221 }
2202 2222