1//===- ToLLVMInterface.cpp - MLIR LLVM Conversion -------------------------===//
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#include "mlir/Conversion/ConvertToLLVM/ToLLVMInterface.h"
10#include "mlir/IR/Dialect.h"
11#include "mlir/IR/Operation.h"
12#include "llvm/ADT/DenseSet.h"
13
14using namespace mlir;
15
16void mlir::populateConversionTargetFromOperation(
17 Operation *root, ConversionTarget &target, LLVMTypeConverter &typeConverter,
18 RewritePatternSet &patterns) {
19 DenseSet<Dialect *> dialects;
20 root->walk(callback: [&](Operation *op) {
21 Dialect *dialect = op->getDialect();
22 if (!dialects.insert(V: dialect).second)
23 return;
24 // First time we encounter this dialect: if it implements the interface,
25 // let's populate patterns !
26 auto *iface = dyn_cast<ConvertToLLVMPatternInterface>(Val: dialect);
27 if (!iface)
28 return;
29 iface->populateConvertToLLVMConversionPatterns(target, typeConverter,
30 patterns);
31 });
32}
33

source code of mlir/lib/Conversion/ConvertToLLVM/ToLLVMInterface.cpp