improved intent insertion
This commit is contained in:
@@ -736,13 +736,13 @@ static void fillIn(FuncInfo *currF, SgExpression *ex, const map<string, int> &pa
|
||||
}
|
||||
}
|
||||
|
||||
static void fillOut(FuncInfo* currF, const string& symb, const map<string, int>& parNames)
|
||||
static void fillType(FuncInfo* currF, const string& symb, const map<string, int>& parNames, const int type)
|
||||
{
|
||||
if (symb != "")
|
||||
{
|
||||
auto it = parNames.find(symb);
|
||||
if (it != parNames.end())
|
||||
currF->funcParams.inout_types[it->second] |= OUT_BIT;
|
||||
currF->funcParams.inout_types[it->second] |= type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -751,7 +751,7 @@ static void checkSpecList(SgExpression* pair, FuncInfo* currF, const map<string,
|
||||
auto valExp = isSgKeywordValExp(pair->lhs());
|
||||
if (valExp->value() == string("unit"))
|
||||
if (pair->rhs() && pair->rhs()->symbol())
|
||||
fillOut(currF, pair->rhs()->symbol()->identifier(), parNames);
|
||||
fillType(currF, pair->rhs()->symbol()->identifier(), parNames, INOUT_BIT);
|
||||
}
|
||||
|
||||
static void checkSpecList(SgExpression *spec, FuncInfo* currF, const map<string, int>& parNames)
|
||||
@@ -814,7 +814,7 @@ static void fillInOut(FuncInfo *currF, SgStatement *start, SgStatement *last, co
|
||||
if (left->lhs()->symbol())
|
||||
symb = left->lhs()->symbol()->identifier();
|
||||
}
|
||||
fillOut(currF, symb, parNames);
|
||||
fillType(currF, symb, parNames, OUT_BIT);
|
||||
} // TODO: need to extend
|
||||
else if (st->variant() == READ_STAT)
|
||||
{
|
||||
@@ -830,7 +830,7 @@ static void fillInOut(FuncInfo *currF, SgStatement *start, SgStatement *last, co
|
||||
string symb = "";
|
||||
if (item->symbol())
|
||||
symb = item->symbol()->identifier();
|
||||
fillOut(currF, symb, parNames);
|
||||
fillType(currF, symb, parNames, OUT_BIT);
|
||||
}
|
||||
else if (item->variant() == IOACCESS)
|
||||
{
|
||||
@@ -851,7 +851,7 @@ static void fillInOut(FuncInfo *currF, SgStatement *start, SgStatement *last, co
|
||||
string symb = "";
|
||||
if (item->symbol())
|
||||
symb = item->symbol()->identifier();
|
||||
fillOut(currF, symb, parNames);
|
||||
fillType(currF, symb, parNames, OUT_BIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -887,7 +887,7 @@ static void fillInOut(FuncInfo *currF, SgStatement *start, SgStatement *last, co
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
if (types[z] == OUT_BIT || types[z] == INOUT_BIT)
|
||||
fillOut(currF, arg->symbol()->identifier(), parNames);
|
||||
fillType(currF, arg->symbol()->identifier(), parNames, OUT_BIT);
|
||||
if (types[z] == IN_BIT || types[z] == INOUT_BIT)
|
||||
fillIn(currF, arg, parNames);
|
||||
}
|
||||
@@ -997,11 +997,11 @@ static FuncInfo* createNewFuction(const string& funcName, SgStatement *st, SgSta
|
||||
return currInfo;
|
||||
}
|
||||
|
||||
static void analyzeFunction(const string& funcName, const string& containsPrefix,
|
||||
SgStatement *function, SgStatement* entry, map<string, vector<FuncInfo*>>& allFuncInfo,
|
||||
const map<int, LoopGraph*>& mapLoopGraph, vector<Messages>& messagesForFile,
|
||||
vector<SgStatement*>& containsFunctions,
|
||||
const set<SgStatement*>& activeOps)
|
||||
static FuncInfo* analyzeFunction(const string& funcName, const string& containsPrefix,
|
||||
SgStatement *function, SgStatement* entry, map<string, vector<FuncInfo*>>& allFuncInfo,
|
||||
const map<int, LoopGraph*>& mapLoopGraph, vector<Messages>& messagesForFile,
|
||||
vector<SgStatement*>& containsFunctions,
|
||||
const set<SgStatement*>& activeOps)
|
||||
{
|
||||
SgStatement* st = function;
|
||||
SgStatement* lastNode = st->lastNodeOfStmt();
|
||||
@@ -1193,6 +1193,8 @@ static void analyzeFunction(const string& funcName, const string& containsPrefix
|
||||
|
||||
st = st->lexNext();
|
||||
}
|
||||
|
||||
return procInfo;
|
||||
}
|
||||
|
||||
static set<SgStatement*> fillActiveOperators(const vector<SAPFOR::BasicBlock*>& blocks)
|
||||
@@ -1269,6 +1271,7 @@ void functionAnalyzer(SgFile *file, map<string, vector<FuncInfo*>> &allFuncInfo,
|
||||
}
|
||||
}
|
||||
|
||||
FuncInfo* lastNonEntry = NULL;
|
||||
for (auto& function : functions)
|
||||
{
|
||||
bool isEntry = (function->variant() == ENTRY_STAT);
|
||||
@@ -1322,7 +1325,16 @@ void functionAnalyzer(SgFile *file, map<string, vector<FuncInfo*>> &allFuncInfo,
|
||||
activeOps.insert(function->controlParent());
|
||||
}
|
||||
|
||||
analyzeFunction(funcName, containsPrefix, isEntry ? function->controlParent() : function, function, allFuncInfo, mapLoopGraph, messagesForFile, containsFunctions, activeOps);
|
||||
auto procInfo = analyzeFunction(funcName, containsPrefix, isEntry ? function->controlParent() : function, function, allFuncInfo, mapLoopGraph, messagesForFile, containsFunctions, activeOps);
|
||||
|
||||
if (isEntry)
|
||||
{
|
||||
if (!lastNonEntry)
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
lastNonEntry->entry.push_back(procInfo);
|
||||
}
|
||||
else
|
||||
lastNonEntry = procInfo;
|
||||
}
|
||||
|
||||
//fill INTERFACE block from modules
|
||||
|
||||
@@ -149,6 +149,8 @@ struct FuncInfo
|
||||
std::map<std::string, FuncInfo*> interfaceBlocks;
|
||||
std::map<std::string, FuncInfo*> interfaceSynonims;
|
||||
|
||||
std::vector<FuncInfo*> entry; // all entry points
|
||||
|
||||
std::set<std::string> externalCalls;
|
||||
|
||||
bool isPure; // does this func or funcs called from this have common block[s] and have no side effects
|
||||
|
||||
@@ -1038,24 +1038,6 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
||||
}
|
||||
else if (curr_regime == TEST_PASS)
|
||||
{
|
||||
/*int funcNum = file->numberOfFunctions();
|
||||
for (int z = 0; z < funcNum; ++z)
|
||||
{
|
||||
SgStatement* f = file->functions(z);
|
||||
for (auto st = f->lexNext(); st != f->lastNodeOfStmt(); st = st->lexNext())
|
||||
{
|
||||
if (st->variant() == CONTAINS_STMT)
|
||||
break;
|
||||
if (isSgExecutableStatement(st))
|
||||
break;
|
||||
|
||||
string key = st->unparse();
|
||||
if (same_decls.find(key) == same_decls.end())
|
||||
same_decls[key] = 1;
|
||||
else
|
||||
same_decls[key]++;
|
||||
}
|
||||
}*/
|
||||
//test pass
|
||||
}
|
||||
|
||||
|
||||
@@ -369,8 +369,11 @@ map<SgStatement*, set<string>> fillFromIntent(SgStatement* header)
|
||||
return intentS;
|
||||
}
|
||||
|
||||
static void insertIntents(vector<string> identificators, SgStatement* header, map <string, SgSymbol*> parSym, int intentVariant, int intentBit)
|
||||
static void insertIntents(set<string>& identificators, SgStatement* header, const map<string, SgSymbol*>& parSym, int intentVariant, int intentBit)
|
||||
{
|
||||
if (identificators.size() == 0)
|
||||
return;
|
||||
|
||||
if (header->variant() == ENTRY_STAT)
|
||||
while (isSgProgHedrStmt(header) == NULL)
|
||||
header = header->controlParent();
|
||||
@@ -388,67 +391,58 @@ static void insertIntents(vector<string> identificators, SgStatement* header, ma
|
||||
if (stmt->variant() != ENTRY_STAT)
|
||||
lastDecl = stmt;
|
||||
|
||||
if (stmt->variant() == VAR_DECL_90)
|
||||
if (stmt->variant() == VAR_DECL_90)
|
||||
{
|
||||
SgVarDeclStmt* s = (SgVarDeclStmt*)stmt;
|
||||
for (int i = 0; i < s->numberOfAttributes(); i++)
|
||||
for (int i = 0; i < s->numberOfAttributes(); i++)
|
||||
{
|
||||
if (s->attribute(i)->variant() == intentVariant)
|
||||
{
|
||||
for (int i = 0; i < s->numberOfVars(); i++)
|
||||
for (int i = 0; i < s->numberOfVars(); i++)
|
||||
{
|
||||
for (auto it = identificators.begin(); it != identificators.end(); it++)
|
||||
{
|
||||
if (*it == s->var(i)->symbol()->identifier())
|
||||
{
|
||||
identificators.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
auto sname = s->var(i)->symbol()->identifier();
|
||||
if (identificators.count(sname))
|
||||
identificators.erase(sname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (stmt->variant() == INTENT_STMT)
|
||||
else if (stmt->variant() == INTENT_STMT)
|
||||
{
|
||||
SgIntentStmt* s = (SgIntentStmt*)stmt;
|
||||
if (s->attribute()->variant() == intentVariant)
|
||||
if (s->attribute()->variant() == intentVariant)
|
||||
{
|
||||
for (int i = 0; i < s->numberOfVars(); i++)
|
||||
for (int i = 0; i < s->numberOfVars(); i++)
|
||||
{
|
||||
for (auto it = identificators.begin(); it != identificators.end(); it++)
|
||||
{
|
||||
if (*it == s->var(i)->symbol()->identifier())
|
||||
{
|
||||
identificators.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
auto sname = s->var(i)->symbol()->identifier();
|
||||
if (identificators.count(sname))
|
||||
identificators.erase(sname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (identificators.size() > 0)
|
||||
SgExpression* attr = new SgExpression(intentVariant);
|
||||
SgExpression* args = NULL;
|
||||
for (auto& par : identificators)
|
||||
{
|
||||
SgExpression* attr = new SgExpression(intentVariant);
|
||||
SgExpression* args = NULL;
|
||||
for (auto& par : identificators)
|
||||
{
|
||||
SgExprListExp* tempArgs = new SgExprListExp();
|
||||
SgVarRefExp* tempPar = new SgVarRefExp(parSym[par]);
|
||||
tempArgs->setLhs(tempPar);
|
||||
if (args)
|
||||
tempArgs->setRhs(args);
|
||||
args = tempArgs;
|
||||
parSym[par]->setAttribute(parSym[par]->attributes() | intentBit);
|
||||
}
|
||||
if (parSym.count(par) == 0)
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
auto s = parSym.at(par);
|
||||
|
||||
SgExprListExp* tempArgs = new SgExprListExp();
|
||||
SgVarRefExp* tempPar = new SgVarRefExp(s);
|
||||
tempArgs->setLhs(tempPar);
|
||||
if (args)
|
||||
{
|
||||
SgIntentStmt* intent = new SgIntentStmt(*args, *attr);
|
||||
lastDecl->insertStmtAfter(*intent, (header == lastDecl) ? *header : *lastDecl->controlParent());
|
||||
}
|
||||
tempArgs->setRhs(args);
|
||||
args = tempArgs;
|
||||
s->setAttribute(s->attributes() | intentBit);
|
||||
}
|
||||
|
||||
if (args)
|
||||
{
|
||||
SgIntentStmt* intent = new SgIntentStmt(*args, *attr);
|
||||
lastDecl->insertStmtAfter(*intent, (header == lastDecl) ? *header : *lastDecl->controlParent());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -476,12 +470,14 @@ static SgSymbol* getParameter(SgStatement* stat, int n)
|
||||
|
||||
static void intentInsert(const FuncInfo* func, SgStatement* headerSt)
|
||||
{
|
||||
vector <string> InIdentificators;
|
||||
vector <string> OutIdentificators;
|
||||
vector <string> InOutIdentificators;
|
||||
|
||||
if (func->funcPointer->variant() == ENTRY_STAT)
|
||||
return;
|
||||
|
||||
map <string, SgSymbol*> parSym;
|
||||
set<string> InIdentificators;
|
||||
set<string> OutIdentificators;
|
||||
set<string> InOutIdentificators;
|
||||
|
||||
map<string, SgSymbol*> parSym;
|
||||
set<string> intentS;
|
||||
auto intentsByStat = fillFromIntent(headerSt);
|
||||
for (auto& elem : intentsByStat)
|
||||
@@ -494,8 +490,7 @@ static void intentInsert(const FuncInfo* func, SgStatement* headerSt)
|
||||
SgSymbol* parS = getParameter(headerSt, i);
|
||||
const string ident = parS->identifier();
|
||||
|
||||
if (ident == "*" ||
|
||||
parS->attributes() & EXTERNAL_BIT)
|
||||
if (ident == "*" || parS->attributes() & EXTERNAL_BIT)
|
||||
continue;
|
||||
|
||||
parSym[ident] = parS;
|
||||
@@ -503,11 +498,41 @@ static void intentInsert(const FuncInfo* func, SgStatement* headerSt)
|
||||
continue;
|
||||
|
||||
if (func->funcParams.isArgInOut(i))
|
||||
InOutIdentificators.push_back(ident);
|
||||
InOutIdentificators.insert(ident);
|
||||
else if (func->funcParams.isArgIn(i))
|
||||
InIdentificators.push_back(ident);
|
||||
InIdentificators.insert(ident);
|
||||
else if (func->funcParams.isArgOut(i))
|
||||
OutIdentificators.push_back(ident);
|
||||
OutIdentificators.insert(ident);
|
||||
}
|
||||
|
||||
//remove conflicted intents
|
||||
for (auto& entry : func->entry)
|
||||
{
|
||||
for (int i = 0; i < entry->funcParams.countOfPars; i++)
|
||||
{
|
||||
const auto& ident = entry->funcParams.identificators[i];
|
||||
if (entry->funcParams.isArgInOut(i))
|
||||
{
|
||||
if (InIdentificators.count(ident))
|
||||
InIdentificators.erase(ident);
|
||||
if (OutIdentificators.count(ident))
|
||||
OutIdentificators.erase(ident);
|
||||
}
|
||||
else if (entry->funcParams.isArgIn(i))
|
||||
{
|
||||
if (InOutIdentificators.count(ident))
|
||||
InOutIdentificators.erase(ident);
|
||||
if (OutIdentificators.count(ident))
|
||||
OutIdentificators.erase(ident);
|
||||
}
|
||||
else if (entry->funcParams.isArgOut(i))
|
||||
{
|
||||
if (InIdentificators.count(ident))
|
||||
InIdentificators.erase(ident);
|
||||
if (InOutIdentificators.count(ident))
|
||||
InOutIdentificators.erase(ident);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
insertIntents(InOutIdentificators, headerSt, parSym, INOUT_OP, INOUT_BIT);
|
||||
|
||||
@@ -36,7 +36,7 @@ static void FindAllVars(SgExpression* expr, set<SgSymbol*>& allVars, set<SgSymbo
|
||||
return;
|
||||
|
||||
const int var = expr->variant();
|
||||
if (var == VAR_REF || var == ARRAY_REF)
|
||||
if (var == VAR_REF || var == ARRAY_REF || var == FUNC_CALL)
|
||||
allVars.insert(expr->symbol());
|
||||
if (var == CONST_REF)
|
||||
allVarsConst.insert(expr->symbol());
|
||||
@@ -180,11 +180,21 @@ static map<char, SgType*> FunctionImplicitCheck(SgStatement* function, const map
|
||||
else if (st->variant() == CONTAINS_STMT || isSgExecutableStatement(st) != NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
set<int> skip = { EXTERN_STAT };
|
||||
|
||||
for (auto st = function; st != endOfFunc && st->variant() != CONTAINS_STMT; st = st->lexNext())
|
||||
{
|
||||
if (skip.count(st->variant()))
|
||||
continue;
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
FindAllVars(st->expr(i), allVars, allVarsConst);
|
||||
|
||||
if (st->variant() == FOR_NODE)
|
||||
allVars.insert(isSgForStmt(st)->doName());
|
||||
}
|
||||
|
||||
varsWithoutDecl = getVars(function->symbol()->identifier(), toRename, allVars, types);
|
||||
varsWithoutDeclConst = getVars(function->symbol()->identifier(), toRename, allVarsConst, types);
|
||||
|
||||
@@ -215,6 +225,13 @@ static map<char, SgType*> FunctionImplicitCheck(SgStatement* function, const map
|
||||
insertPlace->insertStmtAfter(*implNone, *function);
|
||||
insertPlace = insertPlace->lexNext();
|
||||
|
||||
if (function->variant() == FUNC_HEDR)
|
||||
{
|
||||
auto type_op = function->expr(1);
|
||||
if (type_op == NULL)
|
||||
varsWithoutDecl.push_back(function->symbol());
|
||||
}
|
||||
|
||||
makeDeclaration(varsWithoutDecl, function);
|
||||
|
||||
auto declList = makeDeclaration(varsWithoutDeclConst, NULL);
|
||||
@@ -224,7 +241,7 @@ static map<char, SgType*> FunctionImplicitCheck(SgStatement* function, const map
|
||||
|
||||
for (auto& s : toRename)
|
||||
s->changeName(TestAndCorrectName((string(s->identifier()) + "_").c_str()));
|
||||
|
||||
|
||||
return types;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define VERSION_SPF "2331"
|
||||
#define VERSION_SPF "2333"
|
||||
|
||||
Reference in New Issue
Block a user