WIP: testing on big data

This commit is contained in:
2025-05-27 23:34:45 +03:00
parent 6a84171382
commit b137ea5ef3
5 changed files with 86 additions and 19 deletions

View File

@@ -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;

View File

@@ -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);

View File

@@ -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;
@@ -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);

View File

@@ -1020,9 +1020,16 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
countOfTransform += removeDeadCode(func->funcPointer, allFuncInfo, commonBlocks);
}
else if (curr_regime == BUILD_IR_SSA_FORM)
buildIRSSAForm(fullIR, &ssaFormIR);
{
if (ssaFormIR.size() == 0) {
buildIRSSAForm(fullIR, &ssaFormIR);
}
}
else if (curr_regime == EXPLORE_IR_LOOPS)
exploreLoops(&ssaFormIR);
{
exploreLoops(&ssaFormIR, file_name);
}
else if (curr_regime == TEST_PASS)
{
//test pass

View File

@@ -184,3 +184,5 @@ std::map<PTR_LLND, std::pair<std::string, int>> sgExprs;
//for EXPLORE_IR_LOOPS and BUILD_IR_SSA_FORM
map<FuncInfo*, vector<SAPFOR::BasicBlock*>> ssaFormIR;
//
int test = 0;