[llvm-dev] RFC: Refactor SubclassData

Bruno Ricci via llvm-dev llvm-dev at lists.llvm.org
Fri Dec 27 09:34:49 PST 2019


Hi,

On 26/12/2019 20:53, Ehud Katz via llvm-dev wrote:
> I've tested it on MSVC, gcc, clang and icc.
> 
> The solution in clang (in Decl.h) is not ideal (as you have said yourself). The solution I offer, is using a union of fields of class BitField (this is a new class that implements a bitfield of a specific type requested). With this, the definition, of the required bitfields in the subclass data, remains in the hands of the actual class needing them. And these are all restricted hierarchically by the superclasses of that class.

I spent some time packing various bits of data into bit-fields in clang. My experience
is that the solution in clang actually works just fine. The Stmt hierarchy has a huge
number of bit-field classes (I count more than 40! [1]), but because the offsets are
relative adding a bit means only adding one to an enum value a few lines below
(a static_assert then checks that the union is not too large).

[1] https://github.com/llvm/llvm-project/blob/f20fc65887e2085332d111ee0b05736794423c72/clang/include/clang/AST/Stmt.h#L948

Bruno Ricci




More information about the llvm-dev mailing list