Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
PUinfo.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 PUinfo_INCLUDED
00037 #define PUinfo_INCLUDED
00038 /* ====================================================================
00039  * ====================================================================
00040  *
00041  *
00042  * Revision history:
00043  *   26-Dec-94 - Original Version
00044  *
00045  * Description:
00046  *
00047  *   Maintains information about the scope and block associated with
00048  *   a program unit (function/procedure).  We have defined three
00049  *   data-structures for accessing information about call-sites,
00050  *   return-sites, and function return types respectively.  The
00051  *   interface is as follows:
00052  *
00053  *  Exported state variables:
00054  *  -------------------------
00055  *
00056  *    PUinfo_current_func:
00057  *      Denotes the OPR_FUNC_ENTRY node for the current function
00058  *      being processed.  This variable is initialized by 
00059  *      PUinfo_init(), and we provide macros to access the
00060  *      return type and the ST for the function.  
00061  *      PUINFO_RETURN_TO_PARAM is TRUE when the current PU returns
00062  *      through the first parameter (e.g. for large structs).
00063  *
00064  *    PUinfo_local_decls:
00065  *      This buffer is used to accumulate declarations for variables
00066  *      and registers belonging to the current PU.
00067  *
00068  *    PUinfo_returnPreg:
00069  *      Information about how the return type of "PUinfo_current_func"
00070  *      will be split up into return registers.  This variable is 
00071  *      set by a call to PUinfo_Get_ReturnPreg() through PUinfo_init().
00072  *
00073  *  Interface routines:
00074  *  -------------------
00075  *
00076  *    PUinfo_initialize:
00077  *      Given the current symbol table (presumably the global symbol
00078  *      table), this procedure will add its symbols to the name-table.
00079  *      Other initiation is on a per-PU basis.
00080  *
00081  *    PUinfo_finalize:
00082  *      Free up everything that was allocated to the heap through
00083  *      this package.
00084  *
00085  *    PUinfo_init_pu:
00086  *      Given the OPC_FUNC_ENTRY node for a PU, and a subtree under
00087  *      that block, this function will traverse the current symbol-
00088  *      table, and the subtree to accumulate information needed 
00089  *      in the actual translation of the given subtree to a HLL.  
00090  *      The other functions provided in the interface to this file 
00091  *      will allow us to access the information accumulated during 
00092  *      this prepass over the subtree.  Note that no WHIRL->HLL
00093  *      translation is expected outside the given subtree!
00094  *
00095  *    PUinfo_exit_pu:
00096  *      Free up the information accumulated by means of PUinfo_init_pu().
00097  *      This may not literally free up memory, but may make it
00098  *      available for reuse when processing the next PU.
00099  *
00100  *    PUinfo_Symbol_Owns_Name:
00101  *      Given the WHIRL2C_make_valid_c_name (for whirl2c) or the
00102  *      WHIRL2F_make_valid_name (for whirl2f) version of a name, 
00103  *      return TRUE if the "symbol" pointer "owns" the name; return
00104  *      FALSE if the name is empty (NULL or "\0") or when the given
00105  *      id pointer does not own the name.  Only one identifier in a 
00106  *      given scope can "own" each name, and only this identifier can
00107  *      therefore be declared with the unmangled version of the name.
00108  *      Use INVALID_PREG_NUM when the symbol does not denote a preg.
00109  *
00110  *    PUinfo_Symbol_Id:
00111  *      Return a unique identifying number for the given symbol.  Note
00112  *      that this applies to all symbol kinds, except SYMKIND_PREG,
00113  *      for which PUinfo_Symbol_Owns_Name()==FALSE.  If no identifying
00114  *      number has been recorded for the given symbol, the value
00115  *      returned is 0 (zero).
00116  *
00117  *    PUinfo_Get_CallSites:
00118  *    PUinfo_Get_ReturnSites:
00119  *      Get information about every call and return statement, in
00120  *      the order (inorder/lexicographical) in which these will be
00121  *      processed during the WHIRL to HLL translation.  Store statements
00122  *      that assign between return-registers and (temporary) variables
00123  *      or registers are identified to improve the translation to 
00124  *      high-level languages.  The idea is to minimize the use of
00125  *      return-registers.  When RETURNSITE_return_var() or
00126  *      CALLSITE_return_var() is NULL, nothing is known of (temporary) 
00127  *      variables/registers holding call or function result, and the
00128  *      return-registers must be used.
00129  *
00130  *   PUinfo_Preg_Type:
00131  *      The type associated with a preg reference in a WHIRL tree may
00132  *      not always correspond to what we declare in the high-level
00133  *      language, since some pregs may be referred to as more than
00134  *      one type (e.g. integral types of various sizes).  Always use
00135  *      this function to get the actual assumed type of a given preg.
00136  *
00137  *   PUinfo_Is_Preg_Declared:
00138  *      Return TRUE if the given preg-number has been marked as having
00139  *      been declared of the given type.  The type must be identical to
00140  *      what would be returned if it was passed to PUinfo_Preg_Type().
00141  *
00142  *   PUinfo_Set_Preg_Declared:
00143  *      Mark the given preg-number as having been declared of the
00144  *      given type.  The type must be identical to what would be
00145  *      returned if it was passed to PUinfo_Preg_Type().
00146  *
00147  *   PUinfo_Get_ReturnPreg:
00148  *      Returns information about how a return value of the given
00149  *      type will be split into return registers.  Note that before
00150  *      calling PUinfo_init(), we must use RETURN_PREG_mtype() to get
00151  *      the mtype of the registers, while after the analysis of
00152  *      PUinfo_init() we should always use RETURN_PREG_declared_mtype()!
00153  *      This is because we may have various uses of an integral preg as
00154  *      different integral types, but it will be declared as one
00155  *      integral type only and this type is determined based on the
00156  *      analysis of the preg uses in PUinfo_init().
00157  *
00158  *      Note that the return-type information reflects High-WHIRL,
00159  *      which has single pregs for complex and quad types.  In Mid-
00160  *      WHIRL, these are lowered to actual register sized pregs and 
00161  *      distributed over two return registers.
00162  *
00163  * ====================================================================
00164  * ====================================================================
00165  */
00166 
00167         /*----- Information about call sites -----*/
00168         /*----------------------------------------*/
00169 
00170 typedef struct CallSite CALLSITE;
00171 struct CallSite
00172 {
00173    const WN   *call_wn;
00174    TY_IDX      return_ty;  /* Return type of the called function */
00175    const WN   *store1;     /* Store from return register1 (or NULL) */
00176    const WN   *store2;     /* Store from return register2 (or NULL) */
00177    const ST   *return_var; /* Returned value is stored into this ST ... */
00178    STAB_OFFSET var_offset; /* ... at this offset */
00179    BOOL        in_regs;    /* TRUE if value must be in return registers */
00180    CALLSITE   *next;       /* NULL if this is the last call-site in the PU */
00181 };
00182 #define CALLSITE_call(ci) (ci)->call_wn
00183 #define CALLSITE_return_ty(ci) (ci)->return_ty
00184 #define CALLSITE_store1(ci) (ci)->store1
00185 #define CALLSITE_store2(ci) (ci)->store2
00186 #define CALLSITE_return_var(ci) (ci)->return_var
00187 #define CALLSITE_var_offset(ci) (ci)->var_offset
00188 #define CALLSITE_in_regs(ci) (ci)->in_regs
00189 #define CALLSITE_next(ci) (ci)->next
00190 
00191 
00192         /*----- Information about return sites -----*/
00193         /*------------------------------------------*/
00194 
00195 typedef struct ReturnSite RETURNSITE;
00196 struct ReturnSite
00197 {
00198    const WN    *return_wn;
00199    const WN    *store1;     /* Store into return register1 (or NULL) */
00200    const WN    *store2;     /* Store into return register2 (or NULL) */
00201    const ST    *return_var; /* Return registers stored from this ST ... */
00202    STAB_OFFSET  var_offset; /* ... at this offset */
00203    RETURNSITE  *next;       /* NULL if this is the last return-site in the PU */
00204 };
00205 #define RETURNSITE_return(ci) (ci)->return_wn
00206 #define RETURNSITE_store1(ci) (ci)->store1
00207 #define RETURNSITE_store2(ci) (ci)->store2
00208 #define RETURNSITE_return_var(ci) (ci)->return_var
00209 #define RETURNSITE_var_offset(ci) (ci)->var_offset
00210 #define RETURNSITE_next(ci) (ci)->next
00211 
00212 
00213   /*----- Information about pseudo registers for function returns -----*/
00214   /*-------------------------------------------------------------------*/
00215 
00216 typedef struct RETURN_PREG
00217 {
00218                                        
00219    UINT8       num_pregs;  /* Number of pregs needed for return type */
00220    MTYPE       mtype[2];   /* Mtypes for the return pregs (or MTYPE_V) */
00221    STAB_OFFSET offset[2];  /* The preg-numbers for the return pregs */
00222 } RETURN_PREG;
00223 #define RETURN_PREG_num_pregs(rp) (rp)->num_pregs
00224 #define RETURN_PREG_mtype(rp, i) (rp)->mtype[(i)]
00225 #define RETURN_PREG_offset(rp, i) (rp)->offset[(i)]
00226 
00227 
00228   /*----- Information about the current function, return type etc. ----*/
00229   /*-------------------------------------------------------------------*/
00230 
00231 
00232 extern const WN          *PUinfo_current_func;
00233 extern const RETURN_PREG *PUinfo_return_preg;
00234 extern TOKEN_BUFFER       PUinfo_local_decls;
00235 extern TOKEN_BUFFER       PUinfo_pragmas;
00236 extern UINT               PUinfo_local_decls_indent;
00237 
00238 #define PUINFO_FUNC_ST_IDX WN_st_idx(PUinfo_current_func)
00239 #define PUINFO_FUNC_ST     WN_st(PUinfo_current_func)
00240 #define PUINFO_FUNC_TY     ST_pu_type(PUINFO_FUNC_ST)
00241 #define PUINFO_FUNC_NAME   W2CF_Symtab_Nameof_St(PUINFO_FUNC_ST)
00242 
00243 #define PUINFO_RETURN_TY        W2X_Unparse_Target->Func_Return_Type(PUINFO_FUNC_TY)
00244 #define PUINFO_RETURN_PARAM     WN_st(WN_formal(PUinfo_current_func, 0))
00245 #define PUINFO_RETURN_TO_PARAM  W2X_Unparse_Target->Func_Return_To_Param(PUINFO_FUNC_TY)
00246 #define PUINFO_RETURN_CHARACTER W2X_Unparse_Target->Func_Return_Character(PUINFO_FUNC_TY)
00247 
00248 
00249         /*----- Interface routines -----*/
00250         /*------------------------------*/
00251 
00252 extern void PUinfo_initialize(void);
00253 extern void PUinfo_finalize(void);
00254 
00255 extern void PUinfo_init_pu(const WN *wn, WN *body_part_of_interest);
00256 extern void PUinfo_exit_pu(void);
00257 
00258 extern CALLSITE *PUinfo_Get_CallSites(void);
00259 extern RETURNSITE *PUinfo_Get_ReturnSites(void);
00260 
00261 extern TY_IDX PUinfo_Preg_Type(TY_IDX preg_ty, INT16 preg_num);
00262 extern BOOL PUinfo_Is_Preg_Declared(TY_IDX preg_ty, INT16 preg_num);
00263 extern void PUinfo_Set_Preg_Declared(TY_IDX preg_ty, INT16 preg_num);
00264 
00265 extern RETURN_PREG PUinfo_Get_ReturnPreg(TY_IDX return_ty);
00266 
00267 #endif /* PUinfo_INCLUDED */
00268 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines