Commit graph

2477 commits

Author SHA1 Message Date
Matthias Krüger
9e89feefb9
Rollup merge of #135549 - oli-obk:push-tmxtpnrloyqu, r=compiler-errors
Document some safety constraints and use more safe wrappers

Lots of unsafe codegen_llvm code has safe wrappers already, so I used some of them and added some where applicable. I stopped here because this diff is large enough and should probably be reviewed independently of other changes.
2025-02-12 06:07:35 +01:00
Oli Scherer
dcf1e4d72b Document some safety constraints and use more safe wrappers 2025-02-11 09:47:13 +00:00
Oli Scherer
4b83038d63 Add a safe wrapper for WriteBitcodeToFile 2025-02-11 09:41:22 +00:00
Oli Scherer
b2cd1b8ead Remove an unsafe closure invariant by inlining the closure wrapper into the called function 2025-02-11 09:41:22 +00:00
Jacob Pratt
c49ffaf7eb
Rollup merge of #136813 - mrkajetanp:aarch32-fp16-target-feature, r=davidtwco
rustc_target: Add the fp16 target feature for AArch32

As in the commit description. The feature is already available in rustc for AArch64.
2025-02-11 01:02:41 -05:00
Jacob Pratt
6153a8dcea
Rollup merge of #136721 - dpaoliello:cleanllvm2, r=Zalathar
cg_llvm: Reduce visibility of some items outside the `llvm` module

Next piece of #135502

This reduces the visibility of items (other than those in the `llvm` module) so that dead code analysis will correctly identify unused items.
2025-02-11 01:02:40 -05:00
Daniel Paoliello
5f29273921 rustc_codegen_llvm: Mark items as pub(crate) outside of the llvm module 2025-02-10 10:17:25 -08:00
Matthias Krüger
78f5bddd57
Rollup merge of #136419 - EnzymeAD:autodiff-tests, r=onur-ozkan,jieyouxu
adding autodiff tests

I'd like to get started with upstreaming some tests, even though I'm still waiting for an answer on how to best integrate the enzyme pass. Can we therefore temporarily support the -Z llvm-plugins here without too much effort? And in that case, how would that work? I saw you can do remapping, e.g. `rust-src-base`, but I don't think that will give me the path to libEnzyme.so. Do you have another suggestion?

Other than that this test simply checks that the derivative of `x*x` is `2.0 * x`, which in this case is computed as
`%0 = fadd fast double %x.0.val, %x.0.val`
(I'll add a few more tests and move it to an autodiff folder if we can use the -Z flag)

r? ``@jieyouxu``

Locally at least `-Zllvm-plugins=${PWD}/build/x86_64-unknown-linux-gnu/enzyme/build/Enzyme/libEnzyme-19.so` seems to work if I copy the command I get from x.py test and run it manually. However, running x.py test itself fails.

Tracking:

- https://github.com/rust-lang/rust/issues/124509

Zulip discussion: https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Enzyme.20build.20changes
2025-02-10 16:38:23 +01:00
Jubilee
7f8108afc8
Rollup merge of #136053 - Zalathar:defer-counters, r=saethlin
coverage: Defer part of counter-creation until codegen

Follow-up to #135481 and #135873.

One of the pleasant properties of the new counter-assignment algorithm is that we can stop partway through the process, store the intermediate state in MIR, and then resume the rest of the algorithm during codegen. This lets it take into account which parts of the control-flow graph were eliminated by MIR opts, resulting in fewer physical counters and simpler counter expressions.

Those improvements end up completely obsoleting much larger chunks of code that were previously responsible for cleaning up the coverage metadata after MIR opts, while also doing a more thorough cleanup job.

(That change also unlocks some further simplifications that I've kept out of this PR to limit its scope.)
2025-02-10 00:51:49 -08:00
Manuel Drehwald
061abbc369 remove outdated *First autodiff variants for higher-order ad 2025-02-10 01:35:53 -05:00
Manuel Drehwald
1221cff551 move second opt run to lto phase and cleanup code 2025-02-10 01:35:22 -05:00
bors
124cc92199 Auto merge of #136751 - bjorn3:update_rustfmt, r=Mark-Simulacrum
Update bootstrap compiler and rustfmt

The rustfmt version we previously used formats things differently from what the latest nightly rustfmt does. This causes issues for subtrees that get formatted both in-tree and in their own repo. Updating the rustfmt used in-tree solves those issues. Also bumped the bootstrap compiler as the stage0 update command always updates both at the same
time.
2025-02-09 15:44:16 +00:00
bors
a26e97be88 Auto merge of #136754 - Urgau:rollup-qlkhjqr, r=Urgau
Rollup of 5 pull requests

Successful merges:

 - #134679 (Windows: remove readonly files)
 - #136213 (Allow Rust to use a number of libc filesystem calls)
 - #136530 (Implement `x perf` directly in bootstrap)
 - #136601 (Detect (non-raw) borrows of null ZST pointers in CheckNull)
 - #136659 (Pick the max DWARF version when LTO'ing modules with different versions )

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-09 12:54:26 +00:00
Jubilee
5e4d6278af
Rollup merge of #136706 - workingjubilee:finish-up-rustc-abi-updates, r=compiler-errors
compiler: mostly-finish `rustc_abi` updates

This almost-finishes all the updates in the compiler to use `rustc_abi` and removes some of the reexports of `rustc_abi` items in `rustc_target` that were previously available.

r? ```@compiler-errors```
2025-02-08 20:41:21 -08:00
Urgau
5ec56e5fbb
Rollup merge of #136659 - wesleywiser:dwarf_version_lto_merge_behavior, r=jieyouxu
Pick the max DWARF version when LTO'ing modules with different versions

Currently, when rustc compiles code with `-Clto` enabled that was built
with different choices for `-Zdwarf-version`, a warning will be
reported. It's very easy to observe this by compiling most anything (eg,
"hello world") and specifying `-Clto -Zdwarf-version=5` since the
standard library is distributed with `-Zdwarf-version=4`.

This behavior isn't actually useful for a few reasons:
- From observation, LLVM chooses to pick the highest DWARF version
  anyway after issuing the warning.
- Clang specifies that in this case, the max version should be picked
  without a warning and as a general principle, we want to support
  x-lang LTO with Clang which implies using the same module flag merge
  behaviors.
- Debuggers need to be able to handle a variety of versions within the
  same debugging session as you can easily have some parts of a binary
  (or some dynamic libraries within an application) all compiled with
  different DWARF versions.

This commit changes the module flag merge behavior to match Clang and
use the highest version of DWARF. It also adds a test to ensure this
behavior is respected in the case of two crates being LTO'd together and
adds a test to ensure no warning is printed.

Fixes #130041 which fails due to these warnings being printed

cc #103057
2025-02-09 00:37:28 +01:00
bjorn3
1fcae03369 Rustfmt 2025-02-08 22:12:13 +00:00
Wesley Wiser
bbc40e7822 Pick the max DWARF version when LTO'ing modules with different versions
Currently, when rustc compiles code with `-Clto` enabled that was built
with different choices for `-Zdwarf-version`, a warning will be
reported. It's very easy to observe this by compiling most anything (eg,
"hello world") and specifying `-Clto -Zdwarf-version=5` since the
standard library is distributed with `-Zdwarf-version=4`.

This behavior isn't actually useful for a few reasons:
- from observation, LLVM chooses to pick the highest DWARF version
  anyway after issuing the warning
- Clang specifies that in this case, the max version should be picked
  without a warning and as a general principle, we want to support
  x-lang LTO with Clang which implies using the same module flag merge
  behaviors
- Debuggers need to be able to handle a variety of versions withing the
  same debugging session as you can easily have some parts of a binary
  (or some dynamic libraries within an application) all compiled with
  different DWARF versions

This commit changes the module flag merge behavior to match Clang and
use the highest version of DWARF. It also adds a test to ensure this
behavior is respected in the case of two crates being LTO'd together and
updates the test added in the previous commit to ensure no warning is
printed.
2025-02-08 16:33:36 +00:00
Manuel Drehwald
21d096184e fix non-enzyme builds 2025-02-07 22:27:46 -05:00
Matthias Krüger
c9771e9590
Rollup merge of #136691 - bjorn3:linkage_cleanup, r=jieyouxu
Remove Linkage::Private and Linkage::Appending

Neither of them has any use case. Neither known nor theoretical.
2025-02-08 03:58:48 +01:00
Matthias Krüger
93b194516a
Rollup merge of #136640 - Zalathar:debuginfo-align-bits, r=compiler-errors
Debuginfo for function ZSTs should have alignment of 8 bits, not 1 bit

In #116096, function ZSTs were made to have debuginfo that gives them an alignment of “1”. But because alignment in LLVM debuginfo is denoted in *bits*, not bytes, this resulted in an alignment specification of 1 bit instead of 1 byte.

I don't know whether this has any practical consequences, but I noticed that a test started failing when I accidentally fixed the mistake while working on #136632, so I extracted the fix (and the test adjustment) to this PR.
2025-02-08 03:58:45 +01:00
Jubilee Young
eddfe8f503 compiler: remove reexports from rustc_target::callconv 2025-02-07 11:25:18 -08:00
Kajetan Puchalski
53f9852224 rustc_target: Add the fp16 target feature for AArch32 2025-02-07 18:08:19 +00:00
bjorn3
f68cd90412 Remove Linkage::Appending
It can only be used for certain LLVM internal variables like
llvm.global_ctors which users are not allowed to define.
2025-02-07 16:02:19 +00:00
bjorn3
382e4031c2 Remove Linkage::Private
This is the same as Linkage::Internal except that it doesn't emit any
symbol. Some backends may not support it and it isn't all that useful
anyway.
2025-02-07 16:02:19 +00:00
Daniel Paoliello
2a6b27444a Remove dead code from rustc_codegen_llvm and the LLVM wrapper 2025-02-06 16:53:52 -08:00
Zalathar
4385a9e063 Debuginfo for function ZSTs should have alignment of 8 bits, not 1 bit 2025-02-06 23:01:29 +11:00
bors
2f92f050e8 Auto merge of #136471 - safinaskar:parallel, r=SparrowLii
tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc`

tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc`

This is continuation of https://github.com/rust-lang/rust/pull/132282 .

I'm pretty sure I did everything right. In particular, I searched all occurrences of `Lrc` in submodules and made sure that they don't need replacement.

There are other possibilities, through.

We can define `enum Lrc<T> { Rc(Rc<T>), Arc(Arc<T>) }`. Or we can make `Lrc` a union and on every clone we can read from special thread-local variable. Or we can add a generic parameter to `Lrc` and, yes, this parameter will be everywhere across all codebase.

So, if you think we should take some alternative approach, then don't merge this PR. But if it is decided to stick with `Arc`, then, please, merge.

cc "Parallel Rustc Front-end" ( https://github.com/rust-lang/rust/issues/113349 )

r? SparrowLii

`@rustbot` label WG-compiler-parallel
2025-02-06 10:50:05 +00:00
Zalathar
bd855b6c9e coverage: Remove the old code for simplifying counters after MIR opts 2025-02-06 21:44:31 +11:00
Zalathar
20d051ec87 coverage: Defer part of counter-creation until codegen 2025-02-06 21:44:31 +11:00
Zalathar
ee7dc06cf1 coverage: Store BCB node IDs in mappings, and resolve them in codegen
Even though the coverage graph itself is no longer available during codegen,
its nodes can still be used as opaque IDs.
2025-02-06 21:44:29 +11:00
Zalathar
042fd8c24a Remove some unused glob re-exports
These were detected by temporarily making `mod llvm` non-public.
2025-02-06 12:10:45 +11:00
Zalathar
65d7e6937b Remove the mod llvm_ hack, which should no longer be necessary 2025-02-06 12:10:42 +11:00
Manuel Drehwald
70b9ba3d6e fix fwd-mode autodiff case 2025-02-05 18:47:23 -05:00
León Orell Valerian Liehr
75989e98d8
Rollup merge of #136375 - Zalathar:llvm-di-builder, r=workingjubilee
cg_llvm: Replace some DIBuilder wrappers with LLVM-C API bindings (part 1)

Part of #134001, follow-up to #136326, extracted from #134009.

This PR performs an arbitrary subset of the LLVM-C binding migrations from #134009, which should make it less tedious to review. The remaining migrations can occur in one or more subsequent PRs.
2025-02-05 05:03:03 +01:00
bors
3f33b30e19 Auto merge of #135760 - scottmcm:disjoint-bitor, r=WaffleLapkin
Add `unchecked_disjoint_bitor` per ACP373

Following the names from libs-api in https://github.com/rust-lang/libs-team/issues/373#issuecomment-2085686057

Includes a fallback implementation so this doesn't have to update cg_clif or cg_gcc, and overrides it in cg_llvm to use `or disjoint`, which [is available in LLVM 18](https://releases.llvm.org/18.1.0/docs/LangRef.html#or-instruction) so hopefully we don't need any version checks.
2025-02-04 17:46:06 +00:00
Askar Safin
0a21f1d0a2 tree-wide: parallel: Fully removed all Lrc, replaced with Arc 2025-02-03 13:25:57 +03:00
Scott McMurray
f46e6be190 Handle the case where the or disjoint folds immediately to a constant 2025-02-02 21:04:10 -08:00
Matthias Krüger
f5ae630f10
Rollup merge of #136426 - oli-obk:push-nkpuulwurykn, r=compiler-errors
Explain why we retroactively change a static initializer to have a different type

I keep getting confused about it and in turn confused `@GuillaumeGomez` while trying to explain it badly
2025-02-02 23:06:57 +01:00
Oli Scherer
b89263605a Explain why we retroactively change a static initializer to have a different type 2025-02-01 22:39:38 +00:00
Scott McMurray
4ee1602eab Override disjoint_or in the LLVM backend 2025-01-31 22:29:08 -08:00
Zalathar
c3f2930edc Explain why (some) pointer/length strings are *const c_uchar 2025-02-01 14:14:40 +11:00
Zalathar
5413d2bd6f Add FIXME for auditing optional parameters passed to DIBuilder 2025-02-01 14:14:40 +11:00
Zalathar
8ddd9c38f6 Use LLVMDIBuilderCreateDebugLocation
The LLVM-C binding takes an explicit context, whereas our binding obtained the
context from the scope argument.
2025-02-01 14:14:40 +11:00
Zalathar
949b4673ce Use LLVMDIBuilderCreateLexicalBlockFile 2025-02-01 14:14:40 +11:00
Zalathar
70d41bc711 Use LLVMDIBuilderCreateLexicalBlock 2025-02-01 14:14:40 +11:00
Zalathar
878ab125a1 Use LLVMDIBuilderCreateNameSpace 2025-02-01 14:14:39 +11:00
Zalathar
cd2af2dd9a Use LLVMDIBuilderFinalize 2025-02-01 13:38:12 +11:00
Zalathar
832fcfb64f Introduce DIBuilderBox, an owning pointer to DIBuilder 2025-02-01 13:34:14 +11:00
Ben Kimock
ce7cb312fa Add link attribute for Enzyme's FFI 2025-01-31 21:11:23 -05:00
bors
7f36543a48 Auto merge of #136332 - jhpratt:rollup-aa69d0e, r=jhpratt
Rollup of 9 pull requests

Successful merges:

 - #132156 (When encountering unexpected closure return type, point at return type/expression)
 - #133429 (Autodiff Upstreaming - rustc_codegen_ssa, rustc_middle)
 - #136281 (`rustc_hir_analysis` cleanups)
 - #136297 (Fix a typo in profile-guided-optimization.md)
 - #136300 (atomic: extend compare_and_swap migration docs)
 - #136310 (normalize `*.long-type.txt` paths for compare-mode tests)
 - #136312 (Disable `overflow_delimited_expr` in edition 2024)
 - #136313 (Filter out RPITITs when suggesting unconstrained assoc type on too many generics)
 - #136323 (Fix a typo in conventions.md)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-31 09:42:28 +00:00