Compare commits
41 Commits
private_ar
...
private_ar
| Author | SHA1 | Date | |
|---|---|---|---|
| b6665271dd | |||
|
|
68b6883f30 | ||
|
|
fe81822c96 | ||
| 2a0cfdb68e | |||
| 4229041da4 | |||
|
|
14e3bc54f1 | ||
|
|
46ff7761d6 | ||
|
|
19254c0641 | ||
|
|
78aa84f8e5 | ||
|
|
aa7f9cfa4f | ||
|
|
ef76988301 | ||
|
|
0b46007f8e | ||
|
|
3024a52963 | ||
|
|
4245afa5c8 | ||
|
|
7d8c4b4714 | ||
|
|
557c58f879 | ||
|
|
b8d8bb9ddc | ||
|
|
5c6a2444f3 | ||
|
|
e958fdbc7c | ||
|
|
390b1f7076 | ||
|
|
9f3c4310ed | ||
|
|
1c0e02dd9c | ||
|
|
ece05bf29a | ||
|
|
0f4e970adf | ||
|
|
05b72fe9b7 | ||
|
|
806365daa8 | ||
|
|
b27539edea | ||
|
|
7a62268f61 | ||
|
|
88e9a1532e | ||
| 087247b11f | |||
|
|
de5c17b46f | ||
|
|
d5f70c3604 | ||
|
|
af7b343ebd | ||
|
|
3fd03d4c2a | ||
|
|
aa92a918a4 | ||
|
|
6f649696ab | ||
|
|
e2356498dc | ||
|
|
55ba751dc3 | ||
|
|
212460ac15 | ||
|
|
d17b4c2702 | ||
| 3eb09fe5cf |
@@ -10,6 +10,7 @@
|
||||
using namespace std;
|
||||
|
||||
static SgStatement* declPlace = NULL;
|
||||
static unordered_set<SgStatement*> changed;;
|
||||
|
||||
static bool CheckConstIndexes(SgExpression* exp)
|
||||
{
|
||||
@@ -36,13 +37,13 @@ static bool CheckConstIndexes(SgExpression* exp)
|
||||
|
||||
static SgExpression* CreateVar(int& variableNumber, SgType* type)
|
||||
{
|
||||
string varName = "__tmp_prop_var";
|
||||
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());
|
||||
|
||||
const string commonBlockName = "__propagation_common__";
|
||||
const string commonBlockName = "propagation_common__";
|
||||
|
||||
SgStatement* funcStart = declPlace->controlParent();
|
||||
SgStatement* commonStat = NULL;
|
||||
@@ -169,7 +170,6 @@ static SgExpression* CreateVar(int& variableNumber, SgType* type)
|
||||
|
||||
commonList->setLhs(varList);
|
||||
}
|
||||
|
||||
return new SgExpression(VAR_REF, NULL, NULL, varSymbol, type->copyPtr());
|
||||
}
|
||||
|
||||
@@ -227,6 +227,8 @@ static void TransformLeftPart(SgStatement* st, SgExpression* exp, unordered_map<
|
||||
{
|
||||
if (exp->symbol()->type()->variant() == T_STRING)
|
||||
return;
|
||||
if (changed.find(st) != changed.end())
|
||||
return;
|
||||
string expUnparsed = exp->unparse();
|
||||
if (arrayToVariable.find(expUnparsed) == arrayToVariable.end() && exp->symbol()->type()->baseType())
|
||||
{
|
||||
@@ -240,6 +242,56 @@ static void TransformLeftPart(SgStatement* st, SgExpression* exp, unordered_map<
|
||||
newStatement->setlineNumber(getNextNegativeLineNumber());
|
||||
newStatement->setLocalLineNumber(st->lineNumber());
|
||||
st->insertStmtBefore(*newStatement, *st->controlParent());
|
||||
changed.insert(st);
|
||||
}
|
||||
|
||||
static void TransformBorder(SgStatement* st, SgExpression* exp, unordered_map<string, SgExpression*>& arrayToVariable, int& variableNumber)
|
||||
{
|
||||
SgStatement* firstStatement = declPlace->lexPrev();
|
||||
st = st->lexPrev();
|
||||
string array = exp->unparse();
|
||||
arrayToVariable[array] = CreateVar(variableNumber, exp->symbol()->type()->baseType());
|
||||
while (st != firstStatement)
|
||||
{
|
||||
if (st->variant() == ASSIGN_STAT && arrayToVariable.find(st->expr(0)->unparse()) != arrayToVariable.end())
|
||||
{
|
||||
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()) && arrayToVariable.find(st->expr(0)->unparse()) != arrayToVariable.end())
|
||||
{
|
||||
TransformLeftPart(st, st->expr(0), arrayToVariable, variableNumber);
|
||||
}
|
||||
}
|
||||
st = st->lexPrev();
|
||||
}
|
||||
}
|
||||
|
||||
static void CheckVariable(SgStatement* st, SgExpression* exp, unordered_map<string, SgExpression*>& arrayToVariable, int& variableNumber)
|
||||
{
|
||||
SgStatement* firstStatement = declPlace->lexPrev();
|
||||
st = st->lexPrev();
|
||||
string varName = exp->unparse();
|
||||
while (st != firstStatement)
|
||||
{
|
||||
if (st->variant() == ASSIGN_STAT && st->expr(0)->symbol() == exp->symbol())
|
||||
{
|
||||
TransformRightPart(st, st->expr(1), arrayToVariable, variableNumber);
|
||||
}
|
||||
if (st->variant() == ASSIGN_STAT && arrayToVariable.find(st->expr(0)->unparse()) != arrayToVariable.end())
|
||||
{
|
||||
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()) && arrayToVariable.find(st->expr(0)->unparse()) != arrayToVariable.end())
|
||||
{
|
||||
TransformLeftPart(st, st->expr(0), arrayToVariable, variableNumber);
|
||||
}
|
||||
}
|
||||
st = st->lexPrev();
|
||||
}
|
||||
}
|
||||
|
||||
void ArrayConstantPropagation(SgProject& project)
|
||||
@@ -262,40 +314,29 @@ void ArrayConstantPropagation(SgProject& project)
|
||||
|
||||
for (; st != lastNode; st = st->lexNext())
|
||||
{
|
||||
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)
|
||||
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());
|
||||
}
|
||||
TransformBorder(st, upperBound, arrayToVariable, variableNumber);
|
||||
st->expr(0)->setRhs(arrayToVariable[upperBoundUnparsed]->copyPtr());
|
||||
}
|
||||
else if (upperBound->variant() == VAR_REF)
|
||||
CheckVariable(st, upperBound, arrayToVariable, variableNumber);
|
||||
|
||||
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());
|
||||
}
|
||||
TransformBorder(st, lowerBound, arrayToVariable, variableNumber);
|
||||
st->expr(0)->setLhs(arrayToVariable[lowerBoundUnparsed]->copyPtr());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (lowerBound->variant() == VAR_REF)
|
||||
CheckVariable(st, lowerBound, arrayToVariable, variableNumber);
|
||||
}
|
||||
}
|
||||
cout << file->functions(i)->unparse() << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -180,7 +180,8 @@ static void SolveDataFlowIteratively(Region* DFG)
|
||||
b->array_out = newOut;
|
||||
else
|
||||
worklist.erase(b);
|
||||
} while (!worklist.empty());
|
||||
}
|
||||
while (!worklist.empty());
|
||||
}
|
||||
|
||||
static void SolveForBasickBlock(Region* block)
|
||||
|
||||
@@ -95,7 +95,7 @@ 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, ArrayAccessingIndexes& all_use, Region* region) {
|
||||
auto instructions = block->getInstructions();
|
||||
map<string, LoopGraph*> loopForIndex;
|
||||
BuildLoopIndex(loopForIndex, loop);
|
||||
@@ -227,6 +227,7 @@ static int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAcces
|
||||
else
|
||||
{
|
||||
instruction.use[array_name] = { { accessPoint } };
|
||||
all_use[array_name].Insert(accessPoint);
|
||||
if (def.find(array_name) == def.end())
|
||||
use[array_name].Insert(accessPoint);
|
||||
else
|
||||
@@ -327,7 +328,7 @@ Region::Region(LoopGraph* loop, const vector<SAPFOR::BasicBlock*>& Blocks)
|
||||
{
|
||||
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]->array_all_use, bbToRegion[poiner]);
|
||||
|
||||
}
|
||||
this->header = bbToRegion[header];
|
||||
|
||||
@@ -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, array_all_use;
|
||||
|
||||
private:
|
||||
std::vector<Region*> basickBlocks;
|
||||
|
||||
Reference in New Issue
Block a user