[flang] Add -f[no-]signed-zeros

Only add the option processing and store the result. No attributes are
added to FIR yet.

Differential Revision: https://reviews.llvm.org/D137328
This commit is contained in:
Tom Eccles
2022-10-18 17:59:03 +00:00
parent 36b37a1ed5
commit b5b8a8cfbe
8 changed files with 26 additions and 1 deletions

View File

@@ -1902,7 +1902,7 @@ defm finite_math_only : BoolFOption<"finite-math-only",
NegFlag<SetFalse>>;
defm signed_zeros : BoolFOption<"signed-zeros",
LangOpts<"NoSignedZero">, DefaultFalse,
NegFlag<SetTrue, [CC1Option], "Allow optimizations that ignore the sign of floating point zeros",
NegFlag<SetTrue, [CC1Option, FC1Option, FlangOption], "Allow optimizations that ignore the sign of floating point zeros",
[cl_no_signed_zeros.KeyPath, funsafe_math_optimizations.KeyPath]>,
PosFlag<SetFalse>>;
def fhonor_nans : Flag<["-"], "fhonor-nans">, Group<f_Group>;

View File

@@ -86,6 +86,7 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
bool HonorINFs = true;
bool HonorNaNs = true;
bool ApproxFunc = false;
bool SignedZeros = true;
if (const Arg *A = Args.getLastArg(options::OPT_ffp_contract)) {
const StringRef Val = A->getValue();
@@ -129,6 +130,12 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
case options::OPT_fno_approx_func:
ApproxFunc = false;
break;
case options::OPT_fsigned_zeros:
SignedZeros = true;
break;
case options::OPT_fno_signed_zeros:
SignedZeros = false;
break;
}
// If we handled this option claim it
@@ -146,6 +153,9 @@ static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
if (ApproxFunc)
CmdArgs.push_back("-fapprox-func");
if (!SignedZeros)
CmdArgs.push_back("-fno-signed-zeros");
}
void Flang::ConstructJob(Compilation &C, const JobAction &JA,

View File

@@ -27,6 +27,8 @@ LANGOPT(NoHonorInfs, 1, false)
LANGOPT(NoHonorNaNs, 1, false)
/// Allow math functions to be replaced with an approximately equivalent calculation
LANGOPT(ApproxFunc, 1, false)
/// Allow optimizations that ignore the sign of floating point zeros
LANGOPT(NoSignedZeros, 1, false)
#undef LANGOPT
#undef ENUM_LANGOPT

View File

@@ -714,6 +714,12 @@ static bool parseFloatingPointArgs(CompilerInvocation &invoc,
opts.ApproxFunc = true;
}
if (const llvm::opt::Arg *a =
args.getLastArg(clang::driver::options::OPT_fno_signed_zeros)) {
diags.Report(diagUnimplemented) << a->getOption().getName();
opts.NoSignedZeros = true;
}
return true;
}

View File

@@ -45,6 +45,7 @@
! CHECK-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE
! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
! CHECK-NEXT: -fno-integrated-as Disable the integrated assembler
! CHECK-NEXT: -fno-signed-zeros Allow optimizations that ignore the sign of floating point zeros
! CHECK-NEXT: -fopenacc Enable OpenACC
! CHECK-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code.
! CHECK-NEXT: -fsyntax-only Run the preprocessor, parser and semantic analysis stages

View File

@@ -43,6 +43,7 @@
! HELP-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE
! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
! HELP-NEXT: -fno-integrated-as Disable the integrated assembler
! HELP-NEXT: -fno-signed-zeros Allow optimizations that ignore the sign of floating point zeros
! HELP-NEXT: -fopenacc Enable OpenACC
! HELP-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code.
! HELP-NEXT: -fsyntax-only Run the preprocessor, parser and semantic analysis stages
@@ -124,6 +125,7 @@
! HELP-FC1-NEXT: -fno-automatic Implies the SAVE attribute for non-automatic local objects in subprograms unless RECURSIVE
! HELP-FC1-NEXT: -fno-debug-pass-manager Disables debug printing for the new pass manager
! HELP-FC1-NEXT: -fno-reformat Dump the cooked character stream in -E mode
! HELP-FC1-NEXT: -fno-signed-zeros Allow optimizations that ignore the sign of floating point zeros
! HELP-FC1-NEXT: -fopenacc Enable OpenACC
! HELP-FC1-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code.
! HELP-FC1-NEXT: -fsyntax-only Run the preprocessor, parser and semantic analysis stages

View File

@@ -5,8 +5,10 @@
! RUN: -menable-no-infs \
! RUN: -menable-no-nans \
! RUN: -fapprox-func \
! RUN: -fno-signed-zeros \
! RUN: %s 2>&1 | FileCheck %s
! CHECK: ffp-contract= is not currently implemented
! CHECK: menable-no-infs is not currently implemented
! CHECK: menable-no-nans is not currently implemented
! CHECK: fapprox-func is not currently implemented
! CHECK: fno-signed-zeros is not currently implemented

View File

@@ -12,6 +12,7 @@
! RUN: -fno-honor-infinities \
! RUN: -fno-honor-nans \
! RUN: -fapprox-func \
! RUN: -fno-signed-zeros \
! RUN: -mllvm -print-before-all\
! RUN: -P \
! RUN: | FileCheck %s
@@ -26,5 +27,6 @@
! CHECK: "-menable-no-infs"
! CHECK: "-menable-no-nans"
! CHECK: "-fapprox-func"
! CHECK: "-fno-signed-zeros"
! CHECK: "-fconvert=little-endian"
! CHECK: "-mllvm" "-print-before-all"