CIRCT 21.0.0git
Loading...
Searching...
No Matches
SimplifyAssumeEq.cpp
Go to the documentation of this file.
1//===- SimplifyAssumeEq.cpp - Formal Preparations ---------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9//
10// When a symbolic value is assumed equal to another value, the symbolic value
11// is replaced with its equal value to simplify.
12//
13//
14//===----------------------------------------------------------------------===//
15
19
20#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
21
22using namespace circt;
23
24namespace circt {
25namespace verif {
26#define GEN_PASS_DEF_SIMPLIFYASSUMEEQPASS
27#include "circt/Dialect/Verif/Passes.h.inc"
28} // namespace verif
29} // namespace circt
30
31using namespace mlir;
32using namespace verif;
33
34namespace {
35struct SimplifyAssumeEqPass
36 : verif::impl::SimplifyAssumeEqPassBase<SimplifyAssumeEqPass> {
37 void runOnOperation() override;
38};
39
40LogicalResult tryReplaceEqualValues(mlir::Value &from, mlir::Value &to,
41 AssumeOp &op, PatternRewriter &rewriter) {
42 auto *fromOp = from.getDefiningOp();
43 if (fromOp && dyn_cast<verif::SymbolicValueOp>(fromOp)) {
44 rewriter.replaceAllUsesWith(from, to);
45 rewriter.eraseOp(fromOp);
46 rewriter.eraseOp(op);
47 return llvm::success();
48 }
49 return failure();
50}
51
52struct AssumeEqRewritePattern : public OpRewritePattern<verif::AssumeOp> {
54
55 LogicalResult matchAndRewrite(AssumeOp op,
56 PatternRewriter &rewriter) const override {
57 auto prop = op.getProperty();
58 auto icmp = prop.getDefiningOp<comb::ICmpOp>();
59 if (!icmp)
60 return llvm::failure();
61
62 if (icmp.getPredicate() != comb::ICmpPredicate::eq)
63 return llvm::failure();
64
65 auto lhs = icmp.getLhs();
66 auto rhs = icmp.getRhs();
67 // If lhs is symbolic value, replace with rhs, otherwise
68 // if rhs is symbolic value, replace with lhs
69 if (succeeded(tryReplaceEqualValues(lhs, rhs, op, rewriter)))
70 return success();
71 if (succeeded(tryReplaceEqualValues(rhs, lhs, op, rewriter)))
72 return success();
73 return llvm::failure();
74 }
75};
76} // namespace
77
78void SimplifyAssumeEqPass::runOnOperation() {
79 RewritePatternSet patterns(&getContext());
80 patterns.add<AssumeEqRewritePattern>(patterns.getContext());
81
82 if (failed(applyPatternsGreedily(getOperation(), std::move(patterns))))
83 signalPassFailure();
84}
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition verif.py:1