https://github.com/Renaud-K created 
https://github.com/llvm/llvm-project/pull/107126

I would to add 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.


>From 8a1c51bdd290fc47cac359646aeb01623574231f Mon Sep 17 00:00:00 2001
From: Renaud-K <rkauffm...@nvidia.com>
Date: Tue, 3 Sep 2024 09:34:09 -0700
Subject: [PATCH] Allow disabling of types from the command line

---
 clang/include/clang/Driver/Options.td        |  6 ++++++
 flang/include/flang/Frontend/TargetOptions.h |  6 ++++++
 flang/include/flang/Tools/TargetSetup.h      | 11 ++++++++++-
 flang/lib/Frontend/CompilerInvocation.cpp    | 17 ++++++++++++++---
 flang/tools/bbc/bbc.cpp                      |  5 +++--
 5 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 83cf753e824845..8bc47fea5196e7 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6761,6 +6761,12 @@ 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>,
+  Flags<[HelpHidden]>;
+def fdisable_real_10 : Flag<["-"],"fdisable-real-10">, Group<f_Group>,
+  Flags<[HelpHidden]>;
+def fdisable_integer_16 : Flag<["-"],"fdisable-integer-16">, Group<f_Group>,
+  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..b0b64ae583d16c 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..b112b6b4d80578 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()};
@@ -24,7 +26,14 @@ namespace Fortran::tools {
   if (targetTriple.getArch() != llvm::Triple::ArchType::x86_64)
     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 1d73397d330178..5676947c2b1016 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_16)) {
+    opts.disabledIntegerKinds.push_back(16);
+  }
+}
 // Tweak the frontend configuration based on the frontend action
 static void setUpFrontendBasedOnAction(FrontendOptions &opts) {
   if (opts.programAction == DebugDumpParsingLog)
@@ -1529,8 +1540,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..279b04055798d0 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

Reply via email to