Compare commits
3 Commits
40cfd83de5
...
a113463b64
| Author | SHA1 | Date | |
|---|---|---|---|
| a113463b64 | |||
|
|
3de06d9261 | ||
| 678c2cf351 |
@@ -163,6 +163,10 @@ set(PARALLEL_REG src/ParallelizationRegions/ParRegions.cpp
|
|||||||
src/ParallelizationRegions/resolve_par_reg_conflicts.cpp
|
src/ParallelizationRegions/resolve_par_reg_conflicts.cpp
|
||||||
src/ParallelizationRegions/resolve_par_reg_conflicts.h)
|
src/ParallelizationRegions/resolve_par_reg_conflicts.h)
|
||||||
|
|
||||||
|
set(ARRAY_PROP src/ArrayConstantPropagation/propagation.cpp
|
||||||
|
src/ArrayConstantPropagation/propagation.h
|
||||||
|
)
|
||||||
|
|
||||||
set(TR_DEAD_CODE src/Transformations/DeadCodeRemoving/dead_code.cpp
|
set(TR_DEAD_CODE src/Transformations/DeadCodeRemoving/dead_code.cpp
|
||||||
src/Transformations/DeadCodeRemoving/dead_code.h)
|
src/Transformations/DeadCodeRemoving/dead_code.h)
|
||||||
set(TR_CP src/Transformations/CheckPoints/checkpoints.cpp
|
set(TR_CP src/Transformations/CheckPoints/checkpoints.cpp
|
||||||
@@ -420,6 +424,7 @@ set(SOURCE_EXE
|
|||||||
${TRANSFORMS}
|
${TRANSFORMS}
|
||||||
${PARALLEL_REG}
|
${PARALLEL_REG}
|
||||||
${PRIV}
|
${PRIV}
|
||||||
|
${ARRAY_PROP}
|
||||||
${FDVM}
|
${FDVM}
|
||||||
${OMEGA}
|
${OMEGA}
|
||||||
${UTILS}
|
${UTILS}
|
||||||
@@ -471,6 +476,7 @@ source_group (GraphLoop FILES ${GR_LOOP})
|
|||||||
source_group (LoopAnalyzer FILES ${LOOP_ANALYZER})
|
source_group (LoopAnalyzer FILES ${LOOP_ANALYZER})
|
||||||
source_group (ParallelizationRegions FILES ${PARALLEL_REG})
|
source_group (ParallelizationRegions FILES ${PARALLEL_REG})
|
||||||
source_group (PrivateAnalyzer FILES ${PRIV})
|
source_group (PrivateAnalyzer FILES ${PRIV})
|
||||||
|
source_group (ArrayConstantPropagation FILES ${ARRAY_PROP})
|
||||||
source_group (FDVM_Compiler FILES ${FDVM})
|
source_group (FDVM_Compiler FILES ${FDVM})
|
||||||
source_group (SageExtension FILES ${OMEGA})
|
source_group (SageExtension FILES ${OMEGA})
|
||||||
source_group (Utils FILES ${UTILS})
|
source_group (Utils FILES ${UTILS})
|
||||||
|
|||||||
192
src/ArrayConstantPropagation/propagation.cpp
Normal file
192
src/ArrayConstantPropagation/propagation.cpp
Normal file
@@ -0,0 +1,192 @@
|
|||||||
|
#include "propagation.h"
|
||||||
|
|
||||||
|
#include "../Utils/SgUtils.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <unordered_set>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
static SgStatement* declPlace = NULL;
|
||||||
|
|
||||||
|
static bool CheckConstIndexes(SgExpression* exp)
|
||||||
|
{
|
||||||
|
if (!exp)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
SgExpression* lhs = exp->lhs();
|
||||||
|
SgExpression* rhs = exp->rhs();
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (lhs->variant() != INT_VAL)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (rhs)
|
||||||
|
{
|
||||||
|
lhs = rhs->lhs();
|
||||||
|
rhs = rhs->rhs();
|
||||||
|
}
|
||||||
|
} while (rhs);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SgExpression* CreateVar(int& variableNumber, SgType* type)
|
||||||
|
{
|
||||||
|
string varName = "__tmp_prop_var";
|
||||||
|
string name = varName + std::to_string(variableNumber) + "__";
|
||||||
|
variableNumber++;
|
||||||
|
|
||||||
|
SgSymbol* varSymbol = new SgSymbol(VARIABLE_NAME, name.c_str(), *type, *declPlace->controlParent());
|
||||||
|
|
||||||
|
SgVarDeclStmt* decl = varSymbol->makeVarDeclStmt();
|
||||||
|
decl->setVariant(VAR_DECL);
|
||||||
|
SgStatement* insertPoint = declPlace;
|
||||||
|
SgStatement* scope = declPlace->controlParent();
|
||||||
|
decl->setFileName(insertPoint->fileName());
|
||||||
|
decl->setFileId(insertPoint->getFileId());
|
||||||
|
decl->setProject(insertPoint->getProject());
|
||||||
|
decl->setlineNumber(getNextNegativeLineNumber());
|
||||||
|
|
||||||
|
insertPoint->insertStmtBefore(*decl, *scope);
|
||||||
|
|
||||||
|
return new SgExpression(VAR_REF, NULL, NULL, varSymbol, type->copyPtr());
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TransformRightPart(SgStatement* st, SgExpression* exp, unordered_map<string, SgExpression*>& arrayToVariable, int& variableNumber)
|
||||||
|
{
|
||||||
|
if (!exp)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<SgExpression*> subnodes = { exp->lhs(), exp->rhs() };
|
||||||
|
|
||||||
|
string expUnparsed;
|
||||||
|
SgExpression* toAdd = NULL;
|
||||||
|
if (exp->variant() == ARRAY_REF && CheckConstIndexes(exp->lhs()))
|
||||||
|
{
|
||||||
|
cout << st->unparse() << endl;
|
||||||
|
if (arrayToVariable.find(expUnparsed) == arrayToVariable.end() && exp->symbol()->type()->baseType())
|
||||||
|
{
|
||||||
|
arrayToVariable[expUnparsed] = CreateVar(variableNumber, exp->symbol()->type()->baseType());
|
||||||
|
}
|
||||||
|
st->setExpression(1, arrayToVariable[expUnparsed]->copyPtr());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 2; i++)
|
||||||
|
{
|
||||||
|
if (subnodes[i] && subnodes[i]->variant() == ARRAY_REF && subnodes[i]->symbol()->type()->baseType() && CheckConstIndexes(subnodes[i]->lhs()))
|
||||||
|
{
|
||||||
|
expUnparsed = subnodes[i]->unparse();
|
||||||
|
if (arrayToVariable.find(expUnparsed) == arrayToVariable.end())
|
||||||
|
{
|
||||||
|
arrayToVariable[expUnparsed] = CreateVar(variableNumber, subnodes[i]->symbol()->type()->baseType());;
|
||||||
|
}
|
||||||
|
toAdd = arrayToVariable[expUnparsed]->copyPtr();
|
||||||
|
if (toAdd)
|
||||||
|
{
|
||||||
|
if (i == 0)
|
||||||
|
{
|
||||||
|
exp->setLhs(toAdd);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
exp->setRhs(toAdd);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TransformRightPart(st, subnodes[i], arrayToVariable, variableNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TransformLeftPart(SgStatement* st, SgExpression* exp, unordered_map<string, SgExpression*>& arrayToVariable, int& variableNumber)
|
||||||
|
{
|
||||||
|
if (exp->symbol()->type()->variant() == T_STRING)
|
||||||
|
return;
|
||||||
|
string expUnparsed = exp->unparse();
|
||||||
|
if (arrayToVariable.find(expUnparsed) == arrayToVariable.end() && exp->symbol()->type()->baseType())
|
||||||
|
{
|
||||||
|
arrayToVariable[expUnparsed] = CreateVar(variableNumber, exp->symbol()->type());
|
||||||
|
}
|
||||||
|
SgStatement* newStatement = new SgStatement(ASSIGN_STAT, NULL, NULL, arrayToVariable[expUnparsed]->copyPtr(), st->expr(1)->copyPtr(), NULL);
|
||||||
|
|
||||||
|
newStatement->setFileId(st->getFileId());
|
||||||
|
newStatement->setProject(st->getProject());
|
||||||
|
|
||||||
|
newStatement->setlineNumber(getNextNegativeLineNumber());
|
||||||
|
newStatement->setLocalLineNumber(st->lineNumber());
|
||||||
|
st->insertStmtBefore(*newStatement, *st->controlParent());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ArrayConstantPropagation(SgProject& project)
|
||||||
|
{
|
||||||
|
unordered_map<string, SgExpression*> arrayToVariable;
|
||||||
|
int variableNumber = 0;
|
||||||
|
for (int i = 0; i < project.numberOfFiles(); i++)
|
||||||
|
{
|
||||||
|
SgFile* file = &(project.file(i));
|
||||||
|
|
||||||
|
if (!file)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const int funcNum = file->numberOfFunctions();
|
||||||
|
for (int i = 0; i < funcNum; ++i)
|
||||||
|
{
|
||||||
|
SgStatement* st = file->functions(i);
|
||||||
|
declPlace = st->lexNext();
|
||||||
|
SgStatement* lastNode = st->lastNodeOfStmt();
|
||||||
|
|
||||||
|
for (; st != lastNode; st = st->lexNext())
|
||||||
|
{
|
||||||
|
cout << st->unparse() << endl;
|
||||||
|
if (st->variant() == ASSIGN_STAT)
|
||||||
|
{
|
||||||
|
if (st->expr(1))
|
||||||
|
{
|
||||||
|
TransformRightPart(st, st->expr(1), arrayToVariable, variableNumber);
|
||||||
|
}
|
||||||
|
if (st->expr(0) && st->expr(0)->variant() == ARRAY_REF && CheckConstIndexes(st->expr(0)->lhs()))
|
||||||
|
{
|
||||||
|
TransformLeftPart(st, st->expr(0), arrayToVariable, variableNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (st->variant() == FOR_NODE)
|
||||||
|
{
|
||||||
|
SgExpression* lowerBound = st->expr(0)->lhs();
|
||||||
|
SgExpression* upperBound = st->expr(0)->rhs();
|
||||||
|
string lowerBoundUnparsed = lowerBound->unparse(), upperBoundUnparsed = upperBound->unparse();
|
||||||
|
if (upperBound->variant() == ARRAY_REF && upperBound->symbol()->type()->baseType() && CheckConstIndexes(upperBound->lhs()))
|
||||||
|
{
|
||||||
|
if (arrayToVariable.find(upperBoundUnparsed) == arrayToVariable.end())
|
||||||
|
{
|
||||||
|
arrayToVariable[upperBoundUnparsed] = CreateVar(variableNumber, upperBound->symbol()->type()->baseType());
|
||||||
|
}
|
||||||
|
st->expr(0)->setRhs(arrayToVariable[upperBoundUnparsed]->copyPtr());
|
||||||
|
}
|
||||||
|
if (lowerBound->variant() == ARRAY_REF && lowerBound->symbol()->type()->baseType() && CheckConstIndexes(lowerBound->lhs()))
|
||||||
|
{
|
||||||
|
if (arrayToVariable.find(lowerBoundUnparsed) == arrayToVariable.end())
|
||||||
|
{
|
||||||
|
arrayToVariable[lowerBoundUnparsed] = CreateVar(variableNumber, lowerBound->symbol()->type()->baseType());
|
||||||
|
}
|
||||||
|
st->expr(0)->setLhs(arrayToVariable[lowerBoundUnparsed]->copyPtr());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*st = file->functions(i);
|
||||||
|
for (; st != lastNode; st = st->lexNext())
|
||||||
|
{
|
||||||
|
cout << st->unparse() << endl;
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
//FILE* unp = fopen(file->filename(), "w");
|
||||||
|
//file->unparse(unp);
|
||||||
|
}
|
||||||
|
}
|
||||||
4
src/ArrayConstantPropagation/propagation.h
Normal file
4
src/ArrayConstantPropagation/propagation.h
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../Utils/SgUtils.h"
|
||||||
|
|
||||||
|
void ArrayConstantPropagation(SgProject& project);
|
||||||
@@ -12,9 +12,39 @@
|
|||||||
#include "SgUtils.h"
|
#include "SgUtils.h"
|
||||||
#include "graph_loops.h"
|
#include "graph_loops.h"
|
||||||
#include "CFGraph/CFGraph.h"
|
#include "CFGraph/CFGraph.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
static void RemoveEmptyPoints(ArrayAccessingIndexes& container)
|
||||||
|
{
|
||||||
|
ArrayAccessingIndexes resultContainer;
|
||||||
|
unordered_set<string> toRemove;
|
||||||
|
for (auto& [arrayName, accessingSet] : container)
|
||||||
|
{
|
||||||
|
vector<vector<ArrayDimension>> points;
|
||||||
|
for (auto& arrayPoint : accessingSet.GetElements())
|
||||||
|
{
|
||||||
|
if (!arrayPoint.empty())
|
||||||
|
points.push_back(arrayPoint);
|
||||||
|
}
|
||||||
|
if (points.size() < accessingSet.GetElements().size() && !points.empty())
|
||||||
|
resultContainer[arrayName] = points;
|
||||||
|
|
||||||
|
if (points.empty())
|
||||||
|
toRemove.insert(arrayName);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const string& name : toRemove)
|
||||||
|
{
|
||||||
|
container.erase(name);
|
||||||
|
}
|
||||||
|
for (auto& [arrayName, accessingSet] : resultContainer)
|
||||||
|
{
|
||||||
|
container[arrayName] = accessingSet;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void Collapse(Region* region)
|
static void Collapse(Region* region)
|
||||||
{
|
{
|
||||||
if (region->getBasickBlocks().empty())
|
if (region->getBasickBlocks().empty())
|
||||||
@@ -136,11 +166,11 @@ unsigned long long CalculateLength(const AccessingSet& array)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddPrivateArraysToLoop(LoopGraph* loop, ArrayAccessingIndexes privates)
|
void AddPrivateArraysToLoop(LoopGraph* loop, const ArrayAccessingIndexes& privates, set<SgStatement*>& insertedPrivates)
|
||||||
{
|
{
|
||||||
SgStatement* spfStat = new SgStatement(SPF_ANALYSIS_DIR);
|
SgStatement* spfStat = new SgStatement(SPF_ANALYSIS_DIR);
|
||||||
spfStat->setlineNumber(loop->lineNum);
|
spfStat->setlineNumber(loop->loop->lineNumber());
|
||||||
spfStat->setFileName((char*)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;
|
||||||
for (const auto& [_, accessingSet] : privates)
|
for (const auto& [_, accessingSet] : privates)
|
||||||
@@ -171,11 +201,15 @@ void AddPrivateArraysToLoop(LoopGraph* loop, ArrayAccessingIndexes privates)
|
|||||||
}
|
}
|
||||||
toAdd->setLhs(new SgVarRefExp(elem));
|
toAdd->setLhs(new SgVarRefExp(elem));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (arraysToInsert.size() == 0)
|
||||||
|
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||||
|
|
||||||
loop->loop->addAttribute(SPF_ANALYSIS_DIR, spfStat, sizeof(SgStatement));
|
loop->loop->insertStmtBefore(*spfStat, *loop->loop->controlParent());
|
||||||
|
insertedPrivates.insert(spfStat);
|
||||||
}
|
}
|
||||||
|
|
||||||
map<LoopGraph*, ArrayAccessingIndexes> 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, set<SgStatement*> &insertedPrivates)
|
||||||
{
|
{
|
||||||
map<LoopGraph*, ArrayAccessingIndexes> result;
|
map<LoopGraph*, ArrayAccessingIndexes> result;
|
||||||
for (const auto& [fileName, loops] : loopGraph)
|
for (const auto& [fileName, loops] : loopGraph)
|
||||||
@@ -183,6 +217,8 @@ map<LoopGraph*, ArrayAccessingIndexes> FindPrivateArrays(map<string, vector<Loo
|
|||||||
SgFile::switchToFile(fileName);
|
SgFile::switchToFile(fileName);
|
||||||
for (const auto& loop : loops)
|
for (const auto& loop : loops)
|
||||||
{
|
{
|
||||||
|
if (!loop->isFor())
|
||||||
|
continue;
|
||||||
SgStatement* search_func = loop->loop->GetOriginal();
|
SgStatement* search_func = loop->loop->GetOriginal();
|
||||||
|
|
||||||
while (search_func && (!isSgProgHedrStmt(search_func)))
|
while (search_func && (!isSgProgHedrStmt(search_func)))
|
||||||
@@ -199,15 +235,14 @@ map<LoopGraph*, ArrayAccessingIndexes> FindPrivateArrays(map<string, vector<Loo
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
SolveDataFlow(loopRegion);
|
SolveDataFlow(loopRegion);
|
||||||
|
RemoveEmptyPoints(loopRegion->array_priv);
|
||||||
result[loop] = loopRegion->array_priv;
|
result[loop] = loopRegion->array_priv;
|
||||||
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]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,12 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <set>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
#include "range_structures.h"
|
#include "range_structures.h"
|
||||||
#include "graph_loops.h"
|
#include "graph_loops.h"
|
||||||
#include "CFGraph/CFGraph.h"
|
#include "CFGraph/CFGraph.h"
|
||||||
|
|
||||||
std::map<LoopGraph*, ArrayAccessingIndexes> FindPrivateArrays(std::map<std::string, std::vector<LoopGraph*>>& loopGraph, std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& FullIR);
|
void FindPrivateArrays(std::map<std::string, std::vector<LoopGraph*>>& loopGraph, std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& FullIR, std::set<SgStatement*>& insertedPrivates);
|
||||||
std::pair<SAPFOR::BasicBlock*, std::unordered_set<SAPFOR::BasicBlock*>> GetBasicBlocksForLoop(const LoopGraph* loop, const std::vector<SAPFOR::BasicBlock*> blocks);
|
std::pair<SAPFOR::BasicBlock*, std::unordered_set<SAPFOR::BasicBlock*>> GetBasicBlocksForLoop(const LoopGraph* loop, const std::vector<SAPFOR::BasicBlock*> blocks);
|
||||||
|
|||||||
@@ -64,18 +64,13 @@ static vector<ArrayDimension> DimensionDifference(const ArrayDimension& dim1, co
|
|||||||
result.push_back({ dim1.start, dim1.step, (intersection->start - dim1.start) / dim1.step, dim1.array});
|
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;
|
if (intersection->step > dim1.step)
|
||||||
uint64_t interValue = intersection->start;
|
|
||||||
for (int64_t i = start; dim1.start + i * dim1.step <= intersection->start + intersection->step * (intersection->tripCount - 1); i++)
|
|
||||||
{
|
{
|
||||||
uint64_t centerValue = dim1.start + i * dim1.step;
|
uint64_t start = (intersection->start - dim1.start) / dim1.step;
|
||||||
if (centerValue == interValue)
|
uint64_t interValue = intersection->start;
|
||||||
|
for (int64_t i = start; interValue <= intersection->start + intersection->step * (intersection->tripCount - 1); i++)
|
||||||
{
|
{
|
||||||
if (i - start > 1)
|
result.push_back({interValue + dim1.step, dim1.step, intersection->step / dim1.step, dim1.array});
|
||||||
{
|
|
||||||
result.push_back({ dim1.start + (start + 1) * dim1.step, dim1.step, i - start - 1, dim1.array });
|
|
||||||
start = i;
|
|
||||||
}
|
|
||||||
interValue += intersection->step;
|
interValue += intersection->step;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -216,6 +211,10 @@ void AccessingSet::Insert(const vector<ArrayDimension>& element)
|
|||||||
}
|
}
|
||||||
|
|
||||||
AccessingSet AccessingSet::Union(const AccessingSet& source) {
|
AccessingSet AccessingSet::Union(const AccessingSet& source) {
|
||||||
|
if (source.GetElements().empty())
|
||||||
|
return *this;
|
||||||
|
if (allElements.empty())
|
||||||
|
return source;
|
||||||
AccessingSet result;
|
AccessingSet result;
|
||||||
for (auto& element : source.GetElements())
|
for (auto& element : source.GetElements())
|
||||||
result.Insert(element);
|
result.Insert(element);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include<unordered_map>
|
#include<unordered_map>
|
||||||
#include<string>
|
#include<string>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "range_structures.h"
|
#include "range_structures.h"
|
||||||
#include "region.h"
|
#include "region.h"
|
||||||
@@ -108,11 +109,7 @@ static int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAcces
|
|||||||
{
|
{
|
||||||
vector<SAPFOR::Argument*> index_vars;
|
vector<SAPFOR::Argument*> index_vars;
|
||||||
vector<int> refPos;
|
vector<int> refPos;
|
||||||
string array_name;
|
string array_name = instruction->getInstruction()->getArg1()->getValue();
|
||||||
if (operation == SAPFOR::CFG_OP::STORE)
|
|
||||||
array_name = instruction->getInstruction()->getArg1()->getValue();
|
|
||||||
else
|
|
||||||
array_name = instruction->getInstruction()->getArg2()->getValue();
|
|
||||||
|
|
||||||
int j = i - 1;
|
int j = i - 1;
|
||||||
while (j >= 0 && instructions[j]->getInstruction()->getOperation() == SAPFOR::CFG_OP::REF)
|
while (j >= 0 && instructions[j]->getInstruction()->getOperation() == SAPFOR::CFG_OP::REF)
|
||||||
@@ -128,6 +125,7 @@ static int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAcces
|
|||||||
|
|
||||||
auto* ref = isSgArrayRefExp(instruction->getInstruction()->getExpression());
|
auto* ref = isSgArrayRefExp(instruction->getInstruction()->getExpression());
|
||||||
vector<pair<int, int>> coefsForDims;
|
vector<pair<int, int>> coefsForDims;
|
||||||
|
int subs = ref->numberOfSubscripts();
|
||||||
for (int i = 0; ref && i < ref->numberOfSubscripts(); ++i)
|
for (int i = 0; ref && i < ref->numberOfSubscripts(); ++i)
|
||||||
{
|
{
|
||||||
const vector<int*>& coefs = getAttributes<SgExpression*, int*>(ref->subscript(i), set<int>{ INT_VAL });
|
const vector<int*>& coefs = getAttributes<SgExpression*, int*>(ref->subscript(i), set<int>{ INT_VAL });
|
||||||
@@ -174,13 +172,17 @@ static int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAcces
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t start = currentLoop->startVal * currentCoefs.first + currentCoefs.second;
|
uint64_t start = currentLoop->startVal;
|
||||||
uint64_t step = currentCoefs.first;
|
uint64_t step = currentLoop->stepVal;
|
||||||
current_dim = { start, step, (uint64_t)currentLoop->calculatedCountOfIters, ref };
|
uint64_t iters = currentLoop->calculatedCountOfIters;
|
||||||
|
current_dim = { start, step, iters, ref };
|
||||||
}
|
}
|
||||||
|
|
||||||
accessPoint[n - index_vars.size()] = current_dim;
|
if (current_dim.start != 0 && current_dim.step != 0 && current_dim.tripCount != 0)
|
||||||
fillCount++;
|
{
|
||||||
|
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();
|
||||||
@@ -230,8 +232,11 @@ static Region* CreateSubRegion(LoopGraph* loop, const vector<SAPFOR::BasicBlock*
|
|||||||
region->addBasickBlocks(bbToRegion.at(block));
|
region->addBasickBlocks(bbToRegion.at(block));
|
||||||
|
|
||||||
for (LoopGraph* childLoop : loop->children)
|
for (LoopGraph* childLoop : loop->children)
|
||||||
|
{
|
||||||
|
if (!childLoop->isFor())
|
||||||
|
continue;
|
||||||
region->addSubRegions(CreateSubRegion(childLoop, Blocks, bbToRegion));
|
region->addSubRegions(CreateSubRegion(childLoop, Blocks, bbToRegion));
|
||||||
|
}
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,5 +255,9 @@ Region::Region(LoopGraph* loop, const vector<SAPFOR::BasicBlock*>& Blocks)
|
|||||||
SetConnections(bbToRegion, blockSet);
|
SetConnections(bbToRegion, blockSet);
|
||||||
//create subRegions
|
//create subRegions
|
||||||
for (LoopGraph* childLoop : loop->children)
|
for (LoopGraph* childLoop : loop->children)
|
||||||
|
{
|
||||||
|
if (!childLoop->isFor())
|
||||||
|
continue;
|
||||||
subRegions.insert(CreateSubRegion(childLoop, Blocks, bbToRegion));
|
subRegions.insert(CreateSubRegion(childLoop, Blocks, bbToRegion));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,7 @@
|
|||||||
#include "DynamicAnalysis/gCov_parser_func.h"
|
#include "DynamicAnalysis/gCov_parser_func.h"
|
||||||
#include "DynamicAnalysis/createParallelRegions.h"
|
#include "DynamicAnalysis/createParallelRegions.h"
|
||||||
|
|
||||||
|
#include "ArrayConstantPropagation/propagation.h"
|
||||||
#include "DirectiveProcessing/directive_analyzer.h"
|
#include "DirectiveProcessing/directive_analyzer.h"
|
||||||
#include "DirectiveProcessing/directive_creator.h"
|
#include "DirectiveProcessing/directive_creator.h"
|
||||||
#include "DirectiveProcessing/insert_directive.h"
|
#include "DirectiveProcessing/insert_directive.h"
|
||||||
@@ -279,7 +280,8 @@ static string unparseProjectIfNeed(SgFile* file, const int curr_regime, const bo
|
|||||||
for (SgStatement* st = file->firstStatement(); st; st = st->lexNext())
|
for (SgStatement* st = file->firstStatement(); st; st = st->lexNext())
|
||||||
if (isSPF_stat(st)) // except sapfor parallel regions and if attributes dont move
|
if (isSPF_stat(st)) // except sapfor parallel regions and if attributes dont move
|
||||||
if (st->variant() != SPF_PARALLEL_REG_DIR && st->variant() != SPF_END_PARALLEL_REG_DIR)
|
if (st->variant() != SPF_PARALLEL_REG_DIR && st->variant() != SPF_END_PARALLEL_REG_DIR)
|
||||||
toDel.push_back(st);
|
if (insertedPrivates.find(st) == insertedPrivates.end())
|
||||||
|
toDel.push_back(st);
|
||||||
|
|
||||||
for (auto& elem : toDel)
|
for (auto& elem : toDel)
|
||||||
elem->deleteStmt();
|
elem->deleteStmt();
|
||||||
@@ -1914,8 +1916,11 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
|||||||
}
|
}
|
||||||
else if (curr_regime == TRANSFORM_ASSUMED_SIZE_PARAMETERS)
|
else if (curr_regime == TRANSFORM_ASSUMED_SIZE_PARAMETERS)
|
||||||
transformAssumedSizeParameters(allFuncInfo);
|
transformAssumedSizeParameters(allFuncInfo);
|
||||||
else if (curr_regime == FIND_PRIVATE_ARRAYS)
|
else if (curr_regime == FIND_PRIVATE_ARRAYS_ANALYSIS)
|
||||||
auto result = FindPrivateArrays(loopGraph, fullIR);
|
FindPrivateArrays(loopGraph, fullIR, insertedPrivates);
|
||||||
|
|
||||||
|
else if (curr_regime == ARRAY_PROPAGATION)
|
||||||
|
ArrayConstantPropagation(project);
|
||||||
|
|
||||||
const float elapsed = duration_cast<milliseconds>(high_resolution_clock::now() - timeForPass).count() / 1000.;
|
const float elapsed = duration_cast<milliseconds>(high_resolution_clock::now() - timeForPass).count() / 1000.;
|
||||||
const float elapsedGlobal = duration_cast<milliseconds>(high_resolution_clock::now() - globalTime).count() / 1000.;
|
const float elapsedGlobal = duration_cast<milliseconds>(high_resolution_clock::now() - globalTime).count() / 1000.;
|
||||||
@@ -2373,6 +2378,7 @@ void runPass(const int curr_regime, const char *proj_name, const char *folderNam
|
|||||||
case SUBST_EXPR_RD_AND_UNPARSE:
|
case SUBST_EXPR_RD_AND_UNPARSE:
|
||||||
case SUBST_EXPR_AND_UNPARSE:
|
case SUBST_EXPR_AND_UNPARSE:
|
||||||
case REMOVE_DEAD_CODE_AND_UNPARSE:
|
case REMOVE_DEAD_CODE_AND_UNPARSE:
|
||||||
|
case FIND_PRIVATE_ARRAYS:
|
||||||
if (folderName)
|
if (folderName)
|
||||||
runAnalysis(*project, UNPARSE_FILE, true, "", folderName);
|
runAnalysis(*project, UNPARSE_FILE, true, "", folderName);
|
||||||
else
|
else
|
||||||
@@ -2634,7 +2640,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (curr_regime == INSERT_PARALLEL_DIRS_NODIST)
|
if (curr_regime == INSERT_PARALLEL_DIRS_NODIST || curr_regime == FIND_PRIVATE_ARRAYS)
|
||||||
{
|
{
|
||||||
ignoreArrayDistributeState = true;
|
ignoreArrayDistributeState = true;
|
||||||
sharedMemoryParallelization = 1;
|
sharedMemoryParallelization = 1;
|
||||||
|
|||||||
@@ -183,10 +183,13 @@ enum passes {
|
|||||||
SET_IMPLICIT_NONE,
|
SET_IMPLICIT_NONE,
|
||||||
RENAME_INLCUDES,
|
RENAME_INLCUDES,
|
||||||
|
|
||||||
|
FIND_PRIVATE_ARRAYS_ANALYSIS,
|
||||||
FIND_PRIVATE_ARRAYS,
|
FIND_PRIVATE_ARRAYS,
|
||||||
|
|
||||||
TRANSFORM_ASSUMED_SIZE_PARAMETERS,
|
TRANSFORM_ASSUMED_SIZE_PARAMETERS,
|
||||||
|
|
||||||
|
ARRAY_PROPAGATION,
|
||||||
|
|
||||||
TEST_PASS,
|
TEST_PASS,
|
||||||
EMPTY_PASS
|
EMPTY_PASS
|
||||||
};
|
};
|
||||||
@@ -371,10 +374,13 @@ static void setPassValues()
|
|||||||
passNames[SET_IMPLICIT_NONE] = "SET_IMPLICIT_NONE";
|
passNames[SET_IMPLICIT_NONE] = "SET_IMPLICIT_NONE";
|
||||||
passNames[RENAME_INLCUDES] = "RENAME_INLCUDES";
|
passNames[RENAME_INLCUDES] = "RENAME_INLCUDES";
|
||||||
passNames[INSERT_NO_DISTR_FLAGS_FROM_GUI] = "INSERT_NO_DISTR_FLAGS_FROM_GUI";
|
passNames[INSERT_NO_DISTR_FLAGS_FROM_GUI] = "INSERT_NO_DISTR_FLAGS_FROM_GUI";
|
||||||
|
passNames[FIND_PRIVATE_ARRAYS_ANALYSIS] = "FIND_PRIVATE_ARRAYS_ANALYSIS";
|
||||||
passNames[FIND_PRIVATE_ARRAYS] = "FIND_PRIVATE_ARRAYS";
|
passNames[FIND_PRIVATE_ARRAYS] = "FIND_PRIVATE_ARRAYS";
|
||||||
|
|
||||||
passNames[TRANSFORM_ASSUMED_SIZE_PARAMETERS] = "TRANSFORM_ASSUMED_SIZE_PARAMETERS";
|
passNames[TRANSFORM_ASSUMED_SIZE_PARAMETERS] = "TRANSFORM_ASSUMED_SIZE_PARAMETERS";
|
||||||
|
|
||||||
|
passNames[ARRAY_PROPAGATION] = "ARRAY_PROPAGATION";
|
||||||
|
|
||||||
passNames[TEST_PASS] = "TEST_PASS";
|
passNames[TEST_PASS] = "TEST_PASS";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -175,6 +175,11 @@ std::set<std::tuple<std::string, int, std::string>> parametersOfProject; // [fil
|
|||||||
//for GET_MIN_MAX_BLOCK_DIST
|
//for GET_MIN_MAX_BLOCK_DIST
|
||||||
std::pair<int, int> min_max_block = std::make_pair(-1, -1);
|
std::pair<int, int> min_max_block = std::make_pair(-1, -1);
|
||||||
//
|
//
|
||||||
|
|
||||||
|
//for FIND_PRIVATE_ARRAYS
|
||||||
|
std::set<SgStatement*> insertedPrivates;
|
||||||
|
//
|
||||||
|
|
||||||
const char* passNames[EMPTY_PASS + 1];
|
const char* passNames[EMPTY_PASS + 1];
|
||||||
const char* optionNames[EMPTY_OPTION + 1];
|
const char* optionNames[EMPTY_OPTION + 1];
|
||||||
bool passNamesWasInit = false;
|
bool passNamesWasInit = false;
|
||||||
|
|||||||
@@ -316,7 +316,10 @@ void InitPassesDependencies(map<passes, vector<passes>> &passDepsIn, set<passes>
|
|||||||
|
|
||||||
list({ VERIFY_INCLUDES, CORRECT_VAR_DECL }) <= Pass(SET_IMPLICIT_NONE);
|
list({ VERIFY_INCLUDES, CORRECT_VAR_DECL }) <= Pass(SET_IMPLICIT_NONE);
|
||||||
|
|
||||||
list({ CALL_GRAPH2, CALL_GRAPH, BUILD_IR, LOOP_GRAPH, LOOP_ANALYZER_DATA_DIST_S2 }) <= Pass(FIND_PRIVATE_ARRAYS);
|
list({ ARRAY_PROPAGATION, CALL_GRAPH2, CALL_GRAPH, BUILD_IR, LOOP_GRAPH, LOOP_ANALYZER_DATA_DIST_S2 }) <= Pass(FIND_PRIVATE_ARRAYS_ANALYSIS);
|
||||||
|
list({ FIND_PRIVATE_ARRAYS_ANALYSIS, CONVERT_LOOP_TO_ASSIGN, RESTORE_LOOP_FROM_ASSIGN, REVERT_SUBST_EXPR_RD }) <= Pass(FIND_PRIVATE_ARRAYS);
|
||||||
|
|
||||||
|
//Pass( CALL_GRAPH2 ) <= Pass(ARRAY_PROPAGATION);
|
||||||
|
|
||||||
passesIgnoreStateDone.insert({ CREATE_PARALLEL_DIRS, INSERT_PARALLEL_DIRS, INSERT_SHADOW_DIRS, EXTRACT_PARALLEL_DIRS,
|
passesIgnoreStateDone.insert({ CREATE_PARALLEL_DIRS, INSERT_PARALLEL_DIRS, INSERT_SHADOW_DIRS, EXTRACT_PARALLEL_DIRS,
|
||||||
EXTRACT_SHADOW_DIRS, CREATE_REMOTES, UNPARSE_FILE, REMOVE_AND_CALC_SHADOW,
|
EXTRACT_SHADOW_DIRS, CREATE_REMOTES, UNPARSE_FILE, REMOVE_AND_CALC_SHADOW,
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define VERSION_SPF "2447"
|
#define VERSION_SPF "2448"
|
||||||
|
|||||||
@@ -1797,6 +1797,8 @@ int SPF_InsertPrivateArrayDirectives(void*& context, int winHandler, short* opti
|
|||||||
{
|
{
|
||||||
MessageManager::clearCache();
|
MessageManager::clearCache();
|
||||||
MessageManager::setWinHandler(winHandler);
|
MessageManager::setWinHandler(winHandler);
|
||||||
|
ignoreArrayDistributeState = true;
|
||||||
|
sharedMemoryParallelization = 1;
|
||||||
return simpleTransformPass(FIND_PRIVATE_ARRAYS, options, projName, folderName, output, outputMessage);
|
return simpleTransformPass(FIND_PRIVATE_ARRAYS, options, projName, folderName, output, outputMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user