[clang] [RISCV][NFC] Use RISCVISAInfo instead of string comparison (PR #76387)
Wang Pengcheng via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 26 00:07:31 PST 2023
https://github.com/wangpc-pp created https://github.com/llvm/llvm-project/pull/76387
The arch string may not start with rv32/rv64 if we have supported
profiles in `-march`.
>From ed8ebdb6f2133f84d1f5a8d2cd580dba4ceed922 Mon Sep 17 00:00:00 2001
From: wangpc <wangpengcheng.pp at bytedance.com>
Date: Tue, 26 Dec 2023 15:58:10 +0800
Subject: [PATCH] [RISCV][NFC] Use RISCVISAInfo instead of string comparison
The arch string may not start with rv32/rv64 if we have supported
profiles in `-march`.
---
clang/lib/Driver/Driver.cpp | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
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);
+ }
}
}
More information about the cfe-commits
mailing list