Depending on the alignment requirement of the 3 types involved, you might
be able to use PointerUnion to store the discrimination enum in the lower 2
bits of the pointer.
~Craig
On Thu, Apr 15, 2021 at 10:33 AM Paul C. Anagnostopoulos via llvm-dev <
llvm-dev at lists.llvm.org> wrote:
> In TableGen, there is the following struct. In any given instance, only
> one of the pointers is filled in.
>
> struct RecordsEntry {
> std::unique_ptr<Record> Rec;
> std::unique_ptr<ForeachLoop> Loop;
> std::unique_ptr<Record::AssertionTuple> Assertion;
>
> void dump() const;
>
> RecordsEntry() {}
> RecordsEntry(std::unique_ptr<Record> Rec) : Rec(std::move(Rec))
{}
> RecordsEntry(std::unique_ptr<ForeachLoop> Loop)
> : Loop(std::move(Loop)) {}
> RecordsEntry(std::unique_ptr<Record::AssertionTuple> Assertion)
> : Assertion(std::move(Assertion)) {}
> };
>
> It has been suggested that the three pointers be made a union. This
> requires a discrimination enum. I believe that would reduce the struct from
> 24 to 12 bytes, and I think it requires a custom destructor.
>
> What do people think about this? If I should do it, could someone help me
> with the changes?
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20210415/73f3e2c8/attachment.html>