Skip to content

Commit

Permalink
[HWArith] Fix lowering to HW with type aliases
Browse files Browse the repository at this point in the history
Closes #7961
  • Loading branch information
teqdruid committed Dec 19, 2024
1 parent 6118d46 commit 99826b8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Conversion/HWArithToHW/HWArithToHW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ static bool isSignednessType(Type type) {
})
.Case<hw::InOutType>(
[](auto type) { return isSignednessType(type.getElementType()); })
.Case<hw::TypeAliasType>(
[](auto type) { return isSignednessType(type.getInnerType()); })
.Default([](auto type) { return false; });

return match;
Expand Down Expand Up @@ -378,6 +380,10 @@ Type HWArithToHWTypeConverter::removeSignedness(Type type) {
.Case<hw::InOutType>([this](auto type) {
return hw::InOutType::get(removeSignedness(type.getElementType()));
})
.Case<hw::TypeAliasType>([this](auto type) {
return hw::TypeAliasType::get(
type.getRef(), removeSignedness(type.getInnerType()));
})
.Default([](auto type) { return type; });

return convertedType;
Expand Down
21 changes: 21 additions & 0 deletions test/Conversion/HWArithToHW/test_basic.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,24 @@ hw.module @wires () {
sv.assign %r52, %c0_ui2 : ui2
sv.assign %r53, %c0_ui2 : ui2
}

// -----

// CHECK: hw.type_scope @pycde {
// CHECK: hw.typedecl @MMIOIntermediateCmd : !hw.struct<offset: i32>
// CHECK: }
// CHECK: hw.module @MMIOAxiReadWriteMux(out cmd : !hw.typealias<@pycde::@MMIOIntermediateCmd, !hw.struct<offset: i32>>) {
// CHECK: %c0_i32 = hw.constant 0 : i32
// CHECK: [[R0:%.+]] = hw.struct_create (%c0_i32) : !hw.typealias<@pycde::@MMIOIntermediateCmd, !hw.struct<offset: i32>>
// CHECK: hw.output [[R0]] : !hw.typealias<@pycde::@MMIOIntermediateCmd, !hw.struct<offset: i32>>
// CHECK: }

hw.type_scope @pycde {
hw.typedecl @MMIOIntermediateCmd : !hw.struct<offset: ui32>
}
hw.module @MMIOAxiReadWriteMux(out cmd : !hw.typealias<@pycde::@MMIOIntermediateCmd, !hw.struct<offset: ui32>>) {
%2 = hw.constant 0 : i32
%3 = hwarith.cast %2 : (i32) -> ui32
%4 = hw.struct_create (%3) : !hw.typealias<@pycde::@MMIOIntermediateCmd, !hw.struct<offset: ui32>>
hw.output %4: !hw.typealias<@pycde::@MMIOIntermediateCmd, !hw.struct<offset: ui32>>
}

0 comments on commit 99826b8

Please sign in to comment.