Skip to content

[LoongArch] add la v1.1 features for sys::getHostCPUFeatures #115832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 14, 2024

Conversation

tangaac
Copy link
Contributor

@tangaac tangaac commented Nov 12, 2024

Two features (i.e. frecipe and lam-bh) are added to sys.getHostCPUFeatures. More features will be added in future.

In addition, this patch adds the features returned by sys.getHostCPUFeature when -march=native.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' backend:loongarch labels Nov 12, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 12, 2024

@llvm/pr-subscribers-backend-loongarch
@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: None (tangaac)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/115832.diff

2 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/Arch/LoongArch.cpp (+6-1)
  • (modified) llvm/lib/TargetParser/Host.cpp (+9)
diff --git a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
index e69a5562137ccd..2dc7550176f5f0 100644
--- a/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp
@@ -135,8 +135,13 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
     Features.push_back("+lsx");
 
   std::string ArchName;
-  if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
+  if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
     ArchName = A->getValue();
+    if (ArchName == "native")
+      for (auto &F : llvm::sys::getHostCPUFeatures())
+        Features.push_back(
+            Args.MakeArgString((F.second ? "+" : "-") + F.first()));
+  }
   ArchName = postProcessTargetCPUString(ArchName, Triple);
   llvm::LoongArch::getArchFeatures(ArchName, Features);
 
diff --git a/llvm/lib/TargetParser/Host.cpp b/llvm/lib/TargetParser/Host.cpp
index 58ba2553633221..d0f3bbc26716e7 100644
--- a/llvm/lib/TargetParser/Host.cpp
+++ b/llvm/lib/TargetParser/Host.cpp
@@ -2006,6 +2006,15 @@ const StringMap<bool> sys::getHostCPUFeatures() {
   Features["lasx"] = hwcap & (1UL << 5); // HWCAP_LOONGARCH_LASX
   Features["lvz"] = hwcap & (1UL << 9);  // HWCAP_LOONGARCH_LVZ
 
+  Features["frecipe"] = cpucfg2 & (1U << 25);     // CPUCFG.2.FRECIPE
+  Features["lam-bh"] = cpucfg2 & (1U << 27);      // CPUCFG.2.LAM_BH
+
+  // TODO: Need to complete.
+  // Features["div32"] = cpucfg2 & (1U << 26);       // CPUCFG.2.DIV32
+  // Features["lamcas"] = cpucfg2 & (1U << 28);      // CPUCFG.2.LAMCAS
+  // Features["llacq-screl"] = cpucfg2 & (1U << 29); // CPUCFG.2.LLACQ_SCREL
+  // Features["scq"] = cpucfg2 & (1U << 30);         // CPUCFG.2.SCQ
+  // Features["ld-seq-sa"] = cpucfg3 & (1U << 23); // CPUCFG.3.LD_SEQ_SA
   return Features;
 }
 #elif defined(__linux__) && defined(__riscv)

Copy link

github-actions bot commented Nov 12, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@tangaac tangaac force-pushed the feature/host-cpu-feature branch from 10d2d8e to 3d204da Compare November 12, 2024 08:33
Copy link
Contributor

@SixWeining SixWeining left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add theual feature in another PR? Thanks.

@SixWeining SixWeining requested a review from wangleiat November 13, 2024 02:50
@tangaac tangaac force-pushed the feature/host-cpu-feature branch from 3d204da to 3a65187 Compare November 13, 2024 06:49
@tangaac tangaac force-pushed the feature/host-cpu-feature branch from 3a65187 to 206bfe8 Compare November 13, 2024 09:53
@tangaac tangaac force-pushed the feature/host-cpu-feature branch from c1c2bfc to 1f35113 Compare November 14, 2024 02:12
Copy link
Contributor

@SixWeining SixWeining left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Tips: It's not necessary to use force-push to address review comments. Add new commits and they will be squashed when merge.

@SixWeining SixWeining merged commit 2283d50 into llvm:main Nov 14, 2024
5 of 8 checks passed
@tangaac tangaac deleted the feature/host-cpu-feature branch November 19, 2024 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:loongarch clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants