41 addTypeAttributeConversion([&](Type type, Attribute attr) {
42 auto newType = convertType(type);
44 llvm::errs() <<
"Failed to convert type: " << type <<
"\n";
45 return AttributeConversionResult::abort();
47 return AttributeConversionResult(TypeAttr::get(newType));
53 addConversion([](Type type) -> std::optional<Type> {
return type; });
56 addConversion([&](BlockFloatType blockType) -> std::optional<IntegerType> {
60 llvm::errs() <<
"Block type " << blockType.getBlockType()
61 <<
" is not supported in the specified model\n";
68 return mlir::IntegerType::get(blockType.getContext(),
69 blockType.getTotalSizeInBits());
73 addConversion([&](MemRefType memRefType) -> std::optional<MemRefType> {
74 auto newElementType = convertType(memRefType.getElementType());
75 if (!newElementType) {
76 llvm::errs() <<
"Failed to convert memref element type\n";
79 return MemRefType::get(memRefType.getShape(), newElementType,
80 memRefType.getLayout(),
81 memRefType.getMemorySpace());
85 addConversion([&](AIEObjectFifoType objectFifoType)
86 -> std::optional<AIEObjectFifoType> {
87 auto newElementType = convertType(objectFifoType.getElementType());
88 if (!newElementType) {
89 llvm::errs() <<
"Failed to convert ObjectFifoType element type\n";
93 if (
auto newMemRef = dyn_cast<MemRefType>(newElementType))
94 return AIEObjectFifoType::get(objectFifoType.getContext(), newMemRef);
97 <<
"ObjectFifoType converted element type is not a MemRefType\n";
102 addConversion([&](FunctionType funcType) -> std::optional<FunctionType> {
103 llvm::SmallVector<Type> newInputTypes;
104 auto check = convertTypes(funcType.getInputs(), newInputTypes);
105 if (check.failed()) {
106 llvm::errs() <<
"Failed to convert function input types\n";
110 llvm::SmallVector<Type> newOutputTypes;
111 check = convertTypes(funcType.getResults(), newOutputTypes);
112 if (check.failed()) {
113 llvm::errs() <<
"Failed to convert function output types\n";
117 return FunctionType::get(funcType.getContext(), newInputTypes,