Compare commits
6 Commits
libpredict
...
a78606c882
| Author | SHA1 | Date | |
|---|---|---|---|
| a78606c882 | |||
|
|
a0cea2df91 | ||
|
|
4b7df86b8a | ||
| 836894fef1 | |||
| 9ac15eec79 | |||
| 03f565f50b |
Submodule projects/dvm updated: 4b7ef11871...4d4041a081
@@ -121,21 +121,108 @@ static void SolveDataFlow(Region* DFG)
|
||||
Collapse(DFG);
|
||||
}
|
||||
|
||||
unsigned long long CalculateLength(const AccessingSet& array)
|
||||
{
|
||||
if (array.GetElements().empty())
|
||||
return 0;
|
||||
unsigned long long result = 1;
|
||||
for (const auto& range : array.GetElements())
|
||||
{
|
||||
for (const auto& dim : range)
|
||||
{
|
||||
result *= (dim.start + dim.step * dim.tripCount);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void AddPrivateArraysToLoop(LoopGraph* loop, ArrayAccessingIndexes privates)
|
||||
{
|
||||
SgStatement* privSpf = new SgStatement(SPF_ANALYSIS_DIR, NULL, NULL, NULL, NULL, NULL);
|
||||
|
||||
SgExpression* tmp = new SgExpression(ACC_PRIVATE_OP);
|
||||
SgExpression* exprList = new SgExpression(EXPR_LIST, tmp, NULL, NULL);
|
||||
privSpf->setExpression(0, *exprList);
|
||||
exprList = exprList->lhs();
|
||||
|
||||
SgExpression* tmp1 = new SgExpression(EXPR_LIST);
|
||||
exprList->setLhs(tmp1);
|
||||
exprList = exprList->lhs();
|
||||
vector<SgExpression*> arraysToInsert;
|
||||
for (const auto& [_, accessingSet] : privates)
|
||||
{
|
||||
for (const auto& arrayElement : accessingSet.GetElements())
|
||||
{
|
||||
if (arrayElement.empty())
|
||||
continue;
|
||||
|
||||
auto arrayType = isSgArrayType(arrayElement[0].array->symbol()->type());
|
||||
SgExpression* dimList = NULL;
|
||||
if (arrayType)
|
||||
{
|
||||
dimList = arrayType->getDimList();
|
||||
for (int i = 0; i < arrayType->length()->valueInteger(); i++)
|
||||
{
|
||||
int lb = dimList[i].lhs()->valueInteger();
|
||||
int ub = dimList[i].rhs()->valueInteger();
|
||||
int expectedLength = ub - lb + 1;
|
||||
if (expectedLength == CalculateLength(accessingSet))
|
||||
{
|
||||
arraysToInsert.push_back(arrayElement[0].array);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!arraysToInsert.empty())
|
||||
{
|
||||
for (int i = 0; i < arraysToInsert.size(); i++)
|
||||
{
|
||||
exprList->setLhs(arraysToInsert[i]);
|
||||
if (i < arraysToInsert.size() - 1)
|
||||
{
|
||||
SgExpression* tmp = new SgExpression(EXPR_LIST);
|
||||
exprList->setRhs(tmp);
|
||||
exprList = exprList->rhs();
|
||||
}
|
||||
}
|
||||
loop->loop->GetOriginal()->addAttribute(SPF_ANALYSIS_DIR, privSpf, sizeof(SgStatement));
|
||||
}
|
||||
}
|
||||
|
||||
map<LoopGraph*, ArrayAccessingIndexes> FindPrivateArrays(map<string, vector<LoopGraph*>> &loopGraph, map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& FullIR)
|
||||
{
|
||||
map<LoopGraph*, ArrayAccessingIndexes> result;
|
||||
for (const auto& [loopName, loops] : loopGraph)
|
||||
for (const auto& [fileName, loops] : loopGraph)
|
||||
{
|
||||
SgFile::switchToFile(fileName);
|
||||
for (const auto& loop : loops)
|
||||
{
|
||||
SgStatement* search_func = loop->loop->GetOriginal();
|
||||
|
||||
while (search_func && (!isSgProgHedrStmt(search_func)))
|
||||
search_func = search_func->controlParent();
|
||||
|
||||
for (const auto& [funcInfo, blocks]: FullIR)
|
||||
{
|
||||
if (funcInfo->fileName == fileName && funcInfo->funcPointer->GetOriginal() == search_func)
|
||||
{
|
||||
Region* loopRegion = new Region(loop, blocks);
|
||||
if (loopRegion->getBasickBlocks().size() <= 1)
|
||||
{
|
||||
delete(loopRegion);
|
||||
continue;
|
||||
}
|
||||
SolveDataFlow(loopRegion);
|
||||
result[loop] = loopRegion->array_priv;
|
||||
delete(loopRegion);
|
||||
}
|
||||
}
|
||||
if (result.find(loop) != result.end() && !result[loop].empty())
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ static ArrayDimension* DimensionIntersection(const ArrayDimension& dim1, const A
|
||||
|
||||
uint64_t start3 = dim1.start + x0 * dim1.step;
|
||||
uint64_t step3 = c * dim1.step;
|
||||
ArrayDimension* result = new(ArrayDimension){ start3, step3, tMax + 1 };
|
||||
ArrayDimension* result = new(ArrayDimension){ start3, step3, tMax + 1 , dim1.array};
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ static vector<ArrayDimension> DimensionDifference(const ArrayDimension& dim1, co
|
||||
vector<ArrayDimension> result;
|
||||
/* add the part before intersection */
|
||||
if (dim1.start < intersection->start)
|
||||
result.push_back({ dim1.start, dim1.step, (intersection->start - dim1.start) / dim1.step });
|
||||
result.push_back({ dim1.start, dim1.step, (intersection->start - dim1.start) / dim1.step, dim1.array});
|
||||
|
||||
/* add the parts between intersection steps */
|
||||
uint64_t start = (intersection->start - dim1.start) / dim1.step;
|
||||
@@ -73,7 +73,7 @@ static vector<ArrayDimension> DimensionDifference(const ArrayDimension& dim1, co
|
||||
{
|
||||
if (i - start > 1)
|
||||
{
|
||||
result.push_back({ dim1.start + (start + 1) * dim1.step, dim1.step, i - start - 1 });
|
||||
result.push_back({ dim1.start + (start + 1) * dim1.step, dim1.step, i - start - 1, dim1.array });
|
||||
start = i;
|
||||
}
|
||||
interValue += intersection->step;
|
||||
@@ -85,7 +85,7 @@ static vector<ArrayDimension> DimensionDifference(const ArrayDimension& dim1, co
|
||||
/* first value after intersection */
|
||||
uint64_t right_start = intersection->start + intersection->step * (intersection->tripCount - 1) + dim1.step;
|
||||
uint64_t tripCount = (dim1.start + dim1.step * dim1.tripCount - right_start) / dim1.step;
|
||||
result.push_back({ right_start, dim1.step, tripCount });
|
||||
result.push_back({ right_start, dim1.step, tripCount, dim1.array });
|
||||
}
|
||||
delete(intersection);
|
||||
return result;
|
||||
|
||||
@@ -6,9 +6,12 @@
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
#include "SgUtils.h"
|
||||
|
||||
struct ArrayDimension
|
||||
{
|
||||
uint64_t start, step, tripCount;
|
||||
SgArrayRefExp* array;
|
||||
};
|
||||
|
||||
class AccessingSet {
|
||||
|
||||
@@ -148,6 +148,7 @@ static int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAcces
|
||||
int currentVarPos = refPos.back();
|
||||
pair<int, int> currentCoefs = coefsForDims.back();
|
||||
ArrayDimension current_dim;
|
||||
current_dim.array = ref;
|
||||
if (var->getType() == SAPFOR::CFG_ARG_TYPE::CONST)
|
||||
current_dim = { stoul(var->getValue()), 1, 1 };
|
||||
else
|
||||
|
||||
@@ -1019,8 +1019,6 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
||||
if(func->funcPointer->variant() != ENTRY_STAT)
|
||||
countOfTransform += removeDeadCode(func->funcPointer, allFuncInfo, commonBlocks);
|
||||
}
|
||||
else if (curr_regime == FIND_PRIVATE_ARRAYS)
|
||||
FindPrivateArrays(loopGraph, fullIR);
|
||||
else if (curr_regime == TEST_PASS)
|
||||
{
|
||||
//test pass
|
||||
@@ -1916,6 +1914,8 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
||||
}
|
||||
else if (curr_regime == TRANSFORM_ASSUMED_SIZE_PARAMETERS)
|
||||
transformAssumedSizeParameters(allFuncInfo);
|
||||
else if (curr_regime == FIND_PRIVATE_ARRAYS)
|
||||
auto result = FindPrivateArrays(loopGraph, fullIR);
|
||||
|
||||
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.;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define VERSION_SPF "2446"
|
||||
#define VERSION_SPF "2447"
|
||||
|
||||
@@ -1793,6 +1793,13 @@ int SPF_RenameIncludes(void*& context, int winHandler, short* options, short* pr
|
||||
return simpleTransformPass(RENAME_INLCUDES, options, projName, folderName, output, outputMessage);
|
||||
}
|
||||
|
||||
int SPF_InsertPrivateArrayDirectives(void*& context, int winHandler, short* options, short* projName, short* folderName, string& output, string& outputMessage)
|
||||
{
|
||||
MessageManager::clearCache();
|
||||
MessageManager::setWinHandler(winHandler);
|
||||
return simpleTransformPass(FIND_PRIVATE_ARRAYS, options, projName, folderName, output, outputMessage);
|
||||
}
|
||||
|
||||
static inline void convertBackSlash(char *str, int strL)
|
||||
{
|
||||
for (int z = 0; z < strL; ++z)
|
||||
@@ -2499,6 +2506,8 @@ const wstring Sapfor_RunTransformation(const char* transformName_c, const char*
|
||||
retCode = SPF_InsertImplicitNone(context, winHandler, optSh, projSh, fold, output, outputMessage);
|
||||
else if (whichRun == "SPF_RenameIncludes")
|
||||
retCode = SPF_RenameIncludes(context, winHandler, optSh, projSh, fold, output, outputMessage);
|
||||
else if (whichRun == "SPF_InsertPrivateArrayDirectives")
|
||||
retCode = SPF_InsertPrivateArrayDirectives(context, winHandler, optSh, projSh, fold, output, outputMessage);
|
||||
else if (whichRun == "SPF_CreateParallelVariant")
|
||||
{
|
||||
vector<string> splited;
|
||||
|
||||
Reference in New Issue
Block a user