This is an archive of the discontinued LLVM Phabricator instance.

[TableGen] [AMDGPU] Add !sub bang operator for subtraction
ClosedPublic

Authored by Paul-C-Anagnostopoulos on Oct 24 2020, 3:46 PM.

Details

Summary

In my travels through TableGen and the backends, I came across:

foreach Index = Indexes<!add(33, !mul(Size, -1))>.slice in {

To clean this up, I changed it to:

foreach Index = Indexes<!sub(33, Size)>.slice in {

Only then did I finally realize that there is no subtraction bang operator. So there is now.

I also used this opportunity to change the old '-' range punctuation to '...'.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptOct 24 2020, 3:46 PM
Paul-C-Anagnostopoulos requested review of this revision.Oct 24 2020, 3:46 PM
Paul-C-Anagnostopoulos edited the summary of this revision. (Show Details)Oct 24 2020, 3:47 PM
foad added a subscriber: foad.Oct 25 2020, 1:52 AM

I like it.

llvm/docs/TableGen/ProgRef.rst
1667

Can you improve this description so that I can understand what it does if there are more than two operands please? :) (I guess it probably follows the LISP precedent where (- a b c d) is (- a (+ b c d))?)

llvm/docs/TableGen/ProgRef.rst
1667

Thank you for asking this question! In fact, it does something silly, so I will not allow more than two arguments.

Changed !sub so it takes only two arguments.

foad added inline comments.Oct 25 2020, 9:24 AM
llvm/test/TableGen/arithmetic.td
30–35

Nit: choose two numbers for which !sub and !xor give different results? And preferably !srl and !sra too.

llvm/test/TableGen/arithmetic.td
30–35

Good idea. I will do that.

Improve the arithmetic.td test so all results are different.

I will auto-LGTM this revision on Wednesday.

madhur13490 accepted this revision.Oct 28 2020, 6:30 AM
madhur13490 added inline comments.
llvm/docs/TableGen/ProgRef.rst
1667

nit; ".. and produces the arithmetic difference"

llvm/lib/TableGen/TGParser.cpp
1259

I think the condition can be moved to a separate function before it becomes unmanageable.

This revision is now accepted and ready to land.Oct 28 2020, 6:30 AM
Paul-C-Anagnostopoulos marked 2 inline comments as done.Oct 28 2020, 7:37 AM
Paul-C-Anagnostopoulos added inline comments.
llvm/lib/TableGen/TGParser.cpp
1259

There are complex conditions like this all over TableGen.

This revision was automatically updated to reflect the committed changes.
Paul-C-Anagnostopoulos marked an inline comment as done.