[clang] 705065f - [RISCV][NFC] Use RISCVISAInfo instead of string comparison (#76387)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 27 21:00:47 PST 2023
Author: Wang Pengcheng
Date: 2023-12-28T13:00:43+08:00
New Revision: 705065f365a9df5c26bd37f2a3380427da1b1b7f
URL: https://github.com/llvm/llvm-project/commit/705065f365a9df5c26bd37f2a3380427da1b1b7f
DIFF: https://github.com/llvm/llvm-project/commit/705065f365a9df5c26bd37f2a3380427da1b1b7f.diff
LOG: [RISCV][NFC] Use RISCVISAInfo instead of string comparison (#76387)
The arch string may not start with rv32/rv64 if we have supported
profiles in `-march`.
Added:
Modified:
clang/lib/Driver/Driver.cpp
Removed:
################################################################################
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ff95c899c5f3d4..9b2f2a37480983 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 (!llvm::errorToBool(ISAInfo.takeError())) {
+ 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