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
00043
00044
00045
00046
00047
00048
00049
00050
00051 #include <alloca.h>
00052 #if ! defined(BUILD_OS_DARWIN)
00053 #include <elf.h>
00054 #endif
00055
00056 #include "defs.h"
00057 #include "wn.h"
00058 #include "stab.h"
00059 #include "pu_info.h"
00060
00061 #include "opcode.h"
00062 #include "mempool.h"
00063 #include "cxx_memory.h"
00064 #include "wn_pragmas.h"
00065 #include "config_targ.h"
00066 #include "targ_sim.h"
00067 #include "erbe.h"
00068 #include "strtab.h"
00069 #include "wn_util.h"
00070 #include "dwarf_DST.h"
00071 #include "config.h"
00072 #include "cg.h"
00073
00074 #include "dra_internal.h"
00075
00076 #if defined(__linux__) || defined(BUILD_OS_DARWIN) || !defined(SHARED_BUILD)
00077 extern void (*CG_Change_Elf_Symbol_To_Undefined_p) (ST*);
00078 #define CG_Change_Elf_Symbol_To_Undefined (*CG_Change_Elf_Symbol_To_Undefined_p)
00079 #else
00080 #pragma weak CG_Change_Elf_Symbol_To_Undefined
00081 #endif // __linux__
00082
00083
00084
00085
00086
00087
00088
00089 static DRA_INFO* New_DRA (WN** pwn_addr,
00090 ST *array_st,
00091 TY_IDX array_ty,
00092 WN *block,
00093 WN *preamble);
00094
00095 static BOOL Array_TY_OK (TY_IDX array_ty);
00096
00097 static void Insert_Alloca(ST *array_st,
00098 INT16 ndims,
00099 INT64 esize,
00100 WN *dim_size_wn[],
00101 WN *block,
00102 WN *preamble);
00103
00104 static WN* Delete_Dist_Reshape_Pragmas (WN* pwn,
00105 WN* block);
00106
00107 static void DRA_Mangle_Entry(WN *entry_wn,
00108 INT16 num_formals,
00109 DRA_HASH_TABLE *dra_table,
00110 DST_ASSOC_INFO *assoc_info);
00111
00112 static void DRA_Mangle_Call_Site(WN *call_wn,
00113 OPERATOR call_oper,
00114 DRA_HASH_TABLE *dra_table);
00115
00116 static UINT DRA_Preprocess_Entry(WN *entry_wn,
00117 INT16 num_formals,
00118 DRA_HASH_TABLE *dra_table,
00119 BOOL *has_reshaped_formals);
00120
00121 static UINT DRA_Preprocess_Call_Site(WN *call_wn,
00122 INT16 num_args,
00123 DRA_HASH_TABLE *dra_table,
00124 BOOL *has_reshaped_args);
00125
00126 static char* DRA_Insert_Mangling_Sigs(char *orig_name,
00127 char mangled_buf[]);
00128
00129 static char* DRA_Encode_Parameter(ST *st,
00130 TY_IDX ty,
00131 char *buf,
00132 DRA_HASH_TABLE *dra_table);
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 static void
00153 DRA_Read_Pragmas_In_Block (WN *first, WN* block, WN *preamble,
00154 DRA_HASH_TABLE *dra_table)
00155 {
00156 WN *pwn = first;
00157
00158
00159
00160 while (pwn) {
00161
00162 if (WN_opcode(pwn) == OPC_REGION) {
00163
00164 DRA_Read_Pragmas_In_Block (WN_first(WN_region_body(pwn)), WN_region_body(pwn), preamble, dra_table);
00165 }
00166
00167 if (WN_opcode(pwn) == OPC_PRAGMA &&
00168 WN_pragma(pwn) == WN_PRAGMA_DISTRIBUTE_RESHAPE) {
00169
00170 ST *array_st = WN_st(pwn);
00171
00172 if (array_st == NULL || ST_is_not_used(array_st)) {
00173
00174
00175 pwn = Delete_Dist_Reshape_Pragmas(pwn, block);
00176 }
00177
00178 else {
00179
00180 TY_IDX array_ty = Get_Array_Type(array_st);
00181
00182 if (TY_kind(array_ty) != KIND_ARRAY) {
00183
00184
00185 ErrMsgSrcpos(EC_DRA_unsupported_type,
00186 WN_Get_Linenum(pwn),
00187 "DISTRIBUTE_RESHAPE",
00188 ST_name(array_st),
00189 "Cannot reshape non-arrays");
00190
00191 pwn = Delete_Dist_Reshape_Pragmas(pwn, block);
00192 }
00193
00194 else if (ST_is_equivalenced(array_st)) {
00195
00196
00197 ErrMsgSrcpos(EC_DRA_unsupported_type,
00198 WN_Get_Linenum(pwn),
00199 "DISTRIBUTE_RESHAPE",
00200 ST_name(array_st),
00201 "Cannot reshape equivalenced arrays");
00202
00203 pwn = Delete_Dist_Reshape_Pragmas(pwn, block);
00204 }
00205
00206 else if (ST_sclass(array_st) == SCLASS_DGLOBAL ||
00207 ST_is_initialized(array_st)) {
00208
00209
00210
00211 ErrMsgSrcpos(EC_DRA_unsupported_type,
00212 WN_Get_Linenum(pwn),
00213 "DISTRIBUTE_RESHAPE",
00214 ST_name(array_st),
00215 "Cannot reshape initialized data");
00216
00217 pwn = Delete_Dist_Reshape_Pragmas(pwn, block);
00218 }
00219
00220 else if (!Array_TY_OK (array_ty)) {
00221 ErrMsgSrcpos(EC_DRA_unsupported_type,
00222 WN_Get_Linenum(pwn),
00223 "DISTRIBUTE_RESHAPE",
00224 ST_name(array_st),
00225 "Cannot reshape assumed size arrays");
00226
00227 pwn = Delete_Dist_Reshape_Pragmas(pwn, block);
00228 }
00229
00230 else {
00231
00232 FmtAssert (ST_class(array_st) == CLASS_VAR,
00233 ("Distributed array is not a variable"));
00234
00235 DRA_INFO* dra = New_DRA(&pwn, array_st, array_ty, block, preamble);
00236
00237 if (dra != NULL) {
00238
00239
00240 dra_table->Enter(array_st, dra);
00241 }
00242 }
00243 }
00244 }
00245
00246 else {
00247 pwn = WN_next(pwn);
00248 }
00249 }
00250 }
00251
00252 void
00253 DRA_Read_Pragmas (WN* func_nd,
00254 DRA_HASH_TABLE *dra_table)
00255 {
00256 Set_Error_Phase("Processing DISTRIBUTE_RESHAPE pragmas");
00257
00258 WN *block = WN_func_body(func_nd);
00259 WN *preamble = Get_Preamble_End(func_nd);
00260
00261 DRA_Read_Pragmas_In_Block (preamble, block, preamble, dra_table);
00262 }
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280 void
00281 DRA_Mangle_All(WN *func_wn,
00282 DRA_HASH_TABLE *dra_table,
00283 PU_Info *pu_info)
00284 {
00285
00286
00287 if (DRA_func_table == NULL) {
00288 DRA_func_table = CXX_NEW(NAME_ST_TABLE(31, &MEM_src_pool), &MEM_src_pool);
00289 }
00290
00291 DST_ASSOC_INFO* assoc_info = NULL;
00292 DST_IDX pu_idx = PU_Info_pu_dst(pu_info);
00293 if (!DST_IS_NULL(pu_idx)) {
00294 DST_INFO* info = DST_INFO_IDX_TO_PTR(pu_idx);
00295 DST_SUBPROGRAM* pu_attr =
00296 DST_ATTR_IDX_TO_PTR(DST_INFO_attributes(info), DST_SUBPROGRAM);
00297 assoc_info = &(DST_SUBPROGRAM_def_st(pu_attr));
00298 }
00299
00300
00301
00302 DRA_Mangle_Entry(func_wn, WN_num_formals(func_wn), dra_table, assoc_info);
00303
00304
00305
00306 WN_ITER *wni;
00307 for (wni = WN_WALK_TreeIter(func_wn); wni; wni = WN_WALK_TreeNext(wni)) {
00308
00309 WN *stmt_wn = WN_ITER_wn(wni);
00310
00311 if (WN_opcode(stmt_wn) == OPC_ALTENTRY) {
00312 DST_ASSOC_INFO* assoc_info = NULL;
00313 DST_IDX dst_idx = DST_INFO_sibling(DST_INFO_IDX_TO_PTR(pu_idx));
00314 while (!DST_IS_NULL(dst_idx)) {
00315 DST_INFO* info = DST_INFO_IDX_TO_PTR(dst_idx);
00316 if (DST_INFO_tag(info) == DW_TAG_entry_point) {
00317 DST_ENTRY_POINT* attr =
00318 DST_ATTR_IDX_TO_PTR(DST_INFO_attributes(info), DST_ENTRY_POINT);
00319 if (DST_ASSOC_INFO_st_index(DST_ENTRY_POINT_st(attr)) ==
00320 ST_index(WN_st(stmt_wn))) {
00321 assoc_info = &(DST_ENTRY_POINT_st(attr));
00322 break;
00323 }
00324 }
00325 dst_idx = DST_INFO_sibling(info);
00326 }
00327
00328 DRA_Mangle_Entry(stmt_wn, WN_kid_count(stmt_wn), dra_table, assoc_info);
00329 }
00330
00331 else {
00332 OPERATOR stmt_oper = WN_operator(stmt_wn);
00333 if (stmt_oper == OPR_CALL || stmt_oper == OPR_ICALL) {
00334 DRA_Mangle_Call_Site(stmt_wn, stmt_oper, dra_table);
00335 }
00336 }
00337
00338 }
00339 }
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352 WN*
00353 Get_Preamble_End(WN* entry_wn)
00354 {
00355 Is_True (WN_opcode(entry_wn) == OPC_FUNC_ENTRY ||
00356 WN_opcode(entry_wn) == OPC_ALTENTRY,
00357 ("Get_Preamble_End: Expected FUNC_ENTRY or ALTENTRY node"));
00358
00359 WN* wn;
00360 if (WN_opcode(entry_wn) == OPC_FUNC_ENTRY) {
00361 wn = WN_entry_first(entry_wn);
00362 }
00363 else {
00364 wn = WN_next(entry_wn);
00365 }
00366
00367 while (wn != NULL && (WN_opcode(wn) != OPC_PRAGMA ||
00368 WN_pragma(wn) != WN_PRAGMA_PREAMBLE_END)) {
00369 wn = WN_next(wn);
00370 }
00371
00372 Is_True (wn != NULL, ("Could not find the PREAMBLE_END pragma"));
00373
00374 return wn;
00375 }
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389 ST*
00390 Find_Return_Registers(TYPE_ID type,
00391 PREG_NUM *rreg1,
00392 PREG_NUM *rreg2)
00393 {
00394 TYPE_ID mtype1;
00395 TYPE_ID mtype2;
00396
00397 if (WHIRL_Return_Info_On) {
00398
00399 RETURN_INFO return_info = Get_Return_Info (Be_Type_Tbl(type),
00400 Use_Simulated);
00401
00402 if (RETURN_INFO_count(return_info) <= 2) {
00403
00404 *rreg1 = RETURN_INFO_preg (return_info, 0);
00405 *rreg2 = RETURN_INFO_preg (return_info, 1);
00406 }
00407
00408 else {
00409
00410 Fail_FmtAssertion ("Find_Return_Registers: more than 2 return registers");
00411 return NULL;
00412 }
00413 }
00414
00415 else {
00416
00417 Get_Return_Mtypes(Be_Type_Tbl(type), Use_Simulated, &mtype1, &mtype2);
00418 Get_Return_Pregs(mtype1, mtype2, rreg1, rreg2);
00419 }
00420
00421 if (Preg_Offset_Is_Int(*rreg1)) {
00422 if (MTYPE_bit_size(type) == 32) {
00423 return Int32_Preg;
00424 } else {
00425 return Int64_Preg;
00426 }
00427 } else {
00428 if (MTYPE_bit_size(type) == 32) {
00429 return Float32_Preg;
00430 } else {
00431 return Float64_Preg;
00432 }
00433 }
00434 }
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459 static DRA_INFO*
00460 New_DRA (WN** pwn_addr,
00461 ST *array_st,
00462 TY_IDX array_ty,
00463 WN *block,
00464 WN *preamble)
00465 {
00466 TY& ty = Ty_Table[array_ty];
00467 INT16 ndims = TY_AR_ndims(ty);
00468 INT64 esize = TY_size(TY_AR_etype(ty));
00469 DRA_INFO *dra = CXX_NEW(DRA_INFO(ndims, esize, DRA_name_pool_ptr),
00470 DRA_name_pool_ptr);
00471
00472 WN *pwn = *pwn_addr;
00473 WN **dim_size_wn = (WN**) alloca(ndims*sizeof(WN*));
00474 INT16 distr_dims = 0;
00475
00476 for (INT16 i = 0; i < ndims; i++) {
00477
00478
00479
00480 FmtAssert (WN_opcode(pwn) == OPC_PRAGMA,
00481 ("Distribute_Reshape_Pragma: expected a PRAGMA node\n"));
00482
00483 FmtAssert (WN_pragma(pwn) == WN_PRAGMA_DISTRIBUTE_RESHAPE,
00484 ("Distribute_Reshape_Pragma: unexpected PRAGMA type\n"));
00485
00486 switch (WN_pragma_distr_type(pwn)) {
00487
00488 case DISTRIBUTE_STAR:
00489 dra->Init (i, (DISTRIBUTE_TYPE) WN_pragma_distr_type(pwn));
00490 break;
00491
00492 case DISTRIBUTE_BLOCK:
00493 distr_dims++;
00494 dra->Init (i, (DISTRIBUTE_TYPE) WN_pragma_distr_type(pwn));
00495 break;
00496
00497 case DISTRIBUTE_CYCLIC_CONST:
00498 distr_dims++;
00499 dra->Init (i, (DISTRIBUTE_TYPE) WN_pragma_distr_type(pwn),
00500 (INT64) WN_pragma_arg2(pwn));
00501 break;
00502
00503 case DISTRIBUTE_CYCLIC_EXPR:
00504 distr_dims++;
00505 dra->Init (i, (DISTRIBUTE_TYPE) WN_pragma_distr_type(pwn));
00506
00507 pwn = WN_next(pwn);
00508
00509 FmtAssert (WN_opcode(pwn) == OPC_XPRAGMA,
00510 ("Distribute_Reshape_Pragma: expected an XPRAGMA node\n"));
00511
00512 FmtAssert (WN_pragma(pwn) == WN_PRAGMA_DISTRIBUTE_RESHAPE,
00513 ("Distribute_Reshape_Pragma: unexpected XPRAGMA type\n"));
00514
00515 break;
00516
00517 default:
00518 FmtAssert (FALSE,
00519 ("Distribute_Reshape_Pragma: strange distribute type\n"));
00520 break;
00521 }
00522
00523 pwn = WN_next(pwn);
00524 dim_size_wn[i] = WN_kid(pwn, 0);
00525
00526 FmtAssert (WN_opcode(pwn) == OPC_XPRAGMA,
00527 ("Distribute_Reshape_Pragma: expected an XPRAGMA node\n"));
00528
00529 FmtAssert (WN_pragma(pwn) == WN_PRAGMA_DISTRIBUTE_RESHAPE,
00530 ("Distribute_Reshape_Pragma: unexpected XPRAGMA type\n"));
00531
00532 pwn = WN_next(pwn);
00533 }
00534
00535
00536 if (distr_dims == 0) {
00537
00538 ErrMsgSrcpos(EC_DRA_all_stars,
00539 WN_Get_Linenum(*pwn_addr),
00540 ST_name(array_st));
00541
00542
00543
00544
00545 if (ST_sclass(array_st) == SCLASS_AUTO &&
00546 TY_kind(ST_type(array_st)) == KIND_POINTER) {
00547
00548 Insert_Alloca(array_st, ndims, esize, dim_size_wn, block, preamble);
00549 }
00550
00551 dra = NULL;
00552 pwn = Delete_Dist_Reshape_Pragmas (*pwn_addr, block);
00553
00554 }
00555
00556 *pwn_addr = pwn;
00557
00558 return dra;
00559 }
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571 static BOOL
00572 Array_TY_OK (TY_IDX array_ty)
00573 {
00574 const TY& ty = Ty_Table[array_ty];
00575
00576 Is_True (TY_kind(ty) == KIND_ARRAY,
00577 ("Array_TY_OK called on a non-array"));
00578
00579 INT16 ndims = TY_AR_ndims(ty);
00580
00581 Is_True (ndims > 0, ("Array_TY_OK: array has 0 dimensions?"));
00582
00583 for (INT16 i = 0; i < ndims; i++) {
00584
00585
00586 if ((!TY_AR_const_lbnd(ty, i)) &&
00587 (TY_AR_lbnd_val(ty, i) == 0)) {
00588 return FALSE;
00589 }
00590
00591 if ((!TY_AR_const_ubnd(ty, i)) &&
00592 (TY_AR_ubnd_val(ty, i) == 0)) {
00593 return FALSE;
00594 }
00595 }
00596
00597 return TRUE;
00598 }
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611 static void
00612 Insert_Alloca(ST *array_st,
00613 INT16 ndims,
00614 INT64 esize,
00615 WN *dim_size_wn[],
00616 WN *block,
00617 WN *preamble)
00618 {
00619 WN* size_wn = WN_Intconst(MTYPE_I8, esize);
00620 for (INT16 i = 0; i < ndims; i++) {
00621 size_wn = WN_Mpy(MTYPE_I8, size_wn, WN_CopyNode(dim_size_wn[i]));
00622 }
00623
00624 OPCODE call_op = OPCODE_make_op(OPR_INTRINSIC_CALL,
00625 Pointer_type,
00626 MTYPE_V);
00627 WN *call_wn = WN_Create(call_op, 1);
00628 WN_intrinsic(call_wn) =
00629 (Pointer_Size == 8) ? INTRN_U8I8ALLOCA : INTRN_U4I4ALLOCA;
00630
00631 WN* parm_wn = WN_CreateParm (Pointer_type,
00632 size_wn,
00633 Be_Type_Tbl(Pointer_type),
00634 WN_PARM_BY_REFERENCE);
00635 WN_kid0(call_wn) = parm_wn;
00636
00637
00638
00639
00640
00641 WN_INSERT_BlockBefore(block, preamble, call_wn);
00642
00643
00644
00645
00646 PREG_NUM rreg1, rreg2;
00647 ST* rst = Find_Return_Registers (Pointer_type, &rreg1, &rreg2);
00648 FmtAssert(rreg1 != 0 && rreg2 == 0, ("Bad pointer type ret regs"));
00649
00650 WN *ldid_wn =
00651 WN_CreateLdid (OPCODE_make_op(OPR_LDID, Pointer_type, Pointer_type),
00652 rreg1,
00653 rst,
00654 Be_Type_Tbl(Pointer_type));
00655
00656 WN *stid_wn =
00657 WN_CreateStid (OPCODE_make_op(OPR_STID, MTYPE_V, Pointer_type),
00658 0,
00659 array_st,
00660 ST_type(array_st),
00661 ldid_wn);
00662
00663
00664
00665
00666
00667 WN_INSERT_BlockBefore(block, preamble, stid_wn);
00668
00669 Set_ST_pt_to_unique_mem(array_st);
00670 Set_PU_has_alloca (Get_Current_PU ());
00671 }
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686 static WN*
00687 Delete_Dist_Reshape_Pragmas (WN* pwn,
00688 WN *block)
00689 {
00690 FmtAssert (WN_opcode(pwn) == OPC_PRAGMA &&
00691 WN_pragma(pwn) == WN_PRAGMA_DISTRIBUTE_RESHAPE,
00692 ("Delete_Dist_Reshape_Pragma: Wrong opcode and/or pragma\n"));
00693
00694 WN *current = pwn;
00695 WN *next;
00696 ST *st = WN_st(current);
00697
00698 while (current) {
00699
00700
00701
00702 next = WN_next(current);
00703
00704
00705
00706 WN_DELETE_FromBlock (block, current);
00707
00708
00709
00710
00711 current = next;
00712
00713
00714
00715 if ((WN_opcode(current) != OPC_PRAGMA &&
00716 WN_opcode(current) != OPC_XPRAGMA) ||
00717 WN_pragma(current) != WN_PRAGMA_DISTRIBUTE_RESHAPE ||
00718 WN_st(current) != st) {
00719 return current;
00720 }
00721 }
00722
00723 return NULL;
00724 }
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735 static void
00736 Change_ST_Of_Current_PU(ST *new_entry_st)
00737 {
00738
00739
00740
00741 Current_PU_Info->proc_sym = ST_st_idx(new_entry_st);
00742 Scope_tab[CURRENT_SYMTAB].st = new_entry_st;
00743 }
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754 static void
00755 DRA_Mangle_Entry(WN* entry_wn,
00756 INT16 num_formals,
00757 DRA_HASH_TABLE* dra_table,
00758 DST_ASSOC_INFO* assoc_info)
00759 {
00760 BOOL has_reshaped_formals = FALSE;
00761
00762 UINT bufsize = DRA_Preprocess_Entry(entry_wn,
00763 num_formals,
00764 dra_table,
00765 &has_reshaped_formals);
00766
00767 if (has_reshaped_formals) {
00768
00769
00770
00771 char *mangled_buf = (char *) alloca(bufsize);
00772 char *entry_name = ST_name(WN_st(entry_wn));
00773 char *mangled_ptr = DRA_Insert_Mangling_Sigs(entry_name, mangled_buf);
00774
00775
00776
00777 for (INT16 formal = 0; formal < num_formals; ++formal) {
00778
00779 ST *formal_st = WN_st(WN_formal(entry_wn, formal));
00780 TY_IDX formal_ty = Get_Array_Type(formal_st);
00781
00782 mangled_ptr = DRA_Encode_Parameter(formal_st,
00783 formal_ty,
00784 mangled_ptr,
00785 dra_table);
00786 *mangled_ptr++ = DRA_ARG_SEPARATOR;
00787 }
00788
00789 *mangled_ptr = '\0';
00790
00791
00792
00793
00794 ST *old_st = WN_st(entry_wn);
00795 ST *entry_st = old_st;
00796
00797
00798
00799 MANGLED_FUNC *entry_desc = DRA_func_table->Find(Save_Str(mangled_buf));
00800
00801 if (entry_desc == NULL) {
00802
00803 if (strcmp(entry_name, mangled_buf) != 0) {
00804
00805
00806
00807 entry_st = Copy_ST(entry_st, TRUE);
00808 WN_st_idx(entry_wn) = ST_st_idx(entry_st);
00809 Set_ST_name(entry_st, Save_Str(mangled_buf));
00810 Clear_ST_is_not_used(entry_st);
00811 }
00812
00813
00814
00815 entry_desc = CXX_NEW(MANGLED_FUNC, &MEM_src_pool);
00816 entry_desc->st = entry_st;
00817 entry_desc->is_clone = FALSE;
00818 entry_desc->is_called = FALSE;
00819 DRA_func_table->Enter(ST_name_idx(entry_st), entry_desc);
00820 }
00821
00822 else {
00823 entry_st = entry_desc->st;
00824 WN_st_idx (entry_wn) = ST_st_idx (entry_st);
00825 Set_ST_sclass (entry_st, SCLASS_TEXT);
00826
00827
00828 if (Run_cg) {
00829 Set_ST_base (entry_st, ST_base(old_st));
00830 }
00831 }
00832
00833
00834
00835 if (assoc_info != NULL) {
00836 pDST_ASSOC_INFO_st_idx(assoc_info) = ST_st_idx(entry_st);
00837 }
00838
00839
00840
00841 if (entry_st != old_st) {
00842 Change_ST_Of_Current_PU(entry_st);
00843 Set_ST_sclass (old_st, SCLASS_EXTERN);
00844 if (!PU_has_non_mangled_call (Pu_Table[ST_pu (old_st)]))
00845 Set_ST_is_not_used (old_st);
00846 else if (Run_cg) {
00847 CG_Change_Elf_Symbol_To_Undefined(old_st);
00848 }
00849 }
00850 }
00851 else {
00852 Set_PU_has_non_mangled_call(Pu_Table[ST_pu(WN_st(entry_wn))]);
00853 Clear_ST_is_not_used(WN_st(entry_wn));
00854 }
00855 }
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868 static void
00869 DRA_Mangle_Call_Site(WN *call_wn,
00870 OPERATOR call_oper,
00871 DRA_HASH_TABLE *dra_table)
00872 {
00873
00874
00875 if (call_oper == OPR_CALL &&
00876 strncmp(ST_name(WN_st(call_wn)), "dsm_", 4) == 0) {
00877 return;
00878 }
00879
00880
00881
00882 if (call_oper == OPR_CALL &&
00883 (strcmp (ST_name(WN_st(call_wn)), "printf") == 0 ||
00884 strcmp (ST_name(WN_st(call_wn)), "fprintf") == 0 ||
00885 strcmp (ST_name(WN_st(call_wn)), "sprintf") == 0 ||
00886 strcmp (ST_name(WN_st(call_wn)), "vprintf") == 0 ||
00887 strcmp (ST_name(WN_st(call_wn)), "vfprintf") == 0 ||
00888 strcmp (ST_name(WN_st(call_wn)), "vsprintf") == 0 ||
00889 strcmp (ST_name(WN_st(call_wn)), "scanf") == 0 ||
00890 strcmp (ST_name(WN_st(call_wn)), "sscanf") == 0 ||
00891 strcmp (ST_name(WN_st(call_wn)), "fscanf") == 0)) {
00892 return;
00893 }
00894
00895 BOOL has_reshaped_args = FALSE;
00896 INT16 num_args = WN_num_actuals(call_wn);
00897
00898 UINT bufsize = DRA_Preprocess_Call_Site(call_wn,
00899 num_args,
00900 dra_table,
00901 &has_reshaped_args);
00902
00903 if (has_reshaped_args) {
00904
00905
00906
00907
00908 if (call_oper == OPR_ICALL) {
00909 ErrMsgSrcpos(EC_DRA_indirect_call, WN_Get_Linenum(call_wn));
00910 return;
00911 }
00912
00913
00914
00915 char *mangled_buf = (char *) alloca(bufsize);
00916 char *call_name = ST_name(WN_st(call_wn));
00917 char *mangled_ptr = DRA_Insert_Mangling_Sigs(call_name, mangled_buf);
00918
00919
00920
00921 for (INT16 arg = 0; arg < num_args; ++arg) {
00922
00923
00924
00925 WN *arg_wn = WN_kid(WN_actual(call_wn,arg), 0);
00926
00927 if (WN_operator(arg_wn) == OPR_LDA ||
00928 WN_operator(arg_wn) == OPR_LDID) {
00929
00930 ST *arg_st = WN_st(arg_wn);
00931 TY_IDX arg_ty = Get_Array_Type(arg_st);
00932
00933 mangled_ptr = DRA_Encode_Parameter(arg_st,
00934 arg_ty,
00935 mangled_ptr,
00936 dra_table);
00937 }
00938 else {
00939
00940
00941 *mangled_ptr++ = '0';
00942 }
00943 *mangled_ptr++ = DRA_ARG_SEPARATOR;
00944 }
00945 *mangled_ptr = '\0';
00946
00947
00948
00949
00950 ST *old_st = WN_st(call_wn);
00951
00952
00953
00954 MANGLED_FUNC *call_desc = DRA_func_table->Find(Save_Str(mangled_buf));
00955
00956 if (call_desc == NULL) {
00957
00958
00959
00960 PU_IDX new_pu_idx;
00961 PU& new_pu = New_PU (new_pu_idx);
00962 Pu_Table[new_pu_idx] = Pu_Table[ST_pu(old_st)];
00963 Set_PU_no_inline (new_pu);
00964
00965 ST *new_st = Copy_ST(old_st);
00966 WN_st_idx (call_wn) = ST_st_idx (new_st);
00967 Clear_ST_is_not_used (new_st);
00968
00969
00970
00971 Set_ST_pu (new_st, new_pu_idx);
00972
00973
00974
00975 Set_ST_name (new_st, Save_Str(mangled_buf));
00976
00977
00978
00979 Set_ST_sclass (new_st, SCLASS_EXTERN);
00980
00981
00982
00983 Set_ST_base (new_st, new_st);
00984 Set_ST_ofst (new_st, 0);
00985
00986
00987
00988 call_desc = CXX_NEW(MANGLED_FUNC, &MEM_src_pool);
00989 call_desc->st = new_st;
00990 call_desc->is_called = TRUE;
00991 DRA_func_table->Enter(ST_name_idx(new_st), call_desc);
00992 } else {
00993
00994
00995 WN_st_idx (call_wn) = ST_st_idx (call_desc->st);
00996 call_desc->is_called = TRUE;
00997 }
00998
00999
01000
01001 if (!PU_has_non_mangled_call (Pu_Table[ST_pu (old_st)]))
01002 Set_ST_is_not_used (old_st);
01003 }
01004
01005 else {
01006
01007
01008 if (call_oper == OPR_CALL) {
01009 ST* st = WN_st (call_wn);
01010 Set_PU_has_non_mangled_call (Pu_Table[ST_pu (st)]);
01011 Clear_ST_is_not_used (st);
01012 }
01013 }
01014 }
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028 static UINT
01029 DRA_Preprocess_Entry(WN *entry_wn,
01030 INT16 num_formals,
01031 DRA_HASH_TABLE *dra_table,
01032 BOOL *has_reshaped_formals)
01033 {
01034 UINT bufsize = strlen(ST_name(WN_st(entry_wn))) + 2*DRA_MANGLE_SIG_LEN + 1;
01035
01036 for (INT16 formal = 0; formal < num_formals; ++formal) {
01037
01038 ST *formal_st = WN_st(WN_formal(entry_wn, formal));
01039 TY_IDX formal_ty = Get_Array_Type(formal_st);
01040
01041 if (TY_kind(formal_ty) != KIND_ARRAY) {
01042 bufsize += 2;
01043 }
01044 else {
01045 DRA_INFO *dra = dra_table->Find(formal_st);
01046 if (dra == NULL) {
01047 bufsize += 2;
01048 }
01049 else {
01050 *has_reshaped_formals = TRUE;
01051
01052
01053
01054
01055 bufsize += 28 + 22*TY_AR_ndims(Ty_Table[formal_ty]);
01056 }
01057 }
01058 }
01059
01060 return bufsize;
01061 }
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075 static UINT
01076 DRA_Preprocess_Call_Site(WN *call_wn,
01077 INT16 num_args,
01078 DRA_HASH_TABLE *dra_table,
01079 BOOL *has_reshaped_args)
01080 {
01081 UINT bufsize = 0;
01082 if (WN_operator(call_wn) == OPR_CALL) {
01083 bufsize = strlen(ST_name(WN_st(call_wn))) + 2*DRA_MANGLE_SIG_LEN + 1;
01084 }
01085
01086 for (INT16 arg = 0; arg < num_args; ++arg) {
01087
01088
01089
01090 WN *parm_wn = WN_actual(call_wn, arg);
01091 WN *arg_wn = WN_kid(parm_wn, 0);
01092
01093 if (WN_operator(arg_wn) == OPR_LDA ||
01094 WN_operator(arg_wn) == OPR_LDID) {
01095
01096 ST *arg_st = WN_st(arg_wn);
01097 TY_IDX arg_ty = Get_Array_Type(arg_st);
01098
01099 if (TY_kind(arg_ty) != KIND_ARRAY) {
01100 bufsize += 2;
01101 }
01102 else {
01103 DRA_INFO *dra = dra_table->Find(arg_st);
01104 if (dra == NULL) {
01105 bufsize += 2;
01106 }
01107 else {
01108 *has_reshaped_args = TRUE;
01109
01110
01111
01112
01113 bufsize += 28 + 22*TY_AR_ndims(Ty_Table[arg_ty]);
01114 }
01115 }
01116 }
01117 else {
01118 bufsize += 2;
01119 }
01120 }
01121
01122 return bufsize;
01123 }
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137 static char*
01138 DRA_Insert_Mangling_Sigs(char *orig_name,
01139 char mangled_buf[])
01140 {
01141
01142 if (strncmp(orig_name, DRA_MANGLE_SIG, DRA_MANGLE_SIG_LEN)) {
01143
01144
01145 (void) strcpy(mangled_buf, DRA_MANGLE_SIG);
01146 (void) strcpy(mangled_buf + DRA_MANGLE_SIG_LEN, orig_name);
01147 (void) strcpy(mangled_buf + DRA_MANGLE_SIG_LEN + strlen(orig_name),
01148 DRA_MANGLE_SIG);
01149 }
01150 else {
01151
01152
01153 INT name_len = strstr(orig_name+1, DRA_MANGLE_SIG)
01154 + DRA_MANGLE_SIG_LEN - orig_name;
01155 (void) strncpy(mangled_buf, orig_name, name_len);
01156 mangled_buf[name_len] = '\0';
01157 }
01158
01159 return (mangled_buf + strlen(mangled_buf));
01160 }
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175 static char*
01176 DRA_Encode_Parameter(ST *st,
01177 TY_IDX ty_idx,
01178 char *buf,
01179 DRA_HASH_TABLE *dra_table)
01180 {
01181 TY& ty = Ty_Table[ty_idx];
01182
01183
01184 if (TY_kind(ty) != KIND_ARRAY) {
01185 *buf++ = '0';
01186 return buf;
01187 }
01188
01189 DRA_INFO *dra = dra_table->Find(st);
01190
01191
01192
01193 if (dra == NULL) {
01194 *buf++ = '0';
01195 return buf;
01196 }
01197
01198
01199
01200 INT16 ndims = ARB_dimension (TY_arb(ty));
01201 UINT64 size = TY_size (TY_etype(ty));
01202 buf += sprintf(buf, "%d%c", ndims, DRA_NDIMS_END);
01203 buf += sprintf(buf, "%lld%c", size, DRA_ESIZE_END);
01204
01205 for (INT16 dim = 0; dim < ndims; ++dim) {
01206
01207 switch (dra->Distr_Type(dim)) {
01208
01209 case DISTRIBUTE_STAR:
01210 *buf++ = DRA_STAR_CODE;
01211 break;
01212
01213 case DISTRIBUTE_BLOCK:
01214 *buf++ = DRA_BLOCK_CODE;
01215 break;
01216
01217 case DISTRIBUTE_CYCLIC_CONST:
01218 *buf++ = DRA_CYCLIC_CODE;
01219 buf += sprintf(buf, "%lld", dra->Chunk_Const_Val(dim));
01220 break;
01221
01222 case DISTRIBUTE_CYCLIC_EXPR:
01223 *buf++ = DRA_CYCLIC_CODE;
01224 break;
01225 }
01226 }
01227
01228 return buf;
01229 }