Compare commits
2 Commits
24cc61d72f
...
fdab7096d4
| Author | SHA1 | Date | |
|---|---|---|---|
| fdab7096d4 | |||
| b5c923193c |
Submodule projects/dvm updated: 37910dba0a...3a567d7582
@@ -440,18 +440,15 @@ bool replaceConstantRec(SgExpression *&exp)
|
||||
if (exp->variant() == CONST_REF)
|
||||
{
|
||||
SgExpression *ret = ReplaceParameter_(exp);
|
||||
|
||||
int sign = 1;
|
||||
SgExpression* toCalc = ret;
|
||||
if (toCalc->variant() == UNARY_ADD_OP)
|
||||
toCalc = toCalc->lhs();
|
||||
|
||||
if (toCalc->variant() == MINUS_OP)
|
||||
if (ret->variant() == UNARY_ADD_OP)
|
||||
toCalc = ret->lhs();
|
||||
if (ret->variant() == MINUS_OP)
|
||||
{
|
||||
toCalc = toCalc->lhs();
|
||||
toCalc = ret->lhs();
|
||||
sign = -1;
|
||||
}
|
||||
|
||||
if (toCalc->isInteger())
|
||||
{
|
||||
exp = new SgValueExp(sign * toCalc->valueInteger());
|
||||
|
||||
@@ -17,6 +17,20 @@ using std::pair;
|
||||
|
||||
#define DEBUG_TRACE 0
|
||||
|
||||
static bool findAlloatableKeyword(SgExpression* exp)
|
||||
{
|
||||
if (exp)
|
||||
{
|
||||
if (exp->variant() == ALLOCATABLE_OP)
|
||||
return true;
|
||||
|
||||
return findAlloatableKeyword(exp->lhs()) || findAlloatableKeyword(exp->rhs());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static bool checkDynamicArray(DIST::Array *array)
|
||||
{
|
||||
for (const auto &bounds : array->GetSizes())
|
||||
@@ -45,69 +59,27 @@ static SgExpression* findExprWithVariant(SgExpression* exp, int variant)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool switchToDeclarationFile(DIST::Array* array_p,
|
||||
pair<string, int>& decl_place,
|
||||
const string ¤t_file_name,
|
||||
FuncInfo *current_func)
|
||||
static bool checkAssumedSize(SgStatement *st, const string &arrayName, const string ¤tFile)
|
||||
{
|
||||
if (!array_p)
|
||||
return false;
|
||||
|
||||
|
||||
// try to find declaration from current function
|
||||
for (const auto &p : array_p->GetDeclInfo())
|
||||
{
|
||||
if (p.first == current_file_name &&
|
||||
current_func->linesNum.first <= p.second &&
|
||||
p.second <= current_func->linesNum.second)
|
||||
{
|
||||
decl_place = p;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto &p : array_p->GetDeclInfo())
|
||||
{
|
||||
if (SgFile::switchToFile(p.first) != -1)
|
||||
{
|
||||
decl_place = p;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool checkAssumedSize(const string &array_name, DIST::Array* array_p, const string ¤t_file_name, FuncInfo *current_func)
|
||||
{
|
||||
if (!array_p)
|
||||
return true; // raise true to prevent array from copying
|
||||
|
||||
bool found = false;
|
||||
|
||||
pair<string, int> decl_place;
|
||||
DIST::Array* array_p = getArrayFromDeclarated(st, arrayName);
|
||||
|
||||
if (!switchToDeclarationFile(array_p, decl_place, current_file_name, current_func))
|
||||
return true;
|
||||
auto place = *array_p->GetDeclInfo().begin();
|
||||
auto decl_file_name = place.first;
|
||||
|
||||
auto *st = SgStatement::getStatementByFileAndLine(decl_place.first, decl_place.second);
|
||||
SgFile::switchToFile(decl_file_name);
|
||||
|
||||
SgExpression* list = st->expr(0);
|
||||
while (list)
|
||||
{
|
||||
if (list->lhs() &&
|
||||
list->lhs()->symbol() &&
|
||||
list->lhs()->symbol()->identifier() &&
|
||||
list->lhs()->symbol()->identifier() == array_name
|
||||
)
|
||||
if (list->lhs() && list->lhs()->symbol()->identifier() == arrayName)
|
||||
{
|
||||
if(findExprWithVariant(list->lhs(), STAR_RANGE))
|
||||
found = true;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
list = list->rhs();
|
||||
}
|
||||
|
||||
if (!found)
|
||||
@@ -117,8 +89,7 @@ static bool checkAssumedSize(const string &array_name, DIST::Array* array_p, con
|
||||
found = true;
|
||||
}
|
||||
|
||||
if (SgFile::switchToFile(current_file_name) == -1)
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__); // can't switch back to file with array usage
|
||||
SgFile::switchToFile(currentFile);
|
||||
|
||||
return found;
|
||||
}
|
||||
@@ -135,10 +106,7 @@ static void findArrays(SgExpression* exp, set<SgSymbol*>& arrays)
|
||||
}
|
||||
}
|
||||
|
||||
static void populateDistributedIoArrays(map<SgSymbol*, set<SgStatement*>>& arrays,
|
||||
SgStatement* stat,
|
||||
const string& current_file_name,
|
||||
FuncInfo *current_func)
|
||||
static void populateDistributedIoArrays(map<SgSymbol*, set<SgStatement*>>& arrays, SgStatement* stat, const string& current_file)
|
||||
{
|
||||
auto var = stat->variant();
|
||||
|
||||
@@ -241,13 +209,11 @@ static void populateDistributedIoArrays(map<SgSymbol*, set<SgStatement*>>& array
|
||||
DIST::Array* array_p = getArrayFromDeclarated(declaratedInStmt(by_symb), array_name);
|
||||
if (array_p &&
|
||||
array_p->GetDistributeFlagVal() == Distribution::distFlag::IO_PRIV &&
|
||||
!checkAssumedSize(array_name, array_p, current_file_name, current_func)
|
||||
!checkAssumedSize(declaratedInStmt(by_symb), array_name, current_file) &&
|
||||
arrays[by_symb].insert(stat).second
|
||||
)
|
||||
{
|
||||
auto inserted = arrays[by_symb].insert(stat).second;
|
||||
|
||||
if (inserted)
|
||||
__spf_print(DEBUG_TRACE, "[%d]: add array %s %p\n", stat->lineNumber(), array_p->GetName().c_str(), by_symb);
|
||||
__spf_print(DEBUG_TRACE, "[%d]: add array %s\n", stat->lineNumber(), array_p->GetName().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -376,7 +342,8 @@ static void replaceArrayInFragment(SgSymbol* replace_symb,
|
||||
SgSymbol* replace_by,
|
||||
SgStatement* start,
|
||||
SgStatement* last,
|
||||
FuncInfo *func_info)
|
||||
FuncInfo *func_info,
|
||||
const string& filename)
|
||||
{
|
||||
while (start->lexNext() && (!isSgExecutableStatement(start->lexNext()) || start->lexNext()->variant() == ALLOCATE_STMT))
|
||||
start = start->lexNext();
|
||||
@@ -486,9 +453,9 @@ static bool ioReginBorder(SgStatement* stat, SgStatement* last_io_bound)
|
||||
}
|
||||
|
||||
void replaceDistributedArraysInIO(vector<ParallelRegion*>& regions,
|
||||
const map<string, vector<FuncInfo*>>& allFuncInfo,
|
||||
map<string, vector<Messages>>& SPF_messages,
|
||||
map<string, map<int, set<string>>>& newDeclsToInclude)
|
||||
const map<string, vector<FuncInfo*>>& allFuncInfo,
|
||||
map<string, vector<Messages>>& SPF_messages,
|
||||
map<string, map<int, set<string>>>& newDeclsToInclude)
|
||||
{
|
||||
map<SgSymbol*, SgSymbol*> created_copies;
|
||||
map<string, map<int, set<string>>> copied_syms;
|
||||
@@ -497,14 +464,14 @@ void replaceDistributedArraysInIO(vector<ParallelRegion*>& regions,
|
||||
{
|
||||
__spf_print(DEBUG_TRACE, "[%s]: enter region\n", region->GetName().c_str());
|
||||
|
||||
for (auto& lines_by_file : region->GetAllLinesToModify())
|
||||
for (auto& linesByFile : region->GetAllLinesToModify())
|
||||
{
|
||||
const auto& current_file_name = lines_by_file.first;
|
||||
const auto& filename = linesByFile.first;
|
||||
|
||||
if (SgFile::switchToFile(current_file_name) == -1)
|
||||
if (SgFile::switchToFile(filename) == -1)
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
auto func_info_it = allFuncInfo.find(current_file_name);
|
||||
auto func_info_it = allFuncInfo.find(filename);
|
||||
if (func_info_it == allFuncInfo.end())
|
||||
{
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
@@ -514,9 +481,9 @@ void replaceDistributedArraysInIO(vector<ParallelRegion*>& regions,
|
||||
auto *lbound_symb = new SgSymbol(PROCEDURE_NAME, "lbound");
|
||||
auto *ubound_symb = new SgSymbol(PROCEDURE_NAME, "ubound");
|
||||
|
||||
for (auto& lines : lines_by_file.second)
|
||||
for (auto& lines : linesByFile.second)
|
||||
{
|
||||
__spf_print(DEBUG_TRACE, "[fragment] %s: %d:%d %d\n", current_file_name.c_str(), lines.lines.first,
|
||||
__spf_print(DEBUG_TRACE, "[fragment] %s: %d:%d %d\n", filename.c_str(), lines.lines.first,
|
||||
lines.lines.second, lines.isImplicit());
|
||||
|
||||
SgStatement* curr_stmt, * end;
|
||||
@@ -588,70 +555,90 @@ void replaceDistributedArraysInIO(vector<ParallelRegion*>& regions,
|
||||
string array_name = string(array_to_copy->identifier());
|
||||
DIST::Array* array_p = getArrayFromDeclarated(declaratedInStmt(array_to_copy), array_name);
|
||||
|
||||
// at this point all considered arrays must have DIST::Array* references
|
||||
if (!array_p)
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
// ... and be declared in switchable files (not in headers)
|
||||
pair<string, int> decl_place;
|
||||
if (!switchToDeclarationFile(array_p, decl_place, current_file_name, current_func_info))
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
bool fromModule = (array_p->GetLocation().first == DIST::l_MODULE);
|
||||
const string locationName = array_p->GetLocation().second;
|
||||
|
||||
auto place = *array_p->GetDeclInfo().begin();
|
||||
auto decl_file_name = place.first;
|
||||
string suffix = "_io_l";
|
||||
|
||||
switch (array_p->GetLocation().first)
|
||||
if (fromModule)
|
||||
suffix = "_io_m";
|
||||
|
||||
pair<SgSymbol*, SgSymbol*> copied;
|
||||
copied.first = array_to_copy;
|
||||
|
||||
if (SgFile::switchToFile(decl_file_name) == -1)
|
||||
{
|
||||
case DIST::l_MODULE:
|
||||
suffix = "_io_m";
|
||||
break;
|
||||
case DIST::l_COMMON:
|
||||
suffix = "_io_c";
|
||||
break;
|
||||
auto* func_stmt = curr_stmt->getScopeForDeclare();
|
||||
|
||||
SgStatement* insertPlace = NULL;
|
||||
for (auto iterator = func_stmt->lexNext();
|
||||
!isSgExecutableStatement(iterator) || isSPF_stat(iterator) &&
|
||||
!(iterator->variant() == SPF_PARALLEL_REG_DIR || iterator->variant() == SPF_END_PARALLEL_REG_DIR);
|
||||
iterator = iterator->lexNext())
|
||||
{
|
||||
insertPlace = iterator;
|
||||
}
|
||||
|
||||
//NULL - no decl stats in function!
|
||||
if (!insertPlace)
|
||||
insertPlace = func_stmt;
|
||||
|
||||
auto st = insertPlace->controlParent();
|
||||
if (st->variant() == GLOBAL)
|
||||
st = insertPlace;
|
||||
|
||||
auto& copied_symb = array_to_copy->copy();
|
||||
copied.second = &copied_symb;
|
||||
|
||||
auto new_name = string(array_to_copy->identifier()) + "_io_c";
|
||||
copied_symb.changeName(new_name.c_str());
|
||||
|
||||
auto stat = array_to_copy->makeVarDeclStmt();
|
||||
auto res = CalculateInteger(stat->expr(0)->copyPtr());
|
||||
res->lhs()->setSymbol(copied_symb);
|
||||
stat->setExpression(0, res);
|
||||
|
||||
insertPlace->insertStmtAfter(*stat, *st);
|
||||
}
|
||||
|
||||
auto copied_symbol = copyArray(decl_place,
|
||||
array_p,
|
||||
lines_by_file.second,
|
||||
suffix + to_string(region->GetId()),
|
||||
decl_place.first,
|
||||
newDeclsToInclude,
|
||||
copied_syms);
|
||||
|
||||
|
||||
auto* decl_stmt = SgStatement::getStatementByFileAndLine(decl_place.first, decl_place.second);
|
||||
|
||||
// created declaration statement located right after original one
|
||||
if (!decl_stmt || !decl_stmt->lexNext())
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
decl_stmt = decl_stmt->lexNext();
|
||||
|
||||
// insert !$SPF ANALYSIS(PROCESS_PRIVATE(array)) directive before declaration statement
|
||||
|
||||
string dir_str;
|
||||
if (decl_stmt->comments())
|
||||
else
|
||||
{
|
||||
auto str_comment = string(decl_stmt->comments());
|
||||
if (str_comment.size() && str_comment.back() != '\n')
|
||||
dir_str += "\n";
|
||||
copied = copyArray(place, array_p, linesByFile.second, suffix + to_string(region->GetId()), decl_file_name, newDeclsToInclude, copied_syms);
|
||||
}
|
||||
|
||||
dir_str += "!$SPF ANALYSIS(PROCESS_PRIVATE(" + string(copied_symbol.second->identifier()) + "))\n";
|
||||
decl_stmt->addComment(dir_str.c_str());
|
||||
|
||||
created_copies.insert({ array_to_copy, copied_symbol.second });
|
||||
SgStatement* decl = SgStatement::getStatementByFileAndLine(place.first, place.second);
|
||||
|
||||
// make array copy allocatable in case of main array shape not constant
|
||||
if (decl)
|
||||
decl = decl->lexNext();
|
||||
|
||||
if (decl)
|
||||
{
|
||||
string dir_str;
|
||||
if (decl->comments())
|
||||
{
|
||||
string str_comment = string(decl->comments());
|
||||
if (str_comment.size() && str_comment.back() != '\n')
|
||||
dir_str += "\n";
|
||||
}
|
||||
|
||||
dir_str += "!$SPF ANALYSIS(PROCESS_PRIVATE(" + string(copied.second->identifier()) + "))\n";
|
||||
decl->addComment(dir_str.c_str());
|
||||
}
|
||||
|
||||
created_copies.insert({ array_to_copy, copied.second });
|
||||
|
||||
// make array-copy allocatable in case of main array shape not constant
|
||||
if(checkDynamicArray(array_p))
|
||||
{
|
||||
// insert allocatable keyword in declaration
|
||||
auto *kword_list = decl_stmt->expr(2);
|
||||
if (!findExprWithVariant(kword_list, ALLOCATABLE_OP))
|
||||
auto *kword_list = decl->expr(2);
|
||||
if (!findAlloatableKeyword(kword_list))
|
||||
{
|
||||
if (!kword_list)
|
||||
{
|
||||
kword_list = new SgExprListExp();
|
||||
decl_stmt->setExpression(2, *kword_list);
|
||||
decl->setExpression(2, *kword_list);
|
||||
}
|
||||
|
||||
while (kword_list->rhs())
|
||||
@@ -666,30 +653,29 @@ void replaceDistributedArraysInIO(vector<ParallelRegion*>& regions,
|
||||
kword_list->setLhs(new SgExpression(ALLOCATABLE_OP));
|
||||
}
|
||||
|
||||
// can't switch back to file with array usage
|
||||
if (SgFile::switchToFile(current_file_name) == -1)
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
// insert allocate(a_l(lbound(a, 1):ubound(a,1),...)) statement
|
||||
SgStatement* allocate_stmt_place = NULL;
|
||||
SgFile::switchToFile(filename);
|
||||
SgStatement* insertPlace = NULL;
|
||||
|
||||
auto* func_stmt = curr_stmt->getScopeForDeclare();
|
||||
for (auto iterator = func_stmt->lexNext();
|
||||
iterator && !isSgExecutableStatement(iterator);
|
||||
!isSgExecutableStatement(iterator) || isSPF_stat(iterator) &&
|
||||
!(iterator->variant() == SPF_PARALLEL_REG_DIR || iterator->variant() == SPF_END_PARALLEL_REG_DIR);
|
||||
iterator = iterator->lexNext())
|
||||
{
|
||||
allocate_stmt_place = iterator;
|
||||
insertPlace = iterator;
|
||||
}
|
||||
|
||||
//NULL - no decl stats in function!
|
||||
if (!allocate_stmt_place)
|
||||
allocate_stmt_place = func_stmt;
|
||||
if (!insertPlace)
|
||||
insertPlace = func_stmt;
|
||||
|
||||
auto *allocate_stmt_parent = allocate_stmt_place->controlParent();
|
||||
if (allocate_stmt_parent->variant() == GLOBAL)
|
||||
allocate_stmt_parent = allocate_stmt_place;
|
||||
auto st = insertPlace->controlParent();
|
||||
if (st->variant() == GLOBAL)
|
||||
st = insertPlace;
|
||||
|
||||
auto *created_array_ref = new SgArrayRefExp(*copied_symbol.second);
|
||||
auto *stat = new SgStatement(ALLOCATE_STMT);
|
||||
auto *created_array_ref = new SgArrayRefExp(*copied.second);
|
||||
|
||||
auto* dim_list = new SgExprListExp();
|
||||
created_array_ref->setLhs(dim_list);
|
||||
@@ -722,10 +708,9 @@ void replaceDistributedArraysInIO(vector<ParallelRegion*>& regions,
|
||||
}
|
||||
}
|
||||
|
||||
auto *allocate_stmt = new SgStatement(ALLOCATE_STMT);
|
||||
allocate_stmt->setExpression(0, created_array_ref);
|
||||
stat->setExpression(0, created_array_ref);
|
||||
|
||||
allocate_stmt_place->insertStmtAfter(*allocate_stmt, *allocate_stmt_parent);
|
||||
insertPlace->insertStmtAfter(*stat, *st);
|
||||
|
||||
// insert deallocate statemens before all returns
|
||||
auto *find_return_stmt = func_stmt;
|
||||
@@ -743,7 +728,7 @@ void replaceDistributedArraysInIO(vector<ParallelRegion*>& regions,
|
||||
auto *dealloc_stmt = new SgStatement(DEALLOCATE_STMT);
|
||||
|
||||
dealloc_stmt->setExpression(0, new SgExprListExp());
|
||||
dealloc_stmt->expr(0)->setLhs(new SgArrayRefExp(*copied_symbol.second));
|
||||
dealloc_stmt->expr(0)->setLhs(new SgArrayRefExp(*copied.second));
|
||||
|
||||
find_return_stmt->insertStmtAfter(*dealloc_stmt, *next->controlParent());
|
||||
|
||||
@@ -755,9 +740,9 @@ void replaceDistributedArraysInIO(vector<ParallelRegion*>& regions,
|
||||
}
|
||||
}
|
||||
|
||||
// can't switch back to file with array usage
|
||||
if (SgFile::switchToFile(current_file_name) == -1)
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
SgFile::switchToFile(filename);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -769,7 +754,7 @@ void replaceDistributedArraysInIO(vector<ParallelRegion*>& regions,
|
||||
{
|
||||
auto it = created_copies.find(p.first);
|
||||
if (it != created_copies.end())
|
||||
replaceArrayInFragment(p.first, p.second, it->second, last_io_bound, curr_stmt, current_func_info);
|
||||
replaceArrayInFragment(p.first, p.second, it->second, last_io_bound, curr_stmt, current_func_info, filename);
|
||||
else
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
}
|
||||
@@ -789,7 +774,7 @@ void replaceDistributedArraysInIO(vector<ParallelRegion*>& regions,
|
||||
}
|
||||
}
|
||||
|
||||
populateDistributedIoArrays(need_replace, curr_stmt, current_file_name, current_func_info);
|
||||
populateDistributedIoArrays(need_replace, curr_stmt, filename);
|
||||
curr_stmt = curr_stmt->lexNext();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define VERSION_SPF "2441"
|
||||
#define VERSION_SPF "2440"
|
||||
|
||||
Reference in New Issue
Block a user