Skip to content

Commit

Permalink
Revert "[FIRRTL] Canonicalizers: simplify resolve-of-send and hoist r…
Browse files Browse the repository at this point in the history
…ef.sub out of ref.send. (#4764)"

This reverts commit 3ddf879.

Neither of these are safe if the argument to ref.send is not passive.
Revisit in the future.
  • Loading branch information
dtzSiFive committed Mar 9, 2023
1 parent d77dfdd commit 579d21b
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 91 deletions.
32 changes: 0 additions & 32 deletions include/circt/Dialect/FIRRTL/FIRRTLCanonicalization.td
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,6 @@ def UIntTypes : Constraint<CPred<"$0.isa<UIntType>()">>;
// Constraint that enforces types mismatches
def mismatchTypes : Constraint<CPred<"$0.getType() != $1.getType()">>;

// Constraint that argument is ref-of-vector type.
def IsRefVectorType : Constraint<CPred<[{
$0.getType().isa<RefType>() &&
$0.getType().cast<RefType>().getType().isa<FVectorType>()
}]>>;

// Constraint that argument is ref-of-bundle type.
def IsRefBundleType : Constraint<CPred<[{
$0.getType().isa<RefType>() &&
$0.getType().cast<RefType>().getType().isa<BundleType>()
}]>>;


// Constraint that enforces types of known width
def KnownWidth : Constraint<CPred<[{
$0.getType().isa<FIRRTLBaseType>() &&
Expand Down Expand Up @@ -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
2 changes: 0 additions & 2 deletions include/circt/Dialect/FIRRTL/FIRRTLExpressions.td
Original file line number Diff line number Diff line change
Expand Up @@ -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">]> {
Expand Down Expand Up @@ -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
15 changes: 0 additions & 15 deletions lib/Dialect/FIRRTL/FIRRTLFolds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2818,18 +2818,3 @@ void CoverOp::getCanonicalizationPatterns(RewritePatternSet &results,
MLIRContext *context) {
results.add(canonicalizeImmediateVerifOp<CoverOp, /* EraseIfZero = */ true>);
}

//===----------------------------------------------------------------------===//
// References.
//===----------------------------------------------------------------------===//

void RefResolveOp::getCanonicalizationPatterns(RewritePatternSet &results,
MLIRContext *context) {
results.insert<patterns::RefResolveOfSend>(context);
}

void RefSubOp::getCanonicalizationPatterns(RewritePatternSet &results,
MLIRContext *context) {
results.insert<patterns::RefSubOfSendVector, patterns::RefSubOfSendBundle>(
context);
}
42 changes: 0 additions & 42 deletions test/Dialect/FIRRTL/canonicalization.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint<1>>
firrtl.strictconnect %y, %res : !firrtl.uint<1>
}

// CHECK-LABEL: @RefSubHoistVector
firrtl.module @RefSubHoistVector(in %x: !firrtl.vector<uint<1>,2>, out %y : !firrtl.ref<uint<1>>) {
// 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<uint<1>,2>
%sub = firrtl.ref.sub %ref[1] : !firrtl.ref<vector<uint<1>,2>>
firrtl.strictconnect %y, %sub: !firrtl.ref<uint<1>>
}

// CHECK-LABEL: @RefSubHoistBundle
firrtl.module @RefSubHoistBundle(in %x: !firrtl.bundle<a: uint<1>, b: uint<2>>, out %y : !firrtl.ref<uint<2>>) {
// 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<a: uint<1>, b: uint<2>>
%sub = firrtl.ref.sub %ref[1] : !firrtl.ref<bundle<a: uint<1>, b: uint<2>>>
firrtl.strictconnect %y, %sub: !firrtl.ref<uint<2>>
}

// CHECK-LABEL: @RefResolveSubSend
firrtl.module private @RefResolveSubSend(in %x: !firrtl.bundle<a: uint<1>, 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<a: uint<1>, b: uint<2>>
%sub = firrtl.ref.sub %ref[1] : !firrtl.ref<bundle<a: uint<1>, b: uint<2>>>
%res = firrtl.ref.resolve %sub: !firrtl.ref<uint<2>>
firrtl.strictconnect %y, %res : !firrtl.uint<2>
}

}

0 comments on commit 579d21b

Please sign in to comment.