#define LLVM_IR_FPENV_H
#include "llvm/ADT/FloatingPointMode.h"
-#include "llvm/ADT/Optional.h"
#include "llvm/IR/FMF.h"
+#include <optional>
namespace llvm {
class StringRef;
/// Returns a valid RoundingMode enumerator when given a string
/// that is valid as input in constrained intrinsic rounding mode
/// metadata.
-Optional<RoundingMode> convertStrToRoundingMode(StringRef);
+std::optional<RoundingMode> convertStrToRoundingMode(StringRef);
/// For any RoundingMode enumerator, returns a string valid as input in
/// constrained intrinsic rounding mode metadata.
-Optional<StringRef> convertRoundingModeToStr(RoundingMode);
+std::optional<StringRef> convertRoundingModeToStr(RoundingMode);
/// Returns a valid ExceptionBehavior enumerator when given a string
/// valid as input in constrained intrinsic exception behavior metadata.
-Optional<fp::ExceptionBehavior> convertStrToExceptionBehavior(StringRef);
+std::optional<fp::ExceptionBehavior> convertStrToExceptionBehavior(StringRef);
/// For any ExceptionBehavior enumerator, returns a string valid as
/// input in constrained intrinsic exception behavior metadata.
-Optional<StringRef> convertExceptionBehaviorToStr(fp::ExceptionBehavior);
+std::optional<StringRef> convertExceptionBehaviorToStr(fp::ExceptionBehavior);
/// Returns true if the exception handling behavior and rounding mode
/// match what is used in the default floating point environment.
#include <cassert>
#include <cstdint>
#include <functional>
+#include <optional>
#include <utility>
namespace llvm {
/// Set the exception handling to be used with constrained floating point
void setDefaultConstrainedExcept(fp::ExceptionBehavior NewExcept) {
#ifndef NDEBUG
- Optional<StringRef> ExceptStr = convertExceptionBehaviorToStr(NewExcept);
+ std::optional<StringRef> ExceptStr =
+ convertExceptionBehaviorToStr(NewExcept);
assert(ExceptStr && "Garbage strict exception behavior!");
#endif
DefaultConstrainedExcept = NewExcept;
/// Set the rounding mode handling to be used with constrained floating point
void setDefaultConstrainedRounding(RoundingMode NewRounding) {
#ifndef NDEBUG
- Optional<StringRef> RoundingStr = convertRoundingModeToStr(NewRounding);
+ std::optional<StringRef> RoundingStr =
+ convertRoundingModeToStr(NewRounding);
assert(RoundingStr && "Garbage strict rounding mode!");
#endif
DefaultConstrainedRounding = NewRounding;
if (Rounding)
UseRounding = Rounding.value();
- Optional<StringRef> RoundingStr = convertRoundingModeToStr(UseRounding);
+ std::optional<StringRef> RoundingStr =
+ convertRoundingModeToStr(UseRounding);
assert(RoundingStr && "Garbage strict rounding mode!");
auto *RoundingMDS = MDString::get(Context, RoundingStr.value());
if (Except)
UseExcept = Except.value();
- Optional<StringRef> ExceptStr = convertExceptionBehaviorToStr(UseExcept);
+ std::optional<StringRef> ExceptStr =
+ convertExceptionBehaviorToStr(UseExcept);
assert(ExceptStr && "Garbage strict exception behavior!");
auto *ExceptMDS = MDString::get(Context, ExceptStr.value());
#include "llvm/Support/Casting.h"
#include <cassert>
#include <cstdint>
+#include <optional>
namespace llvm {
public:
bool isUnaryOp() const;
bool isTernaryOp() const;
- Optional<RoundingMode> getRoundingMode() const;
- Optional<fp::ExceptionBehavior> getExceptionBehavior() const;
+ std::optional<RoundingMode> getRoundingMode() const;
+ std::optional<fp::ExceptionBehavior> getExceptionBehavior() const;
bool isDefaultFPEnvironment() const;
// Methods for support type inquiry through isa, cast, and dyn_cast:
/// \param St Exception flags raised during constant evaluation.
static bool mayFoldConstrained(ConstrainedFPIntrinsic *CI,
APFloat::opStatus St) {
- Optional<RoundingMode> ORM = CI->getRoundingMode();
- Optional<fp::ExceptionBehavior> EB = CI->getExceptionBehavior();
+ std::optional<RoundingMode> ORM = CI->getRoundingMode();
+ std::optional<fp::ExceptionBehavior> EB = CI->getExceptionBehavior();
// If the operation does not change exception status flags, it is safe
// to fold.
/// Returns the rounding mode that should be used for constant evaluation.
static RoundingMode
getEvaluationRoundingMode(const ConstrainedFPIntrinsic *CI) {
- Optional<RoundingMode> ORM = CI->getRoundingMode();
+ std::optional<RoundingMode> ORM = CI->getRoundingMode();
if (!ORM || *ORM == RoundingMode::Dynamic)
// Even if the rounding mode is unknown, try evaluating the operation.
// If it does not raise inexact exception, rounding was not applied,
// Rounding operations (floor, trunc, ceil, round and nearbyint) do not
// raise FP exceptions, unless the argument is signaling NaN.
- Optional<APFloat::roundingMode> RM;
+ std::optional<APFloat::roundingMode> RM;
switch (IntrinsicID) {
default:
break;
APFloat::opStatus St = U.roundToIntegral(*RM);
if (IntrinsicID == Intrinsic::experimental_constrained_rint &&
St == APFloat::opInexact) {
- Optional<fp::ExceptionBehavior> EB = CI->getExceptionBehavior();
+ std::optional<fp::ExceptionBehavior> EB = CI->getExceptionBehavior();
if (EB && *EB == fp::ebStrict)
return nullptr;
}
} else if (U.isSignaling()) {
- Optional<fp::ExceptionBehavior> EB = CI->getExceptionBehavior();
+ std::optional<fp::ExceptionBehavior> EB = CI->getExceptionBehavior();
if (EB && *EB != fp::ebIgnore)
return nullptr;
U = APFloat::getQNaN(U.getSemantics());
#include <cassert>
#include <cstdint>
#include <iterator>
+#include <optional>
#include <string>
#include <utility>
#include <vector>
// Convert the metadata argument to a constant integer
Metadata *MD = cast<MetadataAsValue>(CI.getArgOperand(1))->getMetadata();
- Optional<RoundingMode> RoundMode =
+ std::optional<RoundingMode> RoundMode =
convertStrToRoundingMode(cast<MDString>(MD)->getString());
// Add the Rounding mode as an integer
// Get the last argument, the metadata and convert it to an integer in the
// call
Metadata *MD = cast<MetadataAsValue>(I.getArgOperand(1))->getMetadata();
- Optional<RoundingMode> RoundMode =
+ std::optional<RoundingMode> RoundMode =
convertStrToRoundingMode(cast<MDString>(MD)->getString());
EVT VT = TLI.getValueType(DAG.getDataLayout(), I.getType());
#include "llvm/IR/Instruction.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h"
+#include <optional>
namespace llvm {
-Optional<RoundingMode> convertStrToRoundingMode(StringRef RoundingArg) {
+std::optional<RoundingMode> 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<Optional<RoundingMode>>(RoundingArg)
+ return StringSwitch<std::optional<RoundingMode>>(RoundingArg)
.Case("round.dynamic", RoundingMode::Dynamic)
.Case("round.tonearest", RoundingMode::NearestTiesToEven)
.Case("round.tonearestaway", RoundingMode::NearestTiesToAway)
.Default(std::nullopt);
}
-Optional<StringRef> convertRoundingModeToStr(RoundingMode UseRounding) {
- Optional<StringRef> RoundingStr;
+std::optional<StringRef> convertRoundingModeToStr(RoundingMode UseRounding) {
+ std::optional<StringRef> RoundingStr;
switch (UseRounding) {
case RoundingMode::Dynamic:
RoundingStr = "round.dynamic";
return RoundingStr;
}
-Optional<fp::ExceptionBehavior>
+std::optional<fp::ExceptionBehavior>
convertStrToExceptionBehavior(StringRef ExceptionArg) {
- return StringSwitch<Optional<fp::ExceptionBehavior>>(ExceptionArg)
+ return StringSwitch<std::optional<fp::ExceptionBehavior>>(ExceptionArg)
.Case("fpexcept.ignore", fp::ebIgnore)
.Case("fpexcept.maytrap", fp::ebMayTrap)
.Case("fpexcept.strict", fp::ebStrict)
.Default(std::nullopt);
}
-Optional<StringRef>
+std::optional<StringRef>
convertExceptionBehaviorToStr(fp::ExceptionBehavior UseExcept) {
- Optional<StringRef> ExceptStr;
+ std::optional<StringRef> ExceptStr;
switch (UseExcept) {
case fp::ebStrict:
ExceptStr = "fpexcept.strict";
return ConstantInt::get(Type::getInt64Ty(Context), 1);
}
-Optional<RoundingMode> ConstrainedFPIntrinsic::getRoundingMode() const {
+std::optional<RoundingMode> ConstrainedFPIntrinsic::getRoundingMode() const {
unsigned NumOperands = arg_size();
Metadata *MD = nullptr;
auto *MAV = dyn_cast<MetadataAsValue>(getArgOperand(NumOperands - 2));
return convertStrToRoundingMode(cast<MDString>(MD)->getString());
}
-Optional<fp::ExceptionBehavior>
+std::optional<fp::ExceptionBehavior>
ConstrainedFPIntrinsic::getExceptionBehavior() const {
unsigned NumOperands = arg_size();
Metadata *MD = nullptr;
}
bool ConstrainedFPIntrinsic::isDefaultFPEnvironment() const {
- Optional<fp::ExceptionBehavior> Except = getExceptionBehavior();
+ std::optional<fp::ExceptionBehavior> Except = getExceptionBehavior();
if (Except) {
if (Except.value() != fp::ebIgnore)
return false;
}
- Optional<RoundingMode> Rounding = getRoundingMode();
+ std::optional<RoundingMode> Rounding = getRoundingMode();
if (Rounding) {
if (Rounding.value() != RoundingMode::NearestTiesToEven)
return false;
" (the operand should be a string)"),
MD);
- Optional<RoundingMode> RoundMode =
+ std::optional<RoundingMode> RoundMode =
convertStrToRoundingMode(cast<MDString>(MD)->getString());
Check(RoundMode && *RoundMode != RoundingMode::Dynamic,
"unsupported rounding mode argument", Call);
}
if (auto *FPI = dyn_cast<ConstrainedFPIntrinsic>(I)) {
- Optional<fp::ExceptionBehavior> ExBehavior = FPI->getExceptionBehavior();
+ std::optional<fp::ExceptionBehavior> ExBehavior =
+ FPI->getExceptionBehavior();
return *ExBehavior != fp::ebStrict;
}
}