<div dir="ltr">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.<div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">~Craig</div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 15, 2021 at 10:33 AM Paul C. Anagnostopoulos via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<p><font face="Helvetica, Arial, sans-serif">In TableGen, there is
the following struct. In any given instance, only one of the
pointers is filled in.</font></p>
<blockquote>
<p><tt> struct RecordsEntry {<br>
std::unique_ptr<Record> Rec;<br>
std::unique_ptr<ForeachLoop> Loop;<br>
std::unique_ptr<Record::AssertionTuple> Assertion;<br>
<br>
void dump() const;<br>
<br>
RecordsEntry() {}<br>
RecordsEntry(std::unique_ptr<Record> Rec) :
Rec(std::move(Rec)) {}<br>
RecordsEntry(std::unique_ptr<ForeachLoop> Loop)<br>
: Loop(std::move(Loop)) {}<br>
RecordsEntry(std::unique_ptr<Record::AssertionTuple>
Assertion)<br>
: Assertion(std::move(Assertion)) {}<br>
};<br>
</tt></p>
</blockquote>
<p>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.</p>
<p>What do people think about this? If I should do it, could someone
help me with the changes?<br>
</p>
<div>
<br>
</div>
</div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>