00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 #ifndef inline_summarize_INCLUDED
00057 #define inline_summarize_INCLUDED
00058
00059
00060
00061
00062
00063 WN_MAP Summary_Map;
00064 WN_MAP Stmt_Map;
00065 BOOL Trace_IPA = FALSE, Trace_Perf = FALSE;
00066 static BOOL DoPreopt = FALSE;
00067 static BOOL Do_Par = FALSE;
00068 static BOOL Do_Common_Const = FALSE;
00069
00070
00071 #include "bitset.h"
00072 #include "ipl_summarize_template.h"
00073 #include "ipl_analyze_template.h"
00074
00075
00076 extern MEM_POOL* PU_pool;
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 template<> void
00087 SUMMARIZE<INLINER>::Identify_switch_clause_labels
00088 (WN* node, INT& default_lab_num, BS* &case_labels, MEM_POOL* mem) {
00089
00090
00091 default_lab_num = (WN_kid_count (node) > 2) ? WN_label_number(WN_kid2(node)) : -1;
00092 BS_ClearD (case_labels);
00093
00094 if (default_lab_num == -1) { return ;}
00095
00096
00097 for (WN* wn_tmp = WN_first(WN_kid1(node)); wn_tmp; wn_tmp = WN_next(wn_tmp)) {
00098 Is_True (WN_operator(wn_tmp) == OPR_CASEGOTO,
00099 ("the operator is expected to be OPR_CASEGOTO"));
00100 case_labels = BS_Union1D (case_labels, WN_label_number(wn_tmp), mem);
00101 }
00102 }
00103
00104 template<> void
00105 SUMMARIZE<INLINER>::Collect_calls_in_switch
00106 (WN* first_stmt, INT default_lab_num, BS* case_labels,
00107 BS* &calls_in_switch, MEM_POOL* mp) {
00108
00109 Is_True (default_lab_num > 0,
00110 ("We need to know the label number of default clause"));
00111
00112 BS_ClearD (calls_in_switch);
00113
00114 for (; first_stmt; first_stmt = WN_next(first_stmt)) {
00115 if (WN_operator (first_stmt) == OPR_LABEL) {
00116 if (BS_MemberP (case_labels, WN_label_number(first_stmt)) ||
00117 WN_label_number(first_stmt) == default_lab_num) {
00118
00119
00120 return;
00121 }
00122 continue;
00123 }
00124
00125
00126 for (WN_TREE_ITER<PRE_ORDER, WN*> iter (first_stmt);
00127 iter.Wn () != NULL; ++iter) {
00128 WN* wn_tmp = iter.Wn ();
00129 if (WN_operator (wn_tmp) == OPR_CALL) {
00130 calls_in_switch =
00131 BS_Union1D (calls_in_switch, WN_map_id(wn_tmp), mp);
00132 }
00133 }
00134 }
00135 }
00136
00137
00138
00139
00140 template<> void
00141 SUMMARIZE<INLINER>::Process_procedure (WN *w)
00142 {
00143 SUMMARY_PROCEDURE *proc = New_procedure ();
00144 SUMMARY_PROC_INFO *proc_info = New_proc_info ();
00145 WN* w2;
00146 BOOL Has_return_already = FALSE;
00147 BOOL Has_pdo_pragma = FALSE;
00148 BOOL Has_local_pragma = FALSE;
00149
00150 static MEM_POOL Temp_pool;
00151 static BOOL Temp_pool_initialized = FALSE;
00152
00153 if (!WHIRL_Return_Val_On)
00154 proc->Set_use_lowered_return_preg ();
00155
00156 if (INLINE_Enable_Copy_Prop) {
00157 if (!Temp_pool_initialized) {
00158 Temp_pool_initialized = TRUE;
00159 MEM_POOL_Initialize(&Temp_pool, "temp_pool", 0);
00160 }
00161 MEM_POOL_Push(&Temp_pool);
00162
00163
00164 Global_hash_table = CXX_NEW (GLOBAL_HASH_TABLE (113, &Temp_pool),
00165 &Temp_pool);
00166 };
00167
00168
00169
00170
00171
00172 Parent_Map = WN_MAP_Create (PU_pool);
00173 LWN_Parentize(w);
00174
00175
00176 if (WN_operator(w) == OPR_FUNC_ENTRY)
00177 Process_pragmas(w);
00178
00179 const PU& pu = Get_Current_PU ();
00180 if (PU_mp_needs_lno (pu))
00181 proc->Set_has_mp_needs_lno ();
00182
00183 ST* st = WN_st(w);
00184
00185 if (PU_src_lang(pu) == PU_CXX_LANG) {
00186 if ((Opt_Level > 1) && !INLINE_Static_Set)
00187 INLINE_Static = TRUE;
00188 if (!IPA_Enable_DFE_Set)
00189 IPA_Enable_DFE_Set = TRUE;
00190 }
00191
00192 #if defined (KEY) && defined (_LIGHTWEIGHT_INLINER)
00193
00194 if (WN_num_formals(w)) {
00195 if (WN_operator(w) == OPR_FUNC_ENTRY)
00196 Process_formal (w, WN_num_formals(w), proc);
00197 else
00198 proc->Set_formal_count(WN_num_formals(w));
00199 }
00200 #endif // KEY && _LIGHTWEIGHT_INLINER
00201
00202 #ifndef _LIGHTWEIGHT_INLINER
00203
00204
00205 if (WN_num_formals(w)) {
00206 if (WN_operator(w) == OPR_FUNC_ENTRY)
00207 Process_formal (w, WN_num_formals(w), proc);
00208 else
00209 proc->Set_formal_count(WN_num_formals(w));
00210 }
00211
00212 if (INLINE_Enable_Subst_Copy_Prop)
00213 proc_info->Set_symbol_index(Get_symbol_index(st));
00214
00215 #endif // _LIGHTWEIGHT_INLINER
00216
00217
00218 proc->Set_symbol_index(Get_symbol_index(st));
00219
00220 if (PU_no_inline (pu) )
00221 proc->Set_no_inline();
00222
00223 if (PU_no_delete (pu) )
00224 proc->Set_no_delete();
00225
00226 if (TY_is_varargs (Ty_Table[ST_pu_type (st)]))
00227 proc->Set_is_varargs();
00228 else {
00229
00230
00231
00232
00233 if ((PU_src_lang(pu) == PU_C_LANG) ||
00234 ((PU_src_lang(pu) == PU_CXX_LANG))) {
00235 if (PU_is_inline_function (pu)) {
00236
00237 if (ST_is_weak_symbol(st) && ST_export(st) != EXPORT_PROTECTED
00238 #ifdef KEY
00239 && ST_export(st) != EXPORT_INTERNAL
00240 #endif
00241 ) {
00242 DevWarn("Inliner encountered a function marked weak inline; NOT inlining it");
00243 proc->Set_no_inline();
00244 } else
00245 proc->Set_may_inline();
00246 }
00247
00248
00249 if (INLINE_Static &&
00250 ST_is_export_local(st) &&
00251 (!PU_is_inline_function(pu)) &&
00252 (ST_addr_not_passed(st)) &&
00253 (ST_addr_not_saved(st)) &&
00254 (!ST_is_weak_symbol(st))) {
00255 proc->Set_may_inline();
00256 Inline_tlog("Heuristic Inlining",0,"candidate is Static Function: %s",ST_name(WN_entry_name(w)));
00257 }
00258 } else {
00259
00260
00261
00262
00263
00264
00265
00266 INLINE_Enable_Copy_Prop = FALSE;
00267 if (PU_is_inline_function (pu) ||
00268 ST_is_export_local(st) ||
00269 ST_export(st) == EXPORT_INTERNAL)
00270 proc->Set_may_inline();
00271 }
00272 }
00273
00274
00275 Set_lang(proc);
00276
00277
00278
00279
00280 Set_entry_point(w);
00281
00282
00283 BS* case_labels = BS_Create_Empty (256, &Temp_pool);
00284
00285 BS* calls_in_switch = BS_Create_Empty (256, &Temp_pool);
00286 BS* bs_tmp = BS_Create_Empty (256, &Temp_pool);
00287
00288 INT default_lab_num = -1;
00289
00290
00291 for (WN_TREE_ITER<PRE_ORDER, WN*> iter (w); iter.Wn () != NULL; ++iter) {
00292
00293 w2 = iter.Wn ();
00294
00295 switch (WN_operator(w2)) {
00296
00297 case OPR_CALL: {
00298 if (INLINE_Enable_Subst_Copy_Prop)
00299 proc_info -> Incr_call_count();
00300
00301
00302 if ((WN_opcode(w2) == OPC_VCALL) &&
00303 (WN_Fake_Call_EH_Region(w2, Parent_Map)))
00304 break;
00305
00306 Process_callsite (w2, proc->Get_callsite_count (), get_loopnest(w2));
00307 SUMMARY_CALLSITE *callsite = Get_callsite(Get_callsite_idx());
00308 callsite->Set_wn (w2);
00309 if (BS_MemberP (calls_in_switch, WN_map_id(w2))) {
00310 callsite->Set_in_case_clause();
00311 }
00312
00313 proc->Incr_call_count ();
00314 proc->Incr_callsite_count ();
00315 }
00316 break;
00317
00318 #ifndef _LIGHTWEIGHT_INLINER
00319
00320
00321 case OPR_LDA:
00322 case OPR_LDID:
00323 case OPR_ILOAD:
00324 if (INLINE_Enable_Copy_Prop) {
00325 Record_ref (w2);
00326 }
00327 break;
00328
00329
00330 case OPR_ISTORE:
00331 case OPR_MSTORE:
00332
00333 if (INLINE_Enable_Subst_Copy_Prop)
00334 proc_info -> Set_has_istore();
00335
00336 case OPR_STID:
00337 if (INLINE_Enable_Copy_Prop) {
00338 Record_mod (w2);
00339 }
00340 break;
00341
00342
00343 case OPR_PARM:
00344 if (INLINE_Enable_Copy_Prop) {
00345 Update_Addr_Passed_Count(w2);
00346 }
00347 break;
00348
00349 #endif // _LIGHTWEIGHT_INLINER
00350
00351 case OPR_ALTENTRY:
00352 proc->Set_has_alt_entry();
00353 proc->Set_no_inline();
00354 break;
00355
00356
00357 case OPR_EXC_SCOPE_BEGIN:
00358 Fail_FmtAssertion ("Invalid opcode from old style Exception Processing\n");
00359 break;
00360
00361 case OPR_PRAGMA:
00362 #ifndef _LIGHTWEIGHT_INLINER
00363 if (WN_st(w2)) {
00364 if ((ST_sclass(WN_st(w2)) == SCLASS_FORMAL ||
00365 ST_sclass(WN_st(w2)) == SCLASS_FORMAL_REF) &&
00366 !(ST_is_value_parm(WN_st(w2))))
00367 proc->Set_has_formal_pragma();
00368
00369 if (PU_has_alloca (Get_Current_PU ()) &&
00370 is_variable_dim_array(ST_type(WN_st(w2))))
00371
00372 proc->Set_has_formal_pragma();
00373
00374
00375
00376 if ((ST_sclass(WN_st(w2)) == SCLASS_FORMAL) ||
00377 PU_has_alloca (Get_Current_PU ()))
00378 {
00379 switch (WN_pragma(w2))
00380 {
00381 case WN_PRAGMA_DISTRIBUTE:
00382 case WN_PRAGMA_DISTRIBUTE_RESHAPE:
00383 case WN_PRAGMA_DYNAMIC:
00384 case WN_PRAGMA_REDISTRIBUTE:
00385 case WN_PRAGMA_AFFINITY:
00386 case WN_PRAGMA_DATA_AFFINITY:
00387 case WN_PRAGMA_THREAD_AFFINITY:
00388 case WN_PRAGMA_PAGE_PLACE:
00389 proc->Set_has_formal_pragma();
00390 break;
00391
00392 default:
00393 break;
00394 }
00395 }
00396
00397 if (TY_is_non_pod(ST_type(WN_st(w2)))) {
00398 switch (WN_pragma(w2)) {
00399 case WN_PRAGMA_LOCAL:
00400 case WN_PRAGMA_LASTLOCAL:
00401 case WN_PRAGMA_FIRSTPRIVATE:
00402 Has_local_pragma = TRUE;
00403 break;
00404
00405 default:
00406 break;
00407 }
00408 }
00409
00410 }
00411 #endif // _LIGHTWEIGHT_INLINER
00412
00413
00414
00415 if (WN_pragma(w2) == WN_PRAGMA_SINGLE_PROCESS_BEGIN) {
00416 proc->Set_has_parallel_pragma();
00417 }
00418
00419 if (WN_pragma(w2) == WN_PRAGMA_PARALLEL_BEGIN) {
00420 proc->Set_has_parallel_region_pragma();
00421 }
00422
00423 #ifndef _LIGHTWEIGHT_INLINER
00424 if ((WN_pragma(w2) == WN_PRAGMA_DOACROSS) ||
00425 (WN_pragma(w2) == WN_PRAGMA_PARALLEL_DO) ||
00426 (WN_pragma(w2) == WN_PRAGMA_PARALLEL_BEGIN) ||
00427 (WN_pragma(w2) == WN_PRAGMA_PARALLEL_SECTIONS))
00428 proc->Set_has_noinline_parallel_pragma();
00429
00430 if ((WN_pragma(w2) == WN_PRAGMA_PDO_BEGIN) ||
00431 (WN_pragma(w2) == WN_PRAGMA_PSECTION_BEGIN) ||
00432 (WN_pragma(w2) == WN_PRAGMA_SINGLE_PROCESS_BEGIN))
00433 Has_pdo_pragma = TRUE;
00434
00435 #endif // _LIGHTWEIGHT_INLINER
00436 break;
00437
00438 case OPR_REGION:
00439 if (REGION_is_mp(w2))
00440 proc->Set_has_parallel_region_pragma();
00441 #ifndef _LIGHTWEIGHT_INLINER
00442 if (WN_region_is_EH(w2))
00443 proc->Set_exc_inline();
00444 if (WN_region_kind(w2)== REGION_KIND_TRY)
00445 proc->Set_exc_try();
00446 #endif // _LIGHTWEIGHT_INLINER
00447 break;
00448
00449 case OPR_RETURN:
00450 case OPR_RETURN_VAL:
00451 if (!proc->Has_early_returns ()) {
00452 if (!Last_Node (iter))
00453 proc->Set_has_early_returns ();
00454 }
00455 break;
00456
00457 case OPR_SWITCH:
00458
00459
00460 if (WN_num_entries(w2) < 6) { break; }
00461
00462
00463 if (default_lab_num != -1) { break; }
00464
00465 Identify_switch_clause_labels(w2, default_lab_num,
00466 case_labels, &Temp_pool);
00467 break;
00468
00469
00470 case OPR_LABEL:
00471 if (default_lab_num == -1) {
00472 break;
00473 }
00474 if (!BS_MemberP (case_labels, WN_label_number(w2))) {
00475 if (WN_label_number(w2) == default_lab_num) {
00476 default_lab_num = -1;
00477 }
00478 break;
00479 }
00480
00481 Collect_calls_in_switch (WN_next(w2), default_lab_num, case_labels,
00482 bs_tmp, &Temp_pool);
00483
00484 calls_in_switch = BS_UnionD (calls_in_switch, bs_tmp, &Temp_pool);
00485 break;
00486
00487 default:
00488 break;
00489 }
00490
00491
00492
00493
00494 if (OPCODE_has_sym(WN_opcode(w2)) && WN_st_idx(w2) != 0) {
00495 ST* st2 = ST_st_idx (WN_st(w2)) == ST_base_idx (WN_st(w2)) ? WN_st(w2) : ST_base (WN_st(w2));
00496 if (ST_level (st2) == CURRENT_SYMTAB) {
00497
00498 if (ST_sclass (st2) == SCLASS_PSTATIC)
00499 proc->Set_has_pstatic ();
00500 } else if ((ST_sclass (st2) == SCLASS_FSTATIC) &&
00501 !ST_class (st2) == CLASS_CONST)
00502 proc->Set_has_fstatic ();
00503
00504 #ifndef _LIGHTWEIGHT_INLINER
00505 if (is_variable_dim_array(ST_type(st2)))
00506 proc->Set_has_var_dim_array();
00507 #endif // _LIGHTWEIGHT_INLINER
00508 }
00509
00510 }
00511
00512 if (proc->Get_callsite_count () > 0)
00513 proc->Set_callsite_index (Get_callsite_idx () -
00514 proc->Get_callsite_count () + 1);
00515
00516
00517
00518 if (INLINE_Enable_Copy_Prop) {
00519 Set_local_addr_taken_attrib();
00520 MEM_POOL_Pop ( &Temp_pool );
00521 }
00522
00523 else if (INLINE_Enable_Split_Common)
00524 {
00525
00526 Set_local_addr_taken_attrib();
00527
00528 }
00529
00530 #ifndef _LIGHTWEIGHT_INLINER
00531 if ( Has_local_pragma && Has_pdo_pragma)
00532 proc->Set_has_pdo_pragma();
00533 #endif // _LIGHTWEIGHT_INLINER
00534
00535 }
00536
00537 #endif