MLIR  19.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 
16 namespace mlir {
17 class ConversionTarget;
18 class LLVMTypeConverter;
19 class MLIRContext;
20 class Operation;
21 class RewritePatternSet;
22 
23 /// Base class for dialect interfaces providing translation to LLVM IR.
24 /// Dialects that can be translated should provide an implementation of this
25 /// interface for the supported operations. The interface may be implemented in
26 /// a separate library to avoid the "main" dialect library depending on LLVM IR.
27 /// The interface can be attached using the delayed registration mechanism
28 /// available in DialectRegistry.
30  : public DialectInterface::Base<ConvertToLLVMPatternInterface> {
31 public:
32  ConvertToLLVMPatternInterface(Dialect *dialect) : Base(dialect) {}
33 
34  /// Hook for derived dialect interface to load the dialects they
35  /// target. The LLVMDialect is implicitly already loaded, but this
36  /// method allows to load other intermediate dialects used in the
37  /// conversion, or target dialects like NVVM for example.
38  virtual void loadDependentDialects(MLIRContext *context) const {}
39 
40  /// Hook for derived dialect interface to provide conversion patterns
41  /// and mark dialect legal for the conversion target.
43  ConversionTarget &target, LLVMTypeConverter &typeConverter,
44  RewritePatternSet &patterns) const = 0;
45 };
46 
47 /// Recursively walk the IR and collect all dialects implementing the interface,
48 /// and populate the conversion patterns.
50  ConversionTarget &target,
51  LLVMTypeConverter &typeConverter,
52  RewritePatternSet &patterns);
53 
54 } // namespace mlir
55 
56 #endif // MLIR_CONVERSION_CONVERTTOLLVM_TOLLVMINTERFACE_H
This class describes a specific conversion target.
Base class for dialect interfaces providing translation to LLVM IR.
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)
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
Definition: Dialect.h:41
Conversion from types to the LLVM IR dialect.
Definition: TypeConverter.h:34
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:60
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
The base class used for all derived interface types.
Include the generated interface declarations.
void populateConversionTargetFromOperation(Operation *op, ConversionTarget &target, LLVMTypeConverter &typeConverter, RewritePatternSet &patterns)
Recursively walk the IR and collect all dialects implementing the interface, and populate the convers...