1 /* 2 * Copyright (c) 1993-2018, NVIDIA CORPORATION. All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 18 #ifndef NME_H_ 19 #define NME_H_ 20 21 #include "gbldefs.h" 22 #include "symtab.h" 23 24 /** \file 25 * \brief NME data structures and definitions 26 */ 27 28 typedef enum NT_KIND { 29 NT_INDARR = 30 -2, /* for C/C++, only used by expand; element of a pointer deref */ 31 NT_ADD = -1, 32 NT_UNK = 0, /* Unknown ref. e.g. *(f()) */ 33 NT_IND = 1, /* Indirect ref e.g. *p */ 34 NT_VAR = 2, /* Variable ref. (struct, array or scalar) */ 35 NT_MEM = 3, /* Structure member ref. */ 36 NT_ARR = 4, /* Array element ref. */ 37 NT_SAFE = 5 /* special names; does not conflict with preceding refs */ 38 } NT_KIND; 39 40 typedef struct { 41 NT_KIND type : 8; 42 bool inlarr; /**< true iff an inlined array ref */ 43 char pd1; 44 char pd2; 45 int stl; /* STL item pointer: rsvd for invariant */ 46 int hshlnk; /* link of names w/ identical hash val */ 47 int nm; /* Dependent on type. */ 48 SPTR sym; /* Dependent on type. */ 49 int rfptr; /* Dependent on type. */ 50 int exp_loop; /* Dependent on type. */ 51 int f6; /* Dependent on type. */ 52 ISZ_T cnst; /* Dependent on type. */ 53 int sub; /* subscript info (0 if NA or not array) */ 54 int f13; /* dependent on type */ 55 int base; /* base nme */ 56 int pte; /* pointer target entry (pte) index */ 57 int rpct_loop; /* If >0, the index of a loop which is guarded by 58 * runtime pointer conflict tests (RPCTs). 59 * The nme is only used within this loop. */ 60 union { 61 struct { 62 unsigned ovs : 1; /* over-subscripted -- more subscripts than rank; can 63 * occur when inlining 64 */ 65 } bits; 66 UINT16 all; /* important flags */ 67 } flags; 68 union { 69 struct { 70 unsigned m1 : 1; 71 unsigned m2 : 1; 72 unsigned m3 : 1; 73 unsigned m4 : 1; 74 unsigned m5 : 1; 75 unsigned m6 : 1; 76 unsigned m7 : 1; 77 unsigned m8 : 1; 78 } attr; 79 UINT16 all; 80 } mask; /* temporary attribute bits */ 81 } NME; 82 83 typedef struct { 84 int next; /* next pointer target */ 85 int type; /* pointer target type */ 86 SPTR sym; /* type-specific value */ 87 int val; /* type-specific value */ 88 int hshlnk; /* link of PTE with name hash val */ 89 } PTE; 90 91 /* RPCT (runtime pointer conflict test) struct: 92 * The NMEs 'nme1' and 'nme2' in an RPCT record are "RPCT NMEs" that 93 * are created by 'add_rpct_nme()', and the RPCT record itself is 94 * created by 'add_rpct( nme1, nme2 )'. The existence of such a 95 * record indicates that the generated code contains a test which 96 * proves at runtime that this pair of references do not conflict, so 97 * 'conflict( nme1, nme2 )' will return NOCONFLICT. 98 */ 99 typedef struct { 100 int nme1; 101 int nme2; 102 int hshlnk; 103 } RPCT; 104 105 typedef struct { 106 STG_MEMBERS(NME); 107 STG_DECLARE(pte, PTE); 108 STG_DECLARE(rpct, RPCT); 109 } NMEB; 110 111 #define NME_LAST nmeb.stg_avail 112 #define PTE_LAST nmeb.pte.stg_avail 113 #define RPCT_LAST nmeb.rpct.stg_avail 114 115 #if DEBUG 116 #define NMECHECK(i) \ 117 (((i) < 0 || (i) >= nmeb.stg_avail) ? (interr("bad nme index", i, ERR_Severe), i) \ 118 : (i)) 119 #else 120 #define NMECHECK(i) i 121 #endif 122 #define NME_TYPE(i) nmeb.stg_base[NMECHECK(i)].type 123 #define NME_INLARR(i) nmeb.stg_base[NMECHECK(i)].inlarr 124 #define NME_SYM(i) nmeb.stg_base[NMECHECK(i)].sym 125 #define NME_NM(i) nmeb.stg_base[NMECHECK(i)].nm 126 #define NME_HSHLNK(i) nmeb.stg_base[NMECHECK(i)].hshlnk 127 #define NME_RFPTR(i) nmeb.stg_base[NMECHECK(i)].rfptr 128 #define NME_ELOOP(i) nmeb.stg_base[NMECHECK(i)].exp_loop 129 #define NME_RAT(i) nmeb.stg_base[NMECHECK(i)].rfptr 130 #define NME_DEF(i) nmeb.stg_base[NMECHECK(i)].f6 131 #define NME_CNST(i) nmeb.stg_base[NMECHECK(i)].cnst 132 #define NME_SUB(i) nmeb.stg_base[NMECHECK(i)].sub 133 #define NME_STL(i) nmeb.stg_base[NMECHECK(i)].stl 134 #define NME_CNT(i) nmeb.stg_base[NMECHECK(i)].f13 135 #define NME_USES(i) nmeb.stg_base[NMECHECK(i)].f13 136 #define NME_BASE(i) nmeb.stg_base[NMECHECK(i)].base 137 #define NME_PTE(i) nmeb.stg_base[NMECHECK(i)].pte 138 #define NME_RPCT_LOOP(i) nmeb.stg_base[NMECHECK(i)].rpct_loop 139 140 #define NME_FLAGS(i) nmeb.stg_base[NMECHECK(i)].flags.all 141 #define NME_OVS(i) nmeb.stg_base[NMECHECK(i)].flags.bits.ovs 142 #define NME_TEMP(i) nmeb.stg_base[NMECHECK(i)].mask.attr.m1 143 #define NME_MASK(i) nmeb.stg_base[NMECHECK(i)].mask.all 144 145 /* 146 * The following two special names entries are referenced during 147 * expansion. addnme never sees NME_VOL. 148 */ 149 #define NME_UNK 0 150 #define NME_VOL 1 151 152 /* Some files check if NT_INDARR is defined. */ 153 #define NT_INDARR NT_INDARR 154 155 /* 156 * Zero means unknown PTE information 157 * may be used as PTE index or PTE type. 158 */ 159 160 #define PT_UNK 0 161 #define PTE_UNK 0 162 #define PTE_END -1 163 164 /* 165 * PSYM: precise symbol 166 * ISYM: imprecise symbol 167 * ANON: anonymous variable 168 * GDYN: dynamically allocated memory 169 * LDYN: dynamically allocated memory allocated during this function call 170 * NLOC: any nonlocal memory (from calling environment) 171 */ 172 #define PT_PSYM 1 173 #define PT_ISYM 2 174 #define PT_ANON 3 175 #define PT_GDYN 4 176 #define PT_LDYN 5 177 #define PT_NLOC 6 178 179 #if DEBUG 180 #define PTECHECK(i) \ 181 (((i) < 0 || (i) >= nmeb.pte.stg_avail) \ 182 ? (interr("bad pte index", i, ERR_Severe), i, i) \ 183 : (i)) 184 #else 185 #define PTECHECK(i) i 186 #endif 187 #define PTE_NEXT(i) nmeb.pte.stg_base[PTECHECK(i)].next 188 #define PTE_TYPE(i) nmeb.pte.stg_base[PTECHECK(i)].type 189 #define PTE_SPTR(i) nmeb.pte.stg_base[PTECHECK(i)].sym 190 #define PTE_VAL(i) nmeb.pte.stg_base[PTECHECK(i)].val 191 #define PTE_HSHLNK(i) nmeb.pte.stg_base[PTECHECK(i)].hshlnk 192 193 #if DEBUG 194 #define RPCT_CHECK(i) \ 195 (((i) < 1 || (i) >= nmeb.rpct.stg_avail) \ 196 ? (interr("bad rpct index", i, ERR_Severe), i) \ 197 : (i)) 198 #else 199 #define RPCT_CHECK(i) i 200 #endif 201 #define RPCT_NME1(i) nmeb.rpct.stg_base[RPCT_CHECK(i)].nme1 202 #define RPCT_NME2(i) nmeb.rpct.stg_base[RPCT_CHECK(i)].nme2 203 #define RPCT_HSHLNK(i) nmeb.rpct.stg_base[RPCT_CHECK(i)].hshlnk 204 205 #ifndef FE90 206 #define SAME -1 207 #define NOCONFLICT 0 208 #define CONFLICT 1 209 #define UNKCONFLICT 2 210 #endif 211 212 /***** External Data Declarations *****/ 213 214 extern NMEB nmeb; 215 216 #include "nmeutil.h" 217 218 #endif // NME_H_ 219