forked from OSchip/llvm-project
[flang][driver] Add options for -fdefault* and -flarge-sizes
Add support for the following Fortran dialect options: - -default* - -flarge-sizes It also adds two test cases: # For checking whether `flang-new` is passing options correctly to `flang-new -fc1`. # For checking if `fdefault-` arguments are processed properly. Also moves the Dialect related option parsing to a dedicated function and adds a member `defaultKinds()` to `CompilerInvocation` Depends on: D96032 Differential Revision: https://reviews.llvm.org/D96344
This commit is contained in:
parent
a1155ae64d
commit
ab971c29a5
|
@ -4238,9 +4238,6 @@ defm check_array_temporaries : BooleanFFlag<"check-array-temporaries">, Group<gf
|
|||
defm cray_pointer : BooleanFFlag<"cray-pointer">, Group<gfortran_Group>;
|
||||
defm d_lines_as_code : BooleanFFlag<"d-lines-as-code">, Group<gfortran_Group>;
|
||||
defm d_lines_as_comments : BooleanFFlag<"d-lines-as-comments">, Group<gfortran_Group>;
|
||||
defm default_double_8 : BooleanFFlag<"default-double-8">, Group<gfortran_Group>;
|
||||
defm default_integer_8 : BooleanFFlag<"default-integer-8">, Group<gfortran_Group>;
|
||||
defm default_real_8 : BooleanFFlag<"default-real-8">, Group<gfortran_Group>;
|
||||
defm dollar_ok : BooleanFFlag<"dollar-ok">, Group<gfortran_Group>;
|
||||
defm dump_fortran_optimized : BooleanFFlag<"dump-fortran-optimized">, Group<gfortran_Group>;
|
||||
defm dump_fortran_original : BooleanFFlag<"dump-fortran-original">, Group<gfortran_Group>;
|
||||
|
@ -4307,6 +4304,14 @@ file}]>;
|
|||
def ffixed_line_length_VALUE : Joined<["-"], "ffixed-line-length-">, Group<f_Group>, Alias<ffixed_line_length_EQ>;
|
||||
def fopenacc : Flag<["-"], "fopenacc">, Group<f_Group>,
|
||||
HelpText<"Enable OpenACC">;
|
||||
def fdefault_double_8 : Flag<["-"],"fdefault-double-8">, Group<f_Group>,
|
||||
HelpText<"Set the default double precision kind to an 8 byte wide type">;
|
||||
def fdefault_integer_8 : Flag<["-"],"fdefault-integer-8">, Group<f_Group>,
|
||||
HelpText<"Set the default integer kind to an 8 byte wide type">;
|
||||
def fdefault_real_8 : Flag<["-"],"fdefault-real-8">, Group<f_Group>,
|
||||
HelpText<"Set the default real kind to an 8 byte wide type">;
|
||||
def flarge_sizes : Flag<["-"],"flarge-sizes">, Group<f_Group>,
|
||||
HelpText<"Use INTEGER(KIND=8) for the result type in size-related intrinsics">;
|
||||
def fbackslash : Flag<["-"], "fbackslash">, Group<f_Group>,
|
||||
HelpText<"Specify that backslash in string introduces an escape character">,
|
||||
DocBrief<[{Change the interpretation of backslashes in string literals from
|
||||
|
|
|
@ -21,16 +21,18 @@ using namespace llvm::opt;
|
|||
|
||||
void Flang::AddFortranDialectOptions(const ArgList &Args,
|
||||
ArgStringList &CmdArgs) const {
|
||||
Args.AddAllArgs(CmdArgs,
|
||||
{options::OPT_ffixed_form, options::OPT_ffree_form,
|
||||
options::OPT_ffixed_line_length_EQ, options::OPT_fopenmp,
|
||||
options::OPT_fopenacc, options::OPT_finput_charset_EQ,
|
||||
options::OPT_fimplicit_none, options::OPT_fno_implicit_none,
|
||||
options::OPT_fbackslash, options::OPT_fno_backslash,
|
||||
options::OPT_flogical_abbreviations,
|
||||
options::OPT_fno_logical_abbreviations,
|
||||
options::OPT_fxor_operator, options::OPT_fno_xor_operator,
|
||||
options::OPT_falternative_parameter_statement});
|
||||
Args.AddAllArgs(
|
||||
CmdArgs, {options::OPT_ffixed_form, options::OPT_ffree_form,
|
||||
options::OPT_ffixed_line_length_EQ, options::OPT_fopenmp,
|
||||
options::OPT_fopenacc, options::OPT_finput_charset_EQ,
|
||||
options::OPT_fimplicit_none, options::OPT_fno_implicit_none,
|
||||
options::OPT_fbackslash, options::OPT_fno_backslash,
|
||||
options::OPT_flogical_abbreviations,
|
||||
options::OPT_fno_logical_abbreviations,
|
||||
options::OPT_fxor_operator, options::OPT_fno_xor_operator,
|
||||
options::OPT_falternative_parameter_statement,
|
||||
options::OPT_fdefault_real_8, options::OPT_fdefault_integer_8,
|
||||
options::OPT_fdefault_double_8, options::OPT_flarge_sizes});
|
||||
}
|
||||
|
||||
void Flang::AddPreprocessingOptions(const ArgList &Args,
|
||||
|
|
|
@ -69,6 +69,9 @@ class CompilerInvocation : public CompilerInvocationBase {
|
|||
// of options.
|
||||
std::string moduleDir_ = ".";
|
||||
|
||||
// Fortran Dialect options
|
||||
Fortran::common::IntrinsicTypeDefaultKinds defaultKinds_;
|
||||
|
||||
public:
|
||||
CompilerInvocation() = default;
|
||||
|
||||
|
@ -88,6 +91,13 @@ public:
|
|||
std::string &moduleDir() { return moduleDir_; }
|
||||
const std::string &moduleDir() const { return moduleDir_; }
|
||||
|
||||
Fortran::common::IntrinsicTypeDefaultKinds &defaultKinds() {
|
||||
return defaultKinds_;
|
||||
}
|
||||
const Fortran::common::IntrinsicTypeDefaultKinds &defaultKinds() const {
|
||||
return defaultKinds_;
|
||||
}
|
||||
|
||||
/// Create a compiler invocation from a list of input options.
|
||||
/// \returns true on success.
|
||||
/// \returns false if an error was encountered while parsing the arguments
|
||||
|
|
|
@ -221,13 +221,6 @@ static InputKind ParseFrontendArgs(FrontendOptions &opts,
|
|||
}
|
||||
}
|
||||
|
||||
// Extensions
|
||||
if (args.hasArg(clang::driver::options::OPT_fopenacc)) {
|
||||
opts.features_.Enable(Fortran::common::LanguageFeature::OpenACC);
|
||||
}
|
||||
if (args.hasArg(clang::driver::options::OPT_fopenmp)) {
|
||||
opts.features_.Enable(Fortran::common::LanguageFeature::OpenMP);
|
||||
}
|
||||
if (const llvm::opt::Arg *arg =
|
||||
args.getLastArg(clang::driver::options::OPT_fimplicit_none,
|
||||
clang::driver::options::OPT_fno_implicit_none)) {
|
||||
|
@ -315,6 +308,48 @@ static void parseSemaArgs(std::string &moduleDir, llvm::opt::ArgList &args,
|
|||
moduleDir = moduleDirList[0];
|
||||
}
|
||||
|
||||
/// Parses all Dialect related arguments and populates the variables
|
||||
/// options accordingly.
|
||||
static void parseDialectArgs(CompilerInvocation &res, llvm::opt::ArgList &args,
|
||||
clang::DiagnosticsEngine &diags) {
|
||||
|
||||
// -fdefault* family
|
||||
if (args.hasArg(clang::driver::options::OPT_fdefault_real_8)) {
|
||||
res.defaultKinds().set_defaultRealKind(8);
|
||||
res.defaultKinds().set_doublePrecisionKind(16);
|
||||
}
|
||||
if (args.hasArg(clang::driver::options::OPT_fdefault_integer_8)) {
|
||||
res.defaultKinds().set_defaultIntegerKind(8);
|
||||
res.defaultKinds().set_subscriptIntegerKind(8);
|
||||
res.defaultKinds().set_sizeIntegerKind(8);
|
||||
}
|
||||
if (args.hasArg(clang::driver::options::OPT_fdefault_double_8)) {
|
||||
if (!args.hasArg(clang::driver::options::OPT_fdefault_real_8)) {
|
||||
// -fdefault-double-8 has to be used with -fdefault-real-8
|
||||
// to be compatible with gfortran
|
||||
const unsigned diagID =
|
||||
diags.getCustomDiagID(clang::DiagnosticsEngine::Error,
|
||||
"Use of `-fdefault-double-8` requires `-fdefault-real-8`");
|
||||
diags.Report(diagID);
|
||||
}
|
||||
// https://gcc.gnu.org/onlinedocs/gfortran/Fortran-Dialect-Options.html
|
||||
res.defaultKinds().set_doublePrecisionKind(8);
|
||||
}
|
||||
if (args.hasArg(clang::driver::options::OPT_flarge_sizes))
|
||||
res.defaultKinds().set_sizeIntegerKind(8);
|
||||
|
||||
// -fopenmp and -fopenacc
|
||||
if (args.hasArg(clang::driver::options::OPT_fopenacc)) {
|
||||
res.frontendOpts().features_.Enable(
|
||||
Fortran::common::LanguageFeature::OpenACC);
|
||||
}
|
||||
if (args.hasArg(clang::driver::options::OPT_fopenmp)) {
|
||||
res.frontendOpts().features_.Enable(
|
||||
Fortran::common::LanguageFeature::OpenMP);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
bool CompilerInvocation::CreateFromArgs(CompilerInvocation &res,
|
||||
llvm::ArrayRef<const char *> commandLineArgs,
|
||||
clang::DiagnosticsEngine &diags) {
|
||||
|
@ -346,6 +381,8 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &res,
|
|||
parsePreprocessorArgs(res.preprocessorOpts(), args);
|
||||
// Parse semantic args
|
||||
parseSemaArgs(res.moduleDir(), args, diags);
|
||||
// Parse dialect arguments
|
||||
parseDialectArgs(res, args, diags);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
@ -454,8 +491,7 @@ void CompilerInvocation::setSemanticsOpts(
|
|||
const auto &fortranOptions = fortranOpts();
|
||||
|
||||
semanticsContext_ = std::make_unique<semantics::SemanticsContext>(
|
||||
*(new Fortran::common::IntrinsicTypeDefaultKinds()),
|
||||
fortranOptions.features, allCookedSources);
|
||||
defaultKinds(), fortranOptions.features, allCookedSources);
|
||||
|
||||
auto &moduleDirJ = moduleDir();
|
||||
semanticsContext_->set_moduleDirectory(moduleDirJ)
|
||||
|
|
|
@ -26,12 +26,16 @@
|
|||
! CHECK-NEXT: Enable the old style PARAMETER statement
|
||||
! CHECK-NEXT: -fbackslash Specify that backslash in string introduces an escape character
|
||||
! CHECK-NEXT: -fcolor-diagnostics Enable colors in diagnostics
|
||||
! CHECK-NEXT: -fdefault-double-8 Set the default double precision kind to an 8 byte wide type
|
||||
! CHECK-NEXT: -fdefault-integer-8 Set the default integer kind to an 8 byte wide type
|
||||
! CHECK-NEXT: -fdefault-real-8 Set the default real kind to an 8 byte wide type
|
||||
! CHECK-NEXT: -ffixed-form Process source files in fixed form
|
||||
! CHECK-NEXT: -ffixed-line-length=<value>
|
||||
! CHECK-NEXT: Use <value> as character line width in fixed mode
|
||||
! CHECK-NEXT: -ffree-form Process source files in free form
|
||||
! CHECK-NEXT: -fimplicit-none No implicit typing allowed unless overridden by IMPLICIT statements
|
||||
! CHECK-NEXT: -finput-charset=<value> Specify the default character set for source files
|
||||
! CHECK-NEXT: -flarge-sizes Use INTEGER(KIND=8) for the result type in size-related intrinsics
|
||||
! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
|
||||
! CHECK-NEXT: -fno-color-diagnostics Disable colors in diagnostics
|
||||
! CHECK-NEXT: -fopenacc Enable OpenACC
|
||||
|
|
|
@ -26,12 +26,16 @@
|
|||
! HELP-NEXT: Enable the old style PARAMETER statement
|
||||
! HELP-NEXT: -fbackslash Specify that backslash in string introduces an escape character
|
||||
! HELP-NEXT: -fcolor-diagnostics Enable colors in diagnostics
|
||||
! HELP-NEXT: -fdefault-double-8 Set the default double precision kind to an 8 byte wide type
|
||||
! HELP-NEXT: -fdefault-integer-8 Set the default integer kind to an 8 byte wide type
|
||||
! HELP-NEXT: -fdefault-real-8 Set the default real kind to an 8 byte wide type
|
||||
! HELP-NEXT: -ffixed-form Process source files in fixed form
|
||||
! HELP-NEXT: -ffixed-line-length=<value>
|
||||
! HELP-NEXT: Use <value> as character line width in fixed mode
|
||||
! HELP-NEXT: -ffree-form Process source files in free form
|
||||
! HELP-NEXT: -fimplicit-none No implicit typing allowed unless overridden by IMPLICIT statements
|
||||
! HELP-NEXT: -finput-charset=<value> Specify the default character set for source files
|
||||
! HELP-NEXT: -flarge-sizes Use INTEGER(KIND=8) for the result type in size-related intrinsics
|
||||
! HELP-NEXT: -flogical-abbreviations Enable logical abbreviations
|
||||
! HELP-NEXT: -fno-color-diagnostics Disable colors in diagnostics
|
||||
! HELP-NEXT: -fopenacc Enable OpenACC
|
||||
|
@ -66,12 +70,16 @@
|
|||
! HELP-FC1-NEXT: -fdebug-unparse-with-symbols
|
||||
! HELP-FC1-NEXT: Unparse and stop.
|
||||
! HELP-FC1-NEXT: -fdebug-unparse Unparse and stop.
|
||||
! HELP-FC1-NEXT: -fdefault-double-8 Set the default double precision kind to an 8 byte wide type
|
||||
! HELP-FC1-NEXT: -fdefault-integer-8 Set the default integer kind to an 8 byte wide type
|
||||
! HELP-FC1-NEXT: -fdefault-real-8 Set the default real kind to an 8 byte wide type
|
||||
! HELP-FC1-NEXT: -ffixed-form Process source files in fixed form
|
||||
! HELP-FC1-NEXT: -ffixed-line-length=<value>
|
||||
! HELP-FC1-NEXT: Use <value> as character line width in fixed mode
|
||||
! HELP-FC1-NEXT: -ffree-form Process source files in free form
|
||||
! HELP-FC1-NEXT: -fimplicit-none No implicit typing allowed unless overridden by IMPLICIT statements
|
||||
! HELP-FC1-NEXT: -finput-charset=<value> Specify the default character set for source files
|
||||
! HELP-FC1-NEXT: -flarge-sizes Use INTEGER(KIND=8) for the result type in size-related intrinsics
|
||||
! HELP-FC1-NEXT: -flogical-abbreviations Enable logical abbreviations
|
||||
! HELP-FC1-NEXT: -fopenacc Enable OpenACC
|
||||
! HELP-FC1-NEXT: -fopenmp Parse OpenMP pragmas and generate parallel code.
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
! Ensure argument -fdefault* work as expected.
|
||||
! TODO: Add checks when actual codegen is possible for this family
|
||||
|
||||
!--------------------------
|
||||
! FLANG DRIVER (flang-new)
|
||||
!--------------------------
|
||||
! RUN: rm -rf %t/dir-flang-new && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -module-dir %t/dir-flang-new %s 2>&1
|
||||
! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=NOOPTION
|
||||
! RUN: rm -rf %t/dir-flang-new && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -fdefault-real-8 -module-dir %t/dir-flang-new %s 2>&1
|
||||
! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=REAL8
|
||||
! RUN: rm -rf %t/dir-flang-new && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -fdefault-real-8 -fdefault-double-8 -module-dir %t/dir-flang-new %s 2>&1
|
||||
! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=DOUBLE8
|
||||
! RUN: not %flang -fsyntax-only -fdefault-double-8 %s 2>&1 | FileCheck %s --check-prefix=ERROR
|
||||
|
||||
!-----------------------------------------
|
||||
! FRONTEND FLANG DRIVER (flang-new -fc1)
|
||||
!-----------------------------------------
|
||||
! RUN: rm -rf %t/dir-flang-new && mkdir -p %t/dir-flang-new && %flang_fc1 -fsyntax-only -module-dir %t/dir-flang-new %s 2>&1
|
||||
! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=NOOPTION
|
||||
! RUN: rm -rf %t/dir-flang-new && mkdir -p %t/dir-flang-new && %flang_fc1 -fsyntax-only -fdefault-real-8 -module-dir %t/dir-flang-new %s 2>&1
|
||||
! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=REAL8
|
||||
! RUN: rm -rf %t/dir-flang-new && mkdir -p %t/dir-flang-new && %flang_fc1 -fsyntax-only -fdefault-real-8 -fdefault-double-8 -module-dir %t/dir-flang-new %s 2>&1
|
||||
! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=DOUBLE8
|
||||
! RUN: not %flang_fc1 -fsyntax-only -fdefault-double-8 %s 2>&1 | FileCheck %s --check-prefix=ERROR
|
||||
|
||||
!-----------------------------------------
|
||||
! EXPECTED OUTPUT FOR NO SPECIFICATION
|
||||
!-----------------------------------------
|
||||
! NOOPTION: integer(4),parameter::real_kind=4_4
|
||||
! NOOPTION-NEXT: intrinsic::kind
|
||||
! NOOPTION-NEXT: integer(4),parameter::double_kind=8_4
|
||||
|
||||
!-------------------------------------------
|
||||
! EXPECTED OUTPUT FOR ONLY -fdefault-real-8
|
||||
!-------------------------------------------
|
||||
! REAL8: integer(4),parameter::real_kind=8_4
|
||||
! REAL8-NEXT: intrinsic::kind
|
||||
! REAL8-NEXT: integer(4),parameter::double_kind=16_4
|
||||
|
||||
!-------------------------------------------------------------
|
||||
! EXPECTED OUTPUT FOR -fdefault-real-8 AND -fdefault-double-8
|
||||
!-------------------------------------------------------------
|
||||
! DOUBLE8: integer(4),parameter::real_kind=8_4
|
||||
! DOUBLE8-NEXT: intrinsic::kind
|
||||
! DOUBLE8-NEXT: integer(4),parameter::double_kind=8_4
|
||||
|
||||
!------------------------------------------------------
|
||||
! EXPECTED OUTPUT FOR PROVIDING ONLY -fdefault-double-8
|
||||
!------------------------------------------------------
|
||||
! ERROR: Use of `-fdefault-double-8` requires `-fdefault-real-8`
|
||||
|
||||
module m
|
||||
implicit none
|
||||
real :: x
|
||||
double precision :: y
|
||||
integer, parameter :: real_kind = kind(x) !-fdefault-real-8
|
||||
integer, parameter :: double_kind = kind(y) !-fdefault-double-8
|
||||
end
|
|
@ -0,0 +1,36 @@
|
|||
! Ensure argument -flarge-sizes works as expected.
|
||||
! TODO: Add checks when actual codegen is possible.
|
||||
|
||||
!--------------------------
|
||||
! FLANG DRIVER (flang-new)
|
||||
!--------------------------
|
||||
! RUN: rm -rf %t/dir-flang-new && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -module-dir %t/dir-flang-new %s 2>&1
|
||||
! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=NOLARGE
|
||||
! RUN: rm -rf %t/dir-flang-new && mkdir -p %t/dir-flang-new && %flang -fsyntax-only -flarge-sizes -module-dir %t/dir-flang-new %s 2>&1
|
||||
! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=LARGE
|
||||
|
||||
!-----------------------------------------
|
||||
! FRONTEND FLANG DRIVER (flang-new -fc1)
|
||||
!-----------------------------------------
|
||||
! RUN: rm -rf %t/dir-flang-new && mkdir -p %t/dir-flang-new && %flang_fc1 -fsyntax-only -module-dir %t/dir-flang-new %s 2>&1
|
||||
! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=NOLARGE
|
||||
! RUN: rm -rf %t/dir-flang-new && mkdir -p %t/dir-flang-new && %flang_fc1 -fsyntax-only -flarge-sizes -module-dir %t/dir-flang-new %s 2>&1
|
||||
! RUN: cat %t/dir-flang-new/m.mod | FileCheck %s --check-prefix=LARGE
|
||||
|
||||
!-----------------------------------------
|
||||
! EXPECTED OUTPUT WITHOUT -flarge-sizes
|
||||
!-----------------------------------------
|
||||
! NOLARGE: real(4)::z(1_8:10_8)
|
||||
! NOLARGE-NEXT: integer(4),parameter::size_kind=4_4
|
||||
|
||||
!-----------------------------------------
|
||||
! EXPECTED OUTPUT FOR -flarge-sizes
|
||||
!-----------------------------------------
|
||||
! LARGE: real(4)::z(1_8:10_8)
|
||||
! LARGE-NEXT: integer(4),parameter::size_kind=8_4
|
||||
|
||||
module m
|
||||
implicit none
|
||||
real :: z(10)
|
||||
integer, parameter :: size_kind = kind(ubound(z, 1)) !-flarge-sizes
|
||||
end
|
|
@ -5,6 +5,14 @@
|
|||
|
||||
! RUN: %flang-new -fsyntax-only -### %s -o %t 2>&1 \
|
||||
! RUN: -finput-charset=utf-8 \
|
||||
! RUN: -fdefault-double-8 \
|
||||
! RUN: -fdefault-integer-8 \
|
||||
! RUN: -fdefault-real-8 \
|
||||
! RUN: -flarge-sizes \
|
||||
! RUN: | FileCheck %s
|
||||
|
||||
! CHECK: "-finput-charset=utf-8"
|
||||
! CHECK: "-fdefault-double-8"
|
||||
! CHECK: "-fdefault-integer-8"
|
||||
! CHECK: "-fdefault-real-8"
|
||||
! CHECK: "-flarge-sizes"
|
||||
|
|
|
@ -10,4 +10,5 @@ target_link_libraries(FlangFrontendTests
|
|||
flangFrontendTool
|
||||
FortranParser
|
||||
FortranSemantics
|
||||
FortranCommon
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue