Author: Renaud Kauffmann Date: 2024-09-04T08:59:55-07:00 New Revision: 697bc748f97736b294dd85b8f78530d023557b72
URL: https://github.com/llvm/llvm-project/commit/697bc748f97736b294dd85b8f78530d023557b72 DIFF: https://github.com/llvm/llvm-project/commit/697bc748f97736b294dd85b8f78530d023557b72.diff LOG: Allow disabling of types from the command line (#107126) Adding hidden options to disable types through the `TargetCharacteristics`. I am seeing issues when I do this programmatically and would like, for anyone, to have the ability to reproduce them for development and testing purposes. I am planning to file a couple of issues following this patch. Added: Modified: clang/include/clang/Driver/Options.td flang/include/flang/Frontend/TargetOptions.h flang/include/flang/Tools/TargetSetup.h flang/lib/Frontend/CompilerInvocation.cpp flang/tools/bbc/bbc.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 8fe9f4f28f8fc1..1142416e227fc8 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -6762,6 +6762,14 @@ def fdefault_integer_8 : Flag<["-"],"fdefault-integer-8">, Group<f_Group>, HelpText<"Set the default integer and logical 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 fdisable_real_3 : Flag<["-"],"fdisable-real-3">, Group<f_Group>, + HelpText<"Disable real(KIND=3) from TargetCharacteristics">, Flags<[HelpHidden]>; +def fdisable_real_10 : Flag<["-"],"fdisable-real-10">, Group<f_Group>, + HelpText<"Disable real(KIND=10) from TargetCharacteristics">, Flags<[HelpHidden]>; +def fdisable_integer_2 : Flag<["-"],"fdisable-integer-2">, Group<f_Group>, + HelpText<"Disable integer(KIND=2) from TargetCharacteristics">, Flags<[HelpHidden]>; +def fdisable_integer_16 : Flag<["-"],"fdisable-integer-16">, Group<f_Group>, + HelpText<"Disable integer(KIND=16) from TargetCharacteristics">, Flags<[HelpHidden]>; def flarge_sizes : Flag<["-"],"flarge-sizes">, Group<f_Group>, HelpText<"Use INTEGER(KIND=8) for the result type in size-related intrinsics">; diff --git a/flang/include/flang/Frontend/TargetOptions.h b/flang/include/flang/Frontend/TargetOptions.h index fa72c77a028a1c..332adcbe6b6ac3 100644 --- a/flang/include/flang/Frontend/TargetOptions.h +++ b/flang/include/flang/Frontend/TargetOptions.h @@ -38,6 +38,12 @@ class TargetOptions { /// The list of target specific features to enable or disable, as written on /// the command line. std::vector<std::string> featuresAsWritten; + + /// The real KINDs disabled for this target + std::vector<int> disabledRealKinds; + + /// The integer KINDs disabled for this target + std::vector<int> disabledIntegerKinds; }; } // end namespace Fortran::frontend diff --git a/flang/include/flang/Tools/TargetSetup.h b/flang/include/flang/Tools/TargetSetup.h index 238d66c9241dd0..37c1e1d2ff63f3 100644 --- a/flang/include/flang/Tools/TargetSetup.h +++ b/flang/include/flang/Tools/TargetSetup.h @@ -10,6 +10,7 @@ #define FORTRAN_TOOLS_TARGET_SETUP_H #include "flang/Evaluate/target.h" +#include "flang/Frontend/TargetOptions.h" #include "llvm/Target/TargetMachine.h" namespace Fortran::tools { @@ -17,6 +18,7 @@ namespace Fortran::tools { [[maybe_unused]] inline static void setUpTargetCharacteristics( Fortran::evaluate::TargetCharacteristics &targetCharacteristics, const llvm::TargetMachine &targetMachine, + const Fortran::frontend::TargetOptions &targetOptions, const std::string &compilerVersion, const std::string &compilerOptions) { const llvm::Triple &targetTriple{targetMachine.getTargetTriple()}; @@ -25,6 +27,12 @@ namespace Fortran::tools { targetCharacteristics.DisableType( Fortran::common::TypeCategory::Real, /*kind=*/10); + for (auto realKind : targetOptions.disabledRealKinds) + targetCharacteristics.DisableType(common::TypeCategory::Real, realKind); + + for (auto intKind : targetOptions.disabledIntegerKinds) + targetCharacteristics.DisableType(common::TypeCategory::Integer, intKind); + targetCharacteristics.set_compilerOptionsString(compilerOptions) .set_compilerVersionString(compilerVersion); diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index 9e42fcc2e39d5e..90c327546198b5 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -438,8 +438,19 @@ static void parseTargetArgs(TargetOptions &opts, llvm::opt::ArgList &args) { for (const llvm::opt::Arg *currentArg : args.filtered(clang::driver::options::OPT_target_feature)) opts.featuresAsWritten.emplace_back(currentArg->getValue()); -} + if (args.hasArg(clang::driver::options::OPT_fdisable_real_10)) + opts.disabledRealKinds.push_back(10); + + if (args.hasArg(clang::driver::options::OPT_fdisable_real_3)) + opts.disabledRealKinds.push_back(3); + + if (args.hasArg(clang::driver::options::OPT_fdisable_integer_2)) + opts.disabledIntegerKinds.push_back(2); + + if (args.hasArg(clang::driver::options::OPT_fdisable_integer_16)) + opts.disabledIntegerKinds.push_back(16); +} // Tweak the frontend configuration based on the frontend action static void setUpFrontendBasedOnAction(FrontendOptions &opts) { if (opts.programAction == DebugDumpParsingLog) @@ -1531,8 +1542,8 @@ CompilerInvocation::getSemanticsCtx( std::string compilerVersion = Fortran::common::getFlangFullVersion(); Fortran::tools::setUpTargetCharacteristics( - semanticsContext->targetCharacteristics(), targetMachine, compilerVersion, - allCompilerInvocOpts); + semanticsContext->targetCharacteristics(), targetMachine, getTargetOpts(), + compilerVersion, allCompilerInvocOpts); return semanticsContext; } diff --git a/flang/tools/bbc/bbc.cpp b/flang/tools/bbc/bbc.cpp index 736d68219581dd..dcff4503f16571 100644 --- a/flang/tools/bbc/bbc.cpp +++ b/flang/tools/bbc/bbc.cpp @@ -18,6 +18,7 @@ #include "flang/Common/OpenMP-features.h" #include "flang/Common/Version.h" #include "flang/Common/default-kinds.h" +#include "flang/Frontend/TargetOptions.h" #include "flang/Lower/Bridge.h" #include "flang/Lower/PFTBuilder.h" #include "flang/Lower/Support/Verifier.h" @@ -556,8 +557,8 @@ int main(int argc, char **argv) { std::string compilerVersion = Fortran::common::getFlangToolFullVersion("bbc"); std::string compilerOptions = ""; Fortran::tools::setUpTargetCharacteristics( - semanticsContext.targetCharacteristics(), *targetMachine, compilerVersion, - compilerOptions); + semanticsContext.targetCharacteristics(), *targetMachine, {}, + compilerVersion, compilerOptions); return mlir::failed( convertFortranSourceToMLIR(inputFilename, options, programPrefix, _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits