[clang] [RISCV][NFC] Use RISCVISAInfo instead of string comparison (PR #76387)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 26 00:07:59 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-driver
Author: Wang Pengcheng (wangpc-pp)
<details>
<summary>Changes</summary>
The arch string may not start with rv32/rv64 if we have supported
profiles in `-march`.
---
Full diff: https://github.com/llvm/llvm-project/pull/76387.diff
1 Files Affected:
- (modified) clang/lib/Driver/Driver.cpp (+10-4)
``````````diff
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ff95c899c5f3d4..671a11f9811f5b 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -86,6 +86,7 @@
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/Program.h"
+#include "llvm/Support/RISCVISAInfo.h"
#include "llvm/Support/StringSaver.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/raw_ostream.h"
@@ -670,10 +671,15 @@ static llvm::Triple computeTargetTriple(const Driver &D,
if (Args.hasArg(options::OPT_march_EQ) ||
Args.hasArg(options::OPT_mcpu_EQ)) {
StringRef ArchName = tools::riscv::getRISCVArch(Args, Target);
- if (ArchName.starts_with_insensitive("rv32"))
- Target.setArch(llvm::Triple::riscv32);
- else if (ArchName.starts_with_insensitive("rv64"))
- Target.setArch(llvm::Triple::riscv64);
+ auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
+ ArchName, /*EnableExperimentalExtensions=*/true);
+ if (ISAInfo) {
+ unsigned XLen = (*ISAInfo)->getXLen();
+ if (XLen == 32)
+ Target.setArch(llvm::Triple::riscv32);
+ else if (XLen == 64)
+ Target.setArch(llvm::Triple::riscv64);
+ }
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/76387
More information about the cfe-commits
mailing list