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
00326 #ifndef snl_utils_INCLUDED
00327 #define snl_utils_INCLUDED "snl_utils.h"
00328
00329 #ifdef _KEEP_RCS_ID
00330 static char *snl_utils_rcs_id = snl_utils_INCLUDED "$Revision$";
00331 #endif
00332
00333 #ifndef mat_INCLUDED
00334 #include "mat.h"
00335 #endif
00336
00337 #ifndef snl_xbounds_INCLUDED
00338 #include "snl_xbounds.h"
00339 #endif
00340
00341
00342
00343
00344
00345 extern BOOL Is_Lexpos(DEPV*, INT dims);
00346 extern BOOL Is_Lexpos(DEPV_ARRAY*);
00347 extern MEM_POOL SNL_local_pool;
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357 #define UCTILE_T 0x1
00358 #define UCTILE_I 0x2
00359 #define UCTILE_O 0x4
00360
00361 struct SNL_REGION {
00362 WN* First;
00363 WN* Last;
00364 SNL_REGION(WN* f, WN* l) : First(f), Last(l) {}
00365 SNL_REGION() : First(NULL), Last(NULL) {}
00366 BOOL operator == (SNL_REGION r) const
00367 {return First == r.First && Last == r.Last;}
00368 BOOL operator != (SNL_REGION r) const
00369 {return First != r.First || Last != r.Last;}
00370 };
00371
00372 enum SNL_INV_CACHE_BLOCK_REASON {
00373 SNL_INV_UNDEFINED,
00374 SNL_INV_TILE_ONLY,
00375 SNL_INV_SE_ONLY,
00376 SNL_INV_TILE_SE,
00377 SNL_INV_LEGO_TILE,
00378 SNL_INV_MP_TILE,
00379 SNL_INV_DOACROSS_TILE
00380 };
00381
00382 #define SNL_MAX_LOOPS LNO_MAX_DO_LOOP_DEPTH
00383
00384 class SNL_TILE_INFO {
00385
00386 public:
00387
00388 SNL_TILE_INFO(WN** loop, const IMAT& L,
00389 const INT* striplevel, MEM_POOL* pool);
00390
00391 SNL_TILE_INFO(INT nloops, INT strips,
00392 const INT* iloop, const INT* stripsz, const INT* striplevel,
00393 SNL_INV_CACHE_BLOCK_REASON reason[], MEM_POOL* pool);
00394
00395 ~SNL_TILE_INFO() {}
00396
00397 MEM_POOL* Pool() const {return _pool;}
00398 BOOL Rectangular() const {return _rectangular;}
00399 void Print(FILE*) const;
00400 const IMAT& L() const {return _l;}
00401 const IMAT& KHT() const {return _kht;}
00402 INT K() const {return _k;}
00403 INT Striplevel(INT i) const {return _striplevel[i];}
00404
00405
00406
00407 INT Iloop(INT i) const {return _iloop[i];}
00408 INT Stripsz(INT i) const {return _stripsz[i];}
00409 INT Nloops() const {return _l.Rows();}
00410 INT Strips() const {return _l.Cols();}
00411 SNL_INV_CACHE_BLOCK_REASON Reason(INT i) const {return _reason[i];}
00412
00413 private:
00414
00415
00416
00417 SNL_TILE_INFO();
00418 SNL_TILE_INFO& operator = (SNL_TILE_INFO&);
00419 SNL_TILE_INFO(const SNL_TILE_INFO&);
00420
00421 MEM_POOL* _pool;
00422 BOOL _rectangular;
00423
00424 IMAT _l;
00425 IMAT _kht;
00426 INT _k;
00427 INT _striplevel[SNL_MAX_LOOPS];
00428
00429
00430
00431 INT _iloop[SNL_MAX_LOOPS];
00432 INT _stripsz[SNL_MAX_LOOPS];
00433 SNL_INV_CACHE_BLOCK_REASON _reason[SNL_MAX_LOOPS];
00434 };
00435
00436
00437
00438
00439
00440
00441
00442
00443 class SNL_TRANS_INDEX_DATA {
00444
00445 public:
00446
00447 struct TDATA {
00448 SYMBOL symbol;
00449 WN* alias_wn;
00450
00451 };
00452 struct IDATA {
00453 SYMBOL pre_symbol;
00454 WN* pre_alias_wn;
00455
00456 SYMBOL post_symbol;
00457 WN* post_alias_wn;
00458 WN* newcode;
00459 INT max_used_depth;
00460 WN* lbtest;
00461 WN* ubtest;
00462
00463 };
00464 struct ODATA {
00465 SYMBOL symbol;
00466 WN* alias_wn;
00467
00468 };
00469
00470 public:
00471
00472 SNL_TRANS_INDEX_DATA(const IMAT* u, const IMAT* uinv,
00473 const IMAT* kht, const SNL_BOUNDS_INFO* bi,
00474 DOLOOP_STACK* stack, INT first_in_stack,
00475 SNL_TILE_INFO* ti, MEM_POOL* p);
00476 ~SNL_TRANS_INDEX_DATA();
00477
00478 public:
00479
00480 INT t_nloops;
00481 INT i_nloops;
00482 INT o_nloops;
00483
00484 TDATA* tdata;
00485 IDATA* idata;
00486 ODATA* odata;
00487
00488 MEM_POOL* pool;
00489
00490 void Print(FILE*) const;
00491 };
00492
00493 extern void SNL_Sanity_Check_Func(WN* wn);
00494
00495 #ifdef Is_True_On
00496 extern void SNL_Sanity_Check_Block(WN* wn);
00497 extern void SNL_Sanity_Check_Loop(WN* wn);
00498 extern void SNL_Sanity_Check_If(WN* wn);
00499 extern void SNL_Sanity_Check_Region(SNL_REGION region);
00500 extern WN* SNL_Sanity_Check_Exp(WN* wn);
00501 #endif
00502
00503
00504
00505
00506 enum SNL_MONO {
00507 SNL_MONO_INVARIANT,
00508 SNL_MONO_INC,
00509 SNL_MONO_DEC,
00510 SNL_MONO_OTHER
00511 };
00512
00513 extern SNL_MONO Mono(WN* wn, SYMBOL symbol, BOOL neg =FALSE);
00514 void Print_Do_Stack(FILE* f, const DOLOOP_STACK *);
00515
00516
00517
00518
00519
00520 class DEF_LIST;
00521
00522 extern void Increase_By(WN* wn, INT c, WN* parent =NULL, INT kid = -1);
00523
00524 extern WN* LWN_Create_Block_From_Stmts_Above(WN* wn);
00525 extern WN* LWN_Create_Block_From_Stmts_Below(WN* wn);
00526 extern INT64 Iterations(WN* loop, MEM_POOL* pool);
00527 extern WN* Find_Next_Innermost_Do(WN* loop);
00528 extern DOLOOP_STACK* Copy_Dostack(const DOLOOP_STACK& stack, MEM_POOL*);
00529
00530 extern MEM_POOL SNL_local_pool;
00531 extern INT Renumber_Loops(WN* first, WN* last, ARRAY_DIRECTED_GRAPH16* =NULL);
00532
00533 extern void Dump_WN(SNL_REGION, FILE*, INT,
00534 INT = 2, INT = 2, WN** = NULL, WN* = NULL,
00535 ARRAY_DIRECTED_GRAPH16* =NULL);
00536
00537 extern void SNL_Add_Du_To_Index_Ldid(WN* loop, WN* ldid, DU_MANAGER*, BOOL);
00538 extern void SNL_Change_Du_To_Index_Ldid(WN* loop, WN* code, DU_MANAGER*, BOOL);
00539 extern void SNL_Change_Du_Pointer(WN* oldptr, WN* ptr, WN* body, DU_MANAGER*);
00540 extern void SNL_Print_Ldid_Pointers(WN* wn);
00541
00542 const DEF_LIST* Find_Def_List_In_Exp(WN* exp, const SYMBOL& sym);
00543 WN* Find_Use_In_Exp(WN* exp, const SYMBOL& sym);
00544 WN* SNL_Copy_Exp(WN*);
00545 void SNL_Fix_Index_Pointers(WN* loop, WN* wn);
00546
00547 extern WN*& SNL_UBexp(WN* snl_end, BOOL* ne = NULL);
00548 extern WN*& SNL_UBvar(WN* snl_end);
00549 extern WN* Good_Do_Next_Innermost(WN* doloop);
00550 extern void SNL_Optimize_Bounds(SNL_REGION region);
00551
00552 extern BOOL SNL_Is_Non_Varying_Access_Array(ACCESS_ARRAY* aa,
00553 INT outer_depth);
00554
00555 extern WN* SNL_Get_Inner_Snl_Loop(WN* outer, INT nloops);
00556
00557 extern BOOL SNL_Is_Invariant(DOLOOP_STACK *stack,
00558 INT d,
00559 INT dd);
00560
00561 extern INT SNL_Loop_Count(WN* wn_snl);
00562
00563 extern WN* SNL_Innermost_Do(WN* wn_outer);
00564
00565 extern INT Is_Inner_SNL(WN* wn_loop);
00566
00567 extern void SNL_Upper_Bound_Standardize(WN* wn_outer, INT nloops);
00568
00569 extern BOOL Valid_SNL_Region(SNL_REGION region);
00570
00571 extern BOOL Need_Fix_Array_Deps_On_Index_Variable(WN* wn_loop);
00572
00573 extern BOOL SNL_Fix_Array_Deps_On_Index_Variable(WN* wn_outer, INT nloops);
00574
00575 extern WN* Next_SNL_Loop(WN* wn_outer);
00576
00577 extern IMAT* Permutation_To_Unimodular(INT permutation[], INT nloops);
00578
00579 extern INT* Unimodular_To_Permutation(IMAT* unimodular);
00580
00581 extern WN* generate_tree_from_row(const mINT32* m, SNL_TRANS_INDEX_DATA* td,
00582 INT64 c, TYPE_ID wtype, INT part);
00583
00584 extern WN* generate_tree_from_bounds_info_row(const mINT32* row,
00585 mINT64 con, BOOL le, const SNL_BOUNDS_SYMBOL_LIST*vi);
00586
00587 extern void Fix_Do_Du_Info(WN* wn, SNL_TRANS_INDEX_DATA* td,
00588 BOOL recursive, WN* loops,
00589 INT only_in_nloops);
00590
00591 extern void SNL_Rebuild_Access_Arrays(WN* wn_outerloop);
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601 #define SNL_DEBUG0(level, string) \
00602 ((snl_debug < level) ? 0 : \
00603 (fprintf(TFile, "SNL DEBUG: "),\
00604 fprintf(TFile, string),\
00605 fprintf(TFile, "\n")))
00606
00607 #define SNL_DEBUG1(level, string, v1) \
00608 ((snl_debug < level) ? 0 : \
00609 (fprintf(TFile, "SNL DEBUG: "),\
00610 fprintf(TFile, string, v1),\
00611 fprintf(TFile, "\n")))
00612
00613 #define SNL_DEBUG2(level, string, v1, v2) \
00614 ((snl_debug < level) ? 0 : \
00615 (fprintf(TFile, "SNL DEBUG: "),\
00616 fprintf(TFile, string, v1, v2),\
00617 fprintf(TFile, "\n")))
00618
00619 #define SNL_DEBUG3(level, string, v1, v2, v3) \
00620 ((snl_debug < level) ? 0 : \
00621 (fprintf(TFile, "SNL DEBUG: "),\
00622 fprintf(TFile, string, v1, v2, v3),\
00623 fprintf(TFile, "\n")))
00624
00625 #endif
00626