This is an archive of the discontinued LLVM Phabricator instance.

Implemented a skeleton for SPIR-V to LLVM dialect conversion, added conversion for spv.BitwiseAndOp
ClosedPublic

Authored by georgemitenkov on Jun 3 2020, 7:55 AM.

Details

Summary

These commits set up the skeleton for SPIR-V to LLVM dialect conversion.
I created SPIR-V to LLVM pass, registered it in Passes.td, InitAllPasses.h.
Added a pattern for spv.BitwiseAndOp and tests for it. Integer, float and vector types are converted through LLVMTypeConverter.

Diff Detail

Event Timeline

georgemitenkov created this revision.Jun 3 2020, 7:55 AM
Herald added a project: Restricted Project. · View Herald Transcript
simoll added a subscriber: simoll.Jun 3 2020, 8:17 AM
rriddle added inline comments.Jun 3 2020, 10:16 AM
mlir/include/mlir/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.h
17

These headers don't look necessary. Can you replace with forward declarations instead?

mlir/include/mlir/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVMPass.h
17

This doesn't seem necessary, can you use forward declarations instead?

mlir/lib/Conversion/CMakeLists.txt
19

Please keep this sorted.

mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp
31

using namespace mlir;

43

This should already be guaranteed, please avoid asserting on things that are already guaranteed by the infra.

46

Remove all trivial braces.

54

This should be mlir::populateSPIRVToLLVMConversionPatterns

mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVMPass.cpp
45

Remove trivial braces.

georgemitenkov marked 8 inline comments as done.
  • Refactored code: removed trivial braces, added forward declarations
  • Refactored the code with git-clang

Code refactoring

  • Removed trivial braces
  • Added forward declarations instead of includes
  • Made cmake sorted
ftynse added a comment.Jun 4 2020, 1:28 AM

Somehow, I now only see the changes made in response to River's comments. Could you please make sure you upload the full patch (arc diff HEAD^ will only include the last commit on your branch for upload in case you have multiple commits; use parent's hash or as many ^^^ as there are commits)

mlir/include/mlir/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.h
2

Nit: pad to 80 cols

mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp
2

Nit: please pad to 80 cols

Added 2 previously missing commits

ftynse added inline comments.Jun 4 2020, 4:20 AM
mlir/include/mlir/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.h
22–24

These two declarations look unused

mlir/test/Conversion/SPIRVToLLVM/convert-to-llvm.mlir
5
georgemitenkov marked 2 inline comments as done.
  • Sorted passes in Passes.td and increased padding to 80 cols

Refactored the padding in header files to 80 cols, also put SPIRVToLLVM pass in Pass.td in sorted order with other passes

  • Added correct padding to .cpp files

Added padding of 80 cols to ConvertSPIRVToLLVMPass.cpp and ConvertSPIRVToLLVM.cpp

antiagainst requested changes to this revision.Jun 4 2020, 8:07 AM

Awesome, George! Nice to see this coming up so fast. Overall looks good to me; I just have a few sytle/comments/etc. nits.

mlir/include/mlir/Conversion/Passes.td
204

"Convert SPIR-V dialect to LLVM dialect" to be consistent?

mlir/include/mlir/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.h
2

Convert SPIR-V to LLVM ...

10

SPIR-V dialect to LLVM dialect

26

Populates ...

Typically we prefer to use descriptive instead of imperative words for documentation. (Although this is somehow not very consistent in the codebase...)

mlir/include/mlir/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVMPass.h
10

from SPIR-V dialect to ...

We are doing more than ops; also types.

24

Creates

mlir/include/mlir/Conversion/VectorToLLVM/ConvertVectorToLLVM.h
16–17

Why this change? Seems unrelated to this patch.

mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp
27

We'd prefer to not pull in all symbols both from LLVM and spirv together... There are likely ops with the same name and it can cause suprising symbol resolution issue later. Let's just qualify all symbols with LLVM:: or spirv:: properly. :)

mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVMPass.cpp
39

Please document why we are pulling in std to llvm conversion patterns here. :)

mlir/test/Conversion/SPIRVToLLVM/convert-to-llvm.mlir
4

Typically we prefer smaller and dedicated tests. The benefits of doing that is you can isolate culprit lines very easily and updating tests is also easier given you'll not need to update unrelated stuff. So here I'd suggest we create two functions, scalar_bitwise_add and vector_bitwise_and and keep the test cases separate. :)

This revision now requires changes to proceed.Jun 4 2020, 8:07 AM

Anther thing about commit message:

  • Typically we want a short one-liner to describe what the change is about concisely and put detailed description in a second paragraph separated by an empy line from the one-liner. The benefits of doing so is that it renders nicely on GitHub history UI and also it's very easy to read when using git log --oneline.
  • MLIR related changes are typically qualified with [MLIR] at the beginning of the commit message. And then we might also want to further qualify it with [SPIRVToLLVM].
georgemitenkov marked 11 inline comments as done.
  • [MLIR][SPIRVToLLVM] Changed description style and split tests

Changed description of files to be consistent with the codebase. Added a comment on the use of std to llvm conversion in patterns. Refactored test into 2 tests that test scalar and vector bitwise and separetely. Removed pattern-match on SSA-values.

georgemitenkov marked 2 inline comments as done.
  • [MLIR][SPIRVToLLVM] Removed unused declarations

Removed unused declarations in ConvertSPIRVToLLVM.h.

antiagainst requested changes to this revision.Jun 4 2020, 2:24 PM

Please bear with me with more nitpicking. :)

mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVMPass.cpp
32

This should be put before populateStdToLLVMConversionPatterns so it's near to what's explaining. :)

mlir/test/Conversion/SPIRVToLLVM/convert-to-llvm.mlir
5

There is no need to capture the value with T0 here given it's not referenced later. You can just do %{{.*}} here.

11

%[[A:.*]] actually captures the matched string into A. Here we are essentially capturing both operands as A (so the later is overwriting the former). Given that we are not particularly interested in the operand here, it's fine to have {{.*}} here.

This revision now requires changes to proceed.Jun 4 2020, 2:24 PM
antiagainst added inline comments.Jun 4 2020, 2:25 PM
mlir/test/Conversion/SPIRVToLLVM/convert-to-llvm.mlir
11
georgemitenkov marked 4 inline comments as done.
  • [MLIR][SPIRVToLLVM] Changed test to use string substitution blocks

Put comment about populateStandardToLLVMPatterns next to the actuall function call. Changed FileCheck tests to use substitution blocks {{.*}} instead of saving the matched pattern in [[A:.*]] for example.

antiagainst accepted this revision.Jun 5 2020, 5:35 AM

Awesome, thanks!

This revision is now accepted and ready to land.Jun 5 2020, 5:35 AM
This revision was automatically updated to reflect the committed changes.