REMOVE_DIST_ARRAYS_FROM_IO Handle assumed-size and assumed-shape arrays #64
@@ -17,13 +17,17 @@ using std::pair;
|
|||||||
|
|
||||||
#define DEBUG_TRACE 0
|
#define DEBUG_TRACE 0
|
||||||
|
|
||||||
static bool checkDynamicArray(DIST::Array *array)
|
static SgStatement* getDeclStatement(int line_num)
|
||||||
{
|
{
|
||||||
for (const auto &bounds : array->GetSizes())
|
PTR_BFND node = current_file->firstStatement()->thebif;
|
||||||
if (bounds.first == -1 || bounds.second == -1)
|
for (; node; node = node->thread)
|
||||||
return true;
|
{
|
||||||
|
SgStatement *st = BfndMapping(node);
|
||||||
|
if (st->lineNumber() == line_num && isSgDeclarationStatement(st))
|
||||||
|
return st;
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SgExpression* findExprWithVariant(SgExpression* exp, int variant)
|
static SgExpression* findExprWithVariant(SgExpression* exp, int variant)
|
||||||
@@ -53,7 +57,6 @@ bool switchToDeclarationFile(DIST::Array* array_p,
|
|||||||
if (!array_p)
|
if (!array_p)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
// try to find declaration from current function
|
// try to find declaration from current function
|
||||||
for (const auto &p : array_p->GetDeclInfo())
|
for (const auto &p : array_p->GetDeclInfo())
|
||||||
{
|
{
|
||||||
@@ -78,6 +81,47 @@ bool switchToDeclarationFile(DIST::Array* array_p,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool checkAssumedShape(SgStatement* decl, const string& array_name)
|
||||||
|
{
|
||||||
|
SgExpression* list = decl->expr(0);
|
||||||
|
SgExpression* dim_list = NULL;
|
||||||
|
|
||||||
|
while (list)
|
||||||
|
{
|
||||||
|
auto *arr_ref = list->lhs();
|
||||||
|
|
||||||
|
xnpster marked this conversation as resolved
Outdated
|
|||||||
|
if (arr_ref &&
|
||||||
|
arr_ref->symbol() &&
|
||||||
|
arr_ref->symbol()->identifier() &&
|
||||||
|
arr_ref->symbol()->identifier() == array_name)
|
||||||
|
{
|
||||||
|
dim_list = arr_ref->lhs();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
list = list->rhs();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!dim_list)
|
||||||
|
{
|
||||||
|
auto *dim_expr = findExprWithVariant(decl->expr(2), DIMENSION_OP);
|
||||||
|
if (dim_expr)
|
||||||
|
dim_list = dim_expr->lhs();
|
||||||
|
}
|
||||||
|
|
||||||
|
while (dim_list)
|
||||||
|
{
|
||||||
|
auto *lhs = dim_list->lhs();
|
||||||
|
|
||||||
|
if (lhs && lhs->variant() == DDOT && (!lhs->lhs() || !lhs->rhs()))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
dim_list = dim_list->rhs();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static bool checkAssumedSize(const string &array_name, DIST::Array* array_p, const string ¤t_file_name, FuncInfo *current_func)
|
static bool checkAssumedSize(const string &array_name, DIST::Array* array_p, const string ¤t_file_name, FuncInfo *current_func)
|
||||||
{
|
{
|
||||||
if (!array_p)
|
if (!array_p)
|
||||||
@@ -90,9 +134,12 @@ static bool checkAssumedSize(const string &array_name, DIST::Array* array_p, con
|
|||||||
if (!switchToDeclarationFile(array_p, decl_place, current_file_name, current_func))
|
if (!switchToDeclarationFile(array_p, decl_place, current_file_name, current_func))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
auto *st = SgStatement::getStatementByFileAndLine(decl_place.first, decl_place.second);
|
auto *st = getDeclStatement(decl_place.second);
|
||||||
|
|
||||||
SgExpression* list = st->expr(0);
|
if (!st)
|
||||||
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
|
SgExpression* list = st->expr(0);
|
||||||
while (list)
|
while (list)
|
||||||
{
|
{
|
||||||
if (list->lhs() &&
|
if (list->lhs() &&
|
||||||
@@ -618,14 +665,30 @@ void replaceDistributedArraysInIO(vector<ParallelRegion*>& regions,
|
|||||||
copied_syms);
|
copied_syms);
|
||||||
|
|
||||||
|
|
||||||
auto* decl_stmt = SgStatement::getStatementByFileAndLine(decl_place.first, decl_place.second);
|
// original declaration statement
|
||||||
|
auto* decl_stmt = getDeclStatement(decl_place.second);
|
||||||
// created declaration statement located right after original one
|
if (!decl_stmt || !isSgDeclarationStatement(decl_stmt))
|
||||||
if (!decl_stmt || !decl_stmt->lexNext())
|
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
decl_stmt = decl_stmt->lexNext();
|
auto dynamic_array = checkAssumedShape(decl_stmt, array_name);
|
||||||
|
|
||||||
|
while (decl_stmt && !isSgExecutableStatement(decl_stmt))
|
||||||
|
{
|
||||||
|
if (isSgDeclarationStatement(decl_stmt) &&
|
||||||
|
decl_stmt->expr(0) &&
|
||||||
|
decl_stmt->expr(0)->lhs() &&
|
||||||
|
decl_stmt->expr(0)->lhs()->symbol() == copied_symbol.second)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
decl_stmt = decl_stmt->lexNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
// created declaration statement
|
||||||
|
if (!decl_stmt || !isSgDeclarationStatement(decl_stmt))
|
||||||
|
Alexander_KS
commented
это в с++17 входит ? это в с++17 входит ?
xnpster
commented
Да, это же просто std::initializer_list Да, это же просто std::initializer_list
|
|||||||
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
// insert !$SPF ANALYSIS(PROCESS_PRIVATE(array)) directive before declaration statement
|
// insert !$SPF ANALYSIS(PROCESS_PRIVATE(array)) directive before declaration statement
|
||||||
|
|
||||||
string dir_str;
|
string dir_str;
|
||||||
@@ -641,8 +704,8 @@ void replaceDistributedArraysInIO(vector<ParallelRegion*>& regions,
|
|||||||
|
|
||||||
created_copies.insert({ array_to_copy, copied_symbol.second });
|
created_copies.insert({ array_to_copy, copied_symbol.second });
|
||||||
|
|
||||||
// make array copy allocatable in case of main array shape not constant
|
// make array copy allocatable in case of assumed-shape array
|
||||||
if(checkDynamicArray(array_p))
|
if(dynamic_array)
|
||||||
{
|
{
|
||||||
// insert allocatable keyword in declaration
|
// insert allocatable keyword in declaration
|
||||||
auto *kword_list = decl_stmt->expr(2);
|
auto *kword_list = decl_stmt->expr(2);
|
||||||
|
|||||||
Reference in New Issue
Block a user
без проверки