[midend] GEP类型推断函数getIndexedType逻辑修复,增加数组type缓存池避免相同type ==操作返回假,修复实参形参类型转换判断逻辑,starttime stoptime提供支持(待后端测试)

This commit is contained in:
rain2133
2025-07-25 03:26:10 +08:00
parent 96c6b0ab6e
commit 1e6f6ed711
3 changed files with 85 additions and 64 deletions

View File

@@ -105,8 +105,17 @@ FunctionType*FunctionType::get(Type *returnType, const std::vector<Type *> &para
}
ArrayType *ArrayType::get(Type *elementType, unsigned numElements) {
// TODO:可以考虑在这里添加缓存,避免重复创建相同的数组类型
return new ArrayType(elementType, numElements);
static std::set<std::unique_ptr<ArrayType>> arrayTypes;
auto iter = std::find_if(arrayTypes.begin(), arrayTypes.end(), [&](const std::unique_ptr<ArrayType> &type) -> bool {
return elementType == type->getElementType() && numElements == type->getNumElements();
});
if (iter != arrayTypes.end()) {
return iter->get();
}
auto type = new ArrayType(elementType, numElements);
assert(type);
auto result = arrayTypes.emplace(type);
return result.first->get();
}
void Value::replaceAllUsesWith(Value *value) {