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