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 // ==================================================================== 00039 // 00040 // Module: opt_ipaa_summary.h 00041 // $Revision: 1.2 $ 00042 // $Date: 02/11/07 23:41:38-00:00 $ 00043 // $Author: fchow@keyresearch.com $ 00044 // $Source: /scratch/mee/2.4-65/kpro64-pending/be/com/SCCS/s.opt_ipaa_summary.h $ 00045 // 00046 // Revision history: 00047 // 2-Nov-95 - Original Version 00048 // 00049 // Description: 00050 // 00051 // Definition of the summary information interface between IPAA and 00052 // the optimizer. We observe the following principles: 00053 // 00054 // 1) The information consists of several tables, with all 00055 // inter-table references being indices. The reason is (4) 00056 // below. 00057 // 00058 // 2) There is a file header table which contains information 00059 // identifying the layout of the file, i.e. which tables are 00060 // present, how big they are, and where they are in the file. 00061 // It also contains a version identifier for verification. Note, 00062 // however, that unlike the local summary information, the 00063 // compilation model currently implies consuming this information 00064 // immediately, so there is no need to cope with multiple versions 00065 // in the consumer (WOPT). 00066 // 00067 // 3) The information is almost independent of the WHIRL symbol 00068 // table. For local variables, that is not easy, so we don't try, 00069 // but for most purposes, reference to the symbol table won't be 00070 // necessary. 00071 // 00072 // 4) The IPAA summary file will be read read-only by the back end, 00073 // so that it may be memory-mapped concurrently by multiple back 00074 // end compilations, and we will limit the data structures which 00075 // must be converted on input to the file descriptor. 00076 // 00077 // In addition, we require the following: 00078 // 00079 // 5) Index zero is not a normal entry for any of the tables. 00080 // Therefore, it always represents an uninitialized, invalid, or 00081 // unknown entry. 00082 // 00083 // Most IPAA summary information will be written to a single file, 00084 // named "<outputname>.ipaa" if -keep is specified. However, the 00085 // following must be put in the WHIRL .o, in section .WHIRL.ipaa: 00086 // 00087 // - IPAA_LOCALS: These contain the mappings from per-file IDs to 00088 // the local symbol tables. 00089 // 00090 // - IPAA_CALLSITES: These contain the mappings from callsites to 00091 // the callees' information in the ipaa file. 00092 // 00093 // See also opt_ipaa_io.(h|cxx) for I/O routines which must reside in 00094 // be.so because they are called before wopt.so is loaded. 00095 // 00096 // ==================================================================== 00097 // ==================================================================== 00098 00099 #ifndef cxx_opt_ipaa_summary_INCLUDED 00100 #define cxx_opt_ipaa_summary_INCLUDED 00101 00102 #ifdef _KEEP_RCS_ID 00103 static char *opt_ipaa_summary_rcs_id = "$Source: /scratch/mee/2.4-65/kpro64-pending/be/com/SCCS/s.opt_ipaa_summary.h $ $Revision: 1.2 $"; 00104 #endif /* _KEEP_RCS_ID */ 00105 00106 // Trace flag for IPAA summary file build/output: 00107 extern BOOL Trace_IPAA_Summary; 00108 00109 // Forward and incomplete definitions: 00110 typedef mINT32 SECTION_IX; 00111 class IPAA_SUMMARY; 00112 struct st; 00113 00114 // Global pointer to the summary information. This pointer MUST be 00115 // either NULL or point to the current summary class instance; the 00116 // latter is required for many of the methods in this module. The 00117 // IPAA_SUMMARY constructors/destructor deal with this automatically; 00118 // anyone trying to manage multiple instances at once must be careful. 00119 extern IPAA_SUMMARY *IPAA_Summary; 00120 00121 // ==================================================================== 00122 // ==================================================================== 00123 // 00124 // IPAA_SYMBOL_REF 00125 // 00126 // This is the basic symbol descriptor -- all symbol references in the 00127 // IPAA information point to one of these. They should be distinct, 00128 // that is, two references to different non-SECTION entries in this 00129 // table should be to different data. SECTION entries ultimately 00130 // point to a non-SECTION entry here (see IPAA_SECTION below). This 00131 // table therefore forms the universe for all sets of symbols from 00132 // IPAA. 00133 // 00134 // The kinds of symbols (SYMBOL_REF_KIND) currently represented are: 00135 // 00136 // SREF_NAME: This is a name, with no other semantic 00137 // implications. It may be used for such 00138 // purposes as referencing file names or symbol 00139 // names (e.g. PUs) without knowing their 00140 // locality characteristics. 00141 // 00142 // SREF_GLOBAL: This is a global symbol, i.e. visible to the 00143 // linker. The only identification required is 00144 // its external name (which may be mangled). 00145 // 00146 // SREF_LOCAL: This is a symbol local to one of the component 00147 // files. It is identified by the name of the 00148 // source file where it originated, and an ID 00149 // within that file. Except while compiling that 00150 // file, more information than this ID should not 00151 // be required for identification. 00152 // 00153 // SREF_SECTION: This is a section of another symbol. Its ID 00154 // fields point to the IPAA_SYMBOL_REF for the 00155 // base symbol, and to a section table entry which 00156 // contains the start offset and size of the 00157 // section. Eventually, this will likely be 00158 // extended to contain stride information as well. 00159 // 00160 // SREF_UNKNOWN: The referenced symbol is unknown. Therefore 00161 // the information applies to any potentially 00162 // addr_taken object. 00163 // 00164 // The index type of this table is SYMREF_IX. It currently uses the 00165 // following indices for dedicated purposes: 00166 // 00167 // SYMREF_IX_INVALID (0): An invalid entry. 00168 // 00169 // SYMREF_IX_UNKNOWN (1): An SREF_UNKNOWN entry. 00170 // 00171 // SYMREF_IX_FIRST (2): The first normal (non-dedicated) entry. 00172 // 00173 // TODO: Probably add flags (in _dummy) for address-taken and for 00174 // automatic variables (SREF_LOCAL only). 00175 // 00176 // ==================================================================== 00177 // ==================================================================== 00178 00179 // The valid kinds of symbol reference: 00180 typedef enum { 00181 SREF_INVALID, // Invalid kind 00182 SREF_NAME, // Simple name 00183 SREF_GLOBAL, // Global symbol 00184 SREF_LOCAL, // Local symbol 00185 SREF_SECTION, // Section of another symbol 00186 SREF_UNKNOWN, // Unknown symbol 00187 SREF_MASK = 7 // Make sure this is a valid mask for others 00188 } SYMBOL_REF_KIND; 00189 00190 // Print symbolic name of a kind to a string: 00191 extern char * sPrint_Symref_Kind ( SYMBOL_REF_KIND kind ); 00192 00193 // The type of a symbol reference table index: 00194 typedef mINT32 SYMREF_IX; 00195 const SYMREF_IX SYMREF_IX_INVALID = 0; 00196 const SYMREF_IX SYMREF_IX_UNKNOWN = 1; 00197 const SYMREF_IX SYMREF_IX_FIRST = 2; 00198 00199 // The symbol reference class -- members of the table: 00200 class IPAA_SYMBOL_REF 00201 { 00202 mINT32 _id1 :24; // NAME/GLOBAL: unused 00203 // LOCAL: per-file identifier 00204 // -- See IPAA_LOCAL_MAP below 00205 // SECTION: section table index 00206 // UNKNOWN: unused 00207 mINT32 _dummy :4; 00208 mINT32 _kind :4; // SYMBOL_REF_KIND of the symbol 00209 mINT32 _id2; // NAME/GLOBAL: string table index (name) 00210 // LOCAL: string table index (file name) 00211 // SECTION: base symbol ref index 00212 // UNKNOWN: unused 00213 00214 public: 00215 00216 // Constructor/destructor: 00217 IPAA_SYMBOL_REF ( SYMBOL_REF_KIND kind, 00218 INT32 id1, INT32 id2 ) 00219 { _kind = kind; _id1 = id1; _id2 = id2; _dummy = 0; } 00220 ~IPAA_SYMBOL_REF () {} 00221 00222 // Tracing: 00223 void Print ( FILE *f, const char *pfx ) const; 00224 void Trace ( const char *pfx ) const; 00225 00226 // Member access: 00227 SYMBOL_REF_KIND Kind (void) const { return (SYMBOL_REF_KIND)_kind; } 00228 00229 INT32 Name_id (void) const { return _id2; } 00230 inline char *Name (void) const; 00231 00232 INT32 Global_id (void) const { return _id2; } 00233 inline char *Global_name (void) const; 00234 00235 INT32 Local_id (void) const { return _id1; } 00236 INT32 Local_file_id (void) const { return _id2; } 00237 inline char *Local_file_name (void) const; 00238 00239 SECTION_IX Section_id (void) const { return (SECTION_IX)_id1; } 00240 SYMREF_IX Section_base (void) const { return (SYMREF_IX)_id2; } 00241 inline INT64 Section_disp (void) const; 00242 inline INT64 Section_size (void) const; 00243 }; 00244 00245 // ==================================================================== 00246 // ==================================================================== 00247 // 00248 // IPAA_SECTION 00249 // 00250 // This class provides the information which describes the part of a 00251 // base symbol referenced by a section, i.e. its displacement and size. 00252 // Eventually, this will likely be extended to contain stride 00253 // information as well. 00254 // 00255 // The index type of this table is SECTION_IX. Index 0 is invalid. 00256 // 00257 // ==================================================================== 00258 // ==================================================================== 00259 00260 class IPAA_SECTION 00261 { 00262 INT64 _disp; // Byte displacement from start of the base 00263 INT64 _size; // Byte size of the section 00264 00265 public: 00266 00267 // Constructor/destructor: 00268 IPAA_SECTION ( INT64 disp, INT64 size ) 00269 { _disp = disp; _size = size; } 00270 ~IPAA_SECTION () {} 00271 00272 // Tracing: 00273 void Print ( FILE *f ) const; 00274 void Trace ( void ) const; 00275 00276 // Member access: 00277 INT64 Disp (void) const { return _disp; } 00278 INT64 Size (void) const { return _size; } 00279 }; 00280 00281 // ==================================================================== 00282 // ==================================================================== 00283 // 00284 // IPAA_MODREF 00285 // 00286 // This class provides mod/ref information for a single symbol 00287 // reference. If the symbol reference is 0, it implies the given 00288 // mod/ref attributes for an unknown symbol or symbols (e.g. via an 00289 // unanalyzable pointer expression). 00290 // 00291 // The MODREF_KIND type matches the definitions of the IPL mod/ref bits 00292 // in ipl_cg.h -- these should be merged. Note that AREF is not used 00293 // in the IPAA output, and the indirect reference kinds are used only 00294 // for formals. 00295 // 00296 // The index type of this table is MODREF_IX. 00297 // 00298 // ==================================================================== 00299 // ==================================================================== 00300 00301 // Define the types which we use to represent mod/ref information: 00302 typedef enum { 00303 MODREF_NONE = 0, // No mod/ref/kill 00304 MODREF_IMOD = 1, // Indirect modification (maybe) -- only formals 00305 MODREF_DMOD = 2, // Direct modification (maybe) 00306 MODREF_IREF = 4, // Indirect reference (maybe) -- only formals 00307 MODREF_DREF = 8, // Direct reference (maybe) 00308 MODREF_AREF = 16, // Address reference (&a) -- unused 00309 MODREF_IKILL = 32, // Indirect kill (always) -- only formals 00310 MODREF_DKILL = 64, // Direct kill (always) 00311 MODREF_ANY = 127 // Anything (full mask) 00312 } MODREF_KIND; 00313 00314 typedef mINT8 REFBITS; 00315 00316 // Print MOD/REF bits symbolically to a string: 00317 extern char *sPrint_Modref ( REFBITS bits ); 00318 00319 typedef mINT32 MODREF_IX; 00320 00321 // Conservative mod/ref information: 00322 const REFBITS MODREF_CONSERVATIVE = 00323 MODREF_DMOD|MODREF_DREF|MODREF_IMOD|MODREF_IREF; 00324 00325 class IPAA_MODREF 00326 { 00327 SYMREF_IX _symref :24; // IPAA_SYMBOL_REF referenced: 0 => unknown 00328 mINT32 _modref :8; // Mod/ref flags 00329 00330 public: 00331 00332 // Constructor/destructor: 00333 IPAA_MODREF ( REFBITS modref, INT32 symref ) 00334 { _modref = modref; _symref = symref; } 00335 ~IPAA_MODREF () {} 00336 00337 // Tracing: 00338 void Print ( FILE *f ) const; 00339 void Trace ( void ) const; 00340 00341 // Member access: 00342 REFBITS Modref (void) const { return _modref; } 00343 SYMREF_IX Symref (void) const { return _symref; } 00344 // More to come, for setting, and for modref bit access... 00345 }; 00346 00347 // ==================================================================== 00348 // ==================================================================== 00349 // 00350 // IPAA_SET 00351 // 00352 // This class provides information about a set of something. The 00353 // current kinds of set are: 00354 // 00355 // SET_MODREF: A set of IPAA_MODREF objects, with the index 00356 // of the first one. This is used to represent 00357 // the global mod/ref information for a PU. 00358 // 00359 // SET_REFBITS: A set of REFBITS objects, with the index 00360 // of the first one. This is used to represent 00361 // the formal mod/ref information for a PU. 00362 // 00363 // SET_SYMREF: A set of IPAA_SYMBOL_REF objects, with the 00364 // index of the first one. This is used to 00365 // represent the points-to set of a formal. 00366 // 00367 // SET_SETS: A set of IPAA_SET objects, with the index of 00368 // the first one. This is used to represent the 00369 // set of formal points-to sets for a PU. 00370 // 00371 // In addition, it seems likely that we will add other kinds, in 00372 // particular to represent sets by bit vectors when that is smaller. 00373 // Those would be represented by indices into a new table. 00374 // 00375 // The index type of this table is SET_IX. 00376 // 00377 // ==================================================================== 00378 // ==================================================================== 00379 00380 // Declare the possible kinds of sets (based on their elements): 00381 typedef enum { 00382 SET_INVALID, // Invalid kind 00383 SET_MODREF, // Simple set of IPAA_MODREF objects 00384 SET_REFBITS, // Simple set of REFBITS objects 00385 SET_SYMREF, // Simple set of IPAA_SYMBOL_REF objects 00386 SET_SETS, // Simple set of IPAA_SET objects 00387 } IPAA_SET_KIND; 00388 00389 // Print a set kind to a string: 00390 extern char * sPrint_Set_Kind ( IPAA_SET_KIND kind ); 00391 00392 // The set table is indexed by this type: 00393 typedef mINT32 SET_IX; 00394 00395 // Declare the actual set class: 00396 class IPAA_SET 00397 { 00398 mINT32 _size :24; // Size of set 00399 IPAA_SET_KIND _kind :8; // Kind of set -- see above 00400 mINT32 _index; // Index of first element of set 00401 00402 public: 00403 00404 // Constructors/destructor: 00405 IPAA_SET ( void ) { _kind = SET_INVALID; _index = 0; _size = 0; } 00406 IPAA_SET ( IPAA_SET_KIND kind, INT32 index, INT32 size ) 00407 { _kind = kind; _index = index; _size = size; } 00408 IPAA_SET ( const REFBITS *refbits, INT32 size ); 00409 IPAA_SET ( const IPAA_MODREF *modref, INT32 size ); 00410 IPAA_SET ( const IPAA_SYMBOL_REF *symref, INT32 size ); 00411 IPAA_SET ( const IPAA_SET *set, INT32 size ); 00412 ~IPAA_SET () {} 00413 00414 // Tracing: 00415 void Print ( FILE *f, BOOL print_members = TRUE ) const; 00416 void Trace ( BOOL print_members = TRUE ) const; 00417 00418 // Member access: 00419 IPAA_SET_KIND Kind (void) const { return (IPAA_SET_KIND)_kind; } 00420 void Set_kind ( IPAA_SET_KIND kind ) { _kind = kind; } 00421 INT32 Index (void) const { return _index; } 00422 void Set_index ( INT32 ix ) { _index = ix; } 00423 INT32 Size (void) const { return _size; } 00424 void Set_size ( INT32 sz ) { _size = sz; } 00425 }; 00426 00427 // ==================================================================== 00428 // ==================================================================== 00429 // 00430 // IPAA_PU_INFO 00431 // 00432 // This class provides mod/ref information for a program unit. 00433 // 00434 // The index type of this table is PU_INFO_IX. 00435 // 00436 // ==================================================================== 00437 // ==================================================================== 00438 00439 typedef mINT32 PU_INFO_IX; 00440 00441 class IPAA_PU_INFO 00442 { 00443 SYMREF_IX _pu :24; // IPAA_SYMBOL_REF for the PU itself 00444 mINT32 _flags :8; // Attribute flags 00445 SET_IX _points_to; // Set of formal points-to sets 00446 SET_IX _formal_modref; // Set of formal mod/ref masks 00447 SET_IX _global_modref; // Set of global mod/ref data 00448 00449 public: 00450 00451 // Constructor/destructor: 00452 IPAA_PU_INFO ( SYMREF_IX pu, SET_IX pt, SET_IX formals, SET_IX globals ) 00453 { 00454 _flags = 0; 00455 _pu = pu; 00456 _points_to = pt; 00457 _formal_modref = formals; 00458 _global_modref = globals; 00459 } 00460 ~IPAA_PU_INFO () {} 00461 00462 // Tracing: 00463 void Print ( FILE *f ) const; 00464 void Trace ( void ) const; 00465 00466 // Member access: 00467 SYMREF_IX Pu_ix (void) const { return _pu; } 00468 SET_IX Points_to_ix (void) const { return _points_to; } 00469 SET_IX Formal_modref_ix (void) const { return _formal_modref; } 00470 SET_IX Global_modref_ix (void) const { return _global_modref; } 00471 00472 // Go get the name of the PU, via Pu_ix and IPAA_Summary: 00473 inline char * Name (void) const; 00474 00475 // More to come, for access for individual formals, etc. 00476 }; 00477 00478 // ==================================================================== 00479 // ==================================================================== 00480 // 00481 // IPAA_FILE_DESCRIPTOR / IPAA_SUMMARY 00482 // 00483 // These classes describe the contents of an IPAA file. They comes in 00484 // two forms: IPAA_FILE_DESCRIPTOR is the in-file form, while 00485 // IPAA_SUMMARY is the form used in IPAA and the back end (WOPT). 00486 // 00487 // ==================================================================== 00488 // ==================================================================== 00489 00490 class IPAA_FILE_DESCRIPTOR; 00491 class IPAA_SUMMARY; 00492 00493 #define IPAA_MAJOR 0 00494 #define IPAA_MINOR 0 00495 #define IPAA_MAGIC 0x49504141 00496 00497 // Attributes stored in the IPAA_FILE_DESCRIPTOR / IPAA_SUMMARY flags: 00498 typedef enum { 00499 IPAA_ADDR_ANAL = 1 // Addressing (addr_taken) analyzed 00500 } ATTR_MASK; 00501 00502 class IPAA_TABLE_DESCRIPTOR 00503 { 00504 friend class IPAA_FILE_DESCRIPTOR; 00505 friend class IPAA_SUMMARY; 00506 00507 mINT32 _table_size :24; // Number of elements in the table 00508 mINT32 _element_size :8; // Byte size of an element 00509 mUINT32 _file_offset; // Byte offset of table in the file 00510 00511 IPAA_TABLE_DESCRIPTOR ( INT32 elmt, INT32 size, UINT32 disp ) 00512 { 00513 _element_size = elmt; 00514 _table_size = size, 00515 _file_offset = disp; 00516 } 00517 ~IPAA_TABLE_DESCRIPTOR () {} 00518 }; 00519 00520 class IPAA_FILE_DESCRIPTOR 00521 { 00522 friend class IPAA_SUMMARY; 00523 00524 mINT32 _magic; // Magic number 00525 mINT8 _major; // Major revision 00526 mINT8 _minor; // Minor revision 00527 mINT8 _size; // Byte size of file descriptor 00528 mINT8 _flags; // Attributes 00529 IPAA_TABLE_DESCRIPTOR _strings; // string (name) table 00530 IPAA_TABLE_DESCRIPTOR _symrefs; // IPAA_SYMBOL_REF table 00531 IPAA_TABLE_DESCRIPTOR _sections; // IPAA_SECTION table 00532 IPAA_TABLE_DESCRIPTOR _modrefs; // IPAA_MODREF table 00533 IPAA_TABLE_DESCRIPTOR _refbits; // REFBITS table 00534 IPAA_TABLE_DESCRIPTOR _sets; // IPAA_SET table 00535 IPAA_TABLE_DESCRIPTOR _pu_info; // IPAA_PU_INFO table 00536 00537 // Constructor for use in IPAA (from IPAA_SUMMARY::Write): 00538 IPAA_FILE_DESCRIPTOR ( INT32 major, INT32 minor ) 00539 : _magic ( IPAA_MAGIC ), 00540 _major ( major ), 00541 _minor ( minor ), 00542 _size ( sizeof(IPAA_FILE_DESCRIPTOR) ), 00543 _flags ( 0 ), 00544 _strings ( 1, 0, 0 ), 00545 _symrefs ( sizeof(IPAA_SYMBOL_REF), 0, 0 ), 00546 _sections ( sizeof(IPAA_SECTION), 0, 0 ), 00547 _modrefs ( sizeof(IPAA_MODREF), 0, 0 ), 00548 _refbits ( sizeof(REFBITS), 0, 0 ), 00549 _sets ( sizeof(IPAA_SET), 0, 0 ), 00550 _pu_info ( sizeof(IPAA_PU_INFO), 0, 0 ) 00551 { 00552 } 00553 00554 // Trivial destructor: 00555 ~IPAA_FILE_DESCRIPTOR () {} 00556 00557 public: 00558 00559 // Tracing: 00560 void Print ( FILE *f ) const; 00561 void Trace ( void ) const; 00562 00563 // Member attribute access: 00564 BOOL Get_addressing ( void ) const 00565 { return ( _flags & IPAA_ADDR_ANAL ); } 00566 void Set_addressing ( void ) { _flags |= IPAA_ADDR_ANAL; } 00567 void Reset_addressing( void ) { _flags &= ~IPAA_ADDR_ANAL; } 00568 00569 }; 00570 00571 // Read (mmap) summary file and return pointer to its file descriptor: 00572 IPAA_FILE_DESCRIPTOR * IPAA_Summary_Read ( char *file_name ); 00573 00574 00575 // ==================================================================== 00576 // 00577 // IPAA_SUMMARY 00578 // 00579 // This class describes the in-memory contents of an IPAA file, while 00580 // it is being constructed in IPAA and while it is being used in the 00581 // back end -- see above. Each constituent table has a current (i.e. 00582 // actual data) size and a max (i.e. allocated space) size. All of the 00583 // sizes are in terms of element counts, except the string table, which 00584 // is in bytes since the elements are variable-length. In IPAA, the 00585 // memory pool must be provided, and will be used for expanding the 00586 // constituent tables. In WOPT, it must be NULL, and adding elements 00587 // will not work. 00588 // 00589 // ==================================================================== 00590 00591 // We want to avoid including this in be.so, so exclude it if we're 00592 // compiling opt_ipaa_io.cxx: 00593 #ifndef OPT_IPAA_IO 00594 00595 class IPAA_SUMMARY 00596 { 00597 class TABLE { 00598 friend class IPAA_SUMMARY; 00599 mINT32 _max; // Maximum (allocated) size 00600 mINT32 _size; // Current (used) size 00601 void *_p; // Data vector 00602 00603 void Print ( FILE *f, char *hdr ) const 00604 { fprintf ( f, "%-16s -- size %d (max %d)\n", hdr, _size, _max ); } 00605 }; 00606 00607 mINT8 _major; // Major revision 00608 mINT8 _minor; // Minor revision 00609 mINT8 _flags; // Minor revision 00610 IPAA_FILE_DESCRIPTOR *_desc; // IPAA_FILE_DESCRIPTOR 00611 MEM_POOL *_mpool; // Memory pool to use 00612 TABLE _hash; // string hash table (internal) 00613 TABLE _strings; // string (name) table 00614 TABLE _symrefs; // IPAA_SYMBOL_REF table 00615 TABLE _sections; // IPAA_SECTION table 00616 TABLE _modrefs; // IPAA_MODREF table 00617 TABLE _refbits; // REFBITS table 00618 TABLE _sets; // IPAA_SET table 00619 TABLE _pu_info; // IPAA_PU_INFO table 00620 00621 // Initialize a TABLE from an IPAA_TABLE_DESCRIPTOR: 00622 void Make_table ( TABLE &t, IPAA_TABLE_DESCRIPTOR &tdesc ) 00623 { 00624 t._p = (void *) ( ((char *)_desc) + tdesc._file_offset ); 00625 t._size = t._max = tdesc._table_size; 00626 } 00627 00628 // Expand one of the tables, containing objects of the given size: 00629 void Expand_table ( TABLE &tab, INT32 size, INT32 count = 1 ); 00630 00631 public: 00632 00633 // Constructor for use in IPAA -- build a new summary: 00634 IPAA_SUMMARY ( MEM_POOL *pool ) 00635 { 00636 bzero ( this, sizeof (IPAA_SUMMARY) ); 00637 _major = IPAA_MAJOR; 00638 _minor = IPAA_MINOR; 00639 IPAA_Summary = this; 00640 _mpool = pool; 00641 _flags = 0; 00642 } 00643 00644 // Constructor for use in WOPT -- read summary file. This should 00645 // read (mmap) the summary file, verify that the version matches 00646 // the current ones, and build this class from the file descriptor. 00647 IPAA_SUMMARY ( char *file_name ); 00648 00649 // Destructor -- clear the global pointer: 00650 ~IPAA_SUMMARY () { IPAA_Summary = NULL; } 00651 00652 // Tracing: 00653 void Print ( FILE *f, char *msg ) const; 00654 void Trace ( char *msg ) const; 00655 00656 // Member access: 00657 BOOL Get_addressing ( void ) const 00658 { return ( _flags & IPAA_ADDR_ANAL ); } 00659 void Set_addressing ( void ) { _flags |= IPAA_ADDR_ANAL; } 00660 void Reset_addressing( void ) { _flags &= ~IPAA_ADDR_ANAL; } 00661 00662 IPAA_FILE_DESCRIPTOR *Get_desc( void ) const { return _desc; } 00663 INT32 Get_string_size ( void ) const { return _strings._size; } 00664 INT32 Get_symref_size ( void ) const { return _symrefs._size; } 00665 INT32 Get_section_size( void ) const { return _sections._size; } 00666 INT32 Get_modref_size ( void ) const { return _modrefs._size; } 00667 INT32 Get_refbit_size ( void ) const { return _refbits._size; } 00668 INT32 Get_set_size ( void ) const { return _sets._size; } 00669 INT32 Get_pu_info_size( void ) const { return _pu_info._size; } 00670 00671 char * Get_strings ( void ) const 00672 { return (char *) _strings._p; } 00673 IPAA_SYMBOL_REF * Get_symrefs ( void ) const 00674 { return (IPAA_SYMBOL_REF *) _symrefs._p; } 00675 IPAA_SECTION * Get_sections ( void ) const 00676 { return (IPAA_SECTION *) _sections._p; } 00677 IPAA_MODREF * Get_modrefs ( void ) const 00678 { return (IPAA_MODREF *) _modrefs._p; } 00679 REFBITS * Get_refbits ( void ) const 00680 { return (REFBITS *) _refbits._p; } 00681 IPAA_SET * Get_sets ( void ) const 00682 { return (IPAA_SET *) _sets._p; } 00683 IPAA_PU_INFO * Get_pu_info ( void ) const 00684 { return (IPAA_PU_INFO *) _pu_info._p; } 00685 00686 char * Get_string ( INT32 i ) const 00687 { return ((char *)_strings._p) + i; } 00688 IPAA_SYMBOL_REF * Get_symref ( SYMREF_IX i ) const 00689 { return ((IPAA_SYMBOL_REF *)_symrefs._p) + i; } 00690 IPAA_SECTION * Get_section ( SECTION_IX i ) const 00691 { return ((IPAA_SECTION *)_sections._p) + i; } 00692 IPAA_MODREF * Get_modref ( MODREF_IX i ) const 00693 { return ((IPAA_MODREF *) _modrefs._p) + i; } 00694 REFBITS Get_refbits ( INT32 i ) const 00695 { return ((REFBITS *) _refbits._p)[i]; } 00696 IPAA_SET * Get_set ( SET_IX i ) const 00697 { return ((IPAA_SET *)_sets._p) + i; } 00698 IPAA_PU_INFO * Get_pu_info ( PU_INFO_IX i ) const 00699 { return ((IPAA_PU_INFO *)_pu_info._p) + i; } 00700 00701 // Add objects to the tables (only valid if _mpool != NULL): 00702 INT32 Add_string ( const char * ); 00703 SYMREF_IX Add_symref ( const IPAA_SYMBOL_REF & ); 00704 SYMREF_IX Add_symref ( INT32 cnt, const IPAA_SYMBOL_REF * ); 00705 SECTION_IX Add_section (const IPAA_SECTION & ); 00706 SECTION_IX Add_section (INT32 cnt, const IPAA_SECTION * ); 00707 MODREF_IX Add_modref ( const IPAA_MODREF & ); 00708 MODREF_IX Add_modref ( INT32 cnt, const IPAA_MODREF * ); 00709 INT32 Add_refbits ( const REFBITS & ); 00710 INT32 Add_refbits ( INT32 cnt, const REFBITS * ); 00711 SET_IX Add_set ( const IPAA_SET & ); 00712 SET_IX Add_set ( INT32 cnt, const IPAA_SET * ); 00713 PU_INFO_IX Add_pu_info (const IPAA_PU_INFO & ); 00714 PU_INFO_IX Add_pu_info (INT32 cnt, const IPAA_PU_INFO * ); 00715 00716 // Build an IPAA_FILE_DESCRIPTOR, and write the summary file: 00717 void Write ( const char *file_name ); 00718 }; 00719 00720 // ==================================================================== 00721 // ==================================================================== 00722 // 00723 // The following are inlinable methods from the classes above which 00724 // depend on the global IPAA_Summary variable. 00725 // 00726 // ==================================================================== 00727 // ==================================================================== 00728 00729 char * 00730 IPAA_SYMBOL_REF::Name ( void ) const 00731 { 00732 return IPAA_Summary->Get_string ( Name_id() ); 00733 } 00734 00735 // ==================================================================== 00736 00737 char * 00738 IPAA_SYMBOL_REF::Global_name ( void ) const 00739 { 00740 return IPAA_Summary->Get_string ( Global_id() ); 00741 } 00742 00743 // ==================================================================== 00744 00745 char * 00746 IPAA_SYMBOL_REF::Local_file_name ( void ) const 00747 { 00748 return IPAA_Summary->Get_string ( Local_file_id() ); 00749 } 00750 00751 // ==================================================================== 00752 00753 INT64 00754 IPAA_SYMBOL_REF::Section_disp ( void ) const 00755 { 00756 return IPAA_Summary -> Get_section ( Section_id() ) -> Disp(); 00757 } 00758 00759 // ==================================================================== 00760 00761 INT64 00762 IPAA_SYMBOL_REF::Section_size ( void ) const 00763 { 00764 return IPAA_Summary -> Get_section ( Section_id() ) -> Size(); 00765 } 00766 00767 // ==================================================================== 00768 00769 char * 00770 IPAA_PU_INFO::Name ( void ) const 00771 { 00772 SYMREF_IX six = Pu_ix(); 00773 if ( six == 0 ) return NULL; 00774 IPAA_SYMBOL_REF *symref = IPAA_Summary -> Get_symref ( six ); 00775 if ( symref->Kind() == SREF_GLOBAL ) return symref->Global_name(); 00776 return NULL; 00777 } 00778 #endif /* not OPT_IPAA_IO */ 00779 00780 // ==================================================================== 00781 // ==================================================================== 00782 // 00783 // The following information is passed in the individual WHIRL files, 00784 // in the .WHIRL.ipaa section. 00785 // 00786 // ==================================================================== 00787 // ==================================================================== 00788 // 00789 // IPAA_CALLSITE 00790 // 00791 // This class describes a callsite; its purpose is to map a 00792 // callsite in WHIRL to the callee's information in the IPAA summary 00793 // file. The mechanism for doing so is a map consisting of a pair 00794 // < callsite_map_id, PU_INFO_INDEX >. The first element is the 00795 // ID of a mapping created in IPL for the callsites; the second is the 00796 // index of the callee's IPAA_PU_INFO record in the IPAA summary file. 00797 // 00798 // IPAA_CALLSITES 00799 // 00800 // This class describes a the callsite mapping, i.e. the set of 00801 // IPAA_CALLSITE records. They should be in _map_id order to allow 00802 // fast binary search lookup in WOPT. 00803 // 00804 // There is one such mapping per PU, with the set of them in their own 00805 // PU-Info subsection in the .B file. 00806 // 00807 // ==================================================================== 00808 // ==================================================================== 00809 00810 class IPAA_CALLSITES; 00811 00812 class IPAA_CALLSITE 00813 { 00814 friend class IPAA_CALLSITES; 00815 00816 mINT32 _map_id; // The mapping ID of the callsite 00817 PU_INFO_IX _pu_idx; // The IPAA_PU_INFO index of the callee 00818 00819 public: 00820 00821 // Constructor: 00822 IPAA_CALLSITE ( INT32 id, INT32 pu ) { _map_id = id; _pu_idx = pu; } 00823 00824 // Destructor: 00825 ~IPAA_CALLSITE ( void ) {} 00826 }; 00827 00828 00829 extern "C" { 00830 // Read table from .B file 00831 void *IPAA_CALLSITES_Read ( char *base, UINT32 size ); 00832 00833 // Write the table to the .B file 00834 void IPAA_CALLSITES_Write ( void *callsites, struct output_file *fl ); 00835 } 00836 00837 00838 class IPAA_CALLSITES 00839 { 00840 PU_INFO_IX _caller; // IPAA_PU_INFO index of the caller 00841 mINT32 _max; // Allocated number of IPAA_CALLSITE pairs 00842 mINT32 _size; // Actual number of IPAA_CALLSITE pairs 00843 // (includes invalid dummy at index 0) 00844 IPAA_CALLSITE *_callsites; // IPAA_CALLSITE vector 00845 MEM_POOL *_mpool; // Memory pool to use for _pu_idx 00846 00847 friend void *IPAA_CALLSITES_Read(char *base, UINT32 size); 00848 friend void IPAA_CALLSITES_Write(void *callsites, struct output_file *fl); 00849 00850 // Access to callsite vector: 00851 INT32 Get_map_id ( INT32 ix ) const 00852 { return _callsites[ix]._map_id; } 00853 PU_INFO_IX Get_pu_idx ( INT32 ix ) const 00854 { return _callsites[ix]._pu_idx; } 00855 00856 // Expand the callsite vector: 00857 void Expand_vector ( INT32 count = 2 ); 00858 00859 public: 00860 00861 // Constructor for IPAA use -- parameter is initial size: 00862 IPAA_CALLSITES ( PU_INFO_IX caller, INT32 size, MEM_POOL *mpool ); 00863 00864 // Destructor -- de-allocate _pu_idx: 00865 ~IPAA_CALLSITES ( void ); 00866 00867 // Tracing: 00868 void Print ( FILE *f, char *msg ) const; 00869 void Trace ( char *msg ) const; 00870 00871 // Given a map ID, where is the callee's PU information? 00872 PU_INFO_IX Map_to_PU_id ( INT32 map_id ); 00873 IPAA_PU_INFO *Map_to_PU ( INT32 map_id ); 00874 00875 // Add a new callsite mapping to the list, resizing if necessary: 00876 INT32 Add_callsite ( INT32 map_id, PU_INFO_IX pu_idx ); 00877 }; 00878 00879 // ==================================================================== 00880 // ==================================================================== 00881 // 00882 // IPAA_LOCAL_MAP 00883 // 00884 // This class describes the mapping from the per-file local IDs used in 00885 // IPAA summary file to the symbol table IDs used in the WHIRL file. 00886 // There will be one such mapping written per .B file, as its own 00887 // ELF section. 00888 // 00889 // The expected usage of this mapping involves being given a symbol, 00890 // and determining whether a reference exists. This requires 00891 // efficiently looking up the local ID given the SYMTAB_id and 00892 // ST_id for the symbol, and then efficiently checking whether that 00893 // symbol is referenced. We expect to do this as follows: 00894 // 00895 // Before using this table in the back end, we will build a mapping 00896 // indexed by ST_id for each SYMTAB we care about. This will allow 00897 // rapid lookup from symbol to local ID, with no IPA arrangement 00898 // (other than breaking these into files, which is required anyway), 00899 // and with only a simple single-pass initialization in the back end. 00900 // 00901 // We can determine whether a particular symbol is referenced as 00902 // follows, if we typically process a callsite completely and then move 00903 // on. We can do a pass over the reference sets for the callsite, 00904 // noting the reference information in the relevant mapping structures, 00905 // so that it is immediately referenceable. It must then be removed 00906 // before processing the next callsite. 00907 // 00908 // ==================================================================== 00909 // ==================================================================== 00910 00911 class IPAA_LOCAL_MAP 00912 { 00913 INT32 _max; // Number of elements allocated in the maps 00914 INT32 _size; // Number of elements used in the maps 00915 mINT16 *_symtab_id; // The local-id -> SYMTAB_id value map 00916 mINT32 *_st_id; // The local-id -> ST_id value map 00917 MEM_POOL *_mpool; // Where to put _symtab_id and _st_id? 00918 00919 friend void *IPAA_LOCAL_MAP_Read(char *base, UINT32 size); 00920 friend void IPAA_LOCAL_MAP_Write(void *localmap, struct output_file *fl); 00921 00922 public: 00923 00924 // Constructor for IPAA use -- parameter is initial size: 00925 IPAA_LOCAL_MAP ( INT32 size, MEM_POOL *mpool ); 00926 00927 // Destructor -- de-allocate _st_id: 00928 ~IPAA_LOCAL_MAP ( void ); 00929 00930 // Tracing: 00931 void Print ( FILE *f ) const; 00932 void Trace ( void ) const; 00933 00934 // Add an ST to the map for the given local index: 00935 void Map_local_to_st ( INT32 local, struct st *st ); 00936 00937 // Given a local ID, return its identifiers: 00938 void Local_to_ids ( INT32 local, INT16 *symtab_id, INT32 *st_id ) 00939 { *symtab_id = _symtab_id[local]; *st_id = _st_id[local]; } 00940 }; 00941 00942 #endif
1.5.6