[PATCH] D77379: [FPEnv] Use single enum to represent rounding mode

Serge Pavlov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 3 03:44:03 PDT 2020


sepavloff created this revision.
sepavloff added reviewers: rjmccall, andrew.w.kaylor, arsenm, kpn, cameron.mcinally, uweigand.
Herald added subscribers: dexonsmith, hiraditya, wdng.
Herald added a project: clang.

Now compiler defines 5 sets of constants to represent rounding mode.
These are:

1. `llvm::APFloatBase::roundingMode`. It specifies all 5 rounding modes

defined by IEEE-754 and is used in `APFloat` implementation.

2. `clang::LangOptions::FPRoundingModeKind`. It specifies 4 of 5 IEEE-754

rounding modes and a special value for dynamic rounding mode. It is used
in clang frontend.

3. `llvm::fp::RoundingMode`. Defines the same values as

`clang::LangOptions::FPRoundingModeKind` but in different order. It is
used to specify rounding mode in IR and functions that operate IR.

4. Rounding mode representation used by `FLT_ROUNDS` (C11, 5.2.4.2.2p7).

Besides constants for rounding mode it also defines a special value to
indicate errors. It is convenient to use in intrinsic functions, as it
is a platform-independent representation for rounding mode. In this
role it is used in some pending patches.

5. Values like `FE_DOWNWARD` and other, which specify rounding mode in

library calls `fesetround` and `fegetround`. Often they represent bits
of some control register, so they are target-dependent. The same names
(not values) and a special name `FE_DYNAMIC` are used in
`#pragma STDC FENV_ROUND`.

The first 4 sets of constants are target independent and could have the
same numerical representation. It would simplify conversion between the
representations. Also now `clang::LangOptions::FPRoundingModeKind` and
`llvm::fp::RoundingMode` do not contain the value for IEEE-754 rounding
direction `roundTiesToAway`, although it is supported natively on
some targets.

This change defines all the rounding mode types via one enumeration
`llvm::RoundingMode`, which also contains rounding mode for IEEE
rounding direction `roundTiesToAway`. This enumeration uses the encoding
specified by C standard for `FLT_ROUNDS`, as it is the only representation
in which numerical values of rounding modes is fixed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77379

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Basic/LangOptions.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Serialization/ASTReader.cpp
  llvm/include/llvm/ADT/APFloat.h
  llvm/include/llvm/ADT/FloatingPointMode.h
  llvm/include/llvm/IR/FPEnv.h
  llvm/include/llvm/IR/IRBuilder.h
  llvm/include/llvm/IR/IntrinsicInst.h
  llvm/lib/Analysis/ConstantFolding.cpp
  llvm/lib/IR/FPEnv.cpp
  llvm/lib/IR/IntrinsicInst.cpp
  llvm/lib/Support/APFloat.cpp
  llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
  llvm/unittests/IR/IRBuilderTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77379.254743.patch
Type: text/x-patch
Size: 29244 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200403/adc3076a/attachment-0001.bin>


More information about the cfe-commits mailing list