MLIR 22.0.0git
ToLLVMInterface.h
Go to the documentation of this file.
1//===- ToLLVMInterface.h - Conversion to LLVM iface ---*- C++ -*-=============//
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#ifndef MLIR_CONVERSION_CONVERTTOLLVM_TOLLVMINTERFACE_H
10#define MLIR_CONVERSION_CONVERTTOLLVM_TOLLVMINTERFACE_H
11
13#include "mlir/IR/MLIRContext.h"
15
16namespace mlir {
17class ConversionTarget;
19class MLIRContext;
20class Operation;
22class AnalysisManager;
23
24/// Base class for dialect interfaces providing translation to LLVM IR.
25/// Dialects that can be translated should provide an implementation of this
26/// interface for the supported operations. The interface may be implemented in
27/// a separate library to avoid the "main" dialect library depending on LLVM IR.
28/// The interface can be attached using the delayed registration mechanism
29/// available in DialectRegistry.
31 : public DialectInterface::Base<ConvertToLLVMPatternInterface> {
32public:
34
35 /// Hook for derived dialect interface to load the dialects they
36 /// target. The LLVMDialect is implicitly already loaded, but this
37 /// method allows to load other intermediate dialects used in the
38 /// conversion, or target dialects like NVVM for example.
39 virtual void loadDependentDialects(MLIRContext *context) const {}
40
41 /// Hook for derived dialect interface to provide conversion patterns
42 /// and mark dialect legal for the conversion target.
45 RewritePatternSet &patterns) const = 0;
46};
47
48/// Recursively walk the IR and collect all dialects implementing the interface,
49/// and populate the conversion patterns.
52 LLVMTypeConverter &typeConverter,
54
55/// Helper function for populating LLVM conversion patterns. If `op` implements
56/// the `ConvertToLLVMOpInterface` interface, then the LLVM conversion pattern
57/// attributes provided by the interface will be used to configure the
58/// conversion target, type converter, and the pattern set.
61 LLVMTypeConverter &typeConverter,
63} // namespace mlir
64
65#include "mlir/Conversion/ConvertToLLVM/ToLLVMAttrInterface.h.inc"
66
67#include "mlir/Conversion/ConvertToLLVM/ToLLVMOpInterface.h.inc"
68
69#endif // MLIR_CONVERSION_CONVERTTOLLVM_TOLLVMINTERFACE_H
This class represents an analysis manager for a particular operation instance.
virtual void populateConvertToLLVMConversionPatterns(ConversionTarget &target, LLVMTypeConverter &typeConverter, RewritePatternSet &patterns) const =0
Hook for derived dialect interface to provide conversion patterns and mark dialect legal for the conv...
virtual void loadDependentDialects(MLIRContext *context) const
Hook for derived dialect interface to load the dialects they target.
ConvertToLLVMPatternInterface(Dialect *dialect)
detail::DialectInterfaceBase< ConcreteType, DialectInterface > Base
The base class used for all derived interface types.
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.
MLIRContext is the top-level object for a collection of MLIR operations.
Definition MLIRContext.h:63
Operation is the basic unit of execution within MLIR.
Definition Operation.h:88
DialectInterfaceBase< ConcreteType, DialectInterface > Base
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.