Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
pu_info.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 #ifndef pu_info_INCLUDED
00037 #define pu_info_INCLUDED
00038 
00039 #include <elf.h>                /* for Elf64_Word */
00040 
00041 #include "dwarf_DST_mem.h"
00042 
00043 #ifndef _symtab_INCLUDED
00044 #include "symtab.h"
00045 #endif
00046 
00047 /*
00048  * This file defines the interface to the program unit (PU) header
00049  * information.  All the data structures associated with PUs are
00050  * stored in the same section, but each structure has its own
00051  * subsection.  The PU header information identifies the positions and
00052  * sizes of the subsections.  To make it easy to access the headers,
00053  * they are read into the PU_Info structures defined below.
00054  * Each file has a tree of PU_Infos to record the header information
00055  * for both the input and output files and to collect pointers to the
00056  * PU data structures in memory.
00057  */
00058 
00059 
00060 /* Version number to identify the structure of the PU section header */
00061 #define PU_HEADER_VERSION 1
00062 
00063 
00064 /*
00065  * Each subsection has a unique identifier that is stored in the binary
00066  * output file.  This provides some chance of adding new subsections
00067  * without making the binary format incompatible with older versions.
00068  *
00069  * CAUTION: We cannot define more than 15 subsection types here
00070  * without changing the implementation of PU_Info_state() because the
00071  * state info is stored in a 32-bit word in the PU_Info structure, at
00072  * two bits per subsection type. See PU_Info_state() for details.
00073  */
00074 
00075 #define WT_SYMTAB       0x0             /* symbol table */
00076 #define WT_TREE         0x1             /* WHIRL tree nodes */
00077 #define WT_DEPGRAPH     0x2             /* dependence graph */
00078 #define WT_PREFETCH     0x3             /* prefetch pointers */
00079 #define WT_REGIONS      0x4             /* RID trees */
00080 #define WT_FEEDBACK     0x5             /* feedback data */
00081 #define WT_FREQ         0x6             /* obsolete */
00082 #define WT_AC_INTERNAL  0x7             /* alias classification temporary */
00083 #define WT_ALIAS_CLASS  0x8             /* alias classification */
00084 
00085 #define WT_SUBSECTIONS  0x9             /* number of subsection types */
00086 #define WT_PROC_SYM     -1              /* special value for proc sym state */
00087 
00088 /*
00089  * These are the misc. flags associated to each PU
00090  */
00091 #define PU_HAS_GLOBALS           0x1 /* has globals symbols in local symtab,
00092                                         i.e., ST_EXPORT != EXPORT_LOCAL */ 
00093 #define PU_HAS_NESTED_PU         0x2 /* has other PU nested under this one */
00094 #define PU_IS_COMPILER_GENERATED 0x4 /* compiler_generated PU */
00095 #define PU_IS_DRA_CLONE          0x8 /* clone generated for reshaped arrays */
00096 #define PU_PREGS_RENUMBERED     0x10 /* Preopt for IPL has processed
00097                                         this PU; used to decide
00098                                         whether to repeat alias
00099                                         classification within preopt
00100                                         for LNO */
00101 
00102 /* reserve the top 4 bits for internal use within IPA */
00103 #define PU_INTERNAL_MASK 0xf0000000
00104 #define PU_DELETED      0x10000000  /* only used internally within IPA */
00105 
00106 /*
00107  * The WHIRL subsection header information is stored internally as a
00108  * tree of PU_Info structures.  (The actual subsection headers
00109  * in the binary files are compacted into arrays but that is too
00110  * inflexible to use internally.)  For each subsection, the PU_Info
00111  * structure records the current state and its position in memory or
00112  * in a file.  The pointer to the structure in memory overlaps with the
00113  * subsection size, so that the subsection file offset is still available
00114  * after reading the structure into memory.  (Some subsections refer to
00115  * WN nodes by their offsets within the WT_TREE subsection, and we need
00116  * to convert those references to pointers.)  To identify the PU,
00117  * the ID for the procedure symbol is also stored in the file.  This
00118  * can be converted to a pointer to the actual ST, and so we also keep
00119  * track of which form is stored.  The state flags are described below.
00120  */
00121 
00122 typedef struct pu_info {
00123     struct pu_info *next;               /* next PU_Info in the list */
00124     struct pu_info *child;              /* first child (nested procedure) */
00125     mINT32 state;                       /* current state of each subsection */
00126 
00127     ST_IDX proc_sym;                    /* ST_IDX of the function st */
00128     mINT32 flags;                       /* flags for any other attributes */
00129     DST_IDX pu_dst;                     /* index for the PU's DST entry */
00130     DST_IDX cu_dst;                     /* index for the compilation units
00131                                          * DST entry
00132                                          */
00133 
00134     struct {
00135         Elf64_Word offset;              /* section offset */
00136         union {
00137             Elf64_Word size;            /* subsection size */
00138             void *ptr;                  /* pointer to structure in memory */
00139         } u;
00140     } subsect[WT_SUBSECTIONS];
00141 
00142     /* other information not stored in the binary files */
00143     struct wn_map_tab *maptab;
00144 } PU_Info;
00145 
00146 
00147 #define PU_Info_proc_sym(pu)            (pu)->proc_sym
00148 #define PU_Info_proc_id(pu)             (pu)->proc_sym
00149         
00150 #ifdef __cplusplus
00151   // convenience function
00152 inline PU &
00153 PU_Info_pu(PU_Info *ppui)
00154 {
00155   return Pu_Table[ST_pu(St_Table[PU_Info_proc_sym(ppui)])];
00156 }
00157 #endif
00158 
00159 #define PU_Info_subsect_offset(pu,scn)  (pu)->subsect[scn].offset
00160 #define PU_Info_subsect_size(pu,scn)    (pu)->subsect[scn].u.size
00161 #define PU_Info_subsect_ptr(pu,scn)     (pu)->subsect[scn].u.ptr
00162 #define PU_Info_flags(pu)               (pu)->flags
00163 #define PU_Info_pu_dst(pu)              (pu)->pu_dst
00164 #define PU_Info_cu_dst(pu)              (pu)->cu_dst
00165 #define PU_Info_cu_dst(pu)              (pu)->cu_dst
00166 #define PU_Info_maptab(pu)              (pu)->maptab
00167 #define PU_Info_next(pu)                (pu)->next
00168 #define PU_Info_child(pu)               (pu)->child
00169 
00170 #define Set_PU_Info_flags(pu,flag_value) (pu)->flags |= (flag_value)
00171 #define Clear_PU_Info_flags(pu,flag_value) (pu)->flags &= ~(flag_value)
00172 #define Is_Set_PU_Info_flags(pu,flag_value) ((pu)->flags & (flag_value))
00173 
00174 
00175 /*
00176  *  The current state of each subsection for a PU is recorded in the
00177  *  state field of the PU_Info structure.  Since there are four
00178  *  possible states, we need two bits for each subsection.  We also
00179  *  need to keep track of whether the procedure's ST is stored as an
00180  *  ID number or as a pointer, so the first two bits are reserved for
00181  *  that (set ndx = -1 in the macros below to get/set the state of the
00182  *  procedure's ST).
00183  */
00184 
00185 typedef enum subsect_state {
00186     Subsect_Missing = 0,                /* information not available */
00187     Subsect_Exists = 1,                 /* in the input file */
00188     Subsect_InMem = 2,                  /* currently in memory */
00189     Subsect_Written = 3                 /* in the output file */
00190 } Subsect_State;
00191 
00192 #define PU_Info_state(pu, ndx) \
00193     (Subsect_State)(((pu)->state >> (((ndx) + 1) << 1)) & 0x3)
00194 #define Set_PU_Info_state(pu, ndx, st) (pu)->state = (pu)->state & \
00195     ~(0x3 << (((ndx) + 1) << 1)) | (st << (((ndx) + 1) << 1))
00196 
00197 
00198 /*
00199  *  High-level interface
00200  */
00201 
00202 #define PU_Info_symtab_ptr(pu) \
00203      (LOCAL_SYMTAB_HEADER_TABLE *) PU_Info_subsect_ptr((pu), WT_SYMTAB)
00204 #define PU_Info_tree_ptr(pu) \
00205      (WN *)PU_Info_subsect_ptr((pu), WT_TREE)
00206 #define PU_Info_depgraph_ptr(pu) \
00207      (void *)PU_Info_subsect_ptr((pu), WT_DEPGRAPH)
00208 #define PU_Info_regions_ptr(pu) \
00209      (struct region_id *)PU_Info_subsect_ptr((pu), WT_REGIONS)
00210 #define PU_Info_feedback_ptr(pu) \
00211      (void *)PU_Info_subsect_ptr((pu), WT_FEEDBACK)
00212 #define PU_Info_frequencies_ptr(pu) \
00213      (INT32 *) PU_Info_subsect_ptr((pu), WT_FREQ)
00214 #define PU_Info_alias_class_ptr(pu) \
00215      (INT32 *) PU_Info_subsect_ptr((pu), WT_ALIAS_CLASS)
00216 #define PU_Info_ac_internal_ptr(pu) \
00217      (void *) PU_Info_subsect_ptr((pu), WT_AC_INTERNAL)
00218 
00219 #define Set_PU_Info_tree_ptr(pu,x) \
00220     PU_Info_subsect_ptr((pu), WT_TREE) = (void *)(x)
00221 #define Set_PU_Info_symtab_ptr(pu,x) \
00222     PU_Info_subsect_ptr((pu), WT_SYMTAB) = (void *)(x)
00223 #define Set_PU_Info_depgraph_ptr(pu,x) \
00224     PU_Info_subsect_ptr((pu), WT_DEPGRAPH) = (void *)(x)
00225 #define Set_PU_Info_regions_ptr(pu,x) \
00226     PU_Info_subsect_ptr((pu), WT_REGIONS) = (void *)(x)
00227 #define Set_PU_Info_feedback_ptr(pu,x) \
00228     PU_Info_subsect_ptr((pu), WT_FEEDBACK) = (void *)(x)
00229 #define Set_PU_Info_frequencies_ptr(pu,x) \
00230     PU_Info_subsect_ptr((pu), WT_FREQ) = (void *) (x)
00231 #define Set_PU_Info_alias_class_ptr(pu,x) \
00232     PU_Info_subsect_ptr((pu), WT_ALIAS_CLASS) = (void *) (x)
00233 #define Set_PU_Info_ac_internal_ptr(pu,x) \
00234      PU_Info_subsect_ptr((pu), WT_AC_INTERNAL) = (void *) (x)
00235 
00236 #define Set_PU_Info_pu_dst(pu, x) \
00237         PU_Info_pu_dst(pu) = x;
00238 #define Set_PU_Info_cu_dst(pu, x) \
00239         PU_Info_cu_dst(pu) = x;
00240 
00241 
00242 #ifdef __cplusplus
00243 extern "C" {
00244 #endif
00245 
00246 extern void PU_Info_init (PU_Info *pu);
00247 extern INT Sizeof_PU_Infos (PU_Info *pu_tree);
00248 extern INT Write_PU_Infos (PU_Info *pu_tree, char *base);
00249 extern PU_Info *Read_PU_Infos (char *base, INT32 size, INT32 *p_num_PUs);
00250 
00251 extern PU_Info *Current_PU_Info;
00252 
00253 extern void Save_Local_Symtab (SYMTAB_IDX level, PU_Info *pu);
00254 extern void Restore_Local_Symtab (PU_Info *pu);
00255 
00256 #ifdef __cplusplus
00257 }
00258 #endif
00259 
00260 #ifdef __cplusplus
00261   // convenience function
00262 inline PU &
00263 Current_PU_Info_pu()
00264 {
00265   return PU_Info_pu(Current_PU_Info);
00266 }
00267 #endif
00268 
00269 #ifdef FIL
00270 extern PU_Info *Last_PU;
00271 #endif
00272 #endif /* pu_info_INCLUDED */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines