Page MenuHomePhabricator

Add size of FP environment to DataLayout
Changes PlannedPublic

Authored by sepavloff on Dec 19 2019, 10:18 PM.

Details

Summary

Add size of FP environment to DataLayout

This change extends the layout specification with a new item. The item
has the form "fe:<size>" in which the argument <size> specifies the size
of floating point environment, which includes rounding mode, raised
exceptions etc.

Saving/restoring the FP environment requries creation of a variable for
the FP state but the size of this variable depends on the used target. As
this operation occurs at IR level, the size of FP state must be provided
by a component intended to represent target properties in
target-independent pipeline.

Diff Detail

Event Timeline

sepavloff created this revision.Dec 19 2019, 10:18 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 19 2019, 10:18 PM
Herald added a subscriber: hiraditya. · View Herald Transcript

Updated patch

  • Removed alignment info. Alignment of stack must be enough.

Do we really need this in the datalayout? I can imagine certain frontends might care, but I can't imagine optimizations inserting new save/restore operations.

As an example, inlining a function that requires default FP environment into a function where FP is non-standard requires saving the FP environment before entry into the inlined function and resoring it upon return.

Not sure what the inliner has to do with this; the required FP environment for each floating-point operation doesn't change if you inline a function.

sepavloff edited the summary of this revision. (Show Details)Jun 14 2020, 10:52 PM

Do we really need this in the datalayout? I can imagine certain frontends might care, but I can't imagine optimizations inserting new save/restore operations.

There are at least two motivations of having FPEnv size in DataLayout:

  • Implementation of a pragma that would set and restore runtime rounding mode, a sequence like this:
fegetenv(&saved_fpenv);
fesetroundinf(FE_DOWNWARD);
... Operations that require specific rounding mode ...
fesetenv(&saved_fpenv);
  • Some IR transformation like inlining, various loop transformation and some others involve code motion. As a result the moved code may be put into surroundings where FP environment is different or unknown, or changing it is undesirable.

In these cases compiler may need to insert save/restore operations but the type of variable to store the environment is target-dependent.

sepavloff planned changes to this revision.Jun 22 2020, 2:56 AM

The dependent revision D71742 is modified so that it does not require size of FP environment to be specified in DataLayout. Probably when implementing frontend part this information will become necessary.