[all-commits] [llvm/llvm-project] 01b55f: [NFC] Tidy up DialectConversion.cpp

River Riddle via All-commits all-commits at lists.llvm.org
Tue Oct 26 19:12:36 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 01b55f163a40073914bf92f5b710319e7cae2e02
      https://github.com/llvm/llvm-project/commit/01b55f163a40073914bf92f5b710319e7cae2e02
  Author: River Riddle <riddleriver at gmail.com>
  Date:   2021-10-27 (Wed, 27 Oct 2021)

  Changed paths:
    M mlir/lib/Transforms/Utils/DialectConversion.cpp

  Log Message:
  -----------
  [NFC] Tidy up DialectConversion.cpp

This file has gotten a bit crusty over the years, and has outdated stylistic decisions.


  Commit: 015192c63415ae828c3a9bc8b56d0667abcca8ae
      https://github.com/llvm/llvm-project/commit/015192c63415ae828c3a9bc8b56d0667abcca8ae
  Author: River Riddle <riddleriver at gmail.com>
  Date:   2021-10-27 (Wed, 27 Oct 2021)

  Changed paths:
    M mlir/docs/Tutorials/Toy/Ch-5.md
    M mlir/examples/toy/Ch5/mlir/LowerToAffineLoops.cpp
    M mlir/examples/toy/Ch6/mlir/LowerToAffineLoops.cpp
    M mlir/examples/toy/Ch7/mlir/LowerToAffineLoops.cpp
    M mlir/include/mlir/Conversion/SPIRVToLLVM/SPIRVToLLVM.h
    M mlir/include/mlir/IR/BlockAndValueMapping.h
    M mlir/include/mlir/IR/Operation.h
    M mlir/include/mlir/IR/OperationSupport.h
    M mlir/include/mlir/Transforms/DialectConversion.h
    M mlir/lib/Conversion/SCFToSPIRV/SCFToSPIRV.cpp
    M mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp
    M mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
    M mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp
    M mlir/lib/Dialect/SPIRV/Transforms/DecorateCompositeTypeLayoutPass.cpp
    M mlir/lib/IR/OperationSupport.cpp
    M mlir/lib/Transforms/Utils/DialectConversion.cpp
    M mlir/test/Conversion/ArithmeticToLLVM/arith-to-llvm.mlir
    M mlir/test/Conversion/ArithmeticToSPIRV/arithmetic-to-spirv.mlir
    M mlir/test/Conversion/ComplexToLLVM/convert-to-llvm.mlir
    M mlir/test/Conversion/MemRefToLLVM/convert-dynamic-memref-ops.mlir
    M mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir
    M mlir/test/Conversion/MemRefToSPIRV/memref-to-spirv.mlir
    M mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
    M mlir/test/Conversion/StandardToLLVM/calling-convention.mlir
    M mlir/test/Conversion/StandardToSPIRV/std-ops-to-spirv.mlir
    M mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir
    M mlir/test/Dialect/ArmSVE/memcpy.mlir
    M mlir/test/Dialect/Linalg/bufferize.mlir
    M mlir/test/Dialect/Linalg/detensorize_0d.mlir
    M mlir/test/Dialect/Linalg/detensorize_while_impure_cf.mlir
    M mlir/test/Dialect/SCF/bufferize.mlir
    M mlir/test/Dialect/Standard/bufferize.mlir
    M mlir/test/Dialect/Standard/func-bufferize.mlir
    M mlir/test/Dialect/Tensor/bufferize.mlir
    M mlir/test/Transforms/test-legalize-remapped-value.mlir
    M mlir/test/Transforms/test-legalize-type-conversion.mlir
    M mlir/test/Transforms/test-legalizer.mlir
    M mlir/test/lib/Dialect/Test/TestOps.td
    M mlir/test/lib/Dialect/Test/TestPatterns.cpp

  Log Message:
  -----------
  [mlir:DialectConversion] Restructure how argument/target materializations get invoked

The current implementation invokes materializations
whenever an input operand does not have a mapping for the
desired type, i.e. it requires materialization at the earliest possible
point. This conflicts with goal of dialect conversion (and also the
current documentation) which states that a materialization is only
required if the materialization is supposed to persist after the
conversion process has finished.

This revision refactors this such that whenever a target
materialization "might" be necessary, we insert an
unrealized_conversion_cast to act as a temporary materialization.
This allows for deferring the invocation of the user
materialization hooks until the end of the conversion process,
where we actually have a better sense if it's actually
necessary. This has several benefits:

* In some cases a target materialization hook is no longer
   necessary
When performing a full conversion, there are some situations
where a temporary materialization is necessary. Moving forward,
these users won't need to provide any target materializations,
as the temporary materializations do not require the user to
provide materialization hooks.

* getRemappedValue can now handle values that haven't been
   converted yet
Before this commit, it wasn't well supported to get the remapped
value of a value that hadn't been converted yet (making it
difficult/impossible to convert multiple operations in many
situations). This commit updates getRemappedValue to properly
handle this case by inserting temporary materializations when
necessary.

Another code-health related benefit is that with this change we
can move a majority of the complexity related to materializations
to the end of the conversion process, instead of handling adhoc
while conversion is happening.

Differential Revision: https://reviews.llvm.org/D111620


Compare: https://github.com/llvm/llvm-project/compare/9c7ace60aa62...015192c63415


More information about the All-commits mailing list