This is an archive of the discontinued LLVM Phabricator instance.

[mlir][PDLL] Add support for generating PDL patterns from PDLL at build time
ClosedPublic

Authored by rriddle on Apr 20 2022, 2:18 AM.

Details

Summary

This essentially sets up mlir-pdll to function in a similar manner to mlir-tblgen. Aside
from the boilerplate of configuring CMake and setting up a basic initial test, two new
options are added to mlir-pdll to mirror options provided by tblgen:

  • -d This option generates a dependency file (i.e. a set of build time dependencies) while processing the input file.
    • --write-if-changed This option only writes to the output file if the data would have changed, which for the build system prevents unnecesarry rebuilds if the file was touched but not actually changed.

Diff Detail

Event Timeline

rriddle created this revision.Apr 20 2022, 2:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 20 2022, 2:18 AM
rriddle requested review of this revision.Apr 20 2022, 2:18 AM
rriddle edited the summary of this revision. (Show Details)
rriddle updated this revision to Diff 424286.Apr 21 2022, 2:04 PM
rriddle edited the summary of this revision. (Show Details)
jpienaar accepted this revision.Apr 24 2022, 11:49 AM

Could we add simple smoke test for -d output? (Not golden of course)

mlir/test/lib/Tools/PDLL/CMakeLists.txt
2

Rm empty newine?

mlir/test/lib/Tools/PDLL/TestPDLL.cpp
31

Move to pass initialization to encourage good behavior

mlir/tools/mlir-pdll/CMakeLists.txt
7

Interesting reuse 🙂

mlir/tools/mlir-pdll/mlir-pdll.cpp
41

Why not StringSet?

This revision is now accepted and ready to land.Apr 24 2022, 11:49 AM
rriddle marked 4 inline comments as done.Apr 26 2022, 2:48 PM

Could we add simple smoke test for -d output? (Not golden of course)

Thanks for catching that! Meant to add one, but forgot.

mlir/tools/mlir-pdll/CMakeLists.txt
7

I went back and forth on how to expose it, but figured that matching the tablegen interface was likely the least intrusive, and easiest for downstream users to interact with. We may want to reconsider this at some point though.

mlir/tools/mlir-pdll/mlir-pdll.cpp
41

Given that this is used for generating build dependency files, I wanted to keep a stable sorted order when building the include set. We could use SetVector, but given that the amount of includes we realistically expect are quite small, it shouldn't matter much here.

This revision was landed with ongoing or failed builds.Apr 26 2022, 6:34 PM
This revision was automatically updated to reflect the committed changes.
rriddle marked 2 inline comments as done.

This change introduced a race condition in the mlir build. We're now occasionally seeing:

##[error]llvm-project\mlir\include\mlir\IR\BuiltinAttributeInterfaces.h(279,10): Error C1083: Cannot open include file: 'mlir/IR/BuiltinAttributeInterfaces.h.inc': No such file or directory
   697>D:\a\_work\1\s\llvm-project\mlir\include\mlir\IR\BuiltinAttributeInterfaces.h(279,10): fatal error C1083: Cannot open include file: 'mlir/IR/BuiltinAttributeInterfaces.h.inc': No such file or directory [D:\a\_work\1\b\llvm\tools\mlir\tools\mlir-pdll\obj.mlir-pdll.vcxproj]
   697>Done Building Project "D:\a\_work\1\b\llvm\tools\mlir\tools\mlir-pdll\obj.mlir-pdll.vcxproj" (default targets) -- FAILED.
   684>Done Building Project "D:\a\_work\1\b\llvm\tools\mlir\tools\mlir-pdll\mlir-pdll.vcxproj" (default targets) -- FAILED.

I looked at the sources and it should, in theory, work correctly, so I'm not sure why it fails. As far as I can tell, the mlir-pdll executable added via add_tablegen has a dependency on the MLIRPDLLCodeGen library which in turn depends on MLIRParser which depends on MLIRIR which depends on MLIRBuiltinAttributeInterfacesIncGen. I would expect cmake to resolve all these dependencies correctly, but perhaps the order matters and the fact that the mlir-pdll is added bfore the tools directory is not populating the dependencies in the right order?