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 #ifdef USE_PCH
00046 #include "be_com_pch.h"
00047 #endif
00048 #pragma hdrstop
00049 #include "defs.h"
00050 #include "config.h"
00051 #include "config_opt.h"
00052 #include "stab.h"
00053 #include "wn.h"
00054 #include "opt_points_to.h"
00055 #include "erglob.h"
00056 #include "opt_sym.h"
00057 #include "opt_util.h"
00058
00059 #ifdef SHARED_BUILD
00060 #if defined(__linux__) || defined(BUILD_OS_DARWIN)
00061 #ifdef SHARED_BUILD
00062 extern AUX_ID (*WN_aux_p) (const WN*);
00063 #define WN_aux (*WN_aux_p)
00064 #else
00065 extern AUX_ID WN_aux (const WN*);
00066 #endif
00067 #else
00068 #pragma weak WN_aux__GPC2WN
00069 #endif // __linux__
00070 #endif // SHARED_BUILD
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 enum BASE_ACTION {
00103 NO_INFO = 0,
00104 SAME_BASE = 0x1,
00105 COMP_BASE = 0x2,
00106 DIFF = 0x3
00107 };
00108
00109 static const BASE_ACTION
00110 base_action_tbl[MAX_BASE_KIND][MAX_BASE_KIND] = {
00111
00112
00113 { NO_INFO, NO_INFO, NO_INFO, NO_INFO},
00114 { NO_INFO, COMP_BASE, NO_INFO, NO_INFO},
00115 { NO_INFO, NO_INFO, SAME_BASE, NO_INFO},
00116 { NO_INFO, NO_INFO, NO_INFO, NO_INFO},
00117 };
00118
00119 #if defined(TARG_SL)
00120 ST* POINTS_TO::Get_ST_base(ST* st) const
00121 {
00122 if(st==NULL)
00123 return NULL;
00124 else {
00125 ST *st_base=st;
00126 ST* base=ST_base(st);
00127 while(base!=NULL && st_base!=base) {
00128 st_base=base;
00129 base=ST_base(st_base);
00130 }
00131 return st_base;
00132 }
00133 }
00134 #endif
00135
00136
00137
00138
00139
00140 BOOL POINTS_TO::Same_base(const POINTS_TO *pt) const
00141 {
00142 BASE_ACTION a = base_action_tbl[this->Base_kind()][pt->Base_kind()];
00143 if ((a == COMP_BASE || a == SAME_BASE)) {
00144 #if defined(TARG_SL)
00145 if(this->Base_kind()==BASE_IS_FIXED && pt->Base_kind()==BASE_IS_FIXED) {
00146 if(Get_ST_base(this->Base())==Get_ST_base(pt->Base()))
00147 return TRUE;
00148 } else
00149 #endif
00150 if(this->Base() == pt->Base())
00151 return TRUE;
00152 }
00153 return FALSE;
00154 }
00155
00156 BOOL POINTS_TO::Same_pointer (const POINTS_TO* pt) const
00157 {
00158 if (Pointer_is_named_symbol ()) {
00159 ST* ptr = Pointer ();
00160 if (!ptr || ptr != pt->Pointer()) {
00161 return FALSE;
00162 }
00163
00164 if (ST_is_constant(ptr)) {
00165
00166
00167
00168 return TRUE;
00169 }
00170
00171 return Pointer_ver () && Pointer_ver () == pt->Pointer_ver();
00172 } else if (Pointer_is_aux_id()) {
00173 return Pointer_aux_id() && Pointer_aux_id() == pt->Pointer_aux_id() &&
00174 Pointer_ver () && Pointer_ver () == pt->Pointer_ver();
00175 } else if (Pointer_is_coderep_id ()) {
00176 return Pointer_coderep_id () &&
00177 Pointer_coderep_id () == pt->Pointer_coderep_id ();
00178 }
00179
00180 return FALSE;
00181 }
00182
00183 BOOL POINTS_TO::Pointer_info_does_help (void) const
00184 {
00185 if (Pointer_is_named_symbol()) {
00186 return Pointer() &&
00187 (ST_is_constant(Pointer()) || Pointer_ver()) &&
00188 Iofst_kind () == OFST_IS_FIXED ;
00189 } else if (Pointer_is_aux_id()) {
00190 return Pointer_ver() && Iofst_kind () == OFST_IS_FIXED ;
00191 } else if (Pointer_is_coderep_id ()) {
00192 return TRUE;
00193 }
00194
00195 return FALSE;
00196 }
00197
00198
00199
00200
00201 BOOL POINTS_TO::Different_base(const POINTS_TO *pt) const
00202 {
00203 BASE_ACTION a = base_action_tbl[this->Base_kind()][pt->Base_kind()];
00204 if (a == DIFF) {
00205 return TRUE;
00206 } else if (a == COMP_BASE) {
00207 #if defined(TARG_SL)
00208 if (this->Base_kind() == BASE_IS_FIXED && pt->Base_kind() == BASE_IS_FIXED) {
00209 if (Get_ST_base(this->Base()) != Get_ST_base(pt->Base()))
00210 return TRUE;
00211 } else
00212 #endif
00213 if(this->Base() != pt->Base())
00214 return TRUE;
00215 }
00216 return FALSE;
00217 }
00218
00219
00220
00221
00222
00223
00224
00225 ALIAS_KIND POINTS_TO::Overlap(const POINTS_TO *p) const
00226 {
00227
00228
00229
00230 if (this->Ofst_kind() != OFST_IS_FIXED ||
00231 p->Ofst_kind() != OFST_IS_FIXED)
00232 return ALIAS_KIND (AR_POSSIBLE_ALIAS);
00233
00234 if (this->Base_is_fixed() && ST_sclass(this->Base()) == SCLASS_REG) {
00235 Is_True(ST_sclass(p->Base()) == SCLASS_REG, ("calling overlap() with different bases."));
00236 return (this->Byte_Ofst() == p->Byte_Ofst()) ?
00237 ALIAS_KIND (AR_DEFINITE_ALIAS) :
00238 ALIAS_KIND (AR_NOT_ALIAS);
00239 }
00240
00241 if (this->Bit_Size() == 0 && p->Bit_Size() == 0) {
00242 if (this->Byte_Ofst() <= p->Byte_Ofst()) {
00243 if (this->Byte_Ofst() + this->Byte_Size() > p->Byte_Ofst())
00244 return ALIAS_KIND (AR_DEFINITE_ALIAS);
00245 } else {
00246 if (p->Byte_Ofst() + p->Byte_Size() > this->Byte_Ofst())
00247 return ALIAS_KIND (AR_DEFINITE_ALIAS) ;
00248 }
00249 } else {
00250
00251 INT64 ofst1 = this->Byte_Ofst() * 8 + this->Bit_Ofst();
00252 INT64 ofst2 = p->Byte_Ofst() * 8 + p->Bit_Ofst();
00253 UINT64 size1 =
00254 this->Bit_Size () ? this->Bit_Size () : this->Byte_Size() * 8;
00255 UINT64 size2 = p->Bit_Size () ? p->Bit_Size() : p->Byte_Size() * 8;
00256
00257 if (ofst1 <= ofst2) {
00258 if (ofst1 + size1 > ofst2)
00259 return ALIAS_KIND (AR_DEFINITE_ALIAS) ;
00260 } else {
00261 if (ofst2 + size2 > ofst1)
00262 return ALIAS_KIND (AR_DEFINITE_ALIAS) ;
00263 }
00264 }
00265 return ALIAS_KIND (AR_NOT_ALIAS);
00266 }
00267
00268 void POINTS_TO::Meet_info_from_alias_class(const POINTS_TO *pt)
00269 {
00270 if (Alias_class() == OPTIMISTIC_AC_ID) {
00271 Set_alias_class(pt->Alias_class());
00272 }
00273 else if ((pt->Alias_class() != OPTIMISTIC_AC_ID) &&
00274 (pt->Alias_class() != Alias_class())) {
00275 Set_alias_class(PESSIMISTIC_AC_ID);
00276 }
00277 if (Ip_alias_class() == OPTIMISTIC_AC_ID) {
00278 Set_ip_alias_class(pt->Ip_alias_class());
00279 }
00280 else if ((pt->Ip_alias_class() != OPTIMISTIC_AC_ID) &&
00281 (pt->Ip_alias_class() != Ip_alias_class())) {
00282 Set_ip_alias_class(PESSIMISTIC_AC_ID);
00283 }
00284
00285 if (!pt->Not_alloca_mem()) Reset_not_alloca_mem();
00286 }
00287
00288
00289
00290
00291 void POINTS_TO::Meet(const POINTS_TO *pt, ST *definition)
00292 {
00293
00294
00295
00296
00297
00298
00299 if (pt->Expr_kind() == EXPR_IS_BEING_PROCESSED) {
00300 Set_ofst_kind(OFST_IS_UNKNOWN);
00301 return;
00302 }
00303
00304
00305
00306 if (this->Expr_kind() == EXPR_IS_ANY) {
00307 this->Copy_non_sticky_info(pt);
00308 return;
00309 }
00310
00311
00312 if (pt->Expr_kind() == EXPR_IS_ANY)
00313 return;
00314
00315
00316
00317
00318 if (pt->Based_sym() != Based_sym()) {
00319 FmtAssert(pt->Based_sym() == NULL ||
00320 (!Unique_pt() && !Restricted()),
00321 ("POINTS_TO::Meet: Inconsistent Based_sym()"));
00322 if (!Unique_pt() && !Restricted()) {
00323 Set_based_sym(NULL);
00324 }
00325 }
00326
00327
00328
00329
00330 Invalidate_ptr_info ();
00331
00332
00333 if ((pt->Expr_kind() != Expr_kind()) &&
00334 (!Unique_pt() && !Restricted())) {
00335 Set_expr_kind(EXPR_IS_UNKNOWN);
00336 Set_base_kind(BASE_IS_UNKNOWN);
00337 Set_ofst_kind(OFST_IS_UNKNOWN);
00338 Set_alias_class(PESSIMISTIC_AC_ID);
00339 Invalidate_ptr_info ();
00340 Set_ip_alias_class(PESSIMISTIC_AC_ID);
00341 Reset_attr();
00342 return;
00343 }
00344
00345
00346
00347 if (pt->Expr_kind() == EXPR_IS_ADDR) {
00348
00349
00350 if (!Same_base(pt)) {
00351
00352 Set_base(definition);
00353 Set_ofst_kind(OFST_IS_UNKNOWN);
00354 Set_base_kind(BASE_IS_UNKNOWN);
00355 } else {
00356
00357
00358 if (this->Ofst_kind() == OFST_IS_FIXED &&
00359 pt->Ofst_kind() == OFST_IS_FIXED &&
00360 this->Is_pointer() == pt->Is_pointer()) {
00361 mINT64 byte_lower = MIN (this->Byte_Ofst(), pt->Byte_Ofst());
00362 mINT64 byte_upper = MAX (this->Byte_Ofst() + this->Byte_Size(),
00363 pt->Byte_Ofst() + pt->Byte_Size());
00364 if (this->Bit_Size() != 0 && pt->Bit_Size() != 0) {
00365
00366 if (byte_upper - byte_lower > 8) {
00367
00368 Set_bit_ofst_size (0, 0);
00369 } else {
00370 INT64 bits_lower = MIN (this->Byte_Ofst() * 8 + this->Bit_Ofst(),
00371 pt->Byte_Ofst() * 8 + pt->Bit_Ofst());
00372 INT64 bits_upper =
00373 MAX (this->Byte_Ofst() * 8 + this->Bit_Ofst() + this->Bit_Size(),
00374 pt->Byte_Ofst() * 8 + pt->Bit_Ofst() + pt->Bit_Size());
00375 Set_bit_ofst_size (bits_lower - byte_lower * 8,
00376 bits_upper - bits_lower);
00377 }
00378 }
00379 Set_byte_ofst(byte_lower);
00380 Set_byte_size(byte_upper - byte_lower);
00381 } else
00382 Set_ofst_kind(OFST_IS_UNKNOWN);
00383 }
00384 }
00385
00386 Meet_info_from_alias_class(pt);
00387
00388
00389 if (!pt->Not_addr_saved()) Reset_not_addr_saved();
00390 if (!pt->Not_addr_passed()) Reset_not_addr_passed();
00391 if (!pt->Local()) Reset_local();
00392 if (!pt->Global()) Reset_global();
00393 if (!pt->Named()) Reset_named();
00394 if (!pt->Const()) Reset_const();
00395 if (!pt->F_param()) Reset_F_param();
00396 if (!pt->No_alias()) Reset_no_alias();
00397 if (!pt->Is_pointer()) Reset_is_pointer();
00398 if (!pt->Safe_to_speculate()) Reset_safe_to_speculate();
00399 if (!pt->Not_f90_target()) Reset_not_f90_target();
00400
00401
00402 if (pt->Weak()) Set_weak();
00403 if (pt->Weak_base()) Set_weak_base();
00404
00405 if (pt->Ty() != Ty()) Set_ty((TY_IDX) 0);
00406 if (pt->Highlevel_Ty () != Highlevel_Ty ()) {
00407 Set_hl_ty ((TY_IDX)0);
00408 Set_field_id (0);
00409 }
00410 if (pt->Field_id () != Field_id ()) Set_field_id (0);
00411
00412 if (pt->Known_f90_pointer() && Known_not_f90_pointer()) {
00413 DevWarn("Alias analysis: f90 pointer meets non-f90 pointer");
00414 Reset_known_not_f90_pointer();
00415 }
00416 if (pt->Known_not_f90_pointer() && Known_f90_pointer()) {
00417 DevWarn("Alias analysis: f90 pointer meets non-f90 pointer");
00418 Reset_known_f90_pointer();
00419 }
00420
00421
00422 _mem_annot.Meet(pt->_mem_annot);
00423
00424 CHECK_POINTS_TO(this);
00425 }
00426
00427
00428
00429
00430
00431 void
00432 Expand_ST_into_base_and_ofst(ST *st, INT64 st_ofst, ST **base, INT64 *ofst)
00433 {
00434
00435
00436
00437
00438
00439 if (ST_sclass(st) == SCLASS_REG ||
00440 ST_sclass(st) == SCLASS_TEXT ||
00441 (ST_class(st) == CLASS_BLOCK && STB_merge(st)) ||
00442 ((Gen_PIC_Shared || Gen_PIC_Call_Shared) && ST_is_preemptible(st)) )
00443 {
00444 *ofst = st_ofst;
00445 *base = st;
00446 return;
00447 }
00448
00449 INT64 tmpofst = 0;
00450 ST *tmpbase = st;
00451
00452 while (ST_base(tmpbase) != tmpbase) {
00453
00454
00455 if (ST_class(tmpbase) == CLASS_BLOCK && STB_merge(tmpbase)) {
00456 *ofst = st_ofst;
00457 *base = st;
00458 return;
00459 }
00460
00461
00462
00463
00464 if (ST_sclass(tmpbase) == SCLASS_FORMAL &&
00465 ST_class(ST_base(tmpbase)) == CLASS_BLOCK)
00466 break;
00467
00468
00469
00470 if (ST_sclass(tmpbase) == SCLASS_FORMAL &&
00471 ST_sclass(tmpbase) != ST_sclass(ST_base(tmpbase)))
00472 break;
00473
00474
00475
00476
00477 if (ST_sclass(ST_base(tmpbase)) == SCLASS_UNKNOWN)
00478 break;
00479
00480
00481
00482 if (ST_sclass(tmpbase) == SCLASS_TEXT)
00483 break;
00484
00485 tmpofst += ST_ofst(tmpbase);
00486 tmpbase = ST_base(tmpbase);
00487 }
00488
00489
00490
00491
00492 if (ST_class(tmpbase) == CLASS_BLOCK && STB_merge(tmpbase)) {
00493 *ofst = st_ofst;
00494 *base = st;
00495 return;
00496 }
00497
00498 *ofst = tmpofst + st_ofst;
00499 *base = tmpbase;
00500 }
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510 void
00511 POINTS_TO::Analyze_ST(ST *st, INT64 byte_ofst, INT64 byte_size,
00512 UINT8 bit_ofst, UINT8 bit_size, TY_IDX ty,
00513 BOOL has_equiv)
00514 {
00515 Init();
00516 Set_ty(ty);
00517
00518 Set_expr_kind(EXPR_IS_ADDR);
00519 Set_ofst_kind(OFST_IS_FIXED);
00520 Set_base_kind(BASE_IS_FIXED);
00521 Set_named();
00522
00523
00524 if (ty != (TY_IDX)0) {
00525 switch (TY_kind (ty)) {
00526 case KIND_SCALAR:
00527 case KIND_POINTER:
00528 case KIND_STRUCT:
00529 Set_safe_to_speculate();
00530 break;
00531 default:
00532 break;
00533 }
00534 }
00535
00536
00537 ST *base;
00538 INT64 ofst;
00539 Expand_ST_into_base_and_ofst(st, byte_ofst, &base, &ofst);
00540 Set_base(base);
00541 Set_byte_ofst(ofst);
00542 Set_byte_size(byte_size);
00543 Set_bit_ofst_size(bit_ofst, bit_size);
00544
00545 if (ST_class(st) == CLASS_CONST ||
00546 ST_class(st) == CLASS_FUNC ||
00547 (ST_class(st) == CLASS_VAR && ST_is_const_var (st))) {
00548
00549 Set_const();
00550
00551 Set_no_alias();
00552 Set_not_addr_saved();
00553 Set_not_addr_passed();
00554
00555 } else {
00556
00557 BOOL not_addr_used_locally = FALSE;
00558
00559 if (ST_class(st) == CLASS_VAR) {
00560 if (!ST_is_f90_target(st)) {
00561 Set_not_f90_target();
00562 }
00563 }
00564 else {
00565 Set_not_f90_target();
00566 }
00567
00568 if (Not_f90_target()) {
00569
00570
00571 Set_known_not_f90_pointer();
00572 }
00573
00574 ST *sclass_st = st;
00575
00576 switch (ST_sclass(sclass_st)) {
00577 case SCLASS_UNKNOWN:
00578 Is_True(FALSE, ("Analyze_ST::Storage class for ST %s is unknown.", ST_name(st)));
00579 break;
00580 case SCLASS_AUTO:
00581 case SCLASS_FORMAL_REF:
00582 if (!ST_addr_saved(st))
00583 Set_not_addr_saved();
00584 if (!BE_ST_addr_passed(st))
00585 Set_not_addr_passed();
00586 if (!BE_ST_addr_used_locally(st))
00587 not_addr_used_locally = TRUE;
00588
00589 if (CURRENT_SYMTAB != ST_IDX_level (ST_st_idx (st)))
00590 Set_global();
00591 else
00592 Set_local();
00593
00594
00595
00596
00597
00598
00599 if (ST_is_optional_argument(st) ||
00600 (ST_sclass(sclass_st) == SCLASS_FORMAL_REF &&
00601 (PU_has_altentry(Get_Current_PU())
00602 #ifdef KEY
00603 || LANG_Formal_Deref_Unsafe
00604 #endif
00605 )))
00606 Reset_safe_to_speculate();
00607 break;
00608 case SCLASS_FORMAL:
00609 Set_formal();
00610
00611
00612
00613
00614
00615
00616
00617 if (!ST_addr_saved(st))
00618 Set_not_addr_saved();
00619 if (!BE_ST_addr_passed(st))
00620 Set_not_addr_passed();
00621 if (!BE_ST_addr_used_locally(st))
00622 not_addr_used_locally = TRUE;
00623 if (CURRENT_SYMTAB != ST_IDX_level (ST_st_idx (st)))
00624 Set_global();
00625 else
00626 Set_local();
00627
00628
00629
00630
00631
00632 #ifdef TARG_X8664
00633 if (byte_ofst >= TY_size(ST_type(st))) {
00634 Set_base_kind(BASE_IS_DYNAMIC);
00635 Set_ofst_kind(OFST_IS_UNKNOWN);
00636 }
00637 #endif
00638 break;
00639 case SCLASS_FSTATIC:
00640 Set_not_auto();
00641 Set_global();
00642 if (!ST_addr_saved(st))
00643 Set_not_addr_saved();
00644 if (!BE_ST_addr_passed(st))
00645 Set_not_addr_passed();
00646 if (!BE_ST_addr_used_locally(st))
00647 not_addr_used_locally = TRUE;
00648
00649
00650 break;
00651 case SCLASS_PSTATIC:
00652 if (ST_is_private_local(st))
00653 Set_local();
00654 else
00655 Set_global();
00656 if (!ST_addr_saved(st))
00657 Set_not_addr_saved();
00658 if (!BE_ST_addr_passed(st))
00659 Set_not_addr_passed();
00660 if (!BE_ST_addr_used_locally(st))
00661 not_addr_used_locally = TRUE;
00662
00663
00664 break;
00665 case SCLASS_UGLOBAL:
00666 case SCLASS_DGLOBAL:
00667 case SCLASS_COMMON:
00668 Set_not_auto();
00669
00670 case SCLASS_EXTERN:
00671 Set_global();
00672 if (OPT_IPA_addr_analysis &&
00673 PU_ipa_addr_analysis(Get_Current_PU())) {
00674 if (!ST_addr_saved(st))
00675 Set_not_addr_saved();
00676 if (!BE_ST_addr_passed (st))
00677 Set_not_addr_passed();
00678 if (!BE_ST_addr_used_locally(st))
00679 not_addr_used_locally = TRUE;
00680 }
00681
00682 if (ST_is_weak_symbol (st)) {
00683 Set_weak();
00684
00685 Reset_not_addr_saved();
00686 Reset_not_addr_passed();
00687 Reset_safe_to_speculate();
00688 }
00689
00690
00691 break;
00692 case SCLASS_REG:
00693
00694
00695 Set_no_alias();
00696 Set_not_addr_saved();
00697 Set_not_addr_passed();
00698 Set_safe_to_speculate();
00699 Set_local();
00700 if (byte_ofst <= Last_Dedicated_Preg_Offset)
00701 Set_dedicated();
00702 break;
00703 case SCLASS_TEXT:
00704
00705 break;
00706 default:
00707 FmtAssert(FALSE, ("Handle ST class %d.", ST_sclass(st)));
00708 }
00709
00710
00711
00712
00713
00714 if (
00715 Not_addr_saved() &&
00716 Not_addr_passed() &&
00717 not_addr_used_locally &&
00718 !has_equiv)
00719 Set_no_alias();
00720 }
00721 }
00722
00723
00724
00725
00726
00727
00728 void POINTS_TO::Analyze_ST_as_base(ST *st, INT64 ofst, TY_IDX ty)
00729 {
00730 Init();
00731 Set_expr_kind(EXPR_IS_UNKNOWN);
00732 Set_base_kind(BASE_IS_UNKNOWN);
00733 Set_ofst_kind(OFST_IS_UNKNOWN);
00734
00735 if (ty != (TY_IDX)NULL && TY_kind(ty) == KIND_POINTER)
00736 Set_expr_kind(EXPR_IS_ADDR);
00737 else
00738 return;
00739
00740 if (ST_class(st) != CLASS_VAR) return;
00741
00742 if (ofst == 0) {
00743 if (TY_is_restrict(ST_type(st))) {
00744 Set_restricted();
00745 Set_based_sym(st);
00746 Set_expr_kind(EXPR_IS_ADDR);
00747 Set_base_kind(BASE_IS_UNKNOWN);
00748 Set_ofst_kind(OFST_IS_UNKNOWN);
00749 } else if (WOPT_Enable_Unique_Pt_Vsym && ST_pt_to_unique_mem(st)) {
00750 Set_unique_pt();
00751 Set_based_sym(st);
00752 Set_expr_kind(EXPR_IS_ADDR);
00753 Set_base_kind(BASE_IS_UNKNOWN);
00754 Set_ofst_kind(OFST_IS_UNKNOWN);
00755 } else if (Alias_Pointer_Cray && st != NULL && !ST_is_temp_var(st)) {
00756 Set_unique_pt();
00757 Set_based_sym(st);
00758 Set_expr_kind(EXPR_IS_ADDR);
00759 Set_base_kind(BASE_IS_UNKNOWN);
00760 Set_ofst_kind(OFST_IS_UNKNOWN);
00761 }
00762 if (Alias_Pointer_Parms && Is_FORTRAN() &&
00763 ST_sclass(st) == SCLASS_FORMAL && !ST_is_value_parm(st)) {
00764 Set_F_param();
00765 Set_based_sym(st);
00766 Set_expr_kind(EXPR_IS_ADDR);
00767 Set_base_kind(BASE_IS_UNKNOWN);
00768 Set_global();
00769 Set_named();
00770 }
00771
00772 Set_ofst_kind(OFST_IS_FIXED);
00773 Set_byte_ofst(0);
00774 Set_byte_size(0);
00775
00776 if (Based_sym () == NULL && WOPT_Enable_Pt_Keep_Track_Ptr) {
00777 Set_pointer (st);
00778 Set_pointer_ver ((VER_ID)0);
00779 Set_iofst_kind (OFST_IS_FIXED);
00780 }
00781 } else {
00782
00783
00784
00785
00786
00787
00788 if (ST_pt_to_unique_mem(st)) {
00789 Set_unique_pt();
00790 Set_based_sym(st);
00791 Set_expr_kind(EXPR_IS_ADDR);
00792 Set_base_kind(BASE_IS_UNKNOWN);
00793 Set_ofst_kind(OFST_IS_UNKNOWN);
00794 }
00795 Set_ofst_kind(OFST_IS_FIXED);
00796 Set_byte_ofst(0);
00797 Set_byte_size(0);
00798
00799 Set_pointer ((ST*)NULL);
00800 Set_pointer_ver ((VER_ID)0);
00801 Set_iofst_kind (OFST_IS_INVALID);
00802 }
00803 }
00804
00805
00806
00807
00808
00809 void POINTS_TO::Lower_to_base(WN *wn)
00810 {
00811 if (Expr_kind() != EXPR_IS_ADDR) {
00812
00813 Set_base_kind(BASE_IS_UNKNOWN);
00814 Set_ofst_kind(OFST_IS_UNKNOWN);
00815 Reset_safe_to_speculate();
00816 return;
00817 }
00818
00819 if (Base_is_fixed()) {
00820 ST *base = Base();
00821 mINT64 ofst = 0;
00822 mINT64 size;
00823 if (((ST_class(base) != CLASS_VAR) &&
00824 (ST_class(base) != CLASS_CONST) &&
00825 (ST_class(base) != CLASS_PREG)) ||
00826 (ST_type(base) == (TY_IDX) NULL)) {
00827 size = 0;
00828 }
00829 else {
00830 size = TY_size(ST_type(base));
00831 }
00832
00833 if (ST_sclass(base) == SCLASS_REG || ST_sclass(base) == SCLASS_TEXT) {
00834 Set_base_kind(BASE_IS_UNKNOWN);
00835 Reset_safe_to_speculate();
00836 return;
00837 }
00838
00839 Expand_ST_into_base_and_ofst (base, 0, &base, &ofst);
00840
00841
00842 mINT64 object_size = 0;
00843 if (Ofst_kind() == OFST_IS_FIXED && wn != NULL &&
00844 (object_size = WN_object_size(wn)) > 0) {
00845 Set_base(base);
00846 Shift_ofst(ofst);
00847 Is_True(Is_pointer(), ("Pt is not a pointer."));
00848 #ifdef KEY
00849
00850
00851 if (!Is_field() || Byte_Size() == 0)
00852 Set_byte_size(Byte_Size() + object_size);
00853 #else
00854 Set_byte_size( Byte_Size() + object_size);
00855 #endif // KEY
00856 } else {
00857
00858 Set_bit_ofst_size(0, 0);
00859 if (size > 0) {
00860 Set_ofst_kind(OFST_IS_FIXED);
00861 Set_base(base);
00862 Set_byte_ofst(ofst);
00863 Set_byte_size(size);
00864 } else {
00865 Set_base(base);
00866 Set_ofst_kind(OFST_IS_UNKNOWN);
00867 }
00868 }
00869
00870
00871
00872 if (Ofst_kind() == OFST_IS_FIXED) {
00873 if (Byte_Ofst() < ofst || Byte_Size() + Byte_Ofst() > size + ofst) {
00874 Reset_safe_to_speculate();
00875 if (!Alias_Common_Scalar)
00876 Set_ofst_kind(OFST_IS_UNKNOWN);
00877 else
00878 Set_byte_size(size);
00879 Set_bit_ofst_size(0, 0);
00880 }
00881
00882 }
00883
00884 } else if (Restricted() || Unique_pt()) {
00885
00886 Reset_safe_to_speculate();
00887 ST *st = Based_sym();
00888 UINT64 size = st ? TY_size (ST_type (st)) : 0;
00889 if (size > 0) {
00890 Set_ofst_kind(OFST_IS_FIXED);
00891 Set_byte_ofst(0);
00892 Set_byte_size(size);
00893 } else
00894 Set_ofst_kind(OFST_IS_UNKNOWN);
00895 Set_bit_ofst_size(0, 0);
00896 } else {
00897
00898 Reset_safe_to_speculate();
00899 if (Ofst_kind() == OFST_IS_FIXED && Is_pointer() && wn != NULL) {
00900 Set_byte_size(Byte_Size() + WN_object_size(wn));
00901 } else {
00902 if ((Pointer () != NULL) && (Iofst_kind () == OFST_IS_FIXED) &&
00903 wn && (WN_desc(wn) != MTYPE_BS)) {
00904 Set_byte_size(Byte_Size() + WN_object_size(wn));
00905 }
00906 Set_ofst_kind(OFST_IS_UNKNOWN);
00907 }
00908 }
00909
00910
00911 Reset_is_pointer();
00912
00913 Is_True(!(Ofst_kind() == OFST_IS_FIXED && Byte_Size() == 0),
00914 ("Ofst is fixed and size == 0."));
00915 }
00916
00917
00918
00919
00920
00921 void POINTS_TO::Analyze_Lda_Base(WN *wn_lda, const OPT_STAB &opt_stab)
00922 {
00923 Is_True(WN_operator(wn_lda) == OPR_LDA, ("WN operator is not LDA."));
00924 AUX_ID aux = WN_aux(wn_lda);
00925
00926
00927
00928
00929
00930
00931
00932
00933 ST *st = opt_stab.Aux_stab_entry(aux)->St();
00934 INT64 st_ofst = opt_stab.Aux_stab_entry(aux)->St_ofst();
00935 Copy_non_sticky_info(opt_stab.Aux_stab_entry(aux)->Points_to());
00936 Set_base(st);
00937 Set_byte_ofst(st_ofst);
00938 #ifdef KEY
00939
00940
00941
00942 if (!Alias_Pointer_Types || opt_stab.Aux_stab_entry(aux)->Field_id() == 0)
00943 Set_byte_size( 0 );
00944 else
00945 Set_is_field();
00946 #else
00947 Set_byte_size( 0 );
00948 #endif // KEY
00949 Set_is_pointer();
00950 Invalidate_ptr_info ();
00951 }
00952
00953
00954
00955 void POINTS_TO::Analyze_Lda_Base(WN *wn_lda, const STAB_ADAPTER &stab)
00956 {
00957 Is_True(WN_operator(wn_lda) == OPR_LDA, ("WN operator is not LDA."));
00958 Analyze_ST(WN_st(wn_lda), WN_offset(wn_lda), 0, 0, 0, (TY_IDX)NULL, TRUE);
00959 Set_is_pointer();
00960 Set_byte_size(0);
00961 Set_bit_ofst_size(0,0);
00962 Invalidate_ptr_info ();
00963 }
00964
00965
00966 void POINTS_TO::Analyze_WN_expr(WN *wn)
00967 {
00968 Analyze_WN_expr(wn, STAB_ADAPTER());
00969 }
00970
00971
00972 ST *Is_nested_call(const WN *wn)
00973 {
00974 return Is_nested_call(wn, STAB_ADAPTER());
00975 }
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985 void
00986 POINTS_TO_LIST::Prepend( POINTS_TO *pt, MEM_POOL *pool )
00987 {
00988 POINTS_TO_NODE *ptn = CXX_NEW( POINTS_TO_NODE(pt), pool );
00989 Prepend( ptn );
00990 }
00991
00992
00993
00994
00995
00996 void POINTS_TO::Print(FILE *fp) const
00997 {
00998 BOOL pr_ofst = FALSE;
00999 BOOL pr_size = FALSE;
01000
01001 switch (Expr_kind()) {
01002 case EXPR_IS_INVALID:
01003 fprintf(fp, "expr invalid\n");
01004 return;
01005 case EXPR_IS_INT:
01006 fprintf(fp, "expr is integer\n");
01007 return;
01008 case EXPR_IS_ANY:
01009 fprintf(fp, "expr is any, ");
01010 break;
01011 case EXPR_IS_UNKNOWN:
01012 fprintf(fp, "expr is unknown, ");
01013 break;
01014 case EXPR_IS_BEING_PROCESSED:
01015 fprintf(fp, "expr is being processed, ");
01016 break;
01017 }
01018
01019 switch (Base_kind()) {
01020 case BASE_IS_INVALID:
01021 fprintf(fp, "base invalid, ");
01022 break;
01023 case BASE_IS_FIXED:
01024 fprintf(fp, "fixed %s, ", ST_class(Base()) != CLASS_CONST ?
01025 ST_name(Base()) : "constant");
01026 pr_ofst = TRUE;
01027 break;
01028 case BASE_IS_DYNAMIC:
01029 fprintf(fp, "dynamic, ");
01030 pr_ofst = TRUE;
01031 break;
01032 case BASE_IS_UNKNOWN:
01033 fprintf(fp, "base unknown, ");
01034 break;
01035 }
01036 if (pr_ofst) {
01037 switch (Ofst_kind()) {
01038 case OFST_IS_INVALID:
01039 fprintf(fp, "ofst invalid, ");
01040 break;
01041 case OFST_IS_FIXED:
01042 fprintf(fp, "byte ofst is %lld, ", Byte_Ofst());
01043 if (Bit_Size() != 0)
01044 fprintf(fp, "bit ofst is %d, ", Bit_Ofst());
01045 pr_size = TRUE;
01046 break;
01047 case OFST_IS_UNKNOWN:
01048 fprintf(fp, "ofst unknown, ");
01049 break;
01050 }
01051 }
01052 if (pr_size) {
01053 fprintf(fp, "byte size is %lld, ", Byte_Size());
01054 if (Bit_Size() != 0)
01055 fprintf(fp, "bit size is %d, ", Bit_Size());
01056 }
01057 fprintf(fp, "per-PU class %d, ", Alias_class());
01058 fprintf(fp, "global class %d, ", Ip_alias_class());
01059 fprintf(fp, "ty=%d, hlty=%d, ", Ty(), Highlevel_Ty ());
01060
01061
01062 fprintf(fp, "attr=");
01063 const char *pr_separator = "";
01064 if (Not_addr_saved()) {
01065 fprintf(fp, "%snot_addr_saved", pr_separator);
01066 pr_separator = "|";
01067 }
01068 if (Not_addr_passed()) {
01069 fprintf(fp, "%snot_addr_passed", pr_separator);
01070 pr_separator = "|";
01071 }
01072 if (Local()) {
01073 fprintf(fp, "%slocal", pr_separator);
01074 pr_separator = "|";
01075 }
01076 if (Global()) {
01077 fprintf(fp, "%sglobal", pr_separator);
01078 pr_separator = "|";
01079 }
01080 if (Named()) {
01081 fprintf(fp, "%snamed", pr_separator);
01082 pr_separator = "|";
01083 }
01084 if (Const()) {
01085 fprintf(fp, "%sconst", pr_separator);
01086 pr_separator = "|";
01087 }
01088 if (Restricted()) {
01089 fprintf(fp, "%srestricted", pr_separator);
01090 pr_separator = "|";
01091 }
01092 if (Unique_pt()) {
01093 fprintf(fp, "%sunique_pt", pr_separator);
01094 pr_separator = "|";
01095 }
01096 if (F_param()) {
01097 fprintf(fp, "%sf_param", pr_separator);
01098 pr_separator = "|";
01099 }
01100 if (Dedicated()) {
01101 fprintf(fp, "%sdedicated", pr_separator);
01102 pr_separator = "|";
01103 }
01104 if (No_alias()) {
01105 fprintf(fp, "%sno_alias", pr_separator);
01106 pr_separator = "|";
01107 }
01108 if (Weak()) {
01109 fprintf(fp, "%sweak", pr_separator);
01110 pr_separator = "|";
01111 }
01112 if (Weak_base()) {
01113 fprintf(fp, "%sweak_base", pr_separator);
01114 pr_separator = "|";
01115 }
01116 if (Is_pointer()) {
01117 fprintf(fp, "%sis_pointer", pr_separator);
01118 pr_separator = "|";
01119 }
01120 if (Safe_to_speculate()) {
01121 fprintf(fp, "%ssafe_to_speculate", pr_separator);
01122 pr_separator = "|";
01123 }
01124 if (Not_auto()) {
01125 fprintf(fp, "%snot_auto", pr_separator);
01126 pr_separator = "|";
01127 }
01128 if (Known_f90_pointer()) {
01129 fprintf(fp, "%sf90_pointer", pr_separator);
01130 pr_separator = "|";
01131 }
01132 if (Known_not_f90_pointer()) {
01133 fprintf(fp, "%snot_f90_pointer", pr_separator);
01134 pr_separator = "|";
01135 }
01136 if (Not_f90_target()) {
01137 fprintf(fp, "%snot_f90_target", pr_separator);
01138 pr_separator = "|";
01139 }
01140 if (Default_vsym()) {
01141 fprintf(fp, "%sdef_vsym", pr_separator);
01142 pr_separator = "|";
01143 }
01144 #ifdef KEY
01145 if (Is_field()) {
01146 fprintf(fp, "%sis_field", pr_separator);
01147 pr_separator = "|";
01148 }
01149 #endif
01150
01151 #ifdef _LP64
01152 #define UNDEFINED_PTR (void *)0xa5a5a5a5a5a5a5a5LL
01153 #else
01154 #define UNDEFINED_PTR (void *)0xa5a5a5a5
01155 #endif
01156
01157 if (Based_sym())
01158 fprintf(fp, ", based_sym=%s(%d)\n", (Based_sym() == UNDEFINED_PTR) ?
01159 "*UNDEFINED*" : ST_name(Based_sym()), Based_sym_depth());
01160 else
01161 fprintf(fp, ", based_sym=null\n");
01162
01163 if (Pointer_is_named_symbol () || Pointer_is_aux_id () ||
01164 Pointer_is_coderep_id ()) {
01165
01166 if (Pointer_is_named_symbol ()) {
01167 fprintf (fp, ", ptr=%s ver=%d ",
01168 Pointer() ? ST_name(Pointer()) : NULL, (INT)Pointer_ver());
01169 } else if (Pointer_is_aux_id ()) {
01170 fprintf (fp, ", ptr=auxid-%d ver=%d ", Pointer_aux_id(), (INT)Pointer_ver());
01171 } else {
01172 fprintf (fp, ", ptr=cdrepid-%d ", Pointer_coderep_id ());
01173 }
01174
01175 if (Iofst_kind () == OFST_IS_FIXED) {
01176 fprintf(fp, "byte ofst %lld, ", Byte_Ofst());
01177 if (Bit_Size() != 0)
01178 fprintf(fp, "bit ofst %d, ", Bit_Ofst());
01179 fprintf(fp, "byte size is %lld, ", Byte_Size());
01180 if (Bit_Size() != 0)
01181 fprintf(fp, "bit size is %d, ", Bit_Size());
01182 }
01183 }
01184
01185 if (_mem_annot.Has_annotation ()) {
01186 _mem_annot.Print (fp, FALSE);
01187 }
01188
01189 fprintf (fp, "\n");
01190 }
01191
01192
01193 #ifdef Is_True_On
01194
01195 void CHECK_POINTS_TO(POINTS_TO *pt)
01196 {
01197 if ( pt->Expr_kind() != EXPR_IS_ANY
01198 && pt->Expr_kind() != EXPR_IS_BEING_PROCESSED)
01199 {
01200 FmtAssert ( pt->Expr_kind() != EXPR_IS_INVALID,
01201 ("CHECK_POINTS_TO: pt is EXPR_IS_INVALID.") );
01202 if ( pt->Expr_kind() == EXPR_IS_ADDR ) {
01203 FmtAssert ( pt->Base_kind() != BASE_IS_INVALID,
01204 ("CHECK_POINTS_TO: pt is BASE_IS_INVALID.") );
01205 }
01206 }
01207
01208
01209
01210 if (pt->Expr_kind() != EXPR_IS_ADDR) {
01211 if (pt->Not_addr_saved() ||
01212 pt->Not_addr_passed() ||
01213 pt->Local() ||
01214 pt->Global() ||
01215 pt->Named() ||
01216 pt->Const() ||
01217
01218
01219 pt->F_param() ||
01220 pt->No_alias())
01221 FmtAssert ( FALSE,
01222 ("CHECK_POINTS_TO: pt has invalid attributes.") );
01223 }
01224 }
01225 #endif
01226