@@ -1225,13 +1225,110 @@ lower_pointer_init(void)
12251225 }
12261226} /* lower_pointer_init */
12271227
1228+ /* When prepend_func_result_as_first_arg(semfin.c) has been called for an
1229+ * entry, the FVAL symbol and its descriptor symbol if exist are referred in
1230+ * the entry's dummy arguments.
1231+ * When we are going to identify all result variables of same dtype from
1232+ * different entry points with a single symbol, here we traverse all the dummy
1233+ * arguments, and replace the FVAL symbol and its descriptor symbol with this
1234+ * single symbol and corresponding descriptor symbol.
1235+ */
1236+ static void
1237+ replace_fval_in_params (SPTR entry , SPTR entrysame )
1238+ {
1239+ SPTR fval , fvalsame , newdsc , newdscsame , newarg , newargsame ;
1240+ int params , narg , i ;
1241+
1242+ fval = FVALG (entry );
1243+ fvalsame = FVALG (entrysame );
1244+ newdsc = NEWDSCG (fval );
1245+ newarg = NEWARGG (fval );
1246+ newdscsame = NEWDSCG (fvalsame );
1247+ newargsame = NEWARGG (fvalsame );
1248+ params = DPDSCG (entry );
1249+ narg = PARAMCTG (entry );
1250+ for (i = 0 ; i < narg ; i ++ ) {
1251+ int arg = aux .dpdsc_base [params + i ];
1252+ if (arg != 0 && arg == newarg ) {
1253+ aux .dpdsc_base [params + i ] = newargsame ;
1254+ continue ;
1255+ }
1256+ if (arg != 0 && arg == newdsc ) {
1257+ aux .dpdsc_base [params + i ] = newdscsame ;
1258+ continue ;
1259+ }
1260+ }
1261+ }
1262+
1263+ /* replace the symbol used in the ast of type A_ID taking advantage of the hash
1264+ * in the AST table
1265+ */
1266+ static void
1267+ replace_sptr_in_ast (SPTR sptr )
1268+ {
1269+ SPTR newsptr ;
1270+ int ast ;
1271+
1272+ if (sptr <= NOSYM ) {
1273+ return ;
1274+ }
1275+ newsptr = LOWER_SYMBOL_REPLACE (sptr );
1276+ if (newsptr <= NOSYM ) {
1277+ return ;
1278+ }
1279+ ast = mk_id (sptr );
1280+ A_SPTRP (ast , newsptr );
1281+ }
1282+
1283+ static inline void
1284+ add_replace_map (SPTR sptr , SPTR newsptr )
1285+ {
1286+ if (sptr <= NOSYM || newsptr <= NOSYM ) {
1287+ return ;
1288+ }
1289+ LOWER_SYMBOL_REPLACE (sptr ) = newsptr ;
1290+ }
1291+
1292+ /* replace the fval symbol and associated symbols when the fval symbol is
1293+ * pointer or array
1294+ */
1295+ static void
1296+ replace_fval_in_ast (SPTR fval , SPTR fvalsame )
1297+ {
1298+ SPTR var , var_same ;
1299+
1300+ replace_sptr_in_ast (fval );
1301+
1302+ var = MIDNUMG (fval );
1303+ var_same = MIDNUMG (fvalsame );
1304+ add_replace_map (var , var_same );
1305+ replace_sptr_in_ast (var );
1306+
1307+ var = PTROFFG (fval );
1308+ var_same = PTROFFG (fvalsame );
1309+ add_replace_map (var , var_same );
1310+ replace_sptr_in_ast (var );
1311+
1312+ var = DESCRG (fval );
1313+ var_same = DESCRG (fvalsame );
1314+ add_replace_map (var , var_same );
1315+ replace_sptr_in_ast (var );
1316+
1317+ var = SDSCG (fval );
1318+ var_same = SDSCG (fvalsame );
1319+ add_replace_map (var , var_same );
1320+ replace_sptr_in_ast (var );
1321+ }
1322+
12281323extern int pghpf_type_sptr ;
12291324extern int pghpf_local_mode_sptr ;
12301325
12311326void
12321327lower_init_sym (void )
12331328{
12341329 int sym , dtype ;
1330+ LOGICAL from_func ;
1331+
12351332 lowersym .sc = SC_LOCAL ;
12361333 lowersym .parallel_depth = 0 ;
12371334 lowersym .task_depth = 0 ;
@@ -1357,21 +1454,24 @@ lower_init_sym(void)
13571454 stack_size = 100 ;
13581455 NEW (stack , int , stack_size );
13591456
1457+ from_func = gbl .rutype == RU_SUBR && gbl .entries > NOSYM && FVALG (gbl .entries );
13601458 /* look for ENTRY points; make all ENTRY points with the same
13611459 * return type use the same FVAL symbol */
1362- if (gbl .rutype == RU_FUNC ) {
1460+ if (from_func || gbl .rutype == RU_FUNC ) {
13631461 int ent , esame ;
13641462 for (ent = gbl .entries ; ent > NOSYM ; ent = SYMLKG (ent )) {
13651463 for (esame = gbl .entries ; esame != ent ; esame = SYMLKG (esame )) {
13661464 int fval , fvalsame ;
13671465 fval = FVALG (ent );
13681466 fvalsame = FVALG (esame );
13691467 if (fval && fvalsame && fval != fvalsame &&
1370- DTYPEG (fval ) == DTYPEG (fvalsame )) {
1468+ same_dtype ( DTYPEG (fval ), DTYPEG (fvalsame ) )) {
13711469 /* esame is the earlier entry point, make ent use the
13721470 * FVAL of esame */
13731471 LOWER_SYMBOL_REPLACE (fval ) = fvalsame ;
1472+ replace_fval_in_params (ent , esame );
13741473 FVALP (ent , fvalsame );
1474+ replace_fval_in_ast (fval , fvalsame );
13751475 break ; /* leave inner loop */
13761476 }
13771477 }
0 commit comments