[PATCH] D74584: [mlir] Refactor TypeConverter to add conversions without inheritance

River Riddle via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 13 17:16:30 PST 2020


rriddle created this revision.
rriddle added a reviewer: ftynse.
Herald added subscribers: llvm-commits, Joonsoo, liufengdb, herhut, lucyrfox, mgester, arpith-jacob, csigg, nicolasvasilache, antiagainst, shauheen, burmako, jpienaar, mehdi_amini, jholewinski.
Herald added a reviewer: mravishankar.
Herald added a reviewer: antiagainst.
Herald added a project: LLVM.

This revision refactors the TypeConverter class to not use inheritance to add type conversions. It instead moves to a registration based system, where conversion callbacks are added to the converter with `addConversion`. This method takes a conversion callback, which must be convertible to any of the following forms(where `T` is a class derived from `Type`:

- Optional<Type> (T type)
  - This form represents a 1-1 type conversion. It should return nullptr or `llvm::None` to signify failure. If `llvm::None` is returned, the converter is allowed to try another conversion function to perform the conversion.
- Optional<LogicalResult>(T type, SmallVectorImpl<Type> &results)
  - This form represents a 1-N type conversion. It should return `failure` or `llvm::None` to signify a failed conversion. If the new set of types is empty, the type is removed and any usages of the existing value are expected to be removed during conversion. If `llvm::None` is returned, the converter is allowed to try another conversion function to perform the conversion.

When attempting to convert a type, the TypeConverter walks each of the registered converters starting with the one registered most recently.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D74584

Files:
  mlir/docs/DialectConversion.md
  mlir/include/mlir/Conversion/LinalgToLLVM/LinalgToLLVM.h
  mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVM.h
  mlir/include/mlir/Dialect/SPIRV/SPIRVLowering.h
  mlir/include/mlir/Support/STLExtras.h
  mlir/include/mlir/Transforms/DialectConversion.h
  mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
  mlir/lib/Conversion/LinalgToLLVM/LinalgToLLVM.cpp
  mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp
  mlir/lib/Dialect/SPIRV/SPIRVLowering.cpp
  mlir/lib/Transforms/DialectConversion.cpp
  mlir/test/lib/TestDialect/TestPatterns.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74584.244553.patch
Type: text/x-patch
Size: 24502 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200214/22a64768/attachment.bin>


More information about the llvm-commits mailing list