[PATCH] Teach AsmPrinter how to print odd constants.

Quentin Colombet qcolombet at apple.com
Tue Jun 4 17:10:20 PDT 2013


Hi,

** Context **
Currently, the compiler asserts if it encounters big constants whose bit width is not a multiple of 64-bits .
Although clang would never generate something like this, the backend should be able to handle any legal IR.

** Proposal **
The proposed patch teaches the AsmPrinter how to emit such constants.

** Implementation Details **
It emits the bytes, that will not be part of the 64-bits chunks, in a separate directive after the 64-bits chunks.
The chosen directive fills the gap in size between the emitted 64-bits chunks and the size expected by the target data layout.

The little endian case is straightforward as the extra bits are emitted at the end.
The big endian case requires more work. The left most bit of the first directive is expected to be the most significant one. Since the bit width of the data is not a multiple of 64-bits, the APInt does not expose nice 64-bits chunks.
The chosen approach is to shift the data so that the chunks are perfectly aligned. Then, the process is similar to little endian case.
See the comments in the patch for more details.

** Test Cases **
The patch includes 3 test cases:
- X86_64: little endian, last directive is 64 bits.
- Mips: big endian, last directive is 64 bits.
- thumbv7: little endian, last directive is 32 bits. 

Thanks for the review,

-Quentin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130604/fc5317ab/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: AsmPrinter-odd-cst.svndiff
Type: application/octet-stream
Size: 5102 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130604/fc5317ab/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130604/fc5317ab/attachment-0001.html>


More information about the llvm-commits mailing list