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
67 lines
2.3 KiB
C++
67 lines
2.3 KiB
C++
//===- 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>();
|
|
}
|