Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mlir/include/mlir/Conversion/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ mlir_tablegen(Passes.capi.cpp.inc -gen-pass-capi-impl --prefix Conversion)
add_public_tablegen_target(MLIRConversionPassIncGen)

add_mlir_doc(Passes ConversionPasses ./ -gen-pass-doc)

add_subdirectory(ConvertToLLVM)
7 changes: 7 additions & 0 deletions mlir/include/mlir/Conversion/ConvertToLLVM/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(LLVM_TARGET_DEFINITIONS ToLLVMInterface.td)
mlir_tablegen(ToLLVMAttrInterface.h.inc -gen-attr-interface-decls)
mlir_tablegen(ToLLVMAttrInterface.cpp.inc -gen-attr-interface-defs)
mlir_tablegen(ToLLVMOpInterface.h.inc -gen-op-interface-decls)
mlir_tablegen(ToLLVMOpInterface.cpp.inc -gen-op-interface-defs)
add_public_tablegen_target(MLIRConvertToLLVMInterfaceIncGen)
add_dependencies(mlir-generic-headers MLIRConvertToLLVMInterfaceIncGen)
14 changes: 14 additions & 0 deletions mlir/include/mlir/Conversion/ConvertToLLVM/ToLLVMInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@

#include "mlir/IR/DialectInterface.h"
#include "mlir/IR/MLIRContext.h"
#include "mlir/IR/OpDefinition.h"

namespace mlir {
class ConversionTarget;
class LLVMTypeConverter;
class MLIRContext;
class Operation;
class RewritePatternSet;
class AnalysisManager;

/// Base class for dialect interfaces providing translation to LLVM IR.
/// Dialects that can be translated should provide an implementation of this
Expand Down Expand Up @@ -50,6 +52,18 @@ void populateConversionTargetFromOperation(Operation *op,
LLVMTypeConverter &typeConverter,
RewritePatternSet &patterns);

/// Helper function for populating LLVM conversion patterns. If `op` implements
/// the `ConvertToLLVMOpInterface` interface, then the LLVM conversion pattern
/// attributes provided by the interface will be used to configure the
/// conversion target, type converter, and the pattern set.
void populateOpConvertToLLVMConversionPatterns(Operation *op,
ConversionTarget &target,
LLVMTypeConverter &typeConverter,
RewritePatternSet &patterns);
} // namespace mlir

#include "mlir/Conversion/ConvertToLLVM/ToLLVMAttrInterface.h.inc"

#include "mlir/Conversion/ConvertToLLVM/ToLLVMOpInterface.h.inc"

#endif // MLIR_CONVERSION_CONVERTTOLLVM_TOLLVMINTERFACE_H
76 changes: 76 additions & 0 deletions mlir/include/mlir/Conversion/ConvertToLLVM/ToLLVMInterface.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@

//===- ToLLVMInterface.td - Conversion to LLVM interfaces -----*- tablegen -*-===//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Defines interfaces for managing transformations, including populating
// pattern rewrites.
//
//===----------------------------------------------------------------------===//

#ifndef MLIR_CONVERSION_CONVERTTOLLVM_TOLLVMINTERFACE_TD
#define MLIR_CONVERSION_CONVERTTOLLVM_TOLLVMINTERFACE_TD

include "mlir/IR/OpBase.td"

//===----------------------------------------------------------------------===//
// Attribute interface
//===----------------------------------------------------------------------===//

def ConvertToLLVMAttrInterface :
AttrInterface<"ConvertToLLVMAttrInterface"> {
let description = [{
The `ConvertToLLVMAttrInterface` attribute interfaces allows using
attributes to configure the convert to LLVM infrastructure, this includes:
- The conversion target.
- The LLVM type converter.
- The pattern set.

This interface permits fined grained configuration of the `convert-to-llvm`
process. For example, attributes with target information like
`#nvvm.target` or `#rodcl.target` can leverage this interface for populating
patterns specific to a particular target.
}];
let cppNamespace = "::mlir";
let methods = [
InterfaceMethod<
/*desc=*/[{
Populate the dialect conversion target, type converter and pattern set.
}],
/*retTy=*/"void",
/*methodName=*/"populateConvertToLLVMConversionPatterns",
/*args=*/(ins "::mlir::ConversionTarget&":$target,
"::mlir::LLVMTypeConverter&":$typeConverter,
"::mlir::RewritePatternSet&":$patternSet)>
];
}

//===----------------------------------------------------------------------===//
// Op interface
//===----------------------------------------------------------------------===//

def ConvertToLLVMOpInterface : OpInterface<"ConvertToLLVMOpInterface"> {
let description = [{
Interface for collecting all convert to LLVM attributes stored in an
operation. See `ConvertToLLVMAttrInterface` for more information on these
attributes.
}];
let cppNamespace = "::mlir";
let methods = [
InterfaceMethod<
/*desc=*/[{
Populate the provided vector with a list of convert to LLVM attributes
to apply.
}],
/*retTy=*/"void",
/*methodName=*/"getConvertToLLVMConversionAttrs",
/*args=*/(ins
"::llvm::SmallVectorImpl<::mlir::ConvertToLLVMAttrInterface>&":$attrs)
>
];
}

#endif // MLIR_CONVERSION_CONVERTTOLLVM_TOLLVMINTERFACE_TD
25 changes: 25 additions & 0 deletions mlir/include/mlir/Conversion/GPUCommon/GPUToLLVM.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//===- GPUToLLVM.h - Convert GPU to LLVM dialect ----------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This files declares registration functions for converting GPU to LLVM.
//
//===----------------------------------------------------------------------===//

#ifndef MLIR_CONVERSION_GPUCOMMON_GPUTOLLVM_H
#define MLIR_CONVERSION_GPUCOMMON_GPUTOLLVM_H

namespace mlir {
class DialectRegistry;
namespace gpu {
/// Registers the `ConvertToLLVMOpInterface` interface on the `gpu::GPUModuleOP`
/// operation.
void registerConvertGpuToLLVMInterface(DialectRegistry &registry);
} // namespace gpu
} // namespace mlir

#endif // MLIR_CONVERSION_GPUCOMMON_GPUTOLLVM_H
27 changes: 27 additions & 0 deletions mlir/include/mlir/Conversion/GPUToNVVM/GPUToNVVM.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//===- GPUToNVVM.h - Convert GPU to NVVM dialect ----------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This files declares registration functions for converting GPU to NVVM.
//
//===----------------------------------------------------------------------===//

#ifndef MLIR_CONVERSION_GPUTONVVM_GPUTONVVM_H
#define MLIR_CONVERSION_GPUTONVVM_GPUTONVVM_H

namespace mlir {
class DialectRegistry;
namespace NVVM {
/// Registers the `ConvertToLLVMAttrInterface` interface on the
/// `NVVM::NVVMTargetAttr` attribute. This interface populates the conversion
/// target, LLVM type converter, and pattern set for converting GPU operations
/// to NVVM.
void registerConvertGpuToNVVMInterface(DialectRegistry &registry);
} // namespace NVVM
} // namespace mlir

#endif // MLIR_CONVERSION_GPUTONVVM_GPUTONVVM_H
4 changes: 4 additions & 0 deletions mlir/include/mlir/Conversion/GPUToNVVM/GPUToNVVMPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ LLVM::LLVMStructType convertMMAToLLVMType(gpu::MMAMatrixType type);
/// Configure target to convert from the GPU dialect to NVVM.
void configureGpuToNVVMConversionLegality(ConversionTarget &target);

/// Configure the LLVM type convert to convert types and address spaces from the
/// GPU dialect to NVVM.
void configureGpuToNVVMTypeConverter(LLVMTypeConverter &converter);

/// Collect a set of patterns to convert from the GPU dialect to NVVM.
void populateGpuToNVVMConversionPatterns(const LLVMTypeConverter &converter,
RewritePatternSet &patterns);
Expand Down
8 changes: 8 additions & 0 deletions mlir/include/mlir/Conversion/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,20 @@ def ConvertToLLVMPass : Pass<"convert-to-llvm"> {
This is a generic pass to convert to LLVM, it uses the
`ConvertToLLVMPatternInterface` dialect interface to delegate to dialects
the injection of conversion patterns.

If `dynamic` is set to `true`, the pass will look for
`ConvertToLLVMAttrInterface` attributes and use them to further configure
the conversion process. This option also uses the `DataLayoutAnalysis`
analysis to configure the type converter. Enabling this option incurs in
extra overhead.
}];

let constructor = "mlir::createConvertToLLVMPass()";
let options = [
ListOption<"filterDialects", "filter-dialects", "std::string",
"Test conversion patterns of only the specified dialects">,
Option<"useDynamic", "dynamic", "bool", "false",
"Use op conversion attributes to configure the conversion">,
];
}

Expand Down
4 changes: 4 additions & 0 deletions mlir/include/mlir/InitAllExtensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "mlir/Conversion/ComplexToLLVM/ComplexToLLVM.h"
#include "mlir/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.h"
#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVM.h"
#include "mlir/Conversion/GPUCommon/GPUToLLVM.h"
#include "mlir/Conversion/GPUToNVVM/GPUToNVVM.h"
#include "mlir/Conversion/IndexToLLVM/IndexToLLVM.h"
#include "mlir/Conversion/MathToLLVM/MathToLLVM.h"
#include "mlir/Conversion/MemRefToLLVM/MemRefToLLVM.h"
Expand Down Expand Up @@ -72,6 +74,8 @@ inline void registerAllExtensions(DialectRegistry &registry) {
registerConvertOpenMPToLLVMInterface(registry);
ub::registerConvertUBToLLVMInterface(registry);
registerConvertAMXToLLVMInterface(registry);
gpu::registerConvertGpuToLLVMInterface(registry);
NVVM::registerConvertGpuToNVVMInterface(registry);

// Register all transform dialect extensions.
affine::registerTransformDialectExtension(registry);
Expand Down
2 changes: 2 additions & 0 deletions mlir/lib/Conversion/ConvertToLLVM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ add_mlir_conversion_library(MLIRConvertToLLVMInterface
ToLLVMInterface.cpp

DEPENDS
MLIRConvertToLLVMInterfaceIncGen

LINK_LIBS PUBLIC
MLIRIR
Expand All @@ -21,6 +22,7 @@ add_mlir_conversion_library(MLIRConvertToLLVMPass

LINK_LIBS PUBLIC
MLIRIR
MLIRConvertToLLVMInterface
MLIRLLVMCommonConversion
MLIRLLVMDialect
MLIRPass
Expand Down
Loading
Loading