diff --git a/sapfor/experts/Sapfor_2017/_src/CFGraph/IRSSAForm.cpp b/sapfor/experts/Sapfor_2017/_src/CFGraph/IRSSAForm.cpp index ea82f27..4ba0232 100644 --- a/sapfor/experts/Sapfor_2017/_src/CFGraph/IRSSAForm.cpp +++ b/sapfor/experts/Sapfor_2017/_src/CFGraph/IRSSAForm.cpp @@ -50,7 +50,7 @@ static void printBlock(BBlock* block) { i->getInstruction()->getArg2()->setValue(i->getInstruction()->getArg2()->getValue() + to_string(i->getInstruction()->getArg2()->getNumber())); } - cout << i->getNumber() << " " << i->getInstruction()->dump() << (i->getInstruction()->getResult() != nullptr ? " 1 " : " 0 ") << (i->getInstruction()->getArg1() != nullptr ? "1 " : "0 ") << (i->getInstruction()->getArg2() != nullptr ? "1 " : "0 ") << endl; + cout << i->getNumber() << " " << i->getInstruction()->dump() << endl;// << (i->getInstruction()->getResult() != nullptr ? " 1 " : " 0 ") << (i->getInstruction()->getArg1() != nullptr ? "1 " : "0 ") << (i->getInstruction()->getArg2() != nullptr ? "1 " : "0 ") << endl; /*if (i->getInstruction()->getResult() != nullptr) { cout << "num - " << i->getInstruction()->getResult()->getNumber() << endl; @@ -320,6 +320,8 @@ static vector getBlocksWithFiFunctions(vector blocks, setgetNumber() << " with var " << var->getValue() << endl; + IR_Block* phiBlock = new IR_Block(phiInstruction); dfBlock->addInstructionInFront(phiBlock); @@ -421,11 +423,13 @@ void RenameInstructionVars(BBlock* block, map& counter, map>& stack) { + cout << "test" << endl; auto size = block->getInstructions().size(); for (auto i = 0; i < size; i++) { auto irBlock = block->getInstructions()[i]; auto instruction = irBlock->getInstruction(); if (instruction->getOperation() == CFG_OP::F_CALL && instruction->getArg1() != nullptr && instruction->getArg1()->getValue() == "FI_FUNCTION" && instruction->getResult() != nullptr) { + //cout << "test" << endl; auto paramInstruction = new Instruction(CFG_OP::PARAM, stack[instruction->getResult()->getValue()].top()); block->addInstructionBeforeInstruction(new IR_Block(paramInstruction), instruction); @@ -435,8 +439,21 @@ void RenameFiFunctionArgsVar(BBlock* block, map>& stac } } +vector findBlocksWithValue(map& iDominators, BBlock* x) { + vector result; -void RenameIR(BBlock* block, map>& dominatorTree, map& counter, map>& stack) { + // Проходим по всем элементам map + for (auto& pair : iDominators) { + // Если значение равно x, добавляем ключ в результат + if (pair.second == x) { + result.push_back(pair.first); + } + } + + return result; +} + +void RenameIR(BBlock* block, map& iDominators, map& counter, map>& stack) { RenameFiFunctionResultVar(block, counter, stack); @@ -446,8 +463,9 @@ void RenameIR(BBlock* block, map>& dominatorTree, mapgetInstructions()) { @@ -484,12 +502,12 @@ map> buildIRSSAForm(map> f restoreConnections(funcIRConst, funcIR); for (auto i : funcIR) { - printBlock(i); + //printBlock(i); } auto dominators = findDominators(funcIR); - cout << endl << endl << endl << "DOMINATORS" << endl << endl << endl; + /*cout << endl << endl << endl << "DOMINATORS" << endl << endl << endl; for (auto i : dominators) { cout << "block - " << i.first->getNumber() << endl; @@ -498,33 +516,34 @@ map> buildIRSSAForm(map> f } cout << endl; - } + }*/ auto iDominators = findImmediateDominators(dominators, funcIR[0]); - for (auto i : iDominators) { + /*for (auto i : iDominators) { cout << "block - " << i.first->getNumber() << endl; cout << "Idominators - " << i.second->getNumber() << endl; cout << endl; } - + */ auto dominatorBorders = findDominatorBorders(funcIR, iDominators); + - - for (auto i : dominatorBorders) { + /*for (auto i : dominatorBorders) { cout << "block - " << i.first->getNumber() << endl; for (auto j : i.second) { cout << "border - " << j->getNumber() << endl; } cout << endl; - } + }*/ + auto globalsAndVarBlocks = getGlobalsAndVarBlocks(funcIR); auto globals = globalsAndVarBlocks.first; auto varBlocks = globalsAndVarBlocks.second; - for (auto i : globals) { + /*for (auto i : globals) { cout << i->getValue() << " " << ToString(i->getType()) << " " << i->getNumber() << endl; } @@ -537,6 +556,7 @@ map> buildIRSSAForm(map> f cout << endl; } cout << endl; + */ funcResult = getBlocksWithFiFunctions(funcIR, globals, varBlocks, dominatorBorders); @@ -550,8 +570,7 @@ map> buildIRSSAForm(map> f varStack[var->getValue()] = tmp; } - RenameIR(funcIR[0], dominatorBorders, count, varStack); - + RenameIR(funcIR[0], iDominators, count, varStack); for (auto i : funcIR) { printBlock(i);