[midend] GEP类型推断函数getIndexedType逻辑修复,增加数组type缓存池避免相同type ==操作返回假,修复实参形参类型转换判断逻辑,starttime stoptime提供支持(待后端测试)
This commit is contained in:
13
src/IR.cpp
13
src/IR.cpp
@@ -105,8 +105,17 @@ FunctionType*FunctionType::get(Type *returnType, const std::vector<Type *> ¶
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user