WIP: added interfaces
This commit is contained in:
@@ -1022,7 +1022,7 @@ static void insertInterface(SgStatement* func, const string& iface, const string
|
||||
SgStatement* ifaceBlock = new SgStatement(INTERFACE_STMT);
|
||||
addControlEndToStmt(ifaceBlock->thebif);
|
||||
|
||||
ifaceBlock->setlineNumber(st->lineNumber());
|
||||
ifaceBlock->setlineNumber(getNextNegativeLineNumber()); // st->lineNumber()
|
||||
ifaceBlock->setFileName(st->fileName());
|
||||
st->insertStmtBefore(*ifaceBlock, *st->controlParent());
|
||||
ifaceBlock->lastNodeOfStmt()->addComment(iface.c_str());
|
||||
@@ -1075,6 +1075,11 @@ static bool isPure(SgStatement* func)
|
||||
return retVal;
|
||||
}
|
||||
|
||||
void DvmhRegionInserter::createInterfaceBlockForOutCall(FuncInfo* func, FuncInfo* callFrom)
|
||||
{
|
||||
insertInterface(func->funcPointer, getInterfaceBlock(callFrom->funcPointer->GetOriginal(), callFrom->funcParams), callFrom->funcName);
|
||||
}
|
||||
|
||||
void DvmhRegionInserter::createInterfaceBlockForParallelFunctions()
|
||||
{
|
||||
for (auto& parF : parallel_functions)
|
||||
@@ -1088,7 +1093,7 @@ void DvmhRegionInserter::createInterfaceBlockForParallelFunctions()
|
||||
if (it == callTo->interfaceBlocks.end())
|
||||
{
|
||||
callTo->interfaceBlocks[parF->funcName] = NULL;
|
||||
insertInterface(callTo->funcPointer, getInterfaceBlock(parF->funcPointer->GetOriginal(), parF->funcParams), parF->funcName);
|
||||
createInterfaceBlockForOutCall(callTo, parF);
|
||||
}
|
||||
else if (it->second) // interface not inserted as comment
|
||||
{
|
||||
@@ -1140,7 +1145,7 @@ void DvmhRegionInserter::createInterfaceBlockForOutCalls(FuncInfo* func)
|
||||
&& isPure(callFrom->funcPointer->GetOriginal()))
|
||||
{
|
||||
func->interfaceBlocks[callFrom->funcName] = callFrom;
|
||||
insertInterface(func->funcPointer, getInterfaceBlock(callFrom->funcPointer->GetOriginal(), callFrom->funcParams), callFrom->funcName);
|
||||
createInterfaceBlockForOutCall(func, callFrom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,8 @@ public:
|
||||
|
||||
const std::set<FuncInfo*>& getParallelFunctions() const { return parallel_functions; }
|
||||
|
||||
static void createInterfaceBlockForOutCalls(FuncInfo* func);
|
||||
static void createInterfaceBlockForOutCall(FuncInfo* func, FuncInfo* callFrom);
|
||||
static void createInterfaceBlockForOutCalls(FuncInfo* func);
|
||||
|
||||
~DvmhRegionInserter()
|
||||
{
|
||||
|
||||
@@ -119,14 +119,6 @@ struct FuncInfo
|
||||
std::set<FuncInfo*> callsFromV;
|
||||
std::vector<FuncInfoCallFrom> callsFromDetailed;
|
||||
|
||||
//TODO: create new object for grouping this info
|
||||
// grouped info of calls from
|
||||
/*std::vector<std::pair<std::string, int>> detailCallsFrom; // <name, line>
|
||||
std::vector<std::pair<void*, int>> pointerDetailCallsFrom; // <pointer, SG_VAR> SgStatement for PROC_STAT, SgExpression for FUNC_CALL, VAR_REF for external calls
|
||||
std::vector<void*> parentForPointer; // parent SgStatement* of FUNC_CALL
|
||||
std::vector<FuncParam> actualParams;*/
|
||||
// end/
|
||||
|
||||
std::map<std::string, std::set<std::string>> commonBlocks;
|
||||
|
||||
std::vector<FuncInfo*> callsTo; //calls of this function
|
||||
|
||||
@@ -503,6 +503,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
||||
{
|
||||
checkForRecursion(file, allFuncInfo, getObjectForFileFromMap(file_name, SPF_messages));
|
||||
intentInsert(getObjectForFileFromMap(file_name, allFuncInfo));
|
||||
insertIntrinsicStat(getObjectForFileFromMap(file_name, allFuncInfo));
|
||||
}
|
||||
else if (curr_regime == LOOP_GRAPH)
|
||||
loopGraphAnalyzer(file, getObjectForFileFromMap(file_name, loopGraph), getObjectForFileFromMap(file_name, intervals), getObjectForFileFromMap(file_name, SPF_messages), mpiProgram);
|
||||
@@ -1335,6 +1336,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
||||
detectCopies(allFuncInfo);
|
||||
fillInterfaceBlock(allFuncInfo);
|
||||
intentInsertToInterfaces(allFuncInfo);
|
||||
//createInterfacesForAssumedSize(allFuncInfo);
|
||||
|
||||
//this call is only for testing
|
||||
//setPureStatus(allFuncInfo);
|
||||
|
||||
@@ -374,6 +374,29 @@ static bool hasCalls(SgStatement* stat)
|
||||
return hasCalls(stat->expr(0)) || hasCalls(stat->expr(1)) || hasCalls(stat->expr(2));
|
||||
}
|
||||
|
||||
static void moveComment(SgStatement* stat)
|
||||
{
|
||||
const char* comm = stat->comments();
|
||||
if (comm)
|
||||
{
|
||||
SgStatement* next = stat->lastNodeOfStmt()->lexNext();
|
||||
if (next)
|
||||
{
|
||||
const char* commNext = next->comments();
|
||||
if (commNext)
|
||||
{
|
||||
string newComm(comm);
|
||||
newComm += commNext;
|
||||
|
||||
next->delComments();
|
||||
next->addComment(newComm.c_str());
|
||||
}
|
||||
else
|
||||
next->addComment(comm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int removeDeadCode(SgStatement* func,
|
||||
const map<string, vector<FuncInfo*>>& allFuncs,
|
||||
const map<string, CommonBlock*>& commonBlocks,
|
||||
@@ -527,12 +550,14 @@ int removeDeadCode(SgStatement* func,
|
||||
else
|
||||
{
|
||||
moveLabelBefore(cp);
|
||||
moveComment(cp);
|
||||
cp->deleteStmt();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
moveLabelBefore(rem);
|
||||
moveComment(rem);
|
||||
rem->deleteStmt();
|
||||
}
|
||||
}
|
||||
@@ -585,6 +610,7 @@ int removeDeadCode(SgStatement* func,
|
||||
{
|
||||
__spf_print(PRINT_USELESS_STATEMENTS, "[Useless block statement on line %d and file %s]\n", rem->lineNumber(), rem->fileName());
|
||||
moveLabelBefore(rem);
|
||||
moveComment(rem);
|
||||
rem->deleteStmt();
|
||||
if (rem == start)
|
||||
mainRemoved = true;
|
||||
|
||||
@@ -30,6 +30,80 @@ using std::wstring;
|
||||
using std::make_pair;
|
||||
using std::to_string;
|
||||
|
||||
void insertIntrinsicStat(const vector<FuncInfo*>& allFuncInfo)
|
||||
{
|
||||
for (auto& func : allFuncInfo)
|
||||
{
|
||||
auto start = func->funcPointer->GetOriginal();
|
||||
auto end = start->lastNodeOfStmt();
|
||||
SgStatement* st = start;
|
||||
SgStatement* intr = NULL;
|
||||
|
||||
//find last decl place
|
||||
for ( ; st != end; st = st->lexNext())
|
||||
{
|
||||
if (isSgExecutableStatement(st))
|
||||
break;
|
||||
|
||||
if (st->variant() == CONTAINS_STMT)
|
||||
break;
|
||||
|
||||
if (st->variant() == INTRIN_STAT)
|
||||
intr = st;
|
||||
}
|
||||
|
||||
map<string, SgSymbol*> intrincis;
|
||||
for (auto& call : func->callsFromDetailed)
|
||||
{
|
||||
auto name = call.detailCallsFrom.first;
|
||||
if (intrincis.find(name) != intrincis.end())
|
||||
continue;
|
||||
|
||||
if (!isIntrinsicFunctionName(name.c_str()))
|
||||
continue;
|
||||
|
||||
void* ptr = call.pointerDetailCallsFrom.first;
|
||||
int var = call.pointerDetailCallsFrom.second;
|
||||
|
||||
SgSymbol* s = NULL;
|
||||
if (var == PROC_STAT)
|
||||
s = ((SgStatement*)ptr)->symbol();
|
||||
else if (var == FUNC_CALL)
|
||||
s = ((SgExpression*)ptr)->symbol();
|
||||
else
|
||||
continue;
|
||||
|
||||
if ((s->attributes() & INTRINSIC_BIT) != 0)
|
||||
continue;
|
||||
|
||||
intrincis[name] = s;
|
||||
}
|
||||
|
||||
if (!intrincis.size())
|
||||
continue;
|
||||
|
||||
if (intr == NULL)
|
||||
{
|
||||
vector<SgExpression*> list;
|
||||
for (auto& elem : intrincis)
|
||||
list.push_back(new SgVarRefExp(elem.second));
|
||||
|
||||
SgStatement* intr = new SgStatement(INTRIN_STAT);
|
||||
intr->setExpression(0, makeExprList(list));
|
||||
|
||||
st->insertStmtBefore(*intr, *func->funcPointer);
|
||||
}
|
||||
else
|
||||
{
|
||||
SgExprListExp* list = isSgExprListExp(intr->expr(0));
|
||||
checkNull(list, convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
for (auto& elem : intrincis)
|
||||
list->append(*new SgVarRefExp(elem.second));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool checkOutCalls(const set<string>& outCalls)
|
||||
{
|
||||
for (auto& elem : outCalls)
|
||||
@@ -39,7 +113,8 @@ bool checkOutCalls(const set<string>& outCalls)
|
||||
return false;
|
||||
}
|
||||
|
||||
void createInterfacesForOutCalls(FuncInfo* func) {
|
||||
void createInterfacesForOutCalls(FuncInfo* func)
|
||||
{
|
||||
if (func->isPure && !func->isMain)
|
||||
{
|
||||
bool hasOutCalls = checkOutCalls(func->callsFrom);
|
||||
@@ -48,6 +123,99 @@ void createInterfacesForOutCalls(FuncInfo* func) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool changeIfHasStarRange(SgExpression* arrayDecl)
|
||||
{
|
||||
SgExpression* list = arrayDecl->lhs();
|
||||
bool has = false;
|
||||
|
||||
while (list)
|
||||
{
|
||||
if (list->lhs()->variant() == STAR_RANGE)
|
||||
has = true;
|
||||
list = list->rhs();
|
||||
}
|
||||
|
||||
if (has)
|
||||
{
|
||||
list = arrayDecl->lhs();
|
||||
while (list)
|
||||
{
|
||||
list->setLhs(new SgExpression(DDOT));
|
||||
list = list->rhs();
|
||||
}
|
||||
}
|
||||
|
||||
return has;
|
||||
}
|
||||
|
||||
void createInterfacesForAssumedSize(const map<string, vector<FuncInfo*>>& allFuncInfo)
|
||||
{
|
||||
set<FuncInfo*> hasAssumedSizeArrays;
|
||||
|
||||
for (auto& funcByFile : allFuncInfo)
|
||||
{
|
||||
if (SgFile::switchToFile(funcByFile.first) == -1)
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
for (auto& func : funcByFile.second)
|
||||
{
|
||||
SgProgHedrStmt* prog = isSgProgHedrStmt(func->funcPointer->GetOriginal());
|
||||
if (prog == NULL)
|
||||
continue;
|
||||
|
||||
for (int z = 0; z < func->funcParams.countOfPars; ++z)
|
||||
{
|
||||
if (func->funcParams.parametersT[z] == ARRAY_T)
|
||||
{
|
||||
auto s = prog->parameter(z);
|
||||
const string name = s->identifier();
|
||||
|
||||
vector<SgStatement*> allDecls;
|
||||
declaratedInStmt(s, &allDecls);
|
||||
|
||||
for (auto& decl : allDecls)
|
||||
{
|
||||
SgExpression* list = decl->expr(0);
|
||||
while (list)
|
||||
{
|
||||
if (list->lhs() && list->lhs()->symbol()->identifier() == name)
|
||||
{
|
||||
if (changeIfHasStarRange(list->lhs()))
|
||||
hasAssumedSizeArrays.insert(func);
|
||||
break;
|
||||
}
|
||||
list = list->rhs();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (hasAssumedSizeArrays.size() == 0)
|
||||
return;
|
||||
|
||||
for (auto& funcByFile : allFuncInfo)
|
||||
{
|
||||
if (SgFile::switchToFile(funcByFile.first) == -1)
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
for (auto& func : funcByFile.second)
|
||||
{
|
||||
for (auto& elem : func->callsFromV)
|
||||
{
|
||||
auto it = hasAssumedSizeArrays.find(elem);
|
||||
if (it != hasAssumedSizeArrays.end())
|
||||
{
|
||||
auto callFrom = *it;
|
||||
DvmhRegionInserter::createInterfaceBlockForOutCall(func, callFrom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static void setPureStatus(FuncInfo* func)
|
||||
{
|
||||
if (func->isPure && !func->isMain)
|
||||
@@ -317,6 +485,9 @@ void intentInsertToInterfaces(const map<string, vector<FuncInfo*>>& allFuncInfo)
|
||||
if (isSgExecutableStatement(st))
|
||||
break;
|
||||
|
||||
if (st->variant() == CONTAINS_STMT)
|
||||
break;
|
||||
|
||||
if (st->controlParent()->variant() == INTERFACE_STMT)
|
||||
{
|
||||
if (st->variant() == PROC_HEDR || st->variant() == FUNC_HEDR)
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
void insertIntrinsicStat(const std::vector<FuncInfo*>& allFuncInfo);
|
||||
|
||||
bool checkOutCalls(const std::set<std::string>& outCalls);
|
||||
std::map<SgStatement*, std::set<std::string>> fillFromIntent(SgStatement* header);
|
||||
void intentInsert(const std::vector<FuncInfo*>& allFuncInfo);
|
||||
void intentInsertToInterfaces(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo);
|
||||
void createInterfacesForAssumedSize(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo);
|
||||
void createInterfacesForOutCalls(FuncInfo* func);
|
||||
void setPureStatus(const std::set<FuncInfo*>& funcInfo);
|
||||
void setPureStatus(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo);
|
||||
|
||||
@@ -3586,4 +3586,4 @@ void addPrivatesToArraysFromGUI(SgFile* file, const map<tuple<int, string, strin
|
||||
|
||||
toInsert.first->insertStmtBefore(*op, *toInsert.first->controlParent());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define VERSION_SPF "2324"
|
||||
#define VERSION_SPF "2327"
|
||||
|
||||
@@ -313,6 +313,23 @@ bool FunctionsChecker(SgFile *file, map<string, pair<string, int>> &funcNames, m
|
||||
|
||||
checkOK = false;
|
||||
}
|
||||
|
||||
if (isIntrinsicFunctionName(funcName.c_str()))
|
||||
{
|
||||
__spf_print(1, "the same function name in different places was found: func %s, places %s:%d and %s:%d\n",
|
||||
funcName.c_str(), file->filename(), st->lineNumber(), "intrinsic", 0);
|
||||
|
||||
wstring messageE, messageR;
|
||||
__spf_printToLongBuf(messageE, L"Function '%s' was declared in more than one place: '%s':%d and '%s':%d",
|
||||
to_wstring(funcName).c_str(), to_wstring(file->filename()).c_str(), st->lineNumber(), to_wstring("intrinsic").c_str(), 0);
|
||||
|
||||
__spf_printToLongBuf(messageR, R92,
|
||||
to_wstring(funcName).c_str(), to_wstring(file->filename()).c_str(), st->lineNumber(), to_wstring("intrinsic").c_str(), 0);
|
||||
|
||||
currMessages[st->fileName()].push_back(Messages(ERROR, st->lineNumber(), messageR, messageE, 1048));
|
||||
|
||||
checkOK = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return checkOK;
|
||||
|
||||
Reference in New Issue
Block a user