[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
This commit is contained in:
Tim Shen 2020-02-25 13:31:56 -08:00
parent e7b9a20584
commit 2a00ae3984
7 changed files with 18 additions and 12 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -679,12 +679,11 @@ public:
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()));

View File

@ -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>();

View File

@ -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) {

View File

@ -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(