[midend-CFGOpt]修复部分指令删除逻辑错误
This commit is contained in:
@ -42,7 +42,7 @@ bool SysYCFGOptUtils::SysYDelInstAfterBr(Function *func) {
|
||||
++Branchiter;
|
||||
while (Branchiter != instructions.end()) {
|
||||
changed = true;
|
||||
Branchiter = instructions.erase(Branchiter);
|
||||
Branchiter = SysYIROptUtils::usedelete(Branchiter); // 删除指令
|
||||
}
|
||||
|
||||
if (Branch) { // 更新前驱后继关系
|
||||
@ -91,7 +91,7 @@ bool SysYCFGOptUtils::SysYBlockMerge(Function *func) {
|
||||
BasicBlock *block = blockiter->get();
|
||||
BasicBlock *nextBlock = blockiter->get()->getSuccessors()[0];
|
||||
// auto nextarguments = nextBlock->getArguments();
|
||||
// 删除br指令
|
||||
// 删除block的br指令
|
||||
if (block->getNumInstructions() != 0) {
|
||||
auto thelastinstinst = block->terminator();
|
||||
if (thelastinstinst->get()->isUnconditional()) {
|
||||
@ -103,14 +103,20 @@ bool SysYCFGOptUtils::SysYBlockMerge(Function *func) {
|
||||
if (brinst->getThenBlock() == brinst->getElseBlock()) {
|
||||
thelastinstinst = SysYIROptUtils::usedelete(thelastinstinst);
|
||||
}
|
||||
else{
|
||||
assert(false && "SysYBlockMerge: unexpected conditional branch with different then and else blocks");
|
||||
}
|
||||
}
|
||||
}
|
||||
// 将后继块的指令移动到当前块
|
||||
// 并将后继块的父指针改为当前块
|
||||
for (auto institer = nextBlock->begin(); institer != nextBlock->end();) {
|
||||
institer->get()->setParent(block);
|
||||
block->getInstructions().emplace_back(institer->release());
|
||||
institer = nextBlock->getInstructions().erase(institer);
|
||||
// institer->get()->setParent(block);
|
||||
// block->getInstructions().emplace_back(institer->release());
|
||||
// 用usedelete删除会导致use关系被删除我只希望移动指令到当前块
|
||||
// institer = SysYIROptUtils::usedelete(institer);
|
||||
// institer = nextBlock->getInstructions().erase(institer);
|
||||
nextBlock->moveInst(institer, block->getInstructions().end(), block);
|
||||
}
|
||||
// 更新前驱后继关系,类似树节点操作
|
||||
block->removeSuccessor(nextBlock);
|
||||
|
||||
Reference in New Issue
Block a user