From 453105d27390046956ad39734f11b503eb332a95 Mon Sep 17 00:00:00 2001 From: xnpster Date: Wed, 1 Oct 2025 18:54:55 +0300 Subject: [PATCH 1/5] REMOVE_DIST_ARRAYS_FROM_IO: consider array declarations from common blocks and dimension statements --- .../ReplaceArraysInIO/replace_dist_arrays_in_io.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Transformations/ReplaceArraysInIO/replace_dist_arrays_in_io.cpp b/src/Transformations/ReplaceArraysInIO/replace_dist_arrays_in_io.cpp index 02c7035..c4da117 100644 --- a/src/Transformations/ReplaceArraysInIO/replace_dist_arrays_in_io.cpp +++ b/src/Transformations/ReplaceArraysInIO/replace_dist_arrays_in_io.cpp @@ -17,6 +17,11 @@ using std::pair; #define DEBUG_TRACE 0 +static inline bool isArrayDeclaration(SgStatement* st) +{ + return isSgDeclarationStatement(st) || st->variant() == DIM_STAT || st->variant() == COMM_STAT; +} + static SgExpression* findExprWithVariant(SgExpression* exp, int variant) { if (exp) @@ -644,18 +649,17 @@ void replaceDistributedArraysInIO(vector& regions, newDeclsToInclude, copied_syms); - // original declaration statement auto *decl_stmt = SgStatement::getStatementByFileAndLine(decl_place.first, decl_place.second); - if (!decl_stmt || !isSgDeclarationStatement(decl_stmt)) + if (!decl_stmt || !isArrayDeclaration(decl_stmt)) printInternalError(convertFileName(__FILE__).c_str(), __LINE__); auto dynamic_array = checkAssumedShape(decl_stmt, array_name); while (decl_stmt && !isSgExecutableStatement(decl_stmt)) { - if (isSgDeclarationStatement(decl_stmt) && + if (isArrayDeclaration(decl_stmt) && decl_stmt->expr(0) && decl_stmt->expr(0)->lhs() && decl_stmt->expr(0)->lhs()->symbol() == copied_symbol.second) @@ -667,7 +671,7 @@ void replaceDistributedArraysInIO(vector& regions, } // created declaration statement - if (!decl_stmt || !isSgDeclarationStatement(decl_stmt)) + if (!decl_stmt || !isArrayDeclaration(decl_stmt)) printInternalError(convertFileName(__FILE__).c_str(), __LINE__); // insert !$SPF ANALYSIS(PROCESS_PRIVATE(array)) directive before declaration statement From 8752f4a13988392aa6baf115756d0c3bfbeda12d Mon Sep 17 00:00:00 2001 From: xnpster Date: Wed, 1 Oct 2025 18:54:55 +0300 Subject: [PATCH 2/5] REMOVE_DIST_ARRAYS_FROM_IO: consider labels and goto statements while inserting copy statements --- .../replace_dist_arrays_in_io.cpp | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/src/Transformations/ReplaceArraysInIO/replace_dist_arrays_in_io.cpp b/src/Transformations/ReplaceArraysInIO/replace_dist_arrays_in_io.cpp index c4da117..021e797 100644 --- a/src/Transformations/ReplaceArraysInIO/replace_dist_arrays_in_io.cpp +++ b/src/Transformations/ReplaceArraysInIO/replace_dist_arrays_in_io.cpp @@ -172,7 +172,7 @@ static void findArrays(SgExpression* exp, set& arrays) } } -static void populateDistributedIoArrays(map>& arrays, +static bool populateDistributedIoArrays(map>& arrays, SgStatement* stat, const string& current_file_name, FuncInfo *current_func) @@ -180,7 +180,7 @@ static void populateDistributedIoArrays(map>& array auto var = stat->variant(); if (var != READ_STAT && var != PRINT_STAT && var != WRITE_STAT) - return; + return false; // check if such IO allowed in dvm: // list should consist only of single array and format string should be * @@ -190,19 +190,19 @@ static void populateDistributedIoArrays(map>& array SgExpression* ioList = stat->expr(0); if (!ioList) - return; + return false; if (ioList->variant() != EXPR_LIST) - return; + return false; if (ioList->rhs() == NULL) { SgExpression* arg = ioList->lhs(); if (!arg) - return; + return false; if (!isArrayRef(arg)) - return; + return false; if (arg->lhs()) need_replace = true; @@ -225,7 +225,6 @@ static void populateDistributedIoArrays(map>& array if (fmt->rhs()->variant() != KEYWORD_VAL || fmt->rhs()->sunparse() != "*") need_replace = true; - break; } case READ_STAT: @@ -266,7 +265,9 @@ static void populateDistributedIoArrays(map>& array } if (!need_replace) - return; + return false; + + bool ret = false; set found_arrays; @@ -285,10 +286,13 @@ static void populateDistributedIoArrays(map>& array if (inserted) __spf_print(DEBUG_TRACE, "[%d]: add array %s %p\n", stat->lineNumber(), array_p->GetName().c_str(), by_symb); + + ret = true; } } __spf_print(DEBUG_TRACE, "[replace]\n"); + return ret; } static void replaceArrayRec(SgSymbol* arr, SgSymbol* replace_by, SgExpression* exp, bool& has_read, bool& has_write, bool from_read, bool from_write) @@ -506,12 +510,16 @@ static bool ioReginBorder(SgStatement* stat, SgStatement* last_io_bound) STOP_STAT, STOP_NODE, EXIT_STMT, - EXIT_NODE + EXIT_NODE, + GOTO_NODE }; if (border_stats.find(var) != border_stats.end()) return true; + if (stat->hasLabel()) + return true; + if (last_io_bound && last_io_bound->lastNodeOfStmt() && last_io_bound->lastNodeOfStmt() == stat) return true; @@ -837,7 +845,17 @@ void replaceDistributedArraysInIO(vector& regions, } } - populateDistributedIoArrays(need_replace, curr_stmt, current_file_name, current_func_info); + auto need_fix_io = populateDistributedIoArrays(need_replace, curr_stmt, current_file_name, current_func_info); + + // incorrect IO statement with label + // move label to dummy statement and insert copy statements between dummy statement and IO + if (need_fix_io && curr_stmt->hasLabel()) + { + moveLabelBefore(curr_stmt); + if (last_io_bound == curr_stmt) // always true + last_io_bound = curr_stmt->lexPrev(); + } + curr_stmt = curr_stmt->lexNext(); } } From 54615e34d4b41ca3a0fb6fdb3913aa1cb5e15e2e Mon Sep 17 00:00:00 2001 From: xnpster Date: Wed, 1 Oct 2025 18:54:55 +0300 Subject: [PATCH 3/5] REMOVE_DIST_ARRAYS_FROM_IO: use more general isSgVarListDeclStmt and isSgNestedVarListDeclStmt functions --- .../ReplaceArraysInIO/replace_dist_arrays_in_io.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Transformations/ReplaceArraysInIO/replace_dist_arrays_in_io.cpp b/src/Transformations/ReplaceArraysInIO/replace_dist_arrays_in_io.cpp index 021e797..248cea2 100644 --- a/src/Transformations/ReplaceArraysInIO/replace_dist_arrays_in_io.cpp +++ b/src/Transformations/ReplaceArraysInIO/replace_dist_arrays_in_io.cpp @@ -19,7 +19,7 @@ using std::pair; static inline bool isArrayDeclaration(SgStatement* st) { - return isSgDeclarationStatement(st) || st->variant() == DIM_STAT || st->variant() == COMM_STAT; + return isSgDeclarationStatement(st) || isSgVarListDeclStmt(st) || isSgNestedVarListDeclStmt(st); } static SgExpression* findExprWithVariant(SgExpression* exp, int variant) @@ -855,7 +855,7 @@ void replaceDistributedArraysInIO(vector& regions, if (last_io_bound == curr_stmt) // always true last_io_bound = curr_stmt->lexPrev(); } - + curr_stmt = curr_stmt->lexNext(); } } From f35d7cb4bd1f5116d326acca5cc94a479803beb1 Mon Sep 17 00:00:00 2001 From: xnpster Date: Wed, 1 Oct 2025 19:48:34 +0300 Subject: [PATCH 4/5] REMOVE_DIST_ARRAYS_FROM_IO: consider write/read statements with nested loops --- .../replace_dist_arrays_in_io.cpp | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Transformations/ReplaceArraysInIO/replace_dist_arrays_in_io.cpp b/src/Transformations/ReplaceArraysInIO/replace_dist_arrays_in_io.cpp index 248cea2..c40bdba 100644 --- a/src/Transformations/ReplaceArraysInIO/replace_dist_arrays_in_io.cpp +++ b/src/Transformations/ReplaceArraysInIO/replace_dist_arrays_in_io.cpp @@ -17,6 +17,14 @@ using std::pair; #define DEBUG_TRACE 0 +static bool hasArrayRef(SgExpression* ex) +{ + if (ex) + return isArrayRef(ex) || hasArrayRef(ex->lhs()) || hasArrayRef(ex->rhs()); + + return false; +} + static inline bool isArrayDeclaration(SgStatement* st) { return isSgDeclarationStatement(st) || isSgVarListDeclStmt(st) || isSgNestedVarListDeclStmt(st); @@ -201,11 +209,15 @@ static bool populateDistributedIoArrays(map>& array if (!arg) return false; - if (!isArrayRef(arg)) + if (hasArrayRef(arg)) + { + if (isArrayRef(arg) && arg->lhs()) + need_replace = true; + } + else + { return false; - - if (arg->lhs()) - need_replace = true; + } } else { From b95b336372bbe965b6fe87d9e2cf07f7a1d598e6 Mon Sep 17 00:00:00 2001 From: ALEXks Date: Wed, 1 Oct 2025 21:12:49 +0300 Subject: [PATCH 5/5] version updated --- src/Utils/version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utils/version.h b/src/Utils/version.h index dce1888..6387e03 100644 --- a/src/Utils/version.h +++ b/src/Utils/version.h @@ -1,3 +1,3 @@ #pragma once -#define VERSION_SPF "2445" +#define VERSION_SPF "2446"