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