fixed inliner
This commit is contained in:
@@ -101,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__);
|
||||
}
|
||||
}
|
||||
@@ -109,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())
|
||||
@@ -1062,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)
|
||||
@@ -1297,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)
|
||||
@@ -1307,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);
|
||||
}
|
||||
|
||||
@@ -1419,7 +1428,6 @@ static bool run_inliner(const map<string, FuncInfo*>& funcMap, set<SgStatement*>
|
||||
}
|
||||
|
||||
set<SgSymbol*> newSymbols;
|
||||
|
||||
bool foundCall = false;
|
||||
|
||||
if (!callSt || !isSgExecutableStatement(callSt))
|
||||
@@ -1433,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());
|
||||
@@ -1448,10 +1455,9 @@ static bool run_inliner(const map<string, FuncInfo*>& funcMap, set<SgStatement*>
|
||||
for (int i = 0; i < 3; ++i)
|
||||
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())
|
||||
@@ -1480,7 +1486,7 @@ static bool run_inliner(const map<string, FuncInfo*>& funcMap, set<SgStatement*>
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -1638,7 +1644,7 @@ static bool inliner(const string& fileName_in, const string& funcName, const int
|
||||
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);
|
||||
|
||||
@@ -2355,6 +2361,7 @@ static void createDeclarations(const map<SgStatement*, set<SgSymbol*>>& newSymbs
|
||||
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)
|
||||
@@ -2364,7 +2371,7 @@ static void convertLinesToAbsolute(const map<string, vector<FuncInfo*>>& allFunc
|
||||
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)
|
||||
@@ -2373,12 +2380,14 @@ static void convertLinesToAbsolute(const map<string, vector<FuncInfo*>>& allFunc
|
||||
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);
|
||||
//__spf_print(1, "%s target %d + %d = %d\n", func->funcName.c_str(), func->linesNum.first, shilftLine, targetLine);
|
||||
for (auto& detCall : func->callsFromDetailed)
|
||||
{
|
||||
__spf_print(1, "%s %d\n", detCall.detailCallsFrom.first.c_str(), detCall.detailCallsFrom.second);
|
||||
if (detCall.detailCallsFrom == make_pair(funcToInl, targetLine))
|
||||
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;
|
||||
}
|
||||
@@ -2386,6 +2395,8 @@ static void convertLinesToAbsolute(const map<string, vector<FuncInfo*>>& allFunc
|
||||
if (absoluteLine)
|
||||
break;
|
||||
}
|
||||
if (absoluteLine)
|
||||
break;
|
||||
}
|
||||
|
||||
if (absoluteLine == 0)
|
||||
@@ -2417,6 +2428,7 @@ void callInliner(const map<string, vector<FuncInfo*>>& allFuncInfo,
|
||||
|
||||
if (inDataProc.size())
|
||||
{
|
||||
__spf_print(1, "count of inline data %ld\n", inDataProc.size());
|
||||
convertLinesToAbsolute(allFuncInfo, inDataProc);
|
||||
|
||||
map<int, vector<int>> sortByLvl;
|
||||
|
||||
@@ -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(".");
|
||||
|
||||
|
||||
@@ -1625,7 +1625,7 @@ int resolveParRegions(vector<ParallelRegion*> ®ions, 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())
|
||||
@@ -1661,7 +1661,7 @@ int resolveParRegions(vector<ParallelRegion*> ®ions, 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())
|
||||
@@ -1793,7 +1793,7 @@ int resolveParRegions(vector<ParallelRegion*> ®ions, const map<string, vector
|
||||
}
|
||||
}
|
||||
|
||||
__spf_print(1, "create functions\n"); // DEBUG
|
||||
__spf_print(1, "create functions\n");
|
||||
|
||||
// creating new functions
|
||||
for (auto &fileFuncs : allFuncInfo)
|
||||
@@ -1907,7 +1907,7 @@ int resolveParRegions(vector<ParallelRegion*> ®ions, 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)
|
||||
|
||||
@@ -1150,6 +1150,12 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
||||
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 == TEST_PASS)
|
||||
@@ -2469,6 +2475,7 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam
|
||||
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:
|
||||
@@ -2705,7 +2712,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");
|
||||
@@ -2727,7 +2735,7 @@ int main(int argc, char **argv)
|
||||
listOfProject.push_back(FileInfo(file, toAddOpt + "-o " + file + ".dep", "", "", "", fileText, 0));
|
||||
}
|
||||
|
||||
int rethrow = parseFiles(errors, listOfProject, filesCompilationOrder, 1, true);
|
||||
int rethrow = parseFiles(errors, listOfProject, filesCompilationOrder, isInline, true);
|
||||
if (rethrow == 0)
|
||||
{
|
||||
for (auto& err : errors)
|
||||
|
||||
@@ -169,6 +169,7 @@ enum passes {
|
||||
FIX_COMMON_BLOCKS,
|
||||
REMOVE_OMP_DIRS,
|
||||
REMOVE_OMP_DIRS_TRANSFORM,
|
||||
REMOVE_COMMENTS,
|
||||
GET_MIN_MAX_BLOCK_DIST,
|
||||
|
||||
TEST_PASS,
|
||||
@@ -344,6 +345,7 @@ static void setPassValues()
|
||||
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[TEST_PASS] = "TEST_PASS";
|
||||
|
||||
@@ -4010,6 +4010,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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define VERSION_SPF "2247"
|
||||
#define VERSION_SPF "2250"
|
||||
|
||||
@@ -1802,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)
|
||||
{
|
||||
@@ -2528,6 +2536,8 @@ const wstring Sapfor_RunTransformation(const char* transformName_c, const char*
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user