diff options
| author | Serge Pavlov <sepavloff@gmail.com> | 2019-08-29 19:29:11 +0700 |
|---|---|---|
| committer | Serge Pavlov <sepavloff@gmail.com> | 2019-11-20 19:05:46 +0700 |
| commit | ea8678d1c78ecf6c719b4a9ff1aa8db0087401ca (patch) | |
| tree | e2d488ae12c93eab851ad66ecef84d5d1eb55ce4 /llvm/lib | |
| parent | c502bae52410c83947e5ad7184dff810083afe75 (diff) | |
| download | bcm5719-llvm-ea8678d1c78ecf6c719b4a9ff1aa8db0087401ca.tar.gz bcm5719-llvm-ea8678d1c78ecf6c719b4a9ff1aa8db0087401ca.zip | |
Move floating point related entities to namespace level
This is recommit of commit e6584b2b7b2d, which was reverted in
30e7ee3c4bac together with af57dbf12e54.
Original message is below.
Enumerations that describe rounding mode and exception behavior were
defined inside ConstrainedFPIntrinsic. It makes sense to use the same
definitions to represent the same properties in other cases, not only
in constrained intrinsics. It was however inconvenient as required to
include constrained intrinsics definitions even if they were not needed.
Also using long scope prefix reduced readability.
This change moves these definitioins to the namespace llvm::fp.
No functional changes.
Differential Revision: https://reviews.llvm.org/D69552
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 3 | ||||
| -rw-r--r-- | llvm/lib/IR/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | llvm/lib/IR/FPEnv.cpp | 78 | ||||
| -rw-r--r-- | llvm/lib/IR/IntrinsicInst.cpp | 67 |
4 files changed, 82 insertions, 67 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 438840aa941..4fa907a4dcf 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -6914,8 +6914,7 @@ void SelectionDAGBuilder::visitConstrainedFPIntrinsic( SDVTList VTs = DAG.getVTList(ValueVTs); SDValue Result = DAG.getNode(Opcode, sdl, VTs, Opers); - if (FPI.getExceptionBehavior() != - ConstrainedFPIntrinsic::ExceptionBehavior::ebIgnore) { + if (FPI.getExceptionBehavior() != fp::ExceptionBehavior::ebIgnore) { SDNodeFlags Flags; Flags.setFPExcept(true); Result->setFlags(Flags); diff --git a/llvm/lib/IR/CMakeLists.txt b/llvm/lib/IR/CMakeLists.txt index a9012637277..f53d536ca8e 100644 --- a/llvm/lib/IR/CMakeLists.txt +++ b/llvm/lib/IR/CMakeLists.txt @@ -22,6 +22,7 @@ add_llvm_library(LLVMCore DiagnosticInfo.cpp DiagnosticPrinter.cpp Dominators.cpp + FPEnv.cpp Function.cpp GVMaterializer.cpp Globals.cpp diff --git a/llvm/lib/IR/FPEnv.cpp b/llvm/lib/IR/FPEnv.cpp new file mode 100644 index 00000000000..00885265823 --- /dev/null +++ b/llvm/lib/IR/FPEnv.cpp @@ -0,0 +1,78 @@ +//===-- FPEnv.cpp ---- FP Environment -------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +/// @file +/// This file contains the implementations of entities that describe floating +/// point environment. +// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/StringSwitch.h" +#include "llvm/IR/FPEnv.h" + +namespace llvm { + +Optional<fp::RoundingMode> StrToRoundingMode(StringRef RoundingArg) { + // For dynamic rounding mode, we use round to nearest but we will set the + // 'exact' SDNodeFlag so that the value will not be rounded. + return StringSwitch<Optional<fp::RoundingMode>>(RoundingArg) + .Case("round.dynamic", fp::rmDynamic) + .Case("round.tonearest", fp::rmToNearest) + .Case("round.downward", fp::rmDownward) + .Case("round.upward", fp::rmUpward) + .Case("round.towardzero", fp::rmTowardZero) + .Default(None); +} + +Optional<StringRef> RoundingModeToStr(fp::RoundingMode UseRounding) { + Optional<StringRef> RoundingStr = None; + switch (UseRounding) { + case fp::rmDynamic: + RoundingStr = "round.dynamic"; + break; + case fp::rmToNearest: + RoundingStr = "round.tonearest"; + break; + case fp::rmDownward: + RoundingStr = "round.downward"; + break; + case fp::rmUpward: + RoundingStr = "round.upward"; + break; + case fp::rmTowardZero: + RoundingStr = "round.towardzero"; + break; + } + return RoundingStr; +} + +Optional<fp::ExceptionBehavior> StrToExceptionBehavior(StringRef ExceptionArg) { + return StringSwitch<Optional<fp::ExceptionBehavior>>(ExceptionArg) + .Case("fpexcept.ignore", fp::ebIgnore) + .Case("fpexcept.maytrap", fp::ebMayTrap) + .Case("fpexcept.strict", fp::ebStrict) + .Default(None); +} + +Optional<StringRef> ExceptionBehaviorToStr(fp::ExceptionBehavior UseExcept) { + Optional<StringRef> ExceptStr = None; + switch (UseExcept) { + case fp::ebStrict: + ExceptStr = "fpexcept.strict"; + break; + case fp::ebIgnore: + ExceptStr = "fpexcept.ignore"; + break; + case fp::ebMayTrap: + ExceptStr = "fpexcept.maytrap"; + break; + } + return ExceptStr; +} + +}
\ No newline at end of file diff --git a/llvm/lib/IR/IntrinsicInst.cpp b/llvm/lib/IR/IntrinsicInst.cpp index 19b01bd3196..12b1bf1dce0 100644 --- a/llvm/lib/IR/IntrinsicInst.cpp +++ b/llvm/lib/IR/IntrinsicInst.cpp @@ -102,8 +102,7 @@ Value *InstrProfIncrementInst::getStep() const { return ConstantInt::get(Type::getInt64Ty(Context), 1); } -Optional<ConstrainedFPIntrinsic::RoundingMode> -ConstrainedFPIntrinsic::getRoundingMode() const { +Optional<fp::RoundingMode> ConstrainedFPIntrinsic::getRoundingMode() const { unsigned NumOperands = getNumArgOperands(); Metadata *MD = cast<MetadataAsValue>(getArgOperand(NumOperands - 2))->getMetadata(); @@ -112,43 +111,7 @@ ConstrainedFPIntrinsic::getRoundingMode() const { return StrToRoundingMode(cast<MDString>(MD)->getString()); } -Optional<ConstrainedFPIntrinsic::RoundingMode> -ConstrainedFPIntrinsic::StrToRoundingMode(StringRef RoundingArg) { - // For dynamic rounding mode, we use round to nearest but we will set the - // 'exact' SDNodeFlag so that the value will not be rounded. - return StringSwitch<Optional<RoundingMode>>(RoundingArg) - .Case("round.dynamic", rmDynamic) - .Case("round.tonearest", rmToNearest) - .Case("round.downward", rmDownward) - .Case("round.upward", rmUpward) - .Case("round.towardzero", rmTowardZero) - .Default(None); -} - -Optional<StringRef> -ConstrainedFPIntrinsic::RoundingModeToStr(RoundingMode UseRounding) { - Optional<StringRef> RoundingStr = None; - switch (UseRounding) { - case ConstrainedFPIntrinsic::rmDynamic: - RoundingStr = "round.dynamic"; - break; - case ConstrainedFPIntrinsic::rmToNearest: - RoundingStr = "round.tonearest"; - break; - case ConstrainedFPIntrinsic::rmDownward: - RoundingStr = "round.downward"; - break; - case ConstrainedFPIntrinsic::rmUpward: - RoundingStr = "round.upward"; - break; - case ConstrainedFPIntrinsic::rmTowardZero: - RoundingStr = "round.towardzero"; - break; - } - return RoundingStr; -} - -Optional<ConstrainedFPIntrinsic::ExceptionBehavior> +Optional<fp::ExceptionBehavior> ConstrainedFPIntrinsic::getExceptionBehavior() const { unsigned NumOperands = getNumArgOperands(); Metadata *MD = @@ -158,32 +121,6 @@ ConstrainedFPIntrinsic::getExceptionBehavior() const { return StrToExceptionBehavior(cast<MDString>(MD)->getString()); } -Optional<ConstrainedFPIntrinsic::ExceptionBehavior> -ConstrainedFPIntrinsic::StrToExceptionBehavior(StringRef ExceptionArg) { - return StringSwitch<Optional<ExceptionBehavior>>(ExceptionArg) - .Case("fpexcept.ignore", ebIgnore) - .Case("fpexcept.maytrap", ebMayTrap) - .Case("fpexcept.strict", ebStrict) - .Default(None); -} - -Optional<StringRef> -ConstrainedFPIntrinsic::ExceptionBehaviorToStr(ExceptionBehavior UseExcept) { - Optional<StringRef> ExceptStr = None; - switch (UseExcept) { - case ConstrainedFPIntrinsic::ebStrict: - ExceptStr = "fpexcept.strict"; - break; - case ConstrainedFPIntrinsic::ebIgnore: - ExceptStr = "fpexcept.ignore"; - break; - case ConstrainedFPIntrinsic::ebMayTrap: - ExceptStr = "fpexcept.maytrap"; - break; - } - return ExceptStr; -} - bool ConstrainedFPIntrinsic::isUnaryOp() const { switch (getIntrinsicID()) { default: |

