<div dir="ltr"><div>TL;DR: Have support in ADT for typed values packing into opaque scalar types</div><div> - Code & design choices: <a href="https://reviews.llvm.org/D81580">https://reviews.llvm.org/D81580</a><br></div><div> - Usage: <a href="https://reviews.llvm.org/differential/changeset/?ref=2005337&whitespace=ignore-most">https://reviews.llvm.org/differential/changeset/?ref=2005337&whitespace=ignore-most</a></div><div> - Example of rewrite: <a href="https://reviews.llvm.org/D81662">https://reviews.llvm.org/D81662</a></div><div><br></div><div>*CONTEXT*</div><div>There are places in LLVM where we need to pack typed fields into opaque values.<br></div><div><br></div><div>For instance, the `XXXInst` classes in `llvm/include/llvm/IR/Instructions.h` that extract information from `Value::SubclassData` via `getSubclassDataFromInstruction()`.</div><div>The bit twiddling is done manually: this impairs readability and prevent consistent handling of out of range values (e.g. <a href="https://github.com/llvm/llvm-project/blob/435b458ad0a4630e6126246a6865748104ccad06/llvm/include/llvm/IR/Instructions.h#L564">https://github.com/llvm/llvm-project/blob/435b458ad0a4630e6126246a6865748104ccad06/llvm/include/llvm/IR/Instructions.h#L564</a>).</div><div>More importantly, the bit pattern is scattered throughout the implementation making it hard to pack additional fields or check for overlapping bits.<br></div><div><br></div><div>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 <a href="https://reviews.llvm.org/D81580">https://reviews.llvm.org/D81580</a>. And here the `Instruction` code rewritten with it <a href="https://reviews.llvm.org/D81662">https://reviews.llvm.org/D81662</a>, I've added comments to highlight problems in the existing logic.</div><div><br></div><div>Feedback would be highly appreciated.</div><div></div></div>