Add new operations
This commit is contained in:
@@ -42,7 +42,7 @@ static bool isParentStmt(SgStatement* stmt, SgStatement* parent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*returns head block and loop*/
|
/*returns head block and loop*/
|
||||||
pair<SAPFOR::BasicBlock*, unordered_set<SAPFOR::BasicBlock*>> GetBasicBlocksForLoop(LoopGraph* loop, vector<SAPFOR::BasicBlock*> blocks)
|
static pair<SAPFOR::BasicBlock*, unordered_set<SAPFOR::BasicBlock*>> GetBasicBlocksForLoop(LoopGraph* loop, vector<SAPFOR::BasicBlock*> blocks)
|
||||||
{
|
{
|
||||||
unordered_set<SAPFOR::BasicBlock*> block_loop;
|
unordered_set<SAPFOR::BasicBlock*> block_loop;
|
||||||
SAPFOR::BasicBlock* head_block = nullptr;
|
SAPFOR::BasicBlock* head_block = nullptr;
|
||||||
@@ -72,7 +72,7 @@ pair<SAPFOR::BasicBlock*, unordered_set<SAPFOR::BasicBlock*>> GetBasicBlocksForL
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BuildLoopIndex(map<string, LoopGraph*>& loopForIndex, LoopGraph* loop) {
|
static void BuildLoopIndex(map<string, LoopGraph*>& loopForIndex, LoopGraph* loop) {
|
||||||
string index = loop->loopSymbol;
|
string index = loop->loopSymbol;
|
||||||
loopForIndex[index] = loop;
|
loopForIndex[index] = loop;
|
||||||
for (const auto& childLoop : loop->children) {
|
for (const auto& childLoop : loop->children) {
|
||||||
@@ -80,7 +80,7 @@ void BuildLoopIndex(map<string, LoopGraph*>& loopForIndex, LoopGraph* loop) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string FindIndexName(int pos, SAPFOR::BasicBlock* block, map<string, LoopGraph*>& loopForIndex) {
|
static string FindIndexName(int pos, SAPFOR::BasicBlock* block, map<string, LoopGraph*>& loopForIndex) {
|
||||||
unordered_set<SAPFOR::Argument*> args = {block->getInstructions()[pos]->getInstruction()->getArg1()};
|
unordered_set<SAPFOR::Argument*> args = {block->getInstructions()[pos]->getInstruction()->getArg1()};
|
||||||
|
|
||||||
for (int i = pos-1; i >= 0; i--) {
|
for (int i = pos-1; i >= 0; i--) {
|
||||||
@@ -111,7 +111,7 @@ string FindIndexName(int pos, SAPFOR::BasicBlock* block, map<string, LoopGraph*>
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAccessingIndexes& def, ArrayAccessingIndexes& use) {
|
static int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAccessingIndexes& def, ArrayAccessingIndexes& use) {
|
||||||
auto instructions = block->getInstructions();
|
auto instructions = block->getInstructions();
|
||||||
map<string, LoopGraph*> loopForIndex;
|
map<string, LoopGraph*> loopForIndex;
|
||||||
BuildLoopIndex(loopForIndex, loop);
|
BuildLoopIndex(loopForIndex, loop);
|
||||||
@@ -232,7 +232,7 @@ int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAccessingInd
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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++)
|
for (uint64_t i = 0; i < dim1.tripCount; i++)
|
||||||
{
|
{
|
||||||
@@ -248,8 +248,9 @@ vector<uint64_t> FindParticularSolution(const ArrayDimension& dim1, const ArrayD
|
|||||||
}
|
}
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
/* dim1 /\ dim2 */
|
/* dim1 /\ dim2 */
|
||||||
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())
|
if (partSolution.empty())
|
||||||
@@ -279,7 +280,7 @@ ArrayDimension* DimensionIntersection(const ArrayDimension& dim1, const ArrayDim
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* dim1 / dim2 */
|
/* dim1 / dim2 */
|
||||||
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)
|
if (!intersection)
|
||||||
@@ -321,7 +322,7 @@ vector<ArrayDimension> DimensionDifference(const ArrayDimension& dim1, const Arr
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
vector<ArrayDimension> DimensionUnion(const ArrayDimension& dim1, const ArrayDimension& dim2)
|
static vector<ArrayDimension> DimensionUnion(const ArrayDimension& dim1, const ArrayDimension& dim2)
|
||||||
{
|
{
|
||||||
vector<ArrayDimension> res;
|
vector<ArrayDimension> res;
|
||||||
ArrayDimension* inter = DimensionIntersection(dim1, dim2);
|
ArrayDimension* inter = DimensionIntersection(dim1, dim2);
|
||||||
@@ -339,6 +340,151 @@ vector<ArrayDimension> DimensionUnion(const ArrayDimension& dim1, const ArrayDim
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static vector<ArrayDimension> ElementsIntersection(const vector<ArrayDimension>& firstElement, const vector<ArrayDimension>& secondElement)
|
||||||
|
{
|
||||||
|
if(firstElement.empty() || secondElement.empty()) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
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()){
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
vector<ArrayDimension> result(dimAmount);
|
||||||
|
for(size_t i = 0; i < dimAmount; i++)
|
||||||
|
{
|
||||||
|
ArrayDimension* resPtr = DimensionIntersection(firstElement[i], secondElement[i]);
|
||||||
|
if(resPtr)
|
||||||
|
{
|
||||||
|
result[i] = *resPtr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static vector<vector<ArrayDimension>> ElementsDifference(const vector<ArrayDimension>& firstElement,
|
||||||
|
const vector<ArrayDimension>& secondElement)
|
||||||
|
{
|
||||||
|
if(firstElement.empty() || secondElement.empty()) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
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]);
|
||||||
|
if(!dimDiff.empty())
|
||||||
|
{
|
||||||
|
vector<ArrayDimension> firstCopy = firstElement;
|
||||||
|
for(const auto range: dimDiff)
|
||||||
|
{
|
||||||
|
firstCopy[i] = range;
|
||||||
|
result.push_back(firstCopy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AccessingSet::FindUncovered(const vector<ArrayDimension>& element, vector<vector<ArrayDimension>>& result) {
|
||||||
|
vector<vector<ArrayDimension>> result, newTails;
|
||||||
|
result.push_back(element);
|
||||||
|
for(const auto& currentElement: allElements)
|
||||||
|
{
|
||||||
|
for(const auto& tailLoc: result)
|
||||||
|
{
|
||||||
|
auto intersection = ElementsIntersection(tailLoc, currentElement);
|
||||||
|
auto diff = ElementsDifference(tailLoc, intersection);
|
||||||
|
if(!diff.empty()) {
|
||||||
|
newTails.insert(newTails.end(), diff.begin(), diff.end());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result = move(newTails);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AccessingSet::ContainsElement(const vector<ArrayDimension>& element)
|
||||||
|
{
|
||||||
|
vector<vector<ArrayDimension>> tails;
|
||||||
|
FindUncovered(element, tails);
|
||||||
|
return !tails.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AccessingSet::FindCoveredBy(const vector<ArrayDimension>& element, vector<vector<ArrayDimension>>& result)
|
||||||
|
{
|
||||||
|
for(const auto& currentElement: allElements)
|
||||||
|
{
|
||||||
|
for(const auto& tailLoc: tails)
|
||||||
|
{
|
||||||
|
auto intersection = ElementsIntersection(tailLoc, currentElement);
|
||||||
|
if(!intersection.empty()) {
|
||||||
|
result.push_back(intersection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<vector<ArrayDimension>>> AccessingSet::GetElements()
|
||||||
|
{
|
||||||
|
return AllElements;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AccessingSet::Insert(const vector<ArrayDimension>& element)
|
||||||
|
{
|
||||||
|
vector<vector<ArrayDimension>> tails;
|
||||||
|
FindUncovered(element, tails);
|
||||||
|
AllElements.insert(AllElements.end(), tails.begin(), tails.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
void AccessingSet::Union(const AccessingSet& source) {
|
||||||
|
for(const auto element: source.GetElements()) {
|
||||||
|
Insert(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<vector<ArrayDimension>> AccessingSet::Intersect(const AccessingSet& secondSet)
|
||||||
|
{
|
||||||
|
vector<vector<ArrayDimension>> result;
|
||||||
|
for(const auto& element: AllElements)
|
||||||
|
{
|
||||||
|
if(ContainsElement(secondSet), element)
|
||||||
|
{
|
||||||
|
result.push_back(element)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vector<vector<ArrayDimension> coveredBy;
|
||||||
|
FindCoveredBy(secondSet, element, coveredBy);
|
||||||
|
if(!coveredBy.empty())
|
||||||
|
{
|
||||||
|
result.insert(result.end(), coveredBy.begin(), coveredBy.end());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void FindPrivateArrays(map<string, vector<LoopGraph*>> &loopGraph, map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& FullIR)
|
void FindPrivateArrays(map<string, vector<LoopGraph*>> &loopGraph, map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& FullIR)
|
||||||
{
|
{
|
||||||
for (const auto& curr_graph_pair: loopGraph)
|
for (const auto& curr_graph_pair: loopGraph)
|
||||||
|
|||||||
@@ -3,13 +3,32 @@
|
|||||||
#include "../GraphLoop/graph_loops.h"
|
#include "../GraphLoop/graph_loops.h"
|
||||||
#include "../CFGraph/CFGraph.h"
|
#include "../CFGraph/CFGraph.h"
|
||||||
|
|
||||||
|
using std::vector;
|
||||||
|
using std::map;
|
||||||
|
using std::string;
|
||||||
|
using std::set;
|
||||||
|
|
||||||
struct ArrayDimension
|
struct ArrayDimension
|
||||||
{
|
{
|
||||||
uint64_t start, step, tripCount;
|
uint64_t start, step, tripCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::map<std::string, std::vector<std::vector<ArrayDimension>>> ArrayAccessingIndexes;
|
typedef map<string, AccessingSet> ArrayAccessingIndexes;
|
||||||
|
|
||||||
void FindPrivateArrays(std::map<std::string, std::vector<LoopGraph*>>& loopGraph, std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& FullIR);
|
class AccessingSet {
|
||||||
void GetDimensionInfo(LoopGraph* loop, std::map<DIST::Array*, std::vector<std::vector<ArrayDimension>>>& loopDimensionsInfo, int level);
|
prinvate:
|
||||||
std::set<SAPFOR::BasicBlock> GetBasicBlocksForLoop(LoopGraph* loop, std::vector<SAPFOR::BasicBlock>);
|
vector<vector<ArrayDimension>>> AllElements;
|
||||||
|
bool ContainsElement(const vector<ArrayDimension>& element);
|
||||||
|
void FindCoveredBy(const vector<ArrayDimension>& element, vector<vector<ArrayDimension>>& result);
|
||||||
|
void FindUncovered(const vector<ArrayDimension>& element, vector<vector<ArrayDimension>>& result);
|
||||||
|
public:
|
||||||
|
AccessingSet(vector<vector<ArrayDimension>>> input): AllElements(input) {};
|
||||||
|
vector<vector<ArrayDimension>>> GetElements();
|
||||||
|
void Insert(const vector<ArrayDimension>& element);
|
||||||
|
void Union(const AccessingSet& source);
|
||||||
|
vector<vector<ArrayDimension>> Intersect(const AccessingSet& secondSet);
|
||||||
|
};
|
||||||
|
|
||||||
|
void FindPrivateArrays(map<string, vector<LoopGraph*>>& loopGraph, map<FuncInfo*, vector<SAPFOR::BasicBlock*>>& FullIR);
|
||||||
|
void GetDimensionInfo(LoopGraph* loop, map<DIST::Array*, vector<vector<ArrayDimension>>>& loopDimensionsInfo, int level);
|
||||||
|
set<SAPFOR::BasicBlock> GetBasicBlocksForLoop(LoopGraph* loop, vector<SAPFOR::BasicBlock>);
|
||||||
|
|||||||
Reference in New Issue
Block a user