refactored private arrays analysis

This commit is contained in:
ALEXks
2026-05-01 12:23:51 +03:00
parent 357f961d68
commit e1bcaeba5c
7 changed files with 104 additions and 107 deletions

View File

@@ -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,11 +189,9 @@ static void SolveForBasickBlock(Region* block)
for (auto& [arrayName, accessSet] : instruction.in)
{
if (newOut.find(arrayName) == newOut.end())
{
newOut[arrayName] = accessSet;
}
}
}
instruction.out = move(newOut);
}
@@ -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);
}
}
}

View File

@@ -3,10 +3,12 @@
#include <vector>
#include <map>
#include <set>
#include <set>
#include "range_structures.h"
#include "graph_loops.h"
#include "CFGraph/CFGraph.h"
void findPrivateArrays(std::map<std::string, std::vector<LoopGraph*>>& loopGraph, std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& FullIR, std::set<SgStatement*>& insertedPrivates);
void findPrivateArrays(std::map<std::string, std::vector<LoopGraph*>>& loopGraph, std::map<FuncInfo*,
std::vector<SAPFOR::BasicBlock*>>& FullIR, std::set<SgStatement*>& insertedPrivates,
std::map<std::string, std::vector<Messages>>& SPF_messages,
const std::map<std::tuple<int, std::string, std::string>, std::pair<DIST::Array*, DIST::ArrayAccessInfo*>>& declaredArrays);

View File

@@ -8,7 +8,7 @@
using namespace std;
static vector<uint64_t> FindParticularSolution(const ArrayDimension& dim1, const ArrayDimension& dim2)
static vector<uint64_t> findParticularSolution(const ArrayDimension& dim1, const ArrayDimension& dim2)
{
for (uint64_t i = 0; i < dim1.tripCount; i++)
{
@@ -24,9 +24,9 @@ static vector<uint64_t> FindParticularSolution(const ArrayDimension& dim1, const
}
/* dim1 /\ dim2 */
static ArrayDimension* DimensionIntersection(const ArrayDimension& dim1, const ArrayDimension& dim2)
static ArrayDimension* dimensionIntersection(const ArrayDimension& dim1, const ArrayDimension& dim2)
{
vector<uint64_t> partSolution = FindParticularSolution(dim1, dim2);
vector<uint64_t> partSolution = findParticularSolution(dim1, dim2);
if (partSolution.empty())
return NULL;
@@ -52,9 +52,9 @@ static ArrayDimension* DimensionIntersection(const ArrayDimension& dim1, const A
}
/* dim1 / dim2 */
static vector<ArrayDimension> DimensionDifference(const ArrayDimension& dim1, const ArrayDimension& dim2)
static vector<ArrayDimension> dimensionDifference(const ArrayDimension& dim1, const ArrayDimension& dim2)
{
ArrayDimension* intersection = DimensionIntersection(dim1, dim2);
ArrayDimension* intersection = dimensionIntersection(dim1, dim2);
if (!intersection)
return { dim1 };
@@ -87,10 +87,10 @@ static vector<ArrayDimension> DimensionDifference(const ArrayDimension& dim1, co
}
static vector<ArrayDimension> DimensionUnion(const ArrayDimension& dim1, const ArrayDimension& dim2)
static vector<ArrayDimension> dimensionUnion(const ArrayDimension& dim1, const ArrayDimension& dim2)
{
vector<ArrayDimension> res;
ArrayDimension* inter = DimensionIntersection(dim1, dim2);
ArrayDimension* inter = dimensionIntersection(dim1, dim2);
if (!inter)
return { dim1, dim2 };
@@ -98,14 +98,14 @@ static vector<ArrayDimension> DimensionUnion(const ArrayDimension& dim1, const A
delete(inter);
vector<ArrayDimension> diff1, diff2;
diff1 = DimensionDifference(dim1, dim2);
diff2 = DimensionDifference(dim2, dim1);
diff1 = dimensionDifference(dim1, dim2);
diff2 = dimensionDifference(dim2, dim1);
res.insert(res.end(), diff1.begin(), diff1.end());
res.insert(res.end(), diff2.begin(), diff2.end());
return res;
}
static vector<ArrayDimension> ElementsIntersection(const vector<ArrayDimension>& firstElement, const vector<ArrayDimension>& secondElement)
static vector<ArrayDimension> elementsIntersection(const vector<ArrayDimension>& firstElement, const vector<ArrayDimension>& secondElement)
{
if (firstElement.empty() || secondElement.empty())
return {};
@@ -113,13 +113,13 @@ static vector<ArrayDimension> ElementsIntersection(const vector<ArrayDimension>&
size_t dimAmount = firstElement.size();
/* check if there is no intersecction */
for (size_t i = 0; i < dimAmount; i++)
if (FindParticularSolution(firstElement[i], secondElement[i]).empty())
if (findParticularSolution(firstElement[i], secondElement[i]).empty())
return {};
vector<ArrayDimension> result(dimAmount);
for (size_t i = 0; i < dimAmount; i++)
{
ArrayDimension* resPtr = DimensionIntersection(firstElement[i], secondElement[i]);
ArrayDimension* resPtr = dimensionIntersection(firstElement[i], secondElement[i]);
if (resPtr)
result[i] = *resPtr;
else
@@ -129,7 +129,7 @@ static vector<ArrayDimension> ElementsIntersection(const vector<ArrayDimension>&
return result;
}
static vector<vector<ArrayDimension>> ElementsDifference(const vector<ArrayDimension>& firstElement,
static vector<vector<ArrayDimension>> elementsDifference(const vector<ArrayDimension>& firstElement,
const vector<ArrayDimension>& secondElement)
{
if (firstElement.empty())
@@ -137,14 +137,14 @@ static vector<vector<ArrayDimension>> ElementsDifference(const vector<ArrayDimen
if (secondElement.empty())
return { firstElement };
vector<ArrayDimension> intersection = ElementsIntersection(firstElement, secondElement);
vector<ArrayDimension> intersection = elementsIntersection(firstElement, secondElement);
vector<vector<ArrayDimension>> result;
if (intersection.empty())
return { firstElement };
for (int i = 0; i < firstElement.size(); i++)
{
auto dimDiff = DimensionDifference(firstElement[i], secondElement[i]);
auto dimDiff = dimensionDifference(firstElement[i], secondElement[i]);
if (!dimDiff.empty())
{
vector<ArrayDimension> firstCopy = firstElement;
@@ -158,14 +158,14 @@ static vector<vector<ArrayDimension>> ElementsDifference(const vector<ArrayDimen
return result;
}
static void ElementsUnion(const vector<ArrayDimension>& firstElement, const vector<ArrayDimension>& secondElement,
static void elementsUnion(const vector<ArrayDimension>& firstElement, const vector<ArrayDimension>& secondElement,
vector<vector<ArrayDimension>>& lc, vector<vector<ArrayDimension>>& rc,
vector<ArrayDimension>& intersection)
{
/* lc(rc) is a set of ranges, which only exist in first(second) element*/
intersection = ElementsIntersection(firstElement, secondElement);
lc = ElementsDifference(firstElement, intersection);
rc = ElementsDifference(secondElement, intersection);
intersection = elementsIntersection(firstElement, secondElement);
lc = elementsDifference(firstElement, intersection);
rc = elementsDifference(secondElement, intersection);
}
void AccessingSet::FindUncovered(const vector<ArrayDimension>& element, vector<vector<ArrayDimension>>& result) const {
@@ -175,8 +175,8 @@ void AccessingSet::FindUncovered(const vector<ArrayDimension>& element, vector<v
{
for (const auto& tailLoc : result)
{
auto intersection = ElementsIntersection(tailLoc, currentElement);
auto diff = ElementsDifference(tailLoc, intersection);
auto intersection = elementsIntersection(tailLoc, currentElement);
auto diff = elementsDifference(tailLoc, intersection);
if (!diff.empty()) {
newTails.insert(newTails.end(), diff.begin(), diff.end());
}
@@ -197,7 +197,7 @@ void AccessingSet::FindCoveredBy(const vector<ArrayDimension>& element, vector<v
{
for (const auto& currentElement : allElements)
{
auto intersection = ElementsIntersection(element, currentElement);
auto intersection = elementsIntersection(element, currentElement);
if (!intersection.empty())
result.push_back(intersection);
}
@@ -283,7 +283,7 @@ bool operator!=(const AccessingSet& lhs, const AccessingSet& rhs)
return false;
}
bool operator!=(const ArrayAccessingIndexes& lhs, const ArrayAccessingIndexes& rhs)
bool operator!=(const arrayAccessingIndexes& lhs, const arrayAccessingIndexes& rhs)
{
if (lhs.size() != rhs.size())
return true;

View File

@@ -33,8 +33,8 @@ public:
friend bool operator!=(const AccessingSet& lhs, const AccessingSet& rhs);
};
using ArrayAccessingIndexes = std::map<std::string, AccessingSet>;
using arrayAccessingIndexes = std::map<std::string, AccessingSet>;
bool operator!=(const ArrayDimension& lhs, const ArrayDimension& rhs);
bool operator!=(const AccessingSet& lhs, const AccessingSet& rhs);
bool operator!=(const ArrayAccessingIndexes& lhs, const ArrayAccessingIndexes& rhs);
bool operator!=(const arrayAccessingIndexes& lhs, const arrayAccessingIndexes& rhs);

View File

@@ -23,7 +23,7 @@ static bool isParentStmt(SgStatement* stmt, SgStatement* parent)
}
/*returns head block and loop*/
pair<SAPFOR::BasicBlock*, set<SAPFOR::BasicBlock*>> GetBasicBlocksForLoop(const LoopGraph* loop, const vector<SAPFOR::BasicBlock*> blocks)
pair<SAPFOR::BasicBlock*, set<SAPFOR::BasicBlock*>> getBasicBlocksForLoop(const LoopGraph* loop, const vector<SAPFOR::BasicBlock*> blocks)
{
set<SAPFOR::BasicBlock*> block_loop;
SAPFOR::BasicBlock* head_block = nullptr;
@@ -51,15 +51,15 @@ pair<SAPFOR::BasicBlock*, set<SAPFOR::BasicBlock*>> GetBasicBlocksForLoop(const
return { head_block, block_loop };
}
static void BuildLoopIndex(map<SgStatement*, LoopGraph*>& loopForIndex, LoopGraph* loop) {
static void buildLoopIndex(map<SgStatement*, LoopGraph*>& loopForIndex, LoopGraph* loop) {
string index = loop->loopSymbol();
loopForIndex[loop->loop->GetOriginal()] = loop;
for (const auto& childLoop : loop->children)
BuildLoopIndex(loopForIndex, childLoop);
buildLoopIndex(loopForIndex, childLoop);
}
static string FindIndexName(int pos, SAPFOR::BasicBlock* block, map<string, LoopGraph*>& loopForIndex) {
static string findIndexName(int pos, SAPFOR::BasicBlock* block, map<string, LoopGraph*>& loopForIndex) {
set<SAPFOR::Argument*> args = { block->getInstructions()[pos]->getInstruction()->getArg1() };
for (int i = pos - 1; i >= 0; i--)
@@ -93,10 +93,10 @@ static string FindIndexName(int pos, SAPFOR::BasicBlock* block, map<string, Loop
return "";
}
static int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAccessingIndexes& def, ArrayAccessingIndexes& use, Region* region) {
static int getDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, arrayAccessingIndexes& def, arrayAccessingIndexes& use, Region* region) {
auto instructions = block->getInstructions();
map<SgStatement*, LoopGraph*> loopForIndex;
BuildLoopIndex(loopForIndex, loop);
buildLoopIndex(loopForIndex, loop);
for (int i = 0; i < instructions.size(); i++)
{
auto instruction = instructions[i];
@@ -233,7 +233,7 @@ static int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAcces
}
static void RemoveHeaderConnection(SAPFOR::BasicBlock* header, const set<SAPFOR::BasicBlock*>& blockSet, map<SAPFOR::BasicBlock*, Region*>& bbToRegion)
static void removeHeaderConnection(SAPFOR::BasicBlock* header, const set<SAPFOR::BasicBlock*>& blockSet, map<SAPFOR::BasicBlock*, Region*>& bbToRegion)
{
for (SAPFOR::BasicBlock* block : blockSet)
{
@@ -249,10 +249,7 @@ static void RemoveHeaderConnection(SAPFOR::BasicBlock* header, const set<SAPFOR:
}
}
static bool DFS(Region* block,
vector<Region*>& result,
const set<Region*>& cycleBlocks,
map<Region*, int>& color)
static bool DFS(Region* block, vector<Region*>& result, const set<Region*>& cycleBlocks, map<Region*, int>& color)
{
auto it = color.find(block);
if (it != color.end())
@@ -275,7 +272,7 @@ static bool DFS(Region* block,
return true;
}
bool HasCycle(Region* block, const std::set<Region*>& cycleBlocks, std::set<Region*>& visitedBlocks)
bool hasCycle(Region* block, const std::set<Region*>& cycleBlocks, std::set<Region*>& visitedBlocks)
{
return false;
if (visitedBlocks.find(block) != visitedBlocks.end())
@@ -283,13 +280,13 @@ bool HasCycle(Region* block, const std::set<Region*>& cycleBlocks, std::set<Regi
visitedBlocks.insert(block);
for (Region* nextBlock : block->getNextRegions())
{
if (cycleBlocks.find(nextBlock) != cycleBlocks.end() && HasCycle(nextBlock, cycleBlocks, visitedBlocks))
if (cycleBlocks.find(nextBlock) != cycleBlocks.end() && hasCycle(nextBlock, cycleBlocks, visitedBlocks))
return true;
}
return false;
}
bool TopologySort(std::vector<Region*>& basikBlocks, Region* header)
bool topologySort(std::vector<Region*>& basikBlocks, Region* header)
{
set<Region*> cycleBlocks(basikBlocks.begin(), basikBlocks.end());
vector<Region*> result;
@@ -301,7 +298,7 @@ bool TopologySort(std::vector<Region*>& basikBlocks, Region* header)
return true;
}
static void SetConnections(map<SAPFOR::BasicBlock*, Region*>& bbToRegion, const set<SAPFOR::BasicBlock*>& blockSet)
static void setConnections(map<SAPFOR::BasicBlock*, Region*>& bbToRegion, const set<SAPFOR::BasicBlock*>& blockSet)
{
for (SAPFOR::BasicBlock* block : blockSet)
{
@@ -315,11 +312,11 @@ static void SetConnections(map<SAPFOR::BasicBlock*, Region*>& bbToRegion, const
}
}
static Region* CreateSubRegion(LoopGraph* loop, const vector<SAPFOR::BasicBlock*>& Blocks, map<SAPFOR::BasicBlock*, Region*>& bbToRegion)
static Region* createSubRegion(LoopGraph* loop, const vector<SAPFOR::BasicBlock*>& Blocks, map<SAPFOR::BasicBlock*, Region*>& bbToRegion)
{
Region* region = new Region;
auto [header, blockSet] = GetBasicBlocksForLoop(loop, Blocks);
RemoveHeaderConnection(header, blockSet, bbToRegion);
auto [header, blockSet] = getBasicBlocksForLoop(loop, Blocks);
removeHeaderConnection(header, blockSet, bbToRegion);
if (bbToRegion.find(header) != bbToRegion.end())
region->setHeader(bbToRegion.at(header));
else
@@ -336,34 +333,34 @@ static Region* CreateSubRegion(LoopGraph* loop, const vector<SAPFOR::BasicBlock*
{
if (!childLoop->isFor())
continue;
region->addSubRegions(CreateSubRegion(childLoop, Blocks, bbToRegion));
region->addSubRegions(createSubRegion(childLoop, Blocks, bbToRegion));
}
if (!TopologySort(region->getBasickBlocks(), region->getHeader()))
if (!topologySort(region->getBasickBlocks(), region->getHeader()))
throw std::runtime_error("Unnoticed cycle");
return region;
}
Region::Region(LoopGraph* loop, const vector<SAPFOR::BasicBlock*>& Blocks)
{
auto [header, blockSet] = GetBasicBlocksForLoop(loop, Blocks);
auto [header, blockSet] = getBasicBlocksForLoop(loop, Blocks);
map<SAPFOR::BasicBlock*, Region*> bbToRegion;
for (auto poiner : blockSet)
{
bbToRegion[poiner] = new Region(*poiner);
this->basickBlocks.push_back(bbToRegion[poiner]);
GetDefUseArray(poiner, loop, bbToRegion[poiner]->array_def, bbToRegion[poiner]->array_use, bbToRegion[poiner]);
getDefUseArray(poiner, loop, bbToRegion[poiner]->array_def, bbToRegion[poiner]->array_use, bbToRegion[poiner]);
}
this->header = bbToRegion[header];
SetConnections(bbToRegion, blockSet);
RemoveHeaderConnection(header, blockSet, bbToRegion);
setConnections(bbToRegion, blockSet);
removeHeaderConnection(header, blockSet, bbToRegion);
//create subRegions
for (LoopGraph* childLoop : loop->children)
{
if (!childLoop->isFor())
continue;
subRegions.insert(CreateSubRegion(childLoop, Blocks, bbToRegion));
subRegions.insert(createSubRegion(childLoop, Blocks, bbToRegion));
}
if (!TopologySort(basickBlocks, this->header))
if (!topologySort(basickBlocks, this->header))
throw std::runtime_error("Unnoticed cycle");
}

View File

@@ -10,7 +10,7 @@
struct RegionInstruction
{
ArrayAccessingIndexes def, use, in, out;
arrayAccessingIndexes def, use, in, out;
};
class Region : public SAPFOR::BasicBlock {
@@ -67,7 +67,7 @@ public:
std::vector<RegionInstruction> instructions;
ArrayAccessingIndexes array_def, array_use, array_out, array_in, array_priv;
arrayAccessingIndexes array_def, array_use, array_out, array_in, array_priv;
private:
std::vector<Region*> basickBlocks;
@@ -79,6 +79,6 @@ private:
Region* header;
};
bool HasCycle(Region* block, const std::set<Region*>& cycleBlocks, std::set<Region*>& visitedBlocks);
bool hasCycle(Region* block, const std::set<Region*>& cycleBlocks, std::set<Region*>& visitedBlocks);
bool TopologySort(std::vector<Region*>& basikBlocks, Region* header);
bool topologySort(std::vector<Region*>& basikBlocks, Region* header);

View File

@@ -1905,7 +1905,7 @@ 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_ANALYSIS)
findPrivateArrays(loopGraph, fullIR, insertedPrivates);
findPrivateArrays(loopGraph, fullIR, insertedPrivates, SPF_messages, declaredArrays);
else if (curr_regime == MERGE_REGIONS)
mergeRegions(parallelRegions, allFuncInfo);
else if (curr_regime == ARRAY_PROPAGATION)