MLIR  22.0.0git
ToLLVMInterface.cpp
Go to the documentation of this file.
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 
10 #include "mlir/IR/Dialect.h"
11 #include "mlir/IR/Operation.h"
12 
13 using namespace mlir;
14 
16  Operation *root, ConversionTarget &target, LLVMTypeConverter &typeConverter,
18  DenseSet<Dialect *> dialects;
19  root->walk([&](Operation *op) {
20  Dialect *dialect = op->getDialect();
21  if (!dialects.insert(dialect).second)
22  return;
23  // First time we encounter this dialect: if it implements the interface,
24  // let's populate patterns !
25  auto *iface = dyn_cast<ConvertToLLVMPatternInterface>(dialect);
26  if (!iface)
27  return;
28  iface->populateConvertToLLVMConversionPatterns(target, typeConverter,
29  patterns);
30  });
31 }
32 
34  Operation *op, ConversionTarget &target, LLVMTypeConverter &typeConverter,
36  auto iface = dyn_cast<ConvertToLLVMOpInterface>(op);
37  if (!iface)
38  iface = op->getParentOfType<ConvertToLLVMOpInterface>();
39  if (!iface)
40  return;
42  iface.getConvertToLLVMConversionAttrs(attrs);
43  for (ConvertToLLVMAttrInterface attr : attrs)
44  attr.populateConvertToLLVMConversionPatterns(target, typeConverter,
45  patterns);
46 }
47 
48 #include "mlir/Conversion/ConvertToLLVM/ToLLVMAttrInterface.cpp.inc"
49 
50 #include "mlir/Conversion/ConvertToLLVM/ToLLVMOpInterface.cpp.inc"
This class describes a specific conversion target.
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
Definition: Dialect.h:38
Conversion from types to the LLVM IR dialect.
Definition: TypeConverter.h:35
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
Dialect * getDialect()
Return the dialect this operation is associated with, or nullptr if the associated dialect is not loa...
Definition: Operation.h:220
std::enable_if_t< llvm::function_traits< std::decay_t< FnT > >::num_args==1, RetT > walk(FnT &&callback)
Walk the operation by calling the callback for each nested operation (including this one),...
Definition: Operation.h:797
OpTy getParentOfType()
Return the closest surrounding parent operation that is of type 'OpTy'.
Definition: Operation.h:238
Include the generated interface declarations.
const FrozenRewritePatternSet & patterns
void populateConversionTargetFromOperation(Operation *op, ConversionTarget &target, TypeConverter &typeConverter, RewritePatternSet &patterns)
Recursively walk the IR and collect all dialects implementing the interface, and populate the convers...
void populateOpConvertToLLVMConversionPatterns(Operation *op, ConversionTarget &target, LLVMTypeConverter &typeConverter, RewritePatternSet &patterns)
Helper function for populating LLVM conversion patterns.