Merged to master

This commit is contained in:
2023-12-11 21:58:41 +03:00
56 changed files with 16021 additions and 14416 deletions

View File

@@ -187,6 +187,9 @@ set(TR_FUNC_PURE _src/Transformations/function_purifying.cpp
_src/Transformations/function_purifying.h)
set(TR_GV _src/Transformations/fix_common_blocks.cpp
_src/Transformations/fix_common_blocks.h)
set(TR_CONV _src/Transformations/convert_to_c.cpp
_src/Transformations/convert_to_c.h)
set(TR_IMPLICIT_NONE _src/Transformations/set_implicit_none.cpp
_src/Transformations/set_implicit_none.h)
@@ -204,6 +207,8 @@ set(TRANSFORMS
${TR_LOOP_UNROLL}
${TR_GV}
${TR_PRIV_DEL}
${TR_CONV})
${TR_PRIV_DEL}
${TR_IMPLICIT_NONE})
set(CFG _src/CFGraph/IR.cpp
@@ -423,6 +428,7 @@ source_group (Transformations\\PrivateArrayRemoving FILES ${TR_PRIV_DEL})
source_group (Transformations\\VectorAssignToLoop FILES ${TR_VECTOR})
source_group (Transformations\\RenameSymbols FILES ${RENAME_SYMBOLS})
source_group (Transformations\\GlobalVariables FILES ${TR_GV})
source_group (Transformations\\ConvertToC FILES ${TR_CONV})
source_group (Transformations\\SetImplicitNone FILES ${TR_IMPLICIT_NONE})

View File

@@ -490,9 +490,9 @@ static SAPFOR::Argument* processExpression(SgExpression* ex, vector<IR_Block*>&
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
string callName = "_ERROR_";
for (int z = 0; z < func->pointerDetailCallsFrom.size() && callName == "_ERROR_"; ++z)
if (func->pointerDetailCallsFrom[z].first == ex)
callName = func->detailCallsFrom[z].first;
for (int z = 0; z < func->callsFromDetailed.size() && callName == "_ERROR_"; ++z)
if (func->callsFromDetailed[z].pointerDetailCallsFrom.first == ex)
callName = func->callsFromDetailed[z].detailCallsFrom.first;
SAPFOR::Argument* fArg = getFuncArg(callName);
@@ -728,8 +728,8 @@ static SgStatement* processStatement(SgStatement* st, vector<IR_Block*>& blocks,
const int var = st->variant();
//printf("%d %d\n", st->lineNumber(), st->variant());
static const set<int> skip = { FORMAT_STAT,
OPEN_STAT, CLOSE_STAT, INQUIRE_STAT, REWIND_STAT, BACKSPACE_STAT, ENDFILE_STAT// <--- TODO
static const set<int> skip = { FORMAT_STAT, OPEN_STAT, CLOSE_STAT, INQUIRE_STAT, REWIND_STAT, BACKSPACE_STAT,
ENDFILE_STAT, PAUSE_NODE // <--- TODO
};
const int blockShift = blocks.size() != 0 ? blocks[0]->getNumber() : Instruction::getNextInstrNum();
@@ -824,7 +824,7 @@ static SgStatement* processStatement(SgStatement* st, vector<IR_Block*>& blocks,
}
}
blocks.push_back(new IR_Block(new Instruction(CFG_OP::EMPTY, st)));
blocks.push_back(new IR_Block(new Instruction(CFG_OP::EMPTY, (ifSt->falseBody()) ? ifSt->falseBody() : st->lastNodeOfStmt())));
blocks[jump_if]->getInstruction()->setArg2(new SAPFOR::Argument(CFG_ARG_TYPE::INSTR, to_string(blocks.back()->getNumber())));
processLabel(st, firstBlock, blocks, labels);
@@ -1094,9 +1094,9 @@ static SgStatement* processStatement(SgStatement* st, vector<IR_Block*>& blocks,
bool hasLabelArgs = processArgs(call, call->numberOfArgs(), blocks, func, commonVars, &labelsOfArgs);
string callName = "_ERROR_";
for (int z = 0; z < func->pointerDetailCallsFrom.size() && callName == "_ERROR_"; ++z)
if (func->pointerDetailCallsFrom[z].first == st)
callName = func->detailCallsFrom[z].first;
for (int z = 0; z < func->callsFromDetailed.size() && callName == "_ERROR_"; ++z)
if (func->callsFromDetailed[z].pointerDetailCallsFrom.first == st)
callName = func->callsFromDetailed[z].detailCallsFrom.first;
SAPFOR::Argument* fArg = getFuncArg(callName);
@@ -1316,7 +1316,9 @@ static SgStatement* processStatement(SgStatement* st, vector<IR_Block*>& blocks,
{
SgStatement* body = select->defOption()->lexNext();
while (body != lastSelect)
while (body != lastSelect &&
body->variant() != CASE_NODE &&
body->variant() != DEFAULT_NODE)
{
const int firstInstr = blocks.size();
body = processLabel(processStatement(body, blocks, labels, func, commonVars, settings), firstInstr, blocks, labels);

View File

@@ -846,8 +846,9 @@ void uniteIntervalsBetweenProcCalls(map<string, vector<SpfInterval*>> &intervals
{
if (SgFile::switchToFile(callsTo->fileName) == -1)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
for (auto &callsFrom : callsTo->pointerDetailCallsFrom)
for (auto &callsInfo: callsTo->callsFromDetailed)
{
auto& callsFrom = callsInfo.pointerDetailCallsFrom;
SgStatement *base = NULL;
if (callsFrom.second == PROC_STAT)
{

View File

@@ -598,7 +598,6 @@ void fillInfoFromDirectives(const LoopGraph *loopInfo, ParallelDirective *direct
void removeOmpDir(void* stIn)
{
SgStatement* st = (SgStatement*)stIn;
vector<OmpDir> resultAll;
char* lineS = st->comments();
if (!lineS)
@@ -620,7 +619,7 @@ void removeOmpDir(void* stIn)
}
}
static inline void addToAttribute(SgStatement* st, int var, const vector<SgExpression*>& list)
static inline void addToAttribute(SgStatement* st, int var, vector<SgExpression*> list)
{
if (list.size())
{
@@ -630,6 +629,89 @@ static inline void addToAttribute(SgStatement* st, int var, const vector<SgExpre
toAdd->setlineNumber(st->lineNumber());
toAdd->setLocalLineNumber(888);
//filter
if (var == ACC_PRIVATE_OP)
{
vector<SgExpression*> list_new;
auto attributes = getAttributes<SgStatement*, SgStatement*>(st, set<int>{SPF_ANALYSIS_DIR});
set<string> privates;
for (auto& attr : attributes)
fillPrivatesFromComment(new Statement(attr), privates);
if (privates.size())
{
for (auto& elem : list)
if (privates.find(elem->unparse()) == privates.end())
list_new.push_back(elem);
list = list_new;
if (!list.size())
{
__spf_print(1, "-- skip privates on line %d from OMP dir\n%s", st->lineNumber(), toAdd->unparse());
return;
}
}
}
else if (var == REDUCTION_OP)
{
auto attributes = getAttributes<SgStatement*, SgStatement*>(st, set<int>{SPF_ANALYSIS_DIR});
map<string, set<string>> reduction;
for (auto& attr : attributes)
fillReductionsFromComment(new Statement(attr), reduction);
map<string, set<string>> reductionToAdd;
fillReductionsFromComment(new Statement(st), reductionToAdd);
vector<SgExpression*> list_new;
if (reduction.size())
{
if (reduction == reductionToAdd)
{
__spf_print(1, "-- skip reduction on line %d from OMP dir\n%s", st->lineNumber(), toAdd->unparse());
return;
}
map<string, set<string>> reductionToAddNew;
for (auto& redPair : reductionToAdd)
{
auto it = reduction.find(redPair.first);
if (it == reduction.end())
reductionToAddNew[redPair.first] = redPair.second;
else
{
set<string> newVar;
for (auto& var : redPair.second)
{
auto itVar = it->second.find(var);
if (itVar == it->second.end())
reductionToAddNew[redPair.first].insert(var);
}
}
}
if (!reductionToAddNew.size())
{
__spf_print(1, "-- skip reduction on line %d from OMP dir\n%s", st->lineNumber(), toAdd->unparse());
return;
}
if (reductionToAddNew != reductionToAdd)
{
list.clear();
for (auto& redPair : reductionToAddNew)
for (auto& var : redPair.second)
list.push_back(new SgExpression(ARRAY_OP,
new SgKeywordValExp(redPair.first.c_str()),
new SgVarRefExp(findSymbolOrCreate(current_file, var, NULL, getFuncStat(st)))));
}
}
}
ex = new SgExprListExp();
ex->setLhs(new SgExpression(var, makeExprList(list), NULL));
toAdd = new SgStatement(SPF_ANALYSIS_DIR, NULL, NULL, ex, NULL, NULL);
st->addAttribute(SPF_ANALYSIS_DIR, toAdd, sizeof(SgStatement));
if (var == ACC_PRIVATE_OP)
@@ -644,17 +726,20 @@ vector<OmpDir> parseOmpDirs(void* stIn, const set<string> &globalPriv, bool forD
SgStatement* st = (SgStatement*)stIn;
vector<OmpDir> resultAll;
char* lineS = st->comments();
const char* lineS = st->comments();
if (!lineS)
return resultAll;
vector<string> split;
splitString(lineS, '\n', split);
string comment(lineS);
convertToLower(comment);
vector<string> split;
splitString(comment, '\n', split);
for (int z = split.size() - 1; z >= 0; z--)
{
string line = split[z];
convertToLower(line);
if (line.substr(0, 6) == "!$omp&")
{
if (z - 1 < 0)

View File

@@ -1631,8 +1631,11 @@ void GroupShadow(const map<string, vector<FuncInfo*>>& allFuncs,
for (auto& elem : byFile.second)
{
mapF[elem->funcName] = elem;
for (auto& call : elem->detailCallsFrom)
for (auto& callInfo : elem->callsFromDetailed)
{
auto& call = callInfo.detailCallsFrom;
mapCallsF[elem->fileName][call.second].insert(call.first);
}
}
map<FuncInfo*, set<FuncInfo*>> callDeps;

View File

@@ -1691,7 +1691,6 @@ static inline bool processStat(SgStatement *st, const string &currFile,
map<pair<string, int>, set<SgStatement*>>& usersDirectives)
{
bool retVal = true;
if (st->variant() == SPF_PARALLEL_REG_DIR || st->variant() == SPF_END_PARALLEL_REG_DIR)
{
bool result = checkParallelRegions(st, commonBlocks, messagesForFile);
@@ -1954,7 +1953,6 @@ bool preprocess_spf_dirs(SgFile *file, const map<string, CommonBlock*> &commonBl
{
int funcNum = file->numberOfFunctions();
const string currFile = file->filename();
bool noError = true;
for (int i = 0; i < funcNum; ++i)

View File

@@ -877,6 +877,37 @@ ArraySet DvmhRegionInserter::get_used_arrs_for_block(SgStatement* st, int usage_
return usages;
}
static bool filterFromList(SgStatement* st, const set<string>& idents, bool exclude = false)
{
bool empty = false;
SgExpression* list = st->expr(0);
vector<SgExpression*> newList;
int total = 0;
while (list)
{
if (exclude)
{
if (idents.find(list->lhs()->symbol()->identifier()) == idents.end())
newList.push_back(list->lhs());
}
else
{
if (idents.find(list->lhs()->symbol()->identifier()) != idents.end())
newList.push_back(list->lhs());
}
total++;
list = list->rhs();
}
if (newList.size() == 0)
empty = true;
else if (total != newList.size())
st->setExpression(0, makeExprList(newList));
return empty;
}
static string getInterfaceBlock(SgStatement* func, const FuncParam& pars)
{
string oldFile = current_file->filename();
@@ -884,8 +915,7 @@ static string getInterfaceBlock(SgStatement* func, const FuncParam& pars)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
auto copy = duplicateProcedure(func, NULL, false, false, false, true);
const set<string> ident(pars.identificators.begin(), pars.identificators.end());
const set<string> idents(pars.identificators.begin(), pars.identificators.end());
//remove all exec
SgStatement* st = copy->lexNext();
@@ -925,26 +955,16 @@ static string getInterfaceBlock(SgStatement* func, const FuncParam& pars)
|| st->variant() == DIM_STAT
|| st->variant() == INTENT_STMT)
{
SgExpression* list = st->expr(0);
vector<SgExpression*> newList;
while (list)
{
if (ident.find(list->lhs()->symbol()->identifier()) != ident.end())
newList.push_back(list->lhs());
list = list->rhs();
}
if (newList.size() == 0)
bool empty = filterFromList(st, idents);
if (empty)
{
SgStatement* next = st->lexNext();
toExtract.push_back(st);
st = next;
continue;
}
else
st->setExpression(0, makeExprList(newList));
}
else
else if (!isDVM_stat(st) && !isSPF_stat(st))
toExtract.push_back(st);
if (st->variant() == CONTAINS_STMT)
@@ -963,7 +983,7 @@ static string getInterfaceBlock(SgStatement* func, const FuncParam& pars)
return retVal;
}
static void insertInterface(SgStatement* func, const string& iface)
static void insertInterface(SgStatement* func, const string& iface, const string& fName)
{
string oldFile = current_file->filename();
if (!func->switchToFile())
@@ -973,6 +993,18 @@ static void insertInterface(SgStatement* func, const string& iface)
SgStatement* last = func->lastNodeOfStmt();
while (st != last)
{
if (st->variant() == VAR_DECL || st->variant() == VAR_DECL_90)
{
bool empty = filterFromList(st, { fName }, true);
if (empty)
{
SgStatement* next = st->lexNext();
st->extractStmt();
st = next;
continue;
}
}
if (isSgExecutableStatement(st))
break;
st = st->lexNext();
@@ -1033,21 +1065,57 @@ static bool isPure(SgStatement* func)
return retVal;
}
void DvmhRegionInserter::createInterfaceBlock()
void DvmhRegionInserter::createInterfaceBlockForParallelFunctions()
{
for (auto& parF : parallel_functions)
{
for (auto& callTo : parF->callsTo)
{
if (callTo->fileName != parF->fileName)
if (callTo->fileName != parF->fileName && isPure(parF->funcPointer->GetOriginal()))
{
if (callTo->interfaceBlocks.find(parF->funcName) == callTo->interfaceBlocks.end()
&& parF->funcParams.countOfPars > 0
&& isPure(parF->funcPointer->GetOriginal()))
insertRoutine(parF->funcPointer->GetOriginal());
auto it = callTo->interfaceBlocks.find(parF->funcName);
if (it == callTo->interfaceBlocks.end())
{
insertRoutine(parF->funcPointer->GetOriginal());
callTo->interfaceBlocks[parF->funcName] = parF;
insertInterface(callTo->funcPointer, getInterfaceBlock(parF->funcPointer->GetOriginal(), parF->funcParams));
callTo->interfaceBlocks[parF->funcName] = NULL;
insertInterface(callTo->funcPointer, getInterfaceBlock(parF->funcPointer->GetOriginal(), parF->funcParams), parF->funcName);
}
else if (it->second) // interface not inserted as comment
{
SgStatement* st = callTo->funcPointer->GetOriginal();
string oldFile = current_file->filename();
if (!st->switchToFile())
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
SgStatement* last = st->lastNodeOfStmt();
SgStatement* iface = NULL;
st = st->lexNext();
while (st != last)
{
if (st->variant() == FUNC_HEDR || st->variant() == PROC_HEDR)
{
if (st->controlParent()->variant() == INTERFACE_STMT &&
st->symbol()->identifier() == parF->funcName)
{
iface = st;
insertRoutine(iface);
break;
}
}
if (st->variant() == CONTAINS_STMT)
break;
if (isSgExecutableStatement(st))
break;
st = st->lexNext();
}
checkNull(iface, convertFileName(__FILE__).c_str(), __LINE__);
if (SgFile::switchToFile(oldFile) == -1)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
}
}
}
@@ -1059,14 +1127,10 @@ void DvmhRegionInserter::createInterfaceBlockForOutCalls(FuncInfo* func)
for (auto& callFrom : func->callsFromV)
{
if (func->interfaceBlocks.find(callFrom->funcName) == func->interfaceBlocks.end()
&& callFrom->funcParams.countOfPars > 0
&& isPure(callFrom->funcPointer->GetOriginal()))
{
if (callFrom->fileName != func->fileName)
insertRoutine(func->funcPointer->GetOriginal());
func->interfaceBlocks[callFrom->funcName] = callFrom;
insertInterface(func->funcPointer, getInterfaceBlock(callFrom->funcPointer->GetOriginal(), callFrom->funcParams));
insertInterface(func->funcPointer, getInterfaceBlock(callFrom->funcPointer->GetOriginal(), callFrom->funcParams), callFrom->funcName);
}
}
}
@@ -1219,4 +1283,80 @@ void DvmhRegionInserter::addUsedWriteArrays(set<DIST::Array*>& arrays)
if (loop->inDvmhRegion == 1)
arrays.insert(loop->usedArraysWriteAll.begin(), loop->usedArraysWriteAll.end());
}
}
void insertDvmhRegions(SgProject& project, int files, const vector<ParallelRegion*>& parallelRegions,
map<string, vector<FuncInfo*>>& allFuncInfo,
map<string, vector<LoopGraph*>> loopGraph,
ReadWriteAnalyzer& rw_analyzer,
const map<DIST::Array*, set<DIST::Array*>> arrayLinksByFuncCalls)
{
vector<DvmhRegionInserter*> inserters;
const bool regionCondition = ((parallelRegions.size() == 0 && parallelRegions[0]->GetName() == "DEFAULT") || mpiProgram == 1);
set<DIST::Array*> usedArraysInRegions;
set<DIST::Array*> usedWriteArraysInRegions;
for (int i = files - 1; i >= 0; --i)
{
SgFile* file = &(project.file(i));
__spf_print(1, "Start region inserter for file %s\n", file->filename());
map<string, FuncInfo*> mapOfFuncs;
createMapOfFunc(allFuncInfo, mapOfFuncs);
auto loopsForFile = getObjectForFileFromMap(file->filename(), loopGraph);
auto funcsForFile = getObjectForFileFromMap(file->filename(), allFuncInfo);
for (auto& loop : loopsForFile)
loop->analyzeParallelDirs();
DvmhRegionInserter* regionInserter = new DvmhRegionInserter(file, loopsForFile, rw_analyzer, arrayLinksByFuncCalls, mapOfFuncs, funcsForFile, mpiProgram == 1);
inserters.push_back(regionInserter);
//collect info about <parallel> functions
regionInserter->updateParallelFunctions(loopGraph);
if (regionCondition)
regionInserter->insertDirectives(NULL);
else
regionInserter->insertDirectives(&parallelRegions);
//remove privates from loops out of DVMH region
//remove parallel directives from loops out of DVMH region for MPI regime
regionInserter->removePrivatesFromParallelLoops();
//add privates to parallel loops with manual parallelization in DVMH regions
regionInserter->addPrivatesToParallelLoops();
regionInserter->addUsedArrays(usedArraysInRegions);
regionInserter->addUsedWriteArrays(usedWriteArraysInRegions);
setPureStatus(regionInserter->getParallelFunctions());
}
for (int i = files - 1, k = 0; i >= 0; --i, ++k)
{
SgFile* file = &(project.file(i));
DvmhRegionInserter* regionInserter = inserters[k];
for (auto& func : regionInserter->getParallelFunctions())
createInterfacesForOutCalls(func);
// create interface for 'parallel' functions and
// insert ROUTINE directive if needed
regionInserter->createInterfaceBlockForParallelFunctions();
}
for (auto& regionInserter : inserters)
{
regionInserter->updateUsedArrays(usedArraysInRegions, usedWriteArraysInRegions);
if (regionCondition)
regionInserter->insertActualDirectives(NULL);
else
regionInserter->insertActualDirectives(&parallelRegions);
delete regionInserter;
}
}

View File

@@ -76,7 +76,7 @@ public:
void insertActualDirectives(const std::vector<ParallelRegion*>* regs);
void updateParallelFunctions(const std::map<std::string, std::vector<LoopGraph*>>& loopGraphs);
void createInterfaceBlock();
void createInterfaceBlockForParallelFunctions();
void removePrivatesFromParallelLoops();
void addPrivatesToParallelLoops();
void addUsedArrays(std::set<DIST::Array*>& arrays);
@@ -105,3 +105,9 @@ public:
delete reg;
}
};
void insertDvmhRegions(SgProject& project, int files, const std::vector<ParallelRegion*>& parallelRegions,
std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo,
std::map<std::string, std::vector<LoopGraph*>> loopGraph,
ReadWriteAnalyzer& rw_analyzer,
const std::map<DIST::Array*, std::set<DIST::Array*>> arrayLinksByFuncCalls);

View File

@@ -39,8 +39,8 @@ using std::stack;
#define DEBUG 0
//TODO: improve parameter checking
static void correctNameIfContains(SgStatement *call, SgExpression *exCall, string &name,
const vector<SgStatement*> &containsFunctions, const string &prefix)
void correctNameIfContains(SgStatement *call, SgExpression *exCall, string &name,
const vector<SgStatement*> &containsFunctions, const string &prefix)
{
if (containsFunctions.size() <= 0)
return;
@@ -357,12 +357,15 @@ static void findFuncCalls(SgStatement *parent, SgExpression *curr, vector<FuncIn
correctNameIfContains(NULL, curr, elem, containsFunctions, prefix);
proc->callsFrom.insert(nameOfCallFunc.begin(), nameOfCallFunc.end());
proc->detailCallsFrom.push_back(make_pair(nameOfCallFunc[1], line)); // original name of call
proc->pointerDetailCallsFrom.push_back(make_pair(curr, FUNC_CALL));
proc->parentForPointer.push_back(parent);
proc->actualParams.push_back(FuncParam());
processActualParams(curr->lhs(), commonBlocks, proc->actualParams.back(), proc->externalCalls);
FuncInfoCallFrom newCall;
newCall.detailCallsFrom = make_pair(nameOfCallFunc[1], line); // original name of call
newCall.pointerDetailCallsFrom = make_pair(curr, FUNC_CALL);
newCall.parentForPointer = parent;
newCall.actualParams = FuncParam();
processActualParams(curr->lhs(), commonBlocks, newCall.actualParams, proc->externalCalls);
proc->callsFromDetailed.push_back(newCall);
}
}
@@ -1115,13 +1118,15 @@ void functionAnalyzer(SgFile *file, map<string, vector<FuncInfo*>> &allFuncInfo,
continue;
proc->callsFrom.insert(pureNameOfCallFunc.begin(), pureNameOfCallFunc.end());
proc->detailCallsFrom.push_back(make_pair(pureNameOfCallFunc[1], st->lineNumber())); // original name of call
proc->pointerDetailCallsFrom.push_back(make_pair(st, PROC_STAT));
proc->parentForPointer.push_back(st);
proc->actualParams.push_back(FuncParam());
FuncInfoCallFrom newCall;
newCall.detailCallsFrom = make_pair(pureNameOfCallFunc[1], st->lineNumber()); // original name of call
newCall.pointerDetailCallsFrom = make_pair(st, PROC_STAT);
newCall.parentForPointer = st;
newCall.actualParams = FuncParam();
processActualParams(st->expr(0), commonBlocks, proc->actualParams.back(), proc->externalCalls);
processActualParams(st->expr(0), commonBlocks, newCall.actualParams, proc->externalCalls);
proc->callsFromDetailed.push_back(newCall);
// Add func call which we've just found
NestedFuncCall funcCall(pureNameOfCallFunc[1]);
@@ -1150,11 +1155,14 @@ void functionAnalyzer(SgFile *file, map<string, vector<FuncInfo*>> &allFuncInfo,
correctNameIfContains(NULL, curr, elem, containsFunctions, prefix);
proc->callsFrom.insert(nameOfCallFunc.begin(), nameOfCallFunc.end());
proc->detailCallsFrom.push_back(make_pair(nameOfCallFunc[1], st->lineNumber())); // original name of call
proc->pointerDetailCallsFrom.push_back(make_pair(curr, VAR_REF));
proc->parentForPointer.push_back(st);
proc->actualParams.push_back(FuncParam());
FuncInfoCallFrom newCall;
newCall.detailCallsFrom = make_pair(nameOfCallFunc[1], st->lineNumber()); // original name of call
newCall.pointerDetailCallsFrom = make_pair(curr, VAR_REF);
newCall.parentForPointer = st;
newCall.actualParams = FuncParam();
proc->callsFromDetailed.push_back(newCall);
}
}
}
@@ -1336,7 +1344,7 @@ static bool matchCallAndDefinition(const FuncParam &funcParDef, const FuncParam&
messages[file].push_back(Messages(NOTE, line, bufR, bufE, 1013));
__spf_print(1, "Function '%s': different type of call and def parameter %d\n", funcName.c_str(), i + 1);
}
result = false;
//result = false;
}
}
else //TODO
@@ -1371,11 +1379,11 @@ static bool matchCallAndDefinition(SgProject* proj, const map<string, int>& file
for (auto& callsTo : currF->callsTo)
{
for (int cf = 0; cf < callsTo->detailCallsFrom.size(); ++cf)
for (int cf = 0; cf < callsTo->callsFromDetailed.size(); ++cf)
{
if (callsTo->detailCallsFrom[cf].first == currF->funcName)
if (callsTo->callsFromDetailed[cf].detailCallsFrom.first == currF->funcName)
{
auto callInfo = callsTo->pointerDetailCallsFrom[cf];
auto callInfo = callsTo->callsFromDetailed[cf].pointerDetailCallsFrom;
if (callInfo.second == VAR_REF) // external call through proc parameter
continue;
@@ -1383,8 +1391,8 @@ static bool matchCallAndDefinition(SgProject* proj, const map<string, int>& file
if (itF == files.end())
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
bool localR = matchCallAndDefinition(currF->funcParams, callsTo->actualParams[cf], currF->funcName,
callsTo->fileName, callsTo->detailCallsFrom[cf].second, messages);
bool localR = matchCallAndDefinition(currF->funcParams, callsTo->callsFromDetailed[cf].actualParams, currF->funcName,
callsTo->fileName, callsTo->callsFromDetailed[cf].detailCallsFrom.second, messages);
if (!localR)
count++;
}
@@ -2256,8 +2264,9 @@ void propagateWritesToArrays(map<string, vector<FuncInfo*>> &allFuncInfo)
if (!ok)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
for (auto &callFrom : callsTo->pointerDetailCallsFrom)
for (auto &callFromInfo : callsTo->callsFromDetailed)
{
auto& callFrom = callFromInfo.pointerDetailCallsFrom;
if (callFrom.second == VAR_REF) // pass procedure through parameter
continue;
@@ -2429,8 +2438,9 @@ int getLvlCall(FuncInfo* currF, int lvl, const string& func, const string& file,
if (currF->funcName == func)
return 0;
for (auto& callsFrom : currF->detailCallsFrom)
for (auto& callsFromInfo : currF->callsFromDetailed)
{
auto& callsFrom = callsFromInfo.detailCallsFrom;
if (callsFrom.first == func && callsFrom.second == line && currF->fileName == file)
return lvl;
}
@@ -2465,12 +2475,12 @@ void setInlineAttributeToCalls(const map<string, FuncInfo*>& allFunctions,
if (itNeed != inDataChains.end())
needToInline = itNeed->second;
for (int k = 0; k < curr->detailCallsFrom.size(); ++k)
for (int k = 0; k < curr->callsFromDetailed.size(); ++k)
{
if (needToInline.find(curr->detailCallsFrom[k]) == needToInline.end() &&
!isIntrinsicFunctionName(curr->detailCallsFrom[k].first.c_str()))
if (needToInline.find(curr->callsFromDetailed[k].detailCallsFrom) == needToInline.end() &&
!isIntrinsicFunctionName(curr->callsFromDetailed[k].detailCallsFrom.first.c_str()))
{
pair<void*, int> detail = curr->pointerDetailCallsFrom[k];
pair<void*, int> detail = curr->callsFromDetailed[k].pointerDetailCallsFrom;
if (SgFile::switchToFile(curr->fileName) == -1)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
@@ -2480,7 +2490,7 @@ void setInlineAttributeToCalls(const map<string, FuncInfo*>& allFunctions,
else if (detail.second == FUNC_CALL)
{
//TODO: many functions in same statement
SgStatement* callSt = SgStatement::getStatementByFileAndLine(curr->fileName, curr->detailCallsFrom[k].second);
SgStatement* callSt = SgStatement::getStatementByFileAndLine(curr->fileName, curr->callsFromDetailed[k].detailCallsFrom.second);
if (!callSt)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
//((SgExpression*)detail.first)->addAttribute(BOOL_VAL);
@@ -2489,8 +2499,8 @@ void setInlineAttributeToCalls(const map<string, FuncInfo*>& allFunctions,
else
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
pointsForShadowCopies.insert(make_pair(curr->fileName, curr->detailCallsFrom[k].second));
__spf_print(1, " added attribute to '%s' <%s, %d>\n", curr->detailCallsFrom[k].first.c_str(), curr->fileName.c_str(), curr->detailCallsFrom[k].second);
pointsForShadowCopies.insert(make_pair(curr->fileName, curr->callsFromDetailed[k].detailCallsFrom.second));
__spf_print(1, " added attribute to '%s' <%s, %d>\n", curr->callsFromDetailed[k].detailCallsFrom.first.c_str(), curr->fileName.c_str(), curr->callsFromDetailed[k].detailCallsFrom.second);
}
}
}

View File

@@ -96,6 +96,16 @@ struct NestedFuncCall
{ }
};
struct FuncInfoCallFrom {
// <name, line>
std::pair<std::string, int> detailCallsFrom;
// <pointer, SG_VAR> SgStatement for PROC_STAT, SgExpression for FUNC_CALL, VAR_REF for external calls
std::pair<void*, int> pointerDetailCallsFrom;
// parent SgStatement* of FUNC_CALL
void* parentForPointer;
FuncParam actualParams;
};
struct FuncInfo
{
std::string funcName;
@@ -107,13 +117,14 @@ struct FuncInfo
std::set<std::string> callsFrom; //calls from this function
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<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;
std::vector<FuncParam> actualParams;*/
// end/
std::map<std::string, std::set<std::string>> commonBlocks;
@@ -176,10 +187,10 @@ struct FuncInfo
std::vector<std::pair<void*, int>> GetDetailedCallInfo(const std::string &funcName)
{
std::vector<std::pair<void*, int>> result;
for (int i = 0; i < pointerDetailCallsFrom.size(); ++i)
for (int i = 0; i < callsFromDetailed.size(); ++i)
{
if (detailCallsFrom[i].first == funcName)
result.push_back(pointerDetailCallsFrom[i]);
if (callsFromDetailed[i].detailCallsFrom.first == funcName)
result.push_back(callsFromDetailed[i].pointerDetailCallsFrom);
}
return result;
}
@@ -208,6 +219,27 @@ struct FuncInfo
}
bool usesIO() const { return (linesOfIO.size() != 0 || linesOfStop.size() != 0); }
std::string getCallName(const std::pair<void*, int>& call_info, const std::string& name, int line)
{
std::set<std::string> names;
for (auto& call : callsFromDetailed)
{
if (call.pointerDetailCallsFrom == call_info && call.detailCallsFrom.second == line)
return call.detailCallsFrom.first;
if (call.detailCallsFrom.second == line)
if (call.detailCallsFrom.first.find(name) != std::string::npos)
names.insert(call.detailCallsFrom.first);
}
//TODO: detect func call better
if (names.size() == 1)
return *names.begin();
return "";
}
};
struct CallV

View File

@@ -154,8 +154,9 @@ void updateFuncInfo(const map<string, vector<FuncInfo*>> &allFuncInfo) // const
for (auto &it : mapFuncInfo)
{
FuncInfo *currInfo = it.second;
for (auto &funcCall : currInfo->detailCallsFrom)
for (auto &callInfo : currInfo->callsFromDetailed)
{
auto& funcCall = callInfo.detailCallsFrom;
auto itCalledFunc = mapFuncInfo.find(funcCall.first);
if (itCalledFunc != mapFuncInfo.end())
{
@@ -375,7 +376,7 @@ string convertToString(const FuncInfo *currFunc)
{
result += "|" + currFunc->funcName + "|" + to_string(currFunc->linesNum.first) +
"#" + to_string(currFunc->linesNum.second) +
"#" + to_string(currFunc->detailCallsFrom.size()) +
"#" + to_string(currFunc->callsFromDetailed.size()) +
"#" + to_string(currFunc->needToInline) + "#" + to_string(currFunc->doNotInline) +
"#" + to_string(currFunc->doNotAnalyze) + "#" + to_string((int)currFunc->isMain);
@@ -389,8 +390,8 @@ string convertToString(const FuncInfo *currFunc)
}
}
for (int i = 0; i < currFunc->detailCallsFrom.size(); ++i)
result += "|" + currFunc->detailCallsFrom[i].first + "|" + to_string(currFunc->detailCallsFrom[i].second);
for (int i = 0; i < currFunc->callsFromDetailed.size(); ++i)
result += "|" + currFunc->callsFromDetailed[i].detailCallsFrom.first + "|" + to_string(currFunc->callsFromDetailed[i].detailCallsFrom.second);
}
return result;
}
@@ -721,9 +722,9 @@ void createLinksBetweenFormalAndActualParams(map<string, vector<FuncInfo*>> &all
//printf("func %s :\n", func->funcName.c_str());
const string &name = func->funcName;
for (auto &caller : func->callsTo)
for (int i = 0; i < caller->detailCallsFrom.size(); ++i)
if (caller->detailCallsFrom[i].first == name)
addLinks(caller->actualParams[i], func->funcParams, arrayLinksByFuncCalls);
for (int i = 0; i < caller->callsFromDetailed.size(); ++i)
if (caller->callsFromDetailed[i].detailCallsFrom.first == name)
addLinks(caller->callsFromDetailed[i].actualParams, func->funcParams, arrayLinksByFuncCalls);
}
}
@@ -822,8 +823,9 @@ bool detectMpiCalls(const map<string, vector<FuncInfo*>>& allFuncInfo, map<strin
{
for (auto& func : byFile.second)
{
for (auto& callsFromThis : func->detailCallsFrom)
for (auto& callInfo: func->callsFromDetailed)
{
auto& callsFromThis = callInfo.detailCallsFrom;
if (isMpiFunction(callsFromThis.first) && funcByName.find(callsFromThis.first) == funcByName.end())
{
retVal = true;

View File

@@ -46,6 +46,7 @@ void detectCopies(std::map<std::string, std::vector<FuncInfo*>> &allFuncInfo);
void fillInterfaceBlock(std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo);
parF detectExpressionType(SgExpression* exp);
void findContainsFunctions(SgStatement *st, std::vector<SgStatement*> &found, const bool searchAll = false);
void correctNameIfContains(SgStatement* call, SgExpression* exCall, std::string& name, const std::vector<SgStatement*>& containsFunctions, const std::string& prefix);
int countPerfectLoopNest(SgStatement* st);
void setInlineAttributeToCalls(const std::map<std::string, FuncInfo*>& allFunctions, const std::map<std::string, std::set<std::pair<std::string, int>>>& inDataChains, const std::map<std::string, std::vector<SgStatement*>>& hiddenData);
#endif

View File

@@ -10,8 +10,10 @@ using std::wstring;
using std::inserter;
using std::copy;
using std::to_string;
bool IsSetsIntersect(const set<DIST::Array*>& lhs, const set<DIST::Array*>& rhs) {
bool IsSetsIntersect(const set<DIST::Array*>& lhs, const set<DIST::Array*>& rhs)
{
if (lhs.empty() || rhs.empty())
return false;
@@ -53,7 +55,8 @@ bool IsSetsIntersect(const set<DIST::Array*>& lhs, const set<DIST::Array*>& rhs)
return false;
}
static void findUsedArraysInParallelLoops(LoopGraph* loop, set<DIST::Array*>& res) {
static void findUsedArraysInParallelLoops(LoopGraph* loop, set<DIST::Array*>& res)
{
if(loop->directive)
copy(loop->usedArraysAll.begin(), loop->usedArraysAll.end(), inserter(res, res.end()));
else
@@ -62,7 +65,8 @@ static void findUsedArraysInParallelLoops(LoopGraph* loop, set<DIST::Array*>& re
}
static void preventLoopsFromParallelizations(LoopGraph* loop, const set<DIST::Array*>& prevent,
vector<Directive*>& createdDirectives) {
vector<Directive*>& createdDirectives,vector<Messages>& messagesForFile)
{
if (loop->directive)
{
if (IsSetsIntersect(prevent, loop->usedArraysAll))
@@ -83,12 +87,44 @@ static void preventLoopsFromParallelizations(LoopGraph* loop, const set<DIST::Ar
delete loop->directive;
loop->directive = NULL;
vector<DIST::Array*> conflict_arrays; // = prevent \intersection loop->usedArraysAll
set_intersection(prevent.begin(), prevent.end(),
loop->usedArraysAll.begin(), loop->usedArraysAll.end(),
back_inserter(conflict_arrays));
for(DIST::Array* conflict_array: conflict_arrays)
{
// constructing string with array and it's sizes
string array_bounds;
const auto& array_sizes = conflict_array->GetSizes();
for(int i = 0; i < array_sizes.size(); i++)
{
if(i != 0)
array_bounds += ",";
const auto& bounds_pair = array_sizes[i];
array_bounds += bounds_pair.first >= 0 ? to_string(bounds_pair.first) : "*";
array_bounds += ":";
array_bounds += bounds_pair.second >= 0 ? to_string(bounds_pair.second) : "*";
}
string array_ref = conflict_array->GetShortName() + "(" + array_bounds + ")";
// add conflict message
std::wstring bufE, bufR;
__spf_printToLongBuf(bufE, L"Array reference '%s' has a different size from the original array", to_wstring(array_ref).c_str());
__spf_printToLongBuf(bufR, R202, to_wstring(array_ref).c_str());
messagesForFile.push_back(Messages(WARR, loop->lineNum, bufR, bufE, 3023));
}
}
}
else
{
for (LoopGraph* child : loop->children)
preventLoopsFromParallelizations(child, prevent, createdDirectives);
preventLoopsFromParallelizations(child, prevent, createdDirectives, messagesForFile);
}
}
@@ -230,6 +266,7 @@ void SelectArrayConfForParallelization(SgProject* proj, map<string, vector<FuncI
for (const auto& byFile : loopGraph)
{
vector<Messages>& fileM = getObjectForFileFromMap(byFile.first.c_str(), allMessages);
auto dirs_it = createdDirectives.find(byFile.first);
if (dirs_it != createdDirectives.end())
{
@@ -261,7 +298,7 @@ void SelectArrayConfForParallelization(SgProject* proj, map<string, vector<FuncI
{
auto prevent_it = preventFromParallelization.find(byFunc);
if (prevent_it != preventFromParallelization.end())
preventLoopsFromParallelizations(loop, prevent_it->second, dirs_it->second);
preventLoopsFromParallelizations(loop, prevent_it->second, dirs_it->second, fileM);
loop_analyzed = true;
break;

View File

@@ -24,6 +24,8 @@ using std::make_pair;
using std::string;
using std::wstring;
using std::to_string;
using std::get;
using std::tuple;
#define DEB 0
@@ -99,7 +101,7 @@ static void checkSymbols(const int currFileId, const set<SgSymbol*>& symbs)
{
if (symb->getFileId() != currFileId)
{
__spf_print(1, "check failed - given %d, correct %d\n", symb->getFileId(), currFileId); // DEBUG
__spf_print(1, "check failed - given %d, correct %d\n", symb->getFileId(), currFileId);
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
}
}
@@ -107,14 +109,21 @@ static void checkSymbols(const int currFileId, const set<SgSymbol*>& symbs)
static map<string, SgExpression*> createMapOfArgs(SgStatement* tempHedr, SgExpression* actualArgs)
{
__spf_print(DEB, "------create map of vars------\n"); // DEBUG
map<string, SgExpression*> vars;
__spf_print(DEB, "------create map of vars------\n");
SgProgHedrStmt* hedr = isSgProgHedrStmt(tempHedr);
checkNull(hedr, convertFileName(__FILE__).c_str(), __LINE__);
int numPars = hedr->numberOfParameters();
map<string, SgExpression*> vars;
int i = 0;
while (actualArgs)
{
if (i >= numPars)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
auto actualArg = actualArgs->lhs();
auto formalArg = ((SgFunctionSymb*)tempHedr->symbol())->parameter(i++);
auto formalArg = hedr->parameter(i++);
auto it = vars.find(formalArg->identifier());
if (it == vars.end())
@@ -211,6 +220,40 @@ static inline SgSymbol* createSymbAndDecl(const string& funcName, const string&
return newS;
}
static SgStatement* findDuplicateInHidden(SgStatement* data)
{
SgStatement* clone = NULL;
auto itF = hiddenData.find(current_file->filename());
if (itF == hiddenData.end())
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
for (auto& func : itF->second)
{
if (func->fileName() != string(data->fileName()))
continue;
SgStatement* st = func->lexNext();
SgStatement* last = func->lastNodeOfStmt();
while (st != last)
{
if (data->lineNumber() == st->lineNumber() && data->variant() == st->variant())
{
clone = st;
break;
}
st = st->lexNext();
}
if (clone)
break;
}
checkNull(clone, convertFileName(__FILE__).c_str(), __LINE__);
return clone;
}
static SgValueExp* oneExpr = NULL;
static SgValueExp* zeroExpr = NULL;
@@ -237,11 +280,14 @@ static vector<SgExpression*> getLowBounds(SgSymbol* arrayS)
int consistInAllocates = 0;
const string origName = OriginalSymbol(copyFrom)->identifier();
for (auto& data : getAttributes<SgStatement*, SgStatement*>(decl, set<int>{ ALLOCATE_STMT }))
for (auto data : getAttributes<SgStatement*, SgStatement*>(decl, set<int>{ ALLOCATE_STMT }))
{
if (data->variant() != ALLOCATE_STMT)
continue;
if (data->getFileId() != current_file_id)
data = findDuplicateInHidden(data);
SgExpression* iter = data->expr(0);
while (iter)
@@ -1023,7 +1069,7 @@ static inline bool insert(SgStatement* callSt, SgStatement* funcStat, SgExpressi
SgStatement* tempHedr = NULL;
SgSymbol* tempSymb = NULL;
__spf_print(DEB, "------creating template------\n"); // DEBUG
__spf_print(DEB, "------creating template------\n");
// 2.a create function template
auto funcSt = funcSymb->body();
if (funcSt->variant() == ENTRY_STAT)
@@ -1104,6 +1150,8 @@ static inline void replaceCall(SgExpression* exp, SgExpression* par, const int i
SgAssignStmt* assign = new SgAssignStmt(*new SgVarRefExp(*v), *exp->copyPtr());
assign->setlineNumber(getNextNegativeLineNumber());
assign->setLocalLineNumber(callSt->lineNumber());
insertPlace->insertStmtBefore(*assign, *callSt->controlParent());
// replace function call to a new variable
@@ -1113,16 +1161,18 @@ static inline void replaceCall(SgExpression* exp, SgExpression* par, const int i
lhs ? par->setLhs(new SgVarRefExp(*v)) : par->setRhs(new SgVarRefExp(*v));
}
static void recFindFuncCall(SgExpression* exp, SgExpression* par, const int i, const bool lhs,
static void recFindFuncCall(FuncInfo* currentFuncI,
SgExpression* exp, SgExpression* par, const int i, const bool lhs,
const string& funcName, bool& foundCall,
SgStatement* callSt, set<SgSymbol*>& newSymbols, SgStatement* insertPlace)
{
if (exp)
{
recFindFuncCall(exp->rhs(), exp, i, false, funcName, foundCall, callSt, newSymbols, insertPlace);
recFindFuncCall(exp->lhs(), exp, i, true, funcName, foundCall, callSt, newSymbols, insertPlace);
recFindFuncCall(currentFuncI, exp->rhs(), exp, i, false, funcName, foundCall, callSt, newSymbols, insertPlace);
recFindFuncCall(currentFuncI, exp->lhs(), exp, i, true, funcName, foundCall, callSt, newSymbols, insertPlace);
if (exp->variant() == FUNC_CALL && exp->symbol() && exp->symbol()->identifier() == funcName)
if (exp->variant() == FUNC_CALL && exp->symbol() &&
currentFuncI->getCallName(make_pair(exp, exp->variant()), exp->symbol()->identifier(), callSt->lineNumber()) == funcName)
{
foundCall = true;
if (par) // do not extract external func call
@@ -1174,7 +1224,7 @@ static SgType* getTrueType(SgType* inExp, parF funcParType)
return inExp;
}
static inline void PrecalculateActualParameters(SgStatement* st, SgSymbol* s, SgExpression* e,
static inline void PrecalculateActualParameters(SgStatement* st, SgExpression* e,
const FuncInfo* func, set<SgSymbol*>& newSymbols)
{
// Precalculate actual parameter expressions
@@ -1254,7 +1304,8 @@ static void renameArgsIfGlobalNameIntersection(FuncInfo* func, const set<string>
for (int z = 0; z < 3; ++z)
renameArgs(st->expr(z), remapArgs);
auto prog = isSgProgHedrStmt(header);
auto prog = isSgProcHedrStmt(header);
PTR_SYMB listP = SYMB_FUNC_PARAM(BIF_SYMB(prog->thebif));
vector<PTR_SYMB> newElems;
for (int p = 0; p < prog->numberOfParameters(); ++p)
@@ -1264,11 +1315,12 @@ static void renameArgsIfGlobalNameIntersection(FuncInfo* func, const set<string>
if (it != remapArgs.end())
{
SgSymbol* replace = findSymbolOrCreate(current_file, it->second, par->type());
SgSymbol* replace = par->copyPtr();
replace->changeName(it->second.c_str());
newElems.push_back(replace->thesymb);
}
else
newElems.push_back(listP);
newElems.push_back(duplicateSymbol(listP));
listP = SYMB_NEXT_DECL(listP);
}
@@ -1316,7 +1368,7 @@ static bool run_inliner(const map<string, FuncInfo*>& funcMap, set<SgStatement*>
for (auto& callSt : toInsert)
{
SgStatement* insertPlace = callSt;
SgStatement* currentFunc = getFuncStat(callSt);
SgProgHedrStmt* currentFunc = (SgProgHedrStmt*) getFuncStat(callSt);
if (usedByFunc.find(currentFunc) == usedByFunc.end())
{
@@ -1333,11 +1385,12 @@ static bool run_inliner(const map<string, FuncInfo*>& funcMap, set<SgStatement*>
usedByFunc[currentFunc] = used;
}
auto itF = funcMap.find(currentFunc->symbol()->identifier());
auto itF = funcMap.find(currentFunc->nameWithContains());
if (itF == funcMap.end())
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
renameArgsIfGlobalNameIntersection(itF->second, globalNames);
FuncInfo* currentFuncI = itF->second;
renameArgsIfGlobalNameIntersection(currentFuncI, globalNames);
set<string> useStatsInFunc;
for (SgStatement* s = currentFunc; s != currentFunc->lastNodeOfStmt(); s = s->lexNext())
@@ -1375,7 +1428,6 @@ static bool run_inliner(const map<string, FuncInfo*>& funcMap, set<SgStatement*>
}
set<SgSymbol*> newSymbols;
bool foundCall = false;
if (!callSt || !isSgExecutableStatement(callSt))
@@ -1389,9 +1441,8 @@ static bool run_inliner(const map<string, FuncInfo*>& funcMap, set<SgStatement*>
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
}
__spf_print(DEB, "------start inliner-----\n"); // DEBUG
__spf_print(DEB, "---statement preprocessing---\n"); // DEBUG
__spf_print(DEB, "------start inliner-----\n");
__spf_print(DEB, "---statement preprocessing---\n");
//simple convertation
if (callSt->controlParent()->variant() == LOGIF_NODE)
LogIftoIfThen(callSt->controlParent());
@@ -1402,36 +1453,40 @@ static bool run_inliner(const map<string, FuncInfo*>& funcMap, set<SgStatement*>
// 1.a: make statement preprocessing
// if call statement contains several inlining functions, split every such call
for (int i = 0; i < 3; ++i)
recFindFuncCall(callSt->expr(i), NULL, i, false, funcName, foundCall, callSt, newSymbols, insertPlace);
recFindFuncCall(currentFuncI, callSt->expr(i), NULL, i, false, funcName, foundCall, callSt, newSymbols, insertPlace);
__spf_print(DEB, "---argument preprocessing---\n"); // DEBUG
__spf_print(DEB, "---argument preprocessing---\n");
// 1.b: make argument preprocessing
checkNull(begin, convertFileName(__FILE__).c_str(), __LINE__);
// if call statement has any expression as its artument, split this expression for separate statement
// if call statement has any function as its argument, split this call
for (auto st = begin->lexNext(); st != end; st = st->lexNext())
{
if (st->variant() == ASSIGN_STAT)
{
auto s = st->expr(1)->symbol();
if (s && s->identifier() == funcName)
auto rPart = st->expr(1);
int line = st->lineNumber() < 0 ? st->localLineNumber() : st->lineNumber();
if (rPart->variant() == FUNC_CALL && rPart->symbol() &&
currentFuncI->getCallName(make_pair(rPart, rPart->variant()), rPart->symbol()->identifier(), line) == funcName)
{
if (isSgVarRefExp(st->expr(0)) || isSgArrayRefExp(st->expr(0)) && !isSgArrayType(st->expr(0)->type()))
PrecalculateActualParameters(st, s, st->expr(1)->lhs(), func, newSymbols);
PrecalculateActualParameters(st, st->expr(1)->lhs(), func, newSymbols);
}
}
else if (st->variant() == PROC_STAT)
{
if (st->symbol() && st->symbol()->identifier() == funcName)
if (st->symbol() &&
currentFuncI->getCallName(make_pair(st, st->variant()), st->symbol()->identifier(), st->lineNumber()) == funcName)
{
foundCall = true;
if (st->expr(0))
PrecalculateActualParameters(st, st->symbol(), st->expr(0), func, newSymbols);
PrecalculateActualParameters(st, st->expr(0), func, newSymbols);
}
}
}
set<SgStatement*> useStats;
__spf_print(DEB, "---start inlining---\n"); // DEBUG
__spf_print(DEB, "---start inlining---\n");
// 2. create function template to modify and insert it
if (foundCall)
{
@@ -1446,33 +1501,34 @@ static bool run_inliner(const map<string, FuncInfo*>& funcMap, set<SgStatement*>
switch (st->variant())
{
case ASSIGN_STAT:
{
auto rPart = st->expr(1);
if (rPart->variant() == FUNC_CALL && rPart->symbol() && rPart->symbol()->identifier() == funcName)
{
bool doInline = insert(st, funcStat, rPart->lhs(), newSymbols, funcMap, toDelete, useStats, SPF_messages, point);
change |= doInline;
isInlined |= doInline;
auto rPart = st->expr(1);
int line = st->lineNumber() < 0 ? st->localLineNumber() : st->lineNumber();
if (rPart->variant() == FUNC_CALL && rPart->symbol() &&
currentFuncI->getCallName(make_pair(rPart, rPart->variant()), rPart->symbol()->identifier(), line) == funcName)
{
bool doInline = insert(st, funcStat, rPart->lhs(), newSymbols, funcMap, toDelete, useStats, SPF_messages, point);
change |= doInline;
isInlined |= doInline;
}
}
}
continue;
break;
case PROC_STAT:
if (st->symbol() && st->symbol()->identifier() == funcName)
if (st->symbol() &&
currentFuncI->getCallName(make_pair(st, st->variant()), st->symbol()->identifier(), st->lineNumber()) == funcName)
{
bool doInline = insert(st, funcStat, st->expr(0), newSymbols, funcMap, toDelete, useStats, SPF_messages, point);
change |= doInline;
isInlined |= doInline;
}
continue;
break;
default:
continue;
break;
}
}
for (auto& st : toDelete)
{
st->extractStmt();
}
}
}
@@ -1584,11 +1640,11 @@ static map<FuncInfo*, set<SgStatement*>> fillNextDeep(const set<SgStatement*>& i
return nextInfo;
}
bool inliner(const string& fileName_in, const string& funcName, const int lineNumber,
const map<string, vector<FuncInfo*>>& allFuncInfo, map<string, vector<Messages>>& SPF_messages,
map<SgStatement*, set<SgSymbol*>>& newSymbsToDeclare, const map<string, CommonBlock*>& commonBlocks,
int deepLvl)
{
static bool inliner(const string& fileName_in, const string& funcName, const int lineNumber,
const map<string, vector<FuncInfo*>>& allFuncInfo, map<string, vector<Messages>>& SPF_messages,
map<SgStatement*, set<SgSymbol*>>& newSymbsToDeclare, const map<string, CommonBlock*>& commonBlocks,
int deepLvl = 0)
{
map<string, FuncInfo*> funcMap;
createMapOfFunc(allFuncInfo, funcMap);
@@ -1613,8 +1669,9 @@ bool inliner(const string& fileName_in, const string& funcName, const int lineNu
{
for (auto& callTo : func->callsTo)
{
for (auto& callFrom : callTo->detailCallsFrom)
for (auto& callInfo : callTo->callsFromDetailed)
{
auto& callFrom = callInfo.detailCallsFrom;
if (callFrom.first == funcName)
{
SgStatement* callSt = SgStatement::getStatementByFileAndLine(fileName, callFrom.second);
@@ -1648,7 +1705,7 @@ bool inliner(const string& fileName_in, const string& funcName, const int lineNu
}
if (markers.size() == 0)
return 0;
return false;
PointCall point;
point.mainPoint.first = fileName;
@@ -1658,7 +1715,7 @@ bool inliner(const string& fileName_in, const string& funcName, const int lineNu
point.currLvl = 0;
point.currCall = func->funcName;
__spf_print(1, "INLINE %s\n", func->funcName.c_str());
__spf_print(1, " INLINE %s\n", func->funcName.c_str());
#ifdef _WIN32
sendMessage_2lvl(wstring(L"<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> '") + wstring(func->funcName.begin(), func->funcName.end()) + L"'");
#else
@@ -1667,6 +1724,12 @@ bool inliner(const string& fileName_in, const string& funcName, const int lineNu
//1 level
bool isInlined = run_inliner(funcMap, toInsert, SPF_messages, fileName, func, newSymbsToDeclare, point, commonBlocks);
if (isInlined == false)
{
__spf_print(1, " missing ...\n");
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
}
if (deepLvl >= 0 && isInlined)
{
int currDeep = 0;
@@ -1691,7 +1754,7 @@ bool inliner(const string& fileName_in, const string& funcName, const int lineNu
point.currLvl = currDeep;
point.currCall = next.first->funcName;
__spf_print(1, "INLINE %s\n", next.first->funcName.c_str());
__spf_print(1, " INLINE %s\n", next.first->funcName.c_str());
bool isInlined = run_inliner(funcMap, next.second, SPF_messages, fileName, next.first, newSymbsToDeclare, point, commonBlocks);
changed |= isInlined;
}
@@ -1704,10 +1767,10 @@ bool inliner(const string& fileName_in, const string& funcName, const int lineNu
return true;
}
bool inliner(const string& allInFunc, const map<string, vector<FuncInfo*>>& allFuncInfo,
map<string, vector<Messages>>& SPF_messages,
map<SgStatement*, set<SgSymbol*>>& newSymbsToDeclare, const map<string, CommonBlock*>& commonBlocks,
int deepLvl)
static bool inliner(const string& allInFunc, const map<string, vector<FuncInfo*>>& allFuncInfo,
map<string, vector<Messages>>& SPF_messages,
map<SgStatement*, set<SgSymbol*>>& newSymbsToDeclare, const map<string, CommonBlock*>& commonBlocks,
int deepLvl = 0)
{
bool result = true;
map<string, FuncInfo*> funcMap;
@@ -1719,8 +1782,9 @@ bool inliner(const string& allInFunc, const map<string, vector<FuncInfo*>>& allF
if (SgFile::switchToFile(func->fileName) == -1)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
for (auto& callFrom : func->detailCallsFrom)
for (auto& callInfo : func->callsFromDetailed)
{
auto& callFrom = callInfo.detailCallsFrom;
bool res = inliner(func->fileName, callFrom.first, callFrom.second, allFuncInfo, SPF_messages, newSymbsToDeclare, commonBlocks, deepLvl);
result = result && res;
}
@@ -1888,7 +1952,7 @@ static bool addNewCommonDecl(SgSymbol* toDec, const int posNum, const string& co
return false;
}
void createDeclarations(const map<SgStatement*, set<SgSymbol*>>& newSymbsToDeclare, const map<string, CommonBlock*>& commonBlocks)
static void createDeclarations(const map<SgStatement*, set<SgSymbol*>>& newSymbsToDeclare, const map<string, CommonBlock*>& commonBlocks)
{
map<pair<string, int>, map<string, string>> preprocDataByFunc; // key is <funcName, int>
map<pair<string, int>, map<string, SgExpression*>> initValue;
@@ -2293,3 +2357,141 @@ void createDeclarations(const map<SgStatement*, set<SgSymbol*>>& newSymbsToDecla
}
}
}
static void convertLinesToAbsolute(const map<string, vector<FuncInfo*>>& allFuncInfo,
vector<tuple<string, string, int>>& inDataProc)
{
set<tuple<string, string, int>> added;
for (int z = 0; z < inDataProc.size(); ++z)
{
if (std::get<2>(inDataProc[z]) > 0)
continue;
auto funcToInl = std::get<0>(inDataProc[z]);
auto file = std::get<1>(inDataProc[z]);
int absoluteLine = 0;
int shilftLine = -std::get<2>(inDataProc[z]);
for (auto& funcByFile : allFuncInfo)
{
if (funcByFile.first != file)
continue;
for (auto& func : funcByFile.second)
{
int targetLine = func->linesNum.first + shilftLine;
//__spf_print(1, "%s target %d + %d = %d\n", func->funcName.c_str(), func->linesNum.first, shilftLine, targetLine);
for (auto& detCall : func->callsFromDetailed)
{
if (detCall.detailCallsFrom == make_pair(funcToInl, targetLine) &&
added.find(make_tuple(file, funcToInl, targetLine)) == added.end())
{
__spf_print(1, "%s %d (was %d) %s\n", funcToInl, targetLine, std::get<2>(inDataProc[z]), funcByFile.first.c_str());
added.insert(make_tuple(file, funcToInl, targetLine));
absoluteLine = targetLine;
break;
}
}
if (absoluteLine)
break;
}
if (absoluteLine)
break;
}
if (absoluteLine == 0)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
std::get<2>(inDataProc[z]) = absoluteLine;
}
}
void callInliner(const map<string, vector<FuncInfo*>>& allFuncInfo,
vector<tuple<string, string, int>>& inDataProc,
map<string, set<pair<string, int>>>& inDataChains,
const set<string>& inDataChainsStart,
map<string, vector<Messages>>& SPF_messages,
const map<string, CommonBlock*>& commonBlocks)
{
map<SgStatement*, set<SgSymbol*>> newSymbsToDeclare;
map<string, FuncInfo*> tmpM;
createMapOfFunc(allFuncInfo, tmpM);
FuncInfo* mainF = NULL;
for (auto& elem : tmpM)
if (elem.second->isMain)
mainF = elem.second;
checkNull(mainF, convertFileName(__FILE__).c_str(), __LINE__);
#if 0
//inliner(mainF->funcName, allFuncInfo, SPF_messages, newSymbsToDeclare);
#else
if (inDataProc.size())
{
__spf_print(1, "count of inline data %ld\n", inDataProc.size());
convertLinesToAbsolute(allFuncInfo, inDataProc);
map<int, vector<int>> sortByLvl;
int maxLvlCall = 0;
for (int z = 0; z < inDataProc.size(); ++z)
{
if (std::get<2>(inDataProc[z]) != -1)
{
int lvl = getLvlCall(mainF, 0, std::get<0>(inDataProc[z]), std::get<1>(inDataProc[z]), std::get<2>(inDataProc[z]));
if (lvl == -1)
{
bool found = false;
for (auto& func : tmpM)
{
if (func.second->isMain)
continue;
int lvlTmp = getLvlCall(func.second, 0, std::get<0>(inDataProc[z]), std::get<1>(inDataProc[z]), std::get<2>(inDataProc[z]));
if (lvlTmp != -1)
lvl = std::max(lvl, lvlTmp);
}
if (lvl == -1)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
}
maxLvlCall = std::max(maxLvlCall, lvl);
sortByLvl[lvl].push_back(z);
}
}
for (int z = 0; z < inDataProc.size(); ++z)
if (std::get<2>(inDataProc[z]) == -1)
sortByLvl[maxLvlCall + 1].push_back(z);
for (auto& byLvl : sortByLvl)
{
for (auto& idx : byLvl.second)
{
auto& tup = inDataProc[idx];
if (std::get<2>(tup) != -1)
{
__spf_print(1, " call inliner with [%s %s %d]\n", std::get<1>(tup).c_str(), std::get<0>(tup).c_str(), std::get<2>(tup));
bool isInlined = inliner(std::get<1>(tup), std::get<0>(tup), std::get<2>(tup), allFuncInfo, SPF_messages, newSymbsToDeclare, commonBlocks);
if (!isInlined)
{
__spf_print(1, " missing ...\n");
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
}
}
}
}
}
else if (inDataChains.size())
{
setInlineAttributeToCalls(tmpM, inDataChains, hiddenData);
for (auto& startPoint : inDataChainsStart)
{
__spf_print(1, "call inliner from '%s'\n", startPoint.c_str());
inliner(startPoint, allFuncInfo, SPF_messages, newSymbsToDeclare, commonBlocks);
}
}
#endif
createDeclarations(newSymbsToDeclare, commonBlocks);
}

View File

@@ -4,6 +4,9 @@
#include <map>
#include <string>
bool inliner(const std::string& fileName, const std::string& funcName, const int lineNumber, const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo, std::map<std::string, std::vector<Messages>>& SPF_messages, std::map<SgStatement*, std::set<SgSymbol*>>& newSymbsToDeclare, const std::map<std::string, CommonBlock*>& commonBlocks, int deepLvl = 0);
bool inliner(const std::string& allInFunc, const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo, std::map<std::string, std::vector<Messages>>& SPF_messages, std::map<SgStatement*, std::set<SgSymbol*>>& newSymbsToDeclare, const std::map<std::string, CommonBlock*>& commonBlocks, int deepLvl = 0);
void createDeclarations(const std::map<SgStatement*, std::set<SgSymbol*>>& newSymbsToDeclare, const std::map<std::string, CommonBlock*>& commonBlocks);
void callInliner(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo,
std::vector<std::tuple<std::string, std::string, int>>& inDataProc,
std::map<std::string, std::set<std::pair<std::string, int>>>& inDataChains,
const std::set<std::string>& inDataChainsStart,
std::map<std::string, std::vector<Messages>>& SPF_messages,
const std::map<std::string, CommonBlock*>& commonBlocks);

View File

@@ -629,16 +629,6 @@ void findArrayRef(const vector<SgForStmt*> &parentLoops, SgExpression *currExp,
fillReductionsFromComment(new Statement(data), loopsReductions);
fillReductionsFromComment(new Statement(data), loopsReductionsLoc);
}
set<string> dummy;
auto res = parseOmpDirs(loop, dummy);
for (auto& dir : res)
if (dir.keys.find("do") != dir.keys.end())
if (itFound->second.first->IsOmpThreadPrivate())
{
loopsPrivates.insert(itFound->second.first->GetShortName());
privatesVarsForLoop[z].insert(itFound->second.first->GetShortName());
}
}
for (auto &elem : loopsReductions)
@@ -927,20 +917,20 @@ static SgExpression* replaceConstatantProcedurePars(SgExpression *dimList, SgSta
for (int z = 0; z < currF->callsTo.size(); ++z)
{
FuncInfo* callOfThis = currF->callsTo[z];
for (int p = 0; p < callOfThis->detailCallsFrom.size(); ++p)
for (int p = 0; p < callOfThis->callsFromDetailed.size(); ++p)
{
if (callOfThis->detailCallsFrom[p].first == procN)
if (callOfThis->callsFromDetailed[p].detailCallsFrom.first == procN)
{
for (auto& par : idxFound)
{
auto parType = callOfThis->actualParams[p].parametersT[par];
auto parType = callOfThis->callsFromDetailed[p].actualParams.parametersT[par];
if (parType != SCALAR_INT_T)
return dimList;
else
{
if (callOfThis->actualParams[p].parameters[par] == NULL)
if (callOfThis->callsFromDetailed[p].actualParams.parameters[par] == NULL)
return dimList;
values[par].insert(((int*)(callOfThis->actualParams[p].parameters[par]))[0]);
values[par].insert(((int*)(callOfThis->callsFromDetailed[p].actualParams.parameters[par]))[0]);
}
}
}
@@ -2609,17 +2599,11 @@ static bool findOmpThreadPrivDecl(SgStatement* st, map<SgStatement*, set<string>
{
st = st->lexNext();
if (st->variant() == CONTAINS_STMT)
break;
if (isSgExecutableStatement(st))
break;
auto res = parseOmpDirs(st, dummy);
for (auto& dir : res)
for (auto& var : dir.threadPrivVars)
it->second.insert(var);
} while (st != lastN);
} while (st != lastN && !isSgExecutableStatement(st) && st->variant() != CONTAINS_STMT);
}
if (it->second.find(toFind->identifier()) != it->second.end())
@@ -2833,7 +2817,9 @@ static void findArrayRefs(SgExpression *ex, SgStatement *st, string fName, int p
const auto oldVal = itNew->second.first->GetDistributeFlagVal();
if (oldVal == DIST::DISTR || oldVal == DIST::NO_DISTR)
{
if (privates.find(symb->identifier()) != privates.end() || itNew->second.first->IsOmpThreadPrivate())
if (itNew->second.first->IsOmpThreadPrivate())
itNew->second.first->SetDistributeFlag(DIST::SPF_PRIV);
else if (privates.find(symb->identifier()) != privates.end())
{
//check in module
if (itNew->second.first->GetLocation().first == DIST::l_MODULE)

View File

@@ -98,7 +98,7 @@ static void updateRegionInfo(SgStatement *st, map<string, pair<Statement*, State
{
string containsPrefix = "";
SgStatement *st_ps = getParentStat(st);
const string funcName = st_ps->symbol()->identifier(); // DEBUG
if (st_ps->variant() == PROC_HEDR || st_ps->variant() == PROG_HEDR || st_ps->variant() == FUNC_HEDR)
containsPrefix = st_ps->symbol()->identifier() + string(".");

View File

@@ -348,10 +348,12 @@ void fillRegionFunctions(vector<ParallelRegion*> &regions, const map<string, vec
// add DEFAULT region (regionId == 0)
if (func->isIndirect())
{
for (auto &elem : func->detailCallsFrom)
for (auto &callInfo : func->callsFromDetailed)
{
auto line = elem.second;
auto call = elem.first;
auto& callFrom = callInfo.detailCallsFrom;
auto line = callFrom.second;
auto call = callFrom.first;
auto callF = getFuncInfo(funcMap, call);
auto regs = getAllRegionsByLine(regions, func->fileName, line).size();
if (callF && !getAllRegionsByLine(regions, func->fileName, line).size())
@@ -1623,7 +1625,7 @@ int resolveParRegions(vector<ParallelRegion*> &regions, const map<string, vector
for (auto& region : regions)
{
__spf_print(1, "[%s]: create local arrays\n", region->GetName().c_str()); // DEBUG
__spf_print(1, "[%s]: create local arrays\n", region->GetName().c_str());
// creating new local arrays
for (auto& funcArrays : region->GetUsedLocalArrays())
@@ -1659,7 +1661,7 @@ int resolveParRegions(vector<ParallelRegion*> &regions, const map<string, vector
}
}
__spf_print(1, "[%s]: create common arrays\n", region->GetName().c_str()); // DEBUG
__spf_print(1, "[%s]: create common arrays\n", region->GetName().c_str());
// creating new common-blocks for files with explicit lines
for (auto& fileLines : region->GetAllLines())
@@ -1791,7 +1793,7 @@ int resolveParRegions(vector<ParallelRegion*> &regions, const map<string, vector
}
}
__spf_print(1, "create functions\n"); // DEBUG
__spf_print(1, "create functions\n");
// creating new functions
for (auto &fileFuncs : allFuncInfo)
@@ -1905,7 +1907,7 @@ int resolveParRegions(vector<ParallelRegion*> &regions, const map<string, vector
if (mpiProgram == 0)
{
__spf_print(1, "insert DVM intervals\n"); // DEBUG
__spf_print(1, "insert DVM intervals\n");
// inserting dvm intervals
for (auto& region : regions)

View File

@@ -78,6 +78,7 @@
#include "Transformations/function_purifying.h"
#include "Transformations/private_removing.h"
#include "Transformations/fix_common_blocks.h"
#include "Transformations/convert_to_c.h"
#include "Transformations/set_implicit_none.h"
#include "RenameSymbols/rename_symbols.h"
@@ -1146,6 +1147,21 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
groupActualAndRemote(file, true);
else if (curr_regime == RENAME_SYMBOLS)
runRenameSymbolsByFiles(file, &project);
else if (curr_regime == REMOVE_OMP_DIRS)
{
for (SgStatement* st = file->firstStatement(); st; st = st->lexNext())
removeOmpDir(st);
}
else if (curr_regime == REMOVE_COMMENTS)
{
for (SgStatement* st = file->firstStatement(); st; st = st->lexNext())
if (st->comments())
st->delComments();
}
else if (curr_regime == GET_MIN_MAX_BLOCK_DIST)
getMaxMinBlockDistribution(file, min_max_block);
else if (curr_regime == CONVERT_TO_C)
covertToC(file);
else if (curr_regime == TEST_PASS)
{
//test pass
@@ -2014,144 +2030,9 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
else if (curr_regime == CREATE_PARALLEL_DIRS)
filterParallelDirectives(loopGraph, createdDirectives);
else if (curr_regime == INLINE_PROCEDURES)
{
map<SgStatement*, set<SgSymbol*>> newSymbsToDeclare;
map<string, FuncInfo*> tmpM;
createMapOfFunc(allFuncInfo, tmpM);
FuncInfo* mainF = NULL;
for (auto& elem : tmpM)
if (elem.second->isMain)
mainF = elem.second;
checkNull(mainF, convertFileName(__FILE__).c_str(), __LINE__);
#if 0
//inliner(mainF->funcName, allFuncInfo, SPF_messages, newSymbsToDeclare);
#else
if (inDataProc.size())
{
map<int, vector<int>> sortByLvl;
int maxLvlCall = 0;
for (int z = 0; z < inDataProc.size(); ++z)
{
if (std::get<2>(inDataProc[z]) != -1)
{
int lvl = getLvlCall(mainF, 0, std::get<0>(inDataProc[z]), std::get<1>(inDataProc[z]), std::get<2>(inDataProc[z]));
if (lvl == -1)
{
bool found = false;
for (auto& func : tmpM)
{
if (func.second->isMain)
continue;
int lvlTmp = getLvlCall(func.second, 0, std::get<0>(inDataProc[z]), std::get<1>(inDataProc[z]), std::get<2>(inDataProc[z]));
if (lvlTmp != -1)
lvl = std::max(lvl, lvlTmp);
}
if (lvl == -1)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
}
maxLvlCall = std::max(maxLvlCall, lvl);
sortByLvl[lvl].push_back(z);
}
}
for (int z = 0; z < inDataProc.size(); ++z)
if (std::get<2>(inDataProc[z]) == -1)
sortByLvl[maxLvlCall + 1].push_back(z);
for (auto& byLvl : sortByLvl)
{
for (auto& idx : byLvl.second)
{
auto& tup = inDataProc[idx];
if (std::get<2>(tup) != -1)
{
__spf_print(1, "call inliner with [%s %s %d]\n", std::get<1>(tup).c_str(), std::get<0>(tup).c_str(), std::get<2>(tup));
inliner(std::get<1>(tup), std::get<0>(tup), std::get<2>(tup), allFuncInfo, SPF_messages, newSymbsToDeclare, commonBlocks);
}
}
}
}
else if (inDataChains.size())
{
setInlineAttributeToCalls(tmpM, inDataChains, hiddenData);
for (auto& startPoint : inDataChainsStart)
{
__spf_print(1, "call inliner from '%s'\n", startPoint.c_str());
inliner(startPoint, allFuncInfo, SPF_messages, newSymbsToDeclare, commonBlocks);
}
}
#endif
createDeclarations(newSymbsToDeclare, commonBlocks);
}
callInliner(allFuncInfo, inDataProc, inDataChains, inDataChainsStart, SPF_messages, commonBlocks);
else if (curr_regime == INSERT_REGIONS)
{
vector<DvmhRegionInserter*> inserters;
const bool regionCondition = ((parallelRegions.size() == 0 && parallelRegions[0]->GetName() == "DEFAULT") || mpiProgram == 1);
set<DIST::Array*> usedArraysInRegions;
set<DIST::Array*> usedWriteArraysInRegions;
set<FuncInfo*> forPure;
for (int i = n - 1; i >= 0; --i)
{
SgFile* file = &(project.file(i));
__spf_print(1, "Start region inserter for file %s\n", file->filename());
map<string, FuncInfo*> mapOfFuncs;
createMapOfFunc(allFuncInfo, mapOfFuncs);
auto loopsForFile = getObjectForFileFromMap(file->filename(), loopGraph);
auto funcsForFile = getObjectForFileFromMap(file->filename(), allFuncInfo);
for (auto& loop : loopsForFile)
loop->analyzeParallelDirs();
DvmhRegionInserter* regionInserter = new DvmhRegionInserter(file, loopsForFile, rw_analyzer, arrayLinksByFuncCalls, mapOfFuncs, funcsForFile, mpiProgram == 1);
inserters.push_back(regionInserter);
//collect info about <parallel> functions
regionInserter->updateParallelFunctions(loopGraph);
if (regionCondition)
regionInserter->insertDirectives(NULL);
else
regionInserter->insertDirectives(&parallelRegions);
//remove privates from loops out of DVMH region
//remove parallel directives from loops out of DVMH region for MPI regime
regionInserter->removePrivatesFromParallelLoops();
//add privates to parallel loops with manual parallelization in DVMH regions
regionInserter->addPrivatesToParallelLoops();
//create interface for 'parallel' functions
regionInserter->createInterfaceBlock();
regionInserter->addUsedArrays(usedArraysInRegions);
regionInserter->addUsedWriteArrays(usedWriteArraysInRegions);
auto parallelFuncs = regionInserter->getParallelFunctions();
forPure.insert(parallelFuncs.begin(), parallelFuncs.end());
}
setPureStatus(forPure);
for (auto& regionInserter : inserters)
{
regionInserter->updateUsedArrays(usedArraysInRegions, usedWriteArraysInRegions);
if (regionCondition)
regionInserter->insertActualDirectives(NULL);
else
regionInserter->insertActualDirectives(&parallelRegions);
delete regionInserter;
}
}
insertDvmhRegions(project, n, parallelRegions, allFuncInfo, loopGraph, rw_analyzer, arrayLinksByFuncCalls);
else if (curr_regime == RENAME_SYMBOLS)
runRenameSymbols(&project, commonBlocks);
else if (curr_regime == FIND_PARAMETERS)
@@ -2179,11 +2060,13 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
else if (curr_regime == SET_IMPLICIT_NONE)
ImplicitCheck(&project);
else if (curr_regime == SELECT_ARRAY_DIM_CONF) {
map<string, vector<Messages>> localMessages;
SelectArrayConfForParallelization(&project, allFuncInfo, loopGraph, createdDirectives, localMessages, arrayLinksByFuncCalls, parallelRegions);
SelectArrayConfForParallelization(&project, allFuncInfo, loopGraph, createdDirectives, SPF_messages, arrayLinksByFuncCalls, parallelRegions);
removeRegionsWithoutDirs(createdDirectives, parallelRegions, allFuncInfo, SPF_messages);
}
else if (curr_regime == GET_MIN_MAX_BLOCK_DIST)
{
__spf_print(1, "GET_MIN_MAX_BLOCK_DIST: %d %d\n", min_max_block.first, min_max_block.second);
}
const float elapsed = duration_cast<milliseconds>(high_resolution_clock::now() - timeForPass).count() / 1000.;
const float elapsedGlobal = duration_cast<milliseconds>(high_resolution_clock::now() - globalTime).count() / 1000.;
@@ -2539,8 +2422,23 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam
}
}
FILE* templatesInfo = NULL;
if (consoleMode && withTemplateInfo) {
string file = (folderName) ? (folderName + string("/")) : "";
file += "templates_info_";
file += to_string(i + 1);
file += ".txt";
templatesInfo = fopen(file.c_str(), "w");
if (templatesInfo == NULL)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
}
for (int z = 0; z < parallelRegions.size(); ++z)
{
if (consoleMode && withTemplateInfo)
fprintf(templatesInfo, "FOR region %s\n", parallelRegions[z]->GetName().c_str());
const DataDirective& dataDirectives = parallelRegions[z]->GetDataDir();
const vector<int>& currentVariant = parallelRegions[z]->GetCurrentVariant();
@@ -2548,12 +2446,23 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam
for (int z1 = 0; z1 < currentVariant.size(); ++z1)
{
if (tmp[z1].first->IsTemplate())
{
if (consoleMode && withTemplateInfo)
{
SgExpression* rule = new SgExpression(EXPR_LIST);
tmp[z1].second[currentVariant[z1]].GenRule(new File(current_file), new Expression(rule), tmp[z1].first->GetNewTemplateDimsOrder());
fprintf(templatesInfo, "%s(%s)\n", tmp[z1].first->GetShortName().c_str(), rule->unparse());
}
tmp[z1].first->ClearTemplateClones();
}
}
}
if (tmpFolder != "" && consoleMode)
folderName = NULL;
if (consoleMode && withTemplateInfo)
fclose(templatesInfo);
}
}
break;
@@ -2571,6 +2480,8 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam
case SET_TO_ALL_DECL_INIT_ZERO:
case CREATE_CHECKPOINTS:
case PURE_INTENT_INSERT:
case REMOVE_OMP_DIRS_TRANSFORM:
case REMOVE_COMMENTS:
runAnalysis(*project, curr_regime, true, "", folderName);
break;
case PRIVATE_REMOVING:
@@ -2738,7 +2649,9 @@ int main(int argc, char **argv)
SPEED = 100;
}
}
else if (curr_arg[1] == 't') // deprecated
else if (string(curr_arg) == "-tinfo")
withTemplateInfo = true;
else if (string(curr_arg) == "-t") // deprecated
{
i++;
int par = atoi(argv[i]);
@@ -2806,7 +2719,8 @@ int main(int argc, char **argv)
parallizeFreeLoops = 1;
else if (string(curr_arg) == "-parse")
{
auto result = splitCommandLineForParse(argv + (i + 1), argc - (i + 1));
bool isInline = false;
auto result = splitCommandLineForParse(argv + (i + 1), argc - (i + 1), isInline);
if (result.second.size() == 0)
{
printf("Nothing to parse\n");
@@ -2828,7 +2742,7 @@ int main(int argc, char **argv)
listOfProject.push_back(FileInfo(file, toAddOpt + "-o " + file + ".dep", "", "", "", fileText, 0));
}
int rethrow = parseFiles(errors, listOfProject, filesCompilationOrder, 0, true);
int rethrow = parseFiles(errors, listOfProject, filesCompilationOrder, isInline, true);
if (rethrow == 0)
{
for (auto& err : errors)

View File

@@ -167,6 +167,11 @@ enum passes {
PRIVATE_ANALYSIS_IR,
FIX_COMMON_BLOCKS,
REMOVE_OMP_DIRS,
REMOVE_OMP_DIRS_TRANSFORM,
REMOVE_COMMENTS,
GET_MIN_MAX_BLOCK_DIST,
CONVERT_TO_C,
SET_IMPLICIT_NONE,
@@ -341,6 +346,11 @@ static void setPassValues()
passNames[PRIVATE_ANALYSIS_IR] = "PRIVATE_ANALYSIS_IR";
passNames[FIX_COMMON_BLOCKS] = "FIX_COMMON_BLOCKS";
passNames[REMOVE_OMP_DIRS] = "REMOVE_OMP_DIRS";
passNames[REMOVE_OMP_DIRS_TRANSFORM] = "REMOVE_OMP_DIRS_TRANSFORM";
passNames[REMOVE_COMMENTS] = "REMOVE_COMMENTS";
passNames[GET_MIN_MAX_BLOCK_DIST] = "GET_MIN_MAX_BLOCK_DIST";
passNames[CONVERT_TO_C] = "CONVERT_TO_C";
passNames[SET_IMPLICIT_NONE] = "SET_IMPLICIT_NONE";
passNames[TEST_PASS] = "TEST_PASS";

View File

@@ -45,6 +45,7 @@ int debSh = 0; // shadow optimization debugging
bool ignoreArrayDistributeState = false;
bool fullDepGraph = false;
bool noLogo = false;
bool withTemplateInfo = false;
uint64_t currentAvailMemory = 0;
int QUALITY; // quality of conflicts search in graph
@@ -167,6 +168,9 @@ std::map<int, UserFiles> filesInfo; // information about open,close,write and re
std::map< std::pair<std::string, int>, std::set<std::string>> parametersOfProject; // [file, line] -> set[vars]
//
//for GET_MIN_MAX_BLOCK_DIST
std::pair<int, int> min_max_block = std::make_pair(-1, -1);
//
const char* passNames[EMPTY_PASS + 1];
const char* optionNames[EMPTY_OPTION + 1];
bool passNamesWasInit = false;

View File

@@ -1011,8 +1011,9 @@ void createCheckpoints(SgFile *file, const map<string, CommonBlock*>& commonBloc
}
for (auto& call : (j->second)->pointerDetailCallsFrom)
for (auto& callInfo : j->second->callsFromDetailed)
{
auto& call = callInfo.pointerDetailCallsFrom;
SgStatement* st = NULL;
if (isSgFuncHedrStmt(hedrTo) && call.second == FUNC_CALL)

View File

@@ -0,0 +1,365 @@
#include "../Utils/leak_detector.h"
#include <cstdio>
#include <cstring>
#include <cstring>
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <set>
#include <vector>
#include <algorithm>
#include <tuple>
#include "dvm.h"
#include "convert_to_c.h"
#include "Utils/utils.h"
#include "Utils/SgUtils.h"
using std::vector;
using std::string;
using std::set;
extern "C" void Set_Function_Language(int);
extern "C" void Unset_Function_Language();
extern "C" int out_upper_case;
static SgStatement* createNewFunc(SgSymbol* sF, SgFile* file, SgProgHedrStmt* prog)
{
SgStatement* st_hedr, * st_end;
SgExpression* fe, *arg_list = NULL;
bool isMain = sF == NULL;
if (!sF)
sF = findSymbolOrCreate(file, "main", C_VoidType());
else
sF->setType(C_VoidType());
// create fuction header
st_hedr = new SgStatement(FUNC_HEDR);
st_hedr->setSymbol(*sF);
fe = new SgFunctionRefExp(*sF);
fe->setSymbol(*sF);
st_hedr->setExpression(0, *fe);
// create end of function
st_end = new SgStatement(CONTROL_END);
st_end->setSymbol(*sF);
if (!isMain)
{
//fill global
first_do_par = prog;
fe = st_hedr->expr(0);
int num = prog->numberOfParameters();
for (int z = 0; z < num; ++z)
{
SgSymbol* arg = prog->parameter(z);
auto typ = C_Type(arg->type());
if (arg->type()->variant() == T_STRING)
typ = C_PointerType(SgTypeChar());
auto s = new SgSymbol(VARIABLE_NAME, arg->identifier(), *typ, *st_hedr);
SgExpression* ae = new SgVarRefExp(s);
ae->setType(typ);
if (arg->type()->variant() == T_STRING)
ae = new SgPointerDerefExp(*ae);
if (z == 0)
{
arg_list = new SgExprListExp(*ae);
fe->setLhs(arg_list);
}
else
{
auto el = new SgExpression(EXPR_LIST);
el->setLhs(NULL);
ae->setLhs(*el);
arg_list->setRhs(*new SgExprListExp(*ae));
arg_list = arg_list->rhs();
}
}
first_do_par = NULL;
}
return st_hedr;
}
static void shiftIntValue(SgExpression* ex, SgExpression* par, bool isLeft, const set<string>& for_vars, bool& rep)
{
if (ex)
{
if (ex->variant() == VAR_REF && for_vars.find(ex->symbol()->identifier()) != for_vars.end())
{
if (isLeft)
par->setLhs(*new SgExpression(SUBT_OP, ex->copyPtr(), new SgValueExp(1)));
else
par->setRhs(*new SgExpression(SUBT_OP, ex->copyPtr(), new SgValueExp(1)));
rep = true;
}
shiftIntValue(ex->lhs(), ex, true, for_vars, rep);
shiftIntValue(ex->rhs(), ex, false, for_vars, rep);
}
}
static void findArrayRef(SgExpression* ex, const set<string>& for_vars)
{
if (ex)
{
if (ex->variant() == ARRAY_REF)
{
SgArrayRefExp* ref = (SgArrayRefExp*)ex;
SgExpression* list = ex->lhs();
for (int z = 0; z < ref->numberOfSubscripts(); ++z)
{
bool rep = false;
if (for_vars.size())
shiftIntValue(ref->subscript(z), list, true, for_vars, rep);
if (!rep || for_vars.size() == 0)
{
auto sub = ref->subscript(z);
auto val = isSgValueExp(sub);
if (val && val->isInteger())
val->setValue(val->intValue() - 1);
else
list->setLhs(*new SgExpression(SUBT_OP, sub->copyPtr(), new SgValueExp(1)));
}
list = list->rhs();
}
}
findArrayRef(ex->lhs(), for_vars);
findArrayRef(ex->rhs(), for_vars);
}
}
static void findLoopSymbols(SgExpression* ex, set<string>& vars)
{
if (ex)
{
if (ex->variant() == VAR_REF)
vars.insert(ex->symbol()->identifier());
findLoopSymbols(ex->lhs(), vars);
findLoopSymbols(ex->rhs(), vars);
}
}
void covertToC(SgFile* file)
{
out_upper_case = 0;
int funcNum = file->numberOfFunctions();
SgStatement* global = file->firstStatement();
vector<SgStatement*> funcs;
for (int i = 0; i < funcNum; ++i)
funcs.push_back(file->functions(i));
for (int i = funcs.size() - 1; i >= 0; --i)
{
SgStatement* st = funcs[i];
SgStatement* last = st->lastNodeOfStmt();
//fill global dvm variables
cur_func = st;
bind_ = 1;
//
SgStatement* func = createNewFunc(st->variant() == PROG_HEDR ? NULL : st->symbol()->copyPtr(), file, isSgProgHedrStmt(st));
SgStatement* lastOfFunc = func->lastNodeOfStmt();
global->insertStmtAfter(*func, *global);
set<string> for_vars;
vector<SgStatement*> dvm_dirs;
for (SgStatement* st = funcs[i]; st != last; )
{
if (st->variant() == FOR_NODE)
for_vars.insert(isSgForStmt(st)->doName()->identifier());
else if (st->variant() == CONTROL_END)
{
auto cp = st->controlParent();
if (cp->variant() == FOR_NODE)
for_vars.erase(isSgForStmt(cp)->doName()->identifier());
}
else if (st->variant() == DVM_PARALLEL_ON_DIR)
{
SgExpression* rule = st->expr(2);
findLoopSymbols(rule, for_vars);
}
for (int z = 0; z < 3; ++z)
findArrayRef(st->expr(z), for_vars);
if (isDVM_stat(st))
{
SgStatement* next = st->lexNext();
dvm_dirs.push_back(st->extractStmt());
st = next;
}
else if(st->variant() == ALLOCATE_STMT ||
st->variant() == DEALLOCATE_STMT)
{
SgStatement* next = st->lexNext();
st->extractStmt();
st = next;
}
else
st = st->lexNext();
if (st->variant() == DVM_PARALLEL_ON_DIR)
for_vars.clear();
}
string dvm_comm = "";
int dir_pos = 0;
int dir_line = dvm_dirs.size() ? dvm_dirs[dir_pos]->lineNumber() : -1;
for (SgStatement* st = funcs[i]; st != last; st = st->lexNext())
{
int curr_line = st->lineNumber();
while (dir_line < curr_line && dir_line != -1)
{
SgStatement* dir = dvm_dirs[dir_pos];
if (dir->variant() == DVM_PARALLEL_ON_DIR)
{
vector<SgStatement*> rems;
vector<string> addS;
SgStatement* tmp0 = new SgAssignStmt(*new SgVarRefExp(*new SgSymbol(VARIABLE_NAME, "tmp0")), *dir->expr(0));
SgStatement* tmp2 = new SgAssignStmt(*new SgVarRefExp(*new SgSymbol(VARIABLE_NAME, "tmp2")), *dir->expr(2));
SgExpression* list = dir->expr(1);
while (list)
{
SgExpression* item = list->lhs();
if (item->variant() != REMOTE_ACCESS_OP)
{
string s = item->unparse();
convertToLower(s);
addS.push_back(s);
}
else
rems.push_back(new SgAssignStmt(*new SgVarRefExp(*new SgSymbol(VARIABLE_NAME, "tmp1")), *item->lhs()));
list = list->rhs();
}
SgCExpStmt* conv0 = (SgCExpStmt*)Translate_Fortran_To_C(tmp0, true);
SgCExpStmt* conv2 = (SgCExpStmt*)Translate_Fortran_To_C(tmp2, true);
Set_Function_Language(C_LANG);
string array = conv0->expr()->rhs()->unparse();
string rule = conv2->expr()->rhs()->unparse();
for (auto& conv : rems)
{
SgCExpStmt* convE = (SgCExpStmt*)Translate_Fortran_To_C(conv, true);
string s = convE->expr()->rhs()->unparse();
convertToLower(s);
addS.push_back(string("remote_access(") + s + ")");
}
Unset_Function_Language();
char buf[1024];
sprintf(buf, "#pragma dvm parallel([%s] on %s) ", rule.c_str(), array.c_str());
string pragma = buf;
for (int z = 0; z < addS.size(); ++z)
{
pragma += addS[z];
if (z != addS.size() - 1)
pragma += ", ";
}
if (dvm_comm.size())
dvm_comm += "\n";
dvm_comm += pragma;
}
else if (dir->variant() == ACC_END_REGION_DIR)
{
if (dvm_comm.size())
dvm_comm += "\n";
dvm_comm += " }";
}
else if (dir->variant() == ACC_REGION_DIR)
{
if (dvm_comm.size())
dvm_comm += "\n";
string type = "";
if (dir->expr(0))
{
type = dir->expr(0)->unparse();
convertToLower(type);
}
dvm_comm += string("#pragma dvm region ") + type + "\n";
dvm_comm += " {";
}
else if (dir->variant() == ACC_GET_ACTUAL_DIR)
{
if (dvm_comm.size())
dvm_comm += "\n";
SgStatement* tmp0 = new SgAssignStmt(*new SgVarRefExp(*new SgSymbol(VARIABLE_NAME, "tmp0")), *dir->expr(0));
SgCExpStmt* conv0 = (SgCExpStmt*)Translate_Fortran_To_C(tmp0, true);
Set_Function_Language(C_LANG);
string array = conv0->expr()->rhs()->unparse();
Unset_Function_Language();
dvm_comm += "#pragma dvm get_actual(" + array + ")";
}
dir_pos++;
dir_line = (dir_pos < dvm_dirs.size()) ? dvm_dirs[dir_pos]->lineNumber() : -1;
}
if (isSgExecutableStatement(st))
{
SgStatement* conv = Translate_Fortran_To_C(st, true);
if (st->comments())
{
string str(st->comments());
vector<string> result;
splitString(str, '\n', result);
str = "";
for (int z = 0; z < result.size(); ++z)
{
str += "//" + result[z].substr(1, result[z].size());
if (z != result.size() - 1)
str += "\n";
}
conv->addComment(str.c_str());
}
if (dvm_comm.size())
{
conv->addComment(dvm_comm.c_str());
dvm_comm.clear();
}
lastOfFunc->insertStmtBefore(*conv, *func);
//printf("on line %d\n%s\n", st->lineNumber(), conv->unparse(C_LANG));
st = st->lastNodeOfStmt();
}
}
funcs[i]->extractStmt();
}
/*string includes;
includes += "#include <math.h>\n";
includes += "#include <stdlib.h>\n";
includes += "#include <stdio.h>\n";
global->addComment(includes.c_str());*/
FILE* file_out = fopen((OnlyName(file->filename()) + ".cdv").c_str(), "w");
fprintf(file_out, "%s\n", global->unparse(C_LANG));
fclose(file_out);
}

View File

@@ -0,0 +1,3 @@
#pragma once
void covertToC(SgFile* file);

View File

@@ -39,6 +39,15 @@ bool checkOutCalls(const set<string>& outCalls)
return false;
}
void createInterfacesForOutCalls(FuncInfo* func) {
if (func->isPure && !func->isMain)
{
bool hasOutCalls = checkOutCalls(func->callsFrom);
if (hasOutCalls)
DvmhRegionInserter::createInterfaceBlockForOutCalls(func);
}
}
static void setPureStatus(FuncInfo* func)
{
if (func->isPure && !func->isMain)
@@ -52,13 +61,10 @@ static void setPureStatus(FuncInfo* func)
for (int z = 0; z < func->funcParams.countOfPars; ++z)
hasOut |= func->funcParams.isArgOut(z);
bool hasPure = (header->expr(2) != NULL) || ((header->symbol()->attributes() & PURE_BIT) != 0);
bool hasOutCalls = checkOutCalls(func->callsFrom);
bool hasIO = func->linesOfIO.size() || func->linesOfStop.size();
//TODO: with hasOutCalls
if (!hasPure && !hasIO && !hasOutCalls && ((isFunc == false) || (isFunc && hasOut == false)))
{
DvmhRegionInserter::createInterfaceBlockForOutCalls(func);
if (!hasPure && !hasIO && ((isFunc == false) || (isFunc && hasOut == false)))
{
header->setExpression(2, new SgExpression(PURE_OP));
header->symbol()->setAttribute(header->symbol()->attributes() | PURE_BIT);
}
@@ -76,6 +82,10 @@ void setPureStatus(const map<string, vector<FuncInfo*>>& allFuncInfo)
for (auto& funcByFile : allFuncInfo)
for (auto& func : funcByFile.second)
setPureStatus(func);
for (auto& funcByFile : allFuncInfo)
for (auto& func : funcByFile.second)
createInterfacesForOutCalls(func);
}
map<SgStatement*, set<string>> fillFromIntent(SgStatement* header)
@@ -429,8 +439,9 @@ static void transferCommons(set<FuncInfo*>& allForChange, map <FuncInfo*, map<st
if (SgFile::switchToFile(curFunc->fileName) == -1)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
for (auto& call : curFunc->pointerDetailCallsFrom)
for (auto& callInfo : curFunc->callsFromDetailed)
{
auto& call = callInfo.pointerDetailCallsFrom;
if (isSgFuncHedrStmt(precFunc->funcPointer->GetOriginal()) && call.second == FUNC_CALL)
{
SgFunctionCallExp* callExp = (SgFunctionCallExp*)call.first;
@@ -792,8 +803,9 @@ static void transferSave(map<FuncInfo*, set<FuncInfo*>>& funcAddedVarsFuncs, vec
if (SgFile::switchToFile(curFunc->fileName) == -1)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
for (auto& call : curFunc->pointerDetailCallsFrom)
for (auto& callInfo : curFunc->callsFromDetailed)
{
auto& call = callInfo.pointerDetailCallsFrom;
if (isSgFuncHedrStmt(precFunc->funcPointer->GetOriginal()) && call.second == FUNC_CALL)
{
SgFunctionCallExp* callExp = (SgFunctionCallExp*)call.first;
@@ -1251,8 +1263,9 @@ static void transferModule(map<FuncInfo*, set<SgSymbol*>>& funcAddedVarsMods, se
}
}
for (auto& call : curFunc->pointerDetailCallsFrom)
for (auto& callInfo : curFunc->callsFromDetailed)
{
auto& call = callInfo.pointerDetailCallsFrom;
if (isSgFuncHedrStmt(precFunc->funcPointer->GetOriginal()) && call.second == FUNC_CALL)
{
SgFunctionCallExp* callExp = (SgFunctionCallExp*)call.first;

View File

@@ -4,6 +4,7 @@ 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 createInterfacesForOutCalls(FuncInfo* func);
void setPureStatus(const std::set<FuncInfo*>& funcInfo);
void setPureStatus(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo);

View File

@@ -5,14 +5,19 @@
#include "../CFGraph/CFGraph.h"
#include "../CFGraph/RD_subst.h"
// Regime defines the regime of private removing
enum class Regime { DEFLT = 1, REGULAR_INDEXES };
// PrivateToRemove represents private variable of loop, that can be removed
// by substitution of its definition statements (DEF) into usage statements (USE).
// fixedDimensions is used for comparison of DEF and USE statements
struct PrivateToRemove {
LoopGraph* loop;
SgSymbol* var;
std::vector<std::pair<SgAssignStmt*, SgAssignStmt*>> defUseStmtsPairs;
SgSymbol* varSymbol;
Regime regime;
std::vector<std::pair<SgAssignStmt*, SgStatement*>> defUseStmtsPairs;
std::vector<bool> fixedDimensions;
std::map<SgArrayRefExp*, std::vector<SgSymbol*>> arrayRefToIterationVarsMap;
};
// removePrivates removes all privates from vector privatesToRemoveGloval

View File

@@ -118,15 +118,16 @@ static map<FuncInfo*, callInfo> countOfCalls(const map<string, vector<FuncInfo*>
for (auto& elem : fromFile.second)
{
int p = 0;
for (auto& detailed : elem->detailCallsFrom)
for (auto& callInfo : elem->callsFromDetailed)
{
auto& detailed = callInfo.detailCallsFrom;
auto it = mapOfFunc.find(detailed.first);
if (it != mapOfFunc.end())
{
auto var = variantCall.find(it->second);
auto createPackCall = createParamCalls(elem->pointerDetailCallsFrom[p], elem->fileName);
auto createPackCall = createParamCalls(elem->callsFromDetailed[p].pointerDetailCallsFrom, elem->fileName);
if (checkUniqAndAdd(var->second, createPackCall, elem->pointerDetailCallsFrom[p], elem->parentForPointer[p]))
if (checkUniqAndAdd(var->second, createPackCall, elem->callsFromDetailed[p].pointerDetailCallsFrom, elem->callsFromDetailed[p].parentForPointer))
count[it->second]++;
}
++p;
@@ -554,9 +555,9 @@ static void copyGroup(const map<string, FuncInfo*> &mapOfFunc, const vector<Func
findInterfaceBlockAndDuplicate(func->funcPointer->GetOriginal(), origName, newName, varOfCall);
// fill additional places to next replaces
for (int z = 0; z < currFunc->pointerDetailCallsFrom.size(); ++z)
for (int z = 0; z < currFunc->callsFromDetailed.size(); ++z)
{
pair<void*, int> place = currFunc->pointerDetailCallsFrom[z];
pair<void*, int> place = currFunc->callsFromDetailed[z].pointerDetailCallsFrom;
if (place.second == PROC_STAT)
{
SgStatement* proc = (SgStatement*)place.first;
@@ -575,12 +576,12 @@ static void copyGroup(const map<string, FuncInfo*> &mapOfFunc, const vector<Func
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
vector<void*> tmp;
infoAdd->second.variantCall.push_back(callVars(make_pair(copyPoint, PROC_STAT), tmp, currFunc->parentForPointer[z]));
infoAdd->second.variantCall.push_back(callVars(make_pair(copyPoint, PROC_STAT), tmp, currFunc->callsFromDetailed[z].parentForPointer));
}
else if (place.second == FUNC_CALL)
{
SgExpression* proc = (SgExpression*)place.first;
SgStatement* parent = (SgStatement*)currFunc->parentForPointer[z];
SgStatement* parent = (SgStatement*)currFunc->callsFromDetailed[z].parentForPointer;
checkNull(parent, convertFileName(__FILE__).c_str(), __LINE__);
if (SgFile::switchToFile(parent->fileName()) == -1)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
@@ -597,7 +598,7 @@ static void copyGroup(const map<string, FuncInfo*> &mapOfFunc, const vector<Func
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
vector<void*> tmp;
infoAdd->second.variantCall.push_back(callVars(make_pair(copyPoint, FUNC_CALL), tmp, currFunc->parentForPointer[z]));
infoAdd->second.variantCall.push_back(callVars(make_pair(copyPoint, FUNC_CALL), tmp, currFunc->callsFromDetailed[z].parentForPointer));
}
else
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);

View File

@@ -232,7 +232,7 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
list({ GET_ALL_ARRAY_DECL, CALL_GRAPH2, CODE_CHECKER_PASSES, SUBST_EXPR_RD, ARRAY_ACCESS_ANALYSIS_FOR_CORNER }) <= list({ LOOP_ANALYZER_NODIST, LOOP_ANALYZER_DATA_DIST_S0, LOOP_ANALYZER_DATA_DIST_S1, ONLY_ARRAY_GRAPH });
Pass(LOOP_ANALYZER_NODIST) <= Pass(INSERT_PARALLEL_DIRS_NODIST);
list({ LOOP_ANALYZER_NODIST, REMOVE_OMP_DIRS }) <= Pass(INSERT_PARALLEL_DIRS_NODIST);
Pass(CHECK_ARGS_DECL) <= Pass(CREATE_TEMPLATE_LINKS);
@@ -262,7 +262,7 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
list({ PREPROC_SPF, CORRECT_VAR_DECL }) <= Pass(FILL_PAR_REGIONS_LINES);
Pass(LOOP_ANALYZER_COMP_DIST) <= list({ CREATE_DISTR_DIRS, CREATE_PARALLEL_DIRS, INSERT_PARALLEL_DIRS });
list({ LOOP_ANALYZER_COMP_DIST, REMOVE_OMP_DIRS }) <= list({ CREATE_DISTR_DIRS, CREATE_PARALLEL_DIRS, INSERT_PARALLEL_DIRS });
Pass(CALL_GRAPH2) <= list({ ONLY_ARRAY_GRAPH, CREATE_NESTED_LOOPS, FIND_FUNC_TO_INCLUDE, CHECK_FUNC_TO_INCLUDE, FIND_PARAMETERS });
@@ -300,8 +300,12 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
list({ BUILD_IR, LOOP_GRAPH, LIVE_ANALYSIS_IR }) <= Pass(PRIVATE_ANALYSIS_IR);
Pass(FILE_LINE_INFO) <= Pass(GET_MIN_MAX_BLOCK_DIST);
Pass(CALL_GRAPH2) <= Pass(FIX_COMMON_BLOCKS);
Pass(REMOVE_OMP_DIRS) <= Pass(REMOVE_OMP_DIRS_TRANSFORM);
Pass(CALL_GRAPH2) <= Pass(SET_IMPLICIT_NONE);
passesIgnoreStateDone.insert({ CREATE_PARALLEL_DIRS, INSERT_PARALLEL_DIRS, INSERT_SHADOW_DIRS, EXTRACT_PARALLEL_DIRS,
@@ -323,7 +327,7 @@ void removalsFromPassesDependencies(map<passes, vector<passes>>& passDepsIn, con
{
passDeps = &passDepsIn;
Pass(INSERT_PARALLEL_DIRS_NODIST) -= list({ FIND_FUNC_TO_INCLUDE, CHECK_FUNC_TO_INCLUDE });
list({ INSERT_PARALLEL_DIRS_NODIST, LOOP_ANALYZER_NODIST }) -= list({ FIND_FUNC_TO_INCLUDE, CHECK_FUNC_TO_INCLUDE });
Pass(passes(curr_regime)).applyRemovals();
}

View File

@@ -12,6 +12,7 @@
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <utility>
#include <string>
@@ -45,6 +46,7 @@
#include "../LoopAnalyzer/loop_analyzer.h"
using std::map;
using std::queue;
using std::multimap;
using std::pair;
using std::tuple;
@@ -402,7 +404,6 @@ string removeIncludeStatsAndUnparse(SgFile *file, const char *fileName, const ch
for (SgStatement *st = file->firstStatement(); st; st = st->lexNext())
{
removeOmpDir(st);
if (st->lineNumber() <= 0 || st->variant() < 0)
continue;
string currFileName = st->fileName();
@@ -1154,7 +1155,8 @@ bool isDVM_stat(SgStatement *st)
(var == DVM_DISTRIBUTE_DIR) ||
(var >= HPF_TEMPLATE_STAT && var <= DVM_REDISTRIBUTE_DIR) ||
(var >= BLOCK_OP && var <= STAGE_OP) ||
(var >= INDIRECT_OP && var <= SHADOW_NAMES_OP))
(var >= INDIRECT_OP && var <= SHADOW_NAMES_OP) ||
(var >= ACC_REGION_DIR && var <= ACC_ASYNC_OP))
ret = true;
return ret;
}
@@ -2611,7 +2613,7 @@ SgExpression* makeExprList(const vector<SgExpression*>& items, bool withSort)
int tmpVal = 0;
for (auto& elem : items)
{
if (elem->variant() == VAR_REF || elem->variant() == ARRAY_REF)
if (elem->variant() == VAR_REF || elem->variant() == ARRAY_REF || elem->variant() == CONST_REF)
sorted.insert(make_pair(elem->unparse(), elem));
else if (elem->lhs() && elem->lhs()->variant() == VAR_REF || elem->lhs()->variant() == ARRAY_REF)
sorted.insert(make_pair(elem->lhs()->unparse(), elem));
@@ -2916,8 +2918,9 @@ private:
{
#ifdef _MSC_VER
ret = pipe(pipes, 1024 * 1024 * 20, O_BINARY); // 20 MB
#else
#else
ret = pipe(pipes) == -1;
fcntl(*pipes, F_SETPIPE_SZ, 1024 * 1024 * 20);
#endif
fd_blocked = (errno == EINTR || errno == EBUSY);
if (fd_blocked)
@@ -3144,6 +3147,17 @@ static inline void restoreOriginalText(const FileInfo& file)
writeFileFromStr(file.fileName, file.text);
}
static void checkRetCode(FileInfo& info, const string& errorMessage)
{
if (info.error != 0)
info.lvl++;
if (errorMessage.find("Warning 308") != string::npos)
if (info.error == 0)
info.error = 1;
}
extern "C" int parse_file(int argc, char* argv[], char* proj_name);
static vector<string> parseList(vector<FileInfo>& listOfProject,
bool needToInclude, bool needToIncludeForInline,
@@ -3221,8 +3235,8 @@ static vector<string> parseList(vector<FileInfo>& listOfProject,
StdCapture::BeginCapture();
if (needToInclude)
filesModified = applyModuleDeclsForFile(&elem, mapFiles, moduleDelc, mapModuleDeps, modDirectOrder, optSplited, needToIncludeForInline);
else if (needToIncludeForInline) //TODO for modules
filesModified = applyModuleDeclsForFile(&elem, mapFiles, moduleDelc, mapModuleDeps, modDirectOrder, optSplited, true);
else if (needToIncludeForInline) // TODO for modules
filesModified = applyModuleDeclsForFile(&elem, mapFiles, moduleDelc, mapModuleDeps, modDirectOrder, optSplited, needToIncludeForInline);
int retCode = parse_file(optSplited.size(), toParse, "dvm.proj");
if (needToInclude || needToIncludeForInline)
@@ -3235,13 +3249,7 @@ static vector<string> parseList(vector<FileInfo>& listOfProject,
elem.error = retCode;
StdCapture::EndCapture();
errorMessage = StdCapture::GetCapture();
if (elem.error != 0)
elem.lvl++;
if (errorMessage.find("Warning 308") != string::npos)
if (elem.error == 0)
elem.error = 1;
checkRetCode(elem, errorMessage);
}
catch (int err)
{
@@ -4003,6 +4011,7 @@ SgProject* createProject(const char* proj_name,
for (int z = 0; z < project->numberOfFiles(); ++z)
{
SgFile* file = &(project->file(z));
//file->unparsestdout();
const string fileN = file->filename();
auto first = file->firstStatement();
@@ -4218,7 +4227,7 @@ SgProject* createProject(const char* proj_name,
for (int z = 0; z < project->numberOfFiles(); ++z)
removeExecutableFromModuleDeclaration(&(project->file(z)), filesInProj);
removeExecutableFromModuleDeclaration(&(project->file(z)), filesInProj, hiddenData[project->file(z).filename()]);
for (int z = 0; z < project->numberOfFiles(); ++z)
{
@@ -4383,8 +4392,56 @@ void removeSpecialCommentsFromProject(SgFile* file)
genVersionDone.erase(file);
}
}
if (stF->lineNumber() > 0)
break;
stF = stF->lexNext();
}
}
void getMaxMinBlockDistribution(SgFile* file, pair<int, int>& min_max)
{
SgStatement* st = file->firstStatement();
while (st)
{
if (isDVM_stat(st))
{
if (st->variant() == DVM_DISTRIBUTE_DIR || st->variant() == DVM_VAR_DECL)
{
for (int z = 0; z < 3; ++z)
{
SgExpression* ex = st->expr(z);
queue<SgExpression*> q;
if (ex)
{
q.push(ex);
int blockCount = 0;
while (q.size())
{
ex = q.front();
q.pop();
if (ex->rhs())
q.push(ex->rhs());
if (ex->lhs())
q.push(ex->lhs());
if (ex->variant() == BLOCK_OP)
blockCount++;
}
if (blockCount)
{
if (min_max == make_pair(-1, -1))
min_max = make_pair(blockCount, blockCount);
else
{
min_max.first = std::min(min_max.first, blockCount);
min_max.second = std::max(min_max.second, blockCount);
}
}
}
}
}
}
st = st->lexNext();
}
}

View File

@@ -107,4 +107,6 @@ bool isEqSymbols(SgSymbol* sym1, SgSymbol* sym2);
std::set<std::string> getAllFilesInProject();
void LogIftoIfThen(SgStatement* stmt);
void removeSpecialCommentsFromProject(SgFile* file);
void removeSpecialCommentsFromProject(SgFile* file);
void getMaxMinBlockDistribution(SgFile* file, std::pair<int, int>& min_max);

View File

@@ -101,6 +101,7 @@ enum typeMessage { WARR, ERROR, NOTE };
// 22 "cannot transform ..."
// 23 "cannot transform ..."
// 24 "loop on line %d was removed"
// 25 "Cannot remove private var '%s' - it is used in the call of function '%s'"
// 30xx PARALLEL GROUP
// 01 "add across dependencies by array '%s' to loop"
@@ -125,6 +126,7 @@ enum typeMessage { WARR, ERROR, NOTE };
// 20 "detected distributed and non distributed array links by function's calls for array %s\n"
// 21 "empty parallel regions is forbidden"
// 22 "Can not find align rules"
// 23 "Array reference '%s' has a different size from the original array"
// 40xx LOW LEVEL WARNINGS
// 01
@@ -273,7 +275,7 @@ static void printStackTrace() { };
} \
} while (0)
// Свободный - R202
// Свободный - R204
// Гайд по русификации сообщений: При добавлении нового сообщения, меняется последний сводобный идентификатор.
// В этом файле остаются только спецификаторы, для которых будет заполнен текст. Полный текст пишется в файле
// russian_errors_text.txt. Спецификаторы там тоже сохраняются, по ним в визуализаторе будет восстановлен
@@ -282,14 +284,14 @@ static void printStackTrace() { };
//russian messages
//1001
static const wchar_t *R1 = L"R1:%ls#%ls#%ls";
static const wchar_t* RR1_1 = L"RR1_1:";
static const wchar_t* RR1_2 = L"RR1_2:";
static const wchar_t* RR1_3 = L"RR1_3:";
static const wchar_t* RR1_4 = L"RR1_4:";
static const wchar_t* RR1_5 = L"RR1_5:";
static const wchar_t* RR1_6 = L"RR1_6:";
static const wchar_t* RR1_7 = L"RR1_7:";
static const wchar_t* RR1_8 = L"RR1_8:";
static const wchar_t *RR1_1 = L"RR1_1:";
static const wchar_t *RR1_2 = L"RR1_2:";
static const wchar_t *RR1_3 = L"RR1_3:";
static const wchar_t *RR1_4 = L"RR1_4:";
static const wchar_t *RR1_5 = L"RR1_5:";
static const wchar_t *RR1_6 = L"RR1_6:";
static const wchar_t *RR1_7 = L"RR1_7:";
static const wchar_t *RR1_8 = L"RR1_8:";
static const wchar_t *R2 = L"R2:";
static const wchar_t *R3 = L"R3:";
@@ -338,7 +340,7 @@ static const wchar_t *R35 = L"R35:";
static const wchar_t *R36 = L"R36:%s";
//1012
static const wchar_t *R37 = L"R37:%s";
static const wchar_t* R149 = L"R149:%s";
static const wchar_t *R149 = L"R149:%s";
//1013
static const wchar_t *R38 = L"R38:%s";
static const wchar_t *R39 = L"R39:%s#%s#%s#%s#%d#%s";
@@ -346,8 +348,8 @@ static const wchar_t *R40 = L"R40:%s";
static const wchar_t *R41 = L"R41:%s#%s#%d#%s";
static const wchar_t *R42 = L"R42:%s#%s#%ls";
static const wchar_t* RR42_1 = L"RR42_1:";
static const wchar_t* RR42_2 = L"RR42_2:";
static const wchar_t *RR42_1 = L"RR42_1:";
static const wchar_t *RR42_2 = L"RR42_2:";
static const wchar_t *R43 = L"R43:%s#%s#%d#%d";
static const wchar_t *R44 = L"R44:%s#%s";
@@ -382,17 +384,17 @@ static const wchar_t *R59 = L"R59:%s";
static const wchar_t *R60 = L"R60:%s";
static const wchar_t *R61 = L"R61:%s";
//1027
static const wchar_t* R179 = L"R179:";
static const wchar_t *R179 = L"R179:";
//1028
static const wchar_t *R62 = L"R62:%s";
//1029 && 1030
static const wchar_t* R158 = L"R158:%s";
static const wchar_t* R159 = L"R159:%s";
static const wchar_t* R160 = L"R160:%s";
static const wchar_t* R161 = L"R161:%s";
static const wchar_t* R162 = L"R162:%s";
static const wchar_t* R163 = L"R163:%s";
static const wchar_t* RR158_1 = L"RR158_1:";
static const wchar_t *R158 = L"R158:%s";
static const wchar_t *R159 = L"R159:%s";
static const wchar_t *R160 = L"R160:%s";
static const wchar_t *R161 = L"R161:%s";
static const wchar_t *R162 = L"R162:%s";
static const wchar_t *R163 = L"R163:%s";
static const wchar_t *RR158_1 = L"RR158_1:";
//1031
static const wchar_t *R63 = L"R63:%s#%d";
//1032
@@ -463,13 +465,13 @@ static const wchar_t *R157 = L"R157:%s#%s";
//1057
static const wchar_t *R175 = L"R175:%s";
//1058
static const wchar_t* R176 = L"R176:";
static const wchar_t *R176 = L"R176:";
//1059
static const wchar_t* R182 = L"R176:%s";
static const wchar_t *R182 = L"R176:%s";
//1060
static const wchar_t* R183 = L"R183:";
static const wchar_t *R183 = L"R183:";
//1061
static const wchar_t* R184 = L"R184:%s";
static const wchar_t *R184 = L"R184:%s";
//2001
static const wchar_t *R94 = L"R94:";
@@ -499,42 +501,44 @@ static const wchar_t *R107 = L"R107:";
//2011
static const wchar_t *R177 = L"R177:";
//2012
static const wchar_t* R173 = L"R173:";
static const wchar_t *R173 = L"R173:";
//2013
static const wchar_t* R174 = L"R174:%s";
static const wchar_t *R174 = L"R174:%s";
//2014
static const wchar_t* R180 = L"R180:%s#%s";
static const wchar_t *R180 = L"R180:%s#%s";
//2015
static const wchar_t* R185 = L"R185:";
static const wchar_t* R186 = L"R186:";
static const wchar_t* R187 = L"R187:";
static const wchar_t* R195 = L"R195:";
static const wchar_t *R185 = L"R185:";
static const wchar_t *R186 = L"R186:";
static const wchar_t *R187 = L"R187:";
static const wchar_t *R195 = L"R195:";
//2016
static const wchar_t* R188 = L"R188:%s";
static const wchar_t *R188 = L"R188:%s";
//2017
static const wchar_t* R189 = L"R189:%s";
static const wchar_t* R190 = L"R190:%s#%s";
static const wchar_t *R189 = L"R189:%s";
static const wchar_t *R190 = L"R190:%s#%s";
//2018
static const wchar_t* R191 = L"R191:%s";
static const wchar_t* R201 = L"R201:%s";
static const wchar_t *R191 = L"R191:%s";
static const wchar_t *R201 = L"R201:%s";
//2019
static const wchar_t* R192 = L"R192:%s";
static const wchar_t *R192 = L"R192:%s";
//2020
static const wchar_t* R193 = L"R193:%s";
static const wchar_t *R193 = L"R193:%s";
//2021
static const wchar_t* R194 = L"R194:%s";
static const wchar_t *R194 = L"R194:%s";
//2022
static const wchar_t* R196 = L"R196:";
static const wchar_t *R196 = L"R196:";
//2023
static const wchar_t* R197 = L"R197:";
static const wchar_t *R197 = L"R197:";
//2024
static const wchar_t* R198 = L"R198:%d";
static const wchar_t *R198 = L"R198:%d";
//2025
static const wchar_t *R203 = L"R203:%s#%s";
//3001
static const wchar_t *R108 = L"R108:%s";
//3002
static const wchar_t *R109 = L"R109:%s#%d";
static const wchar_t* R200 = L"R200:%s#%d";
static const wchar_t *R200 = L"R200:%s#%d";
//3003
static const wchar_t *R110 = L"R110:%s#%s#%d";
//3004
@@ -554,11 +558,11 @@ static const wchar_t *R121 = L"R121:";
static const wchar_t *R122 = L"R122:";
static const wchar_t *R123 = L"R123:";
static const wchar_t *R124 = L"R124:%s#%s#%d#%s#%d#%d";
static const wchar_t* R125 = L"R124:%s#%s#%d#%s#%d";
static const wchar_t *R125 = L"R124:%s#%s#%d#%s#%d";
static const wchar_t *R144 = L"R144:";
static const wchar_t *R145 = L"R145:";
static const wchar_t* R178 = L"R178:";
static const wchar_t* R199 = L"R199:";
static const wchar_t *R178 = L"R178:";
static const wchar_t *R199 = L"R199:";
//3007
static const wchar_t *R126 = L"R126:%s#%d#%d";
static const wchar_t *R127 = L"R127:";
@@ -591,12 +595,14 @@ static const wchar_t *R139 = L"R139:%s#%s";
//3020
static const wchar_t *R140 = L"R140:%s";
static const wchar_t *R141 = L"R141:%s";
static const wchar_t* R153 = L"R153:%s";
static const wchar_t *R153 = L"R153:%s";
static const wchar_t *R142 = L"R142:%s";
//3021
static const wchar_t* R151 = L"R151:";
static const wchar_t *R151 = L"R151:";
//3022
static const wchar_t* R171 = L"R171:%s";
static const wchar_t *R171 = L"R171:%s";
//3023
static const wchar_t *R202 = L"R202:%s";
//4001
//---TODO ошибки из SAGE

View File

@@ -242,6 +242,8 @@ R196 = "Невозможно выполнить преобразование ц
R197 = "Преобразование не может быть выполнено - не произошло никаких изменений в коде"
//2024
R198 = "Цикл на строке %d был удалён"
//2025
R203 = "Нельзя удалить приватную переменную '%s' - она используется в вызове функции %s"
//3001
R108 = "Добавлена across-зависимость к массиву '%s' в цикле"
@@ -310,6 +312,8 @@ R142 = "Для массива '%s' не удается найти единого
R151 = "Пустые области распараллеливания недопускаются."
//3022
R171 = "Невозможно определить правила выравнивания для массива '%s'."
//3023
R202 = "Ссылка '%s' имеет отличный от оригинального массива размер"
//4001
//---TODO ошибки из SAGE

View File

@@ -1372,7 +1372,7 @@ set<ParallelRegion*> getAllRegionsByLine(const vector<ParallelRegion*>& regions,
return regFound;
}
pair<vector<string>, vector<string>> splitCommandLineForParse(char** argv, int argc)
pair<vector<string>, vector<string>> splitCommandLineForParse(char** argv, int argc, bool& isInline)
{
#if __cplusplus >= 201703L
vector<fs::path> filesInDir;
@@ -1410,7 +1410,12 @@ pair<vector<string>, vector<string>> splitCommandLineForParse(char** argv, int a
}
}
else
options.push_back(isFile);
{
if (isFile == "-inl")
isInline = true;
else
options.push_back(isFile);
}
}
vector<string> filesV;

View File

@@ -82,7 +82,7 @@ std::map<DIST::Array*, DIST::ArrayAccessInfo*> createMapOfArrayAccess(const std:
std::string readFileToStr(const std::string& name);
void writeFileFromStr(const std::string& name, const std::string& data);
std::pair<std::vector<std::string>, std::vector<std::string>> splitCommandLineForParse(char** argv, int argc);
std::pair<std::vector<std::string>, std::vector<std::string>> splitCommandLineForParse(char** argv, int argc, bool& isInline);
std::string getClearName(const std::string& in);
std::wstring fixedLongFormat(const wchar_t* old);

View File

@@ -1,3 +1,3 @@
#pragma once
#define VERSION_SPF "2222"
#define VERSION_SPF "2255"

View File

@@ -1153,7 +1153,7 @@ void replaceStructuresToSimpleTypes(SgFile *file)
}
}
void removeExecutableFromModuleDeclaration(SgFile *current, const set<string> &filesInProj)
void removeExecutableFromModuleDeclaration(SgFile *current, const set<string> &filesInProj, vector<SgStatement*>& hiddenData)
{
const string currF = current->filename();
set<string> moduleInFile;
@@ -1164,14 +1164,14 @@ void removeExecutableFromModuleDeclaration(SgFile *current, const set<string> &f
moduleInFile.insert(st->fileName());
}
vector<SgStatement*> toDel;
vector<SgStatement*> toMove;
for (SgStatement* st = current->firstStatement(); st; st = st->lexNext())
{
if (isSgProgHedrStmt(st))
if (moduleInFile.find(st->fileName()) != moduleInFile.end())
toDel.push_back(st);
toMove.push_back(st);
}
for (auto& elem : toDel)
elem->deleteStmt();
for (auto& elem : toMove)
hiddenData.push_back(elem->extractStmt());
}

View File

@@ -49,7 +49,7 @@ void replaceDerivedAssigns(SgFile *file, SgStatement *stToCopy, SgStatement *ins
bool isDerivedAssign(SgStatement *st);
std::map<std::string, SgStatement*> createDerivedTypeDeclMap(SgStatement *forS);
void fillUseStatement(SgStatement* st, std::set<std::string>& useMod, std::map<std::string, std::vector<std::pair<SgSymbol*, SgSymbol*>>>& modByUse, std::map<std::string, std::vector<std::pair<SgSymbol*, SgSymbol*>>>& modByUseOnly);
void removeExecutableFromModuleDeclaration(SgFile* current, const std::set<std::string>& filesInProj);
void removeExecutableFromModuleDeclaration(SgFile* current, const std::set<std::string>& filesInProj, std::vector<SgStatement*>& hiddenData);
bool needToReplaceInterfaceName(SgStatement* interf);
std::string getOrigName(const std::string& file, const std::string& s);

View File

@@ -64,8 +64,11 @@ buildLocationOfGraph(const map<string, vector<FuncInfo*>>& allFuncInfo, const in
for (auto& elem : mapOfFuncs)
{
set<string> callsFrom;
for (auto& callFrom_ : elem.second->detailCallsFrom)
for (auto& callFromInfo : elem.second->callsFromDetailed)
{
auto& callFrom_ = callFromInfo.detailCallsFrom;
callsFrom.insert(callFrom_.first);
}
callsFrom.insert(elem.second->externalCalls.begin(), elem.second->externalCalls.end());
for (auto& call : callsFrom)
@@ -90,8 +93,11 @@ buildLocationOfGraph(const map<string, vector<FuncInfo*>>& allFuncInfo, const in
continue;
set<string> callsFrom;
for (auto& callFrom_ : elem.second->detailCallsFrom)
for (auto& callFromInfo : elem.second->callsFromDetailed)
{
auto& callFrom_ = callFromInfo.detailCallsFrom;
callsFrom.insert(callFrom_.first);
}
callsFrom.insert(elem.second->externalCalls.begin(), elem.second->externalCalls.end());
for (auto& call : callsFrom)

View File

@@ -1262,6 +1262,7 @@ int SPF_GetArrayLinks(void*& context, int winHandler, short *options, short *pro
return retSize;
}
extern std::pair<int, int> min_max_block;
int SPF_GetMaxMinBlockDistribution(void*& context, int winHandler, short *options, short *projName, short *&result, short *&output, int *&outputSize,
short *&outputMessage, int *&outputMessageSize)
{
@@ -1273,64 +1274,10 @@ int SPF_GetMaxMinBlockDistribution(void*& context, int winHandler, short *option
int retSize = -1;
try
{
runPassesForVisualizer(projName, { FILE_LINE_INFO });
runPassesForVisualizer(projName, { GET_MIN_MAX_BLOCK_DIST });
string resVal = "";
int minBlock = 10;
int maxBlock = 0;
for (int z = 0; z < CurrentProject->numberOfFiles(); ++z)
{
SgFile* file = &(CurrentProject->file(z));
SgStatement* st = file->firstStatement();
while (st)
{
if (isDVM_stat(st))
{
if (st->variant() == DVM_DISTRIBUTE_DIR || st->variant() == DVM_VAR_DECL)
{
for (int z = 0; z < 3; ++z)
{
SgExpression* ex = st->expr(z);
queue<SgExpression*> q;
if (ex)
{
q.push(ex);
int blockCount = 0;
while (q.size())
{
ex = q.front();
q.pop();
if (ex->rhs())
q.push(ex->rhs());
if (ex->lhs())
q.push(ex->lhs());
if (ex->variant() == BLOCK_OP)
blockCount++;
}
if (blockCount)
{
minBlock = std::min(minBlock, blockCount);
maxBlock = std::max(maxBlock, blockCount);
}
}
}
}
}
st = st->lexNext();
}
}
if (minBlock == 10 && maxBlock == 0)
minBlock = maxBlock = 0;
resVal = to_string(minBlock) + " " + to_string(maxBlock);
string resVal = "";
resVal = to_string(min_max_block.first) + " " + to_string(min_max_block.second);
copyStringToShort(result, resVal);
retSize = (int)resVal.size() + 1;
@@ -1831,6 +1778,14 @@ int SPF_CreateIntervalsTree(void*& context, int winHandler, short *options, shor
return simpleTransformPass(INSERT_INTER_TREE, options, projName, folderName, output, outputSize, outputMessage, outputMessageSize);
}
int SPF_RemoveOmpDirectives(void*& context, int winHandler, short* options, short* projName, short* folderName, short*& output,
int*& outputSize, short*& outputMessage, int*& outputMessageSize)
{
MessageManager::clearCache();
MessageManager::setWinHandler(winHandler);
return simpleTransformPass(REMOVE_OMP_DIRS_TRANSFORM, options, projName, folderName, output, outputSize, outputMessage, outputMessageSize);
}
int SPF_RemoveDvmDirectives(void*& context, int winHandler, short *options, short *projName, short *folderName, short *&output,
int *&outputSize, short *&outputMessage, int *&outputMessageSize)
{
@@ -1847,6 +1802,14 @@ int SPF_RemoveDvmDirectivesToComments(void*& context, int winHandler, short *opt
return simpleTransformPass(REMOVE_DVM_DIRS_TO_COMMENTS, options, projName, folderName, output, outputSize, outputMessage, outputMessageSize);
}
int SPF_RemoveComments(void*& context, int winHandler, short* options, short* projName, short* folderName, short*& output,
int*& outputSize, short*& outputMessage, int*& outputMessageSize)
{
MessageManager::clearCache();
MessageManager::setWinHandler(winHandler);
return simpleTransformPass(REMOVE_COMMENTS, options, projName, folderName, output, outputSize, outputMessage, outputMessageSize);
}
int SPF_RemoveDvmIntervals(void*& context, int winHandler, short *options, short *projName, short *folderName, short *&output,
int *&outputSize, short *&outputMessage, int *&outputMessageSize)
{
@@ -1971,7 +1934,6 @@ static int inline runModificationPass(passes passName, short* projName, short* f
}
extern tuple<string, int, int, int> inData;
extern map<string, string> outData;
int SPF_ChangeSpfIntervals(void*& context, int winHandler, short *options, short *projName, short *folderName, short *&output,
int *&outputSize, short *&outputMessage, int *&outputMessageSize,
short *fileNameToMod, int *toModifyLines,
@@ -2125,7 +2087,7 @@ int SPF_InlineProcedures(void*& context, int winHandler, short* options, short*
if (result.size() < 2)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
for (int z = 0; z < result.size();)
for (int z = 0; z < result.size(); )
{
string procName = result[z++];
int count = -1;
@@ -2568,10 +2530,14 @@ const wstring Sapfor_RunTransformation(const char* transformName_c, const char*
if (whichRun == "SPF_CorrectCodeStylePass")
retCode = SPF_CorrectCodeStylePass(context, winHandler, optSh, projSh, fold, output, outputSize, outputMessage, outputMessageSize);
else if (whichRun == "SPF_RemoveOmpDirectives")
retCode = SPF_RemoveOmpDirectives(context, winHandler, optSh, projSh, fold, output, outputSize, outputMessage, outputMessageSize);
else if (whichRun == "SPF_RemoveDvmDirectives")
retCode = SPF_RemoveDvmDirectives(context, winHandler, optSh, projSh, fold, output, outputSize, outputMessage, outputMessageSize);
else if (whichRun == "SPF_RemoveDvmDirectivesToComments")
retCode = SPF_RemoveDvmDirectivesToComments(context, winHandler, optSh, projSh, fold, output, outputSize, outputMessage, outputMessageSize);
else if (whichRun == "SPF_RemoveComments")
retCode = SPF_RemoveComments(context, winHandler, optSh, projSh, fold, output, outputSize, outputMessage, outputMessageSize);
else if (whichRun == "SPF_InsertIncludesPass")
retCode = SPF_InsertIncludesPass(context, winHandler, optSh, projSh, fold, (char*)addOpt_c, output, outputSize, outputMessage, outputMessageSize);
else if (whichRun == "SPF_ResolveParallelRegionConflicts")