about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/context.rs
AgeCommit message (Collapse)AuthorLines
2024-09-19Fix a comment.Nicholas Nethercote-2/+2
I'm pretty sure `CodegenCx` applies to codegen units, rather than compilation units.
2024-09-19replace some deprecated functionsLuv-Ray-4/+3
2024-09-18Update the minimum external LLVM to 18Josh Stone-8/+0
2024-09-17Use associative type defaults in `{Layout,FnAbi}OfHelpers`.Nicholas Nethercote-6/+0
This avoids some repetitive boilerplate code.
2024-09-17Rename supertraits of `CodegenMethods`.Nicholas Nethercote-1/+1
Supertraits of `BuilderMethods` are all called `XyzBuilderMethods`. Supertraits of `CodegenMethods` are all called `XyzMethods`. This commit changes the latter to `XyzCodegenMethods`, for consistency.
2024-09-10Add -Z small-data-thresholdPaul Menage-1/+19
This flag allows specifying the threshold size above which LLVM should not consider placing small objects in a .sdata or .sbss section. Support is indicated in the target options via the small-data-threshold-support target option, which can indicate either an LLVM argument or an LLVM module flag. To avoid duplicate specifications in a large number of targets, the default value for support is DefaultForArch, which is translated to a concrete value according to the target's architecture.
2024-08-27Rollup merge of #126013 - nnethercote:unreachable_pub, r=UrgauMatthias Krüger-4/+6
Add `#[warn(unreachable_pub)]` to a bunch of compiler crates By default `unreachable_pub` identifies things that need not be `pub` and tells you to make them `pub(crate)`. But sometimes those things don't need any kind of visibility. So they way I did these was to remove the visibility entirely for each thing the lint identifies, and then add `pub(crate)` back in everywhere the compiler said it was necessary. (Or occasionally `pub(super)` when context suggested that was appropriate.) Tedious, but results in more `pub` removal. There are plenty more crates to do but this seems like enough for a first PR. r? `@compiler-errors`
2024-08-21Add missing module flags for CFI and KCFI sanitizersSami Tolvanen-0/+31
Set the cfi-normalize-integers and kcfi-offset module flags when Control-Flow Integrity sanitizers are used, so functions generated by the LLVM backend use the same CFI/KCFI options as rustc. cfi-normalize-integers tells LLVM to also use integer normalization for generated functions when -Zsanitizer-cfi-normalize-integers is used. kcfi-offset specifies the number of prefix nops between the KCFI type hash and the function entry when -Z patchable-function-entry is used. Note that LLVM assumes all indirectly callable functions use the same number of prefix NOPs with -Zsanitizer=kcfi.
2024-08-20Avoid extra `cast()`s after `CStr::as_ptr()`Josh Stone-11/+11
These used to be `&str` literals that did need a pointer cast, but that became a no-op after switching to `c""` literals in #118566.
2024-08-17Fix `is_val_statically_known` for floatsbeetrees-0/+2
2024-08-16Add `warn(unreachable_pub)` to `rustc_codegen_llvm`.Nicholas Nethercote-4/+6
2024-08-07Rollup merge of #128221 - calebzulawski:implied-target-features, r=AmanieuMatthias Krüger-1/+1
Add implied target features to target_feature attribute See [zulip](https://rust-lang.zulipchat.com/#narrow/stream/208962-t-libs.2Fstdarch/topic/Why.20would.20target-feature.20include.20implied.20features.3F) for some context. Adds implied target features, e.g. `#[target_feature(enable = "avx2")]` acts like `#[target_feature(enable = "avx2,avx,sse4.2,sse4.1...")]`. Fixes #128125, fixes #128426 The implied feature sets are taken from [the rust reference](https://doc.rust-lang.org/reference/attributes/codegen.html?highlight=target-fea#x86-or-x86_64), there are certainly more features and targets to add. Please feel free to reassign this to whoever should review it. r? ``@Amanieu``
2024-08-07Don't use LLVM to compute -Ctarget-featureCaleb Zulawski-1/+1
2024-08-07Don't use LLVM's target featuresCaleb Zulawski-1/+1
2024-08-01Specify the integer type of the `powi` LLVM intrinsicTrevor Gross-4/+4
Since LLVM <https://reviews.llvm.org/D99439> (4c7f820b2b20, "Update @llvm.powi to handle different int sizes for the exponent"), the size of the integer can be specified for the `powi` intrinsic. Make use of this so it is more obvious that integer size is consistent across all float types. This feature is available since LLVM 13 (October 2021). Based on bootstrap we currently support >= 17.0, so there should be no support problems.
2024-07-29Reformat `use` declarations.Nicholas Nethercote-20/+17
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-16Fix unsafe_op_in_unsafe_fn in compilerMichael Goulet-110/+149
2024-07-02Fix spansMichael Goulet-2/+2
2024-07-02Give Instance::expect_resolve a spanMichael Goulet-0/+1
2024-06-21Remove check_overflow method from MiscMethodsbjorn3-8/+0
It can be retrieved from the Session too.
2024-06-21Move vcall_visibility_metadata optimization hint out of a debuginfo ↵bjorn3-0/+10
generation method
2024-06-12Adjust LoongArch64 data layouts for LLVM updateHans Wennborg-0/+8
The data layout was changed in LLVM 19: llvm/llvm-project#93814
2024-05-06Adjust 64-bit ARM data layouts for LLVM updateMatthew Maurer-0/+9
LLVM has updated data layouts to specify `Fn32` on 64-bit ARM to avoid C++ accidentally underaligning functions when trying to comply with member function ABIs. This should only affect Rust in cases where we had a similar bug (I don't believe we have one), but our data layout must match to generate code. As a compatibility adaptatation, if LLVM is not version 19 yet, `Fn32` gets voided from the data layout. See llvm/llvm-project#90415
2024-04-22Stabilize the size of incr comp object file namesBen Kimock-2/+3
2024-04-09Pass value and valueLen to create a StringRefLevi Zim-7/+5
Instead of creating a cstring. Co-authored-by: LoveSy <shana@zju.edu.cn>
2024-04-09Set target-abi module flag for RISC-V targetskxxt-15/+33
Fixes cross-language LTO on RISC-V targets (Fixes #121924)
2024-03-23Auto merge of #119552 - krtab:dead_code_priv_mod_pub_field, r=cjgillot,saethlinbors-5/+1
Replace visibility test with reachability test in dead code detection Fixes https://github.com/rust-lang/rust/issues/119545 Also included is a fix for an error now flagged by the lint
2024-03-20Rollup merge of #121543 - onur-ozkan:clippy-args, r=oli-obkMatthias Krüger-0/+1
various clippy fixes We need to keep the order of the given clippy lint rules before passing them. Since clap doesn't offer any useful interface for this purpose out of the box, we have to handle it manually. Additionally, this PR makes `-D` rules work as expected. Previously, lint rules were limited to `-W`. By enabling `-D`, clippy began to complain numerous lines in the tree, all of which have been resolved in this PR as well. Fixes #121481 cc `@matthiaskrgr`
2024-03-20resolve clippy errorsonur-ozkan-0/+1
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-03-17Update the minimum external LLVM to 17Josh Stone-11/+0
2024-03-12Remove unused fields in some structuresArthur Carcano-5/+1
The dead_code lint was previously eroneously missing those. Since this lint bug has been fixed, the unused fields need to be removed.
2024-03-11Rollup merge of #122166 - beetrees:remove-field-remapping, r=davidtwcoJubilee-11/+2
Remove the unused `field_remapping` field from `TypeLowering` The `field_remapping` field of `TypeLowering` has been unused since #121665. This PR removes it, then replaces the `TypeLowering` struct with its only remaining member `&'ll Type`.
2024-03-10use Instance::expect_resolve() instead of unwraping Instance::resolve()Ralf Jung-5/+6
2024-03-08Remove handling for previously dropped LLVM versionbeetrees-10/+4
2024-03-08Remove the unused `field_remapping` field from `TypeLowering`beetrees-11/+2
2024-03-01Add `f16` and `f128` LLVM intrinsicsTrevor Gross-0/+48
2024-01-29Avoid ICE when is_val_statically_known is not of a supported typeAlex Huang-0/+1
2024-01-27Auto merge of #120062 - davidtwco:llvm-data-layout-check, r=wesleywiserbors-29/+9
llvm: change data layout bug to an error and make it trigger more Fixes #33446. Don't skip the inconsistent data layout check for custom LLVMs or non-built-in targets. With #118708, all targets will have a simple test that would trigger this error if LLVM's data layouts do change - so data layouts would be corrected during the LLVM upgrade. Therefore, with builtin targets, this error won't happen with our LLVM because each target will have been confirmed to work. With non-builtin targets, this error is probably useful to have because you can change the data layout in your target and if it is wrong then that could lead to bugs. When using a custom LLVM, the same justification makes sense for non-builtin targets as with our LLVM, the user can update their target to match their LLVM and that's probably a good thing to do. However, with a custom LLVM, the user cannot change the builtin target data layouts if they don't match - though given that the compiler's data layout is used for layout computation and a bunch of other things - you could get some bugs because of the mismatch and probably want to know about that. I'm not sure if this is something that people do and is okay, but I doubt it? `CFG_LLVM_ROOT` was also always set during local development with `download-ci-llvm` so this bug would never trigger locally. In #33446, two points are raised: - In the issue itself, changing this from a `bug!` to a proper error is what is suggested, by using `isCompatibleDataLayout` from LLVM, but that function still just does the same thing that we do and check for equality, so I've avoided the additional code necessary to do that FFI call. - `@Mark-Simulacrum` suggests a different check is necessary to maintain backwards compatibility with old LLVM versions. I don't know how often this comes up, but we can do that with some simple string manipulation + LLVM version checks as happens already for LLVM 17 just above this diff.
2024-01-25Auto merge of #119911 - NCGThompson:is-statically-known, r=oli-obkbors-0/+14
Replacement of #114390: Add new intrinsic `is_var_statically_known` and optimize pow for powers of two This adds a new intrinsic `is_val_statically_known` that lowers to [``@llvm.is.constant.*`](https://llvm.org/docs/LangRef.html#llvm-is-constant-intrinsic).` It also applies the intrinsic in the int_pow methods to recognize and optimize the idiom `2isize.pow(x)`. See #114390 for more discussion. While I have extended the scope of the power of two optimization from #114390, I haven't added any new uses for the intrinsic. That can be done in later pull requests. Note: When testing or using the library, be sure to use `--stage 1` or higher. Otherwise, the intrinsic will be a noop and the doctests will be skipped. If you are trying out edits, you may be interested in [`--keep-stage 0`](https://rustc-dev-guide.rust-lang.org/building/suggested.html#faster-builds-with---keep-stage). Fixes #47234 Resolves #114390 `@Centri3`
2024-01-19Add new intrinsic `is_constant` and optimize `pow`Catherine Flores-0/+14
Fix overflow check Make MIRI choose the path randomly and rename the intrinsic Add back test Add miri test and make it operate on `ptr` Define `llvm.is.constant` for primitives Update MIRI comment and fix test in stage2 Add const eval test Clarify that both branches must have the same side effects guaranteed non guarantee use immediate type instead Co-Authored-By: Ralf Jung <post@ralfj.de>
2024-01-19LLVM 18 x86 data layout updateMatthew Maurer-0/+8
With https://reviews.llvm.org/D86310 LLVM now has i128 aligned to 16-bytes on x86 based platforms. This will be in LLVM-18. This patch updates all our spec targets to be 16-byte aligned, and removes the alignment when speaking to older LLVM. This results in Rust overaligning things relative to LLVM on older LLVMs. This alignment change was discussed in rust-lang/compiler-team#683 See #54341 for additional information about why this is happening and where this will be useful in the future. This *does not* stabilize `i128`/`u128` for FFI.
2024-01-18llvm: simplify data layout checkDavid Wood-29/+9
Don't skip the inconsistent data layout check for custom LLVMs. With #118708, all targets will have a simple test that would trigger this check if LLVM's data layouts do change - so data layouts would be corrected during the LLVM upgrade. Therefore, with builtin targets, this check won't trigger with our LLVM because each target will have been confirmed to work. With non-builtin targets, this check is probably useful to have because you can change the data layout in your target and if its wrong then that could lead to bugs. When using a custom LLVM, the same justification makes sense for non-builtin targets as with our LLVM, the user can update their target to match their LLVM and that's probably a good thing to do. However, with a custom LLVM, the user cannot change the builtin target data layouts if they don't match - though given that the compiler's data layout is used for layout computation and a bunch of other things - you could get some bugs because of the mismatch and probably want to know about that. `CFG_LLVM_ROOT` was also always set during local development with `download-ci-llvm` so this bug would never trigger locally. Signed-off-by: David Wood <david@davidtw.co>
2023-12-24Remove `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-3/+3
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access.
2023-12-14Auto merge of #118566 - klensy:cstr-new, r=WaffleLapkinbors-18/+16
use c literals in compiler and library Relands refreshed https://github.com/rust-lang/rust/pull/111647
2023-12-07Add emulated TLS supportquininer-0/+1
Currently LLVM uses emutls by default for some targets (such as android, openbsd), but rust does not use it, because `has_thread_local` is false. This commit has some changes to allow users to enable emutls: 1. add `-Zhas-thread-local` flag to specify that std uses `#[thread_local]` instead of pthread key. 2. when using emutls, decorate symbol names to find thread local symbol correctly. 3. change `-Zforce-emulated-tls` to `-Ztls-model=emulated` to explicitly specify whether to generate emutls.
2023-12-03compiler: replace cstr macro with c str literals in compiler and few other c ↵klensy-18/+16
str replacements
2023-11-27Auto merge of #117947 - Dirbaio:drop-llvm-15, r=cuviperbors-12/+0
Update the minimum external LLVM to 16. With this change, we'll have stable support for LLVM 16 and 17. For reference, the previous increase to LLVM 15 was #114148 [Relevant zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/riscv.20forced-atomics)
2023-11-21convert ehcont-guard to an unstable optionArlie Davis-1/+2
2023-11-21Add support for generating the EHCont sectionArlie Davis-0/+9
In the future Windows will enable Control-flow Enforcement Technology (CET aka Shadow Stacks). To protect the path where the context is updated during exception handling, the binary is required to enumerate valid unwind entrypoints in a dedicated section which is validated when the context is being set during exception handling. The required support for EHCONT has already been merged into LLVM, long ago. This change adds the Rust codegen option to enable it. Reference: * https://reviews.llvm.org/D40223 This also adds a new `ehcont-guard` option to the bootstrap config which enables EHCont Guard when building std.
2023-11-21Update the minimum external LLVM to 16.Dario Nieuwenhuis-12/+0