1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
|
/*
* Copyright (c) 1993-2018, NVIDIA CORPORATION. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/** \file
* \brief ILI directive module
*
* Utility routines are valid after the semantic analyzer and after basic
* blocks have been created for a function.
*/
#include "ilidir.h"
#include "gbldefs.h"
#include "global.h"
#include "error.h"
#include "symtab.h"
#include "direct.h"
#if DEBUG
#define TR0(s) \
if (DBGBIT(1, 2048)) \
fprintf(gbl.dbgfil, s);
#define TR1(s, a) \
if (DBGBIT(1, 2048)) \
fprintf(gbl.dbgfil, s, a);
#define TR2(s, a, b) \
if (DBGBIT(1, 2048)) \
fprintf(gbl.dbgfil, s, a, b);
#define TR3(s, a, b, c) \
if (DBGBIT(1, 2048)) \
fprintf(gbl.dbgfil, s, a, b, c);
#else
#define TR0(s)
#define TR1(s, a)
#define TR2(s, a, b)
#define TR3(s, a, b, c)
#endif
static int first; /* beginning loopset index for function; 0 => doesn't
* exist */
static bool opened; /* TRUE if open_pragma found a set which applies to a
* loop */
static int find_lpprg(int);
/** \brief All blocks have been created for a function (called at end of
* expand).
*/
void
ili_lpprg_init(void)
{
int i;
LPPRG *lpprg;
if (direct.lpg.avail <= 1) {
first = 0;
return;
}
first = 1;
TR1("ili_lpprg_init: %s\n", SYMNAME(GBL_CURRFUNC));
for (i = first; i < direct.lpg.avail; i++) {
lpprg = direct.lpg.stgb + i;
if (lpprg->beg_line < 0)
break;
TR3("indx %d, begline %d, endline %d\n", i, lpprg->beg_line,
lpprg->end_line);
}
}
/** \brief Find and open the set of loop pragmas associated with a line number.
*
* SHOULD have a matching close_pragma().
*/
void
open_pragma(int line)
{
int i;
LPPRG *lpprg;
int match;
opened = false;
match = find_lpprg(line);
if (match) {
lpprg = direct.lpg.stgb + match;
TR2(" begline %d, endline %d\n", lpprg->beg_line, lpprg->end_line);
load_dirset(&lpprg->dirset);
opened = true;
#ifdef FE90
direct.indep = lpprg->indep;
direct.index_reuse_list = lpprg->index_reuse_list;
#endif
}
}
/** \brief Close the current pragmas => load the pragmas which have routine
* scope.
*/
void
close_pragma(void)
{
if (opened) {
load_dirset(&direct.rou_begin);
opened = false;
#ifdef FE90
direct.indep = NULL;
direct.index_reuse_list = NULL;
#endif
}
}
#ifdef FE90
void
open_dynpragma(int std, int lineno)
{
int i;
LPPRG *lpprg;
for (i = 1; i < direct.dynlpg.avail; i++) {
lpprg = direct.dynlpg.stgb + i;
if (lpprg->beg_line != std)
continue;
load_dirset(&lpprg->dirset);
direct.indep = lpprg->indep;
direct.index_reuse_list = lpprg->index_reuse_list;
opened = TRUE;
return;
}
open_pragma(lineno);
}
/** \brief Save the current pragma for std. */
void
save_dynpragma(int std)
{
int i;
LPPRG *lpprg;
for (i = 1; i < direct.dynlpg.avail; i++) {
lpprg = direct.dynlpg.stgb + i;
if (lpprg->beg_line != std)
continue;
store_dirset(&lpprg->dirset);
lpprg->indep = direct.indep;
lpprg->index_reuse_list = direct.index_reuse_list;
opened = TRUE; /* so close_pragma will work */
close_pragma();
return;
}
i = direct.dynlpg.avail++;
NEED(direct.dynlpg.avail, direct.dynlpg.stgb, LPPRG, direct.dynlpg.size,
direct.dynlpg.size + 8);
lpprg = direct.dynlpg.stgb + i;
lpprg->beg_line = std;
store_dirset(&lpprg->dirset);
lpprg->indep = direct.indep;
lpprg->index_reuse_list = direct.index_reuse_list;
opened = TRUE; /* so close_pragma will work */
close_pragma();
}
#endif
/** \brief Find the set of loop pragmas associated with a line number (the
* set's beginning and ending line numbers enclose the requested line number).
*
* Since the loop sets occur in lexical order, the last loop set found is the
* set with beginning line number is the floor of the requested line number.
*/
static int
find_lpprg(int line)
{
int i;
LPPRG *lpprg;
int match;
if (first == 0 || line == 0)
return 0;
match = 0;
for (i = first; i < direct.lpg.avail; i++) {
lpprg = direct.lpg.stgb + i;
if (lpprg->beg_line < 0 || lpprg->beg_line > line)
break;
if (lpprg->beg_line <= line && line <= lpprg->end_line)
match = i;
}
TR2("find_lpprg:for line %d, match = %d\n", line, match);
return match;
}
#define STK_SZ 128
static int stk[STK_SZ]; /* should be dynamic ? */
static int top = 0; /* first entry in stack is reserved -- the
* value is zero => use routine's pragmas */
/** \brief Find and open and stack the set of loop pragmas associated with a
* line number.
*
* MUST have a matching pop_pragma(). If a match isn't found, push the
* routine's set.
*/
void
push_pragma(int line)
{
LPPRG *lpprg;
int match;
top++;
if (top >= STK_SZ) {
#if DEBUG
interr("push_pragma:stkovflw", line, ERR_Severe);
#endif
top = STK_SZ - 1;
}
match = find_lpprg(line);
stk[top] = match;
if (match) {
lpprg = direct.lpg.stgb + match;
TR2(" push: begline %d, endline %d\n", lpprg->beg_line, lpprg->end_line);
load_dirset(&lpprg->dirset);
} else {
TR0(" push: using routine\n");
load_dirset(&direct.rou_begin);
}
}
/** \brief Pop the set from the stack and open/restore the set which is on the
* top of stack.
*/
void
pop_pragma(void)
{
LPPRG *lpprg;
int match;
#if DEBUG
if (top <= 0) {
interr("pop_pragma:stkuflw", gbl.lineno, ERR_Severe);
load_dirset(&direct.rou_begin);
return;
}
#endif
top--;
match = stk[top];
if (match) {
lpprg = direct.lpg.stgb + match;
TR1(" pop: using %d\n", match);
load_dirset(&lpprg->dirset);
} else {
TR0(" pop: using routine\n");
load_dirset(&direct.rou_begin);
}
}
|