added cover

This commit is contained in:
ALEXks
2024-04-12 16:36:37 +03:00
parent 18f58020f5
commit b1eb7608ba
5 changed files with 80 additions and 7 deletions

View File

@@ -47,7 +47,7 @@ static inline void addToAttribute(SgStatement* st, int var, vector<SgExpression*
ex->setLhs(new SgExpression(var, makeExprList(list), NULL));
SgStatement* toAdd = new SgStatement(SPF_ANALYSIS_DIR, NULL, NULL, ex, NULL, NULL);
toAdd->setlineNumber(st->lineNumber());
toAdd->setLocalLineNumber(888);
toAdd->setLocalLineNumber(SPF_OMP_DIR);
//filter
if (var == ACC_PRIVATE_OP)

View File

@@ -6,6 +6,10 @@
#include "../Utils/errors.h"
#define SPF_USER_DIR 777
#define SPF_USER_DIR_COPY 999
#define SPF_OMP_DIR 888
struct OmpDir
{
std::set<std::string> privVars;

View File

@@ -20,6 +20,7 @@
#include "directive_parser.h"
#include "../ExpressionTransform/expr_transform.h"
#include "../LoopAnalyzer/loop_analyzer.h"
#include "../DirectiveProcessing/directive_omp_parser.h"
using std::string;
using std::wstring;
@@ -34,7 +35,7 @@ static void addToattribute(SgStatement *toAttr, SgStatement *curr, const int var
// move SgStatement to attribute
SgStatement *toAdd = new SgStatement(toAttr->variant(), NULL, toAttr->symbol(), toAttr->expr(0), toAttr->expr(1), toAttr->expr(2));
toAdd->setlineNumber(toAttr->lineNumber());
toAdd->setLocalLineNumber(777);
toAdd->setLocalLineNumber(SPF_USER_DIR);
curr->addAttribute(variant, toAdd, sizeof(SgStatement));
//copy comments to st
@@ -257,7 +258,7 @@ static bool checkPrivate(SgStatement *st,
if (!defCond && !useCond)
{
if (attributeStatement->localLineNumber() != 888)
if (attributeStatement->localLineNumber() != SPF_OMP_DIR)
{
__spf_print(1, "variable '%s' is not used in loop on line %d\n", privElem.c_str(), attributeStatement->lineNumber());
wstring messageE, messageR;
@@ -272,7 +273,7 @@ static bool checkPrivate(SgStatement *st,
}
else if (!defCond && useCond)
{
if (attributeStatement->localLineNumber() != 888)
if (attributeStatement->localLineNumber() != SPF_OMP_DIR)
{
__spf_print(1, "variable '%s' is not changed in loop on line %d\n", privElem.c_str(), attributeStatement->lineNumber());
wstring messageE, messageR;
@@ -2042,6 +2043,69 @@ bool check_par_reg_dirs(SgFile *file, vector<Messages> &messagesForFile)
return noError;
}
static void distributeAnalysisWithCover(SgFile* file)
{
int funcNum = file->numberOfFunctions();
const string currFile = file->filename();
for (int i = 0; i < funcNum; ++i)
{
SgStatement* st = file->functions(i);
SgStatement* lastNode = st->lastNodeOfStmt();
map<SgStatement*, pair<set<SgStatement*>, int>> spfAnalysis;
do
{
st = st->lexNext();
if (st == NULL)
{
__spf_print(1, "internal error in analysis, parallel directives will not be generated for this file!\n");
break;
}
if (st->variant() == CONTAINS_STMT)
break;
if (st->variant() == FOR_NODE)
{
pair<set<SgStatement*>, int> newData = { set<SgStatement*>(), 0 };
for (auto& data : getAttributes<SgStatement*, SgStatement*>(st, set<int>{ SPF_ANALYSIS_DIR }))
{
newData.first.insert(data);
int cover = getCoverPropertyFromComment(new Statement(data));
if (cover != 0)
newData.second = cover;
}
if (newData.first.size())
spfAnalysis[st] = newData;
}
} while (st != lastNode);
for (auto& data : spfAnalysis)
{
SgForStmt* st = isSgForStmt(data.first);
checkNull(st, convertFileName(__FILE__).c_str(), __LINE__);
int level = st->isPerfectLoopNest();
if (data.second.second < level && data.second.second != 0)
level = data.second.second;
for (int z = 0; z < level - 1; ++z)
{
st = isSgForStmt(st->lexNext());
checkNull(st, convertFileName(__FILE__).c_str(), __LINE__);
for (auto& dirs : data.second.first)
{
auto copy = dirs->copyPtr();
copy->setLocalLineNumber(SPF_USER_DIR_COPY);
st->addAttribute(copy->variant(), copy, sizeof(SgStatement));
}
}
}
}
}
bool preprocess_spf_dirs(SgFile *file, const map<string, CommonBlock*> &commonBlocks, vector<Messages> &messagesForFile, const set<string>& allFileNames,
map<pair<string, int>, set<SgStatement*>>& usersDirectives)
{
@@ -2084,6 +2148,10 @@ bool preprocess_spf_dirs(SgFile *file, const map<string, CommonBlock*> &commonBl
findModulesInFile(file, modules);
bool result = processModules(modules, currFile, &commonBlocks, messagesForFile, allFileNames, usersDirectives);
noError = noError && result;
if (noError)
distributeAnalysisWithCover(file);
return noError;
}
@@ -2184,7 +2252,7 @@ vector<SgStatement*> filterUserSpf(const vector<SgStatement*> &toFilter, bool wi
{
vector<SgStatement*> ret;
for (auto &elem : toFilter)
if (elem->localLineNumber() == 777 || (elem->localLineNumber() == 888 && with_omp)) // user and omp
if (elem->localLineNumber() == SPF_USER_DIR || (elem->localLineNumber() == SPF_OMP_DIR && with_omp)) // user and omp
ret.push_back(elem);
return ret;

View File

@@ -9,6 +9,7 @@
#include "../CFGraph/CFGraph.h"
#include "../SageAnalysisTool/OmegaForSage/include/lang-interf.h"
#include "../DirectiveProcessing/directive_parser.h"
#include "../DirectiveProcessing/directive_omp_parser.h"
using std::string;
using std::vector;
@@ -766,7 +767,7 @@ static void filterSpfAttributes(SgStatement* stat)
if (attr->getAttributeType() == SPF_ANALYSIS_DIR)
{
SgStatement* data = (SgStatement*)attr->getAttributeData();
if (data->localLineNumber() != 777)
if (data->localLineNumber() != SPF_USER_DIR)
continue;
//__spf_print(1, "%s", data->unparse());

View File

@@ -1,3 +1,3 @@
#pragma once
#define VERSION_SPF "2315"
#define VERSION_SPF "2316"