CIRCT 22.0.0git
Loading...
Searching...
No Matches
AssumeTwoValued.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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
11#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
12
13using namespace circt;
14using namespace circt::comb;
15
16namespace circt {
17namespace comb {
18#define GEN_PASS_DEF_ASSUMETWOVALUED
19#include "circt/Dialect/Comb/Passes.h.inc"
20} // namespace comb
21} // namespace circt
22
23namespace {
24struct ICmpOpConversion : OpRewritePattern<ICmpOp> {
26
27 LogicalResult matchAndRewrite(ICmpOp op,
28 PatternRewriter &rewriter) const override {
29 ICmpPredicate newPredicate;
30 switch (op.getPredicate()) {
31 case ICmpPredicate::ceq:
32 case ICmpPredicate::weq:
33 newPredicate = ICmpPredicate::eq;
34 break;
35 case ICmpPredicate::cne:
36 case ICmpPredicate::wne:
37 newPredicate = ICmpPredicate::ne;
38 break;
39 default:
40 return failure();
41 }
42 rewriter.replaceOpWithNewOp<ICmpOp>(op, newPredicate, op.getLhs(),
43 op.getRhs());
44 return success();
45 }
46};
47} // namespace
48
49namespace {
50class AssumeTwoValued : public impl::AssumeTwoValuedBase<AssumeTwoValued> {
51public:
52 using AssumeTwoValuedBase::AssumeTwoValuedBase;
53
54 void runOnOperation() override;
55};
56} // namespace
57
58void AssumeTwoValued::runOnOperation() {
59 auto *ctx = &getContext();
60 RewritePatternSet patterns(ctx);
61 patterns.add<ICmpOpConversion>(ctx);
62
63 if (failed(applyPatternsGreedily(getOperation(), std::move(patterns))))
64 return signalPassFailure();
65}
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition comb.py:1