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 /* ==================================================================== 00037 * ==================================================================== 00038 * 00039 * Module: opt_alias_interface.h 00040 * $Revision: 1.2 $ 00041 * $Date: 02/11/07 23:41:38-00:00 $ 00042 * $Author: fchow@keyresearch.com $ 00043 * $Source: /scratch/mee/2.4-65/kpro64-pending/be/com/SCCS/s.opt_alias_interface.h $ 00044 * 00045 * Revision history: 00046 * 07-APR-95 lo - spilt from opt_alias.h 00047 * 00048 * Description: 00049 * 00050 * ==================================================================== 00051 * ==================================================================== 00052 */ 00053 00054 #ifndef opt_alias_interface_INCLUDED 00055 #define opt_alias_interface_INCLUDED "opt_alias_interface.h" 00056 #ifdef _KEEP_RCS_ID 00057 static char *opt_alias_interfacercs_id = opt_alias_interface_INCLUDED"$Revision: 1.2 $"; 00058 #endif /* _KEEP_RCS_ID */ 00059 00060 00061 /* ======================================================================== 00062 * 00063 * ALIAS ANALYSIS INTERFACE 00064 * ------------------------ 00065 * 00066 * The alias information is generated in the preopt/wopt phase. 00067 * The consumers are IPA, LNO, and CG. The information is passed in memory 00068 * for IPA and LNO. The information is emitted into the WHIRL IR 00069 * and passed through .B file to CG. 00070 * [ The previous sentence is a lie. The information is passed in 00071 * memory to CG as well. -- RK 981106 ] 00072 * 00073 * 00074 * ALIAS_MANAGER 00075 * ------------- 00076 * All the alias data is managed by the ALIAS_MANAGER. 00077 * The alias context is used to identify the alias rule set to 00078 * be applied. See opt_alias_rule.h for details about 00079 * ALIAS_CONTEXT. 00080 * 00081 * struct ALIAS_MANAGER *Create_Alias_Manager(void) 00082 * Create an alias manager. The alias manager will have its 00083 * own memory pool and manage the memory used by the alias information 00084 * itself. 00085 * 00086 * void Delete_Alias_Manager(struct ALIAS_MANAGER *) 00087 * Destroy the alias manager. Free the MEM_POOL used. 00088 * 00089 * ALIAS_CONTEXT Get_Default_Alias_Context(struct ALIAS_MANAGER *) 00090 * Obtain the current alias context. 00091 * 00092 * void Set_Alias_Context(struct ALIAS_MANAGER *, ALIAS_CONTEXT); 00093 * Set up the current alias context. 00094 * 00095 * void Reset_Alias_Context(struct ALIAS_MANAGER *); 00096 * Revert to the default alias context. 00097 * 00098 * 00099 * Alias analysis functions 00100 * ------------------------ 00101 * 00102 * The alias analysis function return ALIAS_RESULT (one of the following 00103 * three values). 00104 * 00105 * NOT_ALIASED: two memory operations are not aliased. 00106 * POSSIBLY_ALIASED: we can't prove the memory operations are not aliased. 00107 * SAME_LOCATION: two memory operations are aliased and access exactly 00108 * the same memory locations. the size of memory accessed 00109 * must be the same too. 00110 * 00111 * WARNING: Alias analyis ALWAYS RETURN conservatively answers. 00112 * Even though two memory operations are not aliased, the analysis may not be 00113 * powerful enough to determine that. It is correct to return POSSILBY_ALIASED. 00114 * Similarly, for two memory operations that access the same location, it is 00115 * correct for the alias analyzer to return POSSIBLY_ALIASED. 00116 * 00117 * ALIAS_RESULT Aliased(const struct ALIAS_MANAGER *, const WN *wn1, const WN *wn2) 00118 * Check whether the memory accessed by wn1 and wn2 overlaps. 00119 * 00120 * ALIAS_RESULT Overlapped_base(const struct ALIAS_MANAGER *, const WN *wn1, const WN *wm2) 00121 * Ignore the context-sensitive offset information from wn1 and wn2. 00122 * Check whether the memory accessed by wn1 and wn2 overlaps. 00123 * 00124 * Example: 00125 * do i 00126 * a[i] 00127 * a[i+1] 00128 * 00129 * Aliased(manager, "a[i]", "a[i+1]") return NOT_ALIASED because 00130 * context-sensitive analysis MAY determine that a[i] and a[i+1] are both 00131 * based on &a[i]. By applying the Offset rule, a[i] and a[i+1] are said 00132 * to be not aliased. 00133 * 00134 * Notice that this is only true for a particular iteration. The a[i+1] 00135 * is aliased to the *p of the following iteration. LNO requested to 00136 * return POSSIBLY_ALIASED for a[i] and a[i+1] because they really care 00137 * about the dependence across all iterations. 00138 * 00139 * The function Overlapped_base() is written to provide this functionality. 00140 * It always return ALIASED if the base is not a constant address. 00141 * It ignores the offset information derived from context-sensitive analysis. 00142 * Therefore, for both a[i] and a[i+1], the offset is undetermined. 00143 * However, for a[1] or a[2], the offset is determined becuase it can be derived 00144 * from the tree underneath the load/store operation. 00145 * 00146 * 00147 * ALIAS_RESULT Aliased_with_region(const struct ALIAS_MANAGER *, 00148 * WN *call_or_region, WN *wn, READ_WRITE); 00149 * Check if the wn operations has dependence with a REGION. 00150 * CALL is regarded a simple region. READ_WRITE specifies 00151 * the dependence checked (READ dependence, WRITE dependence, or both). 00152 * FORWARD_BARRIER/BACKWARD_BARRIER/DEALLOCA are another form or REGION. 00153 * 00154 * 00155 * BOOL Homing_Load( const struct ALIAS_MANAGER *, const WN *load_wn ) 00156 * void Set_Homing_Load( struct ALIAS_MANAGER *, WN *load_wn ) 00157 * void Reset_Homing_Load( struct ALIAS_MANAGER *, WN *load_wn ) 00158 * 00159 * Determine if the load is from a variable's home location to be stored 00160 * into that var's preg. 00161 * 00162 * BOOL Homing_Store( const struct ALIAS_MANAGER *, const WN *store_wn ) 00163 * void Set_Homing_Store( struct ALIAS_MANAGER *, WN *store_wn ) 00164 * void Reset_Homing_Store( struct ALIAS_MANAGER *, WN *store_wn ) 00165 * 00166 * Determine if the store is to a variable's home location and the value 00167 * being stored is that var's preg. 00168 * 00169 * Lowering and Unrolling Support 00170 * ------------------------------ 00171 * 00172 * The alias package provides basic support for the update of 00173 * alias information as new memory operations are created during 00174 * lowering and unrolling. The support is minimal so that correct 00175 * alias analysis is possible. However, re-analyze the unrolled memop 00176 * is needed to provide a better solution. 00177 * In fact, the Aliased_Memop() in cgprep.c of Ragnarok handle this situation 00178 * by examining the INS. 00179 * 00180 * void Copy_alias_info(const struct ALIAS_MANAGER *, WN *wn1, WN *wn2) 00181 * The alias information of wn1 is transfered to wn2. This will be used 00182 * by lowering. For example, LDID a ---> ILOAD (LDA a). 00183 * An iload is created and it should have identical alias behavior as the 00184 * LDID. 00185 * 00186 * void Duplicate_alias_info(struct ALIAS_MANAGER *, 00187 * const WN *wn1, WN *wn2) 00188 * The alias information of wn1 is duplicated to wn2, and some updating 00189 * both wn1 and wn1 to reduce the strength of alias analysis. 00190 * 00191 * void Create_vector_alias(struct ALIAS_MANAGER *, WN *wn1, WN *wn2) 00192 * The alias information of wn1 (accessing an element) is 00193 * copied to wn2 (accessing the entire array). 00194 * 00195 * BOOL Valid_alias(const struct ALIAS_MANAGER *am, WN *wn); 00196 * Return true if the wn has a valid alias mapping 00197 * 00198 * Duplicate_alias_info() is used by unrolling. As CG unrolls a loop, 00199 * it duplicates the memops. The duplicated memops should have similar, but 00200 * not idential alias behavior as the original because 00201 * the alias information does not apply across iterations. 00202 * 00203 * Notice that If the address of the memory operation is a loop invariant, then 00204 * the unroller should use Copy_alias_info() to transfer the alias information 00205 * in order to preserve all the useful alias information. 00206 * 00207 * LNO & Lowerer Support 00208 * --------------------- 00209 * 00210 * This routines update the alias information associated with newly created WHIRL nodes. 00211 * 00212 * void Create_alias(struct ALIAS_MANAGER *, WN *wn) 00213 * Create a new alias id corresponding to WHIRL load/store. 00214 * 00215 * void Create_local_alias(struct ALIAS_MANAGER *, WN *wn) 00216 * Create a new alias id corresponding to the ST in the WHIRL node. 00217 * Assume the ST is a local var, and not address taken. 00218 * 00219 * void Create_global_alias(struct ALIAS_MANAGER *, ST *, WN *ldid, WN *iload) 00220 * The ST is a global variable. 00221 * Create a new alias id corresponding to LDID ST to the ldid WHIRL node. 00222 * Create a new alias id corresponding to ILOAD (LDID ST) to the iload WHIRL node. 00223 * 00224 * void Create_formal_alias(struct ALIAS_MANAGER *, ST *, WN *formal_addr, WN *formal) 00225 * The ST in formal_addr must be SCLASS_FORMAL. 00226 * Assume FORTRAN alias rule: formals are not aliased with other variables. 00227 * Create alias ids for both the variable containing the formal and the formal. 00228 * 00229 * void Create_unique_pointer_alias(struct ALIAS_MANAGER *, ST *, WN *ldid, WN *iload) 00230 * ST is the symbol that points to this chunk memory exclusively. 00231 * ST must have the PT_TO_UNIQUE_MEM bit set. 00232 * Create a new alias id corresponding to LDID ST to the ldid WHIRL node. 00233 * Create a new alias id corresponding to ILOAD (LDID ST) to the iload WHIRL node. 00234 * 00235 * void Create_lda_array_alias(struct ALIAS_MANAGER *am, WN *lda, WN *iload) 00236 * Create a new alias id corresponding to the array access. 00237 * 00238 * void Erase_Restricted_Mapping(WN *wn) 00239 * Erase the restricted pointer stored in the 'restrict map'. 00240 * Should be called when an array is localized. 00241 * 00242 * void Note_Invalid_Based_Symbol(const ST *st) 00243 * Mark the symbol "st" as an invalid based_sym in the restricted 00244 * map. This should be called when an array is distribute/reshaped 00245 * by LNO because memory operations based on the symbol are now 00246 * based on another symbol introduced during the distribute/reshape 00247 * operation. 00248 * 00249 * void Note_Invalid_IP_Alias_Class(const WN *wn) 00250 * Mark the interprocedural alias class of "wn" as invalid. This 00251 * should be called when an array accessed by "wn" is equivalenced 00252 * by LNO during Equivalence_arrays, because the alias behavior of 00253 * the array as seen by IPA is no longer valid. 00254 * 00255 * void Invalidate_Persistent_Alias_Info(ALIAS_MANAGER *, WN *); 00256 * Removes those items marked as invalid by 00257 * Note_Invalid_Based_Symbol and Note_Invalid_IP_Alias_Class. This 00258 * should be called at the end of LNO, after Copy_Restricted_Map is 00259 * used to move the restricted map entries to the new WHIRL tree 00260 * from the alias manager. 00261 * 00262 * ALIAS_RESULT ALIAS_MANAGER::Aliased(WN *wn, const POINTS_TO *pt); 00263 * ALIAS_RESULT ALIAS_MANAGER::Aliased(const POINTS_TO *pt, WN *wn); 00264 * Determine if a WHIRL load/store is aliased with a POINTS_TO. 00265 * 00266 * ALIAS_RESULT ALIAS_MANAGER::Aliased(const POINTS_TO *pt1, const POINTS_TO *pt2); 00267 * Determine if two POINTS_TO are aliased. 00268 * 00269 * POINTS_TO(ST *st, BOOL indirect = FALSE) 00270 * POINTS_TO(ST *st, INT64 ofst, INT64 size, BOOL indirect = FALSE) 00271 * The ALIAS_MANAGER::Aliased() routine takes POINTS_TO. The POINTS_TO 00272 * can be constructed using these constructors. Set indirect to 00273 * FALSE for regular variables. Set indirect to TRUE when the ST is 00274 * a pointer and you want to construct a POINTS_TO for the object the pointer 00275 * points to. 00276 * 00277 * 00278 * Misc 00279 * ---- 00280 * 00281 * void Dump_alias_mgr(const struct ALIAS_MANAGER *, const WN *, FILE *) 00282 * Prints out the WHIRL tree with their alias id. 00283 * Prints out the alias arcs. 00284 * 00285 * void Print_alias_info(char *buf, const struct ALIAS_MANAGER *, WN *wn) 00286 * Prints out some of the alias information. 00287 * 00288 * BOOL ALIAS_MANAGER::Safe_to_speculate(const WN *) 00289 * Returns TRUE if the object accessed by the WN node will be 00290 * allocated, and therefore safe to be speculatively accessed. 00291 * This function returns TRUE under two situations: 00292 * 1) the WN node accesses a PREG; 00293 * 2) the POINTS_TO of the WHIRL node satisfies the following conditions: 00294 * a) the POINTS_TO represents an address expr; 00295 * b) the base ST is valid and non-NULL; 00296 * c) the offset is valid and size is non-zero. 00297 * d) the POINTS_TO have the Safe_to_speculate attribute set 00298 * Condition (2c) is used to suppress the motion of array expr 00299 * if the size of the array is unknown. 00300 * Condition (2d) is used to prevent speculation of weak symbol, 00301 * optional parameters, ... 00302 * 00303 * ======================================================================== 00304 */ 00305 00306 #include "defs.h" 00307 #include "mempool.h" 00308 #include "wn.h" 00309 00310 #ifdef __cplusplus 00311 extern "C" { 00312 #endif 00313 00314 struct ALIAS_MANAGER; 00315 struct POINTS_TO; 00316 struct PU; 00317 00318 typedef enum { 00319 NOT_ALIASED = 0, 00320 POSSIBLY_ALIASED = 1, 00321 SAME_LOCATION = 2 00322 } ALIAS_RESULT; 00323 00324 /* Be careful when redefining the enum. READ and WRITE are bit masks. */ 00325 typedef enum { 00326 NO_READ_NO_WRITE = 0, 00327 READ = 0x1, 00328 WRITE = 0x2, 00329 READ_AND_WRITE =0x3 00330 } READ_WRITE; 00331 00332 typedef UINT32 ALIAS_CONTEXT; 00333 00334 struct ALIAS_MANAGER *Create_Alias_Manager(MEM_POOL *); 00335 00336 void Delete_Alias_Manager(struct ALIAS_MANAGER *, MEM_POOL *); 00337 00338 void Create_Restricted_Map(MEM_POOL *); 00339 00340 void Copy_Restricted_Map(WN *, struct ALIAS_MANAGER *); 00341 00342 void Delete_Restricted_Map(void); 00343 00344 void Erase_Restricted_Mapping(WN *); 00345 00346 void Verify_Restricted_Map(const WN *, const POINTS_TO *); 00347 00348 BOOL Update_From_Restricted_Map(WN *, POINTS_TO *); 00349 00350 void Note_Invalid_Based_Symbol(const ST *); 00351 00352 struct ALIAS_RULE *Alias_Rule(struct ALIAS_MANAGER *); 00353 00354 ALIAS_CONTEXT Get_Default_Alias_Context(struct ALIAS_MANAGER *); 00355 00356 void Set_Alias_Context(struct ALIAS_MANAGER *, ALIAS_CONTEXT); 00357 00358 void Reset_Alias_Context(struct ALIAS_MANAGER *); 00359 00360 /* to be deleted */ void Assign_preg_alias_id(struct ALIAS_MANAGER *, WN *); 00361 00362 BOOL No_alias(const struct ALIAS_MANAGER *am, WN *wn); 00363 00364 BOOL Valid_alias(const struct ALIAS_MANAGER *am, WN *wn); 00365 00366 ALIAS_RESULT Aliased(const struct ALIAS_MANAGER *, WN *, WN *, BOOL ignore_loop_carried=FALSE); 00367 00368 ALIAS_RESULT Overlapped_base(const struct ALIAS_MANAGER *, const WN *, const WN *); 00369 00370 ALIAS_RESULT Aliased_with_region(const struct ALIAS_MANAGER *, const WN *, const WN *, READ_WRITE); 00371 00372 ALIAS_RESULT Aliased_with_intr_op(const struct ALIAS_MANAGER *, const WN *, const WN *); 00373 00374 void Note_Invalid_IP_Alias_Class(ALIAS_MANAGER *, const WN *); 00375 00376 void Invalidate_Persistent_Alias_Info(ALIAS_MANAGER *, WN *); 00377 00378 BOOL Homing_Load( const struct ALIAS_MANAGER *, const WN *load_wn ); 00379 void Set_Homing_Load( struct ALIAS_MANAGER *, WN *load_wn ); 00380 void Reset_Homing_Load( struct ALIAS_MANAGER *, WN *load_wn ); 00381 00382 BOOL Homing_Store( const struct ALIAS_MANAGER *, const WN *store_wn ); 00383 void Set_Homing_Store( struct ALIAS_MANAGER *, WN *store_wn ); 00384 void Reset_Homing_Store( struct ALIAS_MANAGER *, WN *store_wn ); 00385 00386 void Copy_alias_info(const struct ALIAS_MANAGER *, WN *, WN *); 00387 00388 void Duplicate_alias_info(struct ALIAS_MANAGER *, WN *, WN *); 00389 00390 BOOL Verify_alias(struct ALIAS_MANAGER *, WN *); /* opt_verify.cxx */ 00391 00392 void Assign_alias_id(struct ALIAS_MANAGER *, WN *); 00393 00394 void Create_alias(struct ALIAS_MANAGER *, WN *); 00395 00396 void Create_local_alias(struct ALIAS_MANAGER *, WN *); 00397 00398 void Create_global_alias(struct ALIAS_MANAGER *, ST *, WN *, WN *); 00399 00400 void Create_formal_alias(struct ALIAS_MANAGER *, ST *, WN *, WN *); 00401 00402 void Create_vector_alias(struct ALIAS_MANAGER *, WN *, WN *); 00403 00404 void Create_unique_pointer_alias(struct ALIAS_MANAGER *, ST *, WN *, WN *); 00405 00406 void Create_lda_array_alias(struct ALIAS_MANAGER *, WN *, WN *); 00407 00408 void Print_alias_info(char *, const struct ALIAS_MANAGER *, const WN *); 00409 00410 BOOL May_refer_to_alloca_mem(const struct ALIAS_MANAGER *, const WN *); 00411 00412 BOOL Safe_to_speculate(const struct ALIAS_MANAGER *, const WN *); 00413 00414 void Dump_alias_mgr(const struct ALIAS_MANAGER *, const WN *, FILE *fp); 00415 00416 #ifdef __cplusplus 00417 } /* end extern "C" */ 00418 #endif 00419 00420 extern void PU_adjust_addr_flags(ST*, WN*); 00421 00422 #endif /* opt_alias_interface.h include */
1.5.6