fixes
This commit is contained in:
@@ -287,7 +287,6 @@ void ArrayConstantPropagation(SgProject& project)
|
|||||||
|
|
||||||
if (!file)
|
if (!file)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const int funcNum = file->numberOfFunctions();
|
const int funcNum = file->numberOfFunctions();
|
||||||
for (int i = 0; i < funcNum; ++i)
|
for (int i = 0; i < funcNum; ++i)
|
||||||
{
|
{
|
||||||
@@ -327,7 +326,10 @@ void ArrayConstantPropagation(SgProject& project)
|
|||||||
if (scope)
|
if (scope)
|
||||||
funcStarts.insert(scope);
|
funcStarts.insert(scope);
|
||||||
}
|
}
|
||||||
for (const auto& st: funcStarts)
|
for (const auto& st : funcStarts)
|
||||||
|
{
|
||||||
|
SgFile::switchToFile(st->fileName());
|
||||||
InsertCommonAndDeclsForFunction(st, variablesToAdd);
|
InsertCommonAndDeclsForFunction(st, variablesToAdd);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -7,16 +7,20 @@
|
|||||||
#include <numeric>
|
#include <numeric>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "CFGraph/CFGraph.h"
|
||||||
|
#include "Distribution/Array.h"
|
||||||
|
#include "graph_loops.h"
|
||||||
#include "private_arrays_search.h"
|
#include "private_arrays_search.h"
|
||||||
#include "range_structures.h"
|
#include "range_structures.h"
|
||||||
#include "region.h"
|
#include "region.h"
|
||||||
#include "SgUtils.h"
|
#include "SgUtils.h"
|
||||||
#include "graph_loops.h"
|
|
||||||
#include "CFGraph/CFGraph.h"
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "Utils/AstWrapper.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
extern std::map<std::tuple<int, std::string, std::string>, std::pair<DIST::Array*, DIST::ArrayAccessInfo*>> declaredArrays;
|
||||||
|
|
||||||
static unordered_set<Region*> collapsed;
|
static unordered_set<Region*> collapsed;
|
||||||
|
|
||||||
static void RemoveEmptyPoints(ArrayAccessingIndexes& container)
|
static void RemoveEmptyPoints(ArrayAccessingIndexes& container)
|
||||||
@@ -308,29 +312,63 @@ static bool getArrayDeclaredDimensions(SgArrayRefExp* arrayRef, vector<uint64_t>
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static DIST::Array* getDistArrayBySymbol(SgSymbol* arrSym)
|
||||||
|
{
|
||||||
|
if (!arrSym)
|
||||||
|
return nullptr;
|
||||||
|
for (auto& [key, val] : declaredArrays)
|
||||||
|
{
|
||||||
|
DIST::Array* distArr = val.first;
|
||||||
|
if (!distArr)
|
||||||
|
continue;
|
||||||
|
Symbol* declSym = distArr->GetDeclSymbol();
|
||||||
|
if (!declSym)
|
||||||
|
continue;
|
||||||
|
SgSymbol* sgDecl = declSym->GetOriginal();
|
||||||
|
if (sgDecl && isEqSymbols(sgDecl, arrSym))
|
||||||
|
return distArr;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
static bool CheckDimensionLength(const AccessingSet& array)
|
static bool CheckDimensionLength(const AccessingSet& array)
|
||||||
{
|
{
|
||||||
if (array.GetElements().empty())
|
if (array.GetElements().empty())
|
||||||
return false;
|
return false;
|
||||||
size_t dimCount = array.GetElements()[0].size();
|
size_t dimCount = array.GetElements()[0].size();
|
||||||
SgArrayRefExp* arrayRef = array.GetElements()[0][0].array;
|
SgArrayRefExp* arrayRef = array.GetElements()[0][0].array;
|
||||||
if (!arrayRef)
|
if (!arrayRef || !arrayRef->symbol())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
vector<uint64_t> declaredDims;
|
vector<uint64_t> declaredDims;
|
||||||
declaredDims.reserve(dimCount);
|
declaredDims.reserve(dimCount);
|
||||||
if (!getArrayDeclaredDimensions(arrayRef, declaredDims))
|
|
||||||
return false;
|
DIST::Array* distArr = getDistArrayBySymbol(arrayRef->symbol());
|
||||||
|
if (distArr && distArr->GetDimSize() == (int)dimCount)
|
||||||
|
{
|
||||||
|
const auto& sizes = distArr->GetSizes();
|
||||||
|
bool valid = true;
|
||||||
|
for (size_t i = 0; i < dimCount && valid; ++i)
|
||||||
|
{
|
||||||
|
int lo = sizes[i].first;
|
||||||
|
int hi = sizes[i].second;
|
||||||
|
if (lo > hi)
|
||||||
|
valid = false;
|
||||||
|
else
|
||||||
|
declaredDims.push_back((uint64_t)(hi - lo + 1));
|
||||||
|
}
|
||||||
|
if (valid && declaredDims.size() == dimCount)
|
||||||
|
{
|
||||||
vector<ArrayDimension> testArray(dimCount);
|
vector<ArrayDimension> testArray(dimCount);
|
||||||
for (size_t i = 0; i < dimCount; i++)
|
for (size_t i = 0; i < dimCount; i++)
|
||||||
{
|
|
||||||
testArray[i] = { 1, 1, declaredDims[i], nullptr };
|
testArray[i] = { 1, 1, declaredDims[i], nullptr };
|
||||||
|
return AccessingSet({ testArray }).Diff(array).GetElements().empty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
AccessingSet diff = AccessingSet({ testArray }).Diff(array);
|
|
||||||
|
|
||||||
return diff.GetElements().empty();
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void AddPrivateArraysToLoop(LoopGraph* loop, const ArrayAccessingIndexes& privates, set<SgStatement*>& insertedPrivates)
|
static void AddPrivateArraysToLoop(LoopGraph* loop, const ArrayAccessingIndexes& privates, set<SgStatement*>& insertedPrivates)
|
||||||
{
|
{
|
||||||
SgStatement* spfStat = new SgStatement(SPF_ANALYSIS_DIR);
|
SgStatement* spfStat = new SgStatement(SPF_ANALYSIS_DIR);
|
||||||
@@ -338,6 +376,7 @@ static void AddPrivateArraysToLoop(LoopGraph* loop, const ArrayAccessingIndexes&
|
|||||||
spfStat->setFileName(loop->loop->fileName());
|
spfStat->setFileName(loop->loop->fileName());
|
||||||
SgExpression* toAdd = new SgExpression(EXPR_LIST, new SgExpression(ACC_PRIVATE_OP), NULL, NULL);
|
SgExpression* toAdd = new SgExpression(EXPR_LIST, new SgExpression(ACC_PRIVATE_OP), NULL, NULL);
|
||||||
set<SgSymbol*> arraysToInsert;
|
set<SgSymbol*> arraysToInsert;
|
||||||
|
std::cout << "First bp\n";
|
||||||
for (const auto& [_, accessingSet] : privates)
|
for (const auto& [_, accessingSet] : privates)
|
||||||
{
|
{
|
||||||
if (!CheckDimensionLength(accessingSet))
|
if (!CheckDimensionLength(accessingSet))
|
||||||
@@ -395,7 +434,15 @@ void FindPrivateArrays(map<string, vector<LoopGraph*>>& loopGraph, map<FuncInfo*
|
|||||||
{
|
{
|
||||||
if (funcInfo->fileName == fileName && funcInfo->funcPointer->GetOriginal() == search_func)
|
if (funcInfo->fileName == fileName && funcInfo->funcPointer->GetOriginal() == search_func)
|
||||||
{
|
{
|
||||||
Region* loopRegion = new Region(loop, blocks);
|
Region* loopRegion;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
loopRegion = new Region(loop, blocks);
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (loopRegion->getBasickBlocks().size() <= 1)
|
if (loopRegion->getBasickBlocks().size() <= 1)
|
||||||
{
|
{
|
||||||
delete(loopRegion);
|
delete(loopRegion);
|
||||||
@@ -407,7 +454,6 @@ void FindPrivateArrays(map<string, vector<LoopGraph*>>& loopGraph, map<FuncInfo*
|
|||||||
delete(loopRegion);
|
delete(loopRegion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.find(loop) != result.end() && !result[loop].empty())
|
if (result.find(loop) != result.end() && !result[loop].empty())
|
||||||
AddPrivateArraysToLoop(loop, result[loop], insertedPrivates);
|
AddPrivateArraysToLoop(loop, result[loop], insertedPrivates);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,6 +152,8 @@ static int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAcces
|
|||||||
vector<ArrayDimension> accessPoint(n);
|
vector<ArrayDimension> accessPoint(n);
|
||||||
|
|
||||||
auto* ref = isSgArrayRefExp(instruction->getInstruction()->getExpression());
|
auto* ref = isSgArrayRefExp(instruction->getInstruction()->getExpression());
|
||||||
|
if (!ref)
|
||||||
|
continue;
|
||||||
int fillCount = 0;
|
int fillCount = 0;
|
||||||
|
|
||||||
vector<pair<int, int>> coeffsForDims;
|
vector<pair<int, int>> coeffsForDims;
|
||||||
@@ -269,13 +271,30 @@ static void DFS(Region* block, vector<Region*>& result, unordered_set<Region*> c
|
|||||||
result.push_back(block);
|
result.push_back(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TopologySort(std::vector<Region*>& basikBlocks, Region* header)
|
bool HasCycle(Region* block, const std::unordered_set<Region*>& cycleBlocks, std::unordered_set<Region*>& visitedBlocks)
|
||||||
|
{
|
||||||
|
if (visitedBlocks.find(block) != visitedBlocks.end())
|
||||||
|
return true;
|
||||||
|
visitedBlocks.insert(block);
|
||||||
|
for (Region* nextBlock : block->getNextRegions())
|
||||||
|
{
|
||||||
|
if (cycleBlocks.find(nextBlock) != cycleBlocks.end() && HasCycle(nextBlock, cycleBlocks, visitedBlocks))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TopologySort(std::vector<Region*>& basikBlocks, Region* header)
|
||||||
{
|
{
|
||||||
vector<Region*> result;
|
|
||||||
unordered_set<Region*> cycleBlocks(basikBlocks.begin(), basikBlocks.end());
|
unordered_set<Region*> cycleBlocks(basikBlocks.begin(), basikBlocks.end());
|
||||||
|
unordered_set<Region*> visitedBlocks;
|
||||||
|
if (HasCycle(header, cycleBlocks, visitedBlocks))
|
||||||
|
return false;
|
||||||
|
vector<Region*> result;
|
||||||
DFS(header, result, cycleBlocks);
|
DFS(header, result, cycleBlocks);
|
||||||
reverse(result.begin(), result.end());
|
reverse(result.begin(), result.end());
|
||||||
basikBlocks = result;
|
basikBlocks = move(result);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SetConnections(unordered_map<SAPFOR::BasicBlock*, Region*>& bbToRegion, const unordered_set<SAPFOR::BasicBlock*>& blockSet)
|
static void SetConnections(unordered_map<SAPFOR::BasicBlock*, Region*>& bbToRegion, const unordered_set<SAPFOR::BasicBlock*>& blockSet)
|
||||||
@@ -315,7 +334,8 @@ static Region* CreateSubRegion(LoopGraph* loop, const vector<SAPFOR::BasicBlock*
|
|||||||
continue;
|
continue;
|
||||||
region->addSubRegions(CreateSubRegion(childLoop, Blocks, bbToRegion));
|
region->addSubRegions(CreateSubRegion(childLoop, Blocks, bbToRegion));
|
||||||
}
|
}
|
||||||
TopologySort(region->getBasickBlocks(), region->getHeader());
|
if (!TopologySort(region->getBasickBlocks(), region->getHeader()))
|
||||||
|
throw std::runtime_error("Unnoticed cycle");
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,5 +360,6 @@ Region::Region(LoopGraph* loop, const vector<SAPFOR::BasicBlock*>& Blocks)
|
|||||||
continue;
|
continue;
|
||||||
subRegions.insert(CreateSubRegion(childLoop, Blocks, bbToRegion));
|
subRegions.insert(CreateSubRegion(childLoop, Blocks, bbToRegion));
|
||||||
}
|
}
|
||||||
TopologySort(basickBlocks, this->header);
|
if (!TopologySort(basickBlocks, this->header))
|
||||||
|
throw std::runtime_error("Unnoticed cycle");
|
||||||
}
|
}
|
||||||
@@ -79,4 +79,6 @@ private:
|
|||||||
Region* header;
|
Region* header;
|
||||||
};
|
};
|
||||||
|
|
||||||
void TopologySort(std::vector<Region*>& basikBlocks, Region* header);
|
bool HasCycle(Region* block, const std::unordered_set<Region*>& cycleBlocks, std::unordered_set<Region*>& visitedBlocks);
|
||||||
|
|
||||||
|
bool TopologySort(std::vector<Region*>& basikBlocks, Region* header);
|
||||||
@@ -658,7 +658,7 @@ string removeIncludeStatsAndUnparse(SgFile *file, const char *fileName, const ch
|
|||||||
|
|
||||||
if (wasDeleted)
|
if (wasDeleted)
|
||||||
{
|
{
|
||||||
if (str.size() || str.back() != '\n')
|
if (str.size() && str.back() != '\n')
|
||||||
str += '\n';
|
str += '\n';
|
||||||
st->setComments(str.c_str());
|
st->setComments(str.c_str());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user