12#include "mlir/IR/PatternMatch.h"
20static SmallVector<Value>
concatValues(ValueRange a, ValueRange b) {
22 v.append(a.begin(), a.end());
23 v.append(b.begin(), b.end());
29 SmallVector<Value> flatInputs;
30 for (
auto value : values) {
31 if (
auto concatOp = value.getDefiningOp<ConcatOp>()) {
32 auto inputs = concatOp.getInputs();
33 flatInputs.append(inputs.begin(), inputs.end());
35 flatInputs.push_back(value);
46#include "circt/Dialect/LTL/LTLFolds.cpp.inc"
53LogicalResult AndOp::canonicalize(AndOp op, PatternRewriter &rewriter) {
54 if (op.getType() == rewriter.getI1Type()) {
55 rewriter.replaceOpWithNewOp<
comb::AndOp>(op, op.getInputs(),
true);
61LogicalResult OrOp::canonicalize(OrOp op, PatternRewriter &rewriter) {
62 if (op.getType() == rewriter.getI1Type()) {
63 rewriter.replaceOpWithNewOp<
comb::OrOp>(op, op.getInputs(),
true);
69LogicalResult IntersectOp::canonicalize(IntersectOp op,
70 PatternRewriter &rewriter) {
71 if (op.getType() == rewriter.getI1Type()) {
72 rewriter.replaceOpWithNewOp<
comb::AndOp>(op, op.getInputs(),
true);
82OpFoldResult DelayOp::fold(FoldAdaptor adaptor) {
84 if (adaptor.getDelay() == 0 && adaptor.getLength() == 0 &&
85 isa<SequenceType>(getInput().getType()))
91void DelayOp::getCanonicalizationPatterns(RewritePatternSet &results,
92 MLIRContext *context) {
93 results.add<patterns::NestedDelays>(results.getContext());
94 results.add<patterns::MoveDelayIntoConcat>(results.getContext());
101OpFoldResult ConcatOp::fold(FoldAdaptor adaptor) {
103 if (getInputs().size() == 1)
104 return getInputs()[0];
109void ConcatOp::getCanonicalizationPatterns(RewritePatternSet &results,
110 MLIRContext *context) {
111 results.add<patterns::FlattenConcats>(results.getContext());
120 static OpFoldResult fold(uint64_t base, uint64_t more, Value input) {
122 if (base == 1 && more == 0 && isa<SequenceType>(input.getType()))
130OpFoldResult RepeatOp::fold(FoldAdaptor adaptor) {
131 auto more = adaptor.getMore();
132 if (more.has_value())
133 return RepeatLikeOp::fold(adaptor.getBase(), *more, getInput());
137OpFoldResult GoToRepeatOp::fold(FoldAdaptor adaptor) {
138 return RepeatLikeOp::fold(adaptor.getBase(), adaptor.getMore(), getInput());
141OpFoldResult NonConsecutiveRepeatOp::fold(FoldAdaptor adaptor) {
142 return RepeatLikeOp::fold(adaptor.getBase(), adaptor.getMore(), getInput());
static SmallVector< Value > flattenConcats(ValueRange values)
Inline all ConcatOps in a range of values.
static SmallVector< Value > concatValues(ValueRange a, ValueRange b)
Concatenate two value ranges into a larger range.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.