Skip to content

Rollup of 6 pull requests #144231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d1a146b
tests: Skip supported-crate-types test on musl hosts
Gelbpunkt Jul 18, 2025
3fb1af3
enzyme submodule update
ZuseZ4 Jul 18, 2025
42d6b0d
make more builder functions generic
ZuseZ4 Jun 18, 2025
6340164
add -Zoffload=Enable flag behind -Zunstable-options, to enable gpu (h…
ZuseZ4 Jun 18, 2025
5958ebe
add various wrappers for gpu code generation
ZuseZ4 Jul 2, 2025
4a1a5a4
gpu host code generation
ZuseZ4 Jul 2, 2025
e2ab312
add gpu offload codegen host side test
ZuseZ4 Jul 18, 2025
c068599
add unstable-books doc for offload
ZuseZ4 Jul 18, 2025
2a03750
debug impls for drop elaborators
beepster4096 Jul 18, 2025
5a5027a
Move float non determinism helpers to math.rs
LorrensP-2158466 Jul 7, 2025
df62935
Implement nondet behaviour and change/add tests.
LorrensP-2158466 Jul 7, 2025
8978073
Change stdlib float tests to account for miri nondet floats.
LorrensP-2158466 Jul 13, 2025
8f77d54
add non-regression test for issue 144168
lqd Jul 19, 2025
e9fb744
Add test
Nadrieril Jul 20, 2025
3567ab1
Don't consider unstable fields always-inhabited
Nadrieril Jul 20, 2025
5fd597f
Rollup merge of #142097 - ZuseZ4:offload-host1, r=oli-obk
GuillaumeGomez Jul 20, 2025
2591efe
Rollup merge of #143906 - LorrensP-2158466:miri-float-nondet-foreign-…
GuillaumeGomez Jul 20, 2025
a25ef1a
Rollup merge of #144144 - Gelbpunkt:musl-crate-types-test, r=compiler…
GuillaumeGomez Jul 20, 2025
8834ffe
Rollup merge of #144162 - beepster4096:drop_elaborator_debug_impls, r…
GuillaumeGomez Jul 20, 2025
e1bd8d7
Rollup merge of #144189 - lqd:test-144168, r=petrochenkov
GuillaumeGomez Jul 20, 2025
f2f5c89
Rollup merge of #144216 - Nadrieril:revert-pin-hack, r=compiler-errors
GuillaumeGomez Jul 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ pub(crate) fn run_pass_manager(
// We then run the llvm_optimize function a second time, to optimize the code which we generated
// in the enzyme differentiation pass.
let enable_ad = config.autodiff.contains(&config::AutoDiff::Enable);
let enable_gpu = config.offload.contains(&config::Offload::Enable);
let stage = if thin {
write::AutodiffStage::PreAD
} else {
Expand All @@ -668,6 +669,12 @@ pub(crate) fn run_pass_manager(
write::llvm_optimize(cgcx, dcx, module, None, config, opt_level, opt_stage, stage)?;
}

if enable_gpu && !thin {
let cx =
SimpleCx::new(module.module_llvm.llmod(), &module.module_llvm.llcx, cgcx.pointer_size);
crate::builder::gpu_offload::handle_gpu_code(cgcx, &cx);
}

if cfg!(llvm_enzyme) && enable_ad && !thin {
let cx =
SimpleCx::new(module.module_llvm.llmod(), &module.module_llvm.llcx, cgcx.pointer_size);
Expand Down
69 changes: 69 additions & 0 deletions compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::ops::Deref;
use std::{iter, ptr};

pub(crate) mod autodiff;
pub(crate) mod gpu_offload;

use libc::{c_char, c_uint, size_t};
use rustc_abi as abi;
Expand Down Expand Up @@ -117,6 +118,74 @@ impl<'a, 'll, CX: Borrow<SCx<'ll>>> GenericBuilder<'a, 'll, CX> {
}
bx
}

// The generic builder has less functionality and thus (unlike the other alloca) we can not
// easily jump to the beginning of the function to place our allocas there. We trust the user
// to manually do that. FIXME(offload): improve the genericCx and add more llvm wrappers to
// handle this.
pub(crate) fn direct_alloca(&mut self, ty: &'ll Type, align: Align, name: &str) -> &'ll Value {
let val = unsafe {
let alloca = llvm::LLVMBuildAlloca(self.llbuilder, ty, UNNAMED);
llvm::LLVMSetAlignment(alloca, align.bytes() as c_uint);
// Cast to default addrspace if necessary
llvm::LLVMBuildPointerCast(self.llbuilder, alloca, self.cx.type_ptr(), UNNAMED)
};
if name != "" {
let name = std::ffi::CString::new(name).unwrap();
llvm::set_value_name(val, &name.as_bytes());
}
val
}

pub(crate) fn inbounds_gep(
&mut self,
ty: &'ll Type,
ptr: &'ll Value,
indices: &[&'ll Value],
) -> &'ll Value {
unsafe {
llvm::LLVMBuildGEPWithNoWrapFlags(
self.llbuilder,
ty,
ptr,
indices.as_ptr(),
indices.len() as c_uint,
UNNAMED,
GEPNoWrapFlags::InBounds,
)
}
}

pub(crate) fn store(&mut self, val: &'ll Value, ptr: &'ll Value, align: Align) -> &'ll Value {
debug!("Store {:?} -> {:?}", val, ptr);
assert_eq!(self.cx.type_kind(self.cx.val_ty(ptr)), TypeKind::Pointer);
unsafe {
let store = llvm::LLVMBuildStore(self.llbuilder, val, ptr);
llvm::LLVMSetAlignment(store, align.bytes() as c_uint);
store
}
}

pub(crate) fn load(&mut self, ty: &'ll Type, ptr: &'ll Value, align: Align) -> &'ll Value {
unsafe {
let load = llvm::LLVMBuildLoad2(self.llbuilder, ty, ptr, UNNAMED);
llvm::LLVMSetAlignment(load, align.bytes() as c_uint);
load
}
}

fn memset(&mut self, ptr: &'ll Value, fill_byte: &'ll Value, size: &'ll Value, align: Align) {
unsafe {
llvm::LLVMRustBuildMemSet(
self.llbuilder,
ptr,
align.bytes() as c_uint,
fill_byte,
size,
false,
);
}
}
}

/// Empty string, to be used where LLVM expects an instruction name, indicating
Expand Down
Loading
Loading