[midend]将alloca声明统一到entry块,增加mem2reg的机会,TODO:不是很明白为什么开了优化过不了一些样例正在排查原因
This commit is contained in:
@@ -108,6 +108,10 @@ void PassManager::runOptimizationPipeline(Module* moduleIR, IRBuilder* builderIR
|
|||||||
printPasses();
|
printPasses();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->clearPasses();
|
||||||
|
this->addPass(&DCE::ID);
|
||||||
|
this->run();
|
||||||
|
|
||||||
if (DEBUG) std::cout << "--- Custom optimization sequence finished ---\n";
|
if (DEBUG) std::cout << "--- Custom optimization sequence finished ---\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -586,7 +586,18 @@ std::any SysYIRGenerator::visitConstDecl(SysYParser::ConstDeclContext *ctx) {
|
|||||||
|
|
||||||
// 显式地为局部常量在栈上分配空间
|
// 显式地为局部常量在栈上分配空间
|
||||||
// alloca 的类型将是指针指向常量类型,例如 `int*` 或 `int[2][3]*`
|
// alloca 的类型将是指针指向常量类型,例如 `int*` 或 `int[2][3]*`
|
||||||
|
// 将 alloca 全部集中到entry函数中
|
||||||
|
// 记录当前位置
|
||||||
|
BasicBlock *curBB = builder.getBasicBlock();
|
||||||
|
auto curPos =builder.getPosition();
|
||||||
|
Function *currentFunction = builder.getBasicBlock()->getParent();
|
||||||
|
BasicBlock *entryBB = currentFunction->getEntryBlock();
|
||||||
|
// 在terminator前插入
|
||||||
|
auto entryPos = entryBB->terminator();
|
||||||
|
builder.setPosition(entryBB, entryPos);
|
||||||
AllocaInst *alloca = builder.createAllocaInst(Type::getPointerType(variableType), name);
|
AllocaInst *alloca = builder.createAllocaInst(Type::getPointerType(variableType), name);
|
||||||
|
// 恢复当前位置
|
||||||
|
builder.setPosition(curBB, curPos);
|
||||||
|
|
||||||
ArrayValueTree *root = std::any_cast<ArrayValueTree *>(constDef->constInitVal()->accept(this));
|
ArrayValueTree *root = std::any_cast<ArrayValueTree *>(constDef->constInitVal()->accept(this));
|
||||||
ValueCounter values;
|
ValueCounter values;
|
||||||
@@ -743,8 +754,20 @@ std::any SysYIRGenerator::visitVarDecl(SysYParser::VarDeclContext *ctx) {
|
|||||||
|
|
||||||
// 对于数组,alloca 的类型将是指针指向数组类型,例如 `int[2][3]*`
|
// 对于数组,alloca 的类型将是指针指向数组类型,例如 `int[2][3]*`
|
||||||
// 对于标量,alloca 的类型将是指针指向标量类型,例如 `int*`
|
// 对于标量,alloca 的类型将是指针指向标量类型,例如 `int*`
|
||||||
AllocaInst* alloca =
|
|
||||||
builder.createAllocaInst(Type::getPointerType(variableType), name);
|
BasicBlock *curBB = builder.getBasicBlock();
|
||||||
|
auto curPos =builder.getPosition();
|
||||||
|
Function *currentFunction = builder.getBasicBlock()->getParent();
|
||||||
|
BasicBlock *entryBB = currentFunction->getEntryBlock();
|
||||||
|
// 在terminator前插入
|
||||||
|
auto entryPos = entryBB->terminator();
|
||||||
|
builder.setPosition(entryBB, entryPos);
|
||||||
|
AllocaInst *alloca = builder.createAllocaInst(Type::getPointerType(variableType), name);
|
||||||
|
// 恢复当前位置
|
||||||
|
builder.setPosition(curBB, curPos);
|
||||||
|
|
||||||
|
// AllocaInst* alloca =
|
||||||
|
// builder.createAllocaInst(Type::getPointerType(variableType), name);
|
||||||
|
|
||||||
if (varDef->initVal() != nullptr) {
|
if (varDef->initVal() != nullptr) {
|
||||||
ValueCounter values;
|
ValueCounter values;
|
||||||
|
|||||||
Reference in New Issue
Block a user