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.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
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. |
- 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
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 |
mlir/include/mlir/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.h | ||
---|---|---|
22–24 | These two declarations look unused | |
mlir/test/Conversion/SPIRVToLLVM/convert-to-llvm.mlir | ||
5 | Please don't pattern-match on SSA value names, https://mlir.llvm.org/getting_started/TestingGuide/#filecheck-best-practices |
- 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
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. :) |
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].
- [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.
- [MLIR][SPIRVToLLVM] Removed unused declarations
Removed unused declarations in ConvertSPIRVToLLVM.h.
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. |
mlir/test/Conversion/SPIRVToLLVM/convert-to-llvm.mlir | ||
---|---|---|
11 | See here for more details: https://llvm.org/docs/CommandGuide/FileCheck.html#filecheck-string-substitution-blocks |
- [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.
"Convert SPIR-V dialect to LLVM dialect" to be consistent?