[HW] Add a folder for array slice op (#4052)

This PR adds a folder for array slice op to fold slice op which extracts entire inputs.
This commit is contained in:
Hideto Ueno 2022-10-04 20:09:17 +09:00 committed by GitHub
parent a63a23cb7b
commit d81f0623d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View File

@ -109,6 +109,7 @@ def ArraySliceOp : HWOp<"array_slice", [NoSideEffect]> {
let results = (outs ArrayType:$dst);
let hasVerifier = 1;
let hasFolder = 1;
let hasCanonicalizeMethod = 1;
let assemblyFormat = [{

View File

@ -1810,6 +1810,13 @@ LogicalResult ArraySliceOp::verify() {
return success();
}
OpFoldResult ArraySliceOp::fold(ArrayRef<Attribute> constants) {
// If we are slicing the entire input, then return it.
if (getType() == getInput().getType())
return getInput();
return {};
}
LogicalResult ArraySliceOp::canonicalize(ArraySliceOp op,
PatternRewriter &rewriter) {
auto sliceTy = hw::type_cast<ArrayType>(op.getType());

View File

@ -1483,3 +1483,11 @@ hw.module @GetOfUniformArray(%in: i42, %address: i2) -> (out: i42) {
%1 = hw.array_get %0[%address] : !hw.array<4xi42>, i2
hw.output %1 : i42
}
// CHECK-LABEL: ArraySlice
hw.module @ArraySlice(%arr: !hw.array<128xi1>) -> (a: !hw.array<128xi1>) {
%c0_i7 = hw.constant 0 : i7
// CHECK: hw.output %arr
%1 = hw.array_slice %arr[%c0_i7] : (!hw.array<128xi1>) -> !hw.array<128xi1>
hw.output %1 : !hw.array<128xi1>
}