Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
dra_internal.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 dra_internal_INCLUDED
00037 #define dra_internal_INCLUDED
00038 
00039 // ====================================================================
00040 // ====================================================================
00041 //
00042 //
00043 // Revision history:
00044 //  16-Jul-96: Original Version
00045 //
00046 // Description: Internal data structures and interface specifications
00047 //              used to support cloning and name mangling in the 
00048 //              presence of distribute_reshaped array arguments.
00049 //
00050 //              -----------------------------------------------------
00051 //              DO NOT include this file from outside dra_* world !!!
00052 //              -----------------------------------------------------
00053 //
00054 // ====================================================================
00055 // ====================================================================
00056 
00057 // ====================================================================
00058 //
00059 // class DRA_INFO
00060 //       Store basic information for a reshaped array.
00061 //
00062 // Public Methods
00063 // --------------
00064 //
00065 //  DRA_INFO (INT16 ndims, INT64 esize, MEM_POOL *pool)
00066 //      Constructor.
00067 //
00068 //  DISTRIBUTE_TYPE Distr_Type(INT16 dim)
00069 //      Return the type of distribution.
00070 //
00071 //  INT64 Chunk_Const_Val(INT16 dim)
00072 //      Return the chunksize (must be constant)
00073 // 
00074 //  void Init (INT16 dim, DISTRIBUTE_TYPE dt);
00075 //      Initialize routine for block/star/cyclic_expr distributions.
00076 //
00077 //  void Init (INT16 dim, DISTRIBUTE_TYPE dt, INT64 const_val)
00078 //      Initialize routines for cyclic_const
00079 //
00080 //  INT64 Element_Size()
00081 //      Return the size in bytes of a single array element.
00082 //
00083 //  void Print (FILE* fp)
00084 //      Standard print routine
00085 //
00086 // ====================================================================
00087 //
00088 // class DRA_GLOBAL_INFO
00089 //      Store information about global arrays
00090 //
00091 // Public Methods
00092 // --------------
00093 //
00094 //  DRA_GLOBAL_INFO(TY_IDX ty)
00095 //      Constructor
00096 //
00097 //  TY_IDX Get_TY ()
00098 //      Return the original TY of the array.
00099 //
00100 // ====================================================================
00101 //
00102 // class STRING_NODE
00103 //       Derived from the base class SLIST_NODE
00104 //
00105 // class STRING_LIST
00106 //       Derived from the base class SLIST
00107 //
00108 // class STRING_ITER
00109 //       Derived from the base clase SLIST_ITER
00110 //
00111 // ====================================================================
00112 // 
00113 // Exported Types
00114 // --------------
00115 //
00116 //  DRA_HASH_TABLE
00117 //      Hash table of ST entries and the corresponding DRA_INFO's
00118 //
00119 //  STRING_LIST_TABLE
00120 //      Hash table of linked lists of strings
00121 // 
00122 //  NAME_ST_TABLE
00123 //      Hash table of mangled names and their ST entries
00124 //
00125 // ====================================================================
00126 //
00127 // Exported variables
00128 // ------------------
00129 //
00130 // extern NAME_ST_TABLE *DRA_func_table;
00131 //      Global table used to resolve cloned and mangled names
00132 //
00133 // extern DRA_HASH_TABLE *DRA_array_table;
00134 //      Global table used to store information about DRA's
00135 //
00136 // extern MEM_POOL DRA_name_pool, *DRA_name_pool_ptr;
00137 //      Memory pool used for DRA_array_table
00138 //
00139 // extern DRA_GLOBAL_HASH_TABLE *dra_global;
00140 //      Global hash-table that stores information about global arrays.
00141 //
00142 // ====================================================================
00143 //
00144 // Exported Functions
00145 // ------------------
00146 //
00147 // Reading distribute_reshape pragmas and mangling function names:
00148 // extern void DRA_Read_Pragmas (WN* func_nd, DRA_HASH_TABLE *dra_table);
00149 // extern void DRA_Mangle_All(WN *func_wn, 
00150 //                            DRA_HASH_TABLE *dra_table,
00151 //                            PU_Info *pu_info);
00152 // extern WN* Get_Preamble_End(WN *pu_wn);
00153 //  
00154 // Utility functions for processing .rii files:
00155 // extern void Make_rii_File_Name();
00156 // extern char* Mem_Map_Prelinker_File();
00157 // extern void Mem_Unmap_Prelinker_File(char *rii_file);
00158 // extern FILE* Open_Prelinker_File_For_Append();
00159 //
00160 // ====================================================================
00161 // 
00162 // Exported Constants
00163 // ------------------
00164 //
00165 // DRA_MANGLE_SIG, DRA_MANGLE_SIG_LEN
00166 //      Signature string used in name mangling and its length
00167 // DRA_STAR_CODE, DRA_BLOCK_CODE, DRA_CYCLIC_CODE 
00168 //      Encodings for different distribution types
00169 // DRA_NDIMS_END, DRA_ESIZE_END, DRA_ARG_SEPARATOR
00170 //      Encoding separators
00171 // 
00172 // PRELINKER_FILE_SEPARATOR
00173 //      Section separator in .rii files
00174 //
00175 // ====================================================================
00176 
00177 
00178 #ifndef defs_INCLUDED
00179 #include "defs.h"               // standard definitions
00180 #endif
00181 
00182 #ifndef pragmas_INCLUDED
00183 #include "wn_pragmas.h"         // DISTRIBUTE_TYPE
00184 #endif
00185 
00186 #ifndef CXX_MEMORY_INCLUDED
00187 #include "cxx_memory.h"         // CXX_NEW
00188 #endif
00189 
00190 #ifndef cxx_hash_INCLUDED
00191 #include "cxx_hash.h"           // HASH_TABLE
00192 #endif
00193 
00194 
00195 #ifndef cxx_base_INCLUDED
00196 #include "cxx_base.h"           // SLIST, SLIST_NODE
00197 #endif
00198 
00199 #ifndef mtypes_INCLUDED
00200 #include "mtypes.h"             // TYPE_ID
00201 #endif
00202 
00203 #include "symtab.h"
00204 
00205 
00206 typedef struct {
00207   DISTRIBUTE_TYPE _distr_type;  // DISTRIBUTE_STAR,
00208                                 // DISTRIBUTE_BLOCK,
00209                                 // DISTRIBUTE_CYCLIC_EXPR, or
00210                                 // DISTRIBUTE_CYCLIC_CONST.
00211                                 // (definitions in wn_pragmas.h)
00212 
00213   INT64 _chunksize;             // chunk size for CYCLIC_CONST
00214 
00215 } RESHAPED_DIM;
00216 
00217 
00218 
00219 class DRA_INFO {
00220 
00221 private:
00222 
00223   INT16 _ndims;                 // number of dimensions
00224 
00225   INT64 _esize;                 // element size
00226 
00227   struct mem_pool *_pool;       // memory pool used for allocation
00228 
00229   RESHAPED_DIM *_dims;          // distr of each dimension
00230 
00231 public:
00232 
00233   DRA_INFO (INT16 ndims, INT64 esize, struct mem_pool *pool) {
00234     _ndims = ndims;
00235     _esize = esize;
00236     _pool = pool;
00237     _dims = CXX_NEW_ARRAY(RESHAPED_DIM, ndims, pool);
00238     for (INT16 i = 0; i < ndims; i++) {
00239       _dims[i]._chunksize = 0;
00240     }
00241   }
00242 
00243   INT16 Num_Dims() const { return _ndims; }
00244 
00245   DISTRIBUTE_TYPE Distr_Type (INT16 dim) const {
00246     return _dims[dim]._distr_type;
00247   }
00248 
00249   INT64 Chunk_Const_Val (INT16 dim) const {
00250     return _dims[dim]._chunksize;
00251   }
00252 
00253   void Init (INT16 dim, DISTRIBUTE_TYPE dt) {  
00254     Is_True ((dt == DISTRIBUTE_BLOCK) || 
00255              (dt == DISTRIBUTE_STAR)  ||
00256              (dt == DISTRIBUTE_CYCLIC_EXPR),
00257              ("Distribute type must be BLOCK, STAR, or CYCLIC_EXPR"));
00258     _dims[dim]._distr_type = dt;
00259   }
00260 
00261   void Init (INT16 dim, DISTRIBUTE_TYPE dt, INT64 chunksize) { 
00262     Is_True (dt == DISTRIBUTE_CYCLIC_CONST,
00263              ("Distribute type must be CYCLIC_CONST"));
00264     _dims[dim]._distr_type = dt;
00265     _dims[dim]._chunksize = chunksize;
00266   }
00267 
00268   INT64 Element_Size () const { return _esize; }
00269 
00270   void Print (FILE* fp) const {
00271     fprintf (fp, "Distribution: \n");
00272     for (INT16 i = 0; i < _ndims; i++) {
00273       DISTRIBUTE_TYPE dt = _dims[i]._distr_type;
00274       fprintf (fp, "%s", 
00275                (dt == DISTRIBUTE_STAR) ? "STAR" : 
00276                (dt == DISTRIBUTE_BLOCK) ? "BLOCK" : 
00277                (dt == DISTRIBUTE_CYCLIC_EXPR) ? "CYCLIC_EXPR" : 
00278                (dt == DISTRIBUTE_CYCLIC_CONST) ? "CYCLIC_CONST" : 
00279                "unknown");
00280       if (dt == DISTRIBUTE_CYCLIC_CONST) {
00281         fprintf (fp, " (%lld)", _dims[i]._chunksize);
00282       }
00283     }
00284     fprintf (fp, "\n");
00285   }
00286     
00287 };
00288 
00289 
00290 
00291 class STRING_NODE : public SLIST_NODE {
00292   DECLARE_SLIST_NODE_CLASS(STRING_NODE);
00293 
00294   private:
00295     STR_IDX _string;
00296   
00297   public:
00298     STRING_NODE(STR_IDX string) { Set_Next(NULL); _string = string; }
00299     STR_IDX String() { return _string; }
00300 };
00301 
00302 
00303 class STRING_LIST : public SLIST {
00304   DECLARE_SLIST_CLASS(STRING_LIST, STRING_NODE);
00305 };
00306 
00307 
00308 class STRING_ITER : public SLIST_ITER {
00309   DECLARE_SLIST_ITER_CLASS(STRING_ITER, STRING_NODE, STRING_LIST);
00310 };
00311 
00312 
00313 // HASH_TABLE of DRA_INFO's
00314 //
00315 typedef HASH_TABLE<ST*, DRA_INFO*> DRA_HASH_TABLE;
00316 
00317 
00318 // HASH_TABLE of STRING_LIST's 
00319 //
00320 typedef HASH_TABLE<STR_IDX, STRING_LIST*> STRING_LIST_TABLE;
00321 
00322 
00323 typedef struct {
00324   ST *st;
00325   BOOL is_clone;
00326   BOOL is_called;
00327 } MANGLED_FUNC;
00328 
00329 // HASH_TABLE of mangled names and their ST entries with flags
00330 //
00331 typedef HASH_TABLE<STR_IDX, MANGLED_FUNC*> NAME_ST_TABLE;
00332 
00333 typedef HASH_TABLE_ITER <STR_IDX, MANGLED_FUNC*> NAME_ST_TABLE_ITER;
00334 
00335 
00336 class DRA_GLOBAL_INFO {
00337   TY_IDX _orig_ty;
00338   DRA_GLOBAL_INFO (void);
00339   DRA_GLOBAL_INFO (const DRA_GLOBAL_INFO&);
00340   DRA_GLOBAL_INFO* operator= (const DRA_GLOBAL_INFO&);
00341 public:
00342   DRA_GLOBAL_INFO(TY_IDX ty) { _orig_ty = ty; }
00343   TY_IDX Get_TY () { return _orig_ty; }
00344 };
00345 
00346 typedef HASH_TABLE<ST*, DRA_GLOBAL_INFO*> DRA_GLOBAL_HASH_TABLE;
00347 extern DRA_GLOBAL_HASH_TABLE* dra_global;
00348 
00349 typedef HASH_TABLE<ST_IDX, BOOL> DRA_COMMON_HASH_TABLE;
00350 
00351 
00352 // Global table used to resolve cloned and mangled names
00353 //
00354 extern NAME_ST_TABLE *DRA_func_table;
00355 
00356 
00357 // Global table used to store information about DRA's
00358 //
00359 extern DRA_HASH_TABLE *DRA_array_table;
00360 
00361 
00362 // Memory pool used for DRA_array_table
00363 //
00364 extern struct mem_pool DRA_name_pool, *DRA_name_pool_ptr;
00365 
00366 
00367 // File descriptor and pointer to mapped memory for .rii file
00368 //
00369 extern INT DRA_file_desc;
00370 
00371 extern char *DRA_file_mmap;
00372 
00373 extern char DRA_file_name[];
00374 
00375 class WN;
00376 
00377 // Reading distribute_reshape pragmas and mangling function names
00378 //
00379 extern void DRA_Read_Pragmas (WN *func_nd,
00380                               DRA_HASH_TABLE *dra_table);
00381 
00382 extern void DRA_Mangle_All (WN *func_wn,
00383                             DRA_HASH_TABLE *dra_table,
00384                             struct pu_info *pu_info);
00385 
00386 extern void DRA_EC_Declare_Types ();
00387 
00388 extern void DRA_EC_Array_Portion_Parms (WN *func_nd,
00389                                         WN *entry_nd);
00390 
00391 extern WN *Get_Preamble_End (WN *pu_wn);
00392 
00393 extern ST *Find_Return_Registers (TYPE_ID type, 
00394                                         PREG_NUM *rreg1, 
00395                                         PREG_NUM *rreg2);
00396 
00397 
00398 // Utility functions for processing of .rii files
00399 //
00400 extern void DRA_Open_And_Map_File();
00401 
00402 extern void DRA_Set_Write_Location();
00403 
00404 extern void DRA_Mem_Unmap_File();
00405 
00406 extern void DRA_Close_File();
00407 
00408 
00409 
00410 // Constants used in name mangling
00411 // 
00412 // NOTE: All these constants have their #define counterparts
00413 //       in common/com/dra_demangle.c
00414 //       Any change in this file should also be reflected there.      
00415 
00416 static const char* DRA_MANGLE_SIG     = "__nn__";
00417 static const INT   DRA_MANGLE_SIG_LEN = strlen(DRA_MANGLE_SIG);
00418 
00419 static const char  DRA_STAR_CODE      = 'S';
00420 static const char  DRA_BLOCK_CODE     = 'B';
00421 static const char  DRA_CYCLIC_CODE    = 'C';
00422 static const char  DRA_NDIMS_END      = 'D';
00423 static const char  DRA_ESIZE_END      = 'E';
00424 static const char  DRA_ARG_SEPARATOR  = '_';
00425 
00426 
00427 // Section separator in the prelinker (.rii) file
00428 //
00429 static const char* DRA_FILE_SEPARATOR = "----\n";
00430 
00431 // Get the array type of a distributed array given the st
00432 
00433 extern TY_IDX Get_Array_Type (ST* st);
00434 
00435 // Get the original type of a st
00436 
00437 extern TY_IDX Get_Original_Type (ST* st);
00438 
00439 #endif /* dra_internal_INCLUDED */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines