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