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 #ifdef USE_PCH 00037 #include "be_com_pch.h" 00038 #endif /* USE_PCH */ 00039 #pragma hdrstop 00040 #include "be_symtab.h" 00041 #include "pu_info.h" 00042 #include "cxx_memory.h" 00043 00044 BE_SCOPE *Be_scope_tab; 00045 00046 BE_SYMBOL_TABLE Be_symbol_table; 00047 00048 BE_PREG_TAB Be_preg_tab; 00049 00050 static SYMTAB_IDX next_level = 0; 00051 00052 static MEM_POOL Be_symtab_pool; 00053 00054 void 00055 BE_symtab_initialize_be_scopes(void) 00056 { 00057 MEM_POOL_Initialize(&Be_symtab_pool, "back end symbol table", FALSE); 00058 MEM_POOL_Push(&Be_symtab_pool); 00059 } 00060 00061 void 00062 BE_symtab_free_be_scopes(void) 00063 { 00064 MEM_POOL_Pop(&Be_symtab_pool); 00065 MEM_POOL_Delete(&Be_symtab_pool); 00066 } 00067 00068 void 00069 BE_symtab_alloc_scope_level(const SYMTAB_IDX level) 00070 { 00071 while (level >= next_level) { 00072 BE_SCOPE *temp = CXX_NEW_ARRAY(BE_SCOPE, 1 + next_level * 2, 00073 &Be_symtab_pool); 00074 SYMTAB_IDX i; 00075 for (i = 0; i < next_level; i++) { 00076 temp[i] = Be_scope_tab[i]; 00077 } 00078 next_level = 1 + next_level * 2; 00079 for (; i < next_level; i++) { 00080 temp[i].be_st_tab = NULL; 00081 } 00082 CXX_DELETE_ARRAY(Be_scope_tab, &Be_symtab_pool); 00083 Be_scope_tab = temp; 00084 } 00085 SYMTAB_IDX i = level; 00086 while (Be_scope_tab[i].be_st_tab == NULL && i > 0) { 00087 Be_scope_tab[i].be_st_tab = CXX_NEW(BE_ST_TAB, &Be_symtab_pool); 00088 --i; 00089 } 00090 } 00091 00092 // Determine if the ST represents a constant 00093 BOOL 00094 ST_is_const_initialized (const ST* st) 00095 { 00096 /* make sure it's a variable (necessary check?) */ 00097 if ( ST_class(st) != CLASS_VAR ) 00098 return FALSE; 00099 00100 /* make sure it's a constant */ 00101 if (!ST_is_const_var(st)) 00102 return FALSE; 00103 00104 // is it a constant with unknown value? 00105 if (BE_ST_unknown_const(st)) 00106 return FALSE; 00107 00108 // uninitialized constant is the same as initialized with zero, so we 00109 // don't check the ST_is_initialized bit 00110 00111 /* get the type */ 00112 TY_IDX ty = ST_type(st); 00113 00114 /* just because it's constant doesn't mean it can't change behind 00115 * our backs. 00116 */ 00117 if (TY_is_volatile(ty)) { 00118 return FALSE; 00119 } 00120 00121 return TRUE; 00122 } 00123 00124 00125 // Support for ST_is_const_initialized_scalar: 00126 struct match_inito_by_st { 00127 private: 00128 const ST_IDX st_idx; 00129 00130 public: 00131 match_inito_by_st(const ST *const st) : st_idx(ST_st_idx(st)) { } 00132 match_inito_by_st(const ST_IDX esstee_idx) : st_idx(esstee_idx) { } 00133 00134 BOOL operator()(INITO_IDX, const INITO *inito) const 00135 { return INITO_st_idx(*inito) == st_idx; } 00136 }; 00137 00138 // Say whether the specified ST is a constant scalar variable 00139 // initialized by a constant, and if so, copy the TCON for the 00140 // constant into *tcon_copy. The caller takes responsibility for 00141 // entering the TCON into the table if the copy gets modified somehow 00142 // and s/he wants to save the modified version. 00143 BOOL 00144 ST_is_const_initialized_scalar(const ST *st, TCON &tcon_copy) 00145 { 00146 // Make sure it is not a constant with an unknown value. 00147 if (BE_ST_unknown_const(st) != 0) { 00148 Is_True (FALSE, ("Asking for value of unknown const")); 00149 return FALSE; 00150 } 00151 00152 if (!ST_is_const_initialized(st)) 00153 return FALSE; 00154 00155 TY_IDX ty = ST_type(st); 00156 TYPE_ID mtype = TY_mtype(ty); 00157 00158 // exclude all non-scalars 00159 if (!Is_Simple_Type(ty)) { 00160 return FALSE; 00161 } 00162 00163 // Determine if the symbol is explicitly initialized 00164 // (the for-loop is necessary to solve f90 bug #626430). 00165 // 00166 const ST *base; 00167 for (base = st; 00168 (!ST_is_initialized(base) && ST_base_idx(base) != ST_st_idx(base)); 00169 base = ST_base(base)); 00170 00171 BOOL initialized = ST_is_initialized(base); 00172 00173 // is the value known to be initialized to zero? 00174 // uninitialized is equivalent to init. to zero 00175 // 00176 if (!initialized || ST_init_value_zero(st)) { 00177 if (MTYPE_is_integral(mtype)) { 00178 tcon_copy = Host_To_Targ(mtype, 0L); 00179 } 00180 else { 00181 tcon_copy = Host_To_Targ_Float(mtype, 0.0); 00182 } 00183 return TRUE; 00184 } 00185 00186 // try to find the object that inits us; it must be at the same 00187 // scope level. 00188 INITO_IDX inito_idx = For_all_until(Inito_Table, 00189 ST_IDX_level(ST_st_idx(st)), 00190 match_inito_by_st(st)); 00191 00192 /* make sure we found it */ 00193 if (inito_idx == (INITO_IDX) 0) 00194 return FALSE; 00195 00196 /* make sure we have a value */ 00197 INITV &inov = Initv_Table[INITO_val(inito_idx)]; 00198 00199 switch (INITV_kind(inov)) { 00200 case INITVKIND_ZERO: 00201 tcon_copy = Host_To_Targ(mtype, 0L); 00202 return TRUE; 00203 case INITVKIND_ONE: 00204 tcon_copy = Host_To_Targ(mtype, 1L); 00205 return TRUE; 00206 case INITVKIND_VAL: 00207 tcon_copy = Tcon_Table[INITV_tc(inov)]; 00208 return TRUE; 00209 } 00210 return FALSE; 00211 } 00212 00213 00214 extern INITV_IDX 00215 ST_has_initv(const ST *st) 00216 { 00217 if (!ST_is_initialized (st)) 00218 return (INITV_IDX) 0; 00219 00220 TY_IDX ty = ST_type(st); 00221 00222 // try to find the object that inits us; it must be at the same 00223 // scope level. 00224 INITO_IDX inito_idx; 00225 inito_idx = For_all_until(Inito_Table, ST_IDX_level(ST_st_idx(st)), 00226 match_inito_by_st(st)); 00227 00228 if (inito_idx == (INITO_IDX) 0) { 00229 return (INITV_IDX) 0; 00230 } 00231 else { 00232 return INITO_val(inito_idx); 00233 } 00234 } 00235 00236 00237 // Determine if the ST represents a constant scalar variable that has 00238 // a known initialized value. If true, returns the INITV_IDX for the 00239 // value. 00240 extern INITV_IDX 00241 ST_is_const_and_has_initv(const ST *st) 00242 { 00243 // Make sure it is not a constant with an unknown value. 00244 if (BE_ST_unknown_const(st) != 0) { 00245 Is_True (FALSE, ("Asking for value/initv of unknown const")); 00246 return (INITV_IDX) 0; 00247 } 00248 00249 if (!ST_is_const_initialized(st)) 00250 return (INITV_IDX) 0; 00251 00252 return ST_has_initv(st); 00253 }