[llvm-dev] Unionizing a struct
Paul C. Anagnostopoulos via llvm-dev
llvm-dev at lists.llvm.org
Thu Apr 15 10:33:36 PDT 2021
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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210415/80010071/attachment.html>
More information about the llvm-dev
mailing list