fixed code style
This commit is contained in:
@@ -16,9 +16,8 @@ static bool isParentStmt(SgStatement* stmt, SgStatement* parent)
|
||||
{
|
||||
for (; stmt; stmt = stmt->controlParent())
|
||||
if (stmt == parent)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -31,9 +30,8 @@ pair<SAPFOR::BasicBlock*, unordered_set<SAPFOR::BasicBlock*>> GetBasicBlocksForL
|
||||
for (const auto& block : blocks)
|
||||
{
|
||||
if (!block || (block->getInstructions().size() == 0))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
SgStatement* first = block->getInstructions().front()->getInstruction()->getOperator();
|
||||
SgStatement* last = block->getInstructions().back()->getInstruction()->getOperator();
|
||||
if (isParentStmt(first, loop_operator) && isParentStmt(last, loop_operator))
|
||||
@@ -55,36 +53,39 @@ pair<SAPFOR::BasicBlock*, unordered_set<SAPFOR::BasicBlock*>> GetBasicBlocksForL
|
||||
static void BuildLoopIndex(map<string, LoopGraph*>& loopForIndex, LoopGraph* loop) {
|
||||
string index = loop->loopSymbol;
|
||||
loopForIndex[index] = loop;
|
||||
for (const auto& childLoop : loop->children) {
|
||||
|
||||
for (const auto& childLoop : loop->children)
|
||||
BuildLoopIndex(loopForIndex, childLoop);
|
||||
}
|
||||
}
|
||||
|
||||
static string FindIndexName(int pos, SAPFOR::BasicBlock* block, map<string, LoopGraph*>& loopForIndex) {
|
||||
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--)
|
||||
{
|
||||
SAPFOR::Argument* res = block->getInstructions()[i]->getInstruction()->getResult();
|
||||
if (res && args.find(res) != args.end()) {
|
||||
if (res && args.find(res) != args.end())
|
||||
{
|
||||
SAPFOR::Argument* arg1 = block->getInstructions()[i]->getInstruction()->getArg1();
|
||||
SAPFOR::Argument* arg2 = block->getInstructions()[i]->getInstruction()->getArg2();
|
||||
if (arg1) {
|
||||
if (arg1)
|
||||
{
|
||||
string name = arg1->getValue();
|
||||
int idx = name.find('%');
|
||||
if (idx != -1 && loopForIndex.find(name.substr(idx + 1)) != loopForIndex.end())
|
||||
return name.substr(idx + 1);
|
||||
else {
|
||||
else
|
||||
args.insert(arg1);
|
||||
}
|
||||
}
|
||||
if (arg2) {
|
||||
|
||||
if (arg2)
|
||||
{
|
||||
string name = arg2->getValue();
|
||||
int idx = name.find('%');
|
||||
if (idx != -1 && loopForIndex.find(name.substr(idx + 1)) != loopForIndex.end())
|
||||
return name.substr(idx + 1);
|
||||
else {
|
||||
else
|
||||
args.insert(arg2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -98,9 +99,9 @@ static int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAcces
|
||||
for (int i = 0; i < instructions.size(); i++)
|
||||
{
|
||||
auto instruction = instructions[i];
|
||||
if (!instruction->getInstruction()->getArg1()) {
|
||||
if (!instruction->getInstruction()->getArg1())
|
||||
continue;
|
||||
}
|
||||
|
||||
auto operation = instruction->getInstruction()->getOperation();
|
||||
auto type = instruction->getInstruction()->getArg1()->getType();
|
||||
if ((operation == SAPFOR::CFG_OP::STORE || operation == SAPFOR::CFG_OP::LOAD) && type == SAPFOR::CFG_ARG_TYPE::ARRAY)
|
||||
@@ -109,13 +110,10 @@ static int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAcces
|
||||
vector<int> refPos;
|
||||
string array_name;
|
||||
if (operation == SAPFOR::CFG_OP::STORE)
|
||||
{
|
||||
array_name = instruction->getInstruction()->getArg1()->getValue();
|
||||
}
|
||||
array_name = instruction->getInstruction()->getArg1()->getValue();
|
||||
else
|
||||
{
|
||||
array_name = instruction->getInstruction()->getArg2()->getValue();
|
||||
}
|
||||
|
||||
int j = i - 1;
|
||||
while (j >= 0 && instructions[j]->getInstruction()->getOperation() == SAPFOR::CFG_OP::REF)
|
||||
{
|
||||
@@ -123,12 +121,12 @@ static int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAcces
|
||||
refPos.push_back(j);
|
||||
j--;
|
||||
}
|
||||
|
||||
/*to choose correct dimension*/
|
||||
int n = index_vars.size();
|
||||
vector<ArrayDimension> accessPoint(n);
|
||||
|
||||
auto* ref = isSgArrayRefExp(instruction->getInstruction()->getExpression());
|
||||
|
||||
vector<pair<int, int>> coefsForDims;
|
||||
for (int i = 0; ref && i < ref->numberOfSubscripts(); ++i)
|
||||
{
|
||||
@@ -147,52 +145,48 @@ static int GetDefUseArray(SAPFOR::BasicBlock* block, LoopGraph* loop, ArrayAcces
|
||||
int currentVarPos = refPos.back();
|
||||
pair currentCoefs = coefsForDims.back();
|
||||
ArrayDimension current_dim;
|
||||
if (var->getType() == SAPFOR::CFG_ARG_TYPE::CONST) {
|
||||
if (var->getType() == SAPFOR::CFG_ARG_TYPE::CONST)
|
||||
current_dim = { stoul(var->getValue()), 1, 1 };
|
||||
}
|
||||
else
|
||||
{
|
||||
string name, full_name = var->getValue();
|
||||
int pos = full_name.find('%');
|
||||
LoopGraph* currentLoop;
|
||||
if (pos != -1) {
|
||||
if (pos != -1)
|
||||
{
|
||||
name = full_name.substr(pos + 1);
|
||||
if (loopForIndex.find(name) != loopForIndex.end()) {
|
||||
currentLoop = loopForIndex[name];
|
||||
}
|
||||
else {
|
||||
if (loopForIndex.find(name) != loopForIndex.end())
|
||||
currentLoop = loopForIndex[name];
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
name = FindIndexName(currentVarPos, block, loopForIndex);
|
||||
if (name == "") {
|
||||
if (name == "")
|
||||
return -1;
|
||||
}
|
||||
if (loopForIndex.find(name) != loopForIndex.end()) {
|
||||
currentLoop = loopForIndex[name];
|
||||
}
|
||||
else {
|
||||
|
||||
if (loopForIndex.find(name) != loopForIndex.end())
|
||||
currentLoop = loopForIndex[name];
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t start = currentLoop->startVal * currentCoefs.first + currentCoefs.second;
|
||||
uint64_t step = currentCoefs.first;
|
||||
current_dim = { start, step, (uint64_t)currentLoop->calculatedCountOfIters };
|
||||
}
|
||||
|
||||
accessPoint[n - index_vars.size()] = current_dim;
|
||||
index_vars.pop_back();
|
||||
refPos.pop_back();
|
||||
coefsForDims.pop_back();
|
||||
}
|
||||
if (operation == SAPFOR::CFG_OP::STORE)
|
||||
{
|
||||
|
||||
if (operation == SAPFOR::CFG_OP::STORE)
|
||||
def[array_name].Insert(accessPoint);
|
||||
}
|
||||
else
|
||||
{
|
||||
use[array_name].Insert(accessPoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
@@ -204,19 +198,12 @@ static void SetConnections(unordered_map<SAPFOR::BasicBlock*, Region*>& bbToRegi
|
||||
for (SAPFOR::BasicBlock* block : blockSet)
|
||||
{
|
||||
for (SAPFOR::BasicBlock* nextBlock : block->getNext())
|
||||
{
|
||||
if (bbToRegion.find(nextBlock) != bbToRegion.end())
|
||||
{
|
||||
bbToRegion[block]->addNextRegion(bbToRegion[nextBlock]);
|
||||
}
|
||||
}
|
||||
|
||||
for (SAPFOR::BasicBlock* prevBlock : block->getPrev())
|
||||
{
|
||||
if (bbToRegion.find(prevBlock) != bbToRegion.end())
|
||||
{
|
||||
bbToRegion[block]->addPrevRegion(bbToRegion[prevBlock]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,24 +212,17 @@ static Region* CreateSubRegion(LoopGraph* loop, const vector<SAPFOR::BasicBlock*
|
||||
Region* region = new Region;
|
||||
auto [header, blockSet] = GetBasicBlocksForLoop(loop, Blocks);
|
||||
if (bbToRegion.find(header) != bbToRegion.end())
|
||||
{
|
||||
region->setHeader(bbToRegion.at(header));
|
||||
}
|
||||
region->setHeader(bbToRegion.at(header));
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (SAPFOR::BasicBlock* block : blockSet)
|
||||
{
|
||||
if (bbToRegion.find(block) != bbToRegion.end())
|
||||
{
|
||||
region->addBasickBlocks(bbToRegion.at(block));
|
||||
}
|
||||
}
|
||||
|
||||
for (LoopGraph* childLoop : loop->children)
|
||||
{
|
||||
region->addSubRegions(CreateSubRegion(childLoop, Blocks, bbToRegion));
|
||||
}
|
||||
|
||||
cout << header << endl;
|
||||
return region;
|
||||
}
|
||||
@@ -262,7 +242,5 @@ Region::Region(LoopGraph* loop, const vector<SAPFOR::BasicBlock*>& Blocks)
|
||||
SetConnections(bbToRegion, blockSet);
|
||||
//create subRegions
|
||||
for (LoopGraph* childLoop : loop->children)
|
||||
{
|
||||
subRegions.insert(CreateSubRegion(childLoop, Blocks, bbToRegion));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user