13#ifndef CIRCT_DIALECT_COMB_COMBOPS_H
14#define CIRCT_DIALECT_COMB_COMBOPS_H
19#include "mlir/Bytecode/BytecodeOpInterface.h"
20#include "mlir/IR/BuiltinOps.h"
21#include "mlir/IR/Matchers.h"
22#include "mlir/IR/OpImplementation.h"
23#include "mlir/Interfaces/FunctionInterfaces.h"
24#include "mlir/Interfaces/InferIntRangeInterface.h"
25#include "mlir/Interfaces/InferTypeOpInterface.h"
26#include "mlir/Interfaces/SideEffectInterfaces.h"
27#include "mlir/Transforms/DialectConversion.h"
38#include "circt/Dialect/Comb/Comb.h.inc"
52Value
createZExt(OpBuilder &builder, Location loc, Value value,
53 unsigned targetWidth);
59Value
createOrFoldSExt(Value value, Type destTy, ImplicitLocOpBuilder &builder);
63 bool twoState =
false);
65 bool twoState =
false);
68void extractBits(OpBuilder &builder, Value val, SmallVectorImpl<Value> &bits);
73 ArrayRef<Value> selectors, ArrayRef<Value> leafNodes,
74 Value outOfBoundsValue);
78 Value offset,
unsigned width);
83 Value offset, Value replacement,
84 bool twoState =
false);
87Value
createInject(OpBuilder &builder, Location loc, Value value,
88 unsigned offset, Value replacement);
92 mlir::PatternRewriter &rewriter);
99 mlir::PatternRewriter &rewriter);
101 mlir::PatternRewriter &rewriter);
110 PatternRewriter &rewriter, MuxOp rootMux,
bool isFalseSide,
119template <
typename SubType>
125 auto concatOp = dyn_cast<ConcatOp>(op);
129 auto operands = concatOp.getOperands();
131 if (operands.size() != 2)
134 Value signBits = operands[0];
135 Value baseValue = operands[1];
136 auto baseWidth = baseValue.getType().getIntOrFloatBitWidth();
139 auto replicateOp = dyn_cast<ReplicateOp>(signBits.getDefiningOp());
143 Value signBit = replicateOp.getInput();
146 auto extractOp = dyn_cast<ExtractOp>(signBit.getDefiningOp());
150 if ((extractOp.getInput() != baseValue) ||
151 (extractOp.getLowBit() != baseWidth - 1) ||
152 (extractOp.getType().getIntOrFloatBitWidth() != 1))
156 return mlir::detail::matchOperandOrValueAtIndex(op, 1,
lhs);
161template <
typename SubType>
void extractBits(OpBuilder &builder, Value val, SmallVectorImpl< Value > &bits)
Extract bits from a value.
bool foldMuxChainWithComparison(PatternRewriter &rewriter, MuxOp rootMux, bool isFalseSide, llvm::function_ref< MuxChainWithComparisonFoldingStyle(size_t indexWidth, size_t numEntries)> styleFn)
Mux chain folding that converts chains of muxes with index comparisons into array operations or balan...
static SextMatcher< SubType > m_Sext(const SubType &subExpr)
Helper function to create a sign extension matcher.
Value createOrFoldNot(Location loc, Value value, OpBuilder &builder, bool twoState=false)
Create a `‘Not’' gate on a value.
MuxChainWithComparisonFoldingStyle
Enum for mux chain folding styles.
LogicalResult convertSubToAdd(comb::SubOp subOp, mlir::PatternRewriter &rewriter)
Replace a subtraction with an addition of the two's complement.
LogicalResult convertModUByPowerOfTwo(ModUOp modOp, mlir::PatternRewriter &rewriter)
Value createDynamicInject(OpBuilder &builder, Location loc, Value value, Value offset, Value replacement, bool twoState=false)
Replace a range of bits in an integer at a dynamic offset, and return the updated integer value.
Value createInject(OpBuilder &builder, Location loc, Value value, unsigned offset, Value replacement)
Replace a range of bits in an integer and return the updated integer value.
Value createDynamicExtract(OpBuilder &builder, Location loc, Value value, Value offset, unsigned width)
Extract a range of bits from an integer at a dynamic offset.
KnownBits computeKnownBits(Value value)
Compute "known bits" information about the specified value - the set of bits that are guaranteed to a...
Value createOrFoldSExt(Location loc, Value value, Type destTy, OpBuilder &builder)
Create a sign extension operation from a value of integer type to an equal or larger integer type.
Value constructMuxTree(OpBuilder &builder, Location loc, ArrayRef< Value > selectors, ArrayRef< Value > leafNodes, Value outOfBoundsValue)
Construct a mux tree for given leaf nodes.
Value createZExt(OpBuilder &builder, Location loc, Value value, unsigned targetWidth)
Create the ops to zero-extend a value to an integer of equal or larger type.
LogicalResult convertDivUByPowerOfTwo(DivUOp divOp, mlir::PatternRewriter &rewriter)
Convert unsigned division or modulo by a power of two.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
bool match(Operation *op)