[Mlir-commits] [mlir] 920c461 - [mlir][Transform] Add support to drive conversions of func to LLVM with TD
Nicolas Vasilache
llvmlistbot at llvm.org
Thu Aug 10 06:30:47 PDT 2023
Author: Nicolas Vasilache
Date: 2023-08-10T13:17:00Z
New Revision: 920c461219a9ecdc0ec195cdd2e23fb668fe3460
URL: https://github.com/llvm/llvm-project/commit/920c461219a9ecdc0ec195cdd2e23fb668fe3460
DIFF: https://github.com/llvm/llvm-project/commit/920c461219a9ecdc0ec195cdd2e23fb668fe3460.diff
LOG: [mlir][Transform] Add support to drive conversions of func to LLVM with TD
This revision adds a `transform.apply_conversion_patterns.func.func_to_llvm` transformation.
It is unclear at this point whether this should be spelled out as a standalone transformation
or whether it should resemble `transform.apply_conversion_patterns.dialect_to_llvm "fun"`.
This is dependent on how we want to handle the type converter creation.
In particular the current implementation exhibits the fact that
`transform.apply_conversion_patterns.memref.memref_to_llvm_type_converter` was not rich enough
and did not match the LowerToLLVMOptions.
Keeping those options in sync across all the passes that lower to LLVM is very error prone.
Instead, we should have a single `to_llvm_type_converter`.
Differential Revision: https://reviews.llvm.org/D157553
Added:
mlir/include/mlir/Dialect/Func/TransformOps/CMakeLists.txt
mlir/include/mlir/Dialect/Func/TransformOps/FuncTransformOps.h
mlir/include/mlir/Dialect/Func/TransformOps/FuncTransformOps.td
mlir/lib/Dialect/Func/TransformOps/CMakeLists.txt
mlir/lib/Dialect/Func/TransformOps/FuncTransformOps.cpp
Modified:
mlir/include/mlir/Dialect/Func/CMakeLists.txt
mlir/include/mlir/Dialect/MemRef/TransformOps/MemRefTransformOps.td
mlir/include/mlir/InitAllDialects.h
mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
mlir/lib/Dialect/Func/CMakeLists.txt
mlir/lib/Dialect/MemRef/TransformOps/MemRefTransformOps.cpp
mlir/lib/Dialect/Transform/IR/TransformOps.cpp
mlir/test/Conversion/FuncToLLVM/func-memref-return.mlir
mlir/test/Conversion/FuncToLLVM/func-to-llvm.mlir
utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/Func/CMakeLists.txt b/mlir/include/mlir/Dialect/Func/CMakeLists.txt
index 9f57627c321fb0..cb1e9d01821a2c 100644
--- a/mlir/include/mlir/Dialect/Func/CMakeLists.txt
+++ b/mlir/include/mlir/Dialect/Func/CMakeLists.txt
@@ -1,2 +1,3 @@
add_subdirectory(IR)
add_subdirectory(Transforms)
+add_subdirectory(TransformOps)
diff --git a/mlir/include/mlir/Dialect/Func/TransformOps/CMakeLists.txt b/mlir/include/mlir/Dialect/Func/TransformOps/CMakeLists.txt
new file mode 100644
index 00000000000000..7ac6504f3dc2c1
--- /dev/null
+++ b/mlir/include/mlir/Dialect/Func/TransformOps/CMakeLists.txt
@@ -0,0 +1,6 @@
+set(LLVM_TARGET_DEFINITIONS FuncTransformOps.td)
+mlir_tablegen(FuncTransformOps.h.inc -gen-op-decls)
+mlir_tablegen(FuncTransformOps.cpp.inc -gen-op-defs)
+add_public_tablegen_target(MLIRFuncTransformOpsIncGen)
+
+add_mlir_doc(FuncTransformOps FuncTransformOps Dialects/ -gen-op-doc)
diff --git a/mlir/include/mlir/Dialect/Func/TransformOps/FuncTransformOps.h b/mlir/include/mlir/Dialect/Func/TransformOps/FuncTransformOps.h
new file mode 100644
index 00000000000000..8d0b97da95d492
--- /dev/null
+++ b/mlir/include/mlir/Dialect/Func/TransformOps/FuncTransformOps.h
@@ -0,0 +1,27 @@
+//===- FuncTransformOps.h - CF transformation ops --------*- 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_DIALECT_FUNC_TRANSFORMOPS_FUNCTRANSFORMOPS_H
+#define MLIR_DIALECT_FUNC_TRANSFORMOPS_FUNCTRANSFORMOPS_H
+
+#include "mlir/Bytecode/BytecodeOpInterface.h"
+#include "mlir/Dialect/Transform/IR/TransformInterfaces.h"
+#include "mlir/IR/OpImplementation.h"
+
+#define GET_OP_CLASSES
+#include "mlir/Dialect/Func/TransformOps/FuncTransformOps.h.inc"
+
+namespace mlir {
+class DialectRegistry;
+
+namespace func {
+void registerTransformDialectExtension(DialectRegistry ®istry);
+} // namespace func
+} // namespace mlir
+
+#endif // MLIR_DIALECT_FUNC_TRANSFORMOPS_FUNCTRANSFORMOPS_H
diff --git a/mlir/include/mlir/Dialect/Func/TransformOps/FuncTransformOps.td b/mlir/include/mlir/Dialect/Func/TransformOps/FuncTransformOps.td
new file mode 100644
index 00000000000000..7a7e991c786188
--- /dev/null
+++ b/mlir/include/mlir/Dialect/Func/TransformOps/FuncTransformOps.td
@@ -0,0 +1,29 @@
+//===- FuncTransformOps.td - CF transformation ops -*- 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef FUNC_TRANSFORM_OPS
+#define FUNC_TRANSFORM_OPS
+
+include "mlir/Dialect/Transform/IR/TransformDialect.td"
+include "mlir/Dialect/Transform/IR/TransformInterfaces.td"
+include "mlir/Dialect/Transform/IR/TransformTypes.td"
+include "mlir/IR/OpBase.td"
+
+def ApplyFuncToLLVMConversionPatternsOp : Op<Transform_Dialect,
+ "apply_conversion_patterns.func.func_to_llvm",
+ [DeclareOpInterfaceMethods<ConversionPatternDescriptorOpInterface,
+ ["verifyTypeConverter"]>]> {
+ let description = [{
+ Collects patterns that convert Func dialect ops to LLVM dialect ops.
+ These patterns require an "LLVMTypeConverter".
+ }];
+
+ let assemblyFormat = "attr-dict";
+}
+
+#endif // FUNC_TRANSFORM_OPS
diff --git a/mlir/include/mlir/Dialect/MemRef/TransformOps/MemRefTransformOps.td b/mlir/include/mlir/Dialect/MemRef/TransformOps/MemRefTransformOps.td
index 243ce16b019dee..085326e755dbb0 100644
--- a/mlir/include/mlir/Dialect/MemRef/TransformOps/MemRefTransformOps.td
+++ b/mlir/include/mlir/Dialect/MemRef/TransformOps/MemRefTransformOps.td
@@ -32,13 +32,22 @@ def MemrefToLLVMTypeConverterOp : Op<Transform_Dialect,
instead of the classic "malloc", "aligned_alloc" and "free" functions.
- `use_opaque_pointers`: Generate LLVM IR using opaque pointers instead of
typed pointers.
+ // TODO: the following two options don't really make sense for
+ // memref_to_llvm_type_converter specifically.
+ // We should have a single to_llvm_type_converter.
+ - `use_bare_ptr_call_conv`: Replace FuncOp's MemRef arguments with bare
+ pointers to the MemRef element types.
+ - `data-layout`: String description (LLVM format) of the data layout that is
+ expected on the produced module.
}];
let arguments = (ins
- DefaultValuedAttr<BoolAttr, "false">:$use_aligned_alloc,
- DefaultValuedAttr<I64Attr, "0">:$index_bitwidth,
- DefaultValuedAttr<BoolAttr, "false">:$use_generic_functions,
- DefaultValuedAttr<BoolAttr, "false">:$use_opaque_pointers);
+ DefaultValuedOptionalAttr<BoolAttr, "false">:$use_aligned_alloc,
+ DefaultValuedOptionalAttr<I64Attr, "64">:$index_bitwidth,
+ DefaultValuedOptionalAttr<BoolAttr, "false">:$use_generic_functions,
+ DefaultValuedOptionalAttr<BoolAttr, "false">:$use_opaque_pointers,
+ DefaultValuedOptionalAttr<BoolAttr, "false">:$use_bare_ptr_call_conv,
+ OptionalAttr<StrAttr>:$data_layout);
let assemblyFormat = "attr-dict";
}
diff --git a/mlir/include/mlir/InitAllDialects.h b/mlir/include/mlir/InitAllDialects.h
index 110cbe77247305..af67d58e795ba7 100644
--- a/mlir/include/mlir/InitAllDialects.h
+++ b/mlir/include/mlir/InitAllDialects.h
@@ -34,6 +34,7 @@
#include "mlir/Dialect/DLTI/DLTI.h"
#include "mlir/Dialect/EmitC/IR/EmitC.h"
#include "mlir/Dialect/Func/IR/FuncOps.h"
+#include "mlir/Dialect/Func/TransformOps/FuncTransformOps.h"
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
#include "mlir/Dialect/GPU/TransformOps/GPUTransformOps.h"
#include "mlir/Dialect/IRDL/IR/IRDL.h"
@@ -138,6 +139,7 @@ inline void registerAllDialects(DialectRegistry ®istry) {
// Register all dialect extensions.
affine::registerTransformDialectExtension(registry);
bufferization::registerTransformDialectExtension(registry);
+ func::registerTransformDialectExtension(registry);
gpu::registerTransformDialectExtension(registry);
linalg::registerTransformDialectExtension(registry);
memref::registerTransformDialectExtension(registry);
diff --git a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
index 776e6222fdcfeb..cacdd2edb92f27 100644
--- a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
+++ b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
@@ -333,7 +333,7 @@ struct FuncOpConversionBase : public ConvertOpToLLVMPattern<func::FuncOp> {
// Convert input FuncOp to LLVMFuncOp by using the LLVMTypeConverter provided
// to this legalization pattern.
- LLVM::LLVMFuncOp
+ FailureOr<LLVM::LLVMFuncOp>
convertFuncOpToLLVMFuncOp(func::FuncOp funcOp,
ConversionPatternRewriter &rewriter) const {
// Convert the original function arguments. They are converted using the
@@ -344,7 +344,7 @@ struct FuncOpConversionBase : public ConvertOpToLLVMPattern<func::FuncOp> {
funcOp.getFunctionType(), varargsAttr && varargsAttr.getValue(),
shouldUseBarePtrCallConv(funcOp, getTypeConverter()), result);
if (!llvmType)
- return nullptr;
+ return rewriter.notifyMatchFailure(funcOp, "signature conversion failed");
// Propagate argument/result attributes to all converted arguments/result
// obtained after converting a given original argument/result.
@@ -423,7 +423,8 @@ struct FuncOpConversionBase : public ConvertOpToLLVMPattern<func::FuncOp> {
if (!attr) {
funcOp->emitError() << "Contains " << linkageAttrName
<< " attribute not of type LLVM::LinkageAttr";
- return nullptr;
+ return rewriter.notifyMatchFailure(
+ funcOp, "Contains linkage attribute not of type LLVM::LinkageAttr");
}
linkage = attr.getLinkage();
}
@@ -436,7 +437,8 @@ struct FuncOpConversionBase : public ConvertOpToLLVMPattern<func::FuncOp> {
if (!attr) {
funcOp->emitError() << "Contains " << readnoneAttrName
<< " attribute not of type UnitAttr";
- return nullptr;
+ return rewriter.notifyMatchFailure(
+ funcOp, "Contains readnone attribute not of type UnitAttr");
}
memoryAttr = LLVM::MemoryEffectsAttr::get(rewriter.getContext(),
{LLVM::ModRefInfo::NoModRef,
@@ -453,8 +455,10 @@ struct FuncOpConversionBase : public ConvertOpToLLVMPattern<func::FuncOp> {
rewriter.inlineRegionBefore(funcOp.getBody(), newFuncOp.getBody(),
newFuncOp.end());
if (failed(rewriter.convertRegionTypes(&newFuncOp.getBody(), *typeConverter,
- &result)))
- return nullptr;
+ &result))) {
+ return rewriter.notifyMatchFailure(funcOp,
+ "region types conversion failed");
+ }
return newFuncOp;
}
@@ -470,27 +474,28 @@ struct FuncOpConversion : public FuncOpConversionBase {
LogicalResult
matchAndRewrite(func::FuncOp funcOp, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
- auto newFuncOp = convertFuncOpToLLVMFuncOp(funcOp, rewriter);
- if (!newFuncOp)
- return failure();
+ FailureOr<LLVM::LLVMFuncOp> newFuncOp =
+ convertFuncOpToLLVMFuncOp(funcOp, rewriter);
+ if (failed(newFuncOp))
+ return rewriter.notifyMatchFailure(funcOp, "Could not convert funcop");
if (!shouldUseBarePtrCallConv(funcOp, this->getTypeConverter())) {
if (funcOp->getAttrOfType<UnitAttr>(
LLVM::LLVMDialect::getEmitCWrapperAttrName())) {
- if (newFuncOp.isVarArg())
+ if (newFuncOp->isVarArg())
return funcOp->emitError("C interface for variadic functions is not "
"supported yet.");
- if (newFuncOp.isExternal())
- wrapExternalFunction(rewriter, funcOp.getLoc(), *getTypeConverter(),
- funcOp, newFuncOp);
+ if (newFuncOp->isExternal())
+ wrapExternalFunction(rewriter, funcOp->getLoc(), *getTypeConverter(),
+ funcOp, *newFuncOp);
else
- wrapForExternalCallers(rewriter, funcOp.getLoc(), *getTypeConverter(),
- funcOp, newFuncOp);
+ wrapForExternalCallers(rewriter, funcOp->getLoc(),
+ *getTypeConverter(), funcOp, *newFuncOp);
}
} else {
- modifyFuncOpToUseBarePtrCallingConv(rewriter, funcOp.getLoc(),
- *getTypeConverter(), newFuncOp,
+ modifyFuncOpToUseBarePtrCallingConv(rewriter, funcOp->getLoc(),
+ *getTypeConverter(), *newFuncOp,
funcOp.getFunctionType().getInputs());
}
diff --git a/mlir/lib/Dialect/Func/CMakeLists.txt b/mlir/lib/Dialect/Func/CMakeLists.txt
index 5dde654d14ac04..ec999ffdb99da8 100644
--- a/mlir/lib/Dialect/Func/CMakeLists.txt
+++ b/mlir/lib/Dialect/Func/CMakeLists.txt
@@ -1,3 +1,4 @@
add_subdirectory(Extensions)
add_subdirectory(IR)
add_subdirectory(Transforms)
+add_subdirectory(TransformOps)
diff --git a/mlir/lib/Dialect/Func/TransformOps/CMakeLists.txt b/mlir/lib/Dialect/Func/TransformOps/CMakeLists.txt
new file mode 100644
index 00000000000000..b860bd154e48d8
--- /dev/null
+++ b/mlir/lib/Dialect/Func/TransformOps/CMakeLists.txt
@@ -0,0 +1,17 @@
+add_mlir_dialect_library(MLIRFuncTransformOps
+ FuncTransformOps.cpp
+
+ ADDITIONAL_HEADER_DIRS
+ ${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/Func/TransformOps
+
+ DEPENDS
+ MLIRFuncTransformOpsIncGen
+
+ LINK_LIBS PUBLIC
+ MLIRFuncDialect
+ MLIRFuncToLLVM
+ MLIRIR
+ MLIRLLVMCommonConversion
+ MLIRLLVMDialect
+ MLIRTransformDialect
+)
diff --git a/mlir/lib/Dialect/Func/TransformOps/FuncTransformOps.cpp b/mlir/lib/Dialect/Func/TransformOps/FuncTransformOps.cpp
new file mode 100644
index 00000000000000..9e9b6bcea790de
--- /dev/null
+++ b/mlir/lib/Dialect/Func/TransformOps/FuncTransformOps.cpp
@@ -0,0 +1,66 @@
+//===- FuncTransformOps.cpp - Implementation of CF transform ops ---===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Dialect/Func/TransformOps/FuncTransformOps.h"
+
+#include "mlir/Conversion/FuncToLLVM/ConvertFuncToLLVM.h"
+#include "mlir/Conversion/LLVMCommon/TypeConverter.h"
+#include "mlir/Dialect/Func/IR/FuncOps.h"
+#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
+#include "mlir/Dialect/Transform/IR/TransformDialect.h"
+#include "mlir/Dialect/Transform/IR/TransformInterfaces.h"
+#include "mlir/Dialect/Transform/IR/TransformOps.h"
+
+using namespace mlir;
+
+//===----------------------------------------------------------------------===//
+// Apply...ConversionPatternsOp
+//===----------------------------------------------------------------------===//
+
+void transform::ApplyFuncToLLVMConversionPatternsOp::populatePatterns(
+ TypeConverter &typeConverter, RewritePatternSet &patterns) {
+ populateFuncToLLVMConversionPatterns(
+ static_cast<LLVMTypeConverter &>(typeConverter), patterns);
+}
+
+LogicalResult
+transform::ApplyFuncToLLVMConversionPatternsOp::verifyTypeConverter(
+ transform::TypeConverterBuilderOpInterface builder) {
+ if (builder.getTypeConverterType() != "LLVMTypeConverter")
+ return emitOpError("expected LLVMTypeConverter");
+ return success();
+}
+
+//===----------------------------------------------------------------------===//
+// Transform op registration
+//===----------------------------------------------------------------------===//
+
+namespace {
+class FuncTransformDialectExtension
+ : public transform::TransformDialectExtension<
+ FuncTransformDialectExtension> {
+public:
+ using Base::Base;
+
+ void init() {
+ declareGeneratedDialect<LLVM::LLVMDialect>();
+
+ registerTransformOps<
+#define GET_OP_LIST
+#include "mlir/Dialect/Func/TransformOps/FuncTransformOps.cpp.inc"
+ >();
+ }
+};
+} // namespace
+
+#define GET_OP_CLASSES
+#include "mlir/Dialect/Func/TransformOps/FuncTransformOps.cpp.inc"
+
+void mlir::func::registerTransformDialectExtension(DialectRegistry ®istry) {
+ registry.addExtensions<FuncTransformDialectExtension>();
+}
diff --git a/mlir/lib/Dialect/MemRef/TransformOps/MemRefTransformOps.cpp b/mlir/lib/Dialect/MemRef/TransformOps/MemRefTransformOps.cpp
index af067c0453333a..ebab0720af8d73 100644
--- a/mlir/lib/Dialect/MemRef/TransformOps/MemRefTransformOps.cpp
+++ b/mlir/lib/Dialect/MemRef/TransformOps/MemRefTransformOps.cpp
@@ -44,6 +44,13 @@ transform::MemrefToLLVMTypeConverterOp::getTypeConverter() {
if (getIndexBitwidth() != kDeriveIndexBitwidthFromDataLayout)
options.overrideIndexBitwidth(getIndexBitwidth());
+ // TODO: the following two options don't really make sense for
+ // memref_to_llvm_type_converter specifically but we should have a single
+ // to_llvm_type_converter.
+ if (getDataLayout().has_value())
+ options.dataLayout = llvm::DataLayout(getDataLayout().value());
+ options.useBarePtrCallConv = getUseBarePtrCallConv();
+
return std::make_unique<LLVMTypeConverter>(getContext(), options);
}
diff --git a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
index 4547adc5920d9f..7bc7272b054129 100644
--- a/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
+++ b/mlir/lib/Dialect/Transform/IR/TransformOps.cpp
@@ -9,6 +9,7 @@
#include "mlir/Dialect/Transform/IR/TransformOps.h"
#include "mlir/Conversion/ConvertToLLVM/ToLLVMInterface.h"
+#include "mlir/Conversion/LLVMCommon/ConversionTarget.h"
#include "mlir/Conversion/LLVMCommon/TypeConverter.h"
#include "mlir/Dialect/Transform/IR/MatchInterfaces.h"
#include "mlir/Dialect/Transform/IR/TransformAttrs.h"
@@ -498,7 +499,7 @@ DiagnosedSilenceableFailure transform::ApplyConversionPatternsOp::apply(
defaultTypeConverter = typeConverterBuilder.getTypeConverter();
// Configure conversion target.
- ConversionTarget conversionTarget(*ctx);
+ ConversionTarget conversionTarget(*getContext());
if (getLegalOps())
for (Attribute attr : cast<ArrayAttr>(*getLegalOps()))
conversionTarget.addLegalOp(
diff --git a/mlir/test/Conversion/FuncToLLVM/func-memref-return.mlir b/mlir/test/Conversion/FuncToLLVM/func-memref-return.mlir
index c1f41d270e7ea7..b3883703fcdc1a 100644
--- a/mlir/test/Conversion/FuncToLLVM/func-memref-return.mlir
+++ b/mlir/test/Conversion/FuncToLLVM/func-memref-return.mlir
@@ -1,5 +1,8 @@
// RUN: mlir-opt -convert-func-to-llvm='use-opaque-pointers=1' -reconcile-unrealized-casts %s | FileCheck %s
-// RUN: mlir-opt -convert-func-to-llvm='use-bare-ptr-memref-call-conv=1 use-opaque-pointers=1' -split-input-file %s | FileCheck %s --check-prefix=BAREPTR
+
+// RUN: mlir-opt -convert-func-to-llvm='use-bare-ptr-memref-call-conv=1 use-opaque-pointers=1' %s | FileCheck %s --check-prefix=BAREPTR
+
+// RUN: mlir-opt -test-transform-dialect-interpreter %s | FileCheck %s --check-prefix=BAREPTR
// These tests were separated from func-memref.mlir because applying
// -reconcile-unrealized-casts resulted in `llvm.extractvalue` ops getting
@@ -32,8 +35,6 @@ func.func @check_static_return(%static : memref<32x18xf32>) -> memref<32x18xf32>
return %static : memref<32x18xf32>
}
-// -----
-
// CHECK-LABEL: func @check_static_return_with_offset
// CHECK-COUNT-2: !llvm.ptr
// CHECK-COUNT-5: i64
@@ -61,7 +62,6 @@ func.func @check_static_return_with_offset(%static : memref<32x18xf32, strided<[
return %static : memref<32x18xf32, strided<[22,1], offset: 7>>
}
-// -----
// BAREPTR: llvm.func @foo(!llvm.ptr) -> !llvm.ptr
func.func private @foo(memref<10xi8>) -> memref<20xi8>
@@ -87,8 +87,6 @@ func.func @check_memref_func_call(%in : memref<10xi8>) -> memref<20xi8> {
return %res : memref<20xi8>
}
-// -----
-
// BAREPTR-LABEL: func @check_return(
// BAREPTR-SAME: %{{.*}}: memref<?xi8>) -> memref<?xi8>
func.func @check_return(%in : memref<?xi8>) -> memref<?xi8> {
@@ -96,15 +94,12 @@ func.func @check_return(%in : memref<?xi8>) -> memref<?xi8> {
return %in : memref<?xi8>
}
-// -----
-
// BAREPTR-LABEL: func @unconvertible_multiresult
// BAREPTR-SAME: %{{.*}}: memref<?xf32>, %{{.*}}: memref<?xf32>) -> (memref<?xf32>, memref<?xf32>)
func.func @unconvertible_multiresult(%arg0: memref<?xf32> , %arg1: memref<?xf32>) -> (memref<?xf32>, memref<?xf32>) {
return %arg0, %arg1 : memref<?xf32>, memref<?xf32>
}
-// -----
// BAREPTR-LABEL: func @unranked_memref(
// BAREPTR-SAME: %{{.*}}: memref<*xi32>)
func.func @unranked_memref(%arg0:memref<*xi32>) {
@@ -114,3 +109,18 @@ func.func @unranked_memref(%arg0:memref<*xi32>) {
return
}
func.func private @printMemrefI32(memref<*xi32>)
+
+transform.sequence failures(propagate) {
+^bb1(%toplevel_module: !transform.any_op):
+ %func = transform.structured.match ops{["func.func"]} in %toplevel_module
+ : (!transform.any_op) -> !transform.any_op
+ transform.apply_conversion_patterns to %func {
+ transform.apply_conversion_patterns.func.func_to_llvm
+ } with type_converter {
+ transform.apply_conversion_patterns.memref.memref_to_llvm_type_converter
+ {use_bare_ptr_call_conv = true, use_opaque_pointers = true}
+ } {
+ legal_dialects = ["llvm"],
+ partial_conversion
+ } : !transform.any_op
+}
diff --git a/mlir/test/Conversion/FuncToLLVM/func-to-llvm.mlir b/mlir/test/Conversion/FuncToLLVM/func-to-llvm.mlir
index 53b04c844487df..70e47bdbb94d26 100644
--- a/mlir/test/Conversion/FuncToLLVM/func-to-llvm.mlir
+++ b/mlir/test/Conversion/FuncToLLVM/func-to-llvm.mlir
@@ -1,6 +1,9 @@
// RUN: mlir-opt -pass-pipeline="builtin.module(func.func(convert-math-to-llvm,convert-arith-to-llvm),convert-func-to-llvm{use-opaque-pointers=1},reconcile-unrealized-casts)" %s -split-input-file | FileCheck %s
+
// RUN: mlir-opt -pass-pipeline="builtin.module(func.func(convert-math-to-llvm,convert-arith-to-llvm{index-bitwidth=32}),convert-func-to-llvm{index-bitwidth=32 use-opaque-pointers=1},reconcile-unrealized-casts)" %s -split-input-file | FileCheck --check-prefix=CHECK32 %s
+// RUN: mlir-opt -test-transform-dialect-interpreter %s | FileCheck --check-prefix=CHECK32 %s
+
// CHECK-LABEL: func @empty() {
// CHECK-NEXT: llvm.return
// CHECK-NEXT: }
@@ -447,8 +450,6 @@ func.func @dfs_block_order(%arg0: i32) -> (i32) {
cf.br ^bb1
}
-// -----
-
// CHECK-LABEL: func @ceilf(
// CHECK-SAME: f32
func.func @ceilf(%arg0 : f32) {
@@ -457,8 +458,6 @@ func.func @ceilf(%arg0 : f32) {
func.return
}
-// -----
-
// CHECK-LABEL: func @floorf(
// CHECK-SAME: f32
func.func @floorf(%arg0 : f32) {
@@ -467,8 +466,9 @@ func.func @floorf(%arg0 : f32) {
func.return
}
-// -----
-
+// Wrap the following tests in a module to control the place where
+// `llvm.func @abort()` is produced.
+module {
// Lowers `cf.assert` to a function call to `abort` if the assertion is violated.
// CHECK: llvm.func @abort()
// CHECK-LABEL: @assert_test_function
@@ -483,8 +483,7 @@ func.func @assert_test_function(%arg : i1) {
cf.assert %arg, "Computer says no"
return
}
-
-// -----
+}
// This should not trigger an assertion by creating an LLVM::CallOp with a
// nullptr result type.
@@ -497,8 +496,6 @@ func.func @call_zero_result_func() {
}
func.func private @zero_result_func()
-// -----
-
// CHECK-LABEL: func @fmaf(
// CHECK-SAME: %[[ARG0:.*]]: f32
// CHECK-SAME: %[[ARG1:.*]]: vector<4xf32>
@@ -510,8 +507,6 @@ func.func @fmaf(%arg0: f32, %arg1: vector<4xf32>) {
func.return
}
-// -----
-
// CHECK-LABEL: func @switchi8(
func.func @switchi8(%arg0 : i8) -> i32 {
cf.switch %arg0 : i8, [
@@ -537,3 +532,21 @@ func.func @switchi8(%arg0 : i8) -> i32 {
// CHECK-NEXT: %[[E1:.+]] = llvm.mlir.constant(42 : i32) : i32
// CHECK-NEXT: llvm.return %[[E1]] : i32
// CHECK-NEXT: }
+
+transform.sequence failures(propagate) {
+^bb1(%toplevel_module: !transform.any_op):
+ %func = transform.structured.match ops{["func.func"]} in %toplevel_module
+ : (!transform.any_op) -> !transform.any_op
+ transform.apply_conversion_patterns to %func {
+ transform.apply_conversion_patterns.dialect_to_llvm "math"
+ transform.apply_conversion_patterns.dialect_to_llvm "arith"
+ transform.apply_conversion_patterns.dialect_to_llvm "cf"
+ transform.apply_conversion_patterns.func.func_to_llvm
+ } with type_converter {
+ transform.apply_conversion_patterns.memref.memref_to_llvm_type_converter
+ {index_bitwidth = 32, use_opaque_pointers = true}
+ } {
+ legal_dialects = ["llvm"],
+ partial_conversion
+ } : !transform.any_op
+}
diff --git a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
index 09d4e8a08f2ab8..bd79425d01d7ce 100644
--- a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
@@ -4051,6 +4051,57 @@ cc_library(
],
)
+td_library(
+ name = "FuncTransformOpsTdFiles",
+ srcs = [
+ "include/mlir/Dialect/Func/TransformOps/FuncTransformOps.td",
+ ],
+ includes = ["include"],
+ deps = [
+ ":TransformDialectTdFiles",
+ ],
+)
+
+gentbl_cc_library(
+ name = "FuncTransformOpsIncGen",
+ strip_include_prefix = "include",
+ tbl_outs = [
+ (
+ ["-gen-op-decls"],
+ "include/mlir/Dialect/Func/TransformOps/FuncTransformOps.h.inc",
+ ),
+ (
+ ["-gen-op-defs"],
+ "include/mlir/Dialect/Func/TransformOps/FuncTransformOps.cpp.inc",
+ ),
+ ],
+ tblgen = ":mlir-tblgen",
+ td_file = "include/mlir/Dialect/Func/TransformOps/FuncTransformOps.td",
+ deps = [
+ ":FuncTransformOpsTdFiles",
+ ],
+)
+
+cc_library(
+ name = "FuncTransformOps",
+ srcs = [
+ "lib/Dialect/Func/TransformOps/FuncTransformOps.cpp",
+ ],
+ hdrs = [
+ "include/mlir/Dialect/Func/TransformOps/FuncTransformOps.h",
+ ],
+ includes = ["include"],
+ deps = [
+ ":FuncDialect",
+ ":FuncToLLVM",
+ ":FuncTransformOpsIncGen",
+ ":IR",
+ ":LLVMCommonConversion",
+ ":LLVMDialect",
+ ":TransformDialect",
+ ],
+)
+
cc_library(
name = "AllExtensions",
hdrs = ["include/mlir/InitAllExtensions.h"],
More information about the Mlir-commits
mailing list