Loading [MathJax]/extensions/tex2jax.js
CIRCT 22.0.0git
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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/// Construct a full adder for three 1-bit inputs.
90std::pair<Value, Value> fullAdder(OpBuilder &builder, Location loc, Value a,
91 Value b, Value c);
92
93/// Perform Wallace tree reduction on partial products.
94/// See https://en.wikipedia.org/wiki/Wallace_tree
95/// \param targetAddends The number of addends to reduce to (2 for carry-save).
96/// \param inputAddends The rows of bits to be summed.
97SmallVector<Value> wallaceReduction(OpBuilder &builder, Location loc,
98 size_t width, size_t targetAddends,
99 SmallVector<SmallVector<Value>> &addends);
100
101} // namespace comb
102} // namespace circt
103
104#endif // CIRCT_DIALECT_COMB_COMBOPS_H
std::pair< Value, Value > fullAdder(OpBuilder &builder, Location loc, Value a, Value b, Value c)
Construct a full adder for three 1-bit inputs.
Definition CombOps.cpp:221
void extractBits(OpBuilder &builder, Value val, SmallVectorImpl< Value > &bits)
Extract bits from a value.
Definition CombOps.cpp:77
Value createOrFoldNot(Location loc, Value value, OpBuilder &builder, bool twoState=false)
Create a `‘Not’' gate on a value.
Definition CombOps.cpp:65
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:151
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:186
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:131
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:42
SmallVector< Value > wallaceReduction(OpBuilder &builder, Location loc, size_t width, size_t targetAddends, SmallVector< SmallVector< Value > > &addends)
Perform Wallace tree reduction on partial products.
Definition CombOps.cpp:238
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:104
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:24
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition comb.py:1