[midend]修改原因同上一次commit
This commit is contained in:
@@ -233,7 +233,7 @@ Function * Function::clone(const std::string &suffix) const {
|
|||||||
// }
|
// }
|
||||||
ss << oldAllocInst->getName() << suffix;
|
ss << oldAllocInst->getName() << suffix;
|
||||||
auto newAllocInst =
|
auto newAllocInst =
|
||||||
new AllocaInst(oldAllocInst->getType(), dims, oldNewBlockMap.at(oldAllocInst->getParent()), ss.str());
|
new AllocaInst(oldAllocInst->getType(), oldNewBlockMap.at(oldAllocInst->getParent()), ss.str());
|
||||||
ss.str("");
|
ss.str("");
|
||||||
oldNewValueMap.emplace(oldAllocInst, newAllocInst);
|
oldNewValueMap.emplace(oldAllocInst, newAllocInst);
|
||||||
if (isAddedToCreate.find(oldAllocInst) == isAddedToCreate.end()) {
|
if (isAddedToCreate.find(oldAllocInst) == isAddedToCreate.end()) {
|
||||||
@@ -259,7 +259,7 @@ Function * Function::clone(const std::string &suffix) const {
|
|||||||
// }
|
// }
|
||||||
ss << oldAllocInst->getName() << suffix;
|
ss << oldAllocInst->getName() << suffix;
|
||||||
auto newAllocInst =
|
auto newAllocInst =
|
||||||
new AllocaInst(oldAllocInst->getType(), dims, oldNewBlockMap.at(oldAllocInst->getParent()), ss.str());
|
new AllocaInst(oldAllocInst->getType(), oldNewBlockMap.at(oldAllocInst->getParent()), ss.str());
|
||||||
ss.str("");
|
ss.str("");
|
||||||
oldNewValueMap.emplace(oldAllocInst, newAllocInst);
|
oldNewValueMap.emplace(oldAllocInst, newAllocInst);
|
||||||
if (isAddedToCreate.find(oldAllocInst) == isAddedToCreate.end()) {
|
if (isAddedToCreate.find(oldAllocInst) == isAddedToCreate.end()) {
|
||||||
@@ -486,7 +486,7 @@ Function * Function::clone(const std::string &suffix) const {
|
|||||||
// for (const auto &index : oldStoreInst->getIndices()) {
|
// for (const auto &index : oldStoreInst->getIndices()) {
|
||||||
// newIndices.emplace_back(oldNewValueMap.at(index->getValue()));
|
// newIndices.emplace_back(oldNewValueMap.at(index->getValue()));
|
||||||
// }
|
// }
|
||||||
auto newStoreInst = new StoreInst(newValue, newPointer, newIndices,
|
auto newStoreInst = new StoreInst(newValue, newPointer,
|
||||||
oldNewBlockMap.at(oldStoreInst->getParent()), oldStoreInst->getName());
|
oldNewBlockMap.at(oldStoreInst->getParent()), oldStoreInst->getName());
|
||||||
oldNewValueMap.emplace(oldStoreInst, newStoreInst);
|
oldNewValueMap.emplace(oldStoreInst, newStoreInst);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ void Reg2MemContext::allocateMemoryForSSAValues(Function *func) {
|
|||||||
// 默认情况下,将所有参数是提升到内存
|
// 默认情况下,将所有参数是提升到内存
|
||||||
if (isPromotableToMemory(arg)) {
|
if (isPromotableToMemory(arg)) {
|
||||||
// 参数的类型就是 AllocaInst 需要分配的类型
|
// 参数的类型就是 AllocaInst 需要分配的类型
|
||||||
AllocaInst *alloca = builder->createAllocaInst(Type::getPointerType(arg->getType()), {}, arg->getName() + ".reg2mem");
|
AllocaInst *alloca = builder->createAllocaInst(Type::getPointerType(arg->getType()), arg->getName() + ".reg2mem");
|
||||||
// 将参数值 store 到 alloca 中 (这是 Mem2Reg 逆转的关键一步)
|
// 将参数值 store 到 alloca 中 (这是 Mem2Reg 逆转的关键一步)
|
||||||
valueToAllocaMap[arg] = alloca;
|
valueToAllocaMap[arg] = alloca;
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ void Reg2MemContext::allocateMemoryForSSAValues(Function *func) {
|
|||||||
// AllocaInst 应该在入口块,而不是当前指令所在块
|
// AllocaInst 应该在入口块,而不是当前指令所在块
|
||||||
// 这里我们只是创建,并稍后调整其位置
|
// 这里我们只是创建,并稍后调整其位置
|
||||||
// 通常的做法是在循环结束后统一将 alloca 放到 entryBlock 的顶部
|
// 通常的做法是在循环结束后统一将 alloca 放到 entryBlock 的顶部
|
||||||
AllocaInst *alloca = builder->createAllocaInst(Type::getPointerType(inst.get()->getType()), {}, inst.get()->getName() + ".reg2mem");
|
AllocaInst *alloca = builder->createAllocaInst(Type::getPointerType(inst.get()->getType()), inst.get()->getName() + ".reg2mem");
|
||||||
valueToAllocaMap[inst.get()] = alloca;
|
valueToAllocaMap[inst.get()] = alloca;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ bool SysYCFGOptUtils::SysYDelEmptyBlock(Function *func, IRBuilder* pBuilder) {
|
|||||||
SysYIROptUtils::usedelete(thelastinst->get());
|
SysYIROptUtils::usedelete(thelastinst->get());
|
||||||
thelastinst = basicBlock->getInstructions().erase(thelastinst);
|
thelastinst = basicBlock->getInstructions().erase(thelastinst);
|
||||||
pBuilder->setPosition(basicBlock.get(), basicBlock->end());
|
pBuilder->setPosition(basicBlock.get(), basicBlock->end());
|
||||||
pBuilder->createUncondBrInst(thebrBlock, {});
|
pBuilder->createUncondBrInst(thebrBlock);
|
||||||
changed = true; // 标记IR被修改
|
changed = true; // 标记IR被修改
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -348,7 +348,7 @@ bool SysYCFGOptUtils::SysYDelEmptyBlock(Function *func, IRBuilder* pBuilder) {
|
|||||||
SysYIROptUtils::usedelete(thelastinst->get());
|
SysYIROptUtils::usedelete(thelastinst->get());
|
||||||
thelastinst = basicBlock->getInstructions().erase(thelastinst);
|
thelastinst = basicBlock->getInstructions().erase(thelastinst);
|
||||||
pBuilder->setPosition(basicBlock.get(), basicBlock->end());
|
pBuilder->setPosition(basicBlock.get(), basicBlock->end());
|
||||||
pBuilder->createUncondBrInst(thebrBlock, {});
|
pBuilder->createUncondBrInst(thebrBlock);
|
||||||
changed = true; // 标记IR被修改
|
changed = true; // 标记IR被修改
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -528,7 +528,7 @@ bool SysYCFGOptUtils::SysYCondBr2Br(Function *func, IRBuilder* pBuilder) {
|
|||||||
if ((constfloat_Use && constfloat == 1.0F) || (constint_Use && constint == 1)) {
|
if ((constfloat_Use && constfloat == 1.0F) || (constint_Use && constint == 1)) {
|
||||||
// cond为true或非0
|
// cond为true或非0
|
||||||
pBuilder->setPosition(basicblock.get(), basicblock->end());
|
pBuilder->setPosition(basicblock.get(), basicblock->end());
|
||||||
pBuilder->createUncondBrInst(thenBlock, {});
|
pBuilder->createUncondBrInst(thenBlock);
|
||||||
|
|
||||||
// 更新CFG关系
|
// 更新CFG关系
|
||||||
basicblock->removeSuccessor(elseBlock);
|
basicblock->removeSuccessor(elseBlock);
|
||||||
@@ -546,7 +546,7 @@ bool SysYCFGOptUtils::SysYCondBr2Br(Function *func, IRBuilder* pBuilder) {
|
|||||||
} else { // cond为false或0
|
} else { // cond为false或0
|
||||||
|
|
||||||
pBuilder->setPosition(basicblock.get(), basicblock->end());
|
pBuilder->setPosition(basicblock.get(), basicblock->end());
|
||||||
pBuilder->createUncondBrInst(elseBlock, {});
|
pBuilder->createUncondBrInst(elseBlock);
|
||||||
|
|
||||||
// 更新CFG关系
|
// 更新CFG关系
|
||||||
basicblock->removeSuccessor(thenBlock);
|
basicblock->removeSuccessor(thenBlock);
|
||||||
|
|||||||
Reference in New Issue
Block a user