This is an archive of the discontinued LLVM Phabricator instance.

[mlir][tblgen] Emit deprecation warning if `kEmitRawAttributes` is used
ClosedPublic

Authored by zero9178 on Jan 12 2023, 5:08 AM.

Details

Summary

As discussed in https://reviews.llvm.org/D140886, emitting a warning if the old API is used may be beneficial to encourage migration to the new fold API.
This reuse the existing Deprecated infrastructure within TableGen, and simply marks the def for kEmitRawAttributesFolder causing a use of it in a record (even if set within a base class) to emit a warning.

Error message as printed in the terminal:

Included from C:/llvm-project/mlir/python/mlir/dialects/TensorOps.td:13:
Included from C:/llvm-project/mlir/include\mlir/Dialect/Tensor/IR/TensorOps.td:12:
C:/llvm-project/mlir/include\mlir/Dialect/Tensor/IR/TensorBase.td:14:5: warning: Using deprecated def `kEmitRawAttributesFolder`
def Tensor_Dialect : Dialect {
    ^
note: 'useFoldAPI' of 'kEmitRawAttributesFolder' (default) has been deprecated and is pending removal. Please switch to 'kEmitFoldAdaptorFolder'. See https://discourse.llvm.org/t/psa-new-improved-fold-method-signature-has-landed-please-update-your-downstream-projects/67618

Depends on https://reviews.llvm.org/D141530 (to not emit warnings in tree)

If accepted I'd probably not land this for a week or two (since the new fold has only just landed) to give people more time before emitting warnings.

Diff Detail

Event Timeline

zero9178 created this revision.Jan 12 2023, 5:08 AM
zero9178 requested review of this revision.Jan 12 2023, 5:08 AM
mehdi_amini accepted this revision.Jan 12 2023, 5:38 AM

You have a typo in the title: warining -> warning

mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
2343 ↗(On Diff #488592)

Can you print the dialect name as well here?

This revision is now accepted and ready to land.Jan 12 2023, 5:38 AM
zero9178 updated this revision to Diff 488688.Jan 12 2023, 9:05 AM
zero9178 retitled this revision from [mlir][tblgen] Emit deprecation warining if `kEmitRawAttributes` is used to [mlir][tblgen] Emit deprecation warning if `kEmitRawAttributes` is used.
zero9178 edited the summary of this revision. (Show Details)

Address review comments:

  • Include dialect name in the warning message. This uses the name of the dialect, as is used as prefix in IR, not the name of the TableGen record.
zero9178 marked an inline comment as done.Jan 12 2023, 9:07 AM
zero9178 updated this revision to Diff 489363.Jan 15 2023, 7:18 AM
zero9178 edited the summary of this revision. (Show Details)

Make use of the existing Deprecation infrastructure in TableGen

Compared to the previous manual approach this differs in the following ways:

  • It always warns on usage, regardless of if there are any Ops in the Dialect nor any fold methods in any Ops within the Dialect. I have already found some test dialects in tree that I missed migrating thanks to this. One could also consider this a con however, as it'll warn even if a dialect does not have any fold methods.'
  • It warns more often, since any TableGen invocation including a dialect with the old fold value will now emit a warning not just when generating Op defs and decls for a specific dialect.
  • Dialect name is sadly no longer printed in the warning message.

One of the only things I had to adapt in the existing infrastructure is that I tentatively removed the check whether the def is in the Main source file. This is problematic because Dialects are often not required in the main source file being processed by mlir-tblgen (usually that is the Op file), which would therefore not emit a warning.
@jpienaar do you happen to know whether there was a concrete case where with this check removed, it'd otherwise emit too many warnings or was the check motivated elseway?

Now depends on https://reviews.llvm.org/D141794, otherwise a warning will be emitted for every Op within a dialect, not just once for a dialect.

New error message:

Included from C:/llvm-project/mlir/python/mlir/dialects/TensorOps.td:13:
Included from C:/llvm-project/mlir/include\mlir/Dialect/Tensor/IR/TensorOps.td:12:
C:/llvm-project/mlir/include\mlir/Dialect/Tensor/IR/TensorBase.td:14:5: warning: Using deprecated def `kEmitRawAttributesFolder`
def Tensor_Dialect : Dialect {
    ^
note: 'useFoldAPI' of 'kEmitRawAttributesFolder' (default) has been deprecated and is pending removal. Please switch to 'kEmitFoldAdaptorFolder'. See https://discourse.llvm.org/t/psa-new-improved-fold-method-signature-has-landed-please-update-your-downstream-projects/67618

I'd also like to note that I don't have a strong preference for either the previous manual approch or this one, although I think this one is kind of neat given its mostly TableGen code changes :-)

jpienaar accepted this revision.Jan 15 2023, 12:58 PM

I like this one more too (we get towards having a better functioning deprecation mechanism). Normally I err on keeping .td files unchanged where possible. But don't think you have option either way and this has same user facing impact.

mlir/include/mlir/IR/DialectBase.td
16

We may need new diagram of which include is more abstract than which :-) (this base is higher than that base). Not due to you or blocker here.

mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp
109

I think your removal of traversing anonymous classes helped reduce need for this guard.

This revision was landed with ongoing or failed builds.Jan 18 2023, 1:45 AM
This revision was automatically updated to reflect the committed changes.