[clang] [flang] Allow disabling of types from the command line (PR #107126)

2024-09-04 Thread Renaud Kauffmann via cfe-commits

https://github.com/Renaud-K closed 
https://github.com/llvm/llvm-project/pull/107126
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] Allow disabling of types from the command line (PR #107126)

2024-09-04 Thread Renaud Kauffmann via cfe-commits

Renaud-K wrote:

I have been looking into this but long story short, but I am little pressed by 
time and was not planning on spending too much time on this. For the need that 
we have, it should be ok. 

https://github.com/llvm/llvm-project/pull/107126
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] Allow disabling of types from the command line (PR #107126)

2024-09-03 Thread Renaud Kauffmann via cfe-commits

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

>From 8a1c51bdd290fc47cac359646aeb01623574231f Mon Sep 17 00:00:00 2001
From: Renaud-K 
Date: Tue, 3 Sep 2024 09:34:09 -0700
Subject: [PATCH 1/4] 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,
   HelpText<"Set the default integer and logical kind to an 8 byte wide type">;
 def fdefault_real_8 : Flag<["-"],"fdefault-real-8">, Group,
   HelpText<"Set the default real kind to an 8 byte wide type">;
+def fdisable_real_3 : Flag<["-"],"fdisable-real-3">, Group,
+  Flags<[HelpHidden]>;
+def fdisable_real_10 : Flag<["-"],"fdisable-real-10">, Group,
+  Flags<[HelpHidden]>;
+def fdisable_integer_16 : Flag<["-"],"fdisable-integer-16">, Group,
+  Flags<[HelpHidden]>;
 def flarge_sizes : Flag<["-"],"flarge-sizes">, 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 featuresAsWritten;
+
+  /// The real KINDs disabled for this target
+  std::vector disabledRealKinds;
+  
+  /// The integer KINDs disabled for this target
+  std::vector 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(
-  semantic

[clang] [flang] Allow disabling of types from the command line (PR #107126)

2024-09-03 Thread Renaud Kauffmann via cfe-commits

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

>From 8a1c51bdd290fc47cac359646aeb01623574231f Mon Sep 17 00:00:00 2001
From: Renaud-K 
Date: Tue, 3 Sep 2024 09:34:09 -0700
Subject: [PATCH 1/3] 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,
   HelpText<"Set the default integer and logical kind to an 8 byte wide type">;
 def fdefault_real_8 : Flag<["-"],"fdefault-real-8">, Group,
   HelpText<"Set the default real kind to an 8 byte wide type">;
+def fdisable_real_3 : Flag<["-"],"fdisable-real-3">, Group,
+  Flags<[HelpHidden]>;
+def fdisable_real_10 : Flag<["-"],"fdisable-real-10">, Group,
+  Flags<[HelpHidden]>;
+def fdisable_integer_16 : Flag<["-"],"fdisable-integer-16">, Group,
+  Flags<[HelpHidden]>;
 def flarge_sizes : Flag<["-"],"flarge-sizes">, 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 featuresAsWritten;
+
+  /// The real KINDs disabled for this target
+  std::vector disabledRealKinds;
+  
+  /// The integer KINDs disabled for this target
+  std::vector 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(
-  semantic

[clang] [flang] Allow disabling of types from the command line (PR #107126)

2024-09-03 Thread Renaud Kauffmann via cfe-commits

Renaud-K wrote:

The end goal is testing for issues that this PR would expose and that I am 
planning on filing next.
Every bit-width? (5,6,7,9,11,12,13,14,15)  I don't think so.
It does not matter what gfortran does. It is not a feature, it is hidden for 
testing purposes.
 


https://github.com/llvm/llvm-project/pull/107126
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] Allow disabling of types from the command line (PR #107126)

2024-09-03 Thread Renaud Kauffmann via cfe-commits

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

>From 8a1c51bdd290fc47cac359646aeb01623574231f Mon Sep 17 00:00:00 2001
From: Renaud-K 
Date: Tue, 3 Sep 2024 09:34:09 -0700
Subject: [PATCH 1/2] 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,
   HelpText<"Set the default integer and logical kind to an 8 byte wide type">;
 def fdefault_real_8 : Flag<["-"],"fdefault-real-8">, Group,
   HelpText<"Set the default real kind to an 8 byte wide type">;
+def fdisable_real_3 : Flag<["-"],"fdisable-real-3">, Group,
+  Flags<[HelpHidden]>;
+def fdisable_real_10 : Flag<["-"],"fdisable-real-10">, Group,
+  Flags<[HelpHidden]>;
+def fdisable_integer_16 : Flag<["-"],"fdisable-integer-16">, Group,
+  Flags<[HelpHidden]>;
 def flarge_sizes : Flag<["-"],"flarge-sizes">, 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 featuresAsWritten;
+
+  /// The real KINDs disabled for this target
+  std::vector disabledRealKinds;
+  
+  /// The integer KINDs disabled for this target
+  std::vector 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(
-  semantic

[clang] [flang] Allow disabling of types from the command line (PR #107126)

2024-09-03 Thread Renaud Kauffmann via cfe-commits

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 
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,
   HelpText<"Set the default integer and logical kind to an 8 byte wide type">;
 def fdefault_real_8 : Flag<["-"],"fdefault-real-8">, Group,
   HelpText<"Set the default real kind to an 8 byte wide type">;
+def fdisable_real_3 : Flag<["-"],"fdisable-real-3">, Group,
+  Flags<[HelpHidden]>;
+def fdisable_real_10 : Flag<["-"],"fdisable-real-10">, Group,
+  Flags<[HelpHidden]>;
+def fdisable_integer_16 : Flag<["-"],"fdisable-integer-16">, Group,
+  Flags<[HelpHidden]>;
 def flarge_sizes : Flag<["-"],"flarge-sizes">, 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 featuresAsWritten;
+
+  /// The real KINDs disabled for this target
+  std::vector disabledRealKinds;
+  
+  /// The integer KINDs disabled for this target
+  std::vector 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
 stati

[libcxxabi] [llvm] [lldb] [libc] [libcxx] [lld] [flang] [libunwind] [mlir] [compiler-rt] [clang-tools-extra] [clang] Have fir::unwrapSeqOrBoxedSeqType work with BaseBoxType (PR #72160)

2023-11-13 Thread Renaud Kauffmann via cfe-commits

https://github.com/Renaud-K closed 
https://github.com/llvm/llvm-project/pull/72160
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxxabi] [llvm] [lldb] [libc] [libcxx] [lld] [flang] [libunwind] [mlir] [compiler-rt] [clang-tools-extra] [clang] Have fir::unwrapSeqOrBoxedSeqType work with BaseBoxType (PR #72160)

2023-11-13 Thread Renaud Kauffmann via cfe-commits

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

Fixing  fir::unwrapSeqOrBoxedSeqType so it also works with the fir::ClassType

>From af6200e4466066f92a67d69e6f49c8baa28bf62f Mon Sep 17 00:00:00 2001
From: Renaud-K 
Date: Wed, 8 Mar 2023 18:39:40 -0800
Subject: [PATCH] Break circular dependency between FIR dialect and utilities
 Differential revision: https://reviews.llvm.org/D145640

---
 flang/include/flang/Lower/Bridge.h   |  2 +-
 flang/include/flang/Optimizer/Builder/FIRBuilder.h   |  2 +-
 .../Optimizer/{ => Dialect}/Support/FIRContext.h |  0
 .../Optimizer/{ => Dialect}/Support/KindMapping.h|  0
 flang/lib/Frontend/CMakeLists.txt|  3 +--
 flang/lib/Frontend/FrontendActions.cpp   |  4 ++--
 flang/lib/Lower/Bridge.cpp   |  2 +-
 flang/lib/Lower/CMakeLists.txt   |  5 ++---
 flang/lib/Lower/ConvertVariable.cpp  |  2 +-
 flang/lib/Lower/IO.cpp   |  2 +-
 flang/lib/Optimizer/Analysis/CMakeLists.txt  |  3 +--
 flang/lib/Optimizer/Builder/CMakeLists.txt   |  2 +-
 flang/lib/Optimizer/Builder/IntrinsicCall.cpp|  2 +-
 flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp   |  2 +-
 flang/lib/Optimizer/CodeGen/CMakeLists.txt   |  3 +--
 flang/lib/Optimizer/CodeGen/PreCGRewrite.cpp |  2 +-
 flang/lib/Optimizer/CodeGen/Target.cpp   |  2 +-
 flang/lib/Optimizer/CodeGen/Target.h |  2 +-
 flang/lib/Optimizer/CodeGen/TargetRewrite.cpp|  2 +-
 flang/lib/Optimizer/CodeGen/TypeConverter.h  |  4 ++--
 flang/lib/Optimizer/Dialect/CMakeLists.txt   |  6 --
 flang/lib/Optimizer/Dialect/FIRAttr.cpp  |  2 +-
 flang/lib/Optimizer/Dialect/FIROps.cpp   |  4 ++--
 flang/lib/Optimizer/Dialect/FIRType.cpp  |  2 +-
 flang/lib/Optimizer/Dialect/Support/CMakeLists.txt   | 12 
 .../Optimizer/{ => Dialect}/Support/FIRContext.cpp   |  4 ++--
 .../Optimizer/{ => Dialect}/Support/KindMapping.cpp  |  2 +-
 .../Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp|  2 +-
 flang/lib/Optimizer/HLFIR/Transforms/CMakeLists.txt  |  1 +
 .../lib/Optimizer/HLFIR/Transforms/ConvertToFIR.cpp  |  2 +-
 flang/lib/Optimizer/Support/CMakeLists.txt   |  2 --
 flang/lib/Optimizer/Transforms/AbstractResult.cpp|  2 +-
 .../lib/Optimizer/Transforms/AddDebugFoundation.cpp  |  2 +-
 flang/lib/Optimizer/Transforms/ArrayValueCopy.cpp|  2 +-
 flang/lib/Optimizer/Transforms/CMakeLists.txt|  3 +--
 .../lib/Optimizer/Transforms/CharacterConversion.cpp |  4 ++--
 .../Optimizer/Transforms/ControlFlowConverter.cpp|  4 ++--
 .../Optimizer/Transforms/PolymorphicOpConversion.cpp |  4 ++--
 .../lib/Optimizer/Transforms/SimplifyIntrinsics.cpp  |  2 +-
 flang/lib/Optimizer/Transforms/StackArrays.cpp   |  2 +-
 flang/tools/bbc/CMakeLists.txt   |  1 +
 flang/tools/bbc/bbc.cpp  |  4 ++--
 flang/tools/tco/CMakeLists.txt   |  1 +
 flang/tools/tco/tco.cpp  |  4 ++--
 flang/unittests/Optimizer/Builder/CharacterTest.cpp  |  2 +-
 flang/unittests/Optimizer/Builder/ComplexTest.cpp|  2 +-
 .../unittests/Optimizer/Builder/DoLoopHelperTest.cpp |  2 +-
 flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp |  2 +-
 flang/unittests/Optimizer/Builder/HLFIRToolsTest.cpp |  2 +-
 .../Optimizer/Builder/Runtime/RuntimeCallTestBase.h  |  2 +-
 flang/unittests/Optimizer/CMakeLists.txt |  1 +
 flang/unittests/Optimizer/FIRContextTest.cpp |  4 ++--
 flang/unittests/Optimizer/KindMappingTest.cpp|  2 +-
 53 files changed, 75 insertions(+), 64 deletions(-)
 rename flang/include/flang/Optimizer/{ => Dialect}/Support/FIRContext.h (100%)
 rename flang/include/flang/Optimizer/{ => Dialect}/Support/KindMapping.h (100%)
 create mode 100644 flang/lib/Optimizer/Dialect/Support/CMakeLists.txt
 rename flang/lib/Optimizer/{ => Dialect}/Support/FIRContext.cpp (95%)
 rename flang/lib/Optimizer/{ => Dialect}/Support/KindMapping.cpp (99%)

diff --git a/flang/include/flang/Lower/Bridge.h 
b/flang/include/flang/Lower/Bridge.h
index 6766613ebc27dba..b4ee77a0b166ec9 100644
--- a/flang/include/flang/Lower/Bridge.h
+++ b/flang/include/flang/Lower/Bridge.h
@@ -19,7 +19,7 @@
 #include "flang/Lower/LoweringOptions.h"
 #include "flang/Lower/StatementContext.h"
 #include "flang/Optimizer/Builder/FIRBuilder.h"
-#include "flang/Optimizer/Support/KindMapping.h"
+#include "flang/Optimizer/Dialect/Support/KindMapping.h"
 #include "mlir/IR/BuiltinOps.h"
 
 namespace Fortran {
diff --git a/flang/include/flang/Optimizer/Builder/FIRBuilder.h 
b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
index 085e91f0c6fa61d..0dbd77823d8f859 100644
--- a/flang/include/flang/Optimizer/Builder/FIRBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
@@ -20,7 +20,7 

[clang] [flang] add tbaa tags to global and direct values (PR #68727)

2023-10-24 Thread Renaud Kauffmann via cfe-commits

https://github.com/Renaud-K approved this pull request.


https://github.com/llvm/llvm-project/pull/68727
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] add tbaa tags to global variables (PR #68727)

2023-10-11 Thread Renaud Kauffmann via cfe-commits


@@ -406,7 +406,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value 
v) {
 attributes.set(Attribute::Pointer);
 }
 
-  if (type == SourceKind::Global)
+  if (type == SourceKind::Global || type == SourceKind::Direct)

Renaud-K wrote:

I am still struggling a bit with heap data being marked global.

What would make sense for me is:

A direct with no pointer/target would have its own TBAA node.
A global with no target would have its own TBBA node.
Anything else would point to the "Any Data Access" node?



https://github.com/llvm/llvm-project/pull/68727
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] add tbaa tags to global variables (PR #68727)

2023-10-11 Thread Renaud Kauffmann via cfe-commits


@@ -406,7 +406,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value 
v) {
 attributes.set(Attribute::Pointer);
 }
 
-  if (type == SourceKind::Global)
+  if (type == SourceKind::Global || type == SourceKind::Direct)

Renaud-K wrote:

Would it help, if I just said that %val does not come from a global variable. 
It comes from the heap because glbl is an allocatable. The box is global, but 
the data it wraps is not. 

In the example below glbl is a global
```module mod
real, dimension(1000) :: glbl
contains
subroutine func(arg)
  real, intent(in), dimension(:) :: arg
  call escape(glbl)
end subroutine
end module
```

In this case the SourceKind is global and we can infer that it cannot alias 
with anything else because of where it is physically located. But if you prefer 
to stick to Fortran rules, you can say that it is an F77 construct (since it 
does not have any target attribute) and therefore does not alias with anything. 
It would be non-conformant to pass it as an argument. 

```
fir.global @_QMmodEglbl : !fir.array<1000xf32> {
  %0 = fir.zero_bits !fir.array<1000xf32>
  fir.has_value %0 : !fir.array<1000xf32>
}
func.func @_QMmodPfunc(%arg0: !fir.box> {fir.bindc_name = 
"arg"}) {
  %c1000 = arith.constant 1000 : index
  %0 = fir.address_of(@_QMmodEglbl) : !fir.ref>
  %1 = fir.shape %c1000 : (index) -> !fir.shape<1>
  %2 = fir.declare %0(%1) {uniq_name = "_QMmodEglbl"} : 
(!fir.ref>, !fir.shape<1>) -> 
!fir.ref>
  %3 = fir.declare %arg0 {fortran_attrs = #fir.var_attrs, uniq_name 
= "_QMmodFfuncEarg"} : (!fir.box>) -> 
!fir.box>
  fir.call @_QPescape(%2) fastmath : (!fir.ref>) 
-> ()
  return
}
```

In the case of the Direct SourceKind, the outcome w.r.t. `arg` is the same but 
the rule is different. We have a direct memory access because, despite the box 
load and indirect fir.box_addr operations, we could establish that %val is 
indexing into glbl.  There is no target or pointer attribute on `arg` so we say 
that it cannot alias with it. 

A couple of observations here is:
1. Direct SourceKind by itself is not sufficient to determine aliasing, the 
attributes need to be looked at as well.
2. Unlike the global case, the rule for direct is not reflective. Aliasing is 
established w.r.t. another value.

Hopefully, this clarifies things. But if none of that helps I am now wondering 
if we cannot alter the rule to make it reflective. Instead of 
```
lhsSrc.kind == SourceKind::Direct && !rhsSrc.isTargetOrPointer()
```
could we have

```
lhsSrc.kind == SourceKind::Direct && !lhsSrc.isTargetOrPointer()
```

I will play with it today.

https://github.com/llvm/llvm-project/pull/68727
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] add tbaa tags to global variables (PR #68727)

2023-10-11 Thread Renaud Kauffmann via cfe-commits


@@ -406,7 +406,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value 
v) {
 attributes.set(Attribute::Pointer);
 }
 
-  if (type == SourceKind::Global)
+  if (type == SourceKind::Global || type == SourceKind::Direct)

Renaud-K wrote:

No, they would not alias unless they have target/pointer attributes. I will be 
looking into the example and spend more time on this today.

https://github.com/llvm/llvm-project/pull/68727
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] add tbaa tags to global variables (PR #68727)

2023-10-10 Thread Renaud Kauffmann via cfe-commits


@@ -406,7 +406,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value 
v) {
 attributes.set(Attribute::Pointer);
 }
 
-  if (type == SourceKind::Global)
+  if (type == SourceKind::Global || type == SourceKind::Direct)

Renaud-K wrote:

We also wanted to use `SourceKind::Direct` with Allocmem and Alloca in which 
case global would be undefined. 
Maybe we can define the union instead in the TypeSwitch and get rid of this 
condition. 

I am assuming that in tbaa gen, we will be distinguishing based on the 
SourceKind.
A global SymbolRefAttr with a `SourceKind::Global` means that we are directly 
accessing global memory and we know this cannot physically alias with heap and 
stack.
But a global SymbolRefAttr with a `SourceKind::Direct` means we do not know 
much other than the target and pointer attributes.  


https://github.com/llvm/llvm-project/pull/68727
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits