[clang] [RISCV] Allow YAML file to control multilib selection (PR #98856)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Jul 14 21:03:53 PDT 2024
https://github.com/ArcaneNibble created https://github.com/llvm/llvm-project/pull/98856
This changes the bare-metal driver logic such that it _always_ tries multilib.yaml if it exists, and it falls back to the hardwired/default RISC-V multilib selection only if a multilib.yaml doesn't exist. In contrast, the current behavior is that RISC-V can never use multilib.yaml, but other targets will try it if it exists.
The flags `-march=` and `-mabi=` are exposed for multilib.yaml to match on. There is no attempt to help YAML file creators to duplicate the existing hard-wired multilib reuse logic -- they will have to implement it using `Mappings`.
This should be backwards-compatible with existing sysroots, as multilib.yaml was previously never used for RISC-V, and the behavior doesn't change after this PR if the file doesn't exist.
Some actual use-cases that I want this change for:
* `-fno-exceptions` and `-fno-rtti` multilibs for C++ runtimes on small microcontrollers
* There's currently no support for rv32e multilibs in the hard-wired logic
* I want multilibs where vendor extensions such as the QingKe "XW" compressed opcodes are enabled/disabled. Permutations of features such as this can likely never be handled in hard-wired logic.
>From 628d665dc3acc3619511a4fc8bb807fabb520b94 Mon Sep 17 00:00:00 2001
From: R <rqou at berkeley.edu>
Date: Mon, 15 Jul 2024 04:13:07 +0100
Subject: [PATCH] [RISCV] Allow YAML file to control multilib selection
---
clang/lib/Driver/ToolChain.cpp | 12 ++++++++++++
clang/lib/Driver/ToolChains/BareMetal.cpp | 16 +++++++++-------
2 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 85ae4d2a26fee..7cd110a07bd98 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -9,6 +9,7 @@
#include "clang/Driver/ToolChain.h"
#include "ToolChains/Arch/AArch64.h"
#include "ToolChains/Arch/ARM.h"
+#include "ToolChains/Arch/RISCV.h"
#include "ToolChains/Clang.h"
#include "ToolChains/CommonArgs.h"
#include "ToolChains/Flang.h"
@@ -258,6 +259,13 @@ static void getARMMultilibFlags(const Driver &D,
}
}
+static void getRISCVMultilibFlags(const Driver &D, const llvm::Triple &Triple,
+ const llvm::opt::ArgList &Args,
+ Multilib::flags_list &Result) {
+ Result.push_back("-march=" + riscv::getRISCVArch(Args, Triple));
+ Result.push_back(("-mabi=" + riscv::getRISCVABI(Args, Triple)).str());
+}
+
Multilib::flags_list
ToolChain::getMultilibFlags(const llvm::opt::ArgList &Args) const {
using namespace clang::driver::options;
@@ -278,6 +286,10 @@ ToolChain::getMultilibFlags(const llvm::opt::ArgList &Args) const {
case llvm::Triple::thumbeb:
getARMMultilibFlags(D, Triple, Args, Result);
break;
+ case llvm::Triple::riscv32:
+ case llvm::Triple::riscv64:
+ getRISCVMultilibFlags(D, Triple, Args, Result);
+ break;
default:
break;
}
diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 852e0442f50a2..95b4051cb74c7 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -218,17 +218,19 @@ static std::string computeBaseSysRoot(const Driver &D,
void BareMetal::findMultilibs(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args) {
DetectedMultilibs Result;
- if (isRISCVBareMetal(Triple)) {
+ // Look for a multilib.yaml before trying target-specific hardwired logic.
+ // If it exists, always do what it specifies.
+ llvm::SmallString<128> MultilibPath(computeBaseSysRoot(D, Triple));
+ llvm::sys::path::append(MultilibPath, MultilibFilename);
+ if (D.getVFS().exists(MultilibPath)) {
+ findMultilibsFromYAML(*this, D, MultilibPath, Args, Result);
+ SelectedMultilibs = Result.SelectedMultilibs;
+ Multilibs = Result.Multilibs;
+ } else if (isRISCVBareMetal(Triple)) {
if (findRISCVMultilibs(D, Triple, Args, Result)) {
SelectedMultilibs = Result.SelectedMultilibs;
Multilibs = Result.Multilibs;
}
- } else {
- llvm::SmallString<128> MultilibPath(computeBaseSysRoot(D, Triple));
- llvm::sys::path::append(MultilibPath, MultilibFilename);
- findMultilibsFromYAML(*this, D, MultilibPath, Args, Result);
- SelectedMultilibs = Result.SelectedMultilibs;
- Multilibs = Result.Multilibs;
}
}
More information about the cfe-commits
mailing list