13#ifndef CIRCT_DIALECT_COMB_COMBOPS_H
14#define CIRCT_DIALECT_COMB_COMBOPS_H
20#include "mlir/Bytecode/BytecodeOpInterface.h"
21#include "mlir/IR/BuiltinOps.h"
22#include "mlir/IR/Matchers.h"
23#include "mlir/IR/OpImplementation.h"
24#include "mlir/Interfaces/FunctionInterfaces.h"
25#include "mlir/Interfaces/InferIntRangeInterface.h"
26#include "mlir/Interfaces/InferTypeOpInterface.h"
27#include "mlir/Interfaces/SideEffectInterfaces.h"
28#include "mlir/Transforms/DialectConversion.h"
39#include "circt/Dialect/Comb/Comb.h.inc"
57Value
createZExt(OpBuilder &builder, Location loc, Value value,
58 unsigned targetWidth);
64Value
createOrFoldSExt(ImplicitLocOpBuilder &builder, Value value, Type destTy);
68 bool twoState =
false);
70 bool twoState =
false);
73void extractBits(OpBuilder &builder, Value val, SmallVectorImpl<Value> &bits);
78 ArrayRef<Value> selectors, ArrayRef<Value> leafNodes,
79 Value outOfBoundsValue);
83 Value offset,
unsigned width);
88 Value offset, Value replacement,
89 bool twoState =
false);
92Value
createInject(OpBuilder &builder, Location loc, Value value,
93 unsigned offset, Value replacement);
97 mlir::PatternRewriter &rewriter);
104 mlir::PatternRewriter &rewriter);
106 mlir::PatternRewriter &rewriter);
115 PatternRewriter &rewriter, MuxOp rootMux,
bool isFalseSide,
122template <
typename SubType>
128 auto concatOp = dyn_cast<ConcatOp>(op);
132 auto operands = concatOp.getOperands();
134 if (operands.size() < 2)
138 if (!constOp || !constOp.getValue().isZero())
142 return mlir::detail::matchOperandOrValueAtIndex(op, 0,
lhs);
147template <
typename SubType>
158template <
typename SubType>
164 auto concatOp = dyn_cast<ConcatOp>(op);
168 auto operands = concatOp.getOperands();
170 if (operands.size() < 2)
173 Value signBits = operands[0];
174 Value baseValue = operands[1];
175 auto baseWidth = baseValue.getType().getIntOrFloatBitWidth();
178 auto replicateOp = dyn_cast_or_null<ReplicateOp>(signBits.getDefiningOp());
179 Value signBit = replicateOp ? replicateOp.getInput() : signBits;
182 if (signBit.getType().getIntOrFloatBitWidth() != 1)
186 auto extractOp = dyn_cast_or_null<ExtractOp>(signBit.getDefiningOp());
190 if ((extractOp.getInput() != baseValue) ||
191 (extractOp.getLowBit() != baseWidth - 1))
195 return mlir::detail::matchOperandOrValueAtIndex(op, 0,
lhs);
200template <
typename SubType>
static SextByMatcher< SubType > m_SextBy(const SubType &subExpr)
Helper function to create a sign extension matcher.
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...
bool shouldUseBoothEncoding(Value lhs, Value rhs, unsigned threshold=16)
Return true when both operands are wider than the bitwidth threshold and should use Booth encoding.
Value createOrFoldNot(OpBuilder &builder, Location loc, Value value, 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...
static ZextByMatcher< SubType > m_ZextBy(const SubType &subExpr)
Helper function to create a zero extension matcher.
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.
Value createOrFoldSExt(OpBuilder &builder, Location loc, Value value, Type destTy)
Create a sign extension operation from a value of integer type to an equal or larger integer 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)
SextByMatcher(SubType lhs)
bool match(Operation *op)
ZextByMatcher(SubType lhs)