Open64 (mfef90, whirl2f, and IR tools)  TAG: version-openad; SVN changeset: 916
mtypes.cxx
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 /* ====================================================================
00037  * ====================================================================
00038  *
00039  *
00040  * Revision history:
00041  *
00042  * Description:
00043  *
00044  * Define IDs for the types supported by the target machine.  Not all
00045  * of the predefined types will be supported on a given machine; the
00046  * type attributes of those supported are defined in tdt.awk.
00047  *
00048  * ====================================================================
00049  * ====================================================================
00050  */
00051 
00052 #include "defs.h"
00053 #include "mtypes.h"
00054 
00055 #include "ir_a2b_util.h"
00056 
00057 // eraxxon (2005.01): Re-implement table and routines to support b2a
00058 // and a2b conversions.
00059 // 
00060 // N.B.: We cannot simply change the definition of TYPE_DESC because
00061 // mtypes.h is included in *many* C files (e.g. the gcc front-end,
00062 // libdwarf)
00063 
00064 struct MtypeToStr_t : public ir_a2b::enum2str_tbl_entry_t {
00065   MtypeToStr_t(TYPE_ID id_ = 0, const char* name_ = 0) 
00066     : id(id_), name(name_) { }
00067   virtual ~MtypeToStr_t() { }
00068   
00069   virtual INT getEnumVal() const     { return id; }
00070   virtual const char* getStr() const { return name; }
00071   
00072   TYPE_ID     id;   /* MTYPE_xxx */
00073   const char* name; /* name */
00074 };
00075 
00076 
00077 TYPE_DESC Machine_Types[] =
00078 { { MTYPE_UNKNOWN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, MTYPE_UNKNOWN },
00079   { MTYPE_B,     1,  0,  0, 0,  0, 0,   0, 0, 0, MTYPE_CLASS_INTEGER,0, MTYPE_B },
00080   { MTYPE_I1,    8,  8,  8, 1,  1, 1,   1, 0, 0, MTYPE_CLASS_INTEGER,1, MTYPE_U1 },
00081   { MTYPE_I2,   16, 16, 16, 2,  2, 2,   1, 0, 0, MTYPE_CLASS_INTEGER,3, MTYPE_U2 },
00082   { MTYPE_I4,   32, 32, 32, 4,  4, 4,   1, 0, 0, MTYPE_CLASS_INTEGER,5, MTYPE_U4 },
00083   { MTYPE_I8,   64, 64, 64, 8,  8, 8,   1, 0, 0, MTYPE_CLASS_INTEGER,7, MTYPE_U8 },
00084   { MTYPE_U1,    8,  8,  8, 1,  1, 1,   0, 0, 0, MTYPE_CLASS_UNSIGNED_INTEGER,2, MTYPE_I1 },
00085   { MTYPE_U2,   16, 16, 16, 2,  2, 2,   0, 0, 0, MTYPE_CLASS_UNSIGNED_INTEGER,4, MTYPE_I2 },
00086   { MTYPE_U4,   32, 32, 32, 4,  4, 4,   0, 0, 0, MTYPE_CLASS_UNSIGNED_INTEGER,6, MTYPE_I4 },
00087   { MTYPE_U8,   64, 64, 64, 8,  8, 8,   0, 0, 0, MTYPE_CLASS_UNSIGNED_INTEGER,8, MTYPE_I8 },
00088   { MTYPE_F4,   32, 32, 32, 4,  4, 4,   1, 1, 0, MTYPE_CLASS_FLOAT,9, MTYPE_F4 },
00089   { MTYPE_F8,   64, 64, 64, 8,  8, 8,   1, 1, 0, MTYPE_CLASS_FLOAT,11, MTYPE_F8 },
00090   { MTYPE_F10, 128,128,128,16, 16,16,   1, 1, 0, MTYPE_CLASS_FLOAT,13, MTYPE_F10 },
00091   { MTYPE_F16, 128,128,128,16, 16,16,   1, 1, 0, MTYPE_CLASS_FLOAT,15, MTYPE_F16 },
00092   { MTYPE_STR,   0,  0,  0, 1,  1, 4,   0, 0, 0, MTYPE_CLASS_STR,0, MTYPE_STR },
00093   { MTYPE_FQ,  128,128,128,16, 16,16,   1, 1, 0, MTYPE_CLASS_FLOAT,14, MTYPE_FQ },
00094   { MTYPE_M,     0,  0,  0, 0,  0, 0,   0, 0, 0, 0,0, MTYPE_M },
00095   { MTYPE_C4,    64, 64,64, 4,  4, 4,   0, 1, 0, MTYPE_CLASS_COMPLEX_FLOAT,10, MTYPE_C4 },
00096   { MTYPE_C8,    128,128,128, 8,  8, 8, 0, 1, 0, MTYPE_CLASS_COMPLEX_FLOAT,12, MTYPE_C8 },
00097   { MTYPE_CQ,    256,256,256,16, 16,16, 0, 1, 0, MTYPE_CLASS_COMPLEX_FLOAT,16, MTYPE_CQ },
00098   { MTYPE_V,     0,  0,  0, 0,  0, 0,   0, 0, 0, 0,0, MTYPE_V },
00099   { MTYPE_BS,    1,  0,  0, 0,  0, 0,   0, 0, 0, MTYPE_CLASS_INTEGER,0, MTYPE_BS },
00100   { MTYPE_A4,   32, 32, 32, 4,  4, 4,   0, 0, 0, MTYPE_CLASS_UNSIGNED_INTEGER,6, MTYPE_A4 },
00101   { MTYPE_A8,   64, 64, 64, 8,  8, 8,   0, 0, 0, MTYPE_CLASS_UNSIGNED_INTEGER,8, MTYPE_A8 },
00102   { MTYPE_C10,   256,256,256,16, 16,16, 0, 1, 0, MTYPE_CLASS_COMPLEX_FLOAT,16, MTYPE_C10 },
00103   { MTYPE_C16,   256,256,256,16, 16,16, 0, 1, 0, MTYPE_CLASS_COMPLEX_FLOAT,16, MTYPE_C16 },
00104   { MTYPE_I16,   256,256,256,16, 16,16, 0, 1, 0, MTYPE_CLASS_INTEGER,16, MTYPE_I16 },
00105   { MTYPE_U16,   256,256,256,16, 16,16, 0, 1, 0, MTYPE_CLASS_UNSIGNED_INTEGER,16, MTYPE_U16 }
00106 };
00107 
00108 
00109 MtypeToStr_t MtypeToNameTbl[] = {
00110   MtypeToStr_t(MTYPE_UNKNOWN, "UNK"),
00111   MtypeToStr_t(MTYPE_B,       "B"),
00112   MtypeToStr_t(MTYPE_I1,      "I1"),
00113   MtypeToStr_t(MTYPE_I2,      "I2"),
00114   MtypeToStr_t(MTYPE_I4,      "I4"),
00115   MtypeToStr_t(MTYPE_I8,      "I8"),
00116   MtypeToStr_t(MTYPE_U1,      "U1"),
00117   MtypeToStr_t(MTYPE_U2,      "U2"),
00118   MtypeToStr_t(MTYPE_U4,      "U4"),
00119   MtypeToStr_t(MTYPE_U8,      "U8"),
00120   MtypeToStr_t(MTYPE_F4,      "F4"),
00121   MtypeToStr_t(MTYPE_F8,      "F8"),
00122   MtypeToStr_t(MTYPE_F10,     "F10"),
00123   MtypeToStr_t(MTYPE_F16,     "F16"),
00124   MtypeToStr_t(MTYPE_STR,     "STR"),
00125   MtypeToStr_t(MTYPE_FQ,      "FQ"),
00126   MtypeToStr_t(MTYPE_M,       "M"),
00127   MtypeToStr_t(MTYPE_C4,      "C4"),
00128   MtypeToStr_t(MTYPE_C8,      "C8"),
00129   MtypeToStr_t(MTYPE_CQ,      "CQ"),
00130   MtypeToStr_t(MTYPE_V,       "V"),
00131   MtypeToStr_t(MTYPE_BS,      "BS"),
00132   MtypeToStr_t(MTYPE_A4,      "A4"),
00133   MtypeToStr_t(MTYPE_A8,      "A8"),
00134   MtypeToStr_t(MTYPE_C10,     "C10"),
00135   MtypeToStr_t(MTYPE_C16,     "C16"),
00136   MtypeToStr_t(MTYPE_I16,     "I16"),
00137   MtypeToStr_t(MTYPE_U16,     "U16")
00138 };
00139 
00140 
00141 static TYPE_ID Machine_Next_Alignment[] =
00142 {
00143  /* MTYPE_UNKNOWN */    MTYPE_UNKNOWN,
00144  /* MTYPE_B       */    MTYPE_UNKNOWN,
00145  /* MTYPE_I1      */    MTYPE_I2,
00146  /* MTYPE_I2      */    MTYPE_I4,
00147  /* MTYPE_I4      */    MTYPE_I8,
00148  /* MTYPE_I8      */    MTYPE_UNKNOWN,
00149  /* MTYPE_U1      */    MTYPE_U2,
00150  /* MTYPE_U2      */    MTYPE_U4,
00151  /* MTYPE_U4      */    MTYPE_U8,
00152  /* MTYPE_U8      */    MTYPE_UNKNOWN,
00153  /* MTYPE_F4      */    MTYPE_F8,
00154  /* MTYPE_F8      */    MTYPE_FQ,
00155  /* MTYPE_F10     */    MTYPE_UNKNOWN,
00156  /* MTYPE_F16     */    MTYPE_UNKNOWN,
00157  /* MTYPE_STR     */    MTYPE_UNKNOWN,
00158  /* MTYPE_FQ      */    MTYPE_UNKNOWN,  
00159  /* MTYPE_M       */    MTYPE_UNKNOWN,  
00160  /* MTYPE_C4      */    MTYPE_C8,       
00161  /* MTYPE_C8      */    MTYPE_CQ,       
00162  /* MTYPE_CQ      */    MTYPE_UNKNOWN,  
00163  /* MTYPE_V       */    MTYPE_UNKNOWN,
00164  /* MTYPE_BS      */    MTYPE_UNKNOWN,
00165  /* MTYPE_A4      */    MTYPE_UNKNOWN,
00166  /* MTYPE_A8      */    MTYPE_UNKNOWN
00167 };
00168 
00169 static TYPE_ID Machine_Prev_Alignment[] =
00170 {
00171  /* MTYPE_UNKNOWN */    MTYPE_UNKNOWN,
00172  /* MTYPE_B       */    MTYPE_UNKNOWN,
00173  /* MTYPE_I1      */    MTYPE_UNKNOWN,
00174  /* MTYPE_I2      */    MTYPE_I1,
00175  /* MTYPE_I4      */    MTYPE_I2,
00176  /* MTYPE_I8      */    MTYPE_I4,
00177  /* MTYPE_U1      */    MTYPE_UNKNOWN,
00178  /* MTYPE_U2      */    MTYPE_U1,
00179  /* MTYPE_U4      */    MTYPE_U2,
00180  /* MTYPE_U8      */    MTYPE_U4,
00181  /* MTYPE_F4      */    MTYPE_UNKNOWN,
00182  /* MTYPE_F8      */    MTYPE_F4,
00183  /* MTYPE_F10     */    MTYPE_UNKNOWN,
00184  /* MTYPE_F16     */    MTYPE_UNKNOWN,
00185  /* MTYPE_STR     */    MTYPE_UNKNOWN,
00186  /* MTYPE_FQ      */    MTYPE_F8,
00187  /* MTYPE_M       */    MTYPE_UNKNOWN,
00188  /* MTYPE_C4      */    MTYPE_UNKNOWN,
00189  /* MTYPE_C8      */    MTYPE_C4,
00190  /* MTYPE_CQ      */    MTYPE_C8,
00191  /* MTYPE_V       */    MTYPE_UNKNOWN,
00192  /* MTYPE_B       */    MTYPE_UNKNOWN,
00193  /* MTYPE_U4      */    MTYPE_UNKNOWN,
00194  /* MTYPE_U8      */    MTYPE_UNKNOWN
00195 };
00196 
00197 
00198 MTYPE_MASK Machine_Types_Available = 0x1fdffe;
00199 
00200 
00201 /* ====================================================================
00202  *
00203  * Mtype_Name: given a MTYPE, return a string representation
00204  *
00205  * Name_To_Mtype: given a string, return a MTYPE
00206  *
00207  * ====================================================================
00208  */
00209 
00210 #if 0
00211 const char *
00212 Mtype_Name (TYPE_ID b)
00213 {
00214   static char buf[32];
00215 
00216   if ( b>0 && b<=MTYPE_LAST ) {
00217     return MTYPE_name(b);
00218   } else {
00219     sprintf (buf, "BETYPE_%1d", b);
00220     return buf;
00221   }
00222 }
00223 #endif
00224 
00225 const char *
00226 Mtype_Name (TYPE_ID tid)
00227 {
00228   // Do we need the BETYPE stuff?
00229   using namespace ir_a2b;
00230   return MapEnumToStr<MtypeToStr_t, MtypeToNameTbl, 
00231                       MTYPE_LAST+1>("MtypeToNameTbl", tid);
00232 }
00233 
00234 TYPE_ID
00235 Name_To_Mtype (const char* nm) 
00236 {
00237   using namespace ir_a2b;
00238   return MapStrToEnum<MtypeToStr_t, MtypeToNameTbl, 
00239                       MTYPE_LAST+1>("MtypeToNameTbl", nm);
00240 }
00241 
00242 
00243 /* ====================================================================
00244  *
00245  * Mtype_AlignmentClass
00246  *
00247  * Return MTYPE corresponding to alignment(in bytes) and class
00248  *
00249  *      TODO -- this really belongs a matrix (align X class)
00250  * ====================================================================
00251  */
00252 TYPE_ID Mtype_AlignmentClass(INT32 align, mUINT8 type_class)
00253 {
00254   INT32 i;
00255 
00256   for(i=0; i<MTYPE_LAST; i++)
00257   {
00258     if ((MTYPE_type_class(i) == type_class) &&
00259         (MTYPE_align_min(i) == align))
00260       return MTYPE_id(i);
00261   }
00262 
00263   return MTYPE_UNKNOWN; 
00264 }
00265 
00266 
00267 /* ====================================================================
00268  *
00269  * Mtype_Promote_to_A4A8
00270  *
00271  * Convert I4 or U4 to A4, and I8 or U8 to A8; otherwise, do nothing.
00272  *
00273  * ====================================================================
00274  */
00275 TYPE_ID Mtype_Promote_to_A4A8(TYPE_ID x)
00276 {
00277   if (! MTYPE_is_integral(x))
00278     return x;
00279   if (MTYPE_byte_size(x) < 4)
00280     return x;
00281   if (MTYPE_byte_size(x) == 4)
00282     return MTYPE_A4;
00283   return MTYPE_A8;
00284 }
00285 
00286 /* ====================================================================
00287  *
00288  * Mtype_TransferSign
00289  *
00290  * Return signed/unsigned version of y depending on sign of x.
00291  * If either type is A4 or A8, return the A[48] of y.
00292  *
00293  * ====================================================================
00294  */
00295 TYPE_ID Mtype_TransferSign(TYPE_ID x, TYPE_ID y)
00296 {
00297   if (y == MTYPE_A4 || y == MTYPE_A8)
00298     return y;
00299   if (x == MTYPE_A4 || x == MTYPE_A8)
00300     return Mtype_Promote_to_A4A8(y);
00301   if (MTYPE_signed(x) ^ MTYPE_signed(y))
00302   {
00303     return MTYPE_complement(y);
00304   }
00305   return y;
00306 }
00307 
00308 /* ====================================================================
00309  *
00310  * Mtype_TransferSize
00311  *
00312  * Return the mtype version of y taking on the size of x.
00313  * If y is A4 or A8 and x's size is smaller than 4 bytes, return U1 or U2.
00314  *
00315  * ====================================================================
00316  */
00317 TYPE_ID Mtype_TransferSize(TYPE_ID x, TYPE_ID y)
00318 {
00319   if (y == MTYPE_A4 || y == MTYPE_A8) {
00320     switch (MTYPE_byte_size(x)) {
00321     case 1: return MTYPE_U1;
00322     case 2: return MTYPE_U2;
00323     case 4: return MTYPE_A4;
00324     case 8: return MTYPE_A8;
00325     }
00326   }
00327   switch (MTYPE_byte_size(x)) {
00328   case 1: return MTYPE_signed(y) ? MTYPE_I1 : MTYPE_U1;
00329   case 2: return MTYPE_signed(y) ? MTYPE_I2 : MTYPE_U2;
00330   case 4: return MTYPE_signed(y) ? MTYPE_I4 : MTYPE_U4;
00331   case 8: return MTYPE_signed(y) ? MTYPE_I8 : MTYPE_U8;
00332   }
00333   return MTYPE_UNKNOWN;
00334 }
00335 
00336 /* ====================================================================
00337  *
00338  * Mtype_complex_to_real
00339  *
00340  * Return real type corresponding to complex
00341  *
00342  * ====================================================================
00343  */
00344 TYPE_ID Mtype_complex_to_real(TYPE_ID type)
00345 {
00346   if (MTYPE_is_complex(type))
00347   {
00348     switch(type) {
00349     case MTYPE_C4:
00350         return MTYPE_F4;
00351     case MTYPE_C8:
00352         return MTYPE_F8;
00353     case MTYPE_CQ:
00354         return MTYPE_FQ;
00355     }
00356   }
00357   return type;
00358 }
00359 
00360 
00361 
00362 
00363 /* ====================================================================
00364  *
00365  * TYPE_ID  MTYPE_comparison(TYPE_ID)
00366  *
00367  * Return a canonicalized type for a comparison
00368  *
00369  * ====================================================================
00370  */
00371 TYPE_ID  Mtype_comparison(TYPE_ID type)
00372 {
00373   switch(type)
00374   {
00375   case MTYPE_I1:
00376   case MTYPE_I2:
00377     return MTYPE_I4;
00378   case MTYPE_U1:
00379   case MTYPE_U2:
00380     return MTYPE_U4;
00381   default:
00382     return type;
00383   }
00384 }
00385 
00386 
00387 
00388 
00389 /* ====================================================================
00390  *
00391  * TYPE_ID Mtype_next_alignment(TYPE_ID)
00392  *
00393  * Return the next best alignment type (or MTYPE_UNKNOWN)
00394  * This is used to iterate thru types to improve alignment
00395  *
00396  * ====================================================================
00397  */
00398 TYPE_ID Mtype_next_alignment(TYPE_ID type)
00399 {
00400   return Machine_Next_Alignment[type];
00401 }
00402 
00403 
00404 
00405 
00406 /* ====================================================================
00407  *
00408  * TYPE_ID Mtype_prev_alignment(TYPE_ID)
00409  *
00410  * Return the prevevious alignment (or MTYPE_UNKNOWN)
00411  *
00412  * ====================================================================
00413  */
00414 TYPE_ID Mtype_prev_alignment(TYPE_ID type)
00415 {
00416   return Machine_Prev_Alignment[type];
00417 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines