CIRCT  19.0.0git
CombToLLVM.cpp
Go to the documentation of this file.
1 //===- CombToLLVM.cpp - Comb to LLVM Conversion Pass ----------------------===//
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 is the main Comb to LLVM Conversion Pass Implementation.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 #include "../PassDetail.h"
16 #include "circt/Support/LLVM.h"
17 #include "mlir/Conversion/LLVMCommon/ConversionTarget.h"
18 #include "mlir/Conversion/LLVMCommon/Pattern.h"
19 #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
20 #include "mlir/Pass/Pass.h"
21 #include "mlir/Transforms/DialectConversion.h"
22 
23 using namespace mlir;
24 using namespace circt;
25 
26 namespace {
27 /// Convert a comb::ParityOp to the LLVM dialect.
28 struct CombParityOpConversion : public ConvertToLLVMPattern {
29  explicit CombParityOpConversion(MLIRContext *ctx,
30  LLVMTypeConverter &typeConverter)
31  : ConvertToLLVMPattern(comb::ParityOp::getOperationName(), ctx,
32  typeConverter) {}
33 
34  LogicalResult
35  matchAndRewrite(Operation *op, ArrayRef<Value> operands,
36  ConversionPatternRewriter &rewriter) const override {
37  auto parityOp = cast<comb::ParityOp>(op);
38 
39  auto popCount =
40  rewriter.create<LLVM::CtPopOp>(op->getLoc(), parityOp.getInput());
41  rewriter.replaceOpWithNewOp<LLVM::TruncOp>(
42  op, IntegerType::get(rewriter.getContext(), 1), popCount);
43 
44  return success();
45  }
46 };
47 } // namespace
48 
49 void circt::populateCombToLLVMConversionPatterns(LLVMTypeConverter &converter,
50  RewritePatternSet &patterns) {
51  patterns.add<CombParityOpConversion>(patterns.getContext(), converter);
52 }
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
Definition: CalyxOps.cpp:54
This file defines an intermediate representation for circuits acting as an abstraction for constraint...
Definition: DebugAnalysis.h:21
void populateCombToLLVMConversionPatterns(mlir::LLVMTypeConverter &converter, RewritePatternSet &patterns)
Get the Comb to LLVM conversion patterns.
Definition: comb.py:1