WIP: testing on big data
This commit is contained in:
@@ -1945,11 +1945,18 @@ Instruction* findInstructionAfterLoop(const std::vector<SAPFOR::BasicBlock*>& lo
|
||||
return nullptr; // не нашли
|
||||
}
|
||||
|
||||
void exploreLoops(map<FuncInfo*, vector<SAPFOR::BasicBlock*>>* fullIR) {
|
||||
bool isEqual(const char* cstr, const std::string& str) {
|
||||
return str == cstr;
|
||||
}
|
||||
|
||||
void exploreLoops(map<FuncInfo*, vector<SAPFOR::BasicBlock*>>* fullIR, const char* fileName) {
|
||||
for (auto& i : *fullIR)
|
||||
{
|
||||
//for (auto j : i.second)
|
||||
// printBlock(j);
|
||||
// printblock(j);
|
||||
|
||||
if (!isEqual(fileName, i.first->fileName))
|
||||
continue;
|
||||
|
||||
map<int, int> visited;
|
||||
for (auto i : i.second)
|
||||
@@ -2005,24 +2012,24 @@ void exploreLoops(map<FuncInfo*, vector<SAPFOR::BasicBlock*>>* fullIR) {
|
||||
if (firstInstruction->getOperator()->variant() == FOR_NODE) {
|
||||
SgForStmt* stmt = isSgForStmt(firstInstruction->getOperator());
|
||||
|
||||
cout << "for loop" << endl << stmt->sunparse() << endl;
|
||||
cout << "for loop" << endl;// << stmt->sunparse() << endl;
|
||||
}
|
||||
else if (firstInstruction->getOperator()->variant() == WHILE_NODE) {
|
||||
SgWhileStmt* stmt = isSgWhileStmt(firstInstruction->getOperator());
|
||||
|
||||
cout << (stmt->conditional() == NULL ? "infinit" : "") << "while loop" << endl << stmt->sunparse() << endl;
|
||||
cout << (stmt->conditional() == NULL ? "infinit" : "") << "while loop" << endl;//<< stmt->sunparse() << endl;
|
||||
}
|
||||
else if (firstInstruction->getOperator()->variant() == DO_WHILE_NODE) {
|
||||
SgWhileStmt* stmt = isSgDoWhileStmt(firstInstruction->getOperator());
|
||||
|
||||
cout << "do while loop" << endl << stmt->sunparse() << endl;
|
||||
cout << "do while loop" << endl;// << stmt->sunparse() << endl;
|
||||
}
|
||||
else if (firstInstruction->getOperator()->variant() == LOOP_NODE) {
|
||||
cout << "not known loop" << endl << firstInstruction->getOperator()->sunparse() << endl;
|
||||
cout << "not known loop" << endl;// << firstInstruction->getOperator()->sunparse() << endl;
|
||||
}
|
||||
else {
|
||||
|
||||
cout << "goto loop" << firstInstruction->getOperator()->sunparse() << endl;
|
||||
cout << "goto loop" << endl;// firstInstruction->getOperator()->sunparse() << endl;
|
||||
}
|
||||
|
||||
cout << "loop start line " << tmpLoop->lineNum << endl;
|
||||
|
||||
@@ -352,4 +352,4 @@ std::pair<SAPFOR::Instruction*, SAPFOR::BasicBlock*> getInstructionAndBlockByNum
|
||||
std::pair<SAPFOR::Instruction*, SAPFOR::BasicBlock*> getInstructionAndBlockByStatement(const std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>& CFGraph, SgStatement* stmt);
|
||||
int getParamIndex(SAPFOR::Argument* func_param, int max_index);
|
||||
|
||||
void exploreLoops(std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>* fullIR);
|
||||
void exploreLoops(std::map<FuncInfo*, std::vector<SAPFOR::BasicBlock*>>* fullIR, const char* fileName);
|
||||
@@ -181,6 +181,8 @@ static map<BBlock*, vector<BBlock*>> findDominatorBorders(vector<BBlock*>& block
|
||||
if (block->getPrev().size() > 1) {
|
||||
for (auto prev : block->getPrev()) {
|
||||
auto tmpBlock = prev;
|
||||
auto test = iDominators[block];
|
||||
auto test2 = iDominators[prev];
|
||||
|
||||
while (tmpBlock != iDominators[block]) {
|
||||
result[tmpBlock].push_back(block);
|
||||
@@ -219,6 +221,45 @@ static BBlock* findImmediateDominatorsDfsHelper(BBlock* block, BBlock* currentBl
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static map<BBlock*, BBlock*> findImmediateDominators1(const map<BBlock*, vector<BBlock*>>& dominators, BBlock* entry) {
|
||||
map<BBlock*, BBlock*> iDom;
|
||||
|
||||
for (const auto& pair : dominators) {
|
||||
BBlock* b = pair.first;
|
||||
|
||||
if (b == entry) continue;
|
||||
|
||||
const auto& doms = pair.second;
|
||||
|
||||
BBlock* candidate = nullptr;
|
||||
for (auto d : doms) {
|
||||
if (d == b) continue;
|
||||
bool isImmediate = true;
|
||||
|
||||
for (auto other : doms) {
|
||||
if (other == b || other == d) continue;
|
||||
const auto& domsOfOther = dominators.at(other);
|
||||
if (std::find(domsOfOther.begin(), domsOfOther.end(), d) != domsOfOther.end()) {
|
||||
isImmediate = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isImmediate) {
|
||||
candidate = d;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (candidate) {
|
||||
iDom[b] = candidate;
|
||||
}
|
||||
}
|
||||
|
||||
return iDom;
|
||||
}
|
||||
|
||||
|
||||
static map<BBlock*, BBlock*> findImmediateDominators(map<BBlock*, vector<BBlock*>>& dominators, BBlock* fistBlock) {
|
||||
map<BBlock*, BBlock*> iDominators;
|
||||
|
||||
@@ -320,7 +361,7 @@ static void getBlocksWithFiFunctions(vector<BBlock*> blocks, set<BArgument*> glo
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//return blocksWithFiFunctions;
|
||||
}
|
||||
|
||||
@@ -356,10 +397,14 @@ void restoreConnections(const vector<BBlock*>& originalBlocks, vector<BBlock*>&
|
||||
BBlock* originalBlock = originalBlocks[i];
|
||||
BBlock* copiedBlock = copiedBlocks[i];
|
||||
|
||||
for (auto j : copiedBlock->getPrev()) {
|
||||
auto prevCopy = copiedBlock->getPrev();
|
||||
for (auto j : prevCopy) {
|
||||
copiedBlock->removePrev(j);
|
||||
}
|
||||
for (auto j : copiedBlock->getNext()) {
|
||||
|
||||
// Копируем, затем удаляем next связи
|
||||
auto nextCopy = copiedBlock->getNext();
|
||||
for (auto j : nextCopy) {
|
||||
copiedBlock->removeNext(j);
|
||||
}
|
||||
|
||||
@@ -488,9 +533,14 @@ void RenameIR(BBlock* block, map<BBlock*, BBlock*>& iDominators, map<string, int
|
||||
void buildIRSSAForm(map<FuncInfo*, vector<BBlock*>> fullIR, map<FuncInfo*, vector<BBlock*>>* result) {
|
||||
|
||||
for (auto item : fullIR) {
|
||||
|
||||
auto funcinfo = item.first;
|
||||
auto funcIRConst = item.second;
|
||||
|
||||
cout << "Testing " << item.first->funcName << endl;
|
||||
|
||||
|
||||
|
||||
vector<BBlock*> funcIR;
|
||||
|
||||
for (auto i : funcIRConst) {
|
||||
@@ -501,7 +551,6 @@ void buildIRSSAForm(map<FuncInfo*, vector<BBlock*>> fullIR, map<FuncInfo*, vecto
|
||||
for (auto i : funcIR) {
|
||||
//printBlock(i);
|
||||
}
|
||||
|
||||
auto dominators = findDominators(funcIR);
|
||||
|
||||
/*cout << endl << endl << endl << "DOMINATORS" << endl << endl << endl;
|
||||
@@ -515,7 +564,7 @@ void buildIRSSAForm(map<FuncInfo*, vector<BBlock*>> fullIR, map<FuncInfo*, vecto
|
||||
cout << endl;
|
||||
}*/
|
||||
|
||||
auto iDominators = findImmediateDominators(dominators, funcIR[0]);
|
||||
auto iDominators = findImmediateDominators1(dominators, funcIR[0]);
|
||||
|
||||
/*for (auto i : iDominators) {
|
||||
cout << "block - " << i.first->getNumber() << endl;
|
||||
@@ -564,14 +613,16 @@ void buildIRSSAForm(map<FuncInfo*, vector<BBlock*>> fullIR, map<FuncInfo*, vecto
|
||||
count[var->getValue()] = 0;
|
||||
|
||||
stack<BArgument*> tmp;
|
||||
BArgument* tmpArgument = new BArgument(CFG_ARG_TYPE::CONST, CFG_MEM_TYPE::COMMON_, "-1");
|
||||
tmp.push(tmpArgument);
|
||||
varStack[var->getValue()] = tmp;
|
||||
}
|
||||
|
||||
RenameIR(funcIR[0], iDominators, count, varStack);
|
||||
|
||||
//for (auto i : funcIR) {
|
||||
// printBlock(i);
|
||||
//}
|
||||
for (auto i : funcIR) {
|
||||
//printBlock(i);
|
||||
}
|
||||
//cout << endl << endl << endl << endl << endl;
|
||||
//for (auto i : funcIRConst) {
|
||||
// printBlock(i);
|
||||
|
||||
Reference in New Issue
Block a user