This is an archive of the discontinued LLVM Phabricator instance.

[TableGen] Add the !find bang operator
ClosedPublic

Authored by Paul-C-Anagnostopoulos on Apr 26 2021, 12:18 PM.

Details

Summary

This revision adds the !find bang operator, which searches a source string for a target string.

I updated the TableGen Programmer's Reference and added a test.

Diff Detail

Event Timeline

Paul-C-Anagnostopoulos requested review of this revision.Apr 26 2021, 12:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 26 2021, 12:18 PM

Do you have a use case in mind for this feature? (will it help tidy up existing tblgen files significantly? is it necessary to support some use case that's not possible to express currently but that's needed by you or others?)

I added !find() to complement !substr(), so that TableGen would have the two most common string functions. I believe !find will be helpful with 'assert' as people begin adding assertions to TableGen files.

dblaikie accepted this revision.Apr 26 2021, 2:47 PM

I added !find() to complement !substr(), so that TableGen would have the two most common string functions. I believe !find will be helpful with 'assert' as people begin adding assertions to TableGen files.

Fair enough - a general suggestion that these sort of tools aren't necessarily the place for adding a lot of speculative features. Usually we expect some in-tree motivating use case (one that you might/would implement/use) (potentially being used in a fairly-shortly-after follow-up commit) rather than building things that might be nice to have at some point.

So perhaps if you're adding features you could use them in the existing tablegen files to clean them up/improve them in some way to motivate the work, demonstrate how to use the features, and evangelize them (having the existing files using the new features as intended helps other people pick up on them when they go to modify/add/etc to the existing usage).

This revision is now accepted and ready to land.Apr 26 2021, 2:47 PM

It makes good sense to spend some time now on additional TableGen file cleanup. There is one file with TODOs for assert, so I will start there.

I will push this on Wednesday.

@dblaikie: What is your opinion on adding an assertion to a TableGen file when the backend(s) are already checking the condition? I think putting the checking closer to the problem is a good thing, and may result in more specific error messages. But, on the other hand, one could argue that it's pointless work.

I will push this on Wednesday.

@dblaikie: What is your opinion on adding an assertion to a TableGen file when the backend(s) are already checking the condition? I think putting the checking closer to the problem is a good thing, and may result in more specific error messages. But, on the other hand, one could argue that it's pointless work.

Seems plausibly useful - though no doubt send such changes for review by the specific tblgen authors to see what they think (I've never written/modified target tblgens - so I'm on the fringes of this work at best).

This revision was landed with ongoing or failed builds.Apr 28 2021, 6:54 AM
This revision was automatically updated to reflect the committed changes.