[Mlir-commits] [mlir] 2a00ae3 - [MLIR] Add LLVMConversionTarget as a customization point. NFC.
Tim Shen
llvmlistbot at llvm.org
Fri Feb 28 12:21:13 PST 2020
Author: Tim Shen
Date: 2020-02-28T12:20:23-08:00
New Revision: 2a00ae398452884e58135443e52e0600e8a6cb01
URL: https://github.com/llvm/llvm-project/commit/2a00ae398452884e58135443e52e0600e8a6cb01
DIFF: https://github.com/llvm/llvm-project/commit/2a00ae398452884e58135443e52e0600e8a6cb01.diff
LOG: [MLIR] Add LLVMConversionTarget as a customization point. NFC.
This is in preparation for the next patch D75141. The purpose is to
provide a single place where LLVM dialect registers its ops as
legal/illegal.
Reviewers: ftynse, mravishankar, herhut
Subscribers: jholewinski, bixia, sanjoy.google, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, csigg, arpith-jacob, mgester, lucyrfox, aartbik, liufengdb, Joonsoo, llvm-commits
Differential Revision: https://reviews.llvm.org/D75140
Added:
Modified:
mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp
mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp
mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp
mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp
mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
Removed:
################################################################################
diff --git a/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp b/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp
index 3edf0f3f8b70..439009acd886 100644
--- a/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp
+++ b/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp
@@ -162,8 +162,7 @@ void ToyToLLVMLoweringPass::runOnModule() {
// The first thing to define is the conversion target. This will define the
// final target for this lowering. For this lowering, we are only targeting
// the LLVM dialect.
- ConversionTarget target(getContext());
- target.addLegalDialect<LLVM::LLVMDialect>();
+ LLVMConversionTarget target(getContext());
target.addLegalOp<ModuleOp, ModuleTerminatorOp>();
// During this lowering, we will also be lowering the MemRef types, that are
diff --git a/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp b/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp
index 3edf0f3f8b70..439009acd886 100644
--- a/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp
+++ b/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp
@@ -162,8 +162,7 @@ void ToyToLLVMLoweringPass::runOnModule() {
// The first thing to define is the conversion target. This will define the
// final target for this lowering. For this lowering, we are only targeting
// the LLVM dialect.
- ConversionTarget target(getContext());
- target.addLegalDialect<LLVM::LLVMDialect>();
+ LLVMConversionTarget target(getContext());
target.addLegalOp<ModuleOp, ModuleTerminatorOp>();
// During this lowering, we will also be lowering the MemRef types, that are
diff --git a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
index db3a948f000f..2e6a513f10db 100644
--- a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
+++ b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
@@ -369,6 +369,13 @@ class ConvertToLLVMPattern : public ConversionPattern {
LLVMTypeConverter &typeConverter;
};
+/// Derived class that automatically populates legalization information for
+///
diff erent LLVM ops.
+class LLVMConversionTarget : public ConversionTarget {
+public:
+ explicit LLVMConversionTarget(MLIRContext &ctx);
+};
+
} // namespace mlir
#endif // MLIR_CONVERSION_STANDARDTOLLVM_CONVERTSTANDARDTOLLVM_H
diff --git a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
index a2f16b1103e9..3c2d964d2526 100644
--- a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
+++ b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
@@ -679,12 +679,11 @@ class LowerGpuOpsToNVVMOpsPass
OwningRewritePatternList patterns;
populateStdToLLVMConversionPatterns(converter, patterns);
populateGpuToNVVMConversionPatterns(converter, patterns);
- ConversionTarget target(getContext());
+ LLVMConversionTarget target(getContext());
target.addIllegalDialect<gpu::GPUDialect>();
target.addIllegalOp<LLVM::CosOp, LLVM::ExpOp, LLVM::FAbsOp, LLVM::FCeilOp,
LLVM::LogOp, LLVM::Log10Op, LLVM::Log2Op>();
target.addIllegalOp<FuncOp>();
- target.addLegalDialect<LLVM::LLVMDialect>();
target.addLegalDialect<NVVM::NVVMDialect>();
target.addDynamicallyLegalOp<mlir::LLVM::CallOp>(
gpu::filterIllegalLLVMIntrinsics({"tanh", "tanhf"}, m.getContext()));
diff --git a/mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp b/mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp
index 1774f93b7254..497cb448ef42 100644
--- a/mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp
+++ b/mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp
@@ -566,8 +566,7 @@ void ConvertLinalgToLLVMPass::runOnModule() {
populateLinalgToStandardConversionPatterns(patterns, &getContext());
populateLinalgToLLVMConversionPatterns(converter, patterns, &getContext());
- ConversionTarget target(getContext());
- target.addLegalDialect<LLVM::LLVMDialect>();
+ LLVMConversionTarget target(getContext());
target.addDynamicallyLegalOp<FuncOp>(
[&](FuncOp op) { return converter.isSignatureLegal(op.getType()); });
target.addLegalOp<ModuleOp, ModuleTerminatorOp>();
diff --git a/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp b/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp
index b5b415e7705d..72985ffc639b 100644
--- a/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp
+++ b/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp
@@ -2959,8 +2959,7 @@ struct LLVMLoweringPass : public ModulePass<LLVMLoweringPass> {
populateStdToLLVMConversionPatterns(typeConverter, patterns, useAlloca,
emitCWrappers);
- ConversionTarget target(getContext());
- target.addLegalDialect<LLVM::LLVMDialect>();
+ LLVMConversionTarget target(getContext());
if (failed(applyPartialConversion(m, target, patterns, &typeConverter)))
signalPassFailure();
}
@@ -2986,6 +2985,11 @@ struct LLVMLoweringPass : public ModulePass<LLVMLoweringPass> {
};
} // end namespace
+mlir::LLVMConversionTarget::LLVMConversionTarget(MLIRContext &ctx)
+ : ConversionTarget(ctx) {
+ this->addLegalDialect<LLVM::LLVMDialect>();
+}
+
std::unique_ptr<OpPassBase<ModuleOp>>
mlir::createLowerToLLVMPass(bool useAlloca, bool useBarePtrCallConv,
bool emitCWrappers) {
diff --git a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
index 33928916a836..b9182ea1118f 100644
--- a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
+++ b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
@@ -1184,8 +1184,7 @@ void LowerVectorToLLVMPass::runOnModule() {
populateVectorToLLVMConversionPatterns(converter, patterns);
populateStdToLLVMConversionPatterns(converter, patterns);
- ConversionTarget target(getContext());
- target.addLegalDialect<LLVM::LLVMDialect>();
+ LLVMConversionTarget target(getContext());
target.addDynamicallyLegalOp<FuncOp>(
[&](FuncOp op) { return converter.isSignatureLegal(op.getType()); });
if (failed(
More information about the Mlir-commits
mailing list