add directives
This commit is contained in:
@@ -121,6 +121,60 @@ static void SolveDataFlow(Region* DFG)
|
|||||||
Collapse(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.step * dim.tripCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddPrivateArraysToLoop(LoopGraph* loop, ArrayAccessingIndexes privates)
|
||||||
|
{
|
||||||
|
SgStatement* spfStat = new SgStatement(SPF_ANALYSIS_DIR);
|
||||||
|
spfStat->setlineNumber(loop->lineNum);
|
||||||
|
spfStat->setFileName((char*)loop->loop->fileName());
|
||||||
|
SgExpression* toAdd = new SgExpression(EXPR_LIST, new SgExpression(ACC_PRIVATE_OP), NULL, NULL);
|
||||||
|
set<SgSymbol*> arraysToInsert;
|
||||||
|
for (const auto& [_, accessingSet] : privates)
|
||||||
|
{
|
||||||
|
for (const auto& arrayElement : accessingSet.GetElements())
|
||||||
|
{
|
||||||
|
if (arrayElement.empty())
|
||||||
|
continue;
|
||||||
|
arraysToInsert.insert(arrayElement[0].array->symbol());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
spfStat->setExpression(0, *toAdd);
|
||||||
|
toAdd = toAdd->lhs();
|
||||||
|
bool first = true;
|
||||||
|
for (auto& elem : arraysToInsert)
|
||||||
|
{
|
||||||
|
if (first)
|
||||||
|
{
|
||||||
|
toAdd->setLhs(new SgExpression(EXPR_LIST));
|
||||||
|
toAdd = toAdd->lhs();
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
toAdd->setRhs(new SgExpression(EXPR_LIST));
|
||||||
|
toAdd = toAdd->rhs();
|
||||||
|
}
|
||||||
|
toAdd->setLhs(new SgVarRefExp(elem));
|
||||||
|
}
|
||||||
|
|
||||||
|
loop->loop->addAttribute(SPF_ANALYSIS_DIR, spfStat, sizeof(SgStatement));
|
||||||
|
}
|
||||||
|
|
||||||
map<LoopGraph*, ArrayAccessingIndexes> FindPrivateArrays(map<string, vector<LoopGraph*>> &loopGraph, map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& FullIR)
|
map<LoopGraph*, ArrayAccessingIndexes> FindPrivateArrays(map<string, vector<LoopGraph*>> &loopGraph, map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& FullIR)
|
||||||
{
|
{
|
||||||
map<LoopGraph*, ArrayAccessingIndexes> result;
|
map<LoopGraph*, ArrayAccessingIndexes> result;
|
||||||
@@ -149,6 +203,10 @@ map<LoopGraph*, ArrayAccessingIndexes> FindPrivateArrays(map<string, vector<Loo
|
|||||||
delete(loopRegion);
|
delete(loopRegion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (result.find(loop) != result.end() && !result[loop].empty())
|
||||||
|
{
|
||||||
|
AddPrivateArraysToLoop(loop, result[loop]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ static ArrayDimension* DimensionIntersection(const ArrayDimension& dim1, const A
|
|||||||
|
|
||||||
uint64_t start3 = dim1.start + x0 * dim1.step;
|
uint64_t start3 = dim1.start + x0 * dim1.step;
|
||||||
uint64_t step3 = c * 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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ static vector<ArrayDimension> DimensionDifference(const ArrayDimension& dim1, co
|
|||||||
vector<ArrayDimension> result;
|
vector<ArrayDimension> result;
|
||||||
/* add the part before intersection */
|
/* add the part before intersection */
|
||||||
if (dim1.start < intersection->start)
|
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 */
|
/* add the parts between intersection steps */
|
||||||
uint64_t start = (intersection->start - dim1.start) / dim1.step;
|
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)
|
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;
|
start = i;
|
||||||
}
|
}
|
||||||
interValue += intersection->step;
|
interValue += intersection->step;
|
||||||
@@ -85,7 +85,7 @@ static vector<ArrayDimension> DimensionDifference(const ArrayDimension& dim1, co
|
|||||||
/* first value after intersection */
|
/* first value after intersection */
|
||||||
uint64_t right_start = intersection->start + intersection->step * (intersection->tripCount - 1) + dim1.step;
|
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;
|
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);
|
delete(intersection);
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -6,9 +6,12 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include "SgUtils.h"
|
||||||
|
|
||||||
struct ArrayDimension
|
struct ArrayDimension
|
||||||
{
|
{
|
||||||
uint64_t start, step, tripCount;
|
uint64_t start, step, tripCount;
|
||||||
|
SgArrayRefExp* array;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AccessingSet {
|
class AccessingSet {
|
||||||
|
|||||||
@@ -139,17 +139,16 @@ static int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAcces
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(coefsForDims.empty())
|
int fillCount = 0;
|
||||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
|
||||||
|
|
||||||
while (!index_vars.empty())
|
while (!index_vars.empty() && !refPos.empty() && !coefsForDims.empty())
|
||||||
{
|
{
|
||||||
auto var = index_vars.back();
|
auto var = index_vars.back();
|
||||||
int currentVarPos = refPos.back();
|
int currentVarPos = refPos.back();
|
||||||
pair<int, int> currentCoefs = coefsForDims.back();
|
pair<int, int> currentCoefs = coefsForDims.back();
|
||||||
ArrayDimension current_dim;
|
ArrayDimension current_dim;
|
||||||
if (var->getType() == SAPFOR::CFG_ARG_TYPE::CONST)
|
if (var->getType() == SAPFOR::CFG_ARG_TYPE::CONST)
|
||||||
current_dim = { stoul(var->getValue()), 1, 1 };
|
current_dim = { stoul(var->getValue()), 1, 1, ref};
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string name, full_name = var->getValue();
|
string name, full_name = var->getValue();
|
||||||
@@ -177,21 +176,25 @@ static int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAcces
|
|||||||
|
|
||||||
uint64_t start = currentLoop->startVal * currentCoefs.first + currentCoefs.second;
|
uint64_t start = currentLoop->startVal * currentCoefs.first + currentCoefs.second;
|
||||||
uint64_t step = currentCoefs.first;
|
uint64_t step = currentCoefs.first;
|
||||||
current_dim = { start, step, (uint64_t)currentLoop->calculatedCountOfIters };
|
current_dim = { start, step, (uint64_t)currentLoop->calculatedCountOfIters, ref };
|
||||||
}
|
}
|
||||||
|
|
||||||
accessPoint[n - index_vars.size()] = current_dim;
|
accessPoint[n - index_vars.size()] = current_dim;
|
||||||
|
fillCount++;
|
||||||
index_vars.pop_back();
|
index_vars.pop_back();
|
||||||
refPos.pop_back();
|
refPos.pop_back();
|
||||||
coefsForDims.pop_back();
|
coefsForDims.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fillCount == accessPoint.size())
|
||||||
|
{
|
||||||
if (operation == SAPFOR::CFG_OP::STORE)
|
if (operation == SAPFOR::CFG_OP::STORE)
|
||||||
def[array_name].Insert(accessPoint);
|
def[array_name].Insert(accessPoint);
|
||||||
else
|
else
|
||||||
use[array_name].Insert(accessPoint);
|
use[array_name].Insert(accessPoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user