[IR]修复初始化数组指令的逻辑,更新IR常量定义。

This commit is contained in:
rain2133
2025-07-19 16:18:05 +08:00
parent 36cfd2f64d
commit 0d5748e9c5
5 changed files with 184 additions and 103 deletions

View File

@@ -47,7 +47,7 @@ bool AddressCalculationExpansion::run() {
for (const auto& use_ptr : allocaInst->getDims()) {
Value* dimValue = use_ptr->getValue();
if (ConstantValue* constVal = dynamic_cast<ConstantValue*>(dimValue)) {
dims.push_back(constVal->getValue<int>());
dims.push_back(constVal->getInt());
} else {
std::cerr << "Warning: AllocaInst dimension is not a constant integer. Skipping GEP expansion for: ";
SysYPrinter::printValue(allocaInst);
@@ -101,13 +101,13 @@ bool AddressCalculationExpansion::run() {
}
}
Value* totalOffset = ConstantValue::get(0);
Value* totalOffset = ConstantInteger::get(0);
pBuilder->setPosition(bb, it);
for (size_t i = 0; i < indexOperands.size(); ++i) {
Value* index = indexOperands[i];
int stride = calculateStride(dims, i);
Value* strideConst = ConstantValue::get(stride);
Value* strideConst = ConstantInteger::get(stride);
Type* intType = Type::getIntType();
BinaryInst* currentDimOffsetInst = pBuilder->createBinaryInst(Instruction::kMul, intType, index, strideConst);
BinaryInst* newTotalOffsetInst = pBuilder->createBinaryInst(Instruction::kAdd, intType, totalOffset, currentDimOffsetInst);