[llvm] [clang] [SPARC] Consume `tune-cpu` directive in the backend (PR #77195)

2024-01-08 Thread Sergei Barannikov via cfe-commits


@@ -5119,7 +5119,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,
-  HelpText<"Only supported on AArch64, PowerPC, RISC-V, SystemZ, and X86">;
+  HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;

s-barannikov wrote:

Never mind. I tested an older compiler. It seems to have been fixed in upstream.


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


[llvm] [clang] [SPARC] Consume `tune-cpu` directive in the backend (PR #77195)

2024-01-08 Thread via cfe-commits

https://github.com/koachan updated 
https://github.com/llvm/llvm-project/pull/77195

>From 119bf3db5799f3db2c7fd151f336c6d688a0eb96 Mon Sep 17 00:00:00 2001
From: Koakuma 
Date: Sat, 6 Jan 2024 19:46:56 +0700
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/include/clang/Driver/Options.td|  2 +-
 llvm/lib/Target/Sparc/SparcSubtarget.cpp | 15 ++-
 llvm/lib/Target/Sparc/SparcSubtarget.h   |  7 +--
 llvm/lib/Target/Sparc/SparcTargetMachine.cpp |  7 +--
 4 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index df12ba8fbcb296..070373b6b88c96 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5119,7 +5119,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,
-  HelpText<"Only supported on AArch64, PowerPC, RISC-V, SystemZ, and X86">;
+  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">;
 def multiply__defined : Separate<["-"], "multiply_defined">;
diff --git a/llvm/lib/Target/Sparc/SparcSubtarget.cpp 
b/llvm/lib/Target/Sparc/SparcSubtarget.cpp
index 81c2137ea730f8..a5d196c502cd23 100644
--- a/llvm/lib/Target/Sparc/SparcSubtarget.cpp
+++ b/llvm/lib/Target/Sparc/SparcSubtarget.cpp
@@ -25,15 +25,18 @@ using namespace llvm;
 
 void SparcSubtarget::anchor() { }
 
-SparcSubtarget ::initializeSubtargetDependencies(StringRef CPU,
-StringRef FS) {
+SparcSubtarget ::initializeSubtargetDependencies(
+StringRef CPU, StringRef TuneCPU, StringRef FS) {
   // Determine default and user specified characteristics
   std::string CPUName = std::string(CPU);
   if (CPUName.empty())
 CPUName = (Is64Bit) ? "v9" : "v8";
 
+  if (TuneCPU.empty())
+TuneCPU = CPUName;
+
   // Parse features string.
-  ParseSubtargetFeatures(CPUName, /*TuneCPU*/ CPUName, FS);
+  ParseSubtargetFeatures(CPUName, TuneCPU, FS);
 
   // Popc is a v9-only instruction.
   if (!IsV9)
@@ -43,10 +46,12 @@ SparcSubtarget 
::initializeSubtargetDependencies(StringRef CPU,
 }
 
 SparcSubtarget::SparcSubtarget(const Triple , const std::string ,
+   const std::string ,
const std::string , const TargetMachine ,
bool is64Bit)
-: SparcGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS), TargetTriple(TT),
-  Is64Bit(is64Bit), InstrInfo(initializeSubtargetDependencies(CPU, FS)),
+: SparcGenSubtargetInfo(TT, CPU, TuneCPU, FS), TargetTriple(TT),
+  Is64Bit(is64Bit),
+  InstrInfo(initializeSubtargetDependencies(CPU, TuneCPU, FS)),
   TLInfo(TM, *this), FrameLowering(*this) {}
 
 int SparcSubtarget::getAdjustedFrameSize(int frameSize) const {
diff --git a/llvm/lib/Target/Sparc/SparcSubtarget.h 
b/llvm/lib/Target/Sparc/SparcSubtarget.h
index 8e3d05d5d7e5df..4363942c0d6248 100644
--- a/llvm/lib/Target/Sparc/SparcSubtarget.h
+++ b/llvm/lib/Target/Sparc/SparcSubtarget.h
@@ -45,7 +45,8 @@ class SparcSubtarget : public SparcGenSubtargetInfo {
 
 public:
   SparcSubtarget(const Triple , const std::string ,
- const std::string , const TargetMachine , bool is64bit);
+ const std::string , const std::string ,
+ const TargetMachine , bool is64bit);
 
   const SparcInstrInfo *getInstrInfo() const override { return  }
   const TargetFrameLowering *getFrameLowering() const override {
@@ -70,7 +71,9 @@ class SparcSubtarget : public SparcGenSubtargetInfo {
   /// ParseSubtargetFeatures - Parses features string setting specified
   /// subtarget options.  Definition of function is auto generated by tblgen.
   void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
-  SparcSubtarget (StringRef CPU, StringRef FS);
+  SparcSubtarget (StringRef CPU,
+  StringRef TuneCPU,
+  StringRef FS);
 
   bool is64Bit() const { return Is64Bit; }
 
diff --git a/llvm/lib/Target/Sparc/SparcTargetMachine.cpp 
b/llvm/lib/Target/Sparc/SparcTargetMachine.cpp
index dbc26636e39f1f..ae7bbcecc6c7ba 100644
--- a/llvm/lib/Target/Sparc/SparcTargetMachine.cpp
+++ b/llvm/lib/Target/Sparc/SparcTargetMachine.cpp
@@ -116,10 +116,13 @@ SparcTargetMachine::~SparcTargetMachine() = default;
 const SparcSubtarget *
 SparcTargetMachine::getSubtargetImpl(const Function ) const {
   Attribute CPUAttr = 

[llvm] [clang] [SPARC] Consume `tune-cpu` directive in the backend (PR #77195)

2024-01-08 Thread via cfe-commits


@@ -5119,7 +5119,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,
-  HelpText<"Only supported on AArch64, PowerPC, RISC-V, SystemZ, and X86">;
+  HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;

koachan wrote:

Yep, the part responsible in clang already exists 
[here](https://github.com/llvm/llvm-project/blob/ac8b4f874945f83eec8c8f56d9fc80093e02a7b2/clang/lib/Driver/ToolChains/Clang.cpp#L2135-L2145)
 and there's already some test case too:
https://github.com/llvm/llvm-project/blob/main/clang/test/Driver/sparc-mtune.c

Should I add more tests?

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


[llvm] [clang] [SPARC] Consume `tune-cpu` directive in the backend (PR #77195)

2024-01-08 Thread Sergei Barannikov via cfe-commits


@@ -5119,7 +5119,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,
-  HelpText<"Only supported on AArch64, PowerPC, RISC-V, SystemZ, and X86">;
+  HelpText<"Only supported on AArch64, PowerPC, RISC-V, SPARC, SystemZ, and 
X86">;

s-barannikov wrote:

Is this the only required change at the clang side?
Which component is responsible for emitting errors on invalid / incompatible 
-mtune options?
I guess we need some test for this.


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


[llvm] [clang] [SPARC] Consume `tune-cpu` directive in the backend (PR #77195)

2024-01-08 Thread Sergei Barannikov via cfe-commits


@@ -45,7 +45,8 @@ class SparcSubtarget : public SparcGenSubtargetInfo {
 
 public:
   SparcSubtarget(const Triple , const std::string ,
- const std::string , const TargetMachine , bool is64bit);
+ const std::string , const std::string ,

s-barannikov wrote:

While here, could change all `const std::string &` to `StringRef` and/or remove 
the `TT` parameter (it can be obtained as `TM.getTargetTriple()`.).


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