refactored private arrays analysis
This commit is contained in:
@@ -20,14 +20,11 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
extern std::map<std::tuple<int, std::string, std::string>, std::pair<DIST::Array*, DIST::ArrayAccessInfo*>> declaredArrays;
|
||||
extern map<string, vector<Messages>> SPF_messages;
|
||||
|
||||
static set<Region*> collapsed;
|
||||
|
||||
static void RemoveEmptyPoints(ArrayAccessingIndexes& container)
|
||||
static void removeEmptyPoints(arrayAccessingIndexes& container)
|
||||
{
|
||||
ArrayAccessingIndexes resultContainer;
|
||||
arrayAccessingIndexes resultContainer;
|
||||
set<string> toRemove;
|
||||
|
||||
for (auto& [arrayName, accessingSet] : container)
|
||||
@@ -52,7 +49,7 @@ static void RemoveEmptyPoints(ArrayAccessingIndexes& container)
|
||||
container[arrayName] = accessingSet;
|
||||
}
|
||||
|
||||
static void Collapse(Region* region)
|
||||
static void collapse(Region* region)
|
||||
{
|
||||
if (region->getBasickBlocks().empty())
|
||||
return;
|
||||
@@ -90,7 +87,7 @@ static void Collapse(Region* region)
|
||||
RegionInstruction instruction;
|
||||
instruction.def = move(region->array_def);
|
||||
|
||||
ArrayAccessingIndexes recursivePriv;
|
||||
arrayAccessingIndexes recursivePriv;
|
||||
for (auto& byBlock : region->getBasickBlocks())
|
||||
{
|
||||
if (!byBlock->array_priv.empty())
|
||||
@@ -107,7 +104,7 @@ static void Collapse(Region* region)
|
||||
}
|
||||
}
|
||||
|
||||
ArrayAccessingIndexes useUnionB;
|
||||
arrayAccessingIndexes useUnionB;
|
||||
for (auto& byBlock : region->getBasickBlocks())
|
||||
for (auto& instruction : byBlock->instructions)
|
||||
for (auto& [arrayName, _] : instruction.use)
|
||||
@@ -134,9 +131,9 @@ static void Collapse(Region* region)
|
||||
region->array_priv = move(recursivePriv);
|
||||
}
|
||||
|
||||
static void SolveForBasickBlock(Region* block)
|
||||
static void solveForBasickBlock(Region* block)
|
||||
{
|
||||
ArrayAccessingIndexes newIn;
|
||||
arrayAccessingIndexes newIn;
|
||||
bool flagFirst = true;
|
||||
for (Region* prevBlock : block->getPrevRegions())
|
||||
{
|
||||
@@ -175,7 +172,7 @@ static void SolveForBasickBlock(Region* block)
|
||||
if (i > 0)
|
||||
instruction.in = block->instructions[i - 1].out;
|
||||
|
||||
ArrayAccessingIndexes newOut;
|
||||
arrayAccessingIndexes newOut;
|
||||
if (instruction.def.empty())
|
||||
newOut = instruction.in;
|
||||
else if (instruction.in.empty())
|
||||
@@ -192,9 +189,7 @@ static void SolveForBasickBlock(Region* block)
|
||||
for (auto& [arrayName, accessSet] : instruction.in)
|
||||
{
|
||||
if (newOut.find(arrayName) == newOut.end())
|
||||
{
|
||||
newOut[arrayName] = accessSet;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,30 +199,31 @@ static void SolveForBasickBlock(Region* block)
|
||||
block->array_out = block->instructions.back().out;
|
||||
}
|
||||
|
||||
static void SolveDataFlowTopologically(Region* DFG)
|
||||
static void solveDataFlowTopologically(Region* DFG)
|
||||
{
|
||||
for (Region* b : DFG->getBasickBlocks())
|
||||
{
|
||||
collapsed.insert(b);
|
||||
SolveForBasickBlock(b);
|
||||
solveForBasickBlock(b);
|
||||
}
|
||||
}
|
||||
|
||||
static void SolveDataFlow(Region* DFG)
|
||||
static void solveDataFlow(Region* DFG)
|
||||
{
|
||||
if (!DFG)
|
||||
return;
|
||||
|
||||
for (Region* subRegion : DFG->getSubRegions())
|
||||
{
|
||||
SolveDataFlow(subRegion);
|
||||
solveDataFlow(subRegion);
|
||||
DFG->addBasickBlocks(subRegion);
|
||||
}
|
||||
vector<Region*>& blocks = DFG->getBasickBlocks();
|
||||
auto pos = remove_if(blocks.begin(), blocks.end(), [](Region* r) { return collapsed.find(r) != collapsed.end(); });
|
||||
blocks.erase(pos, blocks.end());
|
||||
TopologySort(DFG->getBasickBlocks(), DFG->getHeader());
|
||||
SolveDataFlowTopologically(DFG);
|
||||
Collapse(DFG);
|
||||
topologySort(DFG->getBasickBlocks(), DFG->getHeader());
|
||||
solveDataFlowTopologically(DFG);
|
||||
collapse(DFG);
|
||||
}
|
||||
|
||||
static bool getArrayDeclaredDimensions(SgArrayRefExp* arrayRef, vector<uint64_t>& declaredDims)
|
||||
@@ -247,9 +243,7 @@ static bool getArrayDeclaredDimensions(SgArrayRefExp* arrayRef, vector<uint64_t>
|
||||
else if (constValSymb)
|
||||
dimLength = stol(constValSymb->constantValue()->unparse());
|
||||
else if (subscriptExpr)
|
||||
{
|
||||
dimLength = stol(subscriptExpr->rhs()->unparse()) - stol(subscriptExpr->lhs()->unparse());
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
@@ -260,7 +254,7 @@ static bool getArrayDeclaredDimensions(SgArrayRefExp* arrayRef, vector<uint64_t>
|
||||
return true;
|
||||
}
|
||||
|
||||
static DIST::Array* getDistArrayBySymbol(SgSymbol* arrSym)
|
||||
static DIST::Array* getDistArrayBySymbol(SgSymbol* arrSym, const map<tuple<int, string, string>, pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays)
|
||||
{
|
||||
if (!arrSym)
|
||||
return nullptr;
|
||||
@@ -268,10 +262,10 @@ static DIST::Array* getDistArrayBySymbol(SgSymbol* arrSym)
|
||||
{
|
||||
DIST::Array* distArr = val.first;
|
||||
if (!distArr)
|
||||
continue;
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
Symbol* declSym = distArr->GetDeclSymbol();
|
||||
if (!declSym)
|
||||
continue;
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
SgSymbol* sgDecl = declSym->GetOriginal();
|
||||
if (sgDecl && isEqSymbols(sgDecl, arrSym))
|
||||
return distArr;
|
||||
@@ -279,7 +273,7 @@ static DIST::Array* getDistArrayBySymbol(SgSymbol* arrSym)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static bool CheckDimensionLength(const AccessingSet& array)
|
||||
static bool checkDimensionLength(const AccessingSet& array, const map<tuple<int, string, string>, pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays)
|
||||
{
|
||||
if (array.GetElements().empty())
|
||||
return false;
|
||||
@@ -291,7 +285,7 @@ static bool CheckDimensionLength(const AccessingSet& array)
|
||||
vector<uint64_t> declaredDims;
|
||||
declaredDims.reserve(dimCount);
|
||||
|
||||
DIST::Array* distArr = getDistArrayBySymbol(arrayRef->symbol());
|
||||
DIST::Array* distArr = getDistArrayBySymbol(arrayRef->symbol(), declaredArrays);
|
||||
if (distArr && distArr->GetDimSize() == (int)dimCount)
|
||||
{
|
||||
const auto& sizes = distArr->GetSizes();
|
||||
@@ -317,7 +311,9 @@ static bool CheckDimensionLength(const AccessingSet& array)
|
||||
return false;
|
||||
}
|
||||
|
||||
static void AddPrivateArraysToLoop(LoopGraph* loop, const ArrayAccessingIndexes& privates, set<SgStatement*>& insertedPrivates)
|
||||
static void addPrivateArraysToLoop(LoopGraph* loop, const arrayAccessingIndexes& privates, set<SgStatement*>& insertedPrivates,
|
||||
map<string, vector<Messages>>& SPF_messages,
|
||||
const map<tuple<int, string, string>, pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays)
|
||||
{
|
||||
SgStatement* spfStat = new SgStatement(SPF_ANALYSIS_DIR);
|
||||
spfStat->setlineNumber(loop->loop->lineNumber());
|
||||
@@ -328,19 +324,12 @@ static void AddPrivateArraysToLoop(LoopGraph* loop, const ArrayAccessingIndexes&
|
||||
{
|
||||
int idx = arrayName.find('%');
|
||||
string name = (idx != -1 ? arrayName.substr(idx+1) : arrayName);
|
||||
if (!CheckDimensionLength(accessingSet))
|
||||
if (!checkDimensionLength(accessingSet, declaredArrays))
|
||||
{
|
||||
wstring messageE, messageR;
|
||||
__spf_printToLongBuf(
|
||||
messageE,
|
||||
L"Private array '%s' was skipped because dimension lengths are inconsistent",
|
||||
to_wstring(name).c_str());
|
||||
__spf_printToLongBuf(
|
||||
messageR,
|
||||
R159,
|
||||
to_wstring("array " + name + " has inconsistent dimension lengths").c_str());
|
||||
SPF_messages[loop->loop->fileName()].push_back(
|
||||
Messages(WARR, loop->loop->lineNumber(), messageR, messageE, 1029));
|
||||
__spf_printToLongBuf(messageE, L"Private array '%s' was skipped because dimension lengths are inconsistent", to_wstring(name).c_str());
|
||||
__spf_printToLongBuf(messageR, R159, to_wstring("array " + name + " has inconsistent dimension lengths").c_str());
|
||||
SPF_messages[loop->loop->fileName()].push_back(Messages(WARR, loop->loop->lineNumber(), messageR, messageE, 1029));
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -378,12 +367,18 @@ static void AddPrivateArraysToLoop(LoopGraph* loop, const ArrayAccessingIndexes&
|
||||
}
|
||||
}
|
||||
|
||||
void findPrivateArrays(map<string, vector<LoopGraph*>>& loopGraph, map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& FullIR, set<SgStatement*>& insertedPrivates)
|
||||
void findPrivateArrays(map<string, vector<LoopGraph*>>& loopGraph, map<FuncInfo*,
|
||||
vector<SAPFOR::BasicBlock*>>& FullIR,
|
||||
set<SgStatement*>& insertedPrivates,
|
||||
map<string, vector<Messages>>& SPF_messages,
|
||||
const map<tuple<int, string, string>, pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays)
|
||||
{
|
||||
map<LoopGraph*, ArrayAccessingIndexes> result;
|
||||
map<LoopGraph*, arrayAccessingIndexes> result;
|
||||
for (const auto& [fileName, loops] : loopGraph)
|
||||
{
|
||||
SgFile::switchToFile(fileName);
|
||||
if (SgFile::switchToFile(fileName) == -1)
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
for (const auto& loop : loops)
|
||||
{
|
||||
if (!loop->isFor())
|
||||
@@ -397,28 +392,31 @@ void findPrivateArrays(map<string, vector<LoopGraph*>>& loopGraph, map<FuncInfo*
|
||||
{
|
||||
if (funcInfo->fileName == fileName && funcInfo->funcPointer->GetOriginal() == search_func)
|
||||
{
|
||||
Region* loopRegion;
|
||||
Region* loopRegion = nullptr;
|
||||
try
|
||||
{
|
||||
loopRegion = new Region(loop, blocks);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
continue;
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
}
|
||||
|
||||
if (loopRegion->getBasickBlocks().size() <= 1)
|
||||
{
|
||||
delete(loopRegion);
|
||||
delete loopRegion;
|
||||
continue;
|
||||
}
|
||||
SolveDataFlow(loopRegion);
|
||||
RemoveEmptyPoints(loopRegion->array_priv);
|
||||
|
||||
solveDataFlow(loopRegion);
|
||||
removeEmptyPoints(loopRegion->array_priv);
|
||||
result[loop] = loopRegion->array_priv;
|
||||
delete(loopRegion);
|
||||
delete loopRegion;
|
||||
}
|
||||
}
|
||||
|
||||
if (result.find(loop) != result.end() && !result[loop].empty())
|
||||
AddPrivateArraysToLoop(loop, result[loop], insertedPrivates);
|
||||
addPrivateArraysToLoop(loop, result[loop], insertedPrivates, SPF_messages, declaredArrays);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user