//===-- 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/IR/FPEnv.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Intrinsics.h" #include using namespace llvm; std::optional llvm::convertStrToRoundingMode(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>(RoundingArg) .Case("round.dynamic", RoundingMode::Dynamic) .Case("round.tonearest", RoundingMode::NearestTiesToEven) .Case("round.tonearestaway", RoundingMode::NearestTiesToAway) .Case("round.downward", RoundingMode::TowardNegative) .Case("round.upward", RoundingMode::TowardPositive) .Case("round.towardzero", RoundingMode::TowardZero) .Default(std::nullopt); } std::optional llvm::convertRoundingModeToStr(RoundingMode UseRounding) { switch (UseRounding) { case RoundingMode::Dynamic: return "round.dynamic"; case RoundingMode::NearestTiesToEven: return "round.tonearest"; case RoundingMode::NearestTiesToAway: return "round.tonearestaway"; case RoundingMode::TowardNegative: return "round.downward"; case RoundingMode::TowardPositive: return "round.upward"; case RoundingMode::TowardZero: return "round.towardzero"; default: return std::nullopt; } } std::optional llvm::convertStrToExceptionBehavior(StringRef ExceptionArg) { return StringSwitch>(ExceptionArg) .Case("fpexcept.ignore", fp::ebIgnore) .Case("fpexcept.maytrap", fp::ebMayTrap) .Case("fpexcept.strict", fp::ebStrict) .Default(std::nullopt); } std::optional llvm::convertExceptionBehaviorToStr(fp::ExceptionBehavior UseExcept) { switch (UseExcept) { case fp::ebStrict: return "fpexcept.strict"; case fp::ebIgnore: return "fpexcept.ignore"; case fp::ebMayTrap: return "fpexcept.maytrap"; } return std::nullopt; } Intrinsic::ID llvm::getConstrainedIntrinsicID(const Instruction &Instr) { Intrinsic::ID IID = Intrinsic::not_intrinsic; switch (Instr.getOpcode()) { case Instruction::FCmp: // Unlike other instructions FCmp can be mapped to one of two intrinsic // functions. We choose the non-signaling variant. IID = Intrinsic::experimental_constrained_fcmp; break; // Instructions #define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \ case Instruction::NAME: \ IID = Intrinsic::INTRINSIC; \ break; #define FUNCTION(NAME, NARG, ROUND_MODE, INTRINSIC) #define CMP_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) #include "llvm/IR/ConstrainedOps.def" // Intrinsic calls. case Instruction::Call: if (auto *IntrinCall = dyn_cast(&Instr)) { switch (IntrinCall->getIntrinsicID()) { #define FUNCTION(NAME, NARG, ROUND_MODE, INTRINSIC) \ case Intrinsic::NAME: \ IID = Intrinsic::INTRINSIC; \ break; #define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC) #define CMP_INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) #include "llvm/IR/ConstrainedOps.def" default: break; } } break; default: break; } return IID; }