00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "wn.h"
00025 #include "wn_util.h"
00026 #include "wfe_omp_check_stack.h"
00027 #include <stdlib.h>
00028 #include <stdio.h>
00029 #include <string.h>
00030
00031 extern BOOL Trace_Omp;
00032
00033 namespace {
00034 char dirname[80];
00035 }
00036
00037 static char* WFE_omp_name(WFE_CHECK_KIND kind)
00038 {
00039 switch(kind)
00040 {
00041 case wfe_omp_parallel:
00042 sprintf(dirname,"OMP PARALLEL directive");
00043 break;
00044 case wfe_omp_for:
00045 sprintf(dirname,"OMP FOR directive");
00046 break;
00047 case wfe_omp_single:
00048 sprintf(dirname,"OMP SINGLE directive");
00049 break;
00050 case wfe_omp_sections:
00051 sprintf(dirname,"OMP SECTIONS directive");
00052 break;
00053 case wfe_omp_parallel_sections:
00054 sprintf(dirname,"OMP PARALLEL SECTIONS directive" );
00055 break;
00056 case wfe_omp_parallel_for:
00057 sprintf(dirname,"OMP PARALLEL FOR direcitve");
00058 break;
00059 case wfe_omp_critical:
00060 sprintf(dirname,"OMP CRITICAL directive");
00061 break;
00062 default: sprintf(dirname,"OTHER DIRECTIVES ");
00063 }
00064 return dirname;
00065 }
00066
00067
00068 void WFE_CS_Init()
00069 {
00070 omp_check_size = OMP_CHECK_STACK_SIZE;
00071
00072 omp_check_stack = (CHECK_STMT *) malloc (sizeof (CHECK_STMT) *
00073 omp_check_size );
00074 omp_check_sp = omp_check_stack - 1;
00075
00076 omp_check_last = omp_check_stack + omp_check_size - 1;
00077
00078 omp_check_num = 0;
00079 }
00080
00081
00082 void extern WFE_CS_push( WFE_CHECK_KIND kind, int lnum,int fnum)
00083 {
00084 int new_stack_size;
00085
00086 if (omp_check_sp == omp_check_last)
00087 {
00088 new_stack_size = ENLARGE(omp_check_size);
00089 omp_check_stack =
00090 (CHECK_STMT *) realloc (omp_check_stack, new_stack_size * sizeof(CHECK_STMT));
00091 omp_check_sp=omp_check_stack + omp_check_size - 1;
00092 omp_check_size=new_stack_size;
00093 omp_check_last= omp_check_stack + omp_check_size -1;
00094 }
00095 omp_check_sp++;
00096
00097 bzero (omp_check_sp, sizeof(CHECK_STMT));
00098
00099 omp_check_sp->kind=kind;
00100 omp_check_sp->linenum=lnum;
00101 omp_check_sp->filenum=fnum;
00102
00103 omp_check_num++;
00104
00105 if (Trace_Omp)
00106 printf("Pushing %s ok! Stack now: %d element\n",
00107 WFE_omp_name (omp_check_sp->kind), omp_check_num);
00108 }
00109
00110
00111 extern WFE_CHECK_KIND WFE_CS_pop(WFE_CHECK_KIND kind)
00112 {
00113 FmtAssert (omp_check_sp >= omp_check_stack,
00114 ("no more entries on stack in function WFE_cs_Pop"));
00115
00116 FmtAssert (omp_check_sp->kind == kind,
00117 ("mismatch in statements:expect %d,got %d\n", kind, omp_check_sp->kind ) );
00118
00119 if (Trace_Omp)
00120 printf("Poping %s ok! Stack now: %d element\n",
00121 WFE_omp_name (omp_check_sp->kind), omp_check_num-1);
00122 omp_check_sp--;
00123 omp_check_num--;
00124
00125 return kind;
00126 }
00127
00128
00129 extern CHECK_STMT* WFE_CS_top(void)
00130 {
00131
00132 FmtAssert (omp_check_sp >= omp_check_stack,
00133 ("no more entries on stack in function WFE_CS_Top"));
00134
00135 return omp_check_sp;
00136 }
00137
00138
00139 extern CHECK_STMT *WFE_CS_enclose(void)
00140 {
00141 FmtAssert (omp_check_sp-1 >= omp_check_stack,
00142 ("no entry on stack in function WFE_CS_enclose"));
00143 return omp_check_sp-1;
00144 }
00145
00146
00147 extern void WFE_Set_Prag(WN* omp_prag)
00148 {
00149 FmtAssert (omp_check_sp >= omp_check_stack,
00150 ("no entry on stack in function WFE_Set_Prag"));
00151 omp_check_sp->wn_prag=omp_prag;
00152 }
00153
00154
00155 extern void WFE_Set_Nameflag(char* name)
00156 {
00157 FmtAssert (omp_check_sp >= omp_check_stack,
00158 ("no entry on stack in function WFE_Set_Intflag"));
00159 omp_check_sp->name=name;
00160
00161 }
00162
00163
00164 extern void WFE_Set_Cflag(WFE_CLAUSE_KIND flag)
00165 {
00166 FmtAssert (omp_check_sp >= omp_check_stack,
00167 ("no entriy on stack in function WFE_Set_Cflag"));
00168
00169 omp_check_sp->cflag |=flag;
00170 }
00171
00172
00173 extern void WFE_Set_LFnum(CHECK_STMT* cs,int lnum,int fnum)
00174 {
00175
00176 FmtAssert (omp_check_sp >= omp_check_stack,
00177 ("no entriy on stack in function WFE_Set_LFnum"));
00178
00179 cs->linenum=lnum;
00180 cs->filenum=fnum;
00181 }
00182
00183
00184 extern void WFE_Set_Region (WN * region)
00185 {
00186 FmtAssert (omp_check_sp >= omp_check_stack,
00187 ("no entry on stack in function WFE_Set_Region"));
00188 omp_check_sp->region = region;
00189 }
00190
00191
00192 extern bool WFE_Check_Cflag(CHECK_STMT* cs, WFE_CLAUSE_KIND flag)
00193 {
00194 if(flag & cs->cflag)
00195 return true;
00196 else return false;
00197 }
00198
00199
00200 extern int WFE_CS_Find(WFE_CHECK_KIND kind)
00201 {
00202 int count=0;
00203 CHECK_STMT *temp;
00204
00205 for(temp=omp_check_sp;temp>=omp_check_stack;temp--)
00206 {
00207 count++;
00208 if (temp->kind == kind)
00209 return (omp_check_num - count);
00210 }
00211 return -1;
00212 }
00213
00214
00215 extern CHECK_STMT* WFE_CS_Find_Rtn(WFE_CHECK_KIND kind)
00216 {
00217 CHECK_STMT* temp;
00218 int i;
00219
00220 for(temp=omp_check_sp;temp>=omp_check_stack;temp--)
00221 {
00222 if(temp->kind == kind)
00223 return temp;
00224 }
00225 return NULL;
00226 }
00227
00228
00229 extern int WFE_CS_Find_depth(WFE_CHECK_KIND kind,int depth)
00230 {
00231 int count=0;
00232 int find=0, rval=-1;
00233 CHECK_STMT* temp;
00234
00235 for(temp=omp_check_sp;temp>=omp_check_stack;temp--)
00236 {
00237 count++;
00238 if(temp->kind == kind)
00239 {
00240 rval=omp_check_num - count;
00241 find++;
00242 }
00243 if (find == depth)
00244 return rval;
00245 }
00246 return -1;;
00247 }
00248
00249
00250 extern int WFE_CS_Find_Cflag(WFE_CHECK_KIND kind,WFE_CLAUSE_KIND flag)
00251 {
00252 int rval=-1,count=0;
00253 CHECK_STMT* temp;
00254
00255 for(temp=omp_check_sp;temp>=omp_check_stack;temp--)
00256 {
00257 count++;
00258 if(temp->kind==kind&&(temp->cflag&flag))
00259 {
00260 rval=omp_check_num-count;
00261 break;
00262 }
00263 }
00264
00265 return rval;
00266 }
00267
00268
00269 extern int WFE_CS_Find_fgname(WFE_CHECK_KIND kind ,char* name)
00270 {
00271
00272 int rval=-1, count=0;
00273 CHECK_STMT* temp;
00274
00275 for(temp=omp_check_sp;temp>=omp_check_stack;temp--)
00276 {
00277 count++;
00278 if(temp->kind == kind && temp->name && !strcmp(temp->name, name))
00279 {
00280 rval=omp_check_num-count;
00281 break;
00282 }
00283 }
00284
00285 return rval;
00286
00287 }
00288
00289
00290 extern bool WFE_is_top(WFE_CHECK_KIND kind)
00291 {
00292 if(omp_check_sp->kind==kind)
00293 return true;
00294 else return false;
00295 }
00296
00297
00298 extern bool WFE_is_top_next(WFE_CHECK_KIND kind)
00299 {
00300 if((omp_check_sp-1)->kind==kind)
00301 return true;
00302 else return false;
00303 }
00304
00305
00306 extern bool WFE_bind_to_same(WFE_CHECK_KIND sub1,WFE_CHECK_KIND sub2,WFE_CHECK_KIND bind)
00307 {
00308 int i;
00309 bool rval=false;
00310 int find1=-1,find2=-1,find3=-1,tmp=-1;
00311
00312 find1=WFE_CS_Find(sub1);
00313 find2=WFE_CS_Find(sub2);
00314 find3=WFE_CS_Find(bind);
00315
00316 if(find1<0||find2<0||find3<0)
00317 rval=false;
00318 else if(find1==find2)
00319 {
00320 if(WFE_CS_Find_depth(sub1,2)>-1)
00321 {
00322 tmp=WFE_CS_Find_depth(sub1,2);
00323 if(find3<find2&&find3<tmp)
00324 rval=true;
00325 }
00326 else rval=false;
00327 }
00328
00329 else if(find3<find1&&find3<find2)
00330 {
00331 rval=true;
00332 }
00333 else rval=false;
00334
00335 return rval;
00336
00337 }
00338
00339 extern void WFE_add_pragma_to_enclosing_regions (WN_PRAGMA_ID id, ST * st)
00340 {
00341 WN_VECTOR regions;
00342
00343 for (CHECK_STMT * iter = omp_check_sp;
00344 iter >= omp_check_stack; iter--)
00345 {
00346 WN * reg = iter->region;
00347 if (reg && WN_operator (reg) == OPR_REGION &&
00348 WN_region_kind(reg) == REGION_KIND_MP)
00349 regions.insert (regions.end(), reg);
00350 }
00351
00352
00353 Add_Pragma_To_MP_Regions (®ions, id, st, 0, 0, TRUE);
00354 }
00355