improved CFG functions style
This commit is contained in:
@@ -50,27 +50,28 @@ BBlock::BasicBlock(const BBlock& copyFrom)
|
||||
prev = copyFrom.prev;
|
||||
}
|
||||
|
||||
void BBlock::addInstruction(IR_Block* item)
|
||||
void BBlock::addInstruction(IR_Block* item, bool pushFront)
|
||||
{
|
||||
instructions.push_back(item);
|
||||
if (pushFront)
|
||||
instructions.insert(instructions.begin(), item);
|
||||
else
|
||||
instructions.push_back(item);
|
||||
item->setBasicBlock(this);
|
||||
}
|
||||
|
||||
void BBlock::addInstructionInFront(IR_Block* item)
|
||||
void BBlock::addInstructionBefore(IR_Block* item, Instruction* before)
|
||||
{
|
||||
instructions.insert(instructions.begin(), item);
|
||||
item->setBasicBlock(this);
|
||||
}
|
||||
checkNull(before, convertFileName(__FILE__).c_str(), __LINE__);
|
||||
checkNull(item, convertFileName(__FILE__).c_str(), __LINE__);
|
||||
|
||||
void BBlock::addInstructionBeforeInstruction(IR_Block* item, Instruction* instruction)
|
||||
{
|
||||
for (auto it = instructions.begin(); it != instructions.end(); ++it) {
|
||||
if ((*it)->getInstruction() == instruction) {
|
||||
if ((*it)->getInstruction() == before) {
|
||||
instructions.insert(it, item);
|
||||
item->setBasicBlock(this);
|
||||
return;
|
||||
}
|
||||
}
|
||||
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
|
||||
}
|
||||
|
||||
int BBlock::removePrev(BBlock* removed)
|
||||
@@ -529,7 +530,7 @@ static int buildReachingDefs(const vector<BBlock*>& CFG, const FuncInfo* currF,
|
||||
return iter;
|
||||
}
|
||||
|
||||
//Kosaraju<EFBFBD>Sharir algorithm
|
||||
//Kosaraju-Sharir algorithm
|
||||
static vector<int> getStronglyConnectedComps(vector<vector<int>>& g) {
|
||||
// 1. For each vertex u of the graph, mark u as unvisited. Let l be empty.
|
||||
auto size = g.size();
|
||||
|
||||
@@ -39,9 +39,8 @@ namespace SAPFOR
|
||||
BasicBlock(IR_Block* item);
|
||||
BasicBlock(const BasicBlock& copyFrom);
|
||||
|
||||
void addInstructionBeforeInstruction(IR_Block* item, Instruction* istruction);
|
||||
void addInstructionInFront(IR_Block* item);
|
||||
void addInstruction(IR_Block* item);
|
||||
void addInstructionBefore(IR_Block* item, Instruction* istruction);
|
||||
void addInstruction(IR_Block* item, bool pushFront = false);
|
||||
void addPrev(BasicBlock* prev_) { prev.push_back(prev_); }
|
||||
void addNext(BasicBlock* next_) { next.push_back(next_); }
|
||||
|
||||
|
||||
@@ -354,7 +354,7 @@ static void getBlocksWithFiFunctions(vector<BBlock*> blocks, set<BArgument*> glo
|
||||
Instruction* phiInstruction = new Instruction(CFG_OP::F_CALL, new BArgument(*fiFunc), new BArgument(*paramCount), var, dfBlock->getInstructions()[0]->getInstruction()->getOperator());
|
||||
|
||||
IR_Block* phiBlock = new IR_Block(phiInstruction);
|
||||
dfBlock->addInstructionInFront(phiBlock);
|
||||
dfBlock->addInstruction(phiBlock, true);
|
||||
|
||||
//blocksWithFiFunctions.push_back(dfBlock);
|
||||
}
|
||||
@@ -477,7 +477,7 @@ void RenameFiFunctionArgsVar(BBlock* block, map<string, stack<BArgument*>>& stac
|
||||
}
|
||||
|
||||
paramInstruction->setOperator(block->getInstructions()[0]->getInstruction()->getOperator());
|
||||
block->addInstructionBeforeInstruction(new IR_Block(paramInstruction), instruction);
|
||||
block->addInstructionBefore(new IR_Block(paramInstruction), instruction);
|
||||
|
||||
instruction->getArg2()->setValue(to_string(stoi(instruction->getArg2()->getValue()) + 1));
|
||||
i++;
|
||||
|
||||
Reference in New Issue
Block a user