Page MenuHomePhabricator

Add size of FP environment to DataLayout
Needs ReviewPublic

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

Details

Summary

Add size of FP environment to DataLayout

DataLayout specification is extended with a new item, which has the form
"fe:<size1>:<size2>". The argument <size1> specifies the size of floating
point control modes (such as rounding mode) and correspond to the size of
type femode_t used in C library. The optional argument <size2> represents
size of entire floating point environment and corresponds to the size of
fenv_t. It defaults to the same value as <size1>.

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.

sepavloff updated this revision to Diff 330971.Mar 16 2021, 6:52 AM
sepavloff edited the summary of this revision. (Show Details)

Rebased patch. Added size of control modes.

sepavloff edited the summary of this revision. (Show Details)Mar 16 2021, 6:55 AM
sepavloff added a reviewer: craig.topper.
sepavloff updated this revision to Diff 331292.Mar 17 2021, 9:34 AM
sepavloff edited the summary of this revision. (Show Details)

Use more consistent name: s/getFPControlModesSize/getFPControlModeSize/