region merging: derive array types
This commit is contained in:
@@ -190,12 +190,61 @@ static pair<vector<SgStatement *>, SgSymbol *> generateDeclaration(const string
|
|||||||
return {{decl, comm}, array_symbol};
|
return {{decl, comm}, array_symbol};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SgExpression* findExprWithVariant(SgExpression* exp, int variant)
|
||||||
|
{
|
||||||
|
if (exp)
|
||||||
|
{
|
||||||
|
if (exp->variant() == variant)
|
||||||
|
return exp;
|
||||||
|
|
||||||
|
auto *l = findExprWithVariant(exp->lhs(), variant);
|
||||||
|
if (l)
|
||||||
|
return l;
|
||||||
|
|
||||||
|
auto *r = findExprWithVariant(exp->rhs(), variant);
|
||||||
|
if (r)
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
SgType* GetArrayType(DIST::Array *array)
|
||||||
|
{
|
||||||
|
if (!array)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
for (const auto& decl_place : array->GetDeclInfo())
|
||||||
|
{
|
||||||
|
if (SgFile::switchToFile(decl_place.first) != -1)
|
||||||
|
{
|
||||||
|
auto* decl = SgStatement::getStatementByFileAndLine(decl_place.first, decl_place.second);
|
||||||
|
if (decl)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
auto* found_type = isSgTypeExp(findExprWithVariant(decl->expr(i), TYPE_OP));
|
||||||
|
if (found_type)
|
||||||
|
return found_type->type();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
SgSymbol *insertDeclIfNeeded(const string &array_name,
|
SgSymbol *insertDeclIfNeeded(const string &array_name,
|
||||||
const string &common_block_name,
|
const string &common_block_name,
|
||||||
DIST::Array *example_array,
|
DIST::Array *example_array,
|
||||||
FuncInfo *dest,
|
FuncInfo *dest,
|
||||||
unordered_map<FuncInfo *, unordered_map<string, SgSymbol *>> &inserted_arrays)
|
unordered_map<FuncInfo *, unordered_map<string, SgSymbol *>> &inserted_arrays)
|
||||||
{
|
{
|
||||||
|
auto *type = GetArrayType(example_array);
|
||||||
|
|
||||||
|
if (!type)
|
||||||
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
if (SgFile::switchToFile(dest->fileName) == -1)
|
if (SgFile::switchToFile(dest->fileName) == -1)
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
@@ -218,7 +267,7 @@ SgSymbol *insertDeclIfNeeded(const string &array_name,
|
|||||||
|
|
||||||
auto generated = generateDeclaration(array_name, common_block_name,
|
auto generated = generateDeclaration(array_name, common_block_name,
|
||||||
example_array->GetSizes(),
|
example_array->GetSizes(),
|
||||||
SgTypeInt(), dest->funcPointer);
|
type, dest->funcPointer);
|
||||||
for (auto *new_stmt : generated.first)
|
for (auto *new_stmt : generated.first)
|
||||||
st->insertStmtBefore(*new_stmt, *dest->funcPointer);
|
st->insertStmtBefore(*new_stmt, *dest->funcPointer);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user