fixed code style
This commit is contained in:
@@ -124,7 +124,7 @@ static vector<T>* getCommonElements(const vector<vector<T>>* vectors)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static map<BBlock*, vector<BBlock*>> findDominators(vector<BBlock*> blocks)
|
static map<BBlock*, vector<BBlock*>> findDominators(const vector<BBlock*>& blocks)
|
||||||
{
|
{
|
||||||
map<BBlock*, vector<BBlock*>> result;
|
map<BBlock*, vector<BBlock*>> result;
|
||||||
|
|
||||||
@@ -133,7 +133,7 @@ static map<BBlock*, vector<BBlock*>> findDominators(vector<BBlock*> blocks)
|
|||||||
{
|
{
|
||||||
changed = false;
|
changed = false;
|
||||||
|
|
||||||
for (auto currentBlock : blocks)
|
for (auto& currentBlock : blocks)
|
||||||
{
|
{
|
||||||
auto pred = currentBlock->getPrev();
|
auto pred = currentBlock->getPrev();
|
||||||
auto prevDominators = new vector<vector<BBlock*>>();
|
auto prevDominators = new vector<vector<BBlock*>>();
|
||||||
@@ -166,7 +166,7 @@ static void renumberBlocks(BBlock* current, int* n, map<int, int>* res, set<BBlo
|
|||||||
return a->getInstructions()[0]->getInstruction()->getOperator()->lineNumber() > b->getInstructions()[0]->getInstruction()->getOperator()->lineNumber();
|
return a->getInstructions()[0]->getInstruction()->getOperator()->lineNumber() > b->getInstructions()[0]->getInstruction()->getOperator()->lineNumber();
|
||||||
});
|
});
|
||||||
|
|
||||||
for (auto i : nextBlocks)
|
for (auto& i : nextBlocks)
|
||||||
renumberBlocks(i, n, res, visited);
|
renumberBlocks(i, n, res, visited);
|
||||||
|
|
||||||
(*res)[current->getNumber()] = *n;
|
(*res)[current->getNumber()] = *n;
|
||||||
@@ -214,7 +214,7 @@ static BBlock* findImmediateDominatorsDfsHelper(BBlock* block, BBlock* currentBl
|
|||||||
if (find(dominators[block].begin(), dominators[block].end(), currentBlock) != dominators[block].end())
|
if (find(dominators[block].begin(), dominators[block].end(), currentBlock) != dominators[block].end())
|
||||||
currentImmediateDominator = currentBlock;
|
currentImmediateDominator = currentBlock;
|
||||||
|
|
||||||
for (auto nextBlock : currentBlock->getNext())
|
for (auto& nextBlock : currentBlock->getNext())
|
||||||
{
|
{
|
||||||
auto result = findImmediateDominatorsDfsHelper(block, nextBlock, currentImmediateDominator, visited, dominators);
|
auto result = findImmediateDominatorsDfsHelper(block, nextBlock, currentImmediateDominator, visited, dominators);
|
||||||
|
|
||||||
@@ -239,13 +239,13 @@ static map<BBlock*, BBlock*> findImmediateDominators1(const map<BBlock*, vector<
|
|||||||
const auto& doms = pair.second;
|
const auto& doms = pair.second;
|
||||||
|
|
||||||
BBlock* candidate = NULL;
|
BBlock* candidate = NULL;
|
||||||
for (auto d : doms)
|
for (auto& d : doms)
|
||||||
{
|
{
|
||||||
if (d == b)
|
if (d == b)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
bool isImmediate = true;
|
bool isImmediate = true;
|
||||||
for (auto other : doms)
|
for (auto& other : doms)
|
||||||
{
|
{
|
||||||
if (other == b || other == d)
|
if (other == b || other == d)
|
||||||
continue;
|
continue;
|
||||||
@@ -370,7 +370,7 @@ static void getBlocksWithFiFunctions(const vector<BBlock*> blocks, set<BArgument
|
|||||||
auto block = *worklist.begin();
|
auto block = *worklist.begin();
|
||||||
worklist.erase(block);
|
worklist.erase(block);
|
||||||
|
|
||||||
for (auto dfBlock : dominatorBorders[block])
|
for (auto& dfBlock : dominatorBorders[block])
|
||||||
{
|
{
|
||||||
if (hasFiFunction.find(dfBlock) == hasFiFunction.end())
|
if (hasFiFunction.find(dfBlock) == hasFiFunction.end())
|
||||||
{
|
{
|
||||||
@@ -450,7 +450,7 @@ static BArgument* newName(BArgument* var, map<string, int>& counter, map<string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void renameFiFunctionResultVar(BBlock* block, map<string, int>& counter, map<string, stack<BArgument*>>& stack) {
|
static void renameFiFunctionResultVar(BBlock* block, map<string, int>& counter, map<string, stack<BArgument*>>& stack) {
|
||||||
for (auto irBlock : block->getInstructions())
|
for (auto& irBlock : block->getInstructions())
|
||||||
{
|
{
|
||||||
auto instruction = irBlock->getInstruction();
|
auto instruction = irBlock->getInstruction();
|
||||||
if (instruction->getOperation() == CFG_OP::F_CALL && instruction->getArg1() != NULL &&
|
if (instruction->getOperation() == CFG_OP::F_CALL && instruction->getArg1() != NULL &&
|
||||||
@@ -463,7 +463,7 @@ static void renameFiFunctionResultVar(BBlock* block, map<string, int>& counter,
|
|||||||
|
|
||||||
static void renameInstructionVars(BBlock* block, map<string, int>& counter, map<string, stack<BArgument*>>& stack)
|
static void renameInstructionVars(BBlock* block, map<string, int>& counter, map<string, stack<BArgument*>>& stack)
|
||||||
{
|
{
|
||||||
for (auto irBlock : block->getInstructions())
|
for (auto& irBlock : block->getInstructions())
|
||||||
{
|
{
|
||||||
auto instruction = irBlock->getInstruction();
|
auto instruction = irBlock->getInstruction();
|
||||||
|
|
||||||
@@ -483,7 +483,7 @@ static void renameFiFunctionArgsVar(BBlock* block, map<string, stack<BArgument*>
|
|||||||
auto size = block->getInstructions().size();
|
auto size = block->getInstructions().size();
|
||||||
auto& instructions = block->getInstructions();
|
auto& instructions = block->getInstructions();
|
||||||
|
|
||||||
for (auto i = 0; i < size; i++)
|
for (size_t i = 0; i < size; ++i)
|
||||||
{
|
{
|
||||||
auto irBlock = instructions[i];
|
auto irBlock = instructions[i];
|
||||||
auto instruction = irBlock->getInstruction();
|
auto instruction = irBlock->getInstruction();
|
||||||
@@ -518,9 +518,8 @@ static vector<BBlock*> findBlocksWithValue(map<BBlock*, BBlock*>& iDominators, B
|
|||||||
vector<BBlock*> result;
|
vector<BBlock*> result;
|
||||||
|
|
||||||
// Проходим по всем элементам map
|
// Проходим по всем элементам map
|
||||||
for (auto& pair : iDominators)
|
for (auto& pair : iDominators)
|
||||||
// Если значение равно x, добавляем ключ в результат
|
if (pair.second == x) // Если значение равно x, добавляем ключ в результат
|
||||||
if (pair.second == x)
|
|
||||||
result.push_back(pair.first);
|
result.push_back(pair.first);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -531,10 +530,10 @@ static void renameIR(BBlock* block, map<BBlock*, BBlock*>& iDominators, map<stri
|
|||||||
renameFiFunctionResultVar(block, counter, stack);
|
renameFiFunctionResultVar(block, counter, stack);
|
||||||
renameInstructionVars(block, counter, stack);
|
renameInstructionVars(block, counter, stack);
|
||||||
|
|
||||||
for (auto* successor : block->getNext())
|
for (auto& successor : block->getNext())
|
||||||
renameFiFunctionArgsVar(successor, stack);
|
renameFiFunctionArgsVar(successor, stack);
|
||||||
|
|
||||||
for (auto* child : findBlocksWithValue(iDominators, block))
|
for (auto& child : findBlocksWithValue(iDominators, block))
|
||||||
renameIR(child, iDominators, counter, stack);
|
renameIR(child, iDominators, counter, stack);
|
||||||
|
|
||||||
for (auto& irBlock : block->getInstructions())
|
for (auto& irBlock : block->getInstructions())
|
||||||
@@ -567,12 +566,12 @@ void buildIRSSAForm(const map<FuncInfo*, vector<BBlock*>>& fullIR,
|
|||||||
|
|
||||||
vector<BBlock*> funcIR;
|
vector<BBlock*> funcIR;
|
||||||
|
|
||||||
for (auto i : funcIRConst)
|
for (auto& i : funcIRConst)
|
||||||
funcIR.push_back(new BBlock(*i));
|
funcIR.push_back(new BBlock(*i));
|
||||||
|
|
||||||
restoreConnections(funcIRConst, funcIR);
|
restoreConnections(funcIRConst, funcIR);
|
||||||
|
|
||||||
for (auto i : funcIR) {
|
for (auto& i : funcIR) {
|
||||||
//printBlock(i);
|
//printBlock(i);
|
||||||
}
|
}
|
||||||
auto dominators = findDominators(funcIR);
|
auto dominators = findDominators(funcIR);
|
||||||
@@ -631,7 +630,7 @@ void buildIRSSAForm(const map<FuncInfo*, vector<BBlock*>>& fullIR,
|
|||||||
map<string, int> count;
|
map<string, int> count;
|
||||||
map<string, stack<BArgument*>> varStack;
|
map<string, stack<BArgument*>> varStack;
|
||||||
|
|
||||||
for (auto var : globals)
|
for (auto& var : globals)
|
||||||
{
|
{
|
||||||
count[var->getValue()] = 0;
|
count[var->getValue()] = 0;
|
||||||
|
|
||||||
@@ -643,7 +642,7 @@ void buildIRSSAForm(const map<FuncInfo*, vector<BBlock*>>& fullIR,
|
|||||||
|
|
||||||
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user