[PATCH] Tablegen binary literals should be sized

Pete Cooper peter_cooper at apple.com
Thu Jul 31 13:48:37 PDT 2014


Hi all

Moving this from LLVMDev (http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-July/075223.html) now that i have patches i’d welcome reviews of.  The following is the initial summary from that email thread.

"Currently tablegen parses binary literals such as 0b011 and immediately turns them in to integers internally.  Due to this, 0b011 is a 2-bit value because tablegen will happily drop leading zeroes on integers.

I propose that we change this, and store binary literals with a size.  I think this is much more natural, as when the user writes a value with 3 bits, I think they expect to get a value with 3 bits, and not a 2-bit value which is silently truncated and later silently zero extended.

Given this, I would then like to extend bits initializers to accept these new sized binary literals.  For example, I would like to be able to write

bits<2> opc;
bits<8> x = { opc, 0b1100, rd{1}, rs{0} }

This would let us write some encodings much more concisely, instead of having to put each initializer on its own line.”

For those interested in the low level details, i’ve changed binary literals such as 0b011 from creating an integer ‘3’, to creating a BitsInit ‘{ 0, 1, 1}’.  As Sean suggested, this was better than introducing yet another type just for binary literals.

As part of this, BitsInit values now had to be able to be typed.  This is because we had uses of binary literals which expected to be typed (for example list<bits<2>> [0b00, 0b01]).  I’ve moved BitsInit from being a subclass of Init to a subclass of TypedInit to allow this.

Note that patches 2 and 3 really need to be committed together.  I can squash them before commit, but just wanted to present the changes independently.

Patch 5 can also be committed without any of the others, but just shows that this did actually catch some useful cases where we mismatched sizes of binary expressions.

Thanks,
Pete

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140731/90df8e56/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-TableGen-Change-to-only-accept-bits-n-entries-when-n.patch
Type: application/octet-stream
Size: 2200 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140731/90df8e56/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140731/90df8e56/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Change-TableGen-so-that-binary-literals-such-as-0b00.patch
Type: application/octet-stream
Size: 4362 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140731/90df8e56/attachment-0001.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140731/90df8e56/attachment-0002.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-Change-BitsInit-to-inherit-from-TypedInit.patch
Type: application/octet-stream
Size: 5975 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140731/90df8e56/attachment-0002.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140731/90df8e56/attachment-0003.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0004-Change-the-expression-in-tablegen-to-accept-sized-bi.patch
Type: application/octet-stream
Size: 3279 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140731/90df8e56/attachment-0003.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140731/90df8e56/attachment-0004.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0005-Fix-a-whole-bunch-of-binary-literals-which-were-the-.patch
Type: application/octet-stream
Size: 7273 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140731/90df8e56/attachment-0004.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140731/90df8e56/attachment-0005.html>


More information about the llvm-commits mailing list