1480093f4SDimitry Andric //===-- FPEnv.cpp ---- FP Environment -------------------------------------===// 2480093f4SDimitry Andric // 3480093f4SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4480093f4SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5480093f4SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6480093f4SDimitry Andric // 7480093f4SDimitry Andric //===----------------------------------------------------------------------===// 8480093f4SDimitry Andric // 9480093f4SDimitry Andric /// @file 10480093f4SDimitry Andric /// This file contains the implementations of entities that describe floating 11480093f4SDimitry Andric /// point environment. 12480093f4SDimitry Andric // 13480093f4SDimitry Andric //===----------------------------------------------------------------------===// 14480093f4SDimitry Andric 15480093f4SDimitry Andric #include "llvm/IR/FPEnv.h" 165ffd83dbSDimitry Andric #include "llvm/ADT/StringSwitch.h" 17480093f4SDimitry Andric 18480093f4SDimitry Andric namespace llvm { 19480093f4SDimitry Andric 20*349cc55cSDimitry Andric Optional<RoundingMode> convertStrToRoundingMode(StringRef RoundingArg) { 21480093f4SDimitry Andric // For dynamic rounding mode, we use round to nearest but we will set the 22480093f4SDimitry Andric // 'exact' SDNodeFlag so that the value will not be rounded. 235ffd83dbSDimitry Andric return StringSwitch<Optional<RoundingMode>>(RoundingArg) 245ffd83dbSDimitry Andric .Case("round.dynamic", RoundingMode::Dynamic) 255ffd83dbSDimitry Andric .Case("round.tonearest", RoundingMode::NearestTiesToEven) 265ffd83dbSDimitry Andric .Case("round.tonearestaway", RoundingMode::NearestTiesToAway) 275ffd83dbSDimitry Andric .Case("round.downward", RoundingMode::TowardNegative) 285ffd83dbSDimitry Andric .Case("round.upward", RoundingMode::TowardPositive) 295ffd83dbSDimitry Andric .Case("round.towardzero", RoundingMode::TowardZero) 30480093f4SDimitry Andric .Default(None); 31480093f4SDimitry Andric } 32480093f4SDimitry Andric 33*349cc55cSDimitry Andric Optional<StringRef> convertRoundingModeToStr(RoundingMode UseRounding) { 34480093f4SDimitry Andric Optional<StringRef> RoundingStr = None; 35480093f4SDimitry Andric switch (UseRounding) { 365ffd83dbSDimitry Andric case RoundingMode::Dynamic: 37480093f4SDimitry Andric RoundingStr = "round.dynamic"; 38480093f4SDimitry Andric break; 395ffd83dbSDimitry Andric case RoundingMode::NearestTiesToEven: 40480093f4SDimitry Andric RoundingStr = "round.tonearest"; 41480093f4SDimitry Andric break; 425ffd83dbSDimitry Andric case RoundingMode::NearestTiesToAway: 435ffd83dbSDimitry Andric RoundingStr = "round.tonearestaway"; 445ffd83dbSDimitry Andric break; 455ffd83dbSDimitry Andric case RoundingMode::TowardNegative: 46480093f4SDimitry Andric RoundingStr = "round.downward"; 47480093f4SDimitry Andric break; 485ffd83dbSDimitry Andric case RoundingMode::TowardPositive: 49480093f4SDimitry Andric RoundingStr = "round.upward"; 50480093f4SDimitry Andric break; 515ffd83dbSDimitry Andric case RoundingMode::TowardZero: 52480093f4SDimitry Andric RoundingStr = "round.towardzero"; 53480093f4SDimitry Andric break; 545ffd83dbSDimitry Andric default: 555ffd83dbSDimitry Andric break; 56480093f4SDimitry Andric } 57480093f4SDimitry Andric return RoundingStr; 58480093f4SDimitry Andric } 59480093f4SDimitry Andric 60*349cc55cSDimitry Andric Optional<fp::ExceptionBehavior> 61*349cc55cSDimitry Andric convertStrToExceptionBehavior(StringRef ExceptionArg) { 62480093f4SDimitry Andric return StringSwitch<Optional<fp::ExceptionBehavior>>(ExceptionArg) 63480093f4SDimitry Andric .Case("fpexcept.ignore", fp::ebIgnore) 64480093f4SDimitry Andric .Case("fpexcept.maytrap", fp::ebMayTrap) 65480093f4SDimitry Andric .Case("fpexcept.strict", fp::ebStrict) 66480093f4SDimitry Andric .Default(None); 67480093f4SDimitry Andric } 68480093f4SDimitry Andric 69*349cc55cSDimitry Andric Optional<StringRef> 70*349cc55cSDimitry Andric convertExceptionBehaviorToStr(fp::ExceptionBehavior UseExcept) { 71480093f4SDimitry Andric Optional<StringRef> ExceptStr = None; 72480093f4SDimitry Andric switch (UseExcept) { 73480093f4SDimitry Andric case fp::ebStrict: 74480093f4SDimitry Andric ExceptStr = "fpexcept.strict"; 75480093f4SDimitry Andric break; 76480093f4SDimitry Andric case fp::ebIgnore: 77480093f4SDimitry Andric ExceptStr = "fpexcept.ignore"; 78480093f4SDimitry Andric break; 79480093f4SDimitry Andric case fp::ebMayTrap: 80480093f4SDimitry Andric ExceptStr = "fpexcept.maytrap"; 81480093f4SDimitry Andric break; 82480093f4SDimitry Andric } 83480093f4SDimitry Andric return ExceptStr; 84480093f4SDimitry Andric } 855ffd83dbSDimitry Andric } // namespace llvm 86