diff --git a/dvm/fdvm/trunk/fdvm/acc.cpp b/dvm/fdvm/trunk/fdvm/acc.cpp index eb4fee7..93b35a7 100644 --- a/dvm/fdvm/trunk/fdvm/acc.cpp +++ b/dvm/fdvm/trunk/fdvm/acc.cpp @@ -3912,7 +3912,7 @@ void RefInExpr(SgExpression *e, int mode) if (inparloop && isReductionVar(e->symbol())) return; - if ((use = isInUsesList(e->symbol())) != 0) + if ((use = isInUsesListByChar(e->symbol()->identifier())) != 0) { //!printf("RefInExpr 2 (is in list) %d\n",VAR_INTENT(use)); //uses_list ->unparsestdout(); printf("\n"); *VAR_INTENT(use) = WhatMode(*VAR_INTENT(use), mode); diff --git a/dvm/tools/pppa/trunk/src/makefile.uni b/dvm/tools/pppa/trunk/src/makefile.uni index 4a5cdf9..7cc72b3 100644 --- a/dvm/tools/pppa/trunk/src/makefile.uni +++ b/dvm/tools/pppa/trunk/src/makefile.uni @@ -1,7 +1,7 @@ BINDIR=../../../bin EXECUTABLES = dvmstf -COPT=-c -I../../Zlib/include +COPT=-c -I../../Zlib/include -std=c++11 ZLIB = zlib ZLIBDIR = ../../Zlib/Release diff --git a/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp b/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp index 23b5aa6..a7fc2b1 100644 --- a/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp +++ b/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp @@ -1022,7 +1022,7 @@ static void insertInterface(SgStatement* func, const string& iface, const string SgStatement* ifaceBlock = new SgStatement(INTERFACE_STMT); addControlEndToStmt(ifaceBlock->thebif); - ifaceBlock->setlineNumber(st->lineNumber()); + ifaceBlock->setlineNumber(getNextNegativeLineNumber()); // st->lineNumber() ifaceBlock->setFileName(st->fileName()); st->insertStmtBefore(*ifaceBlock, *st->controlParent()); ifaceBlock->lastNodeOfStmt()->addComment(iface.c_str()); @@ -1075,6 +1075,11 @@ static bool isPure(SgStatement* func) return retVal; } +void DvmhRegionInserter::createInterfaceBlockForOutCall(FuncInfo* func, FuncInfo* callFrom) +{ + insertInterface(func->funcPointer, getInterfaceBlock(callFrom->funcPointer->GetOriginal(), callFrom->funcParams), callFrom->funcName); +} + void DvmhRegionInserter::createInterfaceBlockForParallelFunctions() { for (auto& parF : parallel_functions) @@ -1088,7 +1093,7 @@ void DvmhRegionInserter::createInterfaceBlockForParallelFunctions() if (it == callTo->interfaceBlocks.end()) { callTo->interfaceBlocks[parF->funcName] = NULL; - insertInterface(callTo->funcPointer, getInterfaceBlock(parF->funcPointer->GetOriginal(), parF->funcParams), parF->funcName); + createInterfaceBlockForOutCall(callTo, parF); } else if (it->second) // interface not inserted as comment { @@ -1140,7 +1145,7 @@ void DvmhRegionInserter::createInterfaceBlockForOutCalls(FuncInfo* func) && isPure(callFrom->funcPointer->GetOriginal())) { func->interfaceBlocks[callFrom->funcName] = callFrom; - insertInterface(func->funcPointer, getInterfaceBlock(callFrom->funcPointer->GetOriginal(), callFrom->funcParams), callFrom->funcName); + createInterfaceBlockForOutCall(func, callFrom); } } } diff --git a/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.h b/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.h index 2b5c469..ecf8391 100644 --- a/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.h +++ b/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.h @@ -97,7 +97,8 @@ public: const std::set& getParallelFunctions() const { return parallel_functions; } - static void createInterfaceBlockForOutCalls(FuncInfo* func); + static void createInterfaceBlockForOutCall(FuncInfo* func, FuncInfo* callFrom); + static void createInterfaceBlockForOutCalls(FuncInfo* func); ~DvmhRegionInserter() { diff --git a/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls.h b/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls.h index 07e933f..c2989e7 100644 --- a/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls.h +++ b/sapfor/experts/Sapfor_2017/_src/GraphCall/graph_calls.h @@ -119,14 +119,6 @@ struct FuncInfo std::set callsFromV; std::vector callsFromDetailed; - //TODO: create new object for grouping this info - // grouped info of calls from - /*std::vector> detailCallsFrom; // - std::vector> pointerDetailCallsFrom; // SgStatement for PROC_STAT, SgExpression for FUNC_CALL, VAR_REF for external calls - std::vector parentForPointer; // parent SgStatement* of FUNC_CALL - std::vector actualParams;*/ - // end/ - std::map> commonBlocks; std::vector callsTo; //calls of this function diff --git a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp index 0b251a2..5ba51d1 100644 --- a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp @@ -503,6 +503,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne { checkForRecursion(file, allFuncInfo, getObjectForFileFromMap(file_name, SPF_messages)); intentInsert(getObjectForFileFromMap(file_name, allFuncInfo)); + insertIntrinsicStat(getObjectForFileFromMap(file_name, allFuncInfo)); } else if (curr_regime == LOOP_GRAPH) loopGraphAnalyzer(file, getObjectForFileFromMap(file_name, loopGraph), getObjectForFileFromMap(file_name, intervals), getObjectForFileFromMap(file_name, SPF_messages), mpiProgram); @@ -1335,6 +1336,7 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne detectCopies(allFuncInfo); fillInterfaceBlock(allFuncInfo); intentInsertToInterfaces(allFuncInfo); + //createInterfacesForAssumedSize(allFuncInfo); //this call is only for testing //setPureStatus(allFuncInfo); diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp b/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp index 65cc147..e80aab6 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/dead_code.cpp @@ -374,6 +374,29 @@ static bool hasCalls(SgStatement* stat) return hasCalls(stat->expr(0)) || hasCalls(stat->expr(1)) || hasCalls(stat->expr(2)); } +static void moveComment(SgStatement* stat) +{ + const char* comm = stat->comments(); + if (comm) + { + SgStatement* next = stat->lastNodeOfStmt()->lexNext(); + if (next) + { + const char* commNext = next->comments(); + if (commNext) + { + string newComm(comm); + newComm += commNext; + + next->delComments(); + next->addComment(newComm.c_str()); + } + else + next->addComment(comm); + } + } +} + int removeDeadCode(SgStatement* func, const map>& allFuncs, const map& commonBlocks, @@ -527,12 +550,14 @@ int removeDeadCode(SgStatement* func, else { moveLabelBefore(cp); + moveComment(cp); cp->deleteStmt(); } } else { moveLabelBefore(rem); + moveComment(rem); rem->deleteStmt(); } } @@ -585,6 +610,7 @@ int removeDeadCode(SgStatement* func, { __spf_print(PRINT_USELESS_STATEMENTS, "[Useless block statement on line %d and file %s]\n", rem->lineNumber(), rem->fileName()); moveLabelBefore(rem); + moveComment(rem); rem->deleteStmt(); if (rem == start) mainRemoved = true; diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.cpp b/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.cpp index bc0dbf4..c53de5b 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.cpp @@ -30,6 +30,80 @@ using std::wstring; using std::make_pair; using std::to_string; +void insertIntrinsicStat(const vector& allFuncInfo) +{ + for (auto& func : allFuncInfo) + { + auto start = func->funcPointer->GetOriginal(); + auto end = start->lastNodeOfStmt(); + SgStatement* st = start; + SgStatement* intr = NULL; + + //find last decl place + for ( ; st != end; st = st->lexNext()) + { + if (isSgExecutableStatement(st)) + break; + + if (st->variant() == CONTAINS_STMT) + break; + + if (st->variant() == INTRIN_STAT) + intr = st; + } + + map intrincis; + for (auto& call : func->callsFromDetailed) + { + auto name = call.detailCallsFrom.first; + if (intrincis.find(name) != intrincis.end()) + continue; + + if (!isIntrinsicFunctionName(name.c_str())) + continue; + + void* ptr = call.pointerDetailCallsFrom.first; + int var = call.pointerDetailCallsFrom.second; + + SgSymbol* s = NULL; + if (var == PROC_STAT) + s = ((SgStatement*)ptr)->symbol(); + else if (var == FUNC_CALL) + s = ((SgExpression*)ptr)->symbol(); + else + continue; + + if ((s->attributes() & INTRINSIC_BIT) != 0) + continue; + + intrincis[name] = s; + } + + if (!intrincis.size()) + continue; + + if (intr == NULL) + { + vector list; + for (auto& elem : intrincis) + list.push_back(new SgVarRefExp(elem.second)); + + SgStatement* intr = new SgStatement(INTRIN_STAT); + intr->setExpression(0, makeExprList(list)); + + st->insertStmtBefore(*intr, *func->funcPointer); + } + else + { + SgExprListExp* list = isSgExprListExp(intr->expr(0)); + checkNull(list, convertFileName(__FILE__).c_str(), __LINE__); + + for (auto& elem : intrincis) + list->append(*new SgVarRefExp(elem.second)); + } + } +} + bool checkOutCalls(const set& outCalls) { for (auto& elem : outCalls) @@ -39,7 +113,8 @@ bool checkOutCalls(const set& outCalls) return false; } -void createInterfacesForOutCalls(FuncInfo* func) { +void createInterfacesForOutCalls(FuncInfo* func) +{ if (func->isPure && !func->isMain) { bool hasOutCalls = checkOutCalls(func->callsFrom); @@ -48,6 +123,99 @@ void createInterfacesForOutCalls(FuncInfo* func) { } } +static bool changeIfHasStarRange(SgExpression* arrayDecl) +{ + SgExpression* list = arrayDecl->lhs(); + bool has = false; + + while (list) + { + if (list->lhs()->variant() == STAR_RANGE) + has = true; + list = list->rhs(); + } + + if (has) + { + list = arrayDecl->lhs(); + while (list) + { + list->setLhs(new SgExpression(DDOT)); + list = list->rhs(); + } + } + + return has; +} + +void createInterfacesForAssumedSize(const map>& allFuncInfo) +{ + set hasAssumedSizeArrays; + + for (auto& funcByFile : allFuncInfo) + { + if (SgFile::switchToFile(funcByFile.first) == -1) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + + for (auto& func : funcByFile.second) + { + SgProgHedrStmt* prog = isSgProgHedrStmt(func->funcPointer->GetOriginal()); + if (prog == NULL) + continue; + + for (int z = 0; z < func->funcParams.countOfPars; ++z) + { + if (func->funcParams.parametersT[z] == ARRAY_T) + { + auto s = prog->parameter(z); + const string name = s->identifier(); + + vector allDecls; + declaratedInStmt(s, &allDecls); + + for (auto& decl : allDecls) + { + SgExpression* list = decl->expr(0); + while (list) + { + if (list->lhs() && list->lhs()->symbol()->identifier() == name) + { + if (changeIfHasStarRange(list->lhs())) + hasAssumedSizeArrays.insert(func); + break; + } + list = list->rhs(); + } + } + } + } + } + } + + if (hasAssumedSizeArrays.size() == 0) + return; + + for (auto& funcByFile : allFuncInfo) + { + if (SgFile::switchToFile(funcByFile.first) == -1) + printInternalError(convertFileName(__FILE__).c_str(), __LINE__); + + for (auto& func : funcByFile.second) + { + for (auto& elem : func->callsFromV) + { + auto it = hasAssumedSizeArrays.find(elem); + if (it != hasAssumedSizeArrays.end()) + { + auto callFrom = *it; + DvmhRegionInserter::createInterfaceBlockForOutCall(func, callFrom); + } + } + } + + } +} + static void setPureStatus(FuncInfo* func) { if (func->isPure && !func->isMain) @@ -317,6 +485,9 @@ void intentInsertToInterfaces(const map>& allFuncInfo) if (isSgExecutableStatement(st)) break; + if (st->variant() == CONTAINS_STMT) + break; + if (st->controlParent()->variant() == INTERFACE_STMT) { if (st->variant() == PROC_HEDR || st->variant() == FUNC_HEDR) diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.h b/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.h index 37d24ab..4226cde 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.h +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.h @@ -1,9 +1,12 @@ #pragma once +void insertIntrinsicStat(const std::vector& allFuncInfo); + bool checkOutCalls(const std::set& outCalls); std::map> fillFromIntent(SgStatement* header); void intentInsert(const std::vector& allFuncInfo); void intentInsertToInterfaces(const std::map>& allFuncInfo); +void createInterfacesForAssumedSize(const std::map>& allFuncInfo); void createInterfacesForOutCalls(FuncInfo* func); void setPureStatus(const std::set& funcInfo); void setPureStatus(const std::map>& allFuncInfo); diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp b/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp index 2d19b4f..7bb33a6 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Utils/SgUtils.cpp @@ -3586,4 +3586,4 @@ void addPrivatesToArraysFromGUI(SgFile* file, const mapinsertStmtBefore(*op, *toInsert.first->controlParent()); } -} \ No newline at end of file +} diff --git a/sapfor/experts/Sapfor_2017/_src/Utils/version.h b/sapfor/experts/Sapfor_2017/_src/Utils/version.h index d5b3c37..4b1bd72 100644 --- a/sapfor/experts/Sapfor_2017/_src/Utils/version.h +++ b/sapfor/experts/Sapfor_2017/_src/Utils/version.h @@ -1,3 +1,3 @@ #pragma once -#define VERSION_SPF "2324" +#define VERSION_SPF "2327" diff --git a/sapfor/experts/Sapfor_2017/_src/VerificationCode/StructureChecker.cpp b/sapfor/experts/Sapfor_2017/_src/VerificationCode/StructureChecker.cpp index 757b9ae..99c38d6 100644 --- a/sapfor/experts/Sapfor_2017/_src/VerificationCode/StructureChecker.cpp +++ b/sapfor/experts/Sapfor_2017/_src/VerificationCode/StructureChecker.cpp @@ -313,6 +313,23 @@ bool FunctionsChecker(SgFile *file, map> &funcNames, m checkOK = false; } + + if (isIntrinsicFunctionName(funcName.c_str())) + { + __spf_print(1, "the same function name in different places was found: func %s, places %s:%d and %s:%d\n", + funcName.c_str(), file->filename(), st->lineNumber(), "intrinsic", 0); + + wstring messageE, messageR; + __spf_printToLongBuf(messageE, L"Function '%s' was declared in more than one place: '%s':%d and '%s':%d", + to_wstring(funcName).c_str(), to_wstring(file->filename()).c_str(), st->lineNumber(), to_wstring("intrinsic").c_str(), 0); + + __spf_printToLongBuf(messageR, R92, + to_wstring(funcName).c_str(), to_wstring(file->filename()).c_str(), st->lineNumber(), to_wstring("intrinsic").c_str(), 0); + + currMessages[st->fileName()].push_back(Messages(ERROR, st->lineNumber(), messageR, messageE, 1048)); + + checkOK = false; + } } } return checkOK;