[llvm-dev] [RFC] Small Bitfield utilities

Guillaume Chatelet via llvm-dev llvm-dev at lists.llvm.org
Thu Jun 11 09:04:05 PDT 2020


TL;DR: Have support in ADT for typed values packing into opaque scalar types
 - Code & design choices: https://reviews.llvm.org/D81580
 - Usage:
https://reviews.llvm.org/differential/changeset/?ref=2005337&whitespace=ignore-most
 - Example of rewrite: https://reviews.llvm.org/D81662

*CONTEXT*
There are places in LLVM where we need to pack typed fields into opaque
values.

For instance, the `XXXInst` classes in
`llvm/include/llvm/IR/Instructions.h` that extract information from
`Value::SubclassData` via `getSubclassDataFromInstruction()`.
The bit twiddling is done manually: this impairs readability and prevent
consistent handling of out of range values (e.g.
https://github.com/llvm/llvm-project/blob/435b458ad0a4630e6126246a6865748104ccad06/llvm/include/llvm/IR/Instructions.h#L564
).
More importantly, the bit pattern is scattered throughout the
implementation making it hard to pack additional fields or check for
overlapping bits.

I think it would be useful to have first class support for this use case in
LLVM so here is a patch to get the discussion started
https://reviews.llvm.org/D81580. And here the `Instruction` code rewritten
with it https://reviews.llvm.org/D81662, I've added comments to highlight
problems in the existing logic.

Feedback would be highly appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200611/e314b55a/attachment.html>


More information about the llvm-dev mailing list