about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/context.rs
AgeCommit message (Collapse)AuthorLines
2025-09-25Use standard attribute logic for allocator shimNikita Popov-5/+5
Use llfn_attrs_from_instance() to generate the attributes for the allocator shim. This ensures that we generate all the usual attributes (and don't get to find out one-by-one that a certain attribute is important for a certain target). Additionally this will enable emitting the allocator-specific attributes (not included here). This change is quite awkward because the allocator shim uses SimpleCx, while llfn_attrs_from_instance uses CodegenCx. I've switched it to use SimpleCx plus tcx/sess arguments where necessary. If there's a simpler way to do this, I'd love to know about it...
2025-09-17Adds AArch64 GCS supportReuben Cruise-1/+8
- Adds option to rustc config to enable GCS - Passes `guarded-control-stack` flag to llvm if enabled
2025-09-17Rollup merge of #145660 - jbatez:darwin_objc, r=jdonszelmann,madsmtm,tmandryStuart Cook-3/+78
initial implementation of the darwin_objc unstable feature Tracking issue: https://github.com/rust-lang/rust/issues/145496 This feature makes it possible to reference Objective-C classes and selectors using the same ABI used by native Objective-C on Apple/Darwin platforms. Without it, Rust code interacting with Objective-C must resort to loading classes and selectors using costly string-based lookups at runtime. With it, these references can be loaded efficiently at dynamic load time. r? ```@tmandry``` try-job: `*apple*` try-job: `x86_64-gnu-nopt`
2025-09-16Update the minimum external LLVM to 20Josh Stone-29/+0
2025-09-13initial implementation of the darwin_objc unstable featureJo Bates-3/+78
2025-09-04compiler: Apply target features to the entry functionWANG Rui-2/+8
2025-09-02llvm: nvptx: Layout update to match LLVMMatthew Maurer-0/+4
LLVM upstream switched layouts to support 256-bit vector load/store.
2025-08-24Rename `llvm::Bool` aliases to standard const caseZalathar-1/+1
This avoids the need for `#![allow(non_upper_case_globals)]`.
2025-08-19Rollup merge of #140740 - ojeda:indirect-branch-cs-prefix, r=davidtwco许杰友 Jieyou Xu (Joe)-0/+9
Add `-Zindirect-branch-cs-prefix` Cc: ``@azhogin`` ``@Darksonn`` This goes on top of https://github.com/rust-lang/rust/pull/135927, i.e. please skip the first commit here. Please feel free to inherit it there. In fact, I am not sure if there is any use case for the flag without `-Zretpoline*`. GCC and Clang allow it, though. There is a `FIXME` for two `ignore`s in the test that I took from another test I did in the past -- they may be needed or not here since I didn't run the full CI. Either way, it is not critical. Tracking issue: https://github.com/rust-lang/rust/issues/116852. MCP: https://github.com/rust-lang/compiler-team/issues/868.
2025-08-18Rollup merge of #145309 - winstonallo:issue-145271-fix, r=tgross35Stuart Cook-0/+9
Fix `-Zregparm` for LLVM builtins This fixes the issue where `-Zregparm=N` was not working correctly when calling LLVM intrinsics By default on `x86-32`, arguments are passed on the stack. The `-Zregparm=N` flag allows the first `N` arguments to be passed in registers instead. When calling intrinsics like `memset`, LLVM still passes parameters on the stack, which prevents optimizations like tail calls. As proposed by ````@tgross35,```` I fixed this by setting the `NumRegisterParameters` LLVM module flag to `N` when the `-Zregparm=N` is set. ```rust // compiler/rust_codegen_llvm/src/context.rs#375-382 if let Some(regparm_count) = sess.opts.unstable_opts.regparm { llvm::add_module_flag_u32( llmod, llvm::ModuleFlagMergeBehavior::Error, "NumRegisterParameters", regparm_count, ); } ``` [Here](https://rust.godbolt.org/z/YMezreo48) is a before/after compiler explorer. Here is the final result for the code snippet in the original issue: ```asm entrypoint: push esi mov esi, eax mov eax, ecx mov ecx, esi pop esi jmp memset ; Tail call parameters in registers ``` Fixes: https://github.com/rust-lang/rust/issues/145271
2025-08-17Add -Zindirect-branch-cs-prefix (from draft PR)Alice Ryhl-0/+9
2025-08-14Remove lto inline logicMarcelo Domínguez-10/+0
2025-08-14Complete functionality and general cleanupMarcelo Domínguez-5/+0
2025-08-14Basic implementation of `autodiff` intrinsicMarcelo Domínguez-1/+1
2025-08-13Set NumRegisterParameters LLVM module flag to `N` when `-Zregparm=N` iswinstonallo-0/+9
set * Enforce the `-Zregparm=N` flag by setting the NumRegisterParameters LLVM module flag * Add assembly tests verifying that the parameters are passed in registers for reparm values 1, 2, and 3, for both LLVM intrinsics and non-builtin functions * Add c_void type to minicore
2025-08-12[AVR] Changed data_layoutTom Vijlbrief-0/+6
2025-07-22Rollup merge of #142097 - ZuseZ4:offload-host1, r=oli-obk许杰友 Jieyou Xu (Joe)-1/+17
gpu offload host code generation r? ghost This will generate most of the host side code to use llvm's offload feature. The first PR will only handle automatic mem-transfers to and from the device. So if a user calls a kernel, we will copy inputs back and forth, but we won't do the actual kernel launch. Before merging, we will use LLVM's Info infrastructure to verify that the memcopies match what openmp offloa generates in C++. `LIBOMPTARGET_INFO=-1 ./my_rust_binary` should print that a memcpy to and later from the device is happening. A follow-up PR will generate the actual device-side kernel which will then do computations on the GPU. A third PR will implement manual host2device and device2host functionality, but the goal is to minimize cases where a user has to overwrite our default handling due to performance issues. I'm trying to get a full MVP out first, so this just recognizes GPU functions based on magic names. The final frontend will obviously move this over to use proper macros, like I'm already doing it for the autodiff work. This work will also be compatible with std::autodiff, so one can differentiate GPU kernels. Tracking: - https://github.com/rust-lang/rust/issues/131513
2025-07-18add various wrappers for gpu code generationManuel Drehwald-1/+17
2025-07-18Update AMDGPU data layoutNikita Popov-0/+5
2025-07-14Eliminate all direct uses of LLVMMDStringInContext2Oli Scherer-2/+2
2025-07-14Use context methods instead of directly calling FFIOli Scherer-9/+5
2025-07-14Merge `typeid_metadata` and `create_metadata`Oli Scherer-3/+4
2025-07-07compiler: Parse `p-` specs in datalayout string, allow definition of custom ↵Edoardo Marangoni-1/+1
default data address space
2025-06-17Rollup merge of #142588 - ZuseZ4:generic-ctx-imprv, r=oli-obkJacob Pratt-5/+2
Generic ctx imprv Cleanup work for my gpu pr r? `@oli-obk`
2025-06-16add and use generic get_const_int functionManuel Drehwald-5/+2
2025-06-15Use `LLVMIntrinsicGetDeclaration` to completely remove the hardcoded ↵sayantn-177/+15
intrinsics list
2025-06-12Simplify implementation of Rust intrinsics by using type parameters in the cachesayantn-334/+128
2025-05-30Auto merge of #139385 - joboet:threadlocal_address, r=nikicbors-0/+1
rustc_codegen_llvm: use `threadlocal.address` intrinsic to access TLS Fixes #136044 r? `@nikic`
2025-05-29rustc_codegen_llvm: use `threadlocal.address` intrinsic to access TLSjoboet-0/+1
2025-05-28Remove a couple of uses of interior mutability around staticsbjorn3-5/+12
2025-05-28Remove codegen_unit from MiscCodegenMethodsbjorn3-4/+0
2025-05-10Use the fallback body for `{minimum,maximum}f128` on LLVM as well.Urgau-2/+8
2025-05-09Use intrinsics for `{f16,f32,f64,f128}::{minimum,maximum}` operationsUrgau-0/+10
2025-04-28remove noinline attribute and add alwaysinline after AD passbit-aloo-0/+10
2025-04-05Update the minimum external LLVM to 19Josh Stone-21/+2
2025-04-05Rollup merge of #138368 - rcvalle:rust-kcfi-arity, r=davidtwcoMatthias Krüger-0/+16
KCFI: Add KCFI arity indicator support Adds KCFI arity indicator support to the Rust compiler (see https://github.com/rust-lang/rust/issues/138311, https://github.com/llvm/llvm-project/pull/121070, and https://lore.kernel.org/lkml/CANiq72=3ghFxy8E=AU9p+0imFxKr5iU3sd0hVUXed5BA+KjdNQ@mail.gmail.com/).
2025-04-05KCFI: Add KCFI arity indicator supportRamon de C Valle-0/+16
Adds KCFI arity indicator support to the Rust compiler (see rust-lang/rust#138311, https://github.com/llvm/llvm-project/pull/121070, and https://lore.kernel.org/lkml/CANiq72=3ghFxy8E=AU9p+0imFxKr5iU3sd0hVUXed5BA+KjdNQ@mail.gmail.com/).
2025-04-05Rollup merge of #137880 - EnzymeAD:autodiff-batching, r=oli-obkStuart Cook-2/+21
Autodiff batching Enzyme supports batching, which is especially known from the ML side when training neural networks. There we would normally have a training loop, where in each iteration we would pass in some data (e.g. an image), and a target vector. Based on how close we are with our prediction we compute our loss, and then use backpropagation to compute the gradients and update our weights. That's quite inefficient, so what you normally do is passing in a batch of 8/16/.. images and targets, and compute the gradients for those all at once, allowing better optimizations. Enzyme supports batching in two ways, the first one (which I implemented here) just accepts a Batch size, and then each Dual/Duplicated argument has not one, but N shadow arguments. So instead of ```rs for i in 0..100 { df(x[i], y[i], 1234); } ``` You can now do ```rs for i in 0..100.step_by(4) { df(x[i+0],x[i+1],x[i+2],x[i+3], y[i+0], y[i+1], y[i+2], y[i+3], 1234); } ``` which will give the same results, but allows better compiler optimizations. See the testcase for details. There is a second variant, where we can mark certain arguments and instead of having to pass in N shadow arguments, Enzyme assumes that the argument is N times longer. I.e. instead of accepting 4 slices with 12 floats each, we would accept one slice with 48 floats. I'll implement this over the next days. I will also add more tests for both modes. For any one preferring some more interactive explanation, here's a video of Tim's llvm dev talk, where he presents his work. https://www.youtube.com/watch?v=edvaLAL5RqU I'll also add some other docs to the dev guide and user docs in another PR. r? ghost Tracking: - https://github.com/rust-lang/rust/issues/124509 - https://github.com/rust-lang/rust/issues/135283
2025-04-04add autodiff batching backendManuel Drehwald-2/+21
2025-03-24Auto merge of #133984 - DaniPopes:scmp-ucmp, r=scottmcmbors-0/+12
Lower BinOp::Cmp to llvm.{s,u}cmp.* intrinsics Lowers `mir::BinOp::Cmp` (`three_way_compare` intrinsic) to the corresponding LLVM `llvm.{s,u}cmp.i8.*` intrinsics. These are the intrinsics mentioned in https://github.com/rust-lang/rust/pull/118310, which are now available in LLVM 19. I couldn't find any follow-up PRs/discussions about this, please let me know if I missed something. r? `@scottmcm`
2025-03-17Remove implicit #[no_mangle] for #[rustc_std_internal_symbol]bjorn3-1/+2
2025-03-07Rollup merge of #137549 - oli-obk:llvm-ffi, r=davidtwcoMatthias Krüger-67/+76
Clean up various LLVM FFI things in codegen_llvm cc ```@ZuseZ4``` I touched some autodiff parts The major change of this PR is [bfd88ce](https://github.com/rust-lang/rust/pull/137549/commits/bfd88cead0dd79717f123ad7e9a26ecad88653cb) which makes `CodegenCx` generic just like `GenericBuilder` The other commits mostly took advantage of the new feature of making extern functions safe, but also just used some wrappers that were already there and shrunk unsafe blocks. best reviewed commit-by-commit
2025-03-06Lower BinOp::Cmp to llvm.{s,u}cmp.* intrinsicsDaniPopes-0/+12
Lowers `mir::BinOp::Cmp` (`three_way_compare` intrinsic) to the corresponding LLVM `llvm.{s,u}cmp.i8.*` intrinsics, added in LLVM 19.
2025-02-24Mark more LLVM FFI as safeOli Scherer-6/+4
2025-02-24Use a safe wrapper around an LLVM FFI functionOli Scherer-3/+8
2025-02-24Remove inherent function that has a trait method duplicate of a commonly ↵Oli Scherer-9/+7
imported trait
2025-02-24Deduplicate more functions between `SimpleCx` and `CodegenCx`Oli Scherer-5/+0
2025-02-24Generalize BaseTypeCodegenMethodsOli Scherer-9/+10
2025-02-24Avoid some duplication between SimpleCx and CodegenCxOli Scherer-44/+56
2025-02-24codegen_llvm: avoid `Deref` impls w/ extern typeDavid Wood-1/+1
`rustc_codegen_llvm` relied on `Deref` impls where `Deref::Target` was or contained an extern type - in my experimental implementation of rust-lang/rfcs#3729, this isn't possible as the `Target` associated type's `?Sized` bound cannot be relaxed backwards compatibly (unless we come up with some way of doing this). In later pull requests with the rust-lang/rfcs#3729 implementation, breakage like this could only occur for nightly users relying on the `extern_types` feature. Upstreaming this to avoid needing to keep carrying this patch locally, and I think it'll necessarily need to change eventually.