add pass REMOVE_DIST_ARRAYS_FROM_IO, make copyArray fuction from resolve_par_regions public #53
@@ -126,16 +126,70 @@ static void populateDistributedIoArrays(map<DIST::Array*, set<SgStatement*>>& ar
|
|||||||
__spf_print(DEBUG_TRACE, "[replace]\n");
|
__spf_print(DEBUG_TRACE, "[replace]\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void replaceArrayRec(SgSymbol* arr, SgSymbol* replace_by, SgExpression* exp)
|
static void replaceArrayRec(SgSymbol* arr, SgSymbol* replace_by, SgExpression* exp, bool& has_read, bool& has_write, bool from_read, bool from_write)
|
||||||
{
|
{
|
||||||
if (!exp)
|
if (!exp)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (exp->symbol() && strcmp(exp->symbol()->identifier(), arr->identifier()) == 0)
|
if (exp->symbol() && strcmp(exp->symbol()->identifier(), arr->identifier()) == 0)
|
||||||
|
{
|
||||||
|
has_read |= from_read;
|
||||||
|
has_write |= from_write;
|
||||||
exp->setSymbol(replace_by);
|
exp->setSymbol(replace_by);
|
||||||
|
}
|
||||||
|
|
||||||
replaceArrayRec(arr, replace_by, exp->lhs());
|
switch (exp->variant())
|
||||||
replaceArrayRec(arr, replace_by, exp->rhs());
|
{
|
||||||
|
case FUNC_CALL:
|
||||||
|
{
|
||||||
|
replaceArrayRec(arr, replace_by, exp->rhs(), has_read, has_write, true, false);
|
||||||
|
replaceArrayRec(arr, replace_by, exp->lhs(), has_read, has_write, true, true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case EXPR_LIST:
|
||||||
|
{
|
||||||
|
replaceArrayRec(arr, replace_by, exp->lhs(), has_read, has_write, from_read, from_write);
|
||||||
|
replaceArrayRec(arr, replace_by, exp->rhs(), has_read, has_write, from_read, from_write);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
replaceArrayRec(arr, replace_by, exp->lhs(), has_read, has_write, true, false);
|
||||||
|
replaceArrayRec(arr, replace_by, exp->rhs(), has_read, has_write, true, false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void replaceArrayRec(SgSymbol* arr, SgSymbol* replace_by, SgStatement* st, bool& has_read, bool& has_write)
|
||||||
|
{
|
||||||
|
if (!st)
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch (st->variant())
|
||||||
|
{
|
||||||
|
case ASSIGN_STAT:
|
||||||
|
case READ_STAT:
|
||||||
|
{
|
||||||
|
replaceArrayRec(arr, replace_by, st->expr(0), has_read, has_write, false, true);
|
||||||
|
replaceArrayRec(arr, replace_by, st->expr(1), has_read, has_write, true, false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PROC_STAT:
|
||||||
|
case FUNC_STAT:
|
||||||
|
{
|
||||||
|
replaceArrayRec(arr, replace_by, st->expr(0), has_read, has_write, true, false);
|
||||||
|
replaceArrayRec(arr, replace_by, st->expr(1), has_read, has_write, true, true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
replaceArrayRec(arr, replace_by, st->expr(i), has_read, has_write, true, false);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void copyArrayBetweenStatements(SgSymbol* replace_symb, SgSymbol* replace_by, SgStatement* start, SgStatement* last)
|
static void copyArrayBetweenStatements(SgSymbol* replace_symb, SgSymbol* replace_by, SgStatement* start, SgStatement* last)
|
||||||
@@ -144,10 +198,15 @@ static void copyArrayBetweenStatements(SgSymbol* replace_symb, SgSymbol* replace
|
|||||||
start = start->lexNext();
|
start = start->lexNext();
|
||||||
|
|
||||||
auto* stop = last->lexNext();
|
auto* stop = last->lexNext();
|
||||||
for (auto* st = start; st != stop; st = st->lexNext())
|
|
||||||
for (int i = 0; i < 3; i++)
|
|
||||||
replaceArrayRec(replace_symb, replace_by, st->expr(i));
|
|
||||||
|
|
||||||
|
bool has_read = false, has_write = false;
|
||||||
|
|
||||||
|
for (auto* st = start; st != stop; st = st->lexNext())
|
||||||
|
replaceArrayRec(replace_symb, replace_by, st, has_read, has_write);
|
||||||
|
|
||||||
|
|
||||||
|
if (has_read)
|
||||||
|
{
|
||||||
// A_copy = A
|
// A_copy = A
|
||||||
SgAssignStmt* assign = new SgAssignStmt(*new SgArrayRefExp(*replace_by), *new SgArrayRefExp(*replace_symb));
|
SgAssignStmt* assign = new SgAssignStmt(*new SgArrayRefExp(*replace_by), *new SgArrayRefExp(*replace_symb));
|
||||||
assign->setlineNumber(getNextNegativeLineNumber()); // before region
|
assign->setlineNumber(getNextNegativeLineNumber()); // before region
|
||||||
@@ -156,13 +215,17 @@ static void copyArrayBetweenStatements(SgSymbol* replace_symb, SgSymbol* replace
|
|||||||
parent = parent->controlParent();
|
parent = parent->controlParent();
|
||||||
|
|
||||||
start->insertStmtAfter(*assign, *parent);
|
start->insertStmtAfter(*assign, *parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (has_write)
|
||||||
|
{
|
||||||
// A = A_reg
|
// A = A_reg
|
||||||
assign = new SgAssignStmt(*new SgArrayRefExp(*replace_symb), *new SgArrayRefExp(*replace_by));
|
SgAssignStmt* assign = new SgAssignStmt(*new SgArrayRefExp(*replace_symb), *new SgArrayRefExp(*replace_by));
|
||||||
//TODO: bug with insertion
|
//TODO: bug with insertion
|
||||||
//assign->setlineNumber(getNextNegativeLineNumber()); // after region
|
//assign->setlineNumber(getNextNegativeLineNumber()); // after region
|
||||||
last->insertStmtBefore(*assign, *(last->controlParent()));
|
last->insertStmtBefore(*assign, *(last->controlParent()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void replaceArrayInFragment(DIST::Array* arr, const set<SgStatement*> usages, SgSymbol* replace_by, SgStatement* start, SgStatement* last, const string& filename)
|
static void replaceArrayInFragment(DIST::Array* arr, const set<SgStatement*> usages, SgSymbol* replace_by, SgStatement* start, SgStatement* last, const string& filename)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user