From 579d21b5031763d5a808130d7397a1403cbf4972 Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Thu, 9 Mar 2023 10:18:12 -0600 Subject: [PATCH] Revert "[FIRRTL] Canonicalizers: simplify resolve-of-send and hoist ref.sub out of ref.send. (#4764)" This reverts commit 3ddf879a1ec339735174d735e0414865278c990e. Neither of these are safe if the argument to ref.send is not passive. Revisit in the future. --- .../Dialect/FIRRTL/FIRRTLCanonicalization.td | 32 -------------- .../circt/Dialect/FIRRTL/FIRRTLExpressions.td | 2 - lib/Dialect/FIRRTL/FIRRTLFolds.cpp | 15 ------- test/Dialect/FIRRTL/canonicalization.mlir | 42 ------------------- 4 files changed, 91 deletions(-) diff --git a/include/circt/Dialect/FIRRTL/FIRRTLCanonicalization.td b/include/circt/Dialect/FIRRTL/FIRRTLCanonicalization.td index cbfe952de504..5294f3903eda 100644 --- a/include/circt/Dialect/FIRRTL/FIRRTLCanonicalization.td +++ b/include/circt/Dialect/FIRRTL/FIRRTLCanonicalization.td @@ -56,19 +56,6 @@ def UIntTypes : Constraint()">>; // Constraint that enforces types mismatches def mismatchTypes : Constraint>; -// Constraint that argument is ref-of-vector type. -def IsRefVectorType : Constraint() && - $0.getType().cast().getType().isa() -}]>>; - -// Constraint that argument is ref-of-bundle type. -def IsRefBundleType : Constraint() && - $0.getType().cast().getType().isa() -}]>>; - - // Constraint that enforces types of known width def KnownWidth : Constraint() && @@ -363,23 +350,4 @@ def RegResetWithOneReset : Pat< (DropWrite $reg, (NodeOp $resetVal, $name, $nameKind, $annotations, $inner_sym)), [(OneConstantOp $reset)]>; -// refresolve(refsend(x)) -> x -def RefResolveOfSend : Pat< - (RefResolveOp (RefSendOp $orig)), - (replaceWithValue $orig) >; - -// Hoist ref.sub through send, vector variant. -// refsub(refsend(orig), idx) -> refsend(subindex(orig, idx)) -def RefSubOfSendVector : Pat< - (RefSubOp (RefSendOp:$send $orig), $idx), - (RefSendOp (SubindexOp $orig, $idx)), - [(IsRefVectorType $send)] >; - -// Hoist ref.sub through send, bundle variant. -// refsub(refsend(orig), idx) -> refsend(subfield(orig, idx)) -def RefSubOfSendBundle : Pat< - (RefSubOp (RefSendOp:$send $orig), $idx), - (RefSendOp (SubfieldOp $orig, $idx)), - [(IsRefBundleType $send)] >; - #endif // CIRCT_DIALECT_FIRRTL_FIRRTLCANONICALIZATION_TD diff --git a/include/circt/Dialect/FIRRTL/FIRRTLExpressions.td b/include/circt/Dialect/FIRRTL/FIRRTLExpressions.td index a62b310fe821..291e7e0d0c15 100644 --- a/include/circt/Dialect/FIRRTL/FIRRTLExpressions.td +++ b/include/circt/Dialect/FIRRTL/FIRRTLExpressions.td @@ -807,7 +807,6 @@ def RefResolveOp: FIRRTLExprOp<"ref.resolve", let results = (outs FIRRTLBaseType:$result); let assemblyFormat = "$ref attr-dict `:` qualified(type($ref))"; - let hasCanonicalizer = true; } def RefSendOp: FIRRTLExprOp<"ref.send", [RefResultTypeConstraint<"base", "result">]> { @@ -840,7 +839,6 @@ def RefSubOp : FIRRTLExprOp<"ref.sub"> { let assemblyFormat = "$input `[` $index `]` attr-dict `:` qualified(type($input))"; - let hasCanonicalizer = true; } #endif // CIRCT_DIALECT_FIRRTL_FIRRTLEXPRESSIONS_TD diff --git a/lib/Dialect/FIRRTL/FIRRTLFolds.cpp b/lib/Dialect/FIRRTL/FIRRTLFolds.cpp index d8ef5ed47a19..eed2488143e1 100644 --- a/lib/Dialect/FIRRTL/FIRRTLFolds.cpp +++ b/lib/Dialect/FIRRTL/FIRRTLFolds.cpp @@ -2818,18 +2818,3 @@ void CoverOp::getCanonicalizationPatterns(RewritePatternSet &results, MLIRContext *context) { results.add(canonicalizeImmediateVerifOp); } - -//===----------------------------------------------------------------------===// -// References. -//===----------------------------------------------------------------------===// - -void RefResolveOp::getCanonicalizationPatterns(RewritePatternSet &results, - MLIRContext *context) { - results.insert(context); -} - -void RefSubOp::getCanonicalizationPatterns(RewritePatternSet &results, - MLIRContext *context) { - results.insert( - context); -} diff --git a/test/Dialect/FIRRTL/canonicalization.mlir b/test/Dialect/FIRRTL/canonicalization.mlir index 8804506af0ce..506cf3b3e82b 100644 --- a/test/Dialect/FIRRTL/canonicalization.mlir +++ b/test/Dialect/FIRRTL/canonicalization.mlir @@ -2611,46 +2611,4 @@ firrtl.module @MuxCondWidth(in %cond: !firrtl.uint<1>, out %foo: !firrtl.uint<3> firrtl.strictconnect %foo, %0 : !firrtl.uint<3> } -// CHECK-LABEL: @RefResolveSend -firrtl.module @RefResolveSend(in %x: !firrtl.uint<1>, out %y : !firrtl.uint<1>) { - // CHECK-NEXT: firrtl.strictconnect %y, %x - // CHECK-NEXT: } - %ref = firrtl.ref.send %x : !firrtl.uint<1> - %res = firrtl.ref.resolve %ref : !firrtl.ref> - firrtl.strictconnect %y, %res : !firrtl.uint<1> -} - -// CHECK-LABEL: @RefSubHoistVector -firrtl.module @RefSubHoistVector(in %x: !firrtl.vector,2>, out %y : !firrtl.ref>) { - // CHECK-NEXT: %[[sub:.+]] = firrtl.subindex %x[1] - // CHECK-NEXT: %[[ref:.+]] = firrtl.ref.send %[[sub]] - // CHECK-NEXT: firrtl.strictconnect %y, %[[ref]] - // CHECK-NEXT: } - %ref = firrtl.ref.send %x : !firrtl.vector,2> - %sub = firrtl.ref.sub %ref[1] : !firrtl.ref,2>> - firrtl.strictconnect %y, %sub: !firrtl.ref> -} - -// CHECK-LABEL: @RefSubHoistBundle -firrtl.module @RefSubHoistBundle(in %x: !firrtl.bundle, b: uint<2>>, out %y : !firrtl.ref>) { - // CHECK-NEXT: %[[sub:.+]] = firrtl.subfield %x[b] - // CHECK-NEXT: %[[ref:.+]] = firrtl.ref.send %[[sub]] - // CHECK-NEXT: firrtl.strictconnect %y, %[[ref]] - // CHECK-NEXT: } - %ref = firrtl.ref.send %x : !firrtl.bundle, b: uint<2>> - %sub = firrtl.ref.sub %ref[1] : !firrtl.ref, b: uint<2>>> - firrtl.strictconnect %y, %sub: !firrtl.ref> -} - -// CHECK-LABEL: @RefResolveSubSend -firrtl.module private @RefResolveSubSend(in %x: !firrtl.bundle, b: uint<2>>, out %y : !firrtl.uint<2>) { - // CHECK-NEXT: %[[sub:.+]] = firrtl.subfield %x[b] - // CHECK-NEXT: firrtl.strictconnect %y, %[[sub]] - // CHECK-NEXT: } - %ref = firrtl.ref.send %x : !firrtl.bundle, b: uint<2>> - %sub = firrtl.ref.sub %ref[1] : !firrtl.ref, b: uint<2>>> - %res = firrtl.ref.resolve %sub: !firrtl.ref> - firrtl.strictconnect %y, %res : !firrtl.uint<2> -} - }