Commit Graph

1994 Commits

Author SHA1 Message Date
Andreas Jonson
cfadfabfcd Add range attribute to scalar function results and arguments 2024-08-11 19:40:44 +02:00
Trevor Gross
b3bfd66627
Rollup merge of #128417 - tgross35:f16-f128-math, r=dtolnay
Add `f16` and `f128` math functions

This adds intrinsics and math functions for `f16` and `f128` floating point types. Support is quite limited and some things are broken so tests don't run on many platforms, but this provides a starting point.
2024-08-06 22:17:32 -05:00
daxpedda
80b74d397f
Implement a implicit target feature mechanism 2024-08-04 08:44:23 +02:00
Trevor Gross
e6d570241f Specify the integer type of the powi LLVM intrinsic
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-08-01 15:36:15 -04:00
Matthias Krüger
75dfe1e63d
Rollup merge of #127830 - tgross35:archive-failure-message, r=BoxyUwU
When an archive fails to build, print the path

Currently the output on failure is as follows:

       Compiling block-buffer v0.10.4
       Compiling crypto-common v0.1.6
       Compiling digest v0.10.7
       Compiling sha2 v0.10.8
       Compiling xz2 v0.1.7
    error: failed to build archive: No such file or directory

    error: could not compile `bootstrap` (lib) due to 1 previous error

Change this to print which file is being constructed, to give some hint about what is going on.

    error: failed to build archive at `path/to/output`: No such file or directory
2024-07-31 15:36:30 +02:00
bors
7e3a971870 Auto merge of #128378 - matthiaskrgr:rollup-i3qz9uo, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #127574 (elaborate unknowable goals)
 - #128141 (Set branch protection function attributes)
 - #128315 (Fix vita build of std and forbid unsafe in unsafe in the os/vita module)
 - #128339 ([rustdoc] Make the buttons remain when code example is clicked)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-30 05:50:05 +00:00
bors
710ce90fbe Auto merge of #128250 - Amanieu:select_unpredictable, r=nikic
Add `select_unpredictable` to force LLVM to use CMOV

Since https://reviews.llvm.org/D118118, LLVM will no longer turn CMOVs into branches if it comes from a `select` marked with an `unpredictable` metadata attribute.

This PR introduces `core::intrinsics::select_unpredictable` which emits such a `select` and uses it in the implementation of `binary_search_by`.
2024-07-30 03:22:27 +00:00
Matthias Krüger
6b23cb5cdf
Rollup merge of #128141 - nikic:aarch64-bti, r=DianQK,cuviper
Set branch protection function attributes

Since LLVM 19, it is necessary to set not only module flags, but also function attributes for branch protection on aarch64. See e15d67cfc2 for the relevant LLVM change.

Fixes https://github.com/rust-lang/rust/issues/127829.
2024-07-30 04:31:54 +02:00
bors
80d8270d84 Auto merge of #125016 - nicholasbishop:bishop-cb-112, r=tgross35
Update compiler_builtins to 0.1.114

The `weak-intrinsics` feature was removed from compiler_builtins in https://github.com/rust-lang/compiler-builtins/pull/598, so dropped the `compiler-builtins-weak-intrinsics` feature from alloc/std/sysroot.

In https://github.com/rust-lang/compiler-builtins/pull/593, some builtins for f16/f128 were added. These don't work for all compiler backends, so add a `compiler-builtins-no-f16-f128` feature and disable it for cranelift and gcc.
2024-07-29 07:41:33 +00:00
Nicholas Nethercote
84ac80f192 Reformat use declarations.
The previous commit updated `rustfmt.toml` appropriately. This commit is
the outcome of running `x fmt --all` with the new formatting options.
2024-07-29 08:26:52 +10:00
Guillaume Gomez
19feb90d69
Rollup merge of #127860 - klensy:dedup, r=Mark-Simulacrum
deps: dedup object, wasmparser, wasm-encoder

* dedups one `object`, additional dupe will be removed, with next `thorin-dwp` update
* `wasmparser` pinned to minor versions, so full merge isn't possible
* same with `wasm-encoder`

Turned off some features for `wasmparser` (see features https://github.com/bytecodealliance/wasm-tools/blob/v1.208.1/crates/wasmparser/Cargo.toml) in `run-make-support`, looks working?
2024-07-28 20:07:45 +02:00
Amanieu d'Antras
4f78f9fbb0 Force LLVM to use CMOV for binary search
Since https://reviews.llvm.org/D118118, LLVM will no longer turn CMOVs
into branches if it comes from a `select` marked with an `unpredictable`
metadata attribute.

This PR introduces `core::intrinsics::select_unpredictable` which emits
such a `select` and uses it in the implementation of `binary_search_by`.
2024-07-28 17:24:57 +01:00
klensy
58c9999f25 dedup object
waiting on thorin-dwp update

dedup one wasmparser

run-make-support: drop some features for wasmparser

dedupe wasm-encoder
2024-07-28 17:21:07 +03:00
Matthew Maurer
38931cd227 LLVM: LLVM-20.0 removes MMX types
See llvm/llvm-project#98505
2024-07-25 17:58:37 +00:00
bors
28e684b470 Auto merge of #127995 - workingjubilee:say-turings-prayer, r=BoxyUwU
compiler: Never debug_assert in codegen

In the name of Turing and his Hoarey heralds, assert our truths before creating a monster!

The `rustc_codegen_llvm` and `rustc_codegen_ssa` crates are fairly critical for rustc's correctness. Small mistakes here can easily result in undefined behavior, since a "small mistake" can mean something like "link and execute the wrong code". We should probably run any and all asserts in these modules unconditionally on whether this is a "debug build", and damn the costs in performance.

...Especially because the costs in performance seem to be *nothing*. It is not clear how much correctness we gain here, but I'll take free correctness improvements.
2024-07-25 07:52:31 +00:00
Nikita Popov
ea7625f426 Set branch protection function attributes
Since LLVM 19, it is necessary to set not only module flags, but
also function attributes for branch protection on aarch64. See
e15d67cfc2
for the relevant LLVM change.
2024-07-24 17:13:25 +02:00
Trevor Gross
5e8e46cbd2
Rollup merge of #127506 - liushuyu:s390x-target-features, r=davidtwco
rustc_target: add known safe s390x target features

This pull request adds known safe target features for s390x (aka IBM Z systems).
Currently, these features are unstable since stabilizing the target features requires submitting proposals.

The `vector` feature was added in IBM Z13 (`arch11`), and this is a SIMD feature for the newer IBM Z systems.
The `backchain` attribute is the IBM Z way of adding frame pointers like unwinding capabilities (the "frame-pointer" switch on IBM Z and IBM POWER platforms will add _emulated_ frame pointers to the binary, which profilers can't use for unwinding the stack).

Both attributes can be applied at the LLVM module or function levels. However, the `backchain` attribute has to be enabled for all the functions in the call stack to get a successful unwind process.
2024-07-22 11:40:19 -05:00
Jubilee Young
ce7b069fd8 compiler: Never debug_assert in codegen
The gains in performance are not worth the costs in correctness.
This is partly because the gains are zero and the costs are unknown.
2024-07-20 00:16:44 -07:00
Trevor Gross
986d6bf9fb
Rollup merge of #121533 - ratmice:wasm_init_fini_array, r=nnethercote
Handle .init_array link_section specially on wasm

Given that wasm-ld now has support for [.init_array](8f2bd8ae68/llvm/lib/MC/WasmObjectWriter.cpp (L1852)), it appears we can easily implement that section by falling through to the normal path rather than taking the typical custom_section path for wasm.

The wasm-ld appears to have a bunch of limitations. Only one static with the `link_section` in a crate or else you hit the fatal error in the link above "only one .init_array section fragment supported". They do not get merged.

You can still call multiple constructors by setting it to an array.

```
unsafe extern "C" fn ctor() {
    println!("foo");
}
#[used]
#[link_section = ".init_array"]
static FOO: [unsafe extern "C" fn(); 2] = [ctor, ctor];
```

Another issue appears to be that if crate *A* depends on crate *B*, but *A* doesn't call any symbols from *B* and *B* doesn't `#[export_name = ...]` any symbols, then crate *B*'s constructor will not be called.  The workaround to this is to provide an exported symbol in crate *B*.
2024-07-19 03:27:46 -05:00
liushuyu
01e6e60bf3 rustc_codegen_llvm: properly passing backchain attribute to LLVM ...
... this is a special attribute that was made to be a target-feature in
LLVM 18+, but in all previous versions, this "feature" is a naked
attribute. We will have to handle this situation differently than all
other target-features.
2024-07-17 07:56:00 +08:00
Trevor Gross
63f239c89f
Rollup merge of #124033 - bjorn3:ar_archive_writer_0_3_0, r=davidtwco
Sync ar_archive_writer to LLVM 18.1.3

From LLVM 15.0.0-rc3. This adds support for COFF archives containing Arm64EC object files and has various fixes for AIX big archive files.
2024-07-16 16:15:13 -05:00
Trevor Gross
e0af3c61cd When an archive fails to build, print the path
Currently the output on failure is as follows:

       Compiling block-buffer v0.10.4
       Compiling crypto-common v0.1.6
       Compiling digest v0.10.7
       Compiling sha2 v0.10.8
       Compiling xz2 v0.1.7
    error: failed to build archive: No such file or directory

    error: could not compile `bootstrap` (lib) due to 1 previous error

Print which file is being constructed to give some hint about what is
going on.
2024-07-16 15:44:54 -05:00
Michael Goulet
28503d69ac Fix unsafe_op_in_unsafe_fn in compiler 2024-07-16 00:02:44 -04:00
Zalathar
d4f1f92426 coverage: Restrict ExpressionUsed simplification to Code mappings
In the future, branch and MC/DC mappings might have expressions that don't
correspond to any single point in the control-flow graph. That makes it
trickier to keep track of which expressions should expect an `ExpressionUsed`
node.

We therefore sidestep that complexity by only performing `ExpressionUsed`
simplification for expressions associated directly with ordinary `Code`
mappings.
2024-07-15 20:54:28 +10:00
Jacob Pratt
cb1ccc1842
Rollup merge of #127654 - nikic:llvm-ndebug-fix, r=cuviper
Fix incorrect NDEBUG handling in LLVM bindings

We currently compile our LLVM bindings using `-DNDEBUG` if debuginfo for LLVM is disabled. However, `NDEBUG` doesn't have any relation to debuginfo, it controls whether assertions are enabled.

Split the LLVM_NDEBUG environment variable into two, so that assertions and debuginfo are controlled independently.

After this change, `LLVMRustDIBuilderInsertDeclareAtEnd` triggers an assertion failure on LLVM 19 due to an incorrect cast. Fix it by removing the unused return value entirely.

r? `@cuviper`
2024-07-13 00:24:35 -04:00
Nikita Popov
8dfd3a455d Remove LLVMRustDIBuilderInsertDeclareAtEnd return value
The return value changed from an Instruction to a DbgRecord in
LLVM 19. As we don't actually use the result, drop the return
value entirely to support both.
2024-07-12 22:15:10 +02:00
bors
5e311f933d Auto merge of #127614 - matthiaskrgr:rollup-8geziwi, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #124599 (Suggest borrowing on fn argument that is `impl AsRef`)
 - #127572 (Don't mark `DEBUG_EVENT` struct as `repr(packed)`)
 - #127588 (core: Limit remaining f16 doctests to x86_64 linux)
 - #127591 (Make sure that labels are defined after the primary span in diagnostics)
 - #127598 (Allows `#[diagnostic::do_not_recommend]` to supress trait impls in suggestions as well)
 - #127599 (Rename `lazy_cell_consume` to `lazy_cell_into_inner`)
 - #127601 (check is_ident before parse_ident)
 - #127605 (Remove extern "wasm" ABI)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-11 22:56:52 +00:00
bors
bcf1f6db45 Auto merge of #127487 - tgross35:f16-f128-simd, r=Amanieu
Add `f16` and `f128` as simd types in LLVM

`@sayantn` is working on adding SIMD for `f16` and hitting the `FloatingPointVector` error. This should fix it and unblock adding support for `simd_fma` and `simd_fabs` in stdarch.
2024-07-11 14:08:58 +00:00
Nikita Popov
8a50bcbdce Remove extern "wasm" ABI
Remove the unstable `extern "wasm"` ABI (`wasm_abi` feature tracked
in #83788).

As discussed in https://github.com/rust-lang/rust/pull/127513#issuecomment-2220410679
and following, this ABI is a failed experiment that did not end
up being used for anything. Keeping support for this ABI in LLVM 19
would require us to switch wasm targets to the `experimental-mv`
ABI, which we do not want to do.

It should be noted that `Abi::Wasm` was internally used for two
things: The `-Z wasm-c-abi=legacy` ABI that is still used by
default on some wasm targets, and the `extern "wasm"` ABI. Despite
both being `Abi::Wasm` internally, they were not the same. An
explicit `extern "wasm"` additionally enabled the `+multivalue`
feature.

I've opted to remove `Abi::Wasm` in this patch entirely, instead
of keeping it as an ABI with only internal usage. Both
`-Z wasm-c-abi` variants are now treated as part of the normal
C ABI, just with different different treatment in
adjust_for_foreign_abi.
2024-07-11 12:20:26 +02:00
bors
8672b2b763 Auto merge of #127001 - beetrees:f16-debuginfo, r=michaelwoerister
Add Natvis visualiser and debuginfo tests for `f16`

To render `f16`s in debuggers on MSVC targets, this PR changes the compiler to output `f16`s as `struct f16 { bits: u16 }`, and includes a Natvis visualiser that manually converts the `f16`'s bits to a `float` which is can then be displayed by debuggers. `gdb`, `lldb` and `cdb` tests are also included for `f16` .

`f16`/`f128` MSVC debug info issue: #121837
Tracking issue: #116909
2024-07-09 09:07:42 +00:00
beetrees
b058de90a3
Add Natvis visualiser and debuginfo tests for f16 2024-07-09 03:47:50 +01:00
Trevor Gross
04caa5555a Add f16 and f128 as SIMD types in LLVM 2024-07-08 13:59:39 -04:00
bjorn3
58e551433d Sync ar_archive_writer to LLVM 18.1.3
From LLVM 15.0.0-rc3. This adds support for COFF archives containing
Arm64EC object files and has various fixes for AIX big archive files.
2024-07-07 16:56:35 +00:00
bors
51917ba8f2 Auto merge of #126171 - RalfJung:simd_bitmask_multibyte, r=workingjubilee
simd_bitmask intrinsic: add a non-power-of-2 multi-byte example

r? `@calebzulawski` `@workingjubilee`
2024-07-05 01:58:22 +00:00
bors
489233170a Auto merge of #123781 - RalfJung:miri-fn-identity, r=oli-obk
Miri function identity hack: account for possible inlining

Having a non-lifetime generic is not the only reason a function can be duplicated. Another possibility is that the function may be eligible for cross-crate inlining. So also take into account the inlining attribute in this Miri hack for function pointer identity.

That said, `cross_crate_inlinable` will still sometimes return true even for `inline(never)` functions:
- when they are `DefKind::Ctor(..) | DefKind::Closure` -- I assume those cannot be `InlineAttr::Never` anyway?
- when `cross_crate_inline_threshold == InliningThreshold::Always`

so maybe this is still not quite the right criterion to use for function pointer identity.
2024-07-04 23:45:56 +00:00
Matthias Krüger
c74d620635
Rollup merge of #126803 - tgross35:verbose-asm, r=Amanieu
Change `asm-comments` to `verbose-asm`, always emit user comments

Implements what is described in https://github.com/rust-lang/compiler-team/issues/762

Tracking issue: https://github.com/rust-lang/rust/issues/126802
2024-07-03 17:26:53 +02:00
bors
c872a1418a Auto merge of #125507 - compiler-errors:type-length-limit, r=lcnr
Re-implement a type-size based limit

r? lcnr

This PR reintroduces the type length limit added in #37789, which was accidentally made practically useless by the caching changes to `Ty::walk` in #72412, which caused the `walk` function to no longer walk over identical elements.

Hitting this length limit is not fatal unless we are in codegen -- so it shouldn't affect passes like the mir inliner which creates potentially very large types (which we observed, for example, when the new trait solver compiles `itertools` in `--release` mode).

This also increases the type length limit from `1048576 == 2 ** 20` to `2 ** 24`, which covers all of the code that can be reached with craterbot-check. Individual crates can increase the length limit further if desired.

Perf regression is mild and I think we should accept it -- reinstating this limit is important for the new trait solver and to make sure we don't accidentally hit more type-size related regressions in the future.

Fixes #125460
2024-07-03 11:56:36 +00:00
Trevor Gross
c15a698f56 Rename the asm-comments compiler flag to verbose-asm
Since this codegen flag now only controls LLVM-generated comments rather than
all assembly comments, make the name more accurate (and also match Clang).
2024-07-02 21:42:01 -04:00
Michael Goulet
3273ccea4b Fix spans 2024-07-02 15:48:48 -04:00
Michael Goulet
9dc129ae82 Give Instance::expect_resolve a span 2024-07-02 15:48:48 -04:00
Ralf Jung
41b98da42d Miri function identity hack: account for possible inlining 2024-07-02 21:05:30 +02:00
Matthias Krüger
33b0238586
Rollup merge of #127168 - DianQK:cast-size, r=workingjubilee
Use the aligned size for alloca at args/ret when the pass mode is cast

Fixes #75839. Fixes #121028.

The `load` and `store` instructions in LLVM access the aligned size. For example, `load { i64, i32 }` accesses 16 bytes on x86_64: https://alive2.llvm.org/ce/z/n8CHAp.

BTW, this example is expected to be optimized to immediate UB by Alive2: https://rust.godbolt.org/z/b7xK7hv1c and https://alive2.llvm.org/ce/z/vZDtZH.

r? compiler
2024-07-02 17:47:48 +02:00
DianQK
c453dcd62a
Use the aligned size for alloca at args when the pass mode is cast.
The `load` and `store` instructions in LLVM access the aligned size.
2024-07-02 06:33:35 +08:00
Ralf Jung
e9dd39cda4 fix simd_bitmask return type for non-power-of-two inputs, and add tests 2024-07-01 17:25:14 +02:00
Matthias Krüger
5b90824433
Rollup merge of #123237 - bjorn3:debuginfo_refactor, r=compiler-errors
Various rustc_codegen_ssa cleanups
2024-06-29 22:10:55 +02:00
Matthew Maurer
9b0ae75ecc Support #[patchable_function_entries]
See [RFC](https://github.com/maurer/rust-rfcs/blob/patchable-function-entry/text/0000-patchable-function-entry.md) (yet to be numbered)

TODO before submission:
* Needs an RFC
* Improve error reporting for malformed attributes
2024-06-25 18:23:41 +02:00
Matthew Maurer
ac7595fdb1 Support for -Z patchable-function-entry
`-Z patchable-function-entry` works like `-fpatchable-function-entry`
on clang/gcc. The arguments are total nop count and function offset.

See MCP rust-lang/compiler-team#704
2024-06-25 18:21:42 +02:00
Michael Goulet
faa28be2f1
Rollup merge of #124712 - Enselic:deprecate-inline-threshold, r=pnkfelix
Deprecate no-op codegen option `-Cinline-threshold=...`

This deprecates `-Cinline-threshold` since using it has no effect. This has been the case since the new LLVM pass manager started being used, more than 2 years ago.

Recommend using `-Cllvm-args=--inline-threshold=...` instead.

Closes #89742 which is E-help-wanted.
2024-06-24 15:51:00 -04:00
Jubilee Young
b3a1975cdc compiler(nfc): -Cforce-frame-pointers is a FramePointer 2024-06-23 00:36:33 -07:00
Guillaume Gomez
07e8b3ac01
Rollup merge of #126555 - beetrees:f16-inline-asm-arm, r=Amanieu
Add `f16` inline ASM support for 32-bit ARM

Adds `f16` inline ASM support for 32-bit ARM. SIMD vector types are taken from [here](https://developer.arm.com/architectures/instruction-sets/intrinsics/#f:`@navigationhierarchiesreturnbasetype=[float]&f:@navigationhierarchieselementbitsize=[16]&f:@navigationhierarchiesarchitectures=[A32]).`

Relevant issue: #125398
Tracking issue: #116909

`@rustbot` label +F-f16_and_f128
2024-06-22 12:57:18 +02:00