CIRCT 22.0.0git
Loading...
Searching...
No Matches
CombOps.h
Go to the documentation of this file.
1//===- CombOps.h - Declare Comb dialect operations --------------*- 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// This file declares the operation classes for the Comb dialect.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef CIRCT_DIALECT_COMB_COMBOPS_H
14#define CIRCT_DIALECT_COMB_COMBOPS_H
15
18#include "circt/Support/LLVM.h"
19#include "mlir/Bytecode/BytecodeOpInterface.h"
20#include "mlir/IR/BuiltinOps.h"
21#include "mlir/IR/OpImplementation.h"
22#include "mlir/Interfaces/FunctionInterfaces.h"
23#include "mlir/Interfaces/InferIntRangeInterface.h"
24#include "mlir/Interfaces/InferTypeOpInterface.h"
25#include "mlir/Interfaces/SideEffectInterfaces.h"
26#include "mlir/Transforms/DialectConversion.h"
27
28namespace llvm {
29struct KnownBits;
30}
31
32namespace mlir {
33class PatternRewriter;
34}
35
36#define GET_OP_CLASSES
37#include "circt/Dialect/Comb/Comb.h.inc"
38
39namespace circt {
40namespace comb {
41
42using llvm::KnownBits;
43
44/// Compute "known bits" information about the specified value - the set of bits
45/// that are guaranteed to always be zero, and the set of bits that are
46/// guaranteed to always be one (these must be exclusive!). A bit that exists
47/// in neither set is unknown.
48KnownBits computeKnownBits(Value value);
49
50/// Create the ops to zero-extend a value to an integer of equal or larger type.
51Value createZExt(OpBuilder &builder, Location loc, Value value,
52 unsigned targetWidth);
53
54/// Create a sign extension operation from a value of integer type to an equal
55/// or larger integer type.
56Value createOrFoldSExt(Location loc, Value value, Type destTy,
57 OpBuilder &builder);
58Value createOrFoldSExt(Value value, Type destTy, ImplicitLocOpBuilder &builder);
59
60/// Create a ``Not'' gate on a value.
61Value createOrFoldNot(Location loc, Value value, OpBuilder &builder,
62 bool twoState = false);
63Value createOrFoldNot(Value value, ImplicitLocOpBuilder &builder,
64 bool twoState = false);
65
66/// Extract bits from a value.
67void extractBits(OpBuilder &builder, Value val, SmallVectorImpl<Value> &bits);
68
69/// Construct a mux tree for given leaf nodes. `selectors` is the selector for
70/// each level of the tree. Currently the selector is tested from MSB to LSB.
71Value constructMuxTree(OpBuilder &builder, Location loc,
72 ArrayRef<Value> selectors, ArrayRef<Value> leafNodes,
73 Value outOfBoundsValue);
74
75/// Extract a range of bits from an integer at a dynamic offset.
76Value createDynamicExtract(OpBuilder &builder, Location loc, Value value,
77 Value offset, unsigned width);
78
79/// Replace a range of bits in an integer at a dynamic offset, and return the
80/// updated integer value. Calls `createInject` if the offset is constant.
81Value createDynamicInject(OpBuilder &builder, Location loc, Value value,
82 Value offset, Value replacement,
83 bool twoState = false);
84
85/// Replace a range of bits in an integer and return the updated integer value.
86Value createInject(OpBuilder &builder, Location loc, Value value,
87 unsigned offset, Value replacement);
88
89/// Replace a subtraction with an addition of the two's complement.
90LogicalResult convertSubToAdd(comb::SubOp subOp,
91 mlir::PatternRewriter &rewriter);
92
93/// Enum for mux chain folding styles.
95/// Mux chain folding that converts chains of muxes with index
96/// comparisons into array operations or balanced mux trees. `styleFn` is a
97/// callback that returns the desired folding style based on the index
98/// width and number of entries.
100 PatternRewriter &rewriter, MuxOp rootMux, bool isFalseSide,
101 llvm::function_ref<MuxChainWithComparisonFoldingStyle(size_t indexWidth,
102 size_t numEntries)>
103 styleFn);
104} // namespace comb
105} // namespace circt
106
107#endif // CIRCT_DIALECT_COMB_COMBOPS_H
void extractBits(OpBuilder &builder, Value val, SmallVectorImpl< Value > &bits)
Extract bits from a value.
Definition CombOps.cpp:78
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...
Value createOrFoldNot(Location loc, Value value, OpBuilder &builder, bool twoState=false)
Create a `‘Not’' gate on a value.
Definition CombOps.cpp:66
MuxChainWithComparisonFoldingStyle
Enum for mux chain folding styles.
Definition CombOps.h:94
@ BalancedMuxTree
Definition CombOps.h:94
LogicalResult convertSubToAdd(comb::SubOp subOp, mlir::PatternRewriter &rewriter)
Replace a subtraction with an addition of the two's complement.
Definition CombOps.cpp:221
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.
Definition CombOps.cpp:152
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.
Definition CombOps.cpp:187
Value createDynamicExtract(OpBuilder &builder, Location loc, Value value, Value offset, unsigned width)
Extract a range of bits from an integer at a dynamic offset.
Definition CombOps.cpp:132
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.
Definition CombOps.cpp:43
Value constructMuxTree(OpBuilder &builder, Location loc, ArrayRef< Value > selectors, ArrayRef< Value > leafNodes, Value outOfBoundsValue)
Construct a mux tree for given leaf nodes.
Definition CombOps.cpp:105
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.
Definition CombOps.cpp:25
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition comb.py:1