[PATCH] D144853: [Clang][RISCV] Add CMake options to configure default CPU

Wang Pengcheng via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 27 22:47:42 PST 2023


pcwang-thead updated this revision to Diff 501035.
pcwang-thead added a comment.

Simplify code.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D144853/new/

https://reviews.llvm.org/D144853

Files:
  clang/CMakeLists.txt
  clang/include/clang/Config/config.h.cmake
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp


Index: clang/lib/Driver/ToolChains/Arch/RISCV.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -10,6 +10,7 @@
 #include "../Clang.h"
 #include "ToolChains/CommonArgs.h"
 #include "clang/Basic/CharInfo.h"
+#include "clang/Config/config.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/Options.h"
@@ -308,7 +309,8 @@
 
 std::string riscv::getRISCVTargetCPU(const llvm::opt::ArgList &Args,
                                      const llvm::Triple &Triple) {
-  std::string CPU;
+  std::string CPU = Triple.isRISCV64() ? CLANG_RISCV64_DEFAULT_CPU
+                                       : CLANG_RISCV32_DEFAULT_CPU;
   // If we have -mcpu, use that.
   if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
     CPU = A->getValue();
@@ -317,8 +319,5 @@
   if (CPU == "native")
     CPU = llvm::sys::getHostCPUName();
 
-  if (!CPU.empty())
-    return CPU;
-
-  return Triple.isRISCV64() ? "generic-rv64" : "generic-rv32";
+  return CPU;
 }
Index: clang/include/clang/Config/config.h.cmake
===================================================================
--- clang/include/clang/Config/config.h.cmake
+++ clang/include/clang/Config/config.h.cmake
@@ -32,6 +32,10 @@
 /* Default architecture for SystemZ. */
 #define CLANG_SYSTEMZ_DEFAULT_ARCH "${CLANG_SYSTEMZ_DEFAULT_ARCH}"
 
+/* Default CPU for RISCV. */
+#define CLANG_RISCV32_DEFAULT_CPU "${CLANG_RISCV32_DEFAULT_CPU}"
+#define CLANG_RISCV64_DEFAULT_CPU "${CLANG_RISCV64_DEFAULT_CPU}"
+
 /* Multilib basename for libdir. */
 #define CLANG_INSTALL_LIBDIR_BASENAME "${CLANG_INSTALL_LIBDIR_BASENAME}"
 
Index: clang/CMakeLists.txt
===================================================================
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -247,6 +247,9 @@
 
 set(CLANG_SYSTEMZ_DEFAULT_ARCH "z10" CACHE STRING "SystemZ Default Arch")
 
+set(CLANG_RISCV32_DEFAULT_CPU "generic-rv32" CACHE STRING "RISCV32 Default CPU")
+set(CLANG_RISCV64_DEFAULT_CPU "generic-rv64" CACHE STRING "RISCV64 Default CPU")
+
 set(CLANG_VENDOR ${PACKAGE_VENDOR} CACHE STRING
   "Vendor-specific text for showing with version information.")
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144853.501035.patch
Type: text/x-patch
Size: 2260 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230228/03772b63/attachment-0001.bin>


More information about the cfe-commits mailing list