about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src
AgeCommit message (Collapse)AuthorLines
2025-09-28Rollup merge of #146763 - Zalathar:di-builder, r=jdonszelmannMatthias Krüger-80/+102
cg_llvm: Replace some DIBuilder wrappers with LLVM-C API bindings (part 5) - Part of rust-lang/rust#134001 - Follow-up to rust-lang/rust#146673 --- This is another batch of LLVMDIBuilder binding migrations, replacing some our own LLVMRust bindings with bindings to upstream LLVM-C APIs. Some of these are a little more complex than most of the previous migrations, because they split one LLVMRust binding into multiple LLVM bindings, but nothing too fancy. This appears to be the last of the low-hanging fruit. As noted in https://github.com/rust-lang/rust/issues/134001#issuecomment-2524979268, the remaining bindings are difficult or impossible to migrate at present.
2025-09-26Rollup merge of #146778 - nikic:allocator-shim-attributes, r=jackh726Matthias Krüger-114/+126
Use standard attribute logic for allocator shim 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-26Rollup merge of #146704 - jdonszelmann:port-debug-visualizer, r=petrochenkovMatthias Krüger-1/+1
port `#[debugger_visualizer]` to the new attribute system
2025-09-25Rollup merge of #147015 - Zalathar:dispose-tm, r=lqdStuart Cook-4/+3
Use `LLVMDisposeTargetMachine` After bumping the minimum LLVM version to 20 (rust-lang/rust#145071), we no longer need to run any custom code when disposing of a TargetMachine, so we can just use the upstream LLVM-C function.
2025-09-25Rollup merge of #146667 - calebzulawski:simd-mono-lane-limit, r=lcnr,RalfJungStuart Cook-6/+15
Add an attribute to check the number of lanes in a SIMD vector after monomorphization Allows std::simd to drop the `LaneCount<N>: SupportedLaneCount` trait and maintain good error messages. Also, extends rust-lang/rust#145967 by including spans in layout errors for all ADTs. r? ``@RalfJung`` cc ``@workingjubilee`` ``@programmerjake``
2025-09-25Use `LLVMDisposeTargetMachine`Zalathar-4/+3
2025-09-25Use standard attribute logic for allocator shimNikita Popov-114/+126
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-24Auto merge of #146338 - CrooseGit:dev/reucru01/AArch64-enable-GCS, ↵bors-2/+12
r=Urgau,davidtwco Extends AArch64 branch protection support to include GCS Extends existing support for AArch64 branch protection to include support for [Guarded Control Stacks](https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/arm-a-profile-architecture-2022#guarded-control-stack-gcs:~:text=Extraction%20or%20tracking.-,Guarded%20Control%20Stack%20(GCS),-With%20the%202022).
2025-09-23Including spans in layout errors for all ADTsCaleb Zulawski-4/+6
2025-09-23Add an attribute to check the number of lanes in a SIMD vector after ↵Caleb Zulawski-2/+9
monomorphization Unify zero-length and oversized SIMD errors
2025-09-23Auto merge of #146317 - saethlin:panic=immediate-abort, r=nnethercotebors-3/+2
Add panic=immediate-abort MCP: https://github.com/rust-lang/compiler-team/issues/909 This adds a new panic strategy, `-Cpanic=immediate-abort`. This panic strategy essentially just codifies use of `-Zbuild-std-features=panic_immediate_abort`. This PR is intended to just set up infrastructure, and while it will change how the compiler is invoked for users of the feature, there should be no other impacts. In many parts of the compiler, `PanicStrategy::ImmediateAbort` behaves just like `PanicStrategy::Abort`, because actually most parts of the compiler just mean to ask "can this unwind?" so I've added a helper function so we can say `sess.panic_strategy().unwinds()`. The panic and unwind strategies have some level of compatibility, which mostly means that we can pre-compile the sysroot with unwinding panics then the sysroot can be linked with aborting panics later. The immediate-abort strategy is all-or-nothing, enforced by `compiler/rustc_metadata/src/dependency_format.rs` and this is tested for in `tests/ui/panic-runtime/`. We could _technically_ be more compatible with the other panic strategies, but immediately-aborting panics primarily exist for users who want to eliminate all the code size responsible for the panic runtime. I'm open to other use cases if people want to present them, but not right now. This PR is already large. `-Cpanic=immediate-abort` sets both `cfg(panic = "immediate-abort")` _and_ `cfg(panic = "abort")`. bjorn3 pointed out that people may be checking for the abort cfg to ask if panics will unwind, and also the sysroot feature this is replacing used to require `-Cpanic=abort` so this seems like a good back-compat step. At least for the moment. Unclear if this is a good idea indefinitely. I can imagine this being confusing. The changes to the standard library attributes are purely mechanical. Apart from that, I removed an `unsafe` we haven't needed for a while since the `abort` intrinsic became safe, and I've added a helpful diagnostic for people trying to use the old feature. To test that `-Cpanic=immediate-abort` conflicts with other panic strategies, I've beefed up the core-stubs infrastructure a bit. There is now a separate attribute to set flags on it. I've added a test that this produces the desired codegen, called `tests/run-make-cargo/panic-immediate-abort-codegen/` and also a separate run-make-cargo test that checks that we can build a binary.
2025-09-22Rollup merge of #146845 - Zalathar:prof-target-machine, r=KobzolStuart Cook-0/+10
Add self-profile events for target-machine creation These code paths are surprisingly hot in the `large-workspace` benchmark (e.g. see perf changes from rust-lang/rust#146700), suggesting room for more improvement. It would be handy to see some detailed timings and execution counts.
2025-09-22Rollup merge of #146831 - taiki-e:powerpc-clobber, r=AmanieuStuart Cook-2/+12
Support ctr and lr as clobber-only registers in PowerPC inline assembly Follow-up to rust-lang/rust#131341. CTR and LR are marked as volatile in all ABIs, but I skipped them in rust-lang/rust#131341 due to they are currently marked as reserved. https://github.com/rust-lang/rust/blob/dd7fda570040e8a736f7d8bc28ddd1b444aabc82/compiler/rustc_target/src/asm/powerpc.rs#L209-L212 However, they are actually only unusable as input/output of inline assembly, and should be fine to support as clobber-only registers as discussed in [#t-compiler > ppc/ppc64 inline asm support](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/ppc.2Fppc64.20inline.20asm.20support/with/540413845). r? ````@Amanieu```` or ````@workingjubilee```` cc ````@programmerjake```` ````@rustbot```` label +O-PowerPC +A-inline-assembly
2025-09-21port `#[debugger_visualizer]` to the new attribute systemJana Dönszelmann-1/+1
2025-09-21emit attribute for readonly non-pure inline assemblyFolkert de Vries-2/+3
2025-09-21Add panic=immediate-abortBen Kimock-3/+2
2025-09-21Add self-profile events for target-machine creationZalathar-0/+10
These code paths are surprisingly hot in the `large-workspace` benchmark; it would be handy to see some detailed timings and execution counts.
2025-09-21Support ctr and lr as clobber-only registers in PowerPC inline assemblyTaiki Endo-2/+12
2025-09-19generate list of all variants with `target_spec_enum`Deadbeef-13/+3
This helps us avoid the hardcoded lists elsewhere.
2025-09-19Auto merge of #146700 - Zalathar:quoted-args, r=nikicbors-28/+85
cg_llvm: Move target machine command-line quoting from C++ to Rust When this code was introduced in rust-lang/rust#130446 and rust-lang/rust#131805, it was complicated by the need to maintain compatibility with earlier versions of LLVM. Now that LLVM 20 is the baseline (rust-lang/rust#145071), we can do all of the quoting in pure Rust code, and pass two flat strings to LLVM to be used as-is. --- In this PR, my priority has been to preserve the existing behaviour as much as possible, without worrying too much about what the behaviour *should* be. (Though I did avoid a leading space before the first argument.)
2025-09-19Rollup merge of #146615 - a4lg:codegen-llvm-feature-conversion-tidying, ↵Stuart Cook-22/+20
r=workingjubilee rustc_codegen_llvm: Feature Conversion Tidying The author thinks we can improve `to_llvm_features`, a function to convert a Rust target feature name into an LLVM feature (or nothing, to ignore features unsupported by LLVM) for better maintainability. 1. We can simplify some clauses and some expressions. 2. There are some readability issues. This PR attempts to resolve some of them by tidying many cases.
2025-09-19Remove some unnecessary `as u64` castsZalathar-4/+4
In each of these casts, the LHS is already `u64`.
2025-09-19Use `LLVMDIBuilderCreate(Auto|Parameter)Variable`Zalathar-44/+57
2025-09-19Use `LLVMDIBuilder(CreateExpression|InsertDeclareRecordAtEnd)`Zalathar-16/+26
2025-09-19Use `LLVMDIBuilderGetOrCreateArray`Zalathar-7/+7
2025-09-19Use `LLVMDIBuilderGetOrCreateSubrange`Zalathar-9/+8
2025-09-18Auto merge of #142544 - Sa4dUs:prevent-abi-changes, r=ZuseZ4bors-3/+44
Prevent ABI changes affect EnzymeAD This PR handles ABI changes for autodiff input arguments to improve Enzyme compatibility. Fundamentally this adjusts activities when a function argument is lowered as an `ScalarPair`, so there's no mismatch between diff activities and args. Also removes activities corresponding to ZSTs. fixes: https://github.com/rust-lang/rust/issues/144025 r? `@ZuseZ4`
2025-09-18Move target machine command-line quoting from C++ to RustZalathar-28/+85
2025-09-18Rollup merge of #146673 - Zalathar:di-builder, r=nnethercoteStuart Cook-74/+103
cg_llvm: Replace some DIBuilder wrappers with LLVM-C API bindings (part 4) - Part of rust-lang/rust#134001 - Follow-up to rust-lang/rust#146631 --- This is another batch of LLVMDIBuilder binding migrations, replacing some our own LLVMRust bindings with bindings to upstream LLVM-C APIs.
2025-09-17Rollup merge of #146598 - bjorn3:feature_llvm_enzyme, r=davidtwcoJana Dönszelmann-7/+9
Make llvm_enzyme a regular cargo feature This makes it clearer that it is set by the build system rather than by the rustc that compiles the current rustc. It also avoids bootstrap needing to pass `--check-cfg llvm_enzyme` to rustc.
2025-09-17Rollup merge of #146485 - zachs18:store_fn_arg-no-unsized, r=davidtwcoJana Dönszelmann-8/+3
Remove unsized arg handling in `ArgAbiBuilderMethods::store_fn_arg` implementations ... since it is unreachable and would ICE anyway. These branches are unreachable with how `store_fn_arg` is currently used (where it is called, unsized arguments are either: 1. not (yet) supported, or 2. handled differently)[^1], and even if they were reachable, they would ICE anyway, since they call [`OperandValue::store`](https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_codegen_ssa/mir/operand.rs.html#855-861), which calls [`OperandValue::store_with_flags`](https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_codegen_ssa/mir/operand.rs.html#887-926) which [panics on any unsized layout](https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_codegen_ssa/mir/operand.rs.html#900-903). Also updates the `bug!` message in `store_arg` to not suggest `store_fn_arg` for unsized args. [^1]: `store_fn_arg` is only nontrivially[^2] called in `compiler/rustc_codegen_ssa/src/mir/mod.rs` for: Line 428 `extern "rust-call"` tuple (un)splitting, which does not support unsized arguments, Line 496 which is only for sized `PassMode::Indirect` (`meta_attrs: None`) arguments, and Line 521 which is only for non-`PassMode::Indirect` arguments which can never be unsized. [^2]: `<Bx as ArgAbiBuilderMethods>::store_fn_arg` is what is actually called, but codegen_llvm and codegen_gcc's builders both delegate to their own `codegen_crate::ArgAbiExt::store_fn_arg`, which contain the actual implementations that are changed in this PR.
2025-09-17Check ZST via `PassMode`Marcelo Domínguez-4/+19
2025-09-17Adds AArch64 GCS supportReuben Cruise-2/+12
- Adds option to rustc config to enable GCS - Passes `guarded-control-stack` flag to llvm if enabled
2025-09-17rustc_codegen_llvm: Reorder conversion casesTsukasa OI-11/+11
For maintainability, this commit reorders target feature conversion cases by the architecture.
2025-09-17rustc_codegen_llvm: Simplify `arch` conversionTsukasa OI-10/+7
This commit simplifies construction of `arch` from `sess.target.arch`. It also preserves a reference to `sess.target.arch` as `raw_arch` to make this function future proof.
2025-09-17rustc_codegen_llvm: Name major version of LLVMTsukasa OI-1/+2
It makes LLVM version comparison clearer.
2025-09-17Use `LLVMDIBuilderCreateTypedef`Zalathar-15/+17
2025-09-17Use `LLVMDIBuilderCreateQualifiedType`Zalathar-9/+13
2025-09-17Use `LLVMDIBuilderCreateStaticMemberType`Zalathar-34/+57
2025-09-17Use `LLVMDIBuilderCreateMemberType`Zalathar-16/+16
2025-09-17Support ZST argsMarcelo Domínguez-1/+10
2025-09-17doc and move single branch match to an if letMarcelo Domínguez-6/+6
2025-09-17Adjust autodiff actitivies for ScalarPairMarcelo Domínguez-0/+17
2025-09-17Rollup merge of #146631 - Zalathar:di-builder, r=nnethercoteStuart Cook-130/+149
cg_llvm: Replace some DIBuilder wrappers with LLVM-C API bindings (part 3) - Part of rust-lang/rust#134001 - Follow-up to rust-lang/rust#136375 - Follow-up to rust-lang/rust#136632 --- This is another batch of LLVMDIBuilder binding migrations, replacing some our own LLVMRust bindings with bindings to upstream LLVM-C APIs. This PR migrates all of the bindings that were touched by rust-lang/rust#136632, plus `LLVMDIBuilderCreateStructType`.
2025-09-17Rollup merge of #145660 - jbatez:darwin_objc, r=jdonszelmann,madsmtm,tmandryStuart Cook-8/+342
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-17Use `LLVMDIBuilderCreateStructType`Zalathar-28/+29
2025-09-17Use `LLVMDIBuilderCreatePointerType`Zalathar-43/+45
2025-09-17Use `LLVMDIBuilderCreateBasicType`Zalathar-10/+12
2025-09-17Use `LLVMDIBuilderCreateArrayType`Zalathar-16/+15
2025-09-17Use `LLVMDIBuilderCreateUnionType`Zalathar-21/+25