Skip to content

Commit dabe9cd

Browse files
Auto merge of #150722 - nikic:llvm-22, r=<try>
Update to LLVM 22
2 parents da476f1 + b0ff5bb commit dabe9cd

9 files changed

Lines changed: 32 additions & 5 deletions

File tree

.gitmodules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
shallow = true
2525
[submodule "src/llvm-project"]
2626
path = src/llvm-project
27-
url = https://github.com/rust-lang/llvm-project.git
28-
branch = rustc/21.1-2025-08-01
27+
url = https://github.com/nikic/llvm-project.git
28+
branch = rust-llvm-22
2929
shallow = true
3030
[submodule "src/doc/embedded-book"]
3131
path = src/doc/embedded-book

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,6 +1773,9 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
17731773
}
17741774

17751775
if crate::llvm_util::get_version() >= (22, 0, 0) {
1776+
// LLVM 22 requires the lifetime intrinsic to act directly on the alloca,
1777+
// there can't be an addrspacecast in between.
1778+
let ptr = unsafe { llvm::LLVMRustStripPointerCasts(ptr) };
17761779
self.call_intrinsic(intrinsic, &[self.val_ty(ptr)], &[ptr]);
17771780
} else {
17781781
self.call_intrinsic(intrinsic, &[self.val_ty(ptr)], &[self.cx.const_u64(size), ptr]);

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,15 @@ pub(crate) unsafe fn create_module<'ll>(
211211
// LLVM 22 updated the NVPTX layout to indicate 256-bit vector load/store: https://github.com/llvm/llvm-project/pull/155198
212212
target_data_layout = target_data_layout.replace("-i256:256", "");
213213
}
214+
if sess.target.arch == Arch::PowerPC64 {
215+
// LLVM 22 updated the ABI alignment for double on AIX: https://github.com/llvm/llvm-project/pull/144673
216+
target_data_layout = target_data_layout.replace("-f64:32:64", "");
217+
}
218+
if sess.target.arch == Arch::AmdGpu {
219+
// LLVM 22 specified ELF mangling in the amdgpu data layout:
220+
// https://github.com/llvm/llvm-project/pull/163011
221+
target_data_layout = target_data_layout.replace("-e:m", "");
222+
}
214223
}
215224

216225
// Ensure the data-layout values hardcoded remain the defaults.

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,6 +1959,7 @@ unsafe extern "C" {
19591959
Metadata: &'a Metadata,
19601960
);
19611961
pub(crate) fn LLVMRustIsNonGVFunctionPointerTy(Val: &Value) -> bool;
1962+
pub(crate) fn LLVMRustStripPointerCasts<'a>(Val: &'a Value) -> &'a Value;
19621963

19631964
// Operations on scalar constants
19641965
pub(crate) fn LLVMRustConstIntGetZExtValue(ConstantVal: &ConstantInt, Value: &mut u64) -> bool;

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,6 +1745,10 @@ extern "C" bool LLVMRustIsNonGVFunctionPointerTy(LLVMValueRef V) {
17451745
return false;
17461746
}
17471747

1748+
extern "C" LLVMValueRef LLVMRustStripPointerCasts(LLVMValueRef V) {
1749+
return wrap(unwrap(V)->stripPointerCasts());
1750+
}
1751+
17481752
extern "C" bool LLVMRustLLVMHasZlibCompression() {
17491753
return llvm::compression::zlib::isAvailable();
17501754
}

compiler/rustc_target/src/spec/targets/amdgcn_amd_amdhsa.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::spec::{
55
pub(crate) fn target() -> Target {
66
Target {
77
arch: Arch::AmdGpu,
8-
data_layout: "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128:128:48-p9:192:256:256:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7:8:9".into(),
8+
data_layout: "e-m:e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128:128:48-p9:192:256:256:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7:8:9".into(),
99
llvm_target: "amdgcn-amd-amdhsa".into(),
1010
metadata: TargetMetadata {
1111
description: Some("AMD GPU".into()),

compiler/rustc_target/src/spec/targets/powerpc64_ibm_aix.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ pub(crate) fn target() -> Target {
1717
std: None, // ?
1818
},
1919
pointer_width: 64,
20-
data_layout: "E-m:a-Fi64-i64:64-i128:128-n32:64-S128-v256:256:256-v512:512:512".into(),
20+
data_layout: "E-m:a-Fi64-i64:64-i128:128-n32:64-f64:32:64-S128-v256:256:256-v512:512:512"
21+
.into(),
2122
arch: Arch::PowerPC64,
2223
options: base,
2324
}

src/llvm-project

tests/codegen-llvm/amdgpu-addrspacecast.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,23 @@
33
//@ compile-flags: --crate-type=rlib --target=amdgcn-amd-amdhsa -Ctarget-cpu=gfx900
44
//@ needs-llvm-components: amdgpu
55
//@ add-minicore
6+
//@ revisions: LLVM21 LLVM22
7+
//@ [LLVM21] max-llvm-major-version: 21
8+
//@ [LLVM22] min-llvm-version: 22
69
#![feature(no_core)]
710
#![no_core]
811

912
extern crate minicore;
1013

14+
// Make sure that on LLVM 22, the alloca is passed directly to the lifetime intrinsics,
15+
// not the addrspacecast.
16+
1117
// CHECK-LABEL: @ref_of_local
1218
// CHECK: [[alloca:%[0-9]]] = alloca
1319
// CHECK: %i = addrspacecast ptr addrspace(5) [[alloca]] to ptr
20+
// LLVM22: call void @llvm.lifetime.start.p5(ptr addrspace(5) [[alloca]])
21+
// CHECK: call void %f(ptr{{.*}}%i)
22+
// LLVM22: call void @llvm.lifetime.end.p5(ptr addrspace(5) [[alloca]])
1423
#[no_mangle]
1524
pub fn ref_of_local(f: fn(&i32)) {
1625
let i = 0;

0 commit comments

Comments
 (0)