[clang] [flang] [mlir] Add basic -mtune support (PR #98517)

2024-07-16 Thread Alexis Perry-Holby via cfe-commits

AlexisPerry wrote:

@banach-space If this PR is indeed ready to go, would you mind committing it on 
my behalf?  I don't have commit privileges any more.  Thanks so much for all 
your help!  And thanks to all the reviewers on previous versions of this PR as 
well!

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


[clang] [flang] [mlir] Add basic -mtune support (PR #98517)

2024-07-11 Thread Alexis Perry-Holby via cfe-commits

https://github.com/AlexisPerry updated 
https://github.com/llvm/llvm-project/pull/98517

>From 2e26f0f66f070cd0b684531efc63e63e2e584dfa Mon Sep 17 00:00:00 2001
From: Alexis Perry-Holby 
Date: Thu, 11 Jul 2024 12:51:39 -0600
Subject: [PATCH 1/2] Add basic -mtune support

Initial implementation for the -mtune flag in Flang.
---
 clang/include/clang/Driver/Options.td |  7 +++---
 clang/lib/Driver/ToolChains/Flang.cpp | 10 +++-
 flang/include/flang/Frontend/TargetOptions.h  |  3 +++
 flang/include/flang/Lower/Bridge.h|  6 ++---
 .../flang/Optimizer/CodeGen/CGPasses.td   |  4 +++
 .../include/flang/Optimizer/CodeGen/Target.h  | 21 ++--
 .../Optimizer/Dialect/Support/FIRContext.h|  7 ++
 .../flang/Optimizer/Transforms/Passes.td  |  5 +++-
 flang/lib/Frontend/CompilerInvocation.cpp |  4 +++
 flang/lib/Frontend/FrontendActions.cpp|  3 ++-
 flang/lib/Lower/Bridge.cpp|  3 ++-
 flang/lib/Optimizer/CodeGen/CodeGen.cpp   |  6 -
 flang/lib/Optimizer/CodeGen/Target.cpp| 11 
 flang/lib/Optimizer/CodeGen/TargetRewrite.cpp | 12 -
 flang/lib/Optimizer/CodeGen/TypeConverter.cpp |  3 ++-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 18 +
 flang/test/Driver/tune-cpu-fir.f90| 25 +++
 flang/test/Lower/tune-cpu-llvm.f90|  8 ++
 flang/tools/bbc/bbc.cpp   |  3 ++-
 flang/tools/tco/tco.cpp   |  4 +++
 flang/unittests/Optimizer/FIRContextTest.cpp  |  5 +++-
 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td   |  1 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   |  5 
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  |  3 +++
 mlir/test/Target/LLVMIR/Import/tune-cpu.ll| 16 
 mlir/test/Target/LLVMIR/tune-cpu.mlir | 14 +++
 26 files changed, 190 insertions(+), 17 deletions(-)
 create mode 100644 flang/test/Driver/tune-cpu-fir.f90
 create mode 100644 flang/test/Lower/tune-cpu-llvm.f90
 create mode 100644 mlir/test/Target/LLVMIR/Import/tune-cpu.ll
 create mode 100644 mlir/test/Target/LLVMIR/tune-cpu.mlir

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index cfb37b3c5b474..8d49a4708aaf0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5436,6 +5436,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;
 def multi__module : Flag<["-"], "multi_module">;
 def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
@@ -6760,9 +6761,6 @@ def emit_hlfir : Flag<["-"], "emit-hlfir">, 
Group,
 
 let Visibility = [CC1Option, CC1AsOption] in {
 
-def tune_cpu : Separate<["-"], "tune-cpu">,
-  HelpText<"Tune for a specific cpu type">,
-  MarshallingInfoString>;
 def target_abi : Separate<["-"], "target-abi">,
   HelpText<"Target a particular ABI type">,
   MarshallingInfoString>;
@@ -6789,6 +6787,9 @@ def darwin_target_variant_triple : Separate<["-"], 
"darwin-target-variant-triple
 
 let Visibility = [CC1Option, CC1AsOption, FC1Option] in {
 
+def tune_cpu : Separate<["-"], "tune-cpu">,
+  HelpText<"Tune for a specific cpu type">,
+  MarshallingInfoString>;
 def target_cpu : Separate<["-"], "target-cpu">,
   HelpText<"Target a specific cpu type">,
   MarshallingInfoString>;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index ee8292a508f93..7e42bad258cc6 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -15,6 +15,7 @@
 #include "llvm/Frontend/Debug/Options.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
+#include "llvm/TargetParser/Host.h"
 #include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
 
@@ -411,6 +412,13 @@ void Flang::addTargetOptions(const ArgList ,
   }
 
   // TODO: Add target specific flags, ABI, mtune option etc.
+  if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
+CmdArgs.push_back("-tune-cpu");
+if (A->getValue() == StringRef{"native"})
+  CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
+else
+  CmdArgs.push_back(A->getValue());
+  }
 }
 
 void Flang::addOffloadOptions(Compilation , const InputInfoList ,
@@ -807,7 +815,7 @@ void Flang::ConstructJob(Compilation , const JobAction 
,
   case CodeGenOptions::FramePointerKind::None:
 FPKeepKindStr = "-mframe-pointer=none";
 break;
-   case CodeGenOptions::FramePointerKind::Reserved:
+  case CodeGenOptions::FramePointerKind::Reserved:
 FPKeepKindStr = "-mframe-pointer=reserved";
 break;
   case 

[clang] [flang] [mlir] Add basic -mtune support (PR #98517)

2024-07-11 Thread Alexis Perry-Holby via cfe-commits

https://github.com/AlexisPerry created 
https://github.com/llvm/llvm-project/pull/98517

Initial implementation for the -mtune flag in Flang.

This PR is a clean version of PR #96688, which is a re-land of PR #95043

>From 2e26f0f66f070cd0b684531efc63e63e2e584dfa Mon Sep 17 00:00:00 2001
From: Alexis Perry-Holby 
Date: Thu, 11 Jul 2024 12:51:39 -0600
Subject: [PATCH] Add basic -mtune support

Initial implementation for the -mtune flag in Flang.
---
 clang/include/clang/Driver/Options.td |  7 +++---
 clang/lib/Driver/ToolChains/Flang.cpp | 10 +++-
 flang/include/flang/Frontend/TargetOptions.h  |  3 +++
 flang/include/flang/Lower/Bridge.h|  6 ++---
 .../flang/Optimizer/CodeGen/CGPasses.td   |  4 +++
 .../include/flang/Optimizer/CodeGen/Target.h  | 21 ++--
 .../Optimizer/Dialect/Support/FIRContext.h|  7 ++
 .../flang/Optimizer/Transforms/Passes.td  |  5 +++-
 flang/lib/Frontend/CompilerInvocation.cpp |  4 +++
 flang/lib/Frontend/FrontendActions.cpp|  3 ++-
 flang/lib/Lower/Bridge.cpp|  3 ++-
 flang/lib/Optimizer/CodeGen/CodeGen.cpp   |  6 -
 flang/lib/Optimizer/CodeGen/Target.cpp| 11 
 flang/lib/Optimizer/CodeGen/TargetRewrite.cpp | 12 -
 flang/lib/Optimizer/CodeGen/TypeConverter.cpp |  3 ++-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 18 +
 flang/test/Driver/tune-cpu-fir.f90| 25 +++
 flang/test/Lower/tune-cpu-llvm.f90|  8 ++
 flang/tools/bbc/bbc.cpp   |  3 ++-
 flang/tools/tco/tco.cpp   |  4 +++
 flang/unittests/Optimizer/FIRContextTest.cpp  |  5 +++-
 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td   |  1 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   |  5 
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  |  3 +++
 mlir/test/Target/LLVMIR/Import/tune-cpu.ll| 16 
 mlir/test/Target/LLVMIR/tune-cpu.mlir | 14 +++
 26 files changed, 190 insertions(+), 17 deletions(-)
 create mode 100644 flang/test/Driver/tune-cpu-fir.f90
 create mode 100644 flang/test/Lower/tune-cpu-llvm.f90
 create mode 100644 mlir/test/Target/LLVMIR/Import/tune-cpu.ll
 create mode 100644 mlir/test/Target/LLVMIR/tune-cpu.mlir

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index cfb37b3c5b474..8d49a4708aaf0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5436,6 +5436,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;
 def multi__module : Flag<["-"], "multi_module">;
 def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
@@ -6760,9 +6761,6 @@ def emit_hlfir : Flag<["-"], "emit-hlfir">, 
Group,
 
 let Visibility = [CC1Option, CC1AsOption] in {
 
-def tune_cpu : Separate<["-"], "tune-cpu">,
-  HelpText<"Tune for a specific cpu type">,
-  MarshallingInfoString>;
 def target_abi : Separate<["-"], "target-abi">,
   HelpText<"Target a particular ABI type">,
   MarshallingInfoString>;
@@ -6789,6 +6787,9 @@ def darwin_target_variant_triple : Separate<["-"], 
"darwin-target-variant-triple
 
 let Visibility = [CC1Option, CC1AsOption, FC1Option] in {
 
+def tune_cpu : Separate<["-"], "tune-cpu">,
+  HelpText<"Tune for a specific cpu type">,
+  MarshallingInfoString>;
 def target_cpu : Separate<["-"], "target-cpu">,
   HelpText<"Target a specific cpu type">,
   MarshallingInfoString>;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index ee8292a508f93..7e42bad258cc6 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -15,6 +15,7 @@
 #include "llvm/Frontend/Debug/Options.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
+#include "llvm/TargetParser/Host.h"
 #include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
 
@@ -411,6 +412,13 @@ void Flang::addTargetOptions(const ArgList ,
   }
 
   // TODO: Add target specific flags, ABI, mtune option etc.
+  if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
+CmdArgs.push_back("-tune-cpu");
+if (A->getValue() == StringRef{"native"})
+  CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
+else
+  CmdArgs.push_back(A->getValue());
+  }
 }
 
 void Flang::addOffloadOptions(Compilation , const InputInfoList ,
@@ -807,7 +815,7 @@ void Flang::ConstructJob(Compilation , const JobAction 
,
   case CodeGenOptions::FramePointerKind::None:
 FPKeepKindStr = "-mframe-pointer=none";
 break;
-   case CodeGenOptions::FramePointerKind::Reserved:
+  case 

[clang] [flang] [mlir] [flang] Retry add basic -mtune support (PR #96688)

2024-07-02 Thread Alexis Perry-Holby via cfe-commits


@@ -0,0 +1,9 @@
+; RUN: mlir-translate -import-llvm -split-input-file %s | FileCheck %s

AlexisPerry wrote:

I have been trying to reproduce my error ever since saying I had one and have 
been unsuccessful.  It now appears that mlir-translate doesn't care about the 
target.

@banach-space  That is a much better way of doing things.  Thank you for the 
suggestion and I will make the changes.

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


[clang] [flang] [mlir] [flang] Retry add basic -mtune support (PR #96688)

2024-06-27 Thread Alexis Perry-Holby via cfe-commits


@@ -0,0 +1,9 @@
+; RUN: mlir-translate -import-llvm -split-input-file %s | FileCheck %s

AlexisPerry wrote:

I ran into failures if I didn't include the guard.  I have separate builds for 
x86 and Aarch64.

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


[clang] [flang] [mlir] [flang] Retry add basic -mtune support (PR #96688)

2024-06-27 Thread Alexis Perry-Holby via cfe-commits

https://github.com/AlexisPerry updated 
https://github.com/llvm/llvm-project/pull/96688

>From 2312d31b14aecc6eeea2e81d221ee004e5de3efc Mon Sep 17 00:00:00 2001
From: Alexis Perry-Holby 
Date: Thu, 6 Jun 2024 14:02:52 -0600
Subject: [PATCH 01/13] [flang] Add basic -mtune support

---
 clang/include/clang/Driver/Options.td |  7 ---
 clang/lib/Driver/ToolChains/Flang.cpp |  8 
 flang/include/flang/Frontend/TargetOptions.h  |  3 +++
 flang/include/flang/Lower/Bridge.h|  6 +++---
 .../flang/Optimizer/CodeGen/CGPasses.td   |  4 
 .../include/flang/Optimizer/CodeGen/Target.h  | 19 ++-
 .../Optimizer/Dialect/Support/FIRContext.h|  7 +++
 .../flang/Optimizer/Transforms/Passes.td  |  3 +++
 flang/lib/Frontend/CompilerInvocation.cpp |  4 
 flang/lib/Frontend/FrontendActions.cpp|  3 ++-
 flang/lib/Lower/Bridge.cpp|  3 ++-
 flang/lib/Optimizer/CodeGen/CodeGen.cpp   |  6 +-
 flang/lib/Optimizer/CodeGen/Target.cpp| 11 +++
 flang/lib/Optimizer/CodeGen/TargetRewrite.cpp | 12 +++-
 flang/lib/Optimizer/CodeGen/TypeConverter.cpp |  3 ++-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 18 ++
 flang/tools/bbc/bbc.cpp   |  2 +-
 flang/tools/tco/tco.cpp   |  4 
 flang/unittests/Optimizer/FIRContextTest.cpp  |  3 +++
 .../mlir/Dialect/LLVMIR/LLVMAttrDefs.td   |  9 +
 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td   |  1 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   |  5 +
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  |  3 +++
 23 files changed, 131 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..b81f480e1ed2b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5403,6 +5403,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;
 def multi__module : Flag<["-"], "multi_module">;
 def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
@@ -6722,9 +6723,6 @@ def emit_hlfir : Flag<["-"], "emit-hlfir">, 
Group,
 
 let Visibility = [CC1Option, CC1AsOption] in {
 
-def tune_cpu : Separate<["-"], "tune-cpu">,
-  HelpText<"Tune for a specific cpu type">,
-  MarshallingInfoString>;
 def target_abi : Separate<["-"], "target-abi">,
   HelpText<"Target a particular ABI type">,
   MarshallingInfoString>;
@@ -6751,6 +6749,9 @@ def darwin_target_variant_triple : Separate<["-"], 
"darwin-target-variant-triple
 
 let Visibility = [CC1Option, CC1AsOption, FC1Option] in {
 
+def tune_cpu : Separate<["-"], "tune-cpu">,
+  HelpText<"Tune for a specific cpu type">,
+  MarshallingInfoString>;
 def target_cpu : Separate<["-"], "target-cpu">,
   HelpText<"Target a specific cpu type">,
   MarshallingInfoString>;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 42b45dba2bd31..3dc7ee0ea2bff 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
+#include "llvm/TargetParser/Host.h"
 
 #include 
 
@@ -411,6 +412,13 @@ void Flang::addTargetOptions(const ArgList ,
   }
 
   // TODO: Add target specific flags, ABI, mtune option etc.
+  if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
+CmdArgs.push_back("-tune-cpu");
+if (strcmp(A->getValue(), "native") == 0)
+  CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
+else
+  CmdArgs.push_back(A->getValue());
+  }
 }
 
 void Flang::addOffloadOptions(Compilation , const InputInfoList ,
diff --git a/flang/include/flang/Frontend/TargetOptions.h 
b/flang/include/flang/Frontend/TargetOptions.h
index ef5d270a2185d..a7a7192c55cb1 100644
--- a/flang/include/flang/Frontend/TargetOptions.h
+++ b/flang/include/flang/Frontend/TargetOptions.h
@@ -32,6 +32,9 @@ class TargetOptions {
   /// If given, the name of the target CPU to generate code for.
   std::string cpu;
 
+  /// If given, the name of the target CPU to tune code for.
+  std::string tuneCPU;
+
   /// The list of target specific features to enable or disable, as written on
   /// the command line.
   std::vector featuresAsWritten;
diff --git a/flang/include/flang/Lower/Bridge.h 
b/flang/include/flang/Lower/Bridge.h
index 52110b861b680..4379ed512cdf0 100644
--- a/flang/include/flang/Lower/Bridge.h
+++ b/flang/include/flang/Lower/Bridge.h
@@ -65,11 +65,11 @@ class LoweringBridge {
  const 

[clang] [flang] [mlir] [flang] Retry add basic -mtune support (PR #96688)

2024-06-27 Thread Alexis Perry-Holby via cfe-commits


@@ -0,0 +1,7 @@
+// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s

AlexisPerry wrote:

Thanks again!  Yes, you are absolutely correct.

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


[clang] [flang] [mlir] [flang] Retry add basic -mtune support (PR #96688)

2024-06-27 Thread Alexis Perry-Holby via cfe-commits


@@ -0,0 +1,9 @@
+; RUN: mlir-translate -import-llvm -split-input-file %s | FileCheck %s

AlexisPerry wrote:

Thank you so much for the catch!  Yes, this guard is absolutely needed.

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


[clang] [flang] [mlir] [flang] Retry add basic -mtune support (PR #96688)

2024-06-25 Thread Alexis Perry-Holby via cfe-commits

https://github.com/AlexisPerry created 
https://github.com/llvm/llvm-project/pull/96688

This aims to reland the changes and fix the broken test from PR 
https://github.com/llvm/llvm-project/pull/95043

>From 2312d31b14aecc6eeea2e81d221ee004e5de3efc Mon Sep 17 00:00:00 2001
From: Alexis Perry-Holby 
Date: Thu, 6 Jun 2024 14:02:52 -0600
Subject: [PATCH 01/12] [flang] Add basic -mtune support

---
 clang/include/clang/Driver/Options.td |  7 ---
 clang/lib/Driver/ToolChains/Flang.cpp |  8 
 flang/include/flang/Frontend/TargetOptions.h  |  3 +++
 flang/include/flang/Lower/Bridge.h|  6 +++---
 .../flang/Optimizer/CodeGen/CGPasses.td   |  4 
 .../include/flang/Optimizer/CodeGen/Target.h  | 19 ++-
 .../Optimizer/Dialect/Support/FIRContext.h|  7 +++
 .../flang/Optimizer/Transforms/Passes.td  |  3 +++
 flang/lib/Frontend/CompilerInvocation.cpp |  4 
 flang/lib/Frontend/FrontendActions.cpp|  3 ++-
 flang/lib/Lower/Bridge.cpp|  3 ++-
 flang/lib/Optimizer/CodeGen/CodeGen.cpp   |  6 +-
 flang/lib/Optimizer/CodeGen/Target.cpp| 11 +++
 flang/lib/Optimizer/CodeGen/TargetRewrite.cpp | 12 +++-
 flang/lib/Optimizer/CodeGen/TypeConverter.cpp |  3 ++-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 18 ++
 flang/tools/bbc/bbc.cpp   |  2 +-
 flang/tools/tco/tco.cpp   |  4 
 flang/unittests/Optimizer/FIRContextTest.cpp  |  3 +++
 .../mlir/Dialect/LLVMIR/LLVMAttrDefs.td   |  9 +
 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td   |  1 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   |  5 +
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  |  3 +++
 23 files changed, 131 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..b81f480e1ed2b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5403,6 +5403,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;
 def multi__module : Flag<["-"], "multi_module">;
 def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
@@ -6722,9 +6723,6 @@ def emit_hlfir : Flag<["-"], "emit-hlfir">, 
Group,
 
 let Visibility = [CC1Option, CC1AsOption] in {
 
-def tune_cpu : Separate<["-"], "tune-cpu">,
-  HelpText<"Tune for a specific cpu type">,
-  MarshallingInfoString>;
 def target_abi : Separate<["-"], "target-abi">,
   HelpText<"Target a particular ABI type">,
   MarshallingInfoString>;
@@ -6751,6 +6749,9 @@ def darwin_target_variant_triple : Separate<["-"], 
"darwin-target-variant-triple
 
 let Visibility = [CC1Option, CC1AsOption, FC1Option] in {
 
+def tune_cpu : Separate<["-"], "tune-cpu">,
+  HelpText<"Tune for a specific cpu type">,
+  MarshallingInfoString>;
 def target_cpu : Separate<["-"], "target-cpu">,
   HelpText<"Target a specific cpu type">,
   MarshallingInfoString>;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 42b45dba2bd31..3dc7ee0ea2bff 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
+#include "llvm/TargetParser/Host.h"
 
 #include 
 
@@ -411,6 +412,13 @@ void Flang::addTargetOptions(const ArgList ,
   }
 
   // TODO: Add target specific flags, ABI, mtune option etc.
+  if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
+CmdArgs.push_back("-tune-cpu");
+if (strcmp(A->getValue(), "native") == 0)
+  CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
+else
+  CmdArgs.push_back(A->getValue());
+  }
 }
 
 void Flang::addOffloadOptions(Compilation , const InputInfoList ,
diff --git a/flang/include/flang/Frontend/TargetOptions.h 
b/flang/include/flang/Frontend/TargetOptions.h
index ef5d270a2185d..a7a7192c55cb1 100644
--- a/flang/include/flang/Frontend/TargetOptions.h
+++ b/flang/include/flang/Frontend/TargetOptions.h
@@ -32,6 +32,9 @@ class TargetOptions {
   /// If given, the name of the target CPU to generate code for.
   std::string cpu;
 
+  /// If given, the name of the target CPU to tune code for.
+  std::string tuneCPU;
+
   /// The list of target specific features to enable or disable, as written on
   /// the command line.
   std::vector featuresAsWritten;
diff --git a/flang/include/flang/Lower/Bridge.h 
b/flang/include/flang/Lower/Bridge.h
index 52110b861b680..4379ed512cdf0 100644
--- a/flang/include/flang/Lower/Bridge.h
+++ 

[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-25 Thread Alexis Perry-Holby via cfe-commits

AlexisPerry wrote:

I believe I've addressed all the review comments and all the checks have 
passed.  Could someone with commit access please merge this on my behalf?  
Thank you.

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


[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-24 Thread Alexis Perry-Holby via cfe-commits




AlexisPerry wrote:

Thanks for explaining more thoroughly.  I have moved the test to the Driver 
directory as requested.

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


[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-24 Thread Alexis Perry-Holby via cfe-commits

https://github.com/AlexisPerry updated 
https://github.com/llvm/llvm-project/pull/95043

>From 2312d31b14aecc6eeea2e81d221ee004e5de3efc Mon Sep 17 00:00:00 2001
From: Alexis Perry-Holby 
Date: Thu, 6 Jun 2024 14:02:52 -0600
Subject: [PATCH 01/11] [flang] Add basic -mtune support

---
 clang/include/clang/Driver/Options.td |  7 ---
 clang/lib/Driver/ToolChains/Flang.cpp |  8 
 flang/include/flang/Frontend/TargetOptions.h  |  3 +++
 flang/include/flang/Lower/Bridge.h|  6 +++---
 .../flang/Optimizer/CodeGen/CGPasses.td   |  4 
 .../include/flang/Optimizer/CodeGen/Target.h  | 19 ++-
 .../Optimizer/Dialect/Support/FIRContext.h|  7 +++
 .../flang/Optimizer/Transforms/Passes.td  |  3 +++
 flang/lib/Frontend/CompilerInvocation.cpp |  4 
 flang/lib/Frontend/FrontendActions.cpp|  3 ++-
 flang/lib/Lower/Bridge.cpp|  3 ++-
 flang/lib/Optimizer/CodeGen/CodeGen.cpp   |  6 +-
 flang/lib/Optimizer/CodeGen/Target.cpp| 11 +++
 flang/lib/Optimizer/CodeGen/TargetRewrite.cpp | 12 +++-
 flang/lib/Optimizer/CodeGen/TypeConverter.cpp |  3 ++-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 18 ++
 flang/tools/bbc/bbc.cpp   |  2 +-
 flang/tools/tco/tco.cpp   |  4 
 flang/unittests/Optimizer/FIRContextTest.cpp  |  3 +++
 .../mlir/Dialect/LLVMIR/LLVMAttrDefs.td   |  9 +
 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td   |  1 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   |  5 +
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  |  3 +++
 23 files changed, 131 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..b81f480e1ed2b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5403,6 +5403,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;
 def multi__module : Flag<["-"], "multi_module">;
 def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
@@ -6722,9 +6723,6 @@ def emit_hlfir : Flag<["-"], "emit-hlfir">, 
Group,
 
 let Visibility = [CC1Option, CC1AsOption] in {
 
-def tune_cpu : Separate<["-"], "tune-cpu">,
-  HelpText<"Tune for a specific cpu type">,
-  MarshallingInfoString>;
 def target_abi : Separate<["-"], "target-abi">,
   HelpText<"Target a particular ABI type">,
   MarshallingInfoString>;
@@ -6751,6 +6749,9 @@ def darwin_target_variant_triple : Separate<["-"], 
"darwin-target-variant-triple
 
 let Visibility = [CC1Option, CC1AsOption, FC1Option] in {
 
+def tune_cpu : Separate<["-"], "tune-cpu">,
+  HelpText<"Tune for a specific cpu type">,
+  MarshallingInfoString>;
 def target_cpu : Separate<["-"], "target-cpu">,
   HelpText<"Target a specific cpu type">,
   MarshallingInfoString>;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 42b45dba2bd31..3dc7ee0ea2bff 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
+#include "llvm/TargetParser/Host.h"
 
 #include 
 
@@ -411,6 +412,13 @@ void Flang::addTargetOptions(const ArgList ,
   }
 
   // TODO: Add target specific flags, ABI, mtune option etc.
+  if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
+CmdArgs.push_back("-tune-cpu");
+if (strcmp(A->getValue(), "native") == 0)
+  CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
+else
+  CmdArgs.push_back(A->getValue());
+  }
 }
 
 void Flang::addOffloadOptions(Compilation , const InputInfoList ,
diff --git a/flang/include/flang/Frontend/TargetOptions.h 
b/flang/include/flang/Frontend/TargetOptions.h
index ef5d270a2185d..a7a7192c55cb1 100644
--- a/flang/include/flang/Frontend/TargetOptions.h
+++ b/flang/include/flang/Frontend/TargetOptions.h
@@ -32,6 +32,9 @@ class TargetOptions {
   /// If given, the name of the target CPU to generate code for.
   std::string cpu;
 
+  /// If given, the name of the target CPU to tune code for.
+  std::string tuneCPU;
+
   /// The list of target specific features to enable or disable, as written on
   /// the command line.
   std::vector featuresAsWritten;
diff --git a/flang/include/flang/Lower/Bridge.h 
b/flang/include/flang/Lower/Bridge.h
index 52110b861b680..4379ed512cdf0 100644
--- a/flang/include/flang/Lower/Bridge.h
+++ b/flang/include/flang/Lower/Bridge.h
@@ -65,11 +65,11 @@ class LoweringBridge {
  const 

[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-24 Thread Alexis Perry-Holby via cfe-commits


@@ -0,0 +1,9 @@
+; RUN: mlir-translate -import-llvm -split-input-file %s | FileCheck %s
+
+; CHECK-LABEL: llvm.func @tune_cpu()
+; CHECK-SAME: tune_cpu = "pentium4"

AlexisPerry wrote:

Alright, after some digging, I can confirm that `tune-cpu` is listed among the 
`kExplicitAttributes` and that these attributes are expressly excluded from 
being added to the passthrough dictionary based on the code in 
`processPassthroughAttrs` in `ModuleImport.cpp`.

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


[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-20 Thread Alexis Perry-Holby via cfe-commits

AlexisPerry wrote:

I have lost my upstream commit privileges due to inactivity, so once this is 
fully approved, could someone merge it on my behalf?  Thank you.

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


[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-20 Thread Alexis Perry-Holby via cfe-commits

https://github.com/AlexisPerry updated 
https://github.com/llvm/llvm-project/pull/95043

>From 2312d31b14aecc6eeea2e81d221ee004e5de3efc Mon Sep 17 00:00:00 2001
From: Alexis Perry-Holby 
Date: Thu, 6 Jun 2024 14:02:52 -0600
Subject: [PATCH 01/10] [flang] Add basic -mtune support

---
 clang/include/clang/Driver/Options.td |  7 ---
 clang/lib/Driver/ToolChains/Flang.cpp |  8 
 flang/include/flang/Frontend/TargetOptions.h  |  3 +++
 flang/include/flang/Lower/Bridge.h|  6 +++---
 .../flang/Optimizer/CodeGen/CGPasses.td   |  4 
 .../include/flang/Optimizer/CodeGen/Target.h  | 19 ++-
 .../Optimizer/Dialect/Support/FIRContext.h|  7 +++
 .../flang/Optimizer/Transforms/Passes.td  |  3 +++
 flang/lib/Frontend/CompilerInvocation.cpp |  4 
 flang/lib/Frontend/FrontendActions.cpp|  3 ++-
 flang/lib/Lower/Bridge.cpp|  3 ++-
 flang/lib/Optimizer/CodeGen/CodeGen.cpp   |  6 +-
 flang/lib/Optimizer/CodeGen/Target.cpp| 11 +++
 flang/lib/Optimizer/CodeGen/TargetRewrite.cpp | 12 +++-
 flang/lib/Optimizer/CodeGen/TypeConverter.cpp |  3 ++-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 18 ++
 flang/tools/bbc/bbc.cpp   |  2 +-
 flang/tools/tco/tco.cpp   |  4 
 flang/unittests/Optimizer/FIRContextTest.cpp  |  3 +++
 .../mlir/Dialect/LLVMIR/LLVMAttrDefs.td   |  9 +
 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td   |  1 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   |  5 +
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  |  3 +++
 23 files changed, 131 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..b81f480e1ed2b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5403,6 +5403,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;
 def multi__module : Flag<["-"], "multi_module">;
 def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
@@ -6722,9 +6723,6 @@ def emit_hlfir : Flag<["-"], "emit-hlfir">, 
Group,
 
 let Visibility = [CC1Option, CC1AsOption] in {
 
-def tune_cpu : Separate<["-"], "tune-cpu">,
-  HelpText<"Tune for a specific cpu type">,
-  MarshallingInfoString>;
 def target_abi : Separate<["-"], "target-abi">,
   HelpText<"Target a particular ABI type">,
   MarshallingInfoString>;
@@ -6751,6 +6749,9 @@ def darwin_target_variant_triple : Separate<["-"], 
"darwin-target-variant-triple
 
 let Visibility = [CC1Option, CC1AsOption, FC1Option] in {
 
+def tune_cpu : Separate<["-"], "tune-cpu">,
+  HelpText<"Tune for a specific cpu type">,
+  MarshallingInfoString>;
 def target_cpu : Separate<["-"], "target-cpu">,
   HelpText<"Target a specific cpu type">,
   MarshallingInfoString>;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 42b45dba2bd31..3dc7ee0ea2bff 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
+#include "llvm/TargetParser/Host.h"
 
 #include 
 
@@ -411,6 +412,13 @@ void Flang::addTargetOptions(const ArgList ,
   }
 
   // TODO: Add target specific flags, ABI, mtune option etc.
+  if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
+CmdArgs.push_back("-tune-cpu");
+if (strcmp(A->getValue(), "native") == 0)
+  CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
+else
+  CmdArgs.push_back(A->getValue());
+  }
 }
 
 void Flang::addOffloadOptions(Compilation , const InputInfoList ,
diff --git a/flang/include/flang/Frontend/TargetOptions.h 
b/flang/include/flang/Frontend/TargetOptions.h
index ef5d270a2185d..a7a7192c55cb1 100644
--- a/flang/include/flang/Frontend/TargetOptions.h
+++ b/flang/include/flang/Frontend/TargetOptions.h
@@ -32,6 +32,9 @@ class TargetOptions {
   /// If given, the name of the target CPU to generate code for.
   std::string cpu;
 
+  /// If given, the name of the target CPU to tune code for.
+  std::string tuneCPU;
+
   /// The list of target specific features to enable or disable, as written on
   /// the command line.
   std::vector featuresAsWritten;
diff --git a/flang/include/flang/Lower/Bridge.h 
b/flang/include/flang/Lower/Bridge.h
index 52110b861b680..4379ed512cdf0 100644
--- a/flang/include/flang/Lower/Bridge.h
+++ b/flang/include/flang/Lower/Bridge.h
@@ -65,11 +65,11 @@ class LoweringBridge {
  const 

[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-20 Thread Alexis Perry-Holby via cfe-commits

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


[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-20 Thread Alexis Perry-Holby via cfe-commits




AlexisPerry wrote:

I hear you.  I modeled this test closely after target-features-*.f90 in that 
same directory, which is why I put it in flang/test/Lower.  I am willing to 
move it to flang/test/Driver, but if I do so should I also move the 
target-features-*.f90 tests?  Thank you so much.

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


[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-20 Thread Alexis Perry-Holby via cfe-commits


@@ -411,6 +412,13 @@ void Flang::addTargetOptions(const ArgList ,
   }
 
   // TODO: Add target specific flags, ABI, mtune option etc.
+  if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
+CmdArgs.push_back("-tune-cpu");
+if (strcmp(A->getValue(), "native") == 0)

AlexisPerry wrote:

Thank you for that!  I have made the requested update and there was no build 
warning.

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


[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-20 Thread Alexis Perry-Holby via cfe-commits


@@ -0,0 +1,9 @@
+; RUN: mlir-translate -import-llvm -split-input-file %s | FileCheck %s
+
+; CHECK-LABEL: llvm.func @tune_cpu()
+; CHECK-SAME: tune_cpu = "pentium4"

AlexisPerry wrote:

>From what I can see, L1685 of ModuleImport.cpp has tune-cpu listed among the 
>ExplicitAttributes.  Is this sufficient?  Or is further checking needed?  
>Thank you so much.

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


[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-12 Thread Alexis Perry-Holby via cfe-commits

https://github.com/AlexisPerry updated 
https://github.com/llvm/llvm-project/pull/95043

>From 2312d31b14aecc6eeea2e81d221ee004e5de3efc Mon Sep 17 00:00:00 2001
From: Alexis Perry-Holby 
Date: Thu, 6 Jun 2024 14:02:52 -0600
Subject: [PATCH 1/9] [flang] Add basic -mtune support

---
 clang/include/clang/Driver/Options.td |  7 ---
 clang/lib/Driver/ToolChains/Flang.cpp |  8 
 flang/include/flang/Frontend/TargetOptions.h  |  3 +++
 flang/include/flang/Lower/Bridge.h|  6 +++---
 .../flang/Optimizer/CodeGen/CGPasses.td   |  4 
 .../include/flang/Optimizer/CodeGen/Target.h  | 19 ++-
 .../Optimizer/Dialect/Support/FIRContext.h|  7 +++
 .../flang/Optimizer/Transforms/Passes.td  |  3 +++
 flang/lib/Frontend/CompilerInvocation.cpp |  4 
 flang/lib/Frontend/FrontendActions.cpp|  3 ++-
 flang/lib/Lower/Bridge.cpp|  3 ++-
 flang/lib/Optimizer/CodeGen/CodeGen.cpp   |  6 +-
 flang/lib/Optimizer/CodeGen/Target.cpp| 11 +++
 flang/lib/Optimizer/CodeGen/TargetRewrite.cpp | 12 +++-
 flang/lib/Optimizer/CodeGen/TypeConverter.cpp |  3 ++-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 18 ++
 flang/tools/bbc/bbc.cpp   |  2 +-
 flang/tools/tco/tco.cpp   |  4 
 flang/unittests/Optimizer/FIRContextTest.cpp  |  3 +++
 .../mlir/Dialect/LLVMIR/LLVMAttrDefs.td   |  9 +
 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td   |  1 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   |  5 +
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  |  3 +++
 23 files changed, 131 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..b81f480e1ed2b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5403,6 +5403,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;
 def multi__module : Flag<["-"], "multi_module">;
 def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
@@ -6722,9 +6723,6 @@ def emit_hlfir : Flag<["-"], "emit-hlfir">, 
Group,
 
 let Visibility = [CC1Option, CC1AsOption] in {
 
-def tune_cpu : Separate<["-"], "tune-cpu">,
-  HelpText<"Tune for a specific cpu type">,
-  MarshallingInfoString>;
 def target_abi : Separate<["-"], "target-abi">,
   HelpText<"Target a particular ABI type">,
   MarshallingInfoString>;
@@ -6751,6 +6749,9 @@ def darwin_target_variant_triple : Separate<["-"], 
"darwin-target-variant-triple
 
 let Visibility = [CC1Option, CC1AsOption, FC1Option] in {
 
+def tune_cpu : Separate<["-"], "tune-cpu">,
+  HelpText<"Tune for a specific cpu type">,
+  MarshallingInfoString>;
 def target_cpu : Separate<["-"], "target-cpu">,
   HelpText<"Target a specific cpu type">,
   MarshallingInfoString>;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 42b45dba2bd31..3dc7ee0ea2bff 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
+#include "llvm/TargetParser/Host.h"
 
 #include 
 
@@ -411,6 +412,13 @@ void Flang::addTargetOptions(const ArgList ,
   }
 
   // TODO: Add target specific flags, ABI, mtune option etc.
+  if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
+CmdArgs.push_back("-tune-cpu");
+if (strcmp(A->getValue(), "native") == 0)
+  CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
+else
+  CmdArgs.push_back(A->getValue());
+  }
 }
 
 void Flang::addOffloadOptions(Compilation , const InputInfoList ,
diff --git a/flang/include/flang/Frontend/TargetOptions.h 
b/flang/include/flang/Frontend/TargetOptions.h
index ef5d270a2185d..a7a7192c55cb1 100644
--- a/flang/include/flang/Frontend/TargetOptions.h
+++ b/flang/include/flang/Frontend/TargetOptions.h
@@ -32,6 +32,9 @@ class TargetOptions {
   /// If given, the name of the target CPU to generate code for.
   std::string cpu;
 
+  /// If given, the name of the target CPU to tune code for.
+  std::string tuneCPU;
+
   /// The list of target specific features to enable or disable, as written on
   /// the command line.
   std::vector featuresAsWritten;
diff --git a/flang/include/flang/Lower/Bridge.h 
b/flang/include/flang/Lower/Bridge.h
index 52110b861b680..4379ed512cdf0 100644
--- a/flang/include/flang/Lower/Bridge.h
+++ b/flang/include/flang/Lower/Bridge.h
@@ -65,11 +65,11 @@ class LoweringBridge {
  const 

[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-12 Thread Alexis Perry-Holby via cfe-commits


@@ -371,7 +371,7 @@ static mlir::LogicalResult convertFortranSourceToMLIR(
   ctx, semanticsContext, defKinds, semanticsContext.intrinsics(),
   semanticsContext.targetCharacteristics(), parsing.allCooked(),
   targetTriple, kindMap, loweringOptions, envDefaults,
-  semanticsContext.languageFeatures(), targetMachine);
+  semanticsContext.languageFeatures(), targetMachine, "");

AlexisPerry wrote:

Thank you Tarun, I think that's a much better way to do this. I have made the 
change.

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


[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-12 Thread Alexis Perry-Holby via cfe-commits

https://github.com/AlexisPerry updated 
https://github.com/llvm/llvm-project/pull/95043

>From 2312d31b14aecc6eeea2e81d221ee004e5de3efc Mon Sep 17 00:00:00 2001
From: Alexis Perry-Holby 
Date: Thu, 6 Jun 2024 14:02:52 -0600
Subject: [PATCH 1/8] [flang] Add basic -mtune support

---
 clang/include/clang/Driver/Options.td |  7 ---
 clang/lib/Driver/ToolChains/Flang.cpp |  8 
 flang/include/flang/Frontend/TargetOptions.h  |  3 +++
 flang/include/flang/Lower/Bridge.h|  6 +++---
 .../flang/Optimizer/CodeGen/CGPasses.td   |  4 
 .../include/flang/Optimizer/CodeGen/Target.h  | 19 ++-
 .../Optimizer/Dialect/Support/FIRContext.h|  7 +++
 .../flang/Optimizer/Transforms/Passes.td  |  3 +++
 flang/lib/Frontend/CompilerInvocation.cpp |  4 
 flang/lib/Frontend/FrontendActions.cpp|  3 ++-
 flang/lib/Lower/Bridge.cpp|  3 ++-
 flang/lib/Optimizer/CodeGen/CodeGen.cpp   |  6 +-
 flang/lib/Optimizer/CodeGen/Target.cpp| 11 +++
 flang/lib/Optimizer/CodeGen/TargetRewrite.cpp | 12 +++-
 flang/lib/Optimizer/CodeGen/TypeConverter.cpp |  3 ++-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 18 ++
 flang/tools/bbc/bbc.cpp   |  2 +-
 flang/tools/tco/tco.cpp   |  4 
 flang/unittests/Optimizer/FIRContextTest.cpp  |  3 +++
 .../mlir/Dialect/LLVMIR/LLVMAttrDefs.td   |  9 +
 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td   |  1 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   |  5 +
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  |  3 +++
 23 files changed, 131 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..b81f480e1ed2b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5403,6 +5403,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;
 def multi__module : Flag<["-"], "multi_module">;
 def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
@@ -6722,9 +6723,6 @@ def emit_hlfir : Flag<["-"], "emit-hlfir">, 
Group,
 
 let Visibility = [CC1Option, CC1AsOption] in {
 
-def tune_cpu : Separate<["-"], "tune-cpu">,
-  HelpText<"Tune for a specific cpu type">,
-  MarshallingInfoString>;
 def target_abi : Separate<["-"], "target-abi">,
   HelpText<"Target a particular ABI type">,
   MarshallingInfoString>;
@@ -6751,6 +6749,9 @@ def darwin_target_variant_triple : Separate<["-"], 
"darwin-target-variant-triple
 
 let Visibility = [CC1Option, CC1AsOption, FC1Option] in {
 
+def tune_cpu : Separate<["-"], "tune-cpu">,
+  HelpText<"Tune for a specific cpu type">,
+  MarshallingInfoString>;
 def target_cpu : Separate<["-"], "target-cpu">,
   HelpText<"Target a specific cpu type">,
   MarshallingInfoString>;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 42b45dba2bd31..3dc7ee0ea2bff 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
+#include "llvm/TargetParser/Host.h"
 
 #include 
 
@@ -411,6 +412,13 @@ void Flang::addTargetOptions(const ArgList ,
   }
 
   // TODO: Add target specific flags, ABI, mtune option etc.
+  if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
+CmdArgs.push_back("-tune-cpu");
+if (strcmp(A->getValue(), "native") == 0)
+  CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
+else
+  CmdArgs.push_back(A->getValue());
+  }
 }
 
 void Flang::addOffloadOptions(Compilation , const InputInfoList ,
diff --git a/flang/include/flang/Frontend/TargetOptions.h 
b/flang/include/flang/Frontend/TargetOptions.h
index ef5d270a2185d..a7a7192c55cb1 100644
--- a/flang/include/flang/Frontend/TargetOptions.h
+++ b/flang/include/flang/Frontend/TargetOptions.h
@@ -32,6 +32,9 @@ class TargetOptions {
   /// If given, the name of the target CPU to generate code for.
   std::string cpu;
 
+  /// If given, the name of the target CPU to tune code for.
+  std::string tuneCPU;
+
   /// The list of target specific features to enable or disable, as written on
   /// the command line.
   std::vector featuresAsWritten;
diff --git a/flang/include/flang/Lower/Bridge.h 
b/flang/include/flang/Lower/Bridge.h
index 52110b861b680..4379ed512cdf0 100644
--- a/flang/include/flang/Lower/Bridge.h
+++ b/flang/include/flang/Lower/Bridge.h
@@ -65,11 +65,11 @@ class LoweringBridge {
  const 

[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-12 Thread Alexis Perry-Holby via cfe-commits


@@ -1796,6 +1797,10 @@ void 
ModuleImport::processFunctionAttributes(llvm::Function *func,
   attr.isStringAttribute())
 funcOp.setTargetCpuAttr(StringAttr::get(context, attr.getValueAsString()));
 
+  if (llvm::Attribute attr = func->getFnAttribute("tune-cpu");
+  attr.isStringAttribute())
+funcOp.setTuneCpuAttr(StringAttr::get(context, attr.getValueAsString()));

AlexisPerry wrote:

Thank you so much for this suggestion and for the pointers for how to do this 
kind of test.  I was struggling to figure out the proper mechanism and you 
helped greatly.  I have added two separate tests for tune-cpu instead of 
combining with the target-cpu ones because I think it's cleaner, but I am happy 
to combine if you prefer. Just let me know.  Thanks again for your help! 

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


[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-12 Thread Alexis Perry-Holby via cfe-commits

https://github.com/AlexisPerry updated 
https://github.com/llvm/llvm-project/pull/95043

>From 2312d31b14aecc6eeea2e81d221ee004e5de3efc Mon Sep 17 00:00:00 2001
From: Alexis Perry-Holby 
Date: Thu, 6 Jun 2024 14:02:52 -0600
Subject: [PATCH 1/7] [flang] Add basic -mtune support

---
 clang/include/clang/Driver/Options.td |  7 ---
 clang/lib/Driver/ToolChains/Flang.cpp |  8 
 flang/include/flang/Frontend/TargetOptions.h  |  3 +++
 flang/include/flang/Lower/Bridge.h|  6 +++---
 .../flang/Optimizer/CodeGen/CGPasses.td   |  4 
 .../include/flang/Optimizer/CodeGen/Target.h  | 19 ++-
 .../Optimizer/Dialect/Support/FIRContext.h|  7 +++
 .../flang/Optimizer/Transforms/Passes.td  |  3 +++
 flang/lib/Frontend/CompilerInvocation.cpp |  4 
 flang/lib/Frontend/FrontendActions.cpp|  3 ++-
 flang/lib/Lower/Bridge.cpp|  3 ++-
 flang/lib/Optimizer/CodeGen/CodeGen.cpp   |  6 +-
 flang/lib/Optimizer/CodeGen/Target.cpp| 11 +++
 flang/lib/Optimizer/CodeGen/TargetRewrite.cpp | 12 +++-
 flang/lib/Optimizer/CodeGen/TypeConverter.cpp |  3 ++-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 18 ++
 flang/tools/bbc/bbc.cpp   |  2 +-
 flang/tools/tco/tco.cpp   |  4 
 flang/unittests/Optimizer/FIRContextTest.cpp  |  3 +++
 .../mlir/Dialect/LLVMIR/LLVMAttrDefs.td   |  9 +
 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td   |  1 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   |  5 +
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  |  3 +++
 23 files changed, 131 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..b81f480e1ed2b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5403,6 +5403,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;
 def multi__module : Flag<["-"], "multi_module">;
 def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
@@ -6722,9 +6723,6 @@ def emit_hlfir : Flag<["-"], "emit-hlfir">, 
Group,
 
 let Visibility = [CC1Option, CC1AsOption] in {
 
-def tune_cpu : Separate<["-"], "tune-cpu">,
-  HelpText<"Tune for a specific cpu type">,
-  MarshallingInfoString>;
 def target_abi : Separate<["-"], "target-abi">,
   HelpText<"Target a particular ABI type">,
   MarshallingInfoString>;
@@ -6751,6 +6749,9 @@ def darwin_target_variant_triple : Separate<["-"], 
"darwin-target-variant-triple
 
 let Visibility = [CC1Option, CC1AsOption, FC1Option] in {
 
+def tune_cpu : Separate<["-"], "tune-cpu">,
+  HelpText<"Tune for a specific cpu type">,
+  MarshallingInfoString>;
 def target_cpu : Separate<["-"], "target-cpu">,
   HelpText<"Target a specific cpu type">,
   MarshallingInfoString>;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 42b45dba2bd31..3dc7ee0ea2bff 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
+#include "llvm/TargetParser/Host.h"
 
 #include 
 
@@ -411,6 +412,13 @@ void Flang::addTargetOptions(const ArgList ,
   }
 
   // TODO: Add target specific flags, ABI, mtune option etc.
+  if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
+CmdArgs.push_back("-tune-cpu");
+if (strcmp(A->getValue(), "native") == 0)
+  CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
+else
+  CmdArgs.push_back(A->getValue());
+  }
 }
 
 void Flang::addOffloadOptions(Compilation , const InputInfoList ,
diff --git a/flang/include/flang/Frontend/TargetOptions.h 
b/flang/include/flang/Frontend/TargetOptions.h
index ef5d270a2185d..a7a7192c55cb1 100644
--- a/flang/include/flang/Frontend/TargetOptions.h
+++ b/flang/include/flang/Frontend/TargetOptions.h
@@ -32,6 +32,9 @@ class TargetOptions {
   /// If given, the name of the target CPU to generate code for.
   std::string cpu;
 
+  /// If given, the name of the target CPU to tune code for.
+  std::string tuneCPU;
+
   /// The list of target specific features to enable or disable, as written on
   /// the command line.
   std::vector featuresAsWritten;
diff --git a/flang/include/flang/Lower/Bridge.h 
b/flang/include/flang/Lower/Bridge.h
index 52110b861b680..4379ed512cdf0 100644
--- a/flang/include/flang/Lower/Bridge.h
+++ b/flang/include/flang/Lower/Bridge.h
@@ -65,11 +65,11 @@ class LoweringBridge {
  const 

[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-12 Thread Alexis Perry-Holby via cfe-commits


@@ -32,6 +32,9 @@ class TargetOptions {
   /// If given, the name of the target CPU to generate code for.
   std::string cpu;
 
+  /// If given, the name of the target CPU to tune code for.
+  std::string tuneCPU;

AlexisPerry wrote:

Thank you for the suggestion.  I have made the change. :-)

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


[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-12 Thread Alexis Perry-Holby via cfe-commits

https://github.com/AlexisPerry updated 
https://github.com/llvm/llvm-project/pull/95043

>From 2312d31b14aecc6eeea2e81d221ee004e5de3efc Mon Sep 17 00:00:00 2001
From: Alexis Perry-Holby 
Date: Thu, 6 Jun 2024 14:02:52 -0600
Subject: [PATCH 1/6] [flang] Add basic -mtune support

---
 clang/include/clang/Driver/Options.td |  7 ---
 clang/lib/Driver/ToolChains/Flang.cpp |  8 
 flang/include/flang/Frontend/TargetOptions.h  |  3 +++
 flang/include/flang/Lower/Bridge.h|  6 +++---
 .../flang/Optimizer/CodeGen/CGPasses.td   |  4 
 .../include/flang/Optimizer/CodeGen/Target.h  | 19 ++-
 .../Optimizer/Dialect/Support/FIRContext.h|  7 +++
 .../flang/Optimizer/Transforms/Passes.td  |  3 +++
 flang/lib/Frontend/CompilerInvocation.cpp |  4 
 flang/lib/Frontend/FrontendActions.cpp|  3 ++-
 flang/lib/Lower/Bridge.cpp|  3 ++-
 flang/lib/Optimizer/CodeGen/CodeGen.cpp   |  6 +-
 flang/lib/Optimizer/CodeGen/Target.cpp| 11 +++
 flang/lib/Optimizer/CodeGen/TargetRewrite.cpp | 12 +++-
 flang/lib/Optimizer/CodeGen/TypeConverter.cpp |  3 ++-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 18 ++
 flang/tools/bbc/bbc.cpp   |  2 +-
 flang/tools/tco/tco.cpp   |  4 
 flang/unittests/Optimizer/FIRContextTest.cpp  |  3 +++
 .../mlir/Dialect/LLVMIR/LLVMAttrDefs.td   |  9 +
 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td   |  1 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   |  5 +
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  |  3 +++
 23 files changed, 131 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..b81f480e1ed2b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5403,6 +5403,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;
 def multi__module : Flag<["-"], "multi_module">;
 def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
@@ -6722,9 +6723,6 @@ def emit_hlfir : Flag<["-"], "emit-hlfir">, 
Group,
 
 let Visibility = [CC1Option, CC1AsOption] in {
 
-def tune_cpu : Separate<["-"], "tune-cpu">,
-  HelpText<"Tune for a specific cpu type">,
-  MarshallingInfoString>;
 def target_abi : Separate<["-"], "target-abi">,
   HelpText<"Target a particular ABI type">,
   MarshallingInfoString>;
@@ -6751,6 +6749,9 @@ def darwin_target_variant_triple : Separate<["-"], 
"darwin-target-variant-triple
 
 let Visibility = [CC1Option, CC1AsOption, FC1Option] in {
 
+def tune_cpu : Separate<["-"], "tune-cpu">,
+  HelpText<"Tune for a specific cpu type">,
+  MarshallingInfoString>;
 def target_cpu : Separate<["-"], "target-cpu">,
   HelpText<"Target a specific cpu type">,
   MarshallingInfoString>;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 42b45dba2bd31..3dc7ee0ea2bff 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
+#include "llvm/TargetParser/Host.h"
 
 #include 
 
@@ -411,6 +412,13 @@ void Flang::addTargetOptions(const ArgList ,
   }
 
   // TODO: Add target specific flags, ABI, mtune option etc.
+  if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
+CmdArgs.push_back("-tune-cpu");
+if (strcmp(A->getValue(), "native") == 0)
+  CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
+else
+  CmdArgs.push_back(A->getValue());
+  }
 }
 
 void Flang::addOffloadOptions(Compilation , const InputInfoList ,
diff --git a/flang/include/flang/Frontend/TargetOptions.h 
b/flang/include/flang/Frontend/TargetOptions.h
index ef5d270a2185d..a7a7192c55cb1 100644
--- a/flang/include/flang/Frontend/TargetOptions.h
+++ b/flang/include/flang/Frontend/TargetOptions.h
@@ -32,6 +32,9 @@ class TargetOptions {
   /// If given, the name of the target CPU to generate code for.
   std::string cpu;
 
+  /// If given, the name of the target CPU to tune code for.
+  std::string tuneCPU;
+
   /// The list of target specific features to enable or disable, as written on
   /// the command line.
   std::vector featuresAsWritten;
diff --git a/flang/include/flang/Lower/Bridge.h 
b/flang/include/flang/Lower/Bridge.h
index 52110b861b680..4379ed512cdf0 100644
--- a/flang/include/flang/Lower/Bridge.h
+++ b/flang/include/flang/Lower/Bridge.h
@@ -65,11 +65,11 @@ class LoweringBridge {
  const 

[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-12 Thread Alexis Perry-Holby via cfe-commits




AlexisPerry wrote:

Those are great suggestions, thank you.  I have made the appropriate updates.

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


[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-12 Thread Alexis Perry-Holby via cfe-commits




AlexisPerry wrote:

Thank you for the catch! Yes, the CPU-NOT line was missing.  I have rectified 
this.

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


[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-12 Thread Alexis Perry-Holby via cfe-commits

https://github.com/AlexisPerry updated 
https://github.com/llvm/llvm-project/pull/95043

>From 2312d31b14aecc6eeea2e81d221ee004e5de3efc Mon Sep 17 00:00:00 2001
From: Alexis Perry-Holby 
Date: Thu, 6 Jun 2024 14:02:52 -0600
Subject: [PATCH 1/5] [flang] Add basic -mtune support

---
 clang/include/clang/Driver/Options.td |  7 ---
 clang/lib/Driver/ToolChains/Flang.cpp |  8 
 flang/include/flang/Frontend/TargetOptions.h  |  3 +++
 flang/include/flang/Lower/Bridge.h|  6 +++---
 .../flang/Optimizer/CodeGen/CGPasses.td   |  4 
 .../include/flang/Optimizer/CodeGen/Target.h  | 19 ++-
 .../Optimizer/Dialect/Support/FIRContext.h|  7 +++
 .../flang/Optimizer/Transforms/Passes.td  |  3 +++
 flang/lib/Frontend/CompilerInvocation.cpp |  4 
 flang/lib/Frontend/FrontendActions.cpp|  3 ++-
 flang/lib/Lower/Bridge.cpp|  3 ++-
 flang/lib/Optimizer/CodeGen/CodeGen.cpp   |  6 +-
 flang/lib/Optimizer/CodeGen/Target.cpp| 11 +++
 flang/lib/Optimizer/CodeGen/TargetRewrite.cpp | 12 +++-
 flang/lib/Optimizer/CodeGen/TypeConverter.cpp |  3 ++-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 18 ++
 flang/tools/bbc/bbc.cpp   |  2 +-
 flang/tools/tco/tco.cpp   |  4 
 flang/unittests/Optimizer/FIRContextTest.cpp  |  3 +++
 .../mlir/Dialect/LLVMIR/LLVMAttrDefs.td   |  9 +
 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td   |  1 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   |  5 +
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  |  3 +++
 23 files changed, 131 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..b81f480e1ed2b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5403,6 +5403,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;
 def multi__module : Flag<["-"], "multi_module">;
 def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
@@ -6722,9 +6723,6 @@ def emit_hlfir : Flag<["-"], "emit-hlfir">, 
Group,
 
 let Visibility = [CC1Option, CC1AsOption] in {
 
-def tune_cpu : Separate<["-"], "tune-cpu">,
-  HelpText<"Tune for a specific cpu type">,
-  MarshallingInfoString>;
 def target_abi : Separate<["-"], "target-abi">,
   HelpText<"Target a particular ABI type">,
   MarshallingInfoString>;
@@ -6751,6 +6749,9 @@ def darwin_target_variant_triple : Separate<["-"], 
"darwin-target-variant-triple
 
 let Visibility = [CC1Option, CC1AsOption, FC1Option] in {
 
+def tune_cpu : Separate<["-"], "tune-cpu">,
+  HelpText<"Tune for a specific cpu type">,
+  MarshallingInfoString>;
 def target_cpu : Separate<["-"], "target-cpu">,
   HelpText<"Target a specific cpu type">,
   MarshallingInfoString>;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 42b45dba2bd31..3dc7ee0ea2bff 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
+#include "llvm/TargetParser/Host.h"
 
 #include 
 
@@ -411,6 +412,13 @@ void Flang::addTargetOptions(const ArgList ,
   }
 
   // TODO: Add target specific flags, ABI, mtune option etc.
+  if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
+CmdArgs.push_back("-tune-cpu");
+if (strcmp(A->getValue(), "native") == 0)
+  CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
+else
+  CmdArgs.push_back(A->getValue());
+  }
 }
 
 void Flang::addOffloadOptions(Compilation , const InputInfoList ,
diff --git a/flang/include/flang/Frontend/TargetOptions.h 
b/flang/include/flang/Frontend/TargetOptions.h
index ef5d270a2185d..a7a7192c55cb1 100644
--- a/flang/include/flang/Frontend/TargetOptions.h
+++ b/flang/include/flang/Frontend/TargetOptions.h
@@ -32,6 +32,9 @@ class TargetOptions {
   /// If given, the name of the target CPU to generate code for.
   std::string cpu;
 
+  /// If given, the name of the target CPU to tune code for.
+  std::string tuneCPU;
+
   /// The list of target specific features to enable or disable, as written on
   /// the command line.
   std::vector featuresAsWritten;
diff --git a/flang/include/flang/Lower/Bridge.h 
b/flang/include/flang/Lower/Bridge.h
index 52110b861b680..4379ed512cdf0 100644
--- a/flang/include/flang/Lower/Bridge.h
+++ b/flang/include/flang/Lower/Bridge.h
@@ -65,11 +65,11 @@ class LoweringBridge {
  const 

[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-12 Thread Alexis Perry-Holby via cfe-commits

https://github.com/AlexisPerry updated 
https://github.com/llvm/llvm-project/pull/95043

>From 2312d31b14aecc6eeea2e81d221ee004e5de3efc Mon Sep 17 00:00:00 2001
From: Alexis Perry-Holby 
Date: Thu, 6 Jun 2024 14:02:52 -0600
Subject: [PATCH 1/4] [flang] Add basic -mtune support

---
 clang/include/clang/Driver/Options.td |  7 ---
 clang/lib/Driver/ToolChains/Flang.cpp |  8 
 flang/include/flang/Frontend/TargetOptions.h  |  3 +++
 flang/include/flang/Lower/Bridge.h|  6 +++---
 .../flang/Optimizer/CodeGen/CGPasses.td   |  4 
 .../include/flang/Optimizer/CodeGen/Target.h  | 19 ++-
 .../Optimizer/Dialect/Support/FIRContext.h|  7 +++
 .../flang/Optimizer/Transforms/Passes.td  |  3 +++
 flang/lib/Frontend/CompilerInvocation.cpp |  4 
 flang/lib/Frontend/FrontendActions.cpp|  3 ++-
 flang/lib/Lower/Bridge.cpp|  3 ++-
 flang/lib/Optimizer/CodeGen/CodeGen.cpp   |  6 +-
 flang/lib/Optimizer/CodeGen/Target.cpp| 11 +++
 flang/lib/Optimizer/CodeGen/TargetRewrite.cpp | 12 +++-
 flang/lib/Optimizer/CodeGen/TypeConverter.cpp |  3 ++-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 18 ++
 flang/tools/bbc/bbc.cpp   |  2 +-
 flang/tools/tco/tco.cpp   |  4 
 flang/unittests/Optimizer/FIRContextTest.cpp  |  3 +++
 .../mlir/Dialect/LLVMIR/LLVMAttrDefs.td   |  9 +
 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td   |  1 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   |  5 +
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  |  3 +++
 23 files changed, 131 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..b81f480e1ed2b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5403,6 +5403,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;
 def multi__module : Flag<["-"], "multi_module">;
 def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
@@ -6722,9 +6723,6 @@ def emit_hlfir : Flag<["-"], "emit-hlfir">, 
Group,
 
 let Visibility = [CC1Option, CC1AsOption] in {
 
-def tune_cpu : Separate<["-"], "tune-cpu">,
-  HelpText<"Tune for a specific cpu type">,
-  MarshallingInfoString>;
 def target_abi : Separate<["-"], "target-abi">,
   HelpText<"Target a particular ABI type">,
   MarshallingInfoString>;
@@ -6751,6 +6749,9 @@ def darwin_target_variant_triple : Separate<["-"], 
"darwin-target-variant-triple
 
 let Visibility = [CC1Option, CC1AsOption, FC1Option] in {
 
+def tune_cpu : Separate<["-"], "tune-cpu">,
+  HelpText<"Tune for a specific cpu type">,
+  MarshallingInfoString>;
 def target_cpu : Separate<["-"], "target-cpu">,
   HelpText<"Target a specific cpu type">,
   MarshallingInfoString>;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 42b45dba2bd31..3dc7ee0ea2bff 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
+#include "llvm/TargetParser/Host.h"
 
 #include 
 
@@ -411,6 +412,13 @@ void Flang::addTargetOptions(const ArgList ,
   }
 
   // TODO: Add target specific flags, ABI, mtune option etc.
+  if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
+CmdArgs.push_back("-tune-cpu");
+if (strcmp(A->getValue(), "native") == 0)
+  CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
+else
+  CmdArgs.push_back(A->getValue());
+  }
 }
 
 void Flang::addOffloadOptions(Compilation , const InputInfoList ,
diff --git a/flang/include/flang/Frontend/TargetOptions.h 
b/flang/include/flang/Frontend/TargetOptions.h
index ef5d270a2185d..a7a7192c55cb1 100644
--- a/flang/include/flang/Frontend/TargetOptions.h
+++ b/flang/include/flang/Frontend/TargetOptions.h
@@ -32,6 +32,9 @@ class TargetOptions {
   /// If given, the name of the target CPU to generate code for.
   std::string cpu;
 
+  /// If given, the name of the target CPU to tune code for.
+  std::string tuneCPU;
+
   /// The list of target specific features to enable or disable, as written on
   /// the command line.
   std::vector featuresAsWritten;
diff --git a/flang/include/flang/Lower/Bridge.h 
b/flang/include/flang/Lower/Bridge.h
index 52110b861b680..4379ed512cdf0 100644
--- a/flang/include/flang/Lower/Bridge.h
+++ b/flang/include/flang/Lower/Bridge.h
@@ -65,11 +65,11 @@ class LoweringBridge {
  const 

[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-12 Thread Alexis Perry-Holby via cfe-commits

https://github.com/AlexisPerry updated 
https://github.com/llvm/llvm-project/pull/95043

>From 2312d31b14aecc6eeea2e81d221ee004e5de3efc Mon Sep 17 00:00:00 2001
From: Alexis Perry-Holby 
Date: Thu, 6 Jun 2024 14:02:52 -0600
Subject: [PATCH 1/4] [flang] Add basic -mtune support

---
 clang/include/clang/Driver/Options.td |  7 ---
 clang/lib/Driver/ToolChains/Flang.cpp |  8 
 flang/include/flang/Frontend/TargetOptions.h  |  3 +++
 flang/include/flang/Lower/Bridge.h|  6 +++---
 .../flang/Optimizer/CodeGen/CGPasses.td   |  4 
 .../include/flang/Optimizer/CodeGen/Target.h  | 19 ++-
 .../Optimizer/Dialect/Support/FIRContext.h|  7 +++
 .../flang/Optimizer/Transforms/Passes.td  |  3 +++
 flang/lib/Frontend/CompilerInvocation.cpp |  4 
 flang/lib/Frontend/FrontendActions.cpp|  3 ++-
 flang/lib/Lower/Bridge.cpp|  3 ++-
 flang/lib/Optimizer/CodeGen/CodeGen.cpp   |  6 +-
 flang/lib/Optimizer/CodeGen/Target.cpp| 11 +++
 flang/lib/Optimizer/CodeGen/TargetRewrite.cpp | 12 +++-
 flang/lib/Optimizer/CodeGen/TypeConverter.cpp |  3 ++-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 18 ++
 flang/tools/bbc/bbc.cpp   |  2 +-
 flang/tools/tco/tco.cpp   |  4 
 flang/unittests/Optimizer/FIRContextTest.cpp  |  3 +++
 .../mlir/Dialect/LLVMIR/LLVMAttrDefs.td   |  9 +
 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td   |  1 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   |  5 +
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  |  3 +++
 23 files changed, 131 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..b81f480e1ed2b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5403,6 +5403,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;
 def multi__module : Flag<["-"], "multi_module">;
 def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
@@ -6722,9 +6723,6 @@ def emit_hlfir : Flag<["-"], "emit-hlfir">, 
Group,
 
 let Visibility = [CC1Option, CC1AsOption] in {
 
-def tune_cpu : Separate<["-"], "tune-cpu">,
-  HelpText<"Tune for a specific cpu type">,
-  MarshallingInfoString>;
 def target_abi : Separate<["-"], "target-abi">,
   HelpText<"Target a particular ABI type">,
   MarshallingInfoString>;
@@ -6751,6 +6749,9 @@ def darwin_target_variant_triple : Separate<["-"], 
"darwin-target-variant-triple
 
 let Visibility = [CC1Option, CC1AsOption, FC1Option] in {
 
+def tune_cpu : Separate<["-"], "tune-cpu">,
+  HelpText<"Tune for a specific cpu type">,
+  MarshallingInfoString>;
 def target_cpu : Separate<["-"], "target-cpu">,
   HelpText<"Target a specific cpu type">,
   MarshallingInfoString>;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 42b45dba2bd31..3dc7ee0ea2bff 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
+#include "llvm/TargetParser/Host.h"
 
 #include 
 
@@ -411,6 +412,13 @@ void Flang::addTargetOptions(const ArgList ,
   }
 
   // TODO: Add target specific flags, ABI, mtune option etc.
+  if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
+CmdArgs.push_back("-tune-cpu");
+if (strcmp(A->getValue(), "native") == 0)
+  CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
+else
+  CmdArgs.push_back(A->getValue());
+  }
 }
 
 void Flang::addOffloadOptions(Compilation , const InputInfoList ,
diff --git a/flang/include/flang/Frontend/TargetOptions.h 
b/flang/include/flang/Frontend/TargetOptions.h
index ef5d270a2185d..a7a7192c55cb1 100644
--- a/flang/include/flang/Frontend/TargetOptions.h
+++ b/flang/include/flang/Frontend/TargetOptions.h
@@ -32,6 +32,9 @@ class TargetOptions {
   /// If given, the name of the target CPU to generate code for.
   std::string cpu;
 
+  /// If given, the name of the target CPU to tune code for.
+  std::string tuneCPU;
+
   /// The list of target specific features to enable or disable, as written on
   /// the command line.
   std::vector featuresAsWritten;
diff --git a/flang/include/flang/Lower/Bridge.h 
b/flang/include/flang/Lower/Bridge.h
index 52110b861b680..4379ed512cdf0 100644
--- a/flang/include/flang/Lower/Bridge.h
+++ b/flang/include/flang/Lower/Bridge.h
@@ -65,11 +65,11 @@ class LoweringBridge {
  const 

[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-11 Thread Alexis Perry-Holby via cfe-commits

https://github.com/AlexisPerry updated 
https://github.com/llvm/llvm-project/pull/95043

>From 2312d31b14aecc6eeea2e81d221ee004e5de3efc Mon Sep 17 00:00:00 2001
From: Alexis Perry-Holby 
Date: Thu, 6 Jun 2024 14:02:52 -0600
Subject: [PATCH 1/3] [flang] Add basic -mtune support

---
 clang/include/clang/Driver/Options.td |  7 ---
 clang/lib/Driver/ToolChains/Flang.cpp |  8 
 flang/include/flang/Frontend/TargetOptions.h  |  3 +++
 flang/include/flang/Lower/Bridge.h|  6 +++---
 .../flang/Optimizer/CodeGen/CGPasses.td   |  4 
 .../include/flang/Optimizer/CodeGen/Target.h  | 19 ++-
 .../Optimizer/Dialect/Support/FIRContext.h|  7 +++
 .../flang/Optimizer/Transforms/Passes.td  |  3 +++
 flang/lib/Frontend/CompilerInvocation.cpp |  4 
 flang/lib/Frontend/FrontendActions.cpp|  3 ++-
 flang/lib/Lower/Bridge.cpp|  3 ++-
 flang/lib/Optimizer/CodeGen/CodeGen.cpp   |  6 +-
 flang/lib/Optimizer/CodeGen/Target.cpp| 11 +++
 flang/lib/Optimizer/CodeGen/TargetRewrite.cpp | 12 +++-
 flang/lib/Optimizer/CodeGen/TypeConverter.cpp |  3 ++-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 18 ++
 flang/tools/bbc/bbc.cpp   |  2 +-
 flang/tools/tco/tco.cpp   |  4 
 flang/unittests/Optimizer/FIRContextTest.cpp  |  3 +++
 .../mlir/Dialect/LLVMIR/LLVMAttrDefs.td   |  9 +
 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td   |  1 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   |  5 +
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  |  3 +++
 23 files changed, 131 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..b81f480e1ed2b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5403,6 +5403,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;
 def multi__module : Flag<["-"], "multi_module">;
 def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
@@ -6722,9 +6723,6 @@ def emit_hlfir : Flag<["-"], "emit-hlfir">, 
Group,
 
 let Visibility = [CC1Option, CC1AsOption] in {
 
-def tune_cpu : Separate<["-"], "tune-cpu">,
-  HelpText<"Tune for a specific cpu type">,
-  MarshallingInfoString>;
 def target_abi : Separate<["-"], "target-abi">,
   HelpText<"Target a particular ABI type">,
   MarshallingInfoString>;
@@ -6751,6 +6749,9 @@ def darwin_target_variant_triple : Separate<["-"], 
"darwin-target-variant-triple
 
 let Visibility = [CC1Option, CC1AsOption, FC1Option] in {
 
+def tune_cpu : Separate<["-"], "tune-cpu">,
+  HelpText<"Tune for a specific cpu type">,
+  MarshallingInfoString>;
 def target_cpu : Separate<["-"], "target-cpu">,
   HelpText<"Target a specific cpu type">,
   MarshallingInfoString>;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 42b45dba2bd31..3dc7ee0ea2bff 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
+#include "llvm/TargetParser/Host.h"
 
 #include 
 
@@ -411,6 +412,13 @@ void Flang::addTargetOptions(const ArgList ,
   }
 
   // TODO: Add target specific flags, ABI, mtune option etc.
+  if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
+CmdArgs.push_back("-tune-cpu");
+if (strcmp(A->getValue(), "native") == 0)
+  CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
+else
+  CmdArgs.push_back(A->getValue());
+  }
 }
 
 void Flang::addOffloadOptions(Compilation , const InputInfoList ,
diff --git a/flang/include/flang/Frontend/TargetOptions.h 
b/flang/include/flang/Frontend/TargetOptions.h
index ef5d270a2185d..a7a7192c55cb1 100644
--- a/flang/include/flang/Frontend/TargetOptions.h
+++ b/flang/include/flang/Frontend/TargetOptions.h
@@ -32,6 +32,9 @@ class TargetOptions {
   /// If given, the name of the target CPU to generate code for.
   std::string cpu;
 
+  /// If given, the name of the target CPU to tune code for.
+  std::string tuneCPU;
+
   /// The list of target specific features to enable or disable, as written on
   /// the command line.
   std::vector featuresAsWritten;
diff --git a/flang/include/flang/Lower/Bridge.h 
b/flang/include/flang/Lower/Bridge.h
index 52110b861b680..4379ed512cdf0 100644
--- a/flang/include/flang/Lower/Bridge.h
+++ b/flang/include/flang/Lower/Bridge.h
@@ -65,11 +65,11 @@ class LoweringBridge {
  const 

[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-11 Thread Alexis Perry-Holby via cfe-commits


@@ -411,6 +412,13 @@ void Flang::addTargetOptions(const ArgList ,
   }
 
   // TODO: Add target specific flags, ABI, mtune option etc.
+  if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
+CmdArgs.push_back("-tune-cpu");
+if (strcmp(A->getValue(), "native") == 0)

AlexisPerry wrote:

I see your point, however when I build the code using normal `==` comparison I 
get a warning:
`warning: comparison with string literal results in unspecified behavior`
and I am inclined to avoid such possible unspecified behavior.

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


[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-11 Thread Alexis Perry-Holby via cfe-commits


@@ -371,7 +371,7 @@ static mlir::LogicalResult convertFortranSourceToMLIR(
   ctx, semanticsContext, defKinds, semanticsContext.intrinsics(),
   semanticsContext.targetCharacteristics(), parsing.allCooked(),
   targetTriple, kindMap, loweringOptions, envDefaults,
-  semanticsContext.languageFeatures(), targetMachine);
+  semanticsContext.languageFeatures(), targetMachine, ""); // FIXME

AlexisPerry wrote:

Thank you for catching that.  I meant to remove that comment as the thing it 
was referring to has been fixed.  I'll clean it up now.

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


[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-11 Thread Alexis Perry-Holby via cfe-commits


@@ -58,6 +58,15 @@ def FramePointerKindAttr : LLVM_Attr<"FramePointerKind", 
"framePointerKind"> {
   let assemblyFormat = "`<` $framePointerKind `>`";
 }
 
+//===--===//
+// TuneCPUAttr
+//===--===//
+
+//def TuneCPUAttr : LLVM_Attr<"TuneCPU", "tuneCPU"> {
+  //let parameters = (ins "tuneCPU::tuneCPU":$tuneCPU);
+  //let assemblyFormat = "`<` $tuneCPU `>`";
+//}

AlexisPerry wrote:

Thank you for catching that!  I will clean it up.

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


[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-10 Thread Alexis Perry-Holby via cfe-commits

https://github.com/AlexisPerry updated 
https://github.com/llvm/llvm-project/pull/95043

>From 2312d31b14aecc6eeea2e81d221ee004e5de3efc Mon Sep 17 00:00:00 2001
From: Alexis Perry-Holby 
Date: Thu, 6 Jun 2024 14:02:52 -0600
Subject: [PATCH 1/2] [flang] Add basic -mtune support

---
 clang/include/clang/Driver/Options.td |  7 ---
 clang/lib/Driver/ToolChains/Flang.cpp |  8 
 flang/include/flang/Frontend/TargetOptions.h  |  3 +++
 flang/include/flang/Lower/Bridge.h|  6 +++---
 .../flang/Optimizer/CodeGen/CGPasses.td   |  4 
 .../include/flang/Optimizer/CodeGen/Target.h  | 19 ++-
 .../Optimizer/Dialect/Support/FIRContext.h|  7 +++
 .../flang/Optimizer/Transforms/Passes.td  |  3 +++
 flang/lib/Frontend/CompilerInvocation.cpp |  4 
 flang/lib/Frontend/FrontendActions.cpp|  3 ++-
 flang/lib/Lower/Bridge.cpp|  3 ++-
 flang/lib/Optimizer/CodeGen/CodeGen.cpp   |  6 +-
 flang/lib/Optimizer/CodeGen/Target.cpp| 11 +++
 flang/lib/Optimizer/CodeGen/TargetRewrite.cpp | 12 +++-
 flang/lib/Optimizer/CodeGen/TypeConverter.cpp |  3 ++-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 18 ++
 flang/tools/bbc/bbc.cpp   |  2 +-
 flang/tools/tco/tco.cpp   |  4 
 flang/unittests/Optimizer/FIRContextTest.cpp  |  3 +++
 .../mlir/Dialect/LLVMIR/LLVMAttrDefs.td   |  9 +
 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td   |  1 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   |  5 +
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  |  3 +++
 23 files changed, 131 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..b81f480e1ed2b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5403,6 +5403,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;
 def multi__module : Flag<["-"], "multi_module">;
 def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
@@ -6722,9 +6723,6 @@ def emit_hlfir : Flag<["-"], "emit-hlfir">, 
Group,
 
 let Visibility = [CC1Option, CC1AsOption] in {
 
-def tune_cpu : Separate<["-"], "tune-cpu">,
-  HelpText<"Tune for a specific cpu type">,
-  MarshallingInfoString>;
 def target_abi : Separate<["-"], "target-abi">,
   HelpText<"Target a particular ABI type">,
   MarshallingInfoString>;
@@ -6751,6 +6749,9 @@ def darwin_target_variant_triple : Separate<["-"], 
"darwin-target-variant-triple
 
 let Visibility = [CC1Option, CC1AsOption, FC1Option] in {
 
+def tune_cpu : Separate<["-"], "tune-cpu">,
+  HelpText<"Tune for a specific cpu type">,
+  MarshallingInfoString>;
 def target_cpu : Separate<["-"], "target-cpu">,
   HelpText<"Target a specific cpu type">,
   MarshallingInfoString>;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 42b45dba2bd31..3dc7ee0ea2bff 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
+#include "llvm/TargetParser/Host.h"
 
 #include 
 
@@ -411,6 +412,13 @@ void Flang::addTargetOptions(const ArgList ,
   }
 
   // TODO: Add target specific flags, ABI, mtune option etc.
+  if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
+CmdArgs.push_back("-tune-cpu");
+if (strcmp(A->getValue(), "native") == 0)
+  CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
+else
+  CmdArgs.push_back(A->getValue());
+  }
 }
 
 void Flang::addOffloadOptions(Compilation , const InputInfoList ,
diff --git a/flang/include/flang/Frontend/TargetOptions.h 
b/flang/include/flang/Frontend/TargetOptions.h
index ef5d270a2185d..a7a7192c55cb1 100644
--- a/flang/include/flang/Frontend/TargetOptions.h
+++ b/flang/include/flang/Frontend/TargetOptions.h
@@ -32,6 +32,9 @@ class TargetOptions {
   /// If given, the name of the target CPU to generate code for.
   std::string cpu;
 
+  /// If given, the name of the target CPU to tune code for.
+  std::string tuneCPU;
+
   /// The list of target specific features to enable or disable, as written on
   /// the command line.
   std::vector featuresAsWritten;
diff --git a/flang/include/flang/Lower/Bridge.h 
b/flang/include/flang/Lower/Bridge.h
index 52110b861b680..4379ed512cdf0 100644
--- a/flang/include/flang/Lower/Bridge.h
+++ b/flang/include/flang/Lower/Bridge.h
@@ -65,11 +65,11 @@ class LoweringBridge {
  const 

[clang] [flang] [mlir] [flang] Add basic -mtune support (PR #95043)

2024-06-10 Thread Alexis Perry-Holby via cfe-commits

https://github.com/AlexisPerry created 
https://github.com/llvm/llvm-project/pull/95043

This PR adds -mtune as a valid flang flag and passes the information through to 
LLVM IR as an attribute on all functions.  No specific architecture 
optimizations are added at this time.

>From 2312d31b14aecc6eeea2e81d221ee004e5de3efc Mon Sep 17 00:00:00 2001
From: Alexis Perry-Holby 
Date: Thu, 6 Jun 2024 14:02:52 -0600
Subject: [PATCH] [flang] Add basic -mtune support

---
 clang/include/clang/Driver/Options.td |  7 ---
 clang/lib/Driver/ToolChains/Flang.cpp |  8 
 flang/include/flang/Frontend/TargetOptions.h  |  3 +++
 flang/include/flang/Lower/Bridge.h|  6 +++---
 .../flang/Optimizer/CodeGen/CGPasses.td   |  4 
 .../include/flang/Optimizer/CodeGen/Target.h  | 19 ++-
 .../Optimizer/Dialect/Support/FIRContext.h|  7 +++
 .../flang/Optimizer/Transforms/Passes.td  |  3 +++
 flang/lib/Frontend/CompilerInvocation.cpp |  4 
 flang/lib/Frontend/FrontendActions.cpp|  3 ++-
 flang/lib/Lower/Bridge.cpp|  3 ++-
 flang/lib/Optimizer/CodeGen/CodeGen.cpp   |  6 +-
 flang/lib/Optimizer/CodeGen/Target.cpp| 11 +++
 flang/lib/Optimizer/CodeGen/TargetRewrite.cpp | 12 +++-
 flang/lib/Optimizer/CodeGen/TypeConverter.cpp |  3 ++-
 .../Optimizer/Dialect/Support/FIRContext.cpp  | 18 ++
 flang/tools/bbc/bbc.cpp   |  2 +-
 flang/tools/tco/tco.cpp   |  4 
 flang/unittests/Optimizer/FIRContextTest.cpp  |  3 +++
 .../mlir/Dialect/LLVMIR/LLVMAttrDefs.td   |  9 +
 mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td   |  1 +
 mlir/lib/Target/LLVMIR/ModuleImport.cpp   |  5 +
 mlir/lib/Target/LLVMIR/ModuleTranslation.cpp  |  3 +++
 23 files changed, 131 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d44faa55c456f..b81f480e1ed2b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5403,6 +5403,7 @@ def module_file_info : Flag<["-"], "module-file-info">, 
Flags<[]>,
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
+  Visibility<[ClangOption, FlangOption]>,
   HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;
 def multi__module : Flag<["-"], "multi_module">;
 def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
@@ -6722,9 +6723,6 @@ def emit_hlfir : Flag<["-"], "emit-hlfir">, 
Group,
 
 let Visibility = [CC1Option, CC1AsOption] in {
 
-def tune_cpu : Separate<["-"], "tune-cpu">,
-  HelpText<"Tune for a specific cpu type">,
-  MarshallingInfoString>;
 def target_abi : Separate<["-"], "target-abi">,
   HelpText<"Target a particular ABI type">,
   MarshallingInfoString>;
@@ -6751,6 +6749,9 @@ def darwin_target_variant_triple : Separate<["-"], 
"darwin-target-variant-triple
 
 let Visibility = [CC1Option, CC1AsOption, FC1Option] in {
 
+def tune_cpu : Separate<["-"], "tune-cpu">,
+  HelpText<"Tune for a specific cpu type">,
+  MarshallingInfoString>;
 def target_cpu : Separate<["-"], "target-cpu">,
   HelpText<"Target a specific cpu type">,
   MarshallingInfoString>;
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 42b45dba2bd31..3dc7ee0ea2bff 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -17,6 +17,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/TargetParser/RISCVISAInfo.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
+#include "llvm/TargetParser/Host.h"
 
 #include 
 
@@ -411,6 +412,13 @@ void Flang::addTargetOptions(const ArgList ,
   }
 
   // TODO: Add target specific flags, ABI, mtune option etc.
+  if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
+CmdArgs.push_back("-tune-cpu");
+if (strcmp(A->getValue(), "native") == 0)
+  CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
+else
+  CmdArgs.push_back(A->getValue());
+  }
 }
 
 void Flang::addOffloadOptions(Compilation , const InputInfoList ,
diff --git a/flang/include/flang/Frontend/TargetOptions.h 
b/flang/include/flang/Frontend/TargetOptions.h
index ef5d270a2185d..a7a7192c55cb1 100644
--- a/flang/include/flang/Frontend/TargetOptions.h
+++ b/flang/include/flang/Frontend/TargetOptions.h
@@ -32,6 +32,9 @@ class TargetOptions {
   /// If given, the name of the target CPU to generate code for.
   std::string cpu;
 
+  /// If given, the name of the target CPU to tune code for.
+  std::string tuneCPU;
+
   /// The list of target specific features to enable or disable, as written on
   /// the command line.
   std::vector featuresAsWritten;
diff --git a/flang/include/flang/Lower/Bridge.h 
b/flang/include/flang/Lower/Bridge.h
index