1*480093f4SDimitry Andric //===-- FPEnv.cpp ---- FP Environment -------------------------------------===// 2*480093f4SDimitry Andric // 3*480093f4SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*480093f4SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*480093f4SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*480093f4SDimitry Andric // 7*480093f4SDimitry Andric //===----------------------------------------------------------------------===// 8*480093f4SDimitry Andric // 9*480093f4SDimitry Andric /// @file 10*480093f4SDimitry Andric /// This file contains the implementations of entities that describe floating 11*480093f4SDimitry Andric /// point environment. 12*480093f4SDimitry Andric // 13*480093f4SDimitry Andric //===----------------------------------------------------------------------===// 14*480093f4SDimitry Andric 15*480093f4SDimitry Andric #include "llvm/ADT/StringSwitch.h" 16*480093f4SDimitry Andric #include "llvm/IR/FPEnv.h" 17*480093f4SDimitry Andric 18*480093f4SDimitry Andric namespace llvm { 19*480093f4SDimitry Andric 20*480093f4SDimitry Andric Optional<fp::RoundingMode> StrToRoundingMode(StringRef RoundingArg) { 21*480093f4SDimitry Andric // For dynamic rounding mode, we use round to nearest but we will set the 22*480093f4SDimitry Andric // 'exact' SDNodeFlag so that the value will not be rounded. 23*480093f4SDimitry Andric return StringSwitch<Optional<fp::RoundingMode>>(RoundingArg) 24*480093f4SDimitry Andric .Case("round.dynamic", fp::rmDynamic) 25*480093f4SDimitry Andric .Case("round.tonearest", fp::rmToNearest) 26*480093f4SDimitry Andric .Case("round.downward", fp::rmDownward) 27*480093f4SDimitry Andric .Case("round.upward", fp::rmUpward) 28*480093f4SDimitry Andric .Case("round.towardzero", fp::rmTowardZero) 29*480093f4SDimitry Andric .Default(None); 30*480093f4SDimitry Andric } 31*480093f4SDimitry Andric 32*480093f4SDimitry Andric Optional<StringRef> RoundingModeToStr(fp::RoundingMode UseRounding) { 33*480093f4SDimitry Andric Optional<StringRef> RoundingStr = None; 34*480093f4SDimitry Andric switch (UseRounding) { 35*480093f4SDimitry Andric case fp::rmDynamic: 36*480093f4SDimitry Andric RoundingStr = "round.dynamic"; 37*480093f4SDimitry Andric break; 38*480093f4SDimitry Andric case fp::rmToNearest: 39*480093f4SDimitry Andric RoundingStr = "round.tonearest"; 40*480093f4SDimitry Andric break; 41*480093f4SDimitry Andric case fp::rmDownward: 42*480093f4SDimitry Andric RoundingStr = "round.downward"; 43*480093f4SDimitry Andric break; 44*480093f4SDimitry Andric case fp::rmUpward: 45*480093f4SDimitry Andric RoundingStr = "round.upward"; 46*480093f4SDimitry Andric break; 47*480093f4SDimitry Andric case fp::rmTowardZero: 48*480093f4SDimitry Andric RoundingStr = "round.towardzero"; 49*480093f4SDimitry Andric break; 50*480093f4SDimitry Andric } 51*480093f4SDimitry Andric return RoundingStr; 52*480093f4SDimitry Andric } 53*480093f4SDimitry Andric 54*480093f4SDimitry Andric Optional<fp::ExceptionBehavior> StrToExceptionBehavior(StringRef ExceptionArg) { 55*480093f4SDimitry Andric return StringSwitch<Optional<fp::ExceptionBehavior>>(ExceptionArg) 56*480093f4SDimitry Andric .Case("fpexcept.ignore", fp::ebIgnore) 57*480093f4SDimitry Andric .Case("fpexcept.maytrap", fp::ebMayTrap) 58*480093f4SDimitry Andric .Case("fpexcept.strict", fp::ebStrict) 59*480093f4SDimitry Andric .Default(None); 60*480093f4SDimitry Andric } 61*480093f4SDimitry Andric 62*480093f4SDimitry Andric Optional<StringRef> ExceptionBehaviorToStr(fp::ExceptionBehavior UseExcept) { 63*480093f4SDimitry Andric Optional<StringRef> ExceptStr = None; 64*480093f4SDimitry Andric switch (UseExcept) { 65*480093f4SDimitry Andric case fp::ebStrict: 66*480093f4SDimitry Andric ExceptStr = "fpexcept.strict"; 67*480093f4SDimitry Andric break; 68*480093f4SDimitry Andric case fp::ebIgnore: 69*480093f4SDimitry Andric ExceptStr = "fpexcept.ignore"; 70*480093f4SDimitry Andric break; 71*480093f4SDimitry Andric case fp::ebMayTrap: 72*480093f4SDimitry Andric ExceptStr = "fpexcept.maytrap"; 73*480093f4SDimitry Andric break; 74*480093f4SDimitry Andric } 75*480093f4SDimitry Andric return ExceptStr; 76*480093f4SDimitry Andric } 77*480093f4SDimitry Andric 78*480093f4SDimitry Andric }