CIRCT 22.0.0git
Loading...
Searching...
No Matches
DatapathOps.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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#ifndef CIRCT_DIALECT_DATAPATH_DATAPATHOPS_H
10#define CIRCT_DIALECT_DATAPATH_DATAPATHOPS_H
11
12#include "mlir/IR/OpImplementation.h"
13
16
17#define GET_OP_CLASSES
18#include "circt/Dialect/Datapath/Datapath.h.inc"
19
20namespace circt {
21namespace datapath {
22
23// A pair used to track compressor bits
25 Value val;
26 int64_t delay;
27};
28
29// A general compressor tree interface based around a column-wise
30// representation. Contains alternative compression algorithms.
32public:
33 // Constructor takes addends as input and converts to column representation
34 CompressorTree(size_t width, const SmallVector<SmallVector<Value>> &addends,
35 Location loc);
36
37 // Get the number of columns (bit positions)
38 size_t getWidth() const { return columns.size(); }
39
40 // Get the maximum height of the addend array
41 size_t getMaxHeight() const;
42
43 // Get the target height of next stage
44 size_t getNextStageTargetHeight() const;
45
46 // Update the input delays based on longest path analysis
47 LogicalResult
48 withInputDelays(llvm::function_ref<FailureOr<int64_t>(Value)> getDelay);
49
50 // Apply a compression step (reduce columns with >2 bits using compressors)
51 SmallVector<Value> compressToHeight(OpBuilder &builder, size_t targetHeight);
52
53 // Debug: print the tree structure
54 void dump() const;
55
56private:
57 // Column-wise bit storage - columns[i] contains all bits at bit position i
58 SmallVector<SmallVector<CompressorBit>> columns;
59
60 // Bitwidth of compressor tree
61 const size_t width;
62
63 // Number of reduction stages
64 size_t numStages;
65
66 // Number of full adders used
68
69 // Location of compressor to replace
70 Location loc;
71
72 SmallVector<Value> columnsToAddends(OpBuilder &builder, size_t targetHeight);
73
74 // Perform timing driven compression using Dadda's algorithm
75 SmallVector<Value> compressUsingTiming(OpBuilder &builder,
76 size_t targetHeight);
77
78 // Create a full-adder and update delay of sum and carry bits
79 std::pair<CompressorBit, CompressorBit> fullAdderWithDelay(OpBuilder &builder,
83 // Create a half-adder and update delay of sum and carry bits
84 std::pair<CompressorBit, CompressorBit>
85 halfAdderWithDelay(OpBuilder &builder, CompressorBit a, CompressorBit b);
86};
87
88} // namespace datapath
89} // namespace circt
90
91#endif // CIRCT_DIALECT_DATAPATH_DATAPATHOPS_H
SmallVector< SmallVector< CompressorBit > > columns
Definition DatapathOps.h:58
SmallVector< Value > compressToHeight(OpBuilder &builder, size_t targetHeight)
SmallVector< Value > columnsToAddends(OpBuilder &builder, size_t targetHeight)
LogicalResult withInputDelays(llvm::function_ref< FailureOr< int64_t >(Value)> getDelay)
std::pair< CompressorBit, CompressorBit > halfAdderWithDelay(OpBuilder &builder, CompressorBit a, CompressorBit b)
std::pair< CompressorBit, CompressorBit > fullAdderWithDelay(OpBuilder &builder, CompressorBit a, CompressorBit b, CompressorBit c)
SmallVector< Value > compressUsingTiming(OpBuilder &builder, size_t targetHeight)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.