[all-commits] [llvm/llvm-project] c7ff5b: [FPEnv] Use single enum to represent rounding mode

Serge Pavlov via All-commits all-commits at lists.llvm.org
Wed Apr 8 23:27:43 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: c7ff5b38f27f812dcd6e2e8732208a39232dc284
      https://github.com/llvm/llvm-project/commit/c7ff5b38f27f812dcd6e2e8732208a39232dc284
  Author: Serge Pavlov <sepavloff at gmail.com>
  Date:   2020-04-09 (Thu, 09 Apr 2020)

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

  Log Message:
  -----------
  [FPEnv] Use single enum to represent rounding mode

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 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 uses a special value to
indicate error. It is convenient to use in intrinsic functions, as it
represents 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 type via one `llvm::RoundingMode`,
which also contains rounding mode for IEEE rounding direction `roundTiesToAway`.

Differential Revision: https://reviews.llvm.org/D77379




More information about the All-commits mailing list