Skip to content

Commit 084c9a5

Browse files
committed
rustc_codegen_llvm: Name major version of LLVM
It makes LLVM version comparison clearer.
1 parent 9d82de1 commit 084c9a5

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
228228
} else {
229229
&*sess.target.arch
230230
};
231+
let (major, _, _) = get_version();
231232
match (arch, s) {
232233
("x86", "sse4.2") => Some(LLVMFeature::with_dependencies(
233234
"sse4.2",
@@ -247,8 +248,8 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
247248
("aarch64", "paca") => Some(LLVMFeature::new("pauth")),
248249
("aarch64", "pacg") => Some(LLVMFeature::new("pauth")),
249250
// Before LLVM 20 those two features were packaged together as b16b16
250-
("aarch64", "sve-b16b16") if get_version().0 < 20 => Some(LLVMFeature::new("b16b16")),
251-
("aarch64", "sme-b16b16") if get_version().0 < 20 => Some(LLVMFeature::new("b16b16")),
251+
("aarch64", "sve-b16b16") if major < 20 => Some(LLVMFeature::new("b16b16")),
252+
("aarch64", "sme-b16b16") if major < 20 => Some(LLVMFeature::new("b16b16")),
252253
("aarch64", "flagm2") => Some(LLVMFeature::new("altnzcv")),
253254
// Rust ties fp and neon together.
254255
("aarch64", "neon") => Some(LLVMFeature::with_dependencies(
@@ -263,31 +264,27 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
263264
("aarch64", "fpmr") => None, // only existed in 18
264265
("arm", "fp16") => Some(LLVMFeature::new("fullfp16")),
265266
// NVPTX targets added in LLVM 20
266-
("nvptx64", "sm_100") if get_version().0 < 20 => None,
267-
("nvptx64", "sm_100a") if get_version().0 < 20 => None,
268-
("nvptx64", "sm_101") if get_version().0 < 20 => None,
269-
("nvptx64", "sm_101a") if get_version().0 < 20 => None,
270-
("nvptx64", "sm_120") if get_version().0 < 20 => None,
271-
("nvptx64", "sm_120a") if get_version().0 < 20 => None,
272-
("nvptx64", "ptx86") if get_version().0 < 20 => None,
273-
("nvptx64", "ptx87") if get_version().0 < 20 => None,
267+
("nvptx64", "sm_100") if major < 20 => None,
268+
("nvptx64", "sm_100a") if major < 20 => None,
269+
("nvptx64", "sm_101") if major < 20 => None,
270+
("nvptx64", "sm_101a") if major < 20 => None,
271+
("nvptx64", "sm_120") if major < 20 => None,
272+
("nvptx64", "sm_120a") if major < 20 => None,
273+
("nvptx64", "ptx86") if major < 20 => None,
274+
("nvptx64", "ptx87") if major < 20 => None,
274275
// Filter out features that are not supported by the current LLVM version
275-
("loongarch64", "div32" | "lam-bh" | "lamcas" | "ld-seq-sa" | "scq")
276-
if get_version().0 < 20 =>
277-
{
278-
None
279-
}
280-
("loongarch32" | "loongarch64", "32s") if get_version().0 < 21 => None,
276+
("loongarch64", "div32" | "lam-bh" | "lamcas" | "ld-seq-sa" | "scq") if major < 20 => None,
277+
("loongarch32" | "loongarch64", "32s") if major < 21 => None,
281278
// Filter out features that are not supported by the current LLVM version
282-
("riscv32" | "riscv64", "zacas" | "rva23u64" | "supm") if get_version().0 < 20 => None,
279+
("riscv32" | "riscv64", "zacas" | "rva23u64" | "supm") if major < 20 => None,
283280
(
284281
"s390x",
285282
"message-security-assist-extension12"
286283
| "concurrent-functions"
287284
| "miscellaneous-extensions-4"
288285
| "vector-enhancements-3"
289286
| "vector-packed-decimal-enhancement-3",
290-
) if get_version().0 < 20 => None,
287+
) if major < 20 => None,
291288
// Enable the evex512 target feature if an avx512 target feature is enabled.
292289
("x86", s) if s.starts_with("avx512") => Some(LLVMFeature::with_dependencies(
293290
s,
@@ -301,18 +298,18 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
301298
// https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp#L27-L28
302299
// Before LLVM 19, there was no `v8plus` feature and `v9` means "SPARC-V9 instruction available".
303300
// https://github.com/llvm/llvm-project/blob/llvmorg-18.1.0/llvm/lib/Target/Sparc/MCTargetDesc/SparcELFObjectWriter.cpp#L26
304-
("sparc", "v8plus") if get_version().0 == 19 => Some(LLVMFeature::new("v9")),
301+
("sparc", "v8plus") if major == 19 => Some(LLVMFeature::new("v9")),
305302
("powerpc", "power8-crypto") => Some(LLVMFeature::new("crypto")),
306303
// These new `amx` variants and `movrs` were introduced in LLVM20
307304
("x86", "amx-avx512" | "amx-fp8" | "amx-movrs" | "amx-tf32" | "amx-transpose")
308-
if get_version().0 < 20 =>
305+
if major < 20 =>
309306
{
310307
None
311308
}
312-
("x86", "movrs") if get_version().0 < 20 => None,
309+
("x86", "movrs") if major < 20 => None,
313310
("x86", "avx10.1") => Some(LLVMFeature::new("avx10.1-512")),
314-
("x86", "avx10.2") if get_version().0 < 20 => None,
315-
("x86", "avx10.2") if get_version().0 >= 20 => Some(LLVMFeature::new("avx10.2-512")),
311+
("x86", "avx10.2") if major < 20 => None,
312+
("x86", "avx10.2") if major >= 20 => Some(LLVMFeature::new("avx10.2-512")),
316313
("x86", "apxf") => Some(LLVMFeature::with_dependencies(
317314
"egpr",
318315
smallvec![

0 commit comments

Comments
 (0)