<div dir="ltr">I don't have a lot to add here but wanted to say thanks for thinking deeply about this.<div>Us trying to squeeze into 7 bits was a pretty shallow+short-term view that might make sense if FP was fairly static. Fortunately the immediate need for that has passed (thanks Roman!)</div><div><br></div><div>Growing in #bits suggested that TrailingObjects makes sense, and growing in applicable scope means even that might not be enough (if it's used in more and more nodes). So I guess this was bound to come up, and solution #4 sounds like the most scalable answer, though I don't know the domain well.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Mar 12, 2020 at 7:24 AM Serge Pavlov <<a href="mailto:sepavloff@gmail.com">sepavloff@gmail.com</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 dir="ltr"><div>Hi all,</div><div><br></div><div>There are development efforts aimed at reducing space occupied by the field FPFeatures (<a href="https://reviews.llvm.org/D72841" target="_blank">https://reviews.llvm.org/D72841</a>). The expected result is reduction of the FPFeatures size from 8 bits to 7, so it is really a battle for bit. I have concern that such work can impact readability and maintainability of the code and would like to discuss alternative ways.<br><br><b>Background</b><br><br>There are two main things that form background of the problem.<br><br>First, operations that involve floating point arguments need to specify floating point environment. The latter is comprised of bits of hardware state registers (rounding direction, denormals behavior, exception mask) and options and hints provided by user to compiler (whether NANs may occur, shall sign of zero be conserved, may exceptions be ignored). The list of relevant options was discussed in <a href="http://lists.llvm.org/pipermail/llvm-dev/2020-January/138652.html" target="_blank">http://lists.llvm.org/pipermail/llvm-dev/2020-January/138652.html</a>. It is convenient to collect all aspects of the FP environment into one object, this is what class FPOptions does. Now this class contains only few attributes but in <a href="https://reviews.llvm.org/D72841" target="_blank">https://reviews.llvm.org/D72841</a> an attempt was made to extend it in right direction.<br><br>Second, the Clang internal representation (AST) was implemented to be as compact as possible. The dark side of this principle is inconvenient class organization and diffuse class boundaries, - derived classes keep their states in parent class fields, which are fixed in size. FP environment now is represented by a field in the class BinaryOperatorBitfields and is only 8 bits in size.<br><br><b>The problem</b><br><br>8 bits is too few to keep all FP related state and options. So in <a href="https://reviews.llvm.org/D72841" target="_blank">https://reviews.llvm.org/D72841</a> FPOptions was moved out of BinaryOperatorBitfields and made a field in classes UnaryOperator, BinaryOperator, CallExpr and CXXOperatorCallExpr. It is a step in right direction as, for example, now UnaryOperator does not have FPOption.<br><br>This change however resulted in that every instance of BinaryOperator, CallExpr and other now increase in size. To reduce the space refactoring of <a href="https://reviews.llvm.org/D72841" target="_blank">https://reviews.llvm.org/D72841</a> was started.<br><br>Current support of FP environment in clang is weak, ongoing development in this direction will eventually increase size required for FP state and options and increase number of AST nodes that require knowledge of FP environment (these could be FloatingLiteral, InitListExpr, CXXDefaultArgExpr and some other). We must elaborate solution that allow future extensions without massive changes.<br><br><b>Possible solutions</b><br><br> 1. Consider memory consumption as inevitable evil and add FPOtions to every node where it is needed.</div><div><br> 2. Add FPOptions to subclasses, for example FloatingUnaryOperator and similar. It however would swamp class hierarchy with duplicates and make handling AST more complex, as we use static polymorphism, not dynamic.</div><div><br> 3. Use trailing objects. While this way is natural when the size of additional information is variable, using trailing objects to keep just some fields of an object is inconvenient.</div><div><br> 4. Keep FPOptions is a special node, say FloatingPointRegionStmt. As now FP environment can be modified only at block and function level, actually the same FPOption is replicated to all nodes of that block. This FloatingPointRegionStmt would be similar to nodes like ExprWithCleanups, as it would represent a notion rather than source code construct. We also could embed FPOptions directly into CompoundStmt, but we must also provide similar facility at least for initializers and default arguments.<br><br>I am inclined to the solution 4, as it reduces size consumption and at the same time does not limit implementation of FPOptions.<br></div><br clear="all"><div><div dir="ltr">Thanks,<br>--Serge<br></div></div></div>
</blockquote></div>