Commit graph

2378 commits

Author SHA1 Message Date
bors
feb32c6546 Auto merge of #134794 - RalfJung:abi-required-target-features, r=workingjubilee
Add a notion of "some ABIs require certain target features"

I think I finally found the right shape for the data and checks that I recently added in https://github.com/rust-lang/rust/pull/133099, https://github.com/rust-lang/rust/pull/133417, https://github.com/rust-lang/rust/pull/134337: we have a notion of "this ABI requires the following list of target features, and it is incompatible with the following list of target features". Both `-Ctarget-feature` and `#[target_feature]` are updated to ensure we follow the rules of the ABI.  This removes all the "toggleability" stuff introduced before, though we do keep the notion of a fully "forbidden" target feature -- this is needed to deal with target features that are actual ABI switches, and hence are needed to even compute the list of required target features.

We always explicitly (un)set all required and in-conflict features, just to avoid potential trouble caused by the default features of whatever the base CPU is. We do this *before* applying `-Ctarget-feature` to maintain backward compatibility; this poses a slight risk of missing some implicit feature dependencies in LLVM but has the advantage of not breaking users that deliberately toggle ABI-relevant target features. They get a warning but the feature does get toggled the way they requested.

For now, our logic supports x86, ARM, and RISC-V (just like the previous logic did). Unsurprisingly, RISC-V is the nicest. ;)

As a side-effect this also (unstably) allows *enabling* `x87` when that is harmless. I used the opportunity to mark SSE2 as required on x86-64, to better match the actual logic in LLVM and because all x86-64 chips do have SSE2. This infrastructure also prepares us for requiring SSE on x86-32 when we want to use that for our ABI (and for float semantics sanity), see https://github.com/rust-lang/rust/issues/133611, but no such change is happening in this PR.

r? `@workingjubilee`
2025-01-05 23:21:06 +00:00
Ralf Jung
2e64b5352b add dedicated type for ABI target feature constraints 2025-01-05 10:46:30 +01:00
bors
3dc3c524f7 Auto merge of #133990 - Walnut356:static_const, r=workingjubilee
[Debuginfo] Force enum `DISCR_*` to `static const u64` to allow for inspection via LLDB

see [here](486614878) for more info.

This change mainly helps `*-msvc` debugged with LLDB. Currently, LLDB cannot inspect `static` struct fields, so the intended visualization for enums is only borderline functional, and niche enums with ranges of discriminant cannot be determined at all .

LLDB *can* inspect `static const` values (though for whatever reason, non-enum/non-u64 consts don't work).

This change adds the `LLVMRustDIBuilderCreateQualifiedType` to the rust FFI layer to wrap the discr type with a `const` modifier, as well as forcing all generated integer enum `DISCR_*` values to be u64's. Those values will only ever be used by debugger visualizers anyway, so it shouldn't be a huge deal, but I left a fixme comment for it just in case.. The `tag` also still properly reflects the discriminant type, so no information is lost.
2025-01-04 23:56:29 +00:00
Flakebi
56bf673f0a
Remove range-metadata amdgpu workaround
Range metadata was disabled for amdgpu due to a backend bug. I did not
encounter any problems when removing the workaround to enable range
metadata (tried compiling `core` and `alloc`), so I assume this has
been fixed in LLVM in the last years.

Remove the workaround to re-enable range metadata.
2025-01-02 15:45:04 +01:00
Manuel Drehwald
d753cbf779 upstream rustc_codegen_llvm changes for enzyme/autodiff 2025-01-01 21:42:45 +01:00
Ralf Jung
912b7291d0 add ABI target features *before* -Ctarget-features 2024-12-31 12:41:20 +01:00
Ralf Jung
eb527424a5 x86-64 hardfloat actually requires sse2 2024-12-31 12:41:20 +01:00
Ralf Jung
cfae43d638 clean up target feature system; most of the toggleability is now handled by the ABI target feature check 2024-12-31 12:41:20 +01:00
Ralf Jung
2bf27e09be explicitly model that certain ABIs require/forbid certain target features 2024-12-31 12:41:20 +01:00
Walnut
a1191e30b6 force enum DISCR_* to const u64 to allow for inspection via LLDB's SBTypeStaticField::GetConstantValue() 2024-12-30 19:01:48 -06:00
Ralf Jung
a0dbb37ebd add llvm_floatabi field to target spec that controls FloatABIType 2024-12-30 21:59:05 +01:00
Ralf Jung
fff026c8e5 rustc_llvm: expose FloatABIType target machine parameter 2024-12-30 18:10:59 +01:00
Ralf Jung
62bb35ab5d make -Csoft-float have an effect on all ARM targets 2024-12-29 11:10:36 +01:00
Scott McMurray
4669c0d756 Override carrying_mul_add in cg_llvm 2024-12-27 08:17:40 -08:00
Walnut
bc4266ca96 add LLVMRustDIBuilderCreateQualifiedType to ffi 2024-12-23 19:12:32 -06:00
bjorn3
c02c311d84 Remove some dead code around import library generation
This was missed when replacing the usage of LLVM for generating import
libraries.
2024-12-20 15:20:15 +00:00
Matthias Krüger
57cbd078f2
Rollup merge of #134497 - Zalathar:spans, r=jieyouxu
coverage: Store coverage source regions as `Span` until codegen (take 2)

This is an attempt to re-land #133418:

> Historically, coverage spans were converted into line/column coordinates during the MIR instrumentation pass.

> This PR moves that conversion step into codegen, so that coverage spans spend most of their time stored as Span instead.

> In addition to being conceptually nicer, this also reduces the size of coverage mappings in MIR, because Span is smaller than 4x u32.

That PR was reverted by #133608, because in some circumstances not covered by our test suite we were emitting coverage metadata that was causing `llvm-cov` to exit with an error (#133606).

---

The implementation here is *mostly* the same, but adapted for subsequent changes in the relevant code (e.g. #134163).

I believe that the changes in #134163 should be sufficient to prevent the problem that required the original PR to be reverted. But I haven't been able to reproduce the original breakage in a regression test, and the `llvm-cov` error message is extremely unhelpful, so I can't completely rule out the possibility of this breaking again.

r? jieyouxu (reviewer of the original PR)
2024-12-19 15:26:16 +01:00
Zalathar
aced4dcf10 coverage: Add a synthetic test for when all spans are discarded 2024-12-19 22:03:43 +11:00
Zalathar
837a25dd41 coverage: Identify source files by ID, not by interned filename 2024-12-19 18:09:09 +11:00
Zalathar
34ed51cb83 coverage: Store coverage source regions as Span until codegen 2024-12-19 18:09:09 +11:00
Zalathar
c3780e1d22 coverage: Quietly skip functions that end up having no mappings
In codegen, a used function with `FunctionCoverageInfo` but no mappings has
historically indicated a bug. However, that will no longer be the case after
moving some fallible span-processing steps into codegen.
2024-12-19 18:09:07 +11:00
Zalathar
d416cead5a coverage: Rename some FFI fields from span to cov_span
This will avoid confusion with actual `Span` spans.
2024-12-19 17:26:01 +11:00
Ralf Jung
397ae3cdf6 fix outdated comment
Co-authored-by: Camille Gillot <gillot.camille@gmail.com>
2024-12-18 11:01:54 +01:00
Ralf Jung
e023590de4 make no-variant types a dedicated Variants variant 2024-12-18 11:01:54 +01:00
Ralf Jung
21de42bf8d Variants::Single: do not use invalid VariantIdx for uninhabited enums 2024-12-18 11:00:21 +01:00
bors
a89ca2c85e Auto merge of #134243 - nnethercote:re-export-more-rustc_span, r=jieyouxu
Re-export more `rustc_span::symbol` things from `rustc_span`.

`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason.

This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers to `rustc_span::`. This is a 300+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.

r? `@jieyouxu`
2024-12-18 02:56:38 +00:00
Nicholas Nethercote
2620eb42d7 Re-export more rustc_span::symbol things from rustc_span.
`rustc_span::symbol` defines some things that are re-exported from
`rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some
closely related things such as `Ident` and `kw`. So you can do `use
rustc_span::{Symbol, sym}` but you have to do `use
rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good
reason.

This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`,
and changes many `rustc_span::symbol::` qualifiers in `compiler/` to
`rustc_span::`. This is a 200+ net line of code reduction, mostly
because many files with two `use rustc_span` items can be reduced to
one.
2024-12-18 13:38:53 +11:00
Matthias Krüger
e696f5c180
Rollup merge of #134323 - Zalathar:dismantle-map-data, r=jieyouxu
coverage: Dismantle `map_data.rs` by moving its responsibilities elsewhere

This is a series of incremental changes that combine to let us get rid of `coverageinfo/map_data.rs`, by moving all of its responsibilities into more appropriate places.

Some of the notable consequences are:

- We once again build the per-CGU file table on the fly while preparing individual covfun records, instead of building the whole table up-front. The up-front approach was introduced by #117042 to work around various other problems in generating the covmap/covfun records, but subsequent cleanups have made that approach no longer necessary.
- Expression conversion and mapping-region conversion are now performed directly in `mapgen::covfun`, which should make future changes easier.
- We no longer insert unused function instances into the same map that is also used to track used function instances. This helps to decouple the handling of used vs unused functions.

---

There should be no meaningful change to compiler output. The file table is no longer sorted, because reordering it would invalidate the file indices stored in individual covfun records, but the table order should still be deterministic (albeit arbitrary).

There are some subsequent cleanups that I intend to investigate, but this is enough change for one PR.
2024-12-17 22:34:42 +01:00
Zalathar
541d4e85d9 coverage: Track used functions in a set instead of a map
This patch dismantles what was left of `FunctionCoverage` in `map_data.rs`,
replaces `function_coverage_map` with a set, and overhauls how we prepare
covfun records for unused functions.
2024-12-17 14:14:19 +11:00
Zalathar
d34c365eb0 coverage: Pull function source hash out of map_data.rs 2024-12-17 13:55:20 +11:00
Zalathar
527f8127bb coverage: Pull region conversion out of map_data.rs 2024-12-17 13:55:20 +11:00
Zalathar
252276a53d coverage: Pull expression conversion out of map_data.rs 2024-12-17 13:55:20 +11:00
Zalathar
154fae1e8d coverage: Build the global file table on the fly 2024-12-17 13:55:19 +11:00
Zalathar
fe412af4fc coverage: Use is_eligible_for_coverage to filter unused functions
The checks in `is_eligible_for_coverage` include `is_fn_like`, but will also
exclude various function-like things that cannot possibly have coverage
instrumentation.
2024-12-17 13:30:11 +11:00
Jonathan Dönszelmann
efb98b6552
rename rustc_attr to rustc_attr_parsing and create rustc_attr_data_structures 2024-12-16 19:08:19 +01:00
bors
d18506299b Auto merge of #133417 - RalfJung:aarch64-float-abi, r=workingjubilee
reject aarch64 target feature toggling that would change the float ABI

~~Stacked on top of https://github.com/rust-lang/rust/pull/133099. Only the last two commits are new.~~

The first new commit lays the groundwork for separately controlling whether a feature may be enabled or disabled. The second commit uses that to make it illegal to *disable* the `neon` feature (which is only possible via `-Ctarget-feature`, and so the new check just adds a warning). Enabling the `neon` feature remains allowed on targets that don't disable `neon` or `fp-armv8`, which is all our built-in targets. This way, the entire PR is not a breaking change.

Fixes https://github.com/rust-lang/rust/issues/131058 for hardfloat targets (together with https://github.com/rust-lang/rust/pull/133102 which fixed it for softfloat targets).

Part of https://github.com/rust-lang/rust/issues/116344.
2024-12-15 16:32:03 +00:00
Ralf Jung
eb2e928250 target_features: control separately whether enabling and disabling a target feature is allowed 2024-12-14 08:24:18 +01:00
Matthias Krüger
704102c0f0
Rollup merge of #134208 - Zalathar:covmap-covfun, r=compiler-errors
coverage: Tidy up creation of covmap and covfun records

This is a small follow-up to #134163 that mostly just inlines and renames some variables, and adds a few comments.

It also slightly defers the creation of the LLVM value that holds the filename table, to just before the value is needed.

---

try-job: x86_64-mingw-2
try-job: dist-x86_64-linux
2024-12-14 05:01:07 +01:00
bors
327c7ee436 Auto merge of #133099 - RalfJung:forbidden-hardfloat-features, r=workingjubilee
forbid toggling x87 and fpregs on hard-float targets

Part of https://github.com/rust-lang/rust/issues/116344, follow-up to https://github.com/rust-lang/rust/pull/129884:

The `x87`  target feature on x86 and the `fpregs` target feature on ARM must not be disabled on a hardfloat target, as that would change the float ABI. However, *enabling* `fpregs` on ARM is [explicitly requested](https://github.com/rust-lang/rust/issues/130988) as it seems to be useful. Therefore, we need to refine the distinction of "forbidden" target features and "allowed" target features: all (un)stable target features can determine on a per-target basis whether they should be allowed to be toggled or not. `fpregs` then checks whether the current target has the `soft-float` feature, and if yes, `fpregs` is permitted -- otherwise, it is not. (Same for `x87` on x86).

Also fixes https://github.com/rust-lang/rust/issues/132351. Since `fpregs` and `x87` can be enabled on some builds and disabled on others, it would make sense that one can query it via `cfg`. Therefore, I made them behave in `cfg` like any other unstable target feature.

The first commit prepares the infrastructure, but does not change behavior. The second commit then wires up `fpregs` and `x87` with that new infrastructure.

r? `@workingjubilee`
2024-12-13 19:43:00 +00:00
Zalathar
5f5745beb0 coverage: Tidy up creation of covfun records 2024-12-12 22:13:07 +11:00
Zalathar
de53fe245d coverage: Tidy up creation of covmap records 2024-12-12 22:10:42 +11:00
Zalathar
f7c6a2cf11 Fix our llvm::Bool typedef to be signed, to match LLVMBool
In the LLVM-C API, boolean values are passed as `typedef int LLVMBool`, but our
Rust-side typedef was using `c_uint` instead.

Signed and unsigned integers have the same ABI on most platforms, but that
isn't universally true, so we should prefer to be consistent with LLVM.
2024-12-12 20:54:33 +11:00
bors
903d2976fd Auto merge of #129181 - beetrees:asm-spans, r=pnkfelix,compiler-errors
Pass end position of span through inline ASM cookie

Before this PR, only the start position of the span was passed though the inline ASM cookie to diagnostics. LLVM 19 has full support for 64-bit inline ASM cookies; this PR uses that to pass the end position of the span in the upper 32 bits, meaning inline ASM diagnostics now point at the entire line the error occurred on, not just the first character of it.
2024-12-12 02:34:06 +00:00
bors
1daec069fb Auto merge of #128004 - folkertdev:naked-fn-asm, r=Amanieu
codegen `#[naked]` functions using global asm

tracking issue: https://github.com/rust-lang/rust/issues/90957

Fixes #124375

This implements the approach suggested in the tracking issue: use the existing global assembly infrastructure to emit the body of `#[naked]` functions. The main advantage is that we now have full control over what gets generated, and are no longer dependent on LLVM not sneakily messing with our output (inlining, adding extra instructions, etc).

I discussed this approach with `@Amanieu` and while I think the general direction is correct, there is probably a bunch of stuff that needs to change or move around here. I'll leave some inline comments on things that I'm not sure about.

Combined with https://github.com/rust-lang/rust/pull/127853, if both accepted, I think that resolves all steps from the tracking issue.

r? `@Amanieu`
2024-12-11 21:51:07 +00:00
Ralf Jung
60eca2c575 apply review feedback 2024-12-11 22:18:51 +01:00
Ralf Jung
2d887a5c5c generalize 'forbidden feature' concept so that even (un)stable feature can be invalid to toggle
Also rename some things for extra clarity
2024-12-11 22:11:15 +01:00
Matthias Krüger
eefefbea2f
Rollup merge of #134165 - durin42:wasm-target-string, r=jieyouxu
wasm(32|64): update alignment string

See llvm/llvm-project@c5ab70c508

`@rustbot` label: +llvm-main
2024-12-11 20:00:21 +01:00
Matthias Krüger
13c13ee4ec
Rollup merge of #134163 - Zalathar:covfun, r=SparrowLii,jieyouxu
coverage: Rearrange the code for embedding per-function coverage metadata

This is a series of refactorings to the code that prepares and embeds per-function coverage metadata records (“covfun records”) in the `__llvm_covfun` linker section of the final binary. The `llvm-cov` tool reads this metadata from the binary when preparing a coverage report.

Beyond general cleanup, a big motivation behind these changes is to pave the way for re-landing an updated version of #133418.

---

There should be no change in compiler output, as demonstrated by the absence of (meaningful) changes to coverage tests.

The first patch is just moving code around, so I suggest looking at the other patches to see the actual changes.

---

try-job: x86_64-gnu
try-job: x86_64-msvc
try-job: aarch64-apple
2024-12-11 20:00:18 +01:00
Augie Fackler
48b883287a wasm(32|64): update alignment string
See llvm/llvm-project@c5ab70c508

@rustbot label: +llvm-main
2024-12-11 05:52:59 -05:00
Zalathar
3f3a9bf7f5 coverage: Store intermediate region tables in CovfunRecord
This defers the call to `llvm_cov::write_function_mappings_to_buffer` until
just before its enclosing global variable is created.
2024-12-11 21:35:45 +11:00