Open64 (mfef90, whirl2f, and IR tools)
TAG: version-openad; SVN changeset: 916
|
00001 /* 00002 00003 Copyright (C) 2000, 2001 Silicon Graphics, Inc. All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify it 00006 under the terms of version 2 of the GNU General Public License as 00007 published by the Free Software Foundation. 00008 00009 This program is distributed in the hope that it would be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 00013 Further, this software is distributed without any warranty that it is 00014 free of the rightful claim of any third person regarding infringement 00015 or the like. Any license provided herein, whether implied or 00016 otherwise, applies only to this software file. Patent licenses, if 00017 any, provided herein do not apply to combinations of this program with 00018 other software, or any other product whatsoever. 00019 00020 You should have received a copy of the GNU General Public License along 00021 with this program; if not, write the Free Software Foundation, Inc., 59 00022 Temple Place - Suite 330, Boston MA 02111-1307, USA. 00023 00024 Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pky, 00025 Mountain View, CA 94043, or: 00026 00027 http://www.sgi.com 00028 00029 For further information regarding this notice, see: 00030 00031 http://oss.sgi.com/projects/GenInfo/NoticeExplan 00032 00033 */ 00034 00035 00036 /* -*-Mode: c++;-*- (Tell emacs to use c++ mode) */ 00037 00038 #ifndef symtab_utils_INCLUDED 00039 #define symtab_utils_INCLUDED 00040 00041 #include <upc_symtab_utils.h> 00042 00043 00044 // This file should contains only function prototypes and inlined function 00045 // definitions for utility routines operating on the symbol table classes. 00046 00047 //---------------------------------------------------------------------- 00048 // ST-related utilities 00049 //---------------------------------------------------------------------- 00050 extern INT64 00051 ST_size (const ST *); // size of st (depends on class) 00052 00053 extern ST * 00054 Copy_ST (ST *st); // make a copy of st in the same scope 00055 00056 extern ST * 00057 Copy_ST (ST *st, SYMTAB_IDX scope); // copy an st to different ST table 00058 00059 extern ST * 00060 Copy_ST_No_Base (ST *st, SYMTAB_IDX scope); // copy an st to different ST table, used by IPA inlining and cloning 00061 00062 // Return TRUE iff the ST is known to be a constant literal or a const 00063 // variable. 00064 extern BOOL 00065 ST_is_constant (const ST *); 00066 00067 // Return FALSE if the current PU is recursive or the ST is not in 00068 // the local symtab. May return TRUE otherwise; the more we return 00069 // TRUE, the better we optimize. 00070 extern BOOL 00071 ST_is_private_local(const ST *); 00072 00073 // Create symbols for temp var or symbol. 00074 extern ST * 00075 Gen_Temp_Symbol(TY_IDX ty, const char *rootname); 00076 00077 extern ST * 00078 Gen_Read_Only_Symbol(TY_IDX, const char *rootname); 00079 00080 inline BOOL 00081 ST_visible_outside_dso(const ST &s) 00082 { 00083 // rely on fe or ipa to set static funcs to internal 00084 return (ST_export(s) != EXPORT_INTERNAL && 00085 ST_export(s) != EXPORT_LOCAL_INTERNAL); 00086 } 00087 inline BOOL 00088 ST_visible_outside_dso(const ST *s) { return ST_visible_outside_dso(*s); } 00089 00090 00091 // implementation still incomplete. 00092 ST * 00093 Gen_Intrinsic_Function(TY_IDX, const char *function_name); 00094 00095 // implementation still incomplete. 00096 TY_IDX 00097 Make_Function_Type(TY_IDX return_ty_idx); 00098 00099 TY_IDX 00100 Make_Array_Type(TYPE_ID element_type, INT32 ndim, INT64 len); 00101 00102 //---------------------------------------------------------------------- 00103 // TY-related utilities 00104 //---------------------------------------------------------------------- 00105 extern TY_IDX MTYPE_TO_TY_array[MTYPE_LAST+1]; 00106 #define MTYPE_To_TY(t) MTYPE_TO_TY_array[t] 00107 #define Be_Type_Tbl(t) MTYPE_TO_TY_array[t] 00108 00109 // Well known predefined types 00110 extern TY_IDX Void_Type, FE_int_Type, FE_double_Type; 00111 extern TY_IDX Spill_Int_Type, Spill_Float_Type; 00112 00113 TY_IDX 00114 Copy_TY (TY_IDX ty); // make a copy of a ty 00115 00116 // Given a alignment value that is assumed to be a power of 2, returns the 00117 // log (base 2) of it. That is, (1 << TY_log_base2 (align)) == align. 00118 extern UINT 00119 TY_log_base2 (UINT align); 00120 00121 // return a type that points to ty. return 0 if none can be found 00122 TY_IDX 00123 TY_pointer (TY_IDX ty, BOOL f90_pointer = FALSE); 00124 00130 TY_IDX 00131 Make_Shared_Type(TY_IDX ty_idx, int bsize, CONSISTENCY_class consistency = NO_CONSISTENCY); 00132 00133 // f90_pointer argument is ignored now, use Make_F90_Pointer_Type 00134 TY_IDX 00135 Make_Pointer_Type (TY_IDX ty_idx, BOOL f90_pointer = FALSE); 00136 00137 TY_IDX 00138 Make_F90_Pointer_Type (TY_IDX ty_idx); 00139 00140 00141 inline TY_IDX 00142 Make_Align_Type (TY_IDX ty_idx, INT32 align) 00143 { 00144 Set_TY_align (ty_idx, align); 00145 return ty_idx; 00146 } 00147 00148 TY_IDX 00149 Make_Array_Type (TYPE_ID element, INT32 ndim, INT64 len); 00150 00151 /* Given a variable, find the type to which it is promoted for 00152 * passing as a procedure argument. For most, this is simply 00153 * ST_type(st). However, if ST_promote_parm(st) is set, we must check 00154 * the promotion rules for C: 00155 */ 00156 TY_IDX 00157 Promoted_Parm_Type(const ST *); 00158 00159 /* Are two types equivalent? This function does equivalence check on 00160 * name equivalence + structural equivalence (looks also at names) by 00161 * default, while flags may be set to turn off/on certain checks. The 00162 * default is to have all flags be zero (FALSE). Note that alignment 00163 * and qualifier checking can only be turned on for the top level of a 00164 * constructed type. Nested type references are always checked for 00165 * qualifier and alignment equality. 00166 */ 00167 #define TY_EQUIV_NO_FLAGS 0x00000000 00168 #define TY_EQUIV_IGNORE_NAMES 0x00000001 /* ignore names */ 00169 #define TY_EQUIV_ALIGN 0x00000002 /* check for equal alignment */ 00170 #define TY_EQUIV_QUALIFIER 0x00000004 /* check for equal qualifiers */ 00171 BOOL 00172 TY_are_equivalent (TY_IDX ty_id1, 00173 TY_IDX ty_id2, 00174 UINT32 flags = TY_EQUIV_NO_FLAGS); 00175 00176 /* TY_is_unique: Is a given type "new" or has it already been created? 00177 * calls TY_are_equivalent with all flags "off" (TY_EQUIV_NO_FLAGS) 00178 * to check for duplicates from existing TY table; Returns the input 00179 * TY_IDX if the given type is unique, and another equivalent TY_IDX 00180 * otherwise. 00181 * 00182 * Note that this function serves two purposes. It checks for duplicates 00183 * against other types for which this function has already been called; 00184 * and it enters a unique type into a hash-table for use in subsequent 00185 * calls to this function. I.e. it serves both to test for uniqueness, 00186 * and to create a dataset of unique types. 00187 */ 00188 extern TY_IDX 00189 TY_is_unique (const TY_IDX ty_idx); 00190 00191 //---------------------------------------------------------------------- 00192 // PREG-related utilities 00193 //---------------------------------------------------------------------- 00194 /* 00195 * predefined PREG symbols, one for each mtype 00196 * (actually only have pregs for the register-size mtypes and simulated mtypes; 00197 * in particular, the I1/I2/U1/U2 mtypes point to the 4-byte PREG. 00198 */ 00199 extern ST* MTYPE_TO_PREG_array[MTYPE_LAST+1]; 00200 #define MTYPE_To_PREG(t) MTYPE_TO_PREG_array[t] 00201 #define Int32_Preg MTYPE_To_PREG (MTYPE_I4) 00202 #define Int64_Preg MTYPE_To_PREG (MTYPE_I8) 00203 #define Float32_Preg MTYPE_To_PREG (MTYPE_F4) 00204 #define Float64_Preg MTYPE_To_PREG (MTYPE_F8) 00205 /* preferred preg symbols for physical registers 00206 * (point to one of above pregs, depending on ABI). */ 00207 extern ST *Int_Preg, *Float_Preg, *Return_Val_Preg; /* for pseudo-registers */ 00208 00209 const char * 00210 Preg_Name (PREG_NUM i); 00211 00212 /* create a non-dedicated preg */ 00213 extern PREG_NUM 00214 Create_Preg_explicit (TYPE_ID mtype, const char *name, 00215 SCOPE *scope_tab, SYMTAB_IDX level); 00216 00217 extern PREG_NUM 00218 Create_Preg (TYPE_ID mtype, const char *name); 00219 00220 extern INT32 00221 Preg_Increment (TYPE_ID mtype); 00222 00223 //---------------------------------------------------------------------- 00224 // ARB utilities 00225 //---------------------------------------------------------------------- 00226 BOOL 00227 ARB_are_equivalent(ARB_HANDLE arb_id1, 00228 ARB_HANDLE arb_id2, 00229 UINT32 flags = TY_EQUIV_NO_FLAGS); 00230 00231 // Swap the internal contents of two ARB's 00232 void ARB_swap(ARB_HANDLE arb1, ARB_HANDLE arb2); 00233 00234 // Copy the internal contents of an ARB's 00235 inline void ARB_copy(ARB_HANDLE arb1, ARB_HANDLE arb2) { 00236 *(arb1.Entry()) = *(arb2.Entry()); 00237 } 00238 00239 00240 //---------------------------------------------------------------------- 00241 // FLD utilities 00242 //---------------------------------------------------------------------- 00243 BOOL 00244 FLD_are_equivalent(FLD_HANDLE fld_id1, 00245 FLD_HANDLE fld_id2, 00246 UINT32 flags = TY_EQUIV_NO_FLAGS); 00247 00248 extern FLD_HANDLE 00249 FLD_get_to_field (TY_IDX struct_ty_idx, UINT field_id, UINT &cur_field_id); 00250 00251 //---------------------------------------------------------------------- 00252 // TYLIST utilities 00253 //---------------------------------------------------------------------- 00254 BOOL 00255 TYLIST_are_equivalent(TYLIST_IDX tylist_id1, 00256 TYLIST_IDX tylist_id2, 00257 UINT32 flags = TY_EQUIV_NO_FLAGS); 00258 00259 //---------------------------------------------------------------------- 00260 // BLK utilities 00261 //---------------------------------------------------------------------- 00262 BLK_IDX Copy_BLK (BLK_IDX b); // copy a block 00263 00264 // Get the base symbol and the offset from a ST 00265 extern void Base_Symbol_And_Offset ( 00266 ST *st, // Symbol to analyze 00267 ST **base_symbol, // Result: root base of st 00268 INT64 *offset_from_base // Result: offset from primary base 00269 ); 00270 00271 //---------------------------------------------------------------------- 00272 // Enum value <-> string 00273 //---------------------------------------------------------------------- 00274 00275 const char * 00276 Class_Name (ST_CLASS cl); 00277 00278 ST_CLASS 00279 Name_To_Class (const char* nm); 00280 00281 00282 const char * 00283 Sclass_Name (ST_SCLASS sc); 00284 00285 ST_SCLASS 00286 Name_To_Sclass (const char* nm); 00287 00288 00289 const char * 00290 Export_Name (ST_EXPORT ex); 00291 00292 ST_EXPORT 00293 Name_To_Export (const char* nm); 00294 00295 00296 const char * 00297 Kind_Name (TY_KIND k); 00298 00299 TY_KIND 00300 Name_To_Kind (const char* nm); 00301 00302 00303 const char * 00304 LABEL_Kind_Name (LABEL_KIND k); 00305 00306 LABEL_KIND 00307 Name_To_LABEL_Kind (const char* nm); 00308 00309 00310 const char * 00311 ST_ATTR_Kind_Name (ST_ATTR_KIND k); 00312 00313 ST_ATTR_KIND 00314 Name_To_ST_ATTR_Kind (const char* nm); 00315 00316 00317 //---------------------------------------------------------------------- 00318 // Flags <-> string 00319 //---------------------------------------------------------------------- 00320 00321 const char * 00322 FILE_INFO_FLAGS_To_Str (UINT64 flags); 00323 00324 UINT64 00325 Str_To_FILE_INFO_FLAGS (const char* str); 00326 00327 00328 const char * 00329 ST_FLAGS_To_Str (UINT64 flags); 00330 00331 UINT64 00332 Str_To_ST_FLAGS (const char* str); 00333 00334 00335 const char * 00336 ST_EXT_FLAGS_To_Str (UINT64 flags); 00337 00338 UINT64 00339 Str_To_ST_EXT_FLAGS (const char* str); 00340 00341 00342 const char * 00343 FLD_FLAGS_To_Str (UINT64 flags); 00344 00345 UINT64 00346 Str_To_FLD_FLAGS (const char* str); 00347 00348 00349 const char * 00350 ARB_FLAGS_To_Str (UINT64 flags); 00351 00352 UINT64 00353 Str_To_ARB_FLAGS (const char* str); 00354 00355 00356 const char * 00357 LABEL_FLAGS_To_Str (UINT64 flags); 00358 00359 UINT64 00360 Str_To_LABEL_FLAGS (const char* str); 00361 00362 00363 const char * 00364 TY_FLAGS_To_Str (UINT64 flags); 00365 00366 UINT64 00367 Str_To_TY_FLAGS (const char* str); 00368 00369 00370 const char * 00371 TY_PU_FLAGS_To_Str (UINT64 flags); 00372 00373 UINT64 00374 Str_To_TY_PU_FLAGS (const char* str); 00375 00376 00377 const char * 00378 PU_FLAGS_To_Str (UINT64 flags); 00379 00380 UINT64 00381 Str_To_PU_FLAGS (const char* str); 00382 00383 00384 const char * 00385 PU_SRC_LANG_FLAGS_To_Str (UINT64 flags); 00386 00387 UINT64 00388 Str_To_PU_SRC_LANG_FLAGS (const char* str); 00389 00390 00391 const char * 00392 BLK_FLAGS_To_Str (UINT64 flags); 00393 00394 UINT64 00395 Str_To_BLK_FLAGS (const char* str); 00396 00397 00398 //---------------------------------------------------------------------- 00399 // 00400 //---------------------------------------------------------------------- 00401 00402 void 00403 Print_local_symtab (FILE *f, const SCOPE& scope); 00404 00405 void 00406 Print_global_symtab (FILE *f); 00407 00408 inline void 00409 Print_symtab (FILE *f, SYMTAB_IDX level) 00410 { 00411 if (level > GLOBAL_SYMTAB) 00412 Print_local_symtab (f, Scope_tab[level]); 00413 else 00414 Print_global_symtab (f); 00415 } 00416 00417 00418 //---------------------------------------------------------------------- 00419 // Initialization 00420 //---------------------------------------------------------------------- 00421 void 00422 New_Scope (SYMTAB_IDX level, MEM_POOL *pool, BOOL reserve_index_zero); 00423 00424 void 00425 Delete_Scope (SYMTAB_IDX level); 00426 00427 void 00428 Initialize_Symbol_Tables (BOOL reserve_index_zero); 00429 00430 void 00431 Initialize_Special_Global_Symbols (); 00432 00433 00434 //---------------------------------------------------------------------- 00435 // Iterators 00436 //---------------------------------------------------------------------- 00437 inline PU_ITER 00438 Make_pu_iter (PU_IDX pu_idx) 00439 { 00440 return PU_ITER (&Pu_Table, pu_idx); 00441 } 00442 00443 inline ST_ITER 00444 Make_st_iter (const ST *st) 00445 { 00446 ST_IDX idx = ST_st_idx (*st); 00447 return ST_ITER (Scope_tab[ST_IDX_level (idx)].st_tab, ST_IDX_index (idx)); 00448 } 00449 00450 inline TY_ITER 00451 Make_ty_iter (TY_IDX ty_idx) 00452 { 00453 return TY_ITER (&Ty_Table, TY_IDX_index (ty_idx)); 00454 } 00455 00456 inline FLD_ITER 00457 Make_fld_iter (FLD_HANDLE fld) 00458 { 00459 return FLD_ITER (&Fld_Table, fld.Idx()); 00460 } 00461 00462 inline TYLIST_ITER 00463 Make_tylist_iter (TYLIST_IDX tylist_idx) 00464 { 00465 return TYLIST_ITER (&Tylist_Table, tylist_idx); 00466 } 00467 00468 inline ARB_ITER 00469 Make_arb_iter (ARB_HANDLE arb) 00470 { 00471 return ARB_ITER (&Arb_Table, arb.Idx()); 00472 } 00473 00474 inline LABEL_ITER 00475 Make_label_iter (LABEL_IDX label_idx) 00476 { 00477 return LABEL_ITER (Scope_tab[CURRENT_SYMTAB].label_tab, label_idx); 00478 } 00479 00480 inline PREG_ITER 00481 Make_preg_iter (PREG_IDX preg_idx) 00482 { 00483 return PREG_ITER (Scope_tab[CURRENT_SYMTAB].preg_tab, preg_idx); 00484 } 00485 00486 inline ST_ATTR_ITER 00487 Make_st_attr_iter (ST_ATTR_IDX st_attr_idx) 00488 { 00489 return ST_ATTR_ITER (Scope_tab[CURRENT_SYMTAB].st_attr_tab, st_attr_idx); 00490 } 00491 00492 inline TCON_ITER 00493 Make_tcon_iter (TCON_IDX tcon_idx) 00494 { 00495 return TCON_ITER (&Tcon_Table, tcon_idx); 00496 } 00497 00498 inline INITO_ITER 00499 Make_inito_iter (INITO_IDX inito_idx) 00500 { 00501 return INITO_ITER (Scope_tab[INITO_IDX_level (inito_idx)].inito_tab, 00502 INITO_IDX_index (inito_idx)); 00503 } 00504 00505 inline INITV_ITER 00506 Make_initv_iter (INITV_IDX initv_idx) 00507 { 00508 return INITV_ITER (&Initv_Table, initv_idx); 00509 } 00510 00511 00512 // loop over all symbols, always skip the first entry because it is reserved. 00513 00514 template <class T, UINT block_size, class OP> 00515 inline void 00516 For_all (SEGMENTED_ARRAY<T, block_size>& table, const OP& op) 00517 { 00518 For_all_entries (table, op, 1); 00519 } 00520 00521 template <class T, UINT block_size, class OP> 00522 inline void 00523 For_all (RELATED_SEGMENTED_ARRAY<T, block_size>& table, const OP& op) 00524 { 00525 For_all_entries (table, op, 1); 00526 } 00527 00528 template <class OP> 00529 inline void 00530 For_all (const SYMBOL_TABLE&, SYMTAB_IDX level, const OP& op) 00531 { 00532 For_all_entries (*Scope_tab[level].st_tab, op, 1); 00533 } 00534 00535 template <class OP> 00536 inline void 00537 For_all (const INITO_TABLE&, SYMTAB_IDX level, const OP& op) 00538 { 00539 For_all_entries (*Scope_tab[level].inito_tab, op, 1); 00540 } 00541 00542 template <class OP> 00543 inline void 00544 For_all (const LABEL_TABLE&, const OP& op) 00545 { 00546 For_all_entries (*Scope_tab[CURRENT_SYMTAB].label_tab, op, 1); 00547 } 00548 00549 template <class OP> 00550 inline void 00551 For_all (const PREG_TABLE&, const OP& op) 00552 { 00553 For_all_entries (*Scope_tab[CURRENT_SYMTAB].preg_tab, op, 1); 00554 } 00555 00556 template <class OP> 00557 inline void 00558 For_all (const ST_ATTR_TABLE&, SYMTAB_IDX level, const OP& op) 00559 { 00560 For_all_entries (*Scope_tab[level].st_attr_tab, op, 1); 00561 } 00562 00563 template <class OP> 00564 inline void 00565 For_all (const TYPE_TABLE&, const OP& op) 00566 { 00567 For_all_entries (Ty_tab, op, 1); 00568 } 00569 00570 00571 //---------------------------------------------------------------------- 00572 // iterator with early exit 00573 //---------------------------------------------------------------------- 00574 00575 template <class T, UINT block_size, class PREDICATE> 00576 inline UINT32 00577 For_all_until (const SEGMENTED_ARRAY<T, block_size>& table, 00578 const PREDICATE& pred) 00579 { 00580 UINT32 idx = Find_entry_if (table, pred, 1); 00581 return (idx == NOT_FOUND) ? 0 : idx; 00582 } 00583 00584 template <class T, UINT block_size, class PREDICATE> 00585 inline UINT32 00586 For_all_until (const RELATED_SEGMENTED_ARRAY<T, block_size>& table, 00587 const PREDICATE& pred) 00588 { 00589 UINT32 idx = Find_entry_if (table, pred, 1); 00590 return (idx == NOT_FOUND) ? 0 : idx; 00591 } 00592 00593 template <class PREDICATE> 00594 inline ST_IDX 00595 For_all_until (const SYMBOL_TABLE&, SYMTAB_IDX level, const PREDICATE& pred) 00596 { 00597 UINT32 idx = Find_entry_if (*Scope_tab[level].st_tab, pred, 1); 00598 return (idx == NOT_FOUND) ? 0 : make_ST_IDX (idx, level); 00599 } 00600 00601 template <class PREDICATE> 00602 inline INITO_IDX 00603 For_all_until (const INITO_TABLE&, SYMTAB_IDX level, const PREDICATE& pred) 00604 { 00605 UINT32 idx = Find_entry_if (*Scope_tab[level].inito_tab, pred, 1); 00606 return (idx == NOT_FOUND) ? 0 : make_INITO_IDX (idx, level); 00607 } 00608 00609 template <class PREDICATE> 00610 inline UINT32 00611 For_all_until (const LABEL_TABLE&, const PREDICATE& pred) 00612 { 00613 UINT32 idx = Find_entry_if (*Scope_tab[CURRENT_SYMTAB].label_tab, pred, 1); 00614 return (idx == NOT_FOUND) ? 0 : idx; 00615 } 00616 00617 template <class PREDICATE> 00618 inline UINT32 00619 For_all_until (const PREG_TABLE&, const PREDICATE& pred) 00620 { 00621 UINT32 idx = Find_entry_if (*Scope_tab[CURRENT_SYMTAB].preg_tab, pred, 1); 00622 return (idx == NOT_FOUND) ? 0 : idx; 00623 } 00624 00625 template <class PREDICATE> 00626 inline ST_ATTR_IDX 00627 For_all_until (const ST_ATTR_TABLE&, SYMTAB_IDX level, const PREDICATE& pred) 00628 { 00629 UINT32 idx = Find_entry_if (*Scope_tab[level].st_attr_tab, pred, 1); 00630 return (idx == NOT_FOUND) ? 0 : idx; 00631 } 00632 00633 00634 template <class PREDICATE> 00635 inline TY_IDX 00636 For_all_until (const TYPE_TABLE&, const PREDICATE& pred) 00637 { 00638 UINT32 idx = Find_entry_if (Ty_tab, pred, 1); 00639 return (idx == NOT_FOUND) ? 0 : make_TY_IDX (idx); 00640 } 00641 00642 00643 00644 00645 // loop over all symbols (should change to use iterators) 00646 00647 #define FOREACH_SYMBOL(level,s,i) \ 00648 for (i = 1; i < ST_Table_Size(level) && (s = &St_Table(level,i)); ++i) 00649 00650 #define FOREACH_LABEL(level,s,i) \ 00651 for (i = 1; i < LABEL_Table_Size(level) && (s = &Label_Table(i)); ++i) 00652 00653 // loop over all inito's 00654 #define FOREACH_INITO(level,o,i) \ 00655 for (i = 1; i < INITO_Table_Size(level) && (o = &Inito_Table(level,i)); ++i) 00656 00657 #define FOREACH_INITV(init,v) \ 00658 for (v = init; v != 0; v = Initv_Table[v].next) 00659 00660 #endif /* symtab_utils_INCLUDED */ 00661 00662