Skip to content

Commit

Permalink
Allow disabling of types from the command line (#107126)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Renaud-K authored Sep 4, 2024
1 parent 0367305 commit 697bc74
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 5 deletions.
8 changes: 8 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -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">;

Expand Down
6 changes: 6 additions & 0 deletions flang/include/flang/Frontend/TargetOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions flang/include/flang/Tools/TargetSetup.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
#define FORTRAN_TOOLS_TARGET_SETUP_H

#include "flang/Evaluate/target.h"
#include "flang/Frontend/TargetOptions.h"
#include "llvm/Target/TargetMachine.h"

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()};
Expand All @@ -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);

Expand Down
17 changes: 14 additions & 3 deletions flang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions flang/tools/bbc/bbc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 697bc74

Please sign in to comment.