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
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #define __STDC_LIMIT_MACROS
00043 #include <stdint.h>
00044 #include "anl_common.h"
00045 #include "anl_diagnostics.h"
00046 #include "anl_file_mngr.h"
00047 #include "w2cf_translator.h"
00048 #include "anl_varlist.h"
00049 #include "anl_pragma_attribute.h"
00050 #include "anl_loop_construct.h"
00051 #include "anl_pragma_construct.h"
00052 #include "anl_region_construct.h"
00053 #include "anl_func_entry.h"
00054
00055 extern ANL_DIAGNOSTICS *Anl_Diag;
00056 extern BOOL Anl_Owhile;
00057
00058
00059
00060
00061
00062 void
00063 Adjust_Srcpos_Range(WN *stmt,
00064 ANL_SRCPOS *min,
00065 ANL_SRCPOS *max)
00066 {
00067 WN_ITER *stmt_iter;
00068
00069
00070
00071
00072
00073 for (stmt_iter = WN_WALK_StmtIter(stmt);
00074 stmt_iter != NULL;
00075 stmt_iter = WN_WALK_StmtNext(stmt_iter))
00076 {
00077 ANL_SRCPOS srcpos(WN_ITER_wn(stmt_iter));
00078
00079 if (srcpos > *max)
00080 *max = srcpos;
00081 else if (srcpos < *min)
00082 *min = srcpos;
00083 }
00084 }
00085
00086
00087
00088
00089
00090 void
00091 ANL_FUNC_ENTRY::_Push_Construct_Level(ANL_CBUF *cbuf)
00092 {
00093 _construct_level++;
00094 if (_construct_level == 1)
00095 cbuf->Write_Char('\n');
00096 }
00097
00098
00099 void
00100 ANL_FUNC_ENTRY::_Pop_Construct_Level()
00101 {
00102 _construct_level--;
00103 }
00104
00105
00106
00107
00108
00109 ANL_FUNC_ENTRY::~ANL_FUNC_ENTRY()
00110 {
00111 for (INT i = _dir_entries.Size()-1; i >= 0; i--)
00112 CXX_DELETE(_dir_entries.Indexed_Get(i), _pool);
00113 }
00114
00115
00116 void
00117 ANL_FUNC_ENTRY::Get_Pragma_Srcpos_Range(WN *apragma,
00118 ANL_SRCPOS *min,
00119 ANL_SRCPOS *max)
00120 {
00121 ANL_SRCPOS pos(apragma);
00122 WN_PRAGMA_ID id = (WN_PRAGMA_ID)WN_pragma(apragma);
00123 WN *next = WN_next(apragma);
00124 INT32 num_dims;
00125
00126 *min = pos;
00127 *max = pos;
00128
00129 switch (id)
00130 {
00131 case WN_PRAGMA_PREFETCH_REF:
00132 case WN_PRAGMA_DYNAMIC:
00133 case WN_PRAGMA_COPYIN:
00134 case WN_PRAGMA_NUMTHREADS:
00135 case WN_PRAGMA_PAGE_PLACE:
00136 case WN_PRAGMA_KAP_CONCURRENTIZE:
00137 case WN_PRAGMA_KAP_NOCONCURRENTIZE:
00138 case WN_PRAGMA_KAP_ASSERT_PERMUTATION:
00139 case WN_PRAGMA_CRI_CNCALL:
00140 case WN_PRAGMA_KAP_ASSERT_CONCURRENT_CALL:
00141 case WN_PRAGMA_KAP_ASSERT_DO:
00142 case WN_PRAGMA_KAP_ASSERT_DOPREFER:
00143 case WN_PRAGMA_IVDEP:
00144 while (next != NULL &&
00145 (WN_operator(next) == OPR_XPRAGMA ||
00146 WN_operator(next) == OPR_PRAGMA) &&
00147 WN_pragma(next) == id &&
00148 ANL_SRCPOS(next).Linenum() == pos.Linenum())
00149 {
00150 ANL_SRCPOS srcpos(next);
00151 if (srcpos > *max)
00152 *max = srcpos;
00153 next = WN_next(next);
00154 }
00155 break;
00156 case WN_PRAGMA_DISTRIBUTE:
00157 case WN_PRAGMA_REDISTRIBUTE:
00158 case WN_PRAGMA_DISTRIBUTE_RESHAPE:
00159 for (num_dims = 1;
00160 (next != NULL &&
00161 WN_operator(next) == OPR_PRAGMA &&
00162 WN_pragma(next) == id &&
00163 num_dims == WN_pragma_index(next));
00164 num_dims++, next = WN_next(next))
00165 {
00166 ANL_SRCPOS srcpos(next);
00167 if (srcpos > *max)
00168 *max = srcpos;
00169 }
00170
00171
00172
00173
00174 if (WN_operator(next)==OPR_STID &&
00175 ST_class(WN_st(next))==CLASS_PREG)
00176 {
00177 next = WN_next(next);
00178 if (WN_operator(next)==OPR_STID &&
00179 ST_class(WN_st(next))==CLASS_PREG)
00180 next = WN_next(next);
00181 }
00182 break;
00183 default:
00184 break;
00185 }
00186 while (_w2cf->Is_A_Pragma_Clause(next))
00187 {
00188 if (!WN_pragma_compiler_generated(next))
00189 {
00190 ANL_SRCPOS srcpos(next);
00191 if (srcpos > *max)
00192 *max = srcpos;
00193 }
00194 next = WN_next(next);
00195 }
00196 }
00197
00198
00199 void
00200 ANL_FUNC_ENTRY::Set_Construct_Id(WN *construct, INT64 id)
00201 {
00202 if (id > INT32_MAX)
00203 Anl_Diag->Error("Too many constructs for PROMPF!!");
00204 else
00205 WN_MAP32_Set(_id_map, construct, id);
00206 }
00207
00208
00209 void
00210 ANL_FUNC_ENTRY::Emit_Nested_Original_Constructs(ANL_CBUF *cbuf,
00211 WN *from_stmt,
00212 WN *to_stmt)
00213 {
00214
00215
00216
00217
00218 BOOL flag;
00219 ANL_PRAGMA_ATTRIBUTE *dir_attribute = NULL;
00220 ANL_PRAGMA_CONSTRUCT *pragma_construct = NULL;
00221 ANL_REGION_CONSTRUCT *region_construct = NULL;
00222 ANL_LOOP_CONSTRUCT *loop_construct = NULL;
00223 WN *stmt = from_stmt;
00224
00225 while (stmt != NULL && stmt != WN_next(to_stmt))
00226 {
00227 switch (WN_operator(stmt))
00228 {
00229 case OPR_IF:
00230 Emit_Nested_Original_Constructs(cbuf,
00231 WN_kid1(stmt),
00232 WN_kid1(stmt));
00233 Emit_Nested_Original_Constructs(cbuf,
00234 WN_kid2(stmt),
00235 WN_kid2(stmt));
00236 stmt = WN_next(stmt);
00237 break;
00238
00239 case OPR_BLOCK:
00240 Emit_Nested_Original_Constructs(cbuf,
00241 WN_first(stmt),
00242 WN_last(stmt));
00243 stmt = WN_next(stmt);
00244 break;
00245
00246 case OPR_XPRAGMA:
00247 case OPR_PRAGMA:
00248 if (ANL_PRAGMA_CONSTRUCT::Is_ProMpf_Pragma_Construct(stmt))
00249 {
00250 _Push_Construct_Level(cbuf);
00251 pragma_construct =
00252 CXX_NEW(ANL_PRAGMA_CONSTRUCT(stmt,
00253 _construct_level,
00254 this,
00255 _pool), _pool);
00256 pragma_construct->Write(cbuf);
00257 stmt = pragma_construct->Next_Stmt();
00258 CXX_DELETE(pragma_construct, _pool);
00259 _Pop_Construct_Level();
00260 }
00261 else if (ANL_PRAGMA_ATTRIBUTE::Is_ProMpf_Pragma_Attribute(stmt))
00262 {
00263 dir_attribute =
00264 CXX_NEW(ANL_PRAGMA_ATTRIBUTE(stmt,
00265 _construct_level,
00266 this,
00267 _pool), _pool);
00268 _dir_entries.Insert_Last(dir_attribute, &flag);
00269 stmt = dir_attribute->Next_Stmt();
00270 }
00271 else
00272 stmt = WN_next(stmt);
00273 break;
00274
00275 case OPR_REGION:
00276 if (ANL_REGION_CONSTRUCT::Is_ProMpf_Region_Construct(stmt))
00277 {
00278 _Push_Construct_Level(cbuf);
00279 region_construct =
00280 CXX_NEW(ANL_REGION_CONSTRUCT(stmt,
00281 _construct_level,
00282 this,
00283 _pool), _pool);
00284 region_construct->Write(cbuf);
00285 stmt = region_construct->Next_Stmt();
00286 CXX_DELETE(region_construct, _pool);
00287 _Pop_Construct_Level();
00288 }
00289 else
00290 {
00291 Emit_Nested_Original_Constructs(cbuf,
00292 WN_first(WN_region_body(stmt)),
00293 WN_last(WN_region_body(stmt)));
00294 stmt = WN_next(stmt);
00295 }
00296 break;
00297
00298 case OPR_DO_WHILE:
00299 case OPR_WHILE_DO:
00300 if (Anl_Owhile)
00301 {
00302
00303
00304 _Push_Construct_Level(cbuf);
00305 loop_construct =
00306 CXX_NEW(ANL_LOOP_CONSTRUCT(stmt,
00307 _construct_level,
00308 this,
00309 _pool), _pool);
00310 loop_construct->Write(cbuf);
00311 stmt = loop_construct->Next_Stmt();
00312 CXX_DELETE(loop_construct, _pool);
00313 _Pop_Construct_Level();
00314 }
00315 else
00316 {
00317
00318
00319 Emit_Nested_Original_Constructs(cbuf,
00320 WN_kid1(stmt),
00321 WN_kid1(stmt));
00322 stmt = WN_next(stmt);
00323 }
00324 break;
00325
00326 case OPR_DO_LOOP:
00327 _Push_Construct_Level(cbuf);
00328 loop_construct =
00329 CXX_NEW(ANL_LOOP_CONSTRUCT(stmt,
00330 _construct_level,
00331 this,
00332 _pool), _pool);
00333 loop_construct->Write(cbuf);
00334 stmt = loop_construct->Next_Stmt();
00335 CXX_DELETE(loop_construct, _pool);
00336 _Pop_Construct_Level();
00337 break;
00338
00339 default:
00340 stmt = WN_next(stmt);
00341 break;
00342 }
00343 }
00344 }
00345
00346
00347 void
00348 ANL_FUNC_ENTRY::Emit_Dir_Entries(ANL_CBUF *cbuf,
00349 INT64 for_construct_id,
00350 INT32 for_construct_level,
00351 BOOL (*do_emit)(ANL_PRAGMA_ATTRIBUTE *dir,
00352 INT32 construct_level))
00353 {
00354 for (INT i = _dir_entries.Size() - 1; i >= 0; i--)
00355 {
00356 ANL_PRAGMA_ATTRIBUTE *dir = _dir_entries.Indexed_Get(i);
00357
00358 if (do_emit(dir, for_construct_level))
00359 {
00360 dir->Write(cbuf, for_construct_id);
00361 _dir_entries.Indexed_Remove(i);
00362 CXX_DELETE(dir, _pool);
00363 }
00364 }
00365 }
00366
00367
00368 void
00369 ANL_FUNC_ENTRY::Emit_Original_Construct(ANL_FILE_MNGR *outp_file)
00370 {
00371 const INT64 id = _next_id->Post_Incr();
00372 ANL_CBUF cbuf(_pool);
00373 ANL_CBUF varlist_cbuf(_pool);
00374 ANL_CBUF nested_cbuf(_pool);
00375 ANL_SRCPOS min_srcpos(_pu);
00376 ANL_SRCPOS max_srcpos(_pu);
00377 ANL_VARLIST varlist(_pool, this);
00378
00379 Set_Construct_Id(_pu, id);
00380
00381
00382
00383 Adjust_Srcpos_Range(_pu, &min_srcpos, &max_srcpos);
00384 cbuf.Write_String("function ");
00385 cbuf.Write_Int(id);
00386 cbuf.Write_String(" \"");
00387 _w2cf->Original_Symname_To_String(&cbuf, &St_Table[WN_entry_name(_pu)]);
00388 cbuf.Write_String("\" range ");
00389 min_srcpos.Write(&cbuf);
00390 cbuf.Write_Char('-');
00391 max_srcpos.Write(&cbuf);
00392 cbuf.Write_Char('\n');
00393 outp_file->Write_String(cbuf.Chars());
00394
00395
00396
00397
00398 varlist.Insert_Var_Refs(WN_func_body(_pu));
00399 varlist.Write(&varlist_cbuf, id);
00400 varlist_cbuf.Write_Char('\n');
00401
00402
00403
00404 Emit_Nested_Original_Constructs(&nested_cbuf,
00405 WN_first(WN_func_body(_pu)),
00406 WN_last(WN_func_body(_pu)));
00407
00408
00409
00410
00411 cbuf.Reset();
00412 for (INT i = _dir_entries.Size()-1; i >= 0; i--)
00413 {
00414 ANL_PRAGMA_ATTRIBUTE *dir = _dir_entries.Indexed_Get(i);
00415 dir->Write(&cbuf, id);
00416 _dir_entries.Indexed_Remove(i);
00417 CXX_DELETE(dir, _pool);
00418 }
00419
00420
00421
00422 if (cbuf.Size() > 0)
00423 outp_file->Write_String(cbuf.Chars());
00424 if (varlist_cbuf.Size() > 0)
00425 outp_file->Write_String(varlist_cbuf.Chars());
00426 if (nested_cbuf.Size() > 0)
00427 outp_file->Write_String(nested_cbuf.Chars());
00428
00429
00430
00431 cbuf.Reset();
00432 cbuf.Write_String("end_function ");
00433 cbuf.Write_Int(id);
00434 cbuf.Write_String("\n\n\n");
00435 outp_file->Write_String(cbuf.Chars());
00436
00437 }