[PATCH] D123952: [FPEnv] Allow CompoundStmt to keep FP options

Serge Pavlov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 18 11:04:36 PDT 2022


sepavloff created this revision.
sepavloff added reviewers: rsmith, rjmccall, aaron.ballman, kpn.
Herald added subscribers: dexonsmith, martong.
Herald added a reviewer: shafik.
Herald added a project: All.
sepavloff requested review of this revision.
Herald added a project: clang.

AST does not have special nodes for pragmas. Instead a pragma modifies
some state variables of Sema, which in turn result in modified
attributes of AST nodes. This technique applies to floating point
operations as well. Every AST node that can depend on FP options keep
current set of them within it.

This technique works well for options like exception behavior or fast
math options. They represent instructions to the compiler how to modify
code generation for the affected nodes. However treatment of FP control
modes has problems with this technique. Modifying FP control mode
(like rounding direction) usually requires operations on hardware, like
writing to control registers. It must be done prior to the first
operation that depends on the control mode. In particular, such
operations are required for implementation of `pragma STDC FENV_ROUND`,
compiler should set up necessary rounding direction at the beginning of
compound statement where the pragma occurs. As there is no representation
for pragmas in AST, the code generation becomes a complicated task in
this case.

To solve this issue FP options are kept inside CompoundStmt. Unlike to FP
options in expressions, these does not affect any operation on FP values,
but only inform the codegen about the FP options that act in the body of
the statement. As all pragmas that modify FP environment may occurs only
at the start of compound statement or at global level, such solution
works for all relevant pragmas. The options are kept as a difference
from the options in the enclosing compound statement or default options,
it helps codegen to set only changed control modes.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123952

Files:
  clang/include/clang/AST/Stmt.h
  clang/include/clang/AST/TextNodeDumper.h
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Sema/ScopeInfo.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/Stmt.cpp
  clang/lib/AST/TextNodeDumper.cpp
  clang/lib/Analysis/BodyFarm.cpp
  clang/lib/Basic/LangOptions.cpp
  clang/lib/CodeGen/CGCoroutine.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/AST/ast-dump-fpfeatures.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123952.423427.patch
Type: text/x-patch
Size: 19269 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220418/557e9653/attachment-0001.bin>


More information about the cfe-commits mailing list