This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly][NFC] Convert StackBased instruction field to 'bit' from string
ClosedPublic

Authored by asb on May 16 2022, 11:17 AM.

Details

Summary

This is (IMHO) cleaner and (objectively) more strongly typed than using strings.

A follow-on patch will do the same for IsWasm64.

It feels like modifying TableGen to support KeyCol = [false] and ValueCols = [[true]] etc might be slightly nicer than ["0"] and [["1"]]. @Paul-C-Anagnostopoulos - any thoughts on how feasible it would be to add that or if it might lead to unexpected issues?

Diff Detail

Unit TestsFailed

Event Timeline

asb created this revision.May 16 2022, 11:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 16 2022, 11:17 AM
asb requested review of this revision.May 16 2022, 11:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 16 2022, 11:17 AM
Herald added a subscriber: aheejin. · View Herald Transcript
asb added a reviewer: pmatos.May 16 2022, 11:24 AM
tlively accepted this revision.May 16 2022, 5:46 PM
This revision is now accepted and ready to land.May 16 2022, 5:46 PM
asb added a comment.May 16 2022, 8:11 PM

The 'true' and 'false' literals are available.

https://llvm.org/docs/TableGen/ProgRef.html#simple-values

@Paul-C-Anagnostopoulos indeed, but they're not usable in KeyCol/ValueCols without some further changes to TableGen Element type mismatch for list: element type 'int' not convertible to 'string

asb added a comment.May 17 2022, 3:00 AM

The 'true' and 'false' literals are available.

https://llvm.org/docs/TableGen/ProgRef.html#simple-values

@Paul-C-Anagnostopoulos indeed, but they're not usable in KeyCol/ValueCols without some further changes to TableGen Element type mismatch for list: element type 'int' not convertible to 'string

Having a quick look at the options:

  • Make it so int/bits are coercible to string. It would be very handy in this case, but I'd worry about unintended consequences
  • Add some shorthand for !cast<string>(foo) that makes it a bit more attractive to use in this case. e.g. let KeyCol = [!tostr(false)]
  • Making the logic for comparing KeyCol/ValueCols fuzzier. i.e. compare the field vs "false" in addition to "0". Not sure if this would have unintended consequences either...

Anyway, for the time being I'll land this and live with "0" and "1". But if you have any thoughts on the above, let me know.

I think you can use defvar to define two constants strue and sfalse, then use them instead of true and false. However, defvar'ed constants are a bit funky, so you'll have to test it.