From b8da3d5eb177f0cfb8ae39858637c0c772fa4f50 Mon Sep 17 00:00:00 2001 From: ALEXks Date: Wed, 15 Nov 2023 13:20:28 +0300 Subject: [PATCH] fixed functions purifying --- .../_src/DvmhRegions/DvmhRegionInserter.cpp | 3 --- sapfor/experts/Sapfor_2017/_src/Sapfor.cpp | 12 ++++++++++- .../Transformations/function_purifying.cpp | 20 ++++++++++++++----- .../_src/Transformations/function_purifying.h | 1 + .../experts/Sapfor_2017/_src/Utils/version.h | 2 +- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp b/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp index 1acb3c5..4f4a0ef 100644 --- a/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp +++ b/sapfor/experts/Sapfor_2017/_src/DvmhRegions/DvmhRegionInserter.cpp @@ -1129,9 +1129,6 @@ void DvmhRegionInserter::createInterfaceBlockForOutCalls(FuncInfo* func) if (func->interfaceBlocks.find(callFrom->funcName) == func->interfaceBlocks.end() && 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), callFrom->funcName); } diff --git a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp index 6b35f73..95af46e 100644 --- a/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Sapfor.cpp @@ -2137,8 +2137,18 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne regionInserter->addUsedWriteArrays(usedWriteArraysInRegions); setPureStatus(regionInserter->getParallelFunctions()); + } - //create interface for 'parallel' functions and + for (int i = n - 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(); } diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.cpp b/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.cpp index 99b3c8a..bc0dbf4 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.cpp +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.cpp @@ -39,6 +39,15 @@ bool checkOutCalls(const set& 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>& allFuncInfo) for (auto& funcByFile : allFuncInfo) for (auto& func : funcByFile.second) setPureStatus(func); + + for (auto& funcByFile : allFuncInfo) + for (auto& func : funcByFile.second) + createInterfacesForOutCalls(func); } map> fillFromIntent(SgStatement* header) diff --git a/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.h b/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.h index 7748fdd..37d24ab 100644 --- a/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.h +++ b/sapfor/experts/Sapfor_2017/_src/Transformations/function_purifying.h @@ -4,6 +4,7 @@ bool checkOutCalls(const std::set& outCalls); std::map> fillFromIntent(SgStatement* header); void intentInsert(const std::vector& allFuncInfo); void intentInsertToInterfaces(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/version.h b/sapfor/experts/Sapfor_2017/_src/Utils/version.h index 7f74a25..a3eced5 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 "2237" +#define VERSION_SPF "2238"