[clang] 2d65097 - [RISCV] Unify all the code that adds unaligned-scalar/vector-mem to Features vector. (#94660)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 6 18:12:10 PDT 2024
Author: Craig Topper
Date: 2024-06-06T18:12:07-07:00
New Revision: 2d65097b4ff18f99e4baf18e2e0b155ecf478b0a
URL: https://github.com/llvm/llvm-project/commit/2d65097b4ff18f99e4baf18e2e0b155ecf478b0a
DIFF: https://github.com/llvm/llvm-project/commit/2d65097b4ff18f99e4baf18e2e0b155ecf478b0a.diff
LOG: [RISCV] Unify all the code that adds unaligned-scalar/vector-mem to Features vector. (#94660)
Instead of having multiple places insert into the Features vector
independently, check all the conditions in one place.
This avoids a subtle ordering requirement that -mstrict-align processing
had to be done after the others.
Added:
Modified:
clang/lib/Driver/ToolChains/Arch/RISCV.cpp
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 2e2bce8494672..26789b0ba6e09 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -67,11 +67,6 @@ static void getRISCFeaturesFromMcpu(const Driver &D, const Arg *A,
D.Diag(clang::diag::err_drv_unsupported_option_argument)
<< A->getSpelling() << Mcpu;
}
-
- if (llvm::RISCV::hasFastUnalignedAccess(Mcpu)) {
- Features.push_back("+unaligned-scalar-mem");
- Features.push_back("+unaligned-vector-mem");
- }
}
void riscv::getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple,
@@ -82,6 +77,8 @@ void riscv::getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple,
if (!getArchFeatures(D, MArch, Features, Args))
return;
+ bool CPUFastUnaligned = false;
+
// If users give march and mcpu, get std extension feature from MArch
// and other features (ex. mirco architecture feature) from mcpu
if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
@@ -90,6 +87,9 @@ void riscv::getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple,
CPU = llvm::sys::getHostCPUName();
getRISCFeaturesFromMcpu(D, A, Triple, CPU, Features);
+
+ if (llvm::RISCV::hasFastUnalignedAccess(CPU))
+ CPUFastUnaligned = true;
}
// Handle features corresponding to "-ffixed-X" options
@@ -169,18 +169,23 @@ void riscv::getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple,
Features.push_back("-relax");
}
- // Android requires fast unaligned access on RISCV64.
- if (Triple.isAndroid()) {
+ // If -mstrict-align or -mno-strict-align is passed, use it. Otherwise, the
+ // unaligned-*-mem is enabled if the CPU supports it or the target is
+ // Android.
+ if (const Arg *A = Args.getLastArg(options::OPT_mno_strict_align,
+ options::OPT_mstrict_align)) {
+ if (A->getOption().matches(options::OPT_mno_strict_align)) {
+ Features.push_back("+unaligned-scalar-mem");
+ Features.push_back("+unaligned-vector-mem");
+ } else {
+ Features.push_back("-unaligned-scalar-mem");
+ Features.push_back("-unaligned-vector-mem");
+ }
+ } else if (CPUFastUnaligned || Triple.isAndroid()) {
Features.push_back("+unaligned-scalar-mem");
Features.push_back("+unaligned-vector-mem");
}
- // -mstrict-align is default, unless -mno-strict-align is specified.
- AddTargetFeature(Args, Features, options::OPT_mno_strict_align,
- options::OPT_mstrict_align, "unaligned-scalar-mem");
- AddTargetFeature(Args, Features, options::OPT_mno_strict_align,
- options::OPT_mstrict_align, "unaligned-vector-mem");
-
// Now add any that the user explicitly requested on the command line,
// which may override the defaults.
handleTargetFeaturesGroup(D, Triple, Args, Features,
More information about the cfe-commits
mailing list