39 addTypeAttributeConversion([&](Type type, Attribute attr) {
40 auto newType = convertType(type);
42 llvm::errs() <<
"Failed to convert type: " << type <<
"\n";
43 return AttributeConversionResult::abort();
45 return AttributeConversionResult(TypeAttr::get(newType));
51 addConversion([](Type type) -> std::optional<Type> {
return type; });
54 addConversion([&](BlockFloatType blockType) -> std::optional<IntegerType> {
58 llvm::errs() <<
"Block type " << blockType.getBlockType()
59 <<
" is not supported in the specified model\n";
66 return mlir::IntegerType::get(blockType.getContext(), blockType.getTotalSizeInBits());
70 addConversion([&](MemRefType memRefType) -> std::optional<MemRefType> {
71 auto newElementType = convertType(memRefType.getElementType());
72 if (!newElementType) {
73 llvm::errs() <<
"Failed to convert memref element type\n";
76 return MemRefType::get(memRefType.getShape(), newElementType,
77 memRefType.getLayout(),
78 memRefType.getMemorySpace());
82 addConversion([&](AIEObjectFifoType objectFifoType)
83 -> std::optional<AIEObjectFifoType> {
84 auto newElementType = convertType(objectFifoType.getElementType());
85 if (!newElementType) {
86 llvm::errs() <<
"Failed to convert ObjectFifoType element type\n";
90 if (
auto newMemRef = dyn_cast<MemRefType>(newElementType))
91 return AIEObjectFifoType::get(objectFifoType.getContext(), newMemRef);
94 <<
"ObjectFifoType converted element type is not a MemRefType\n";
99 addConversion([&](AIEObjectFifoSubviewType objectFifoSubviewType)
100 -> std::optional<AIEObjectFifoSubviewType> {
101 auto newElementType = convertType(objectFifoSubviewType.getElementType());
102 if (!newElementType) {
104 <<
"Failed to convert ObjectFifoSubviewType element type\n";
108 if (
auto newMemRef = dyn_cast<MemRefType>(newElementType))
109 return AIEObjectFifoSubviewType::get(objectFifoSubviewType.getContext(),
113 <<
"ObjectFifoSubviewType element type is not a MemRefType\n";
118 addConversion([&](FunctionType funcType) -> std::optional<FunctionType> {
119 llvm::SmallVector<Type> newInputTypes;
120 auto check = convertTypes(funcType.getInputs(), newInputTypes);
121 if (check.failed()) {
122 llvm::errs() <<
"Failed to convert function input types\n";
126 llvm::SmallVector<Type> newOutputTypes;
127 check = convertTypes(funcType.getResults(), newOutputTypes);
128 if (check.failed()) {
129 llvm::errs() <<
"Failed to convert function output types\n";
133 return FunctionType::get(funcType.getContext(), newInputTypes,