Skip to content

Commit

Permalink
Revert "[CLANG][PATCH][FPEnv] Add support for option -ffp-eval-method…
Browse files Browse the repository at this point in the history
… and extend #pragma float_control similarly"

This reverts commit ce8024e.
There are a couple buildbot problems
  • Loading branch information
Melanie Blower committed Jul 20, 2021
1 parent edfdb5f commit d48ad35
Show file tree
Hide file tree
Showing 32 changed files with 87 additions and 648 deletions.
25 changes: 2 additions & 23 deletions clang/docs/LanguageExtensions.rst
Expand Up @@ -3552,7 +3552,7 @@ same spelling and syntax. For pragmas specified at file scope, a stack
is supported so that the ``pragma float_control`` settings can be pushed or popped.
When ``pragma float_control(precise, on)`` is enabled, the section of code
governed by the pragma uses precise floating-point semantics, effectively
governed by the pragma uses precise floating point semantics, effectively
``-ffast-math`` is disabled and ``-ffp-contract=on``
(fused multiply add) is enabled.
Expand All @@ -3563,29 +3563,8 @@ when ``pragma float_control(precise, off)`` is enabled, the section of code
governed by the pragma behaves as though the command-line option
``-ffp-exception-behavior=ignore`` is enabled.
When ``pragma float_control(source, on)`` is enabled, the section of code governed
by the pragma behaves as though the command-line option
``-ffp-eval-method=source`` is enabled. Note: The default
floating-point evaluation method is target-specific, typically ``source``.
When ``pragma float_control(double, on)`` is enabled, the section of code governed
by the pragma behaves as though the command-line option
``-ffp-eval-method=double`` is enabled.
When ``pragma float_control(extended, on)`` is enabled, the section of code governed
by the pragma behaves as though the command-line option
``-ffp-eval-method=extended`` is enabled.
When ``pragma float_control(source, off)`` or
``pragma float_control(double, off)`` or
``pragma float_control(extended, off)`` is enabled,
the section of code governed
by the pragma behaves as though the command-line option
``-ffp-eval-method=source`` is enabled, returning floating-point evaluation
method to the default setting.
The full syntax this pragma supports is
``float_control(except|precise|source|double|extended, on|off [, push])`` and
``float_control(except|precise, on|off [, push])`` and
``float_control(push|pop)``.
The ``push`` and ``pop`` forms, including using ``push`` as the optional
third argument, can only occur at file scope.
Expand Down
11 changes: 0 additions & 11 deletions clang/docs/UsersManual.rst
Expand Up @@ -1478,17 +1478,6 @@ Note that floating-point operations performed as part of constant initialization
* ``maytrap`` The compiler avoids transformations that may raise exceptions that would not have been raised by the original code. Constant folding performed by the compiler is exempt from this option.
* ``strict`` The compiler ensures that all transformations strictly preserve the floating point exception semantics of the original code.

.. option:: -ffp-eval-method=<value>

Specify the floating-point evaluation method.

Valid values are: ``source``, ``double``, and ``extended``.
The default value is target-specific, typically ``source``. Details:

* ``source`` The compiler uses the floating-point type declared in the source program as the evaluation method.
* ``double`` The compiler uses ``double`` as the floating-point evaluation method for all float expressions of type that is narrower than ``double``.
* ``extended`` The compiler uses ``long double`` as the floating-point evaluation method for all float expressions of type that is narrower than ``long double``.

.. option:: -f[no-]protect-parens:

This option pertains to floating-point types, complex types with
Expand Down
1 change: 0 additions & 1 deletion clang/include/clang/Basic/FPOptions.def
Expand Up @@ -23,5 +23,4 @@ OPTION(NoHonorInfs, bool, 1, NoHonorNaNs)
OPTION(NoSignedZero, bool, 1, NoHonorInfs)
OPTION(AllowReciprocal, bool, 1, NoSignedZero)
OPTION(AllowApproxFunc, bool, 1, AllowReciprocal)
OPTION(FPEvalMethod, LangOptions::FPEvalMethodKind, 2, AllowApproxFunc)
#undef OPTION
1 change: 0 additions & 1 deletion clang/include/clang/Basic/LangOptions.def
Expand Up @@ -295,7 +295,6 @@ BENIGN_ENUM_LANGOPT(DefaultFPContractMode, FPModeKind, 2, FPM_Off, "FP contracti
COMPATIBLE_LANGOPT(ExpStrictFP, 1, false, "Enable experimental strict floating point")
BENIGN_ENUM_LANGOPT(FPRoundingMode, RoundingMode, 3, RoundingMode::NearestTiesToEven, "FP Rounding Mode type")
BENIGN_ENUM_LANGOPT(FPExceptionMode, FPExceptionModeKind, 2, FPE_Ignore, "FP Exception Behavior Mode type")
BENIGN_ENUM_LANGOPT(FPEvalMethod, FPEvalMethodKind, 2, FEM_TargetDefault, "FP type used for floating point arithmetic")
LANGOPT(NoBitFieldTypeAlign , 1, 0, "bit-field type alignment")
LANGOPT(HexagonQdsp6Compat , 1, 0, "hexagon-qdsp6 backward compatibility")
LANGOPT(ObjCAutoRefCount , 1, 0, "Objective-C automated reference counting")
Expand Down
14 changes: 0 additions & 14 deletions clang/include/clang/Basic/LangOptions.h
Expand Up @@ -233,19 +233,6 @@ class LangOptions : public LangOptionsBase {
/// Possible exception handling behavior.
enum class ExceptionHandlingKind { None, SjLj, WinEH, DwarfCFI, Wasm };

/// Possible float expression evaluation method choices.
enum FPEvalMethodKind {
/// Use the declared type for fp arithmetic.
FEM_Source,
/// Use the type double for fp arithmetic.
FEM_Double,
/// Use extended type for fp arithmetic.
FEM_Extended,
/// Use the default float eval method specified by Target:
// most targets are defined with evaluation method FEM_Source.
FEM_TargetDefault
};

enum class LaxVectorConversionKind {
/// Permit no implicit vector bitcasts.
None,
Expand Down Expand Up @@ -537,7 +524,6 @@ class FPOptions {
setAllowFEnvAccess(true);
else
setAllowFEnvAccess(LangOptions::FPM_Off);
setFPEvalMethod(LO.getFPEvalMethod());
}

bool allowFPContractWithinStatement() const {
Expand Down
5 changes: 1 addition & 4 deletions clang/include/clang/Basic/PragmaKinds.h
Expand Up @@ -32,10 +32,7 @@ enum PragmaFloatControlKind {
PFC_Except, // #pragma float_control(except [,on])
PFC_NoExcept, // #pragma float_control(except, off)
PFC_Push, // #pragma float_control(push)
PFC_Pop, // #pragma float_control(pop)
PFC_Source, // #pragma float_control(source, {on|off} [,push])
PFC_Double, // #pragma float_control(double, {on|off} [,push])
PFC_Extended, // #pragma float_control(extended, {on|off} [,push])
PFC_Pop // #pragma float_control(pop)
};
}

Expand Down
3 changes: 1 addition & 2 deletions clang/include/clang/Basic/TargetInfo.h
Expand Up @@ -687,8 +687,7 @@ class TargetInfo : public virtual TransferrableTargetInfo,
}

/// Return the value for the C99 FLT_EVAL_METHOD macro.
// Note: implementation defined values may be negative.
virtual int getFPEvalMethod() const { return 0; }
virtual unsigned getFloatEvalMethod() const { return 0; }

// getLargeArrayMinWidth/Align - Return the minimum array size that is
// 'large' and its alignment.
Expand Down
5 changes: 0 additions & 5 deletions clang/include/clang/Driver/Options.td
Expand Up @@ -1434,11 +1434,6 @@ def : Flag<["-"], "fextended-identifiers">, Group<clang_ignored_f_Group>;
def : Flag<["-"], "fno-extended-identifiers">, Group<f_Group>, Flags<[Unsupported]>;
def fhosted : Flag<["-"], "fhosted">, Group<f_Group>;
def fdenormal_fp_math_EQ : Joined<["-"], "fdenormal-fp-math=">, Group<f_Group>, Flags<[CC1Option]>;
def ffp_eval_method_EQ : Joined<["-"], "ffp-eval-method=">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Specifies the evaluation method to use for floating-point arithmetic.">,
Values<"source,double,extended">, NormalizedValuesScope<"LangOptions">,
NormalizedValues<["FEM_Source", "FEM_Double", "FEM_Extended"]>,
MarshallingInfoEnum<LangOpts<"FPEvalMethod">, "FEM_TargetDefault">;
def ffp_model_EQ : Joined<["-"], "ffp-model=">, Group<f_Group>, Flags<[NoXarchOption]>,
HelpText<"Controls the semantics of floating-point calculations.">;
def ffp_exception_behavior_EQ : Joined<["-"], "ffp-exception-behavior=">, Group<f_Group>, Flags<[CC1Option]>,
Expand Down
7 changes: 0 additions & 7 deletions clang/include/clang/Lex/Preprocessor.h
Expand Up @@ -178,17 +178,12 @@ class Preprocessor {
IdentifierInfo *Ident__is_target_vendor; // __is_target_vendor
IdentifierInfo *Ident__is_target_os; // __is_target_os
IdentifierInfo *Ident__is_target_environment; // __is_target_environment
IdentifierInfo *Ident__FLT_EVAL_METHOD__ = nullptr; // __FLT_EVAL_METHOD__

// Weak, only valid (and set) while InMacroArgs is true.
Token* ArgMacro;

SourceLocation DATELoc, TIMELoc;

// Corresponding to __FLT_EVAL_METHOD__. Initialized from TargetInfo
// or the command line. Implementation-defined values can be negative.
int CurrentFPEvalMethod = 0;

// Next __COUNTER__ value, starts at 0.
unsigned CounterValue = 0;

Expand Down Expand Up @@ -1993,8 +1988,6 @@ class Preprocessor {
}
unsigned getCounterValue() const { return CounterValue; }
void setCounterValue(unsigned V) { CounterValue = V; }
int getCurrentFPEvalMethod() const { return CurrentFPEvalMethod; }
void setCurrentFPEvalMethod(int V) { CurrentFPEvalMethod = V; }

/// Retrieves the module that we're currently building, if any.
Module *getCurrentModule();
Expand Down
4 changes: 0 additions & 4 deletions clang/include/clang/Lex/PreprocessorOptions.h
Expand Up @@ -146,9 +146,6 @@ class PreprocessorOptions {
/// When enabled, the preprocessor will construct editor placeholder tokens.
bool LexEditorPlaceholders = true;

/// When enabled, the preprocessor will expand special builtin macros.
bool LexExpandSpecialBuiltins = true;

/// True if the SourceManager should report the original file name for
/// contents of files that were remapped to other files. Defaults to true.
bool RemappedFilesKeepOriginalName = true;
Expand Down Expand Up @@ -252,7 +249,6 @@ class PreprocessorOptions {
ImplicitPCHInclude.clear();
SingleFileParseMode = false;
LexEditorPlaceholders = true;
LexExpandSpecialBuiltins = true;
RetainRemappedFileBuffers = true;
PrecompiledPreambleBytes.first = 0;
PrecompiledPreambleBytes.second = false;
Expand Down
10 changes: 7 additions & 3 deletions clang/include/clang/Sema/Sema.h
Expand Up @@ -1501,15 +1501,19 @@ class Sema final {
/// statements.
class FPFeaturesStateRAII {
public:
FPFeaturesStateRAII(Sema &S);
~FPFeaturesStateRAII();
FPFeaturesStateRAII(Sema &S) : S(S), OldFPFeaturesState(S.CurFPFeatures) {
OldOverrides = S.FpPragmaStack.CurrentValue;
}
~FPFeaturesStateRAII() {
S.CurFPFeatures = OldFPFeaturesState;
S.FpPragmaStack.CurrentValue = OldOverrides;
}
FPOptionsOverride getOverrides() { return OldOverrides; }

private:
Sema& S;
FPOptions OldFPFeaturesState;
FPOptionsOverride OldOverrides;
int OldEvalMethod;
};

void addImplicitTypedef(StringRef Name, QualType T);
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Basic/Targets/OSTargets.h
Expand Up @@ -735,7 +735,7 @@ class AIXTargetInfo : public OSTargetInfo<Target> {
}

// AIX sets FLT_EVAL_METHOD to be 1.
int getFPEvalMethod() const override { return 1; }
unsigned getFloatEvalMethod() const override { return 1; }
bool hasInt128Type() const override { return false; }

bool defaultsToAIXPowerAlignment() const override { return true; }
Expand Down
6 changes: 3 additions & 3 deletions clang/lib/Basic/Targets/X86.h
Expand Up @@ -165,7 +165,7 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public TargetInfo {
return LongDoubleFormat == &llvm::APFloat::IEEEquad() ? "g" : "e";
}

int getFPEvalMethod() const override {
unsigned getFloatEvalMethod() const override {
// X87 evaluates with 80 bits "long double" precision.
return SSELevel == NoSSE ? 2 : 0;
}
Expand Down Expand Up @@ -468,12 +468,12 @@ class LLVM_LIBRARY_VISIBILITY NetBSDI386TargetInfo
NetBSDI386TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
: NetBSDTargetInfo<X86_32TargetInfo>(Triple, Opts) {}

int getFPEvalMethod() const override {
unsigned getFloatEvalMethod() const override {
unsigned Major, Minor, Micro;
getTriple().getOSVersion(Major, Minor, Micro);
// New NetBSD uses the default rounding mode.
if (Major >= 7 || (Major == 6 && Minor == 99 && Micro >= 26) || Major == 0)
return X86_32TargetInfo::getFPEvalMethod();
return X86_32TargetInfo::getFloatEvalMethod();
// NetBSD before 6.99.26 defaults to "double" rounding.
return 1;
}
Expand Down
17 changes: 0 additions & 17 deletions clang/lib/Driver/ToolChains/Clang.cpp
Expand Up @@ -2630,8 +2630,6 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
StringRef FPModel = "";
// -ffp-exception-behavior options: strict, maytrap, ignore
StringRef FPExceptionBehavior = "";
// -ffp-eval-method options: double, extended, source
StringRef FPEvalMethod = "";
const llvm::DenormalMode DefaultDenormalFPMath =
TC.getDefaultDenormalModeForType(Args, JA);
const llvm::DenormalMode DefaultDenormalFP32Math =
Expand Down Expand Up @@ -2823,18 +2821,6 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
break;
}

// Validate and pass through -ffp-eval-method option.
case options::OPT_ffp_eval_method_EQ: {
StringRef Val = A->getValue();
if (Val.equals("double") || Val.equals("extended") ||
Val.equals("source"))
FPEvalMethod = Val;
else
D.Diag(diag::err_drv_unsupported_option_argument)
<< A->getOption().getName() << Val;
break;
}

case options::OPT_ffinite_math_only:
HonorINFs = false;
HonorNaNs = false;
Expand Down Expand Up @@ -2979,9 +2965,6 @@ static void RenderFloatingPointOptions(const ToolChain &TC, const Driver &D,
CmdArgs.push_back(Args.MakeArgString("-ffp-exception-behavior=" +
FPExceptionBehavior));

if (!FPEvalMethod.empty())
CmdArgs.push_back(Args.MakeArgString("-ffp-eval-method=" + FPEvalMethod));

ParseMRecip(D, Args, CmdArgs);

// -ffast-math enables the __FAST_MATH__ preprocessor macro, but check for the
Expand Down
7 changes: 1 addition & 6 deletions clang/lib/Frontend/CompilerInvocation.cpp
Expand Up @@ -4239,13 +4239,8 @@ static bool ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args,
// Always avoid lexing editor placeholders when we're just running the
// preprocessor as we never want to emit the
// "editor placeholder in source file" error in PP only mode.
// Certain predefined macros which depend upon semantic processing,
// for example __FLT_EVAL_METHOD__, are not expanded in PP mode, they
// appear in the preprocessed output as an unexpanded macro name.
if (isStrictlyPreprocessorAction(Action)) {
if (isStrictlyPreprocessorAction(Action))
Opts.LexEditorPlaceholders = false;
Opts.LexExpandSpecialBuiltins = false;
}

return Diags.getNumErrors() == NumErrorsBefore;
}
Expand Down
3 changes: 1 addition & 2 deletions clang/lib/Frontend/InitPreprocessor.cpp
Expand Up @@ -1078,8 +1078,7 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
}

// Macros to control C99 numerics and <float.h>
// Note: __FLT_EVAL_METHOD__ is not defined here since it is a special
// builtin macro, its value may fluctuate during compilation.
Builder.defineMacro("__FLT_EVAL_METHOD__", Twine(TI.getFloatEvalMethod()));
Builder.defineMacro("__FLT_RADIX__", "2");
Builder.defineMacro("__DECIMAL_DIG__", "__LDBL_DECIMAL_DIG__");

Expand Down
15 changes: 4 additions & 11 deletions clang/lib/Lex/PPMacroExpansion.cpp
Expand Up @@ -345,11 +345,6 @@ void Preprocessor::RegisterBuiltinMacros() {
Ident__TIME__ = RegisterBuiltinMacro(*this, "__TIME__");
Ident__COUNTER__ = RegisterBuiltinMacro(*this, "__COUNTER__");
Ident_Pragma = RegisterBuiltinMacro(*this, "_Pragma");
if (PPOpts->LexExpandSpecialBuiltins)
// Suppress macro expansion if compiler stops before semantic analysis,
// the macro identifier will appear in the preprocessed output.
Ident__FLT_EVAL_METHOD__ =
RegisterBuiltinMacro(*this, "__FLT_EVAL_METHOD__");

// C++ Standing Document Extensions.
if (getLangOpts().CPlusPlus)
Expand Down Expand Up @@ -1612,10 +1607,6 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
// Surround the string with " and strip the trailing newline.
OS << '"' << StringRef(Result).drop_back() << '"';
Tok.setKind(tok::string_literal);
} else if (II == Ident__FLT_EVAL_METHOD__) {
// __FLT_EVAL_METHOD__ expands to a simple numeric value.
OS << getCurrentFPEvalMethod();
Tok.setKind(tok::numeric_constant);
} else if (II == Ident__COUNTER__) {
// __COUNTER__ expands to a simple numeric value.
OS << CounterValue++;
Expand Down Expand Up @@ -1713,7 +1704,8 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {

return false;
});
} else if (II == Ident__has_cpp_attribute || II == Ident__has_c_attribute) {
} else if (II == Ident__has_cpp_attribute ||
II == Ident__has_c_attribute) {
bool IsCXX = II == Ident__has_cpp_attribute;
EvaluateFeatureLikeBuiltinMacro(
OS, Tok, II, *this, [&](Token &Tok, bool &HasLexedNextToken) -> int {
Expand All @@ -1740,7 +1732,8 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
getLangOpts())
: 0;
});
} else if (II == Ident__has_include || II == Ident__has_include_next) {
} else if (II == Ident__has_include ||
II == Ident__has_include_next) {
// The argument to these two builtins should be a parenthesized
// file name string literal using angle brackets (<>) or
// double-quotes ("").
Expand Down

0 comments on commit d48ad35

Please sign in to comment.