Commit Graph

777 Commits

Author SHA1 Message Date
Yuki Okushi
330e03f682
Rollup merge of #97062 - bjorn3:cg_ssa_driver_refactor, r=compiler-errors
Couple of refactorings to cg_ssa::base::codegen_crate

This makes the code simpler and easier to read.
2022-05-19 08:22:42 +09:00
SparrowLii
38bf1158bd Change Successors to impl Iterator<Item = BasicBlock> 2022-05-17 08:41:01 +08:00
bjorn3
a06deb5191 Compute pre_compiled_cgus more eagerly
This reduces the complexity of this code a lot
2022-05-15 11:49:25 +00:00
bjorn3
1c1f16c3e3 Move cgu_reuse a bit earlier
There is no reason it needs to be lazily computed at the first iteration
of the cgu loop.
2022-05-15 11:49:25 +00:00
bors
1c80ac003b Auto merge of #96930 - ayrtonm:mips32-tmp-file, r=petrochenkov
Fix e_flags for 32-bit MIPS targets in generated object file

In #95604 the compiler started generating a temporary symbols.o which is added to the linker invocation. This object file has an `e_flags` which is invalid for 32-bit MIPS targets. Even though symbols.o doesn't contain code, linking these targets with [lld fails](https://github.com/llvm/llvm-project/blob/main/lld/ELF/Arch/MipsArchTree.cpp#L76-L79) with
```
rust-lld: error: foo-cgu.0.rcgu.o: ABI 'o32' is incompatible with target ABI 'n64'
```
because it omits the ABI bits (`EF_MIPS_ABI_O32`) so lld assumes it's using the N64 ABI. This breaks linking on nightly for the out-of-tree [mipsel-sony-psx target](https://github.com/ayrtonm/psx-sdk-rs/issues/9), the builtin mipsel-sony-psp target (cc `@overdrivenpotato)` and probably any other 32-bit MIPS target using lld.

This PR sets the ABI in `e_flags` to O32 since that's the only ABI for 32-bit MIPS that LLVM supports. It also sets other `e_flags` bits based on the target to avoid similar issues with the object file arch and PIC. I had to bump the object crate version since some of these constants were [added recently](https://github.com/gimli-rs/object/pull/433). I'm not sure if this PR needs a test, but I can confirm that it fixes the linking issue on both targets I mentioned.
2022-05-13 08:48:31 +00:00
Scott McMurray
89a18cb600 Add unsigned_offset_from on pointers
Like we have `add`/`sub` which are the `usize` version of `offset`, this adds the `usize` equivalent of `offset_from`.  Like how `.add(d)` replaced a whole bunch of `.offset(d as isize)`, you can see from the changes here that it's fairly common that code actually knows the order between the pointers and *wants* a `usize`, not an `isize`.

As a bonus, this can do `sub nuw`+`udiv exact`, rather than `sub`+`sdiv exact`, which can be optimized slightly better because it doesn't have to worry about negatives.  That's why the slice iterators weren't using `offset_from`, though I haven't updated that code in this PR because slices are so perf-critical that I'll do it as its own change.

This is an intrinsic, like `offset_from`, so that it can eventually be allowed in CTFE.  It also allows checking the extra safety condition -- see the test confirming that CTFE catches it if you pass the pointers in the wrong order.
2022-05-11 17:16:25 -07:00
Ayrton
3d5b1eeb75 Fix e_flags for 32-bit MIPS targets in generated object file
In #95604 the compiler started generating a temporary symbols.o which is added
to the linker invocation. This object file has an `e_flags` which may be invalid
for 32-bit MIPS targets. Even though symbols.o doesn't contain code, linking
    with [lld fails](https://github.com/llvm/llvm-project/blob/main/lld/ELF/Arch/MipsArchTree.cpp#L79) with
```
rust-lld: error: foo-cgu.0.rcgu.o: ABI 'o32' is incompatible with target ABI 'n64'
```
because it omits the ABI bits (EF_MIPS_ABI_O32) so lld assumes it's using the
N64 ABI. This breaks linking on nightly for the out-of-tree [psx
target](https://github.com/ayrtonm/psx-sdk-rs/issues/9), the builtin
mipsel-sony-psp target (cc @overdrivenpotato) and any other 32-bit MIPS
target using lld.

This PR sets the ABI in `e_flags` to O32 since that's the only ABI for 32-bit
MIPS that LLVM supports. It also sets other `e_flags` bits based on the target.
I had to bump the object crate version since some of these constants were [added
recently](https://github.com/gimli-rs/object/pull/433). I'm not sure if this
PR needs a test, but I can confirm that it fixes the linking issue on both
targets I mentioned.
2022-05-10 22:48:19 -04:00
bors
a7d6768e3b Auto merge of #91779 - ridwanabdillahi:natvis, r=michaelwoerister
Add a new Rust attribute to support embedding debugger visualizers

Implemented [this RFC](https://github.com/rust-lang/rfcs/pull/3191) to add support for embedding debugger visualizers into a PDB.

Added a new attribute `#[debugger_visualizer]` and updated the `CrateMetadata` to store debugger visualizers for crate dependencies.

RFC: https://github.com/rust-lang/rfcs/pull/3191
2022-05-05 12:26:38 +00:00
Josh Triplett
0fc5c524f5 Stabilize bool::then_some 2022-05-04 13:22:08 +02:00
ridwanabdillahi
175a4eab84 Add support for a new attribute #[debugger_visualizer] to support embedding debugger visualizers into a generated PDB.
Cleanup `DebuggerVisualizerFile` type and other minor cleanup of queries.

Merge the queries for debugger visualizers into a single query.

Revert move of `resolve_path` to `rustc_builtin_macros`. Update dependencies in Cargo.toml for `rustc_passes`.

Respond to PR comments. Load visualizer files into opaque bytes `Vec<u8>`. Debugger visualizers for dynamically linked crates should not be embedded in the current crate.

Update the unstable book with the new feature. Add the tracking issue for the debugger_visualizer feature.

Respond to PR comments and minor cleanups.
2022-05-03 10:53:54 -07:00
bors
e1df625306 Auto merge of #96601 - tmiasko:ssa-rpo, r=davidtwco
Use reverse postorder in `non_ssa_locals`

The reverse postorder, unlike preorder, is now cached inside the MIR
body. Code generation uses reverse postorder anyway, so it might be
a small perf improvement to use it here as well.
2022-05-03 12:16:00 +00:00
Yuki Okushi
329a73dbd6
Rollup merge of #96587 - bjorn3:refactor_backend_write, r=michaelwoerister
Refactor the WriteBackendMethods and ExtraBackendMethods traits

The new interface is slightly less confusing and is easier to implement for non-LLVM backends.
2022-05-03 14:58:57 +09:00
bors
24c8985043 Auto merge of #96436 - petrochenkov:nowhole2, r=wesleywiser
linker: Stop using whole-archive on dependencies of dylibs

https://github.com/rust-lang/rust/pull/95604 implemented a better and more fine-grained way of keeping exported symbols alive.

Addresses the second question from https://github.com/rust-lang/rust/pull/93901#issuecomment-1041325522.
r? `@wesleywiser`
2022-05-02 16:28:47 +00:00
Tomasz Miąsko
fa41852c7a Use reverse postorder in non_ssa_locals
The reverse postorder, unlike preorder, is now cached inside the MIR
body. Code generation uses reverse postorder anyway, so it might be
a small perf improvement to use it here as well.
2022-05-01 14:58:29 +02:00
bjorn3
78c65a52db Merge new_metadata into codegen_allocator 2022-04-30 21:20:08 +02:00
bjorn3
fab72301d9 Remove config parameter of optimize_fat and avoid interior mutability for module 2022-04-30 20:58:42 +02:00
bjorn3
ee94ff254a Let LtoModuleCodegen::optimize take self by value 2022-04-30 20:51:17 +02:00
bjorn3
336bb0afea Rename run_lto_pass_manager to optimize_fat and remove thin parameter 2022-04-30 20:50:17 +02:00
bors
9a98c63b30 Auto merge of #96500 - SparrowLii:rpo, r=tmiasko
Reduce duplication of RPO calculation of mir

Computing the RPO of mir is not a low-cost thing, but it is duplicate in many places. In particular the `iterate_to_fixpoint` method which is called multiple times when computing the data flow.
This PR reduces the number of times the RPO is recalculated as much as possible, which should save some compile time.
2022-04-30 05:06:47 +00:00
SparrowLii
7149bbcdc5 Eliminate duplication of RPO calculation for mir
add `postorder_cache` to mir Body

add `ReversePostorderCache` struct

correct struct name and comments
2022-04-30 03:42:57 +08:00
bors
1c8966e5e9 Auto merge of #96474 - SparrowLii:langcall, r=lcnr
Eliminate duplication code of building panic langcall during codegen

From the FIXME in the `codegen_panic_intrinsic` func.
2022-04-29 17:20:00 +00:00
Dylan DPC
48199e0e3f
Rollup merge of #96523 - nbdd0121:windows, r=petrochenkov
Add `@feat.00` symbol to symbols.o for COFF

Fix #96498

This is based on top of #96444.

r? ``@petrochenkov``
2022-04-29 11:23:16 +02:00
bors
5560c51738 Auto merge of #96444 - nbdd0121:used2, r=petrochenkov
Use decorated names for linked_symbols on Windows

Fix #96423

r? `@petrochenkov`
2022-04-29 05:34:29 +00:00
Gary Guo
0fce0db96f Add @feat.00 symbol to symbols.o for COFF 2022-04-28 21:33:23 +01:00
SparrowLii
cf00142b4d use tcx.require_lang_item() instead 2022-04-28 20:18:01 +08:00
Dylan DPC
d956d014f2
Rollup merge of #96432 - SparrowLii:dbg_scope, r=davidtwco
not need `Option` for `dbg_scope`

This PR fixes a few FIXME about not using `Option` in `dbg_scope` field of `DebugScope`, during `create_function_debug_context` func in codegen parts.
Added a `BitSet<SourceScope>` parameter to `make_mir_scope` to indicate whether the `DebugScope` has been instantiated.
cc ````@eddyb````
2022-04-28 02:40:34 +02:00
Gary Guo
4f9acb2687 Use decorated names for linked_symbols on Windows 2022-04-27 13:17:13 +01:00
SparrowLii
d735aa6810 Eliminate duplication of building panic langcall in codegen 2022-04-27 18:58:59 +08:00
Vadim Petrochenkov
4136b8feb0 linker: Generate symbols.o for dylibs 2022-04-26 23:16:08 +03:00
Vadim Petrochenkov
73317f8b0d linker: Stop using whole-archive on dependencies of dylibs
https://github.com/rust-lang/rust/pull/95604 implemented a better and more fine-grained way of keeping exported symbols alive.
2022-04-26 23:16:07 +03:00
SparrowLii
843e8d19ec not need Option for dbg_scope 2022-04-26 21:00:19 +08:00
bors
18b53cefdf Auto merge of #95604 - nbdd0121:used2, r=petrochenkov
Generate synthetic object file to ensure all exported and used symbols participate in the linking

Fix #50007 and #47384

This is the synthetic object file approach that I described in https://github.com/rust-lang/rust/pull/95363#issuecomment-1079932354, allowing all exported and used symbols to be linked while still allowing them to be GCed.

Related #93791, #95363

r? `@petrochenkov`
cc `@carbotaniuman`
2022-04-25 16:14:54 +00:00
Gary Guo
6f9b2b3247 Stop exporting rust_eh_personality and friends from cdylib 2022-04-25 14:06:30 +01:00
Gary Guo
9ebeb284b5 Fix MSVC hang issue 2022-04-24 13:13:41 +01:00
bors
5176945ad4 Auto merge of #95612 - davidtwco:split-debuginfo-in-bootstrap, r=Mark-Simulacrum
bootstrap: add split-debuginfo config

Replace `run-dysutil` option with more general `split-debuginfo` option that works on all platforms.

r? `@Mark-Simulacrum`
2022-04-21 05:24:48 +00:00
Dylan DPC
9fad214593
Rollup merge of #96142 - cjgillot:no-crate-def-index, r=petrochenkov
Stop using CRATE_DEF_INDEX outside of metadata encoding.

`CRATE_DEF_ID` and `CrateNum::as_def_id` are almost always what we want.  We should not manipulate raw `DefIndex` outside of metadata encoding.
2022-04-19 14:43:21 +02:00
Gary Guo
e2fdb84df7 Conditionally export msan symbols only if they are defined
* `__msan_keep_going` is defined when `-Zsanitizer-recover=memory`.
* `__msan_track_origins` is defined when `-Zsanitizer-memory-track-origins`.
2022-04-18 20:50:56 +01:00
Gary Guo
c475117ffb Refactor exported_symbols and linked_symbols for code reuse 2022-04-18 20:50:56 +01:00
Gary Guo
773f533eae Synthesis object file for #[used] and exported symbols 2022-04-18 20:50:56 +01:00
Gary Guo
49cc6d1f84 Add SymbolExportInfo
This is currently a wrapper to `SymbolExportLevel` but it allows
later addition of extra information.
2022-04-18 20:50:56 +01:00
David Wood
b786345347 ssa: don't pack debuginfo on windows not only msvc
Small fix that prevents `thorin` from running on platforms where it
definitely shouldn't be running.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-18 03:47:51 +01:00
Camille GILLOT
07ee031763 Stop using CRATE_DEF_INDEX.
`CRATE_DEF_ID` and `CrateNum::as_def_id` are almost always what we want.
2022-04-17 12:14:42 +02:00
bors
ac8b11810f Auto merge of #96010 - eduardosm:Unique-on-top-of-NonNull, r=m-ou-se,tmiasko
Implement `core::ptr::Unique` on top of `NonNull`

Removes the use `rustc_layout_scalar_valid_range_start` and some `unsafe` blocks.
2022-04-17 05:26:08 +00:00
Amanieu d'Antras
547405e801 Add codegen for global_asm! sym operands 2022-04-15 14:36:30 +01:00
Eduardo Sánchez Muñoz
c58af72a03 Add additional extract_field / project_field to take into account extra level of struct nesting. 2022-04-14 19:35:40 +02:00
bors
34a6c9f26e Auto merge of #95968 - davidtwco:translation-lazy-fallback, r=oli-obk
errors: lazily load fallback fluent bundle

Addresses (hopefully) https://github.com/rust-lang/rust/pull/95667#issuecomment-1094794087.

Loading the fallback bundle in compilation sessions that won't go on to emit any errors unnecessarily degrades compile time performance, so lazily create the Fluent bundle when it is first required.

r? `@ghost` (just for perf initially)
2022-04-13 21:04:19 +00:00
bors
f38c5c8e5d Auto merge of #95656 - cjgillot:no-id-hashing-mode, r=Aaron1011
Remove NodeIdHashingMode.

r? `@ghost`
2022-04-13 11:27:17 +00:00
David Wood
9bfe0e39e4 errors: lazily load fallback fluent bundle
Loading the fallback bundle in compilation sessions that won't go on to
emit any errors unnecessarily degrades compile time performance, so
lazily create the Fluent bundle when it is first required.

Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-13 02:44:59 +01:00
Camille GILLOT
443333dc1f Remove NodeIdHashingMode. 2022-04-12 19:59:32 +02:00
Jakob Degen
48b01a0d0e Add new MutatatingUseContexts for deinit and SetDiscriminant 2022-04-11 09:26:26 -04:00