diff --git a/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp b/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp --- a/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp +++ b/mlir/examples/toy/Ch6/mlir/LowerToLLVM.cpp @@ -162,8 +162,7 @@ // 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 --- a/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp +++ b/mlir/examples/toy/Ch7/mlir/LowerToLLVM.cpp @@ -162,8 +162,7 @@ // 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 --- a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h +++ b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h @@ -369,6 +369,12 @@ LLVMTypeConverter &typeConverter; }; +/// Customization class for LLVM conversion target. +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 --- a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp +++ b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp @@ -679,12 +679,11 @@ 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 --- a/mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp +++ b/mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp @@ -566,8 +566,7 @@ 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 --- a/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp +++ b/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp @@ -2959,8 +2959,7 @@ 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 @@ }; } // 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 --- a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp +++ b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp @@ -1184,8 +1184,7 @@ 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(