CIRCT 23.0.0git
Loading...
Searching...
No Matches
DatapathToComb.cpp
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
14#include "mlir/Analysis/TopologicalSortUtils.h"
15#include "mlir/Dialect/Func/IR/FuncOps.h"
16#include "mlir/IR/PatternMatch.h"
17#include "mlir/Pass/Pass.h"
18#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
19#include "llvm/Support/Debug.h"
20#include "llvm/Support/KnownBits.h"
21#include <algorithm>
22
23#define DEBUG_TYPE "datapath-to-comb"
24
25namespace circt {
26#define GEN_PASS_DEF_CONVERTDATAPATHTOCOMB
27#include "circt/Conversion/Passes.h.inc"
28} // namespace circt
29
30using namespace circt;
31using namespace datapath;
32
33// A wrapper for comb::extractBits that returns a SmallVector<Value>.
34static SmallVector<Value> extractBits(OpBuilder &builder, Value val) {
35 SmallVector<Value> bits;
36 comb::extractBits(builder, val, bits);
37 return bits;
38}
39
40//===----------------------------------------------------------------------===//
41// Conversion patterns
42//===----------------------------------------------------------------------===//
43
44namespace {
45// Replace compressor by an adder of the inputs and zero for the other results:
46// compress(a,b,c,d) -> {a+b+c+d, 0}
47// Facilitates use of downstream compression algorithms e.g. Yosys
48struct DatapathCompressOpAddConversion : mlir::OpRewritePattern<CompressOp> {
50 LogicalResult
51 matchAndRewrite(CompressOp op,
52 mlir::PatternRewriter &rewriter) const override {
53 Location loc = op.getLoc();
54 auto inputs = op.getOperands();
55 unsigned width = inputs[0].getType().getIntOrFloatBitWidth();
56 // Sum all the inputs - set that to result value 0
57 auto addOp = comb::AddOp::create(rewriter, loc, inputs, true);
58 // Replace remaining results with zeros
59 auto zeroOp = hw::ConstantOp::create(rewriter, loc, APInt(width, 0));
60 SmallVector<Value> results(op.getNumResults() - 1, zeroOp);
61 results.push_back(addOp);
62 rewriter.replaceOp(op, results);
63 return success();
64 }
65};
66
67// Replace compressor by a wallace tree of full-adders
68struct DatapathCompressOpConversion : mlir::OpRewritePattern<CompressOp> {
69 DatapathCompressOpConversion(MLIRContext *context,
71 : mlir::OpRewritePattern<CompressOp>(context), analysis(analysis) {}
72
73 LogicalResult
74 matchAndRewrite(CompressOp op,
75 mlir::PatternRewriter &rewriter) const override {
76 Location loc = op.getLoc();
77 auto inputs = op.getOperands();
78
79 SmallVector<SmallVector<Value>> addends;
80 for (auto input : inputs) {
81 addends.push_back(
82 extractBits(rewriter, input)); // Extract bits from each input
83 }
84
85 // Compressor tree reduction
86 auto width = inputs[0].getType().getIntOrFloatBitWidth();
87 auto targetAddends = op.getNumResults();
88 datapath::CompressorTree comp(width, addends, loc);
89
90 if (analysis) {
91 // Update delay information with arrival times
92 if (failed(comp.withInputDelays(
93 [&](Value v) { return analysis->getMaxDelay(v, 0); })))
94 return failure();
95 }
96
97 rewriter.replaceOp(op, comp.compressToHeight(rewriter, targetAddends));
98 return success();
99 }
100
101private:
102 synth::IncrementalLongestPathAnalysis *analysis = nullptr;
103};
104
105struct DatapathPartialProductOpConversion : OpRewritePattern<PartialProductOp> {
106 using OpRewritePattern<PartialProductOp>::OpRewritePattern;
107
108 DatapathPartialProductOpConversion(MLIRContext *context, bool forceBooth)
109 : OpRewritePattern<PartialProductOp>(context), forceBooth(forceBooth){};
110
111 const bool forceBooth;
112
113 LogicalResult matchAndRewrite(PartialProductOp op,
114 PatternRewriter &rewriter) const override {
115
116 Value a = op.getLhs();
117 Value b = op.getRhs();
118 unsigned width = a.getType().getIntOrFloatBitWidth();
119
120 // Skip a zero width value.
121 if (width == 0) {
122 rewriter.replaceOpWithNewOp<hw::ConstantOp>(op, op.getType(0), 0);
123 return success();
124 }
125
126 // Square partial product array can be reduced to upper triangular array.
127 // For example: AND array for a 4-bit squarer:
128 // 0 0 0 a0a3 a0a2 a0a1 a0a0
129 // 0 0 a1a3 a1a2 a1a1 a1a0 0
130 // 0 a2a3 a2a2 a2a1 a2a0 0 0
131 // a3a3 a3a2 a3a1 a3a0 0 0 0
132 //
133 // Can be reduced to:
134 // 0 0 a0a3 a0a2 a0a1 0 a0
135 // 0 a1a3 a1a2 0 a1 0 0
136 // a2a3 0 a2 0 0 0 0
137 // a3 0 0 0 0 0 0
138 if (a == b)
139 return lowerSqrAndArray(rewriter, a, op, width);
140
141 // Use result rows as a heuristic to guide partial product
142 // implementation
143 if (op.getNumResults() > 16 || forceBooth)
144 return lowerBoothArray(rewriter, a, b, op, width);
145 else
146 return lowerAndArray(rewriter, a, b, op, width);
147 }
148
149private:
150 static LogicalResult lowerAndArray(PatternRewriter &rewriter, Value a,
151 Value b, PartialProductOp op,
152 unsigned width) {
153
154 Location loc = op.getLoc();
155 // Keep a as a bitvector - multiply by each digit of b
156 SmallVector<Value> bBits = extractBits(rewriter, b);
157
158 auto rowWidth = width;
159 auto knownBitsA = comb::computeKnownBits(a);
160 if (!knownBitsA.Zero.isZero()) {
161 if (knownBitsA.Zero.countLeadingOnes() > 1) {
162 rowWidth -= knownBitsA.Zero.countLeadingOnes();
163 a = rewriter.createOrFold<comb::ExtractOp>(loc, a, 0, rowWidth);
164 }
165 }
166
167 SmallVector<Value> partialProducts;
168 partialProducts.reserve(width);
169 // AND Array Construction:
170 // partialProducts[i] = ({b[i],..., b[i]} & a) << i
171 assert(op.getNumResults() <= width &&
172 "Cannot return more results than the operator width");
173
174 for (unsigned i = 0; i < op.getNumResults(); ++i) {
175 auto repl =
176 rewriter.createOrFold<comb::ReplicateOp>(loc, bBits[i], rowWidth);
177 auto ppRow = rewriter.createOrFold<comb::AndOp>(loc, repl, a);
178 if (rowWidth < width) {
179 auto padding = width - rowWidth;
180 auto zeroPad = hw::ConstantOp::create(rewriter, loc, APInt(padding, 0));
181 ppRow = rewriter.createOrFold<comb::ConcatOp>(
182 loc, ValueRange{zeroPad, ppRow}); // Pad to full width
183 }
184
185 if (i == 0) {
186 partialProducts.push_back(ppRow);
187 continue;
188 }
189 auto shiftBy = hw::ConstantOp::create(rewriter, loc, APInt(i, 0));
190 auto ppAlign =
191 comb::ConcatOp::create(rewriter, loc, ValueRange{ppRow, shiftBy});
192 auto ppAlignTrunc = rewriter.createOrFold<comb::ExtractOp>(
193 loc, ppAlign, 0, width); // Truncate to width+i bits
194 partialProducts.push_back(ppAlignTrunc);
195 }
196
197 rewriter.replaceOp(op, partialProducts);
198 return success();
199 }
200
201 static LogicalResult lowerSqrAndArray(PatternRewriter &rewriter, Value a,
202 PartialProductOp op, unsigned width) {
203
204 Location loc = op.getLoc();
205 SmallVector<Value> aBits = extractBits(rewriter, a);
206
207 SmallVector<Value> partialProducts;
208 partialProducts.reserve(width);
209 // AND Array Construction - reducing to upper triangle:
210 // partialProducts[i] = ({a[i],..., a[i]} & a) << i
211 // optimised to: {a[i] & a[n-1], ..., a[i] & a[i+1], 0, a[i], 0, ..., 0}
212 assert(op.getNumResults() <= width &&
213 "Cannot return more results than the operator width");
214 auto zeroFalse = hw::ConstantOp::create(rewriter, loc, APInt(1, 0));
215 for (unsigned i = 0; i < op.getNumResults(); ++i) {
216 SmallVector<Value> row;
217 row.reserve(width);
218
219 if (2 * i >= width) {
220 // Pad the remaining rows with zeros
221 auto zeroWidth = hw::ConstantOp::create(rewriter, loc, APInt(width, 0));
222 partialProducts.push_back(zeroWidth);
223 continue;
224 }
225
226 if (i > 0) {
227 auto shiftBy = hw::ConstantOp::create(rewriter, loc, APInt(2 * i, 0));
228 row.push_back(shiftBy);
229 }
230 row.push_back(aBits[i]);
231
232 // Track width of constructed row
233 unsigned rowWidth = 2 * i + 1;
234 if (rowWidth < width) {
235 row.push_back(zeroFalse);
236 ++rowWidth;
237 }
238
239 for (unsigned j = i + 1; j < width; ++j) {
240 // Stop when we reach the required width
241 if (rowWidth == width)
242 break;
243
244 // Otherwise pad with zeros or partial product bits
245 ++rowWidth;
246 // Number of results indicates number of non-zero bits in input
247 if (j >= op.getNumResults()) {
248 row.push_back(zeroFalse);
249 continue;
250 }
251
252 auto ppBit =
253 rewriter.createOrFold<comb::AndOp>(loc, aBits[i], aBits[j]);
254 row.push_back(ppBit);
255 }
256 std::reverse(row.begin(), row.end());
257 auto ppRow = comb::ConcatOp::create(rewriter, loc, row);
258 partialProducts.push_back(ppRow);
259 }
260
261 rewriter.replaceOp(op, partialProducts);
262 return success();
263 }
264
265 static LogicalResult lowerBoothArray(PatternRewriter &rewriter, Value a,
266 Value b, PartialProductOp op,
267 unsigned width) {
268 Location loc = op.getLoc();
269 auto zeroFalse = hw::ConstantOp::create(rewriter, loc, APInt(1, 0));
270 auto zeroWidth = hw::ConstantOp::create(rewriter, loc, APInt(width, 0));
271
272 // Detect leading zeros in multiplicand due to zero-extension
273 // and truncate to reduce partial product bits
274 // {'0, a} * {'0, b}
275 auto rowWidth = width;
276 auto knownBitsA = comb::computeKnownBits(a);
277 if (!knownBitsA.Zero.isZero()) {
278 if (knownBitsA.Zero.countLeadingOnes() > 1) {
279 // Retain one leading zero to represent 2*{1'b0, a} = {a, 1'b0}
280 // {'0, a} -> {1'b0, a}
281 rowWidth -= knownBitsA.Zero.countLeadingOnes() - 1;
282 a = rewriter.createOrFold<comb::ExtractOp>(loc, a, 0, rowWidth);
283 }
284 }
285
286 // TODO - replace with a concatenation to aid longest path analysis
287 auto oneRowWidth =
288 hw::ConstantOp::create(rewriter, loc, APInt(rowWidth, 1));
289 // Booth encoding will select each row from {-2a, -1a, 0, 1a, 2a}
290 Value twoA = rewriter.createOrFold<comb::ShlOp>(loc, a, oneRowWidth);
291
292 // Encode based on the bits of b
293 // TODO: sort a and b based on non-zero bits to encode the smaller input
294 SmallVector<Value> bBits = extractBits(rewriter, b);
295
296 // Identify zero bits of b to reduce height of partial product array
297 auto bWidth = b.getType().getIntOrFloatBitWidth();
298 auto knownBitsB = comb::computeKnownBits(b);
299 if (!knownBitsB.Zero.isZero()) {
300 bWidth -= knownBitsB.Zero.countLeadingOnes();
301 for (unsigned i = 0; i < width; ++i)
302 if (knownBitsB.Zero[i])
303 bBits[i] = zeroFalse;
304 }
305
306 SmallVector<Value> partialProducts;
307 partialProducts.reserve(width);
308
309 // Booth encoding halves array height by grouping three bits at a time:
310 // partialProducts[i] = a * (-2*b[2*i+1] + b[2*i] + b[2*i-1]) << 2*i
311 // encNeg \approx (-2*b[2*i+1] + b[2*i] + b[2*i-1]) <= 0
312 // encOne = (-2*b[2*i+1] + b[2*i] + b[2*i-1]) == +/- 1
313 // encTwo = (-2*b[2*i+1] + b[2*i] + b[2*i-1]) == +/- 2
314 SmallVector<Value> encNegs;
315 Value encNegPrev;
316
317 // For even width - additional row contains the final sign correction
318 for (unsigned i = 0; i <= width; i += 2) {
319 // Get Booth bits: b[i+1], b[i], b[i-1] (b[-1] = 0)
320 Value bim1 = (i == 0) ? zeroFalse : bBits[i - 1];
321 Value bi = (i < width) ? bBits[i] : zeroFalse;
322 Value bip1 = (i + 1 < width) ? bBits[i + 1] : zeroFalse;
323
324 // Is the encoding zero or negative (an approximation)
325 Value encNeg = bip1;
326 encNegs.push_back(encNeg); // Store for sign-extension optimisation
327 // Is the encoding one = b[i] xor b[i-1]
328 Value encOne = rewriter.createOrFold<comb::XorOp>(loc, bi, bim1, true);
329 // Is the encoding two = (bip1 & ~bi & ~bim1) | (~bip1 & bi & bim1)
330 Value constOne = hw::ConstantOp::create(rewriter, loc, APInt(1, 1));
331 Value biInv = rewriter.createOrFold<comb::XorOp>(loc, bi, constOne, true);
332 Value bip1Inv =
333 rewriter.createOrFold<comb::XorOp>(loc, bip1, constOne, true);
334 Value bim1Inv =
335 rewriter.createOrFold<comb::XorOp>(loc, bim1, constOne, true);
336
337 Value andLeft = rewriter.createOrFold<comb::AndOp>(
338 loc, ValueRange{bip1Inv, bi, bim1}, true);
339 Value andRight = rewriter.createOrFold<comb::AndOp>(
340 loc, ValueRange{bip1, biInv, bim1Inv}, true);
341 Value encTwo =
342 rewriter.createOrFold<comb::OrOp>(loc, andLeft, andRight, true);
343
344 Value encNegRepl =
345 rewriter.createOrFold<comb::ReplicateOp>(loc, encNeg, rowWidth);
346 Value encOneRepl =
347 rewriter.createOrFold<comb::ReplicateOp>(loc, encOne, rowWidth);
348 Value encTwoRepl =
349 rewriter.createOrFold<comb::ReplicateOp>(loc, encTwo, rowWidth);
350
351 // Select between 2*a or 1*a or 0*a
352 Value selTwoA = rewriter.createOrFold<comb::AndOp>(loc, encTwoRepl, twoA);
353 Value selOneA = rewriter.createOrFold<comb::AndOp>(loc, encOneRepl, a);
354 Value magA =
355 rewriter.createOrFold<comb::OrOp>(loc, selTwoA, selOneA, true);
356
357 // Conditionally invert the row
358 Value ppRow =
359 rewriter.createOrFold<comb::XorOp>(loc, magA, encNegRepl, true);
360
361 // No sign-correction in the first row
362 if (i == 0) {
363 partialProducts.push_back(ppRow);
364 encNegPrev = encNeg;
365 continue;
366 }
367
368 if (i == 2) {
369 Value withSignCorrection = rewriter.createOrFold<comb::ConcatOp>(
370 loc, ValueRange{ppRow, zeroFalse, encNegPrev});
371 partialProducts.push_back(withSignCorrection);
372 encNegPrev = encNeg;
373 continue;
374 }
375
376 // Insert a sign-correction from the previous row
377 // {ppRow, 0, encNegPrev} << (i-2)
378 Value shiftBy = hw::ConstantOp::create(rewriter, loc, APInt(i - 2, 0));
379 Value withSignCorrection = rewriter.createOrFold<comb::ConcatOp>(
380 loc, ValueRange{ppRow, zeroFalse, encNegPrev, shiftBy});
381 partialProducts.push_back(withSignCorrection);
382 encNegPrev = encNeg;
383
384 if (partialProducts.size() == op.getNumResults())
385 break;
386
387 // Next row would be all zeros - need to account for the sign-correction
388 // of the previous row so the last row added is:
389 // {0, 0, 0, 0, 0, encNegPrev} << i
390 if (i > bWidth + 1)
391 break;
392 }
393
394 // Sign-extension:
395 // { s1, s1, s1, s1, s1, p1}
396 // { s2, s2, s2, p2 }
397 // { s3, p3 }
398 // TODO: optimize by only replicating the sign bit once using
399 // typical sign-extension trick - can be handled by separate
400 // canonicalization patterns
401 for (unsigned i = 0; i < partialProducts.size(); ++i) {
402 auto ppRow = partialProducts[i];
403 auto encNeg = encNegs[i];
404 auto ppWidth = ppRow.getType().getIntOrFloatBitWidth();
405 if (ppWidth < width) {
406 auto padding = width - ppWidth;
407
408 // Replicate the encNeg bit for sign-extension
409 Value encNegPad =
410 rewriter.createOrFold<comb::ReplicateOp>(loc, encNeg, padding);
411 ppRow = rewriter.createOrFold<comb::ConcatOp>(
412 loc, ValueRange{encNegPad, ppRow}); // Pad to full width
413 }
414
415 // Truncate any excess bits
416 ppWidth = ppRow.getType().getIntOrFloatBitWidth();
417 if (ppWidth > width) {
418 ppRow = rewriter.createOrFold<comb::ExtractOp>(loc, ppRow, 0, width);
419 }
420 partialProducts[i] = ppRow;
421 assert(partialProducts[i].getType().getIntOrFloatBitWidth() == width &&
422 "Expected sign-extended partial product to be full width");
423 }
424
425 // Zero-pad to match the required output width
426 while (partialProducts.size() < op.getNumResults())
427 partialProducts.push_back(zeroWidth);
428
429 assert(partialProducts.size() == op.getNumResults() &&
430 "Expected number of booth partial products to match results");
431
432 rewriter.replaceOp(op, partialProducts);
433 return success();
434 }
435};
436
437struct DatapathPosPartialProductOpConversion
438 : OpRewritePattern<PosPartialProductOp> {
439 using OpRewritePattern<PosPartialProductOp>::OpRewritePattern;
440
441 DatapathPosPartialProductOpConversion(MLIRContext *context, bool forceBooth)
442 : OpRewritePattern<PosPartialProductOp>(context),
443 forceBooth(forceBooth){};
444
445 const bool forceBooth;
446
447 LogicalResult matchAndRewrite(PosPartialProductOp op,
448 PatternRewriter &rewriter) const override {
449
450 Value a = op.getAddend0();
451 Value b = op.getAddend1();
452 Value c = op.getMultiplicand();
453 unsigned width = a.getType().getIntOrFloatBitWidth();
454
455 // Skip a zero width value.
456 if (width == 0) {
457 rewriter.replaceOpWithNewOp<hw::ConstantOp>(op, op.getType(0), 0);
458 return success();
459 }
460
461 // TODO: Implement Booth lowering
462 return lowerAndArray(rewriter, a, b, c, op, width);
463 }
464
465private:
466 static LogicalResult lowerAndArray(PatternRewriter &rewriter, Value a,
467 Value b, Value c, PosPartialProductOp op,
468 unsigned width) {
469
470 Location loc = op.getLoc();
471 // Encode (a+b) by implementing a half-adder - then note the following
472 // fact carry[i] & save[i] == false
473 auto carry = rewriter.createOrFold<comb::AndOp>(loc, a, b);
474 auto save = rewriter.createOrFold<comb::XorOp>(loc, a, b);
475
476 SmallVector<Value> carryBits = extractBits(rewriter, carry);
477 SmallVector<Value> saveBits = extractBits(rewriter, save);
478
479 // Reduce c width based on leading zeros
480 auto rowWidth = width;
481 auto knownBitsC = comb::computeKnownBits(c);
482 if (!knownBitsC.Zero.isZero()) {
483 if (knownBitsC.Zero.countLeadingOnes() > 1) {
484 // Retain one leading zero to represent 2*{1'b0, c} = {c, 1'b0}
485 // {'0, c} -> {1'b0, c}
486 rowWidth -= knownBitsC.Zero.countLeadingOnes() - 1;
487 c = rewriter.createOrFold<comb::ExtractOp>(loc, c, 0, rowWidth);
488 }
489 }
490
491 // Compute 2*c for use in array construction
492 Value zero = hw::ConstantOp::create(rewriter, loc, APInt(1, 0));
493 Value twoCWider =
494 comb::ConcatOp::create(rewriter, loc, ValueRange{c, zero});
495 Value twoC = comb::ExtractOp::create(rewriter, loc, twoCWider, 0, rowWidth);
496
497 // AND Array Construction:
498 // pp[i] = ( (carry[i] * (c<<1)) | (save[i] * c) ) << i
499 SmallVector<Value> partialProducts;
500 partialProducts.reserve(width);
501
502 assert(op.getNumResults() <= width &&
503 "Cannot return more results than the operator width");
504
505 for (unsigned i = 0; i < op.getNumResults(); ++i) {
506 auto replSave =
507 rewriter.createOrFold<comb::ReplicateOp>(loc, saveBits[i], rowWidth);
508 auto replCarry =
509 rewriter.createOrFold<comb::ReplicateOp>(loc, carryBits[i], rowWidth);
510
511 auto ppRowSave = rewriter.createOrFold<comb::AndOp>(loc, replSave, c);
512 auto ppRowCarry =
513 rewriter.createOrFold<comb::AndOp>(loc, replCarry, twoC);
514 auto ppRow =
515 rewriter.createOrFold<comb::OrOp>(loc, ppRowSave, ppRowCarry);
516 auto ppAlign = ppRow;
517 if (i > 0) {
518 auto shiftBy = hw::ConstantOp::create(rewriter, loc, APInt(i, 0));
519 ppAlign =
520 comb::ConcatOp::create(rewriter, loc, ValueRange{ppRow, shiftBy});
521 }
522
523 // May need to truncate shifted value
524 if (rowWidth + i > width) {
525 auto ppAlignTrunc =
526 rewriter.createOrFold<comb::ExtractOp>(loc, ppAlign, 0, width);
527 partialProducts.push_back(ppAlignTrunc);
528 continue;
529 }
530 // May need to zero pad to approriate width
531 if (rowWidth + i < width) {
532 auto padding = width - rowWidth - i;
533 Value zeroPad =
534 hw::ConstantOp::create(rewriter, loc, APInt(padding, 0));
535 partialProducts.push_back(rewriter.createOrFold<comb::ConcatOp>(
536 loc, ValueRange{zeroPad, ppAlign})); // Pad to full width
537 continue;
538 }
539
540 partialProducts.push_back(ppAlign);
541 }
542
543 rewriter.replaceOp(op, partialProducts);
544 return success();
545 }
546};
547
548} // namespace
549
550//===----------------------------------------------------------------------===//
551// Convert Datapath to Comb pass
552//===----------------------------------------------------------------------===//
553
554namespace {
555struct ConvertDatapathToCombPass
556 : public impl::ConvertDatapathToCombBase<ConvertDatapathToCombPass> {
557 void runOnOperation() override;
558 using ConvertDatapathToCombBase<
559 ConvertDatapathToCombPass>::ConvertDatapathToCombBase;
560};
561} // namespace
562
564 Operation *op, RewritePatternSet &&patterns,
566 // TODO: Topologically sort the operations in the module to ensure that all
567 // dependencies are processed before their users.
568 mlir::GreedyRewriteConfig config;
569 // Set the listener to update timing information
570 // HACK: Setting max iterations to 2 to ensure that the patterns are
571 // one-shot, making sure target operations are datapath operations are
572 // replaced.
573 config.setMaxIterations(2).setListener(analysis).setUseTopDownTraversal(true);
574
575 // Apply the patterns greedily
576 if (failed(mlir::applyPatternsGreedily(op, std::move(patterns), config)))
577 return failure();
578
579 return success();
580}
581
582void ConvertDatapathToCombPass::runOnOperation() {
583 RewritePatternSet patterns(&getContext());
584
585 patterns.add<DatapathPartialProductOpConversion,
586 DatapathPosPartialProductOpConversion>(patterns.getContext(),
587 forceBooth);
588 synth::IncrementalLongestPathAnalysis *analysis = nullptr;
589 if (timingAware)
590 analysis = &getAnalysis<synth::IncrementalLongestPathAnalysis>();
591 if (lowerCompressToAdd)
592 // Lower compressors to simple add operations for downstream optimisations
593 patterns.add<DatapathCompressOpAddConversion>(patterns.getContext());
594 else
595 // Lower compressors to a complete gate-level implementation
596 patterns.add<DatapathCompressOpConversion>(patterns.getContext(), analysis);
597
599 getOperation(), std::move(patterns), analysis)))
600 return signalPassFailure();
601
602 // Verify that all Datapath operations have been successfully converted.
603 // Walk the operation and check for any remaining Datapath dialect
604 // operations.
605 auto result = getOperation()->walk([&](Operation *op) {
606 if (llvm::isa_and_nonnull<datapath::DatapathDialect>(op->getDialect())) {
607 op->emitError("Datapath operation not converted: ") << *op;
608 return WalkResult::interrupt();
609 }
610 return WalkResult::advance();
611 });
612 if (result.wasInterrupted())
613 return signalPassFailure();
614}
assert(baseType &&"element must be base type")
static SmallVector< Value > extractBits(OpBuilder &builder, Value val)
static Value zeroPad(PatternRewriter &rewriter, Location loc, Value input, size_t targetWidth, size_t trailingZeros)
static SmallVector< Value > extractBits(OpBuilder &builder, Value val)
static LogicalResult applyPatternsGreedilyWithTimingInfo(Operation *op, RewritePatternSet &&patterns, synth::IncrementalLongestPathAnalysis *analysis)
static std::unique_ptr< Context > context
create(low_bit, result_type, input=None)
Definition comb.py:187
create(data_type, value)
Definition hw.py:433
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.