From 2a00ae398452884e58135443e52e0600e8a6cb01 Mon Sep 17 00:00:00 2001 From: Tim Shen Date: Tue, 25 Feb 2020 13:31:56 -0800 Subject: [PATCH] [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 --- mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp | 3 +-- mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp | 3 +-- .../mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h | 7 +++++++ mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp | 3 +-- mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp | 3 +-- mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp | 8 ++++++-- mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp | 3 +-- 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp b/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp index 3edf0f3..439009a 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(); + LLVMConversionTarget target(getContext()); target.addLegalOp(); // 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 3edf0f3..439009a 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(); + LLVMConversionTarget target(getContext()); target.addLegalOp(); // 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 db3a948..2e6a513 100644 --- a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h +++ b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h @@ -369,6 +369,13 @@ protected: LLVMTypeConverter &typeConverter; }; +/// Derived class that automatically populates legalization information for +/// different 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 a2f16b1..3c2d964 100644 --- a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp +++ b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp @@ -679,12 +679,11 @@ public: OwningRewritePatternList patterns; populateStdToLLVMConversionPatterns(converter, patterns); populateGpuToNVVMConversionPatterns(converter, patterns); - ConversionTarget target(getContext()); + LLVMConversionTarget target(getContext()); target.addIllegalDialect(); target.addIllegalOp(); target.addIllegalOp(); - target.addLegalDialect(); target.addLegalDialect(); target.addDynamicallyLegalOp( gpu::filterIllegalLLVMIntrinsics({"tanh", "tanhf"}, m.getContext())); diff --git a/mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp b/mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp index 1774f93..497cb44 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(); + LLVMConversionTarget target(getContext()); target.addDynamicallyLegalOp( [&](FuncOp op) { return converter.isSignatureLegal(op.getType()); }); target.addLegalOp(); diff --git a/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp b/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp index b5b415e..72985ff 100644 --- a/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp +++ b/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp @@ -2959,8 +2959,7 @@ struct LLVMLoweringPass : public ModulePass { populateStdToLLVMConversionPatterns(typeConverter, patterns, useAlloca, emitCWrappers); - ConversionTarget target(getContext()); - target.addLegalDialect(); + LLVMConversionTarget target(getContext()); if (failed(applyPartialConversion(m, target, patterns, &typeConverter))) signalPassFailure(); } @@ -2986,6 +2985,11 @@ struct LLVMLoweringPass : public ModulePass { }; } // end namespace +mlir::LLVMConversionTarget::LLVMConversionTarget(MLIRContext &ctx) + : ConversionTarget(ctx) { + this->addLegalDialect(); +} + std::unique_ptr> 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 3392891..b9182ea 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(); + LLVMConversionTarget target(getContext()); target.addDynamicallyLegalOp( [&](FuncOp op) { return converter.isSignatureLegal(op.getType()); }); if (failed( -- 2.7.4