WIP: testing on big data
This commit is contained in:
@@ -1945,11 +1945,18 @@ Instruction* findInstructionAfterLoop(const std::vector<SAPFOR::BasicBlock*>& lo
|
|||||||
return nullptr; // не нашли
|
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& i : *fullIR)
|
||||||
{
|
{
|
||||||
//for (auto j : i.second)
|
//for (auto j : i.second)
|
||||||
// printBlock(j);
|
// printblock(j);
|
||||||
|
|
||||||
|
if (!isEqual(fileName, i.first->fileName))
|
||||||
|
continue;
|
||||||
|
|
||||||
map<int, int> visited;
|
map<int, int> visited;
|
||||||
for (auto i : i.second)
|
for (auto i : i.second)
|
||||||
@@ -2005,24 +2012,24 @@ void exploreLoops(map<FuncInfo*, vector<SAPFOR::BasicBlock*>>* fullIR) {
|
|||||||
if (firstInstruction->getOperator()->variant() == FOR_NODE) {
|
if (firstInstruction->getOperator()->variant() == FOR_NODE) {
|
||||||
SgForStmt* stmt = isSgForStmt(firstInstruction->getOperator());
|
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) {
|
else if (firstInstruction->getOperator()->variant() == WHILE_NODE) {
|
||||||
SgWhileStmt* stmt = isSgWhileStmt(firstInstruction->getOperator());
|
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) {
|
else if (firstInstruction->getOperator()->variant() == DO_WHILE_NODE) {
|
||||||
SgWhileStmt* stmt = isSgDoWhileStmt(firstInstruction->getOperator());
|
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) {
|
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 {
|
else {
|
||||||
|
|
||||||
cout << "goto loop" << firstInstruction->getOperator()->sunparse() << endl;
|
cout << "goto loop" << endl;// firstInstruction->getOperator()->sunparse() << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "loop start line " << tmpLoop->lineNum << 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);
|
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);
|
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) {
|
if (block->getPrev().size() > 1) {
|
||||||
for (auto prev : block->getPrev()) {
|
for (auto prev : block->getPrev()) {
|
||||||
auto tmpBlock = prev;
|
auto tmpBlock = prev;
|
||||||
|
auto test = iDominators[block];
|
||||||
|
auto test2 = iDominators[prev];
|
||||||
|
|
||||||
while (tmpBlock != iDominators[block]) {
|
while (tmpBlock != iDominators[block]) {
|
||||||
result[tmpBlock].push_back(block);
|
result[tmpBlock].push_back(block);
|
||||||
@@ -219,6 +221,45 @@ static BBlock* findImmediateDominatorsDfsHelper(BBlock* block, BBlock* currentBl
|
|||||||
return nullptr;
|
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) {
|
static map<BBlock*, BBlock*> findImmediateDominators(map<BBlock*, vector<BBlock*>>& dominators, BBlock* fistBlock) {
|
||||||
map<BBlock*, BBlock*> iDominators;
|
map<BBlock*, BBlock*> iDominators;
|
||||||
|
|
||||||
@@ -356,10 +397,14 @@ void restoreConnections(const vector<BBlock*>& originalBlocks, vector<BBlock*>&
|
|||||||
BBlock* originalBlock = originalBlocks[i];
|
BBlock* originalBlock = originalBlocks[i];
|
||||||
BBlock* copiedBlock = copiedBlocks[i];
|
BBlock* copiedBlock = copiedBlocks[i];
|
||||||
|
|
||||||
for (auto j : copiedBlock->getPrev()) {
|
auto prevCopy = copiedBlock->getPrev();
|
||||||
|
for (auto j : prevCopy) {
|
||||||
copiedBlock->removePrev(j);
|
copiedBlock->removePrev(j);
|
||||||
}
|
}
|
||||||
for (auto j : copiedBlock->getNext()) {
|
|
||||||
|
// Копируем, затем удаляем next связи
|
||||||
|
auto nextCopy = copiedBlock->getNext();
|
||||||
|
for (auto j : nextCopy) {
|
||||||
copiedBlock->removeNext(j);
|
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) {
|
void buildIRSSAForm(map<FuncInfo*, vector<BBlock*>> fullIR, map<FuncInfo*, vector<BBlock*>>* result) {
|
||||||
|
|
||||||
for (auto item : fullIR) {
|
for (auto item : fullIR) {
|
||||||
|
|
||||||
auto funcinfo = item.first;
|
auto funcinfo = item.first;
|
||||||
auto funcIRConst = item.second;
|
auto funcIRConst = item.second;
|
||||||
|
|
||||||
|
cout << "Testing " << item.first->funcName << endl;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
vector<BBlock*> funcIR;
|
vector<BBlock*> funcIR;
|
||||||
|
|
||||||
for (auto i : funcIRConst) {
|
for (auto i : funcIRConst) {
|
||||||
@@ -501,7 +551,6 @@ void buildIRSSAForm(map<FuncInfo*, vector<BBlock*>> fullIR, map<FuncInfo*, vecto
|
|||||||
for (auto i : funcIR) {
|
for (auto i : funcIR) {
|
||||||
//printBlock(i);
|
//printBlock(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto dominators = findDominators(funcIR);
|
auto dominators = findDominators(funcIR);
|
||||||
|
|
||||||
/*cout << endl << endl << endl << "DOMINATORS" << endl << endl << endl;
|
/*cout << endl << endl << endl << "DOMINATORS" << endl << endl << endl;
|
||||||
@@ -515,7 +564,7 @@ void buildIRSSAForm(map<FuncInfo*, vector<BBlock*>> fullIR, map<FuncInfo*, vecto
|
|||||||
cout << endl;
|
cout << endl;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
auto iDominators = findImmediateDominators(dominators, funcIR[0]);
|
auto iDominators = findImmediateDominators1(dominators, funcIR[0]);
|
||||||
|
|
||||||
/*for (auto i : iDominators) {
|
/*for (auto i : iDominators) {
|
||||||
cout << "block - " << i.first->getNumber() << endl;
|
cout << "block - " << i.first->getNumber() << endl;
|
||||||
@@ -564,14 +613,16 @@ void buildIRSSAForm(map<FuncInfo*, vector<BBlock*>> fullIR, map<FuncInfo*, vecto
|
|||||||
count[var->getValue()] = 0;
|
count[var->getValue()] = 0;
|
||||||
|
|
||||||
stack<BArgument*> tmp;
|
stack<BArgument*> tmp;
|
||||||
|
BArgument* tmpArgument = new BArgument(CFG_ARG_TYPE::CONST, CFG_MEM_TYPE::COMMON_, "-1");
|
||||||
|
tmp.push(tmpArgument);
|
||||||
varStack[var->getValue()] = tmp;
|
varStack[var->getValue()] = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
RenameIR(funcIR[0], iDominators, count, varStack);
|
RenameIR(funcIR[0], iDominators, count, varStack);
|
||||||
|
|
||||||
//for (auto i : funcIR) {
|
for (auto i : funcIR) {
|
||||||
//printBlock(i);
|
//printBlock(i);
|
||||||
//}
|
}
|
||||||
//cout << endl << endl << endl << endl << endl;
|
//cout << endl << endl << endl << endl << endl;
|
||||||
//for (auto i : funcIRConst) {
|
//for (auto i : funcIRConst) {
|
||||||
// printBlock(i);
|
// printBlock(i);
|
||||||
|
|||||||
@@ -1020,9 +1020,16 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
|
|||||||
countOfTransform += removeDeadCode(func->funcPointer, allFuncInfo, commonBlocks);
|
countOfTransform += removeDeadCode(func->funcPointer, allFuncInfo, commonBlocks);
|
||||||
}
|
}
|
||||||
else if (curr_regime == BUILD_IR_SSA_FORM)
|
else if (curr_regime == BUILD_IR_SSA_FORM)
|
||||||
|
{
|
||||||
|
if (ssaFormIR.size() == 0) {
|
||||||
buildIRSSAForm(fullIR, &ssaFormIR);
|
buildIRSSAForm(fullIR, &ssaFormIR);
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (curr_regime == EXPLORE_IR_LOOPS)
|
else if (curr_regime == EXPLORE_IR_LOOPS)
|
||||||
exploreLoops(&ssaFormIR);
|
{
|
||||||
|
exploreLoops(&ssaFormIR, file_name);
|
||||||
|
}
|
||||||
|
|
||||||
else if (curr_regime == TEST_PASS)
|
else if (curr_regime == TEST_PASS)
|
||||||
{
|
{
|
||||||
//test pass
|
//test pass
|
||||||
|
|||||||
@@ -184,3 +184,5 @@ std::map<PTR_LLND, std::pair<std::string, int>> sgExprs;
|
|||||||
//for EXPLORE_IR_LOOPS and BUILD_IR_SSA_FORM
|
//for EXPLORE_IR_LOOPS and BUILD_IR_SSA_FORM
|
||||||
map<FuncInfo*, vector<SAPFOR::BasicBlock*>> ssaFormIR;
|
map<FuncInfo*, vector<SAPFOR::BasicBlock*>> ssaFormIR;
|
||||||
//
|
//
|
||||||
|
|
||||||
|
int test = 0;
|
||||||
Reference in New Issue
Block a user