about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src/mir
AgeCommit message (Collapse)AuthorLines
2023-08-24when terminating during unwinding, show the reason whyRalf Jung-78/+83
2023-08-22Auto merge of #114643 - dpaoliello:inlinedebuginfo, r=wesleywiserbors-3/+13
Use the same DISubprogram for each instance of the same inlined function within a caller # Issue Details: The call to `panic` within a function like `Option::unwrap` is translated to LLVM as a `tail call` (as it will never return), when multiple calls to the same function like this is inlined LLVM will notice the common `tail call` block (i.e., loading the same panic string + location info and then calling `panic`) and merge them together. When merging these instructions together, LLVM will also attempt to merge the debug locations as well, but this fails (i.e., debug info is dropped) as Rust emits a new `DISubprogram` at each inline site thus LLVM doesn't recognize that these are actually the same function and so thinks that there isn't a common debug location. As an example of this when building for x86_64 Windows (note the lack of `.cv_loc` before the call to `panic`, thus it will be attributed to the same line at the `addq` instruction): ``` .cv_loc 0 1 23 0 # src\lib.rs:23:0 addq $40, %rsp retq leaq .Lalloc_f570dea0a53168780ce9a91e67646421(%rip), %rcx leaq .Lalloc_629ace53b7e5b76aaa810d549cc84ea3(%rip), %r8 movl $43, %edx callq _ZN4core9panicking5panic17h12e60b9063f6dee8E int3 ``` # Fix Details: Cache the `DISubprogram` emitted for each inlined function instance within a caller so that this can be reused if that instance is encountered again, this also requires caching the `DILexicalBlock` and `DIVariable` objects to avoid creating duplicates. After this change the above assembly now looks like: ``` .cv_loc 0 1 23 0 # src\lib.rs:23:0 addq $40, %rsp retq .cv_inline_site_id 5 within 0 inlined_at 1 0 0 .cv_inline_site_id 6 within 5 inlined_at 1 12 0 .cv_loc 6 2 935 0 # library\core\src\option.rs:935:0 leaq .Lalloc_5f55955de67e57c79064b537689facea(%rip), %rcx leaq .Lalloc_e741d4de8cb5801e1fd7a6c6795c1559(%rip), %r8 movl $43, %edx callq _ZN4core9panicking5panic17hde1558f32d5b1c04E int3 ```
2023-08-20give some unwind-related terminators a more clear nameRalf Jung-4/+4
2023-08-17Revert "Implement references VarDebugInfo."Camille GILLOT-42/+12
This reverts commit 2ec007191348ef7cc13eb55e44e007b02cf75cf3.
2023-08-11Use the same DISubprogram for each instance of the same inlined function ↵Daniel Paoliello-3/+13
within the caller
2023-08-06Rollup merge of #114505 - ouz-a:cleanup_mir, r=RalfJungMatthias Krüger-1/+1
Add documentation to has_deref Documentation of `has_deref` needed some polish to be more clear about where it should be used and what's it's purpose. cc https://github.com/rust-lang/rust/issues/114401 r? `@RalfJung`
2023-08-06cleanup misinformation regarding has_derefouz-a-1/+1
2023-08-03Forbid old-style `simd_shuffleN` intrinsicsOli Scherer-2/+2
2023-08-01Auto merge of #105545 - erikdesjardins:ptrclean, r=bjorn3bors-106/+28
cleanup: remove pointee types This can't be merged until the oldest LLVM version we support uses opaque pointers, which will be the case after #114148. (Also note `-Cllvm-args="-opaque-pointers=0"` can technically be used in LLVM 15, though I don't think we should support that configuration.) I initially hoped this would provide some minor perf win, but in https://github.com/rust-lang/rust/pull/105412#issuecomment-1341224450 it had very little impact, so this is only valuable as a cleanup. As a followup, this will enable #96242 to be resolved. r? `@ghost` `@rustbot` label S-blocked
2023-07-30inline format!() args up to and including rustc_codegen_llvmMatthias Krüger-13/+8
2023-07-29cg_ssa: remove pointee types and pointercast/bitcast-of-ptrErik Desjardins-106/+28
2023-07-20Monomorphize constants before inspecting themOli Scherer-1/+1
2023-07-18Permit pre-evaluated constants in simd_shuffleOli Scherer-0/+14
2023-07-15Auto merge of #112157 - erikdesjardins:align, r=nikicbors-24/+56
Resurrect: rustc_target: Add alignment to indirectly-passed by-value types, correcting the alignment of byval on x86 in the process. Same as #111551, which I [accidentally closed](https://github.com/rust-lang/rust/pull/111551#issuecomment-1571222612) :/ --- This resurrects PR #103830, which has sat idle for a while. Beyond #103830, this also: - fixes byval alignment for types containing vectors on Darwin (see `tests/codegen/align-byval-vector.rs`) - fixes byval alignment for overaligned types on x86 Windows (see `tests/codegen/align-byval.rs`) - fixes ABI for types with 128bit requested alignment on ARM64 Linux (see `tests/codegen/aarch64-struct-align-128.rs`) r? `@nikic` --- `@pcwalton's` original PR description is reproduced below: Commit 88e4d2c from five years ago removed support for alignment on indirectly-passed arguments because of problems with the `i686-pc-windows-msvc` target. Unfortunately, the `memcpy` optimizations I recently added to LLVM 16 depend on this to forward `memcpy`s. This commit attempts to fix the problems with `byval` parameters on that target and now correctly adds the `align` attribute. The problem is summarized in [this comment] by `@eddyb.` Briefly, 32-bit x86 has special alignment rules for `byval` parameters: for the most part, their alignment is forced to 4. This is not well-documented anywhere but in the Clang source. I looked at the logic in Clang `TargetInfo.cpp` and tried to replicate it here. The relevant methods in that file are `X86_32ABIInfo::getIndirectResult()` and `X86_32ABIInfo::getTypeStackAlignInBytes()`. The `align` parameter attribute for `byval` parameters in LLVM must match the platform ABI, or miscompilations will occur. Note that this doesn't use the approach suggested by eddyb, because I felt it was overkill to store the alignment in `on_stack` when special handling is really only needed for 32-bit x86. As a side effect, this should fix #80127, because it will make the `align` parameter attribute for `byval` parameters match the platform ABI on LLVM x86-64. [this comment]: #80822 (comment)
2023-07-14refactor(rustc_middle): Substs -> GenericArgMahdi Dibaiee-27/+27
2023-07-12Re-format let-else per rustfmt updateMark Rousskov-1/+5
2023-07-10ensure byval allocas are sufficiently alignedErik Desjardins-24/+56
2023-07-09Rollup merge of #111618 - cjgillot:name-return-place, r=tmiaskoMatthias Krüger-2/+1
Always name the return place. MIR opts more and more consider `_0` as just another local, so there is no point in keeping the special case in debug-info logic.
2023-07-08Always name the return place.Camille GILLOT-2/+1
2023-07-07Rename `adjustment::PointerCast` and variants using it to `PointerCoercion`Nilstrieb-9/+13
It makes it sound like the `ExprKind` and `Rvalue` are supposed to represent all pointer related casts, when in reality their just used to share a some enum variants. Make it clear there these are only coercion to make it clear why only some pointer related "casts" are in the enum.
2023-07-05Move `TyCtxt::mk_x` to `Ty::new_x` where applicableBoxy-13/+19
2023-07-05Narrow trait `CoverageInfoBuilderMethods` down to just one methodZalathar-39/+4
This effectively inlines most of `FunctionCx::codegen_coverage` into the LLVM implementation of `CoverageInfoBuilderMethods`.
2023-07-02Auto merge of #112718 - oli-obk:SIMD-destructure_mir_const, r=cjgillotbors-24/+34
Make simd_shuffle_indices use valtrees This removes the second-to-last user of the `destructure_mir_constant` query. So in a follow-up we can remove the query and just move the query provider function directly into pretty printing (which is the last user). cc `@rust-lang/clippy` there's a small functional change, but I think it is correct?
2023-06-29Rollup merge of #111322 - mirkootter:master, r=davidtwcoMatthias Krüger-6/+23
Support for native WASM exceptions ### Motivation Currently, rustc does not support native WASM exceptions. It does support JavaScript based exceptions for the wasm32-emscripten-target, but this requires back&forth with javascript for many calls, which is very slow. Native wasm support for exceptions is quite common: Clang+LLVM implemented them years ago, and all major browsers support them by now. They enable zero-cost exceptions, at least with regard to runtime-performance-cost. They may increase startup-time and code size, though. ### Important: This PR does not change default behaviour Exceptions usually add a lot of code in form of unwinding blocks, increasing the binary size. Most users probably do not want that, especially which regard to web development. Therefore, wasm exceptions play a similar role as WASM-threads: rustc should support them, like clang does, but users who want to use it have to use some command-line magic like rustflags to opt in. ### What does this PR do? As stated above, the default behaviour is not changed. It is already possible to opt-in into wasm exceptions using the command line. Unfortunately, the LLVM IR is invalid and the LLVM backend crashes. ``` rustc <sourcefile> --target wasm32-unknown-unknown -C panic=unwind -C llvm-args=-wasm-enable-eh -C target-feature=+exception-handling ``` As it turns out, LLVM is quite picky when it comes to IR for exception handling. If the IR does not look exactly like it should, some LLVM-assertions fail and the code generation crashes. This PR adds the necessary modifications to the code generator to make it work. It also adds `exception-handling` as a wasm target feature. ### What this PR does not / what is missing This PR is not a full fledges solution. It is the first step. A few parts are still missing; however, it is already useable (see next section). Currently missing: * The std library has to be adapted. Currently, only [no_std] crates work * Usually, nested exceptions abort the program (i.e. a panic during the cleanup of another panic). This is currently not done yet. - Currently, code inside cleanup handlers does not unwind - To fix this requires a little more work: The code generator currently maintains a single terminate block per function for this. Unfortunately, WASM requires funclet based exception handling. Therefore, we need to create a terminate block per funclet. This is probably not a big problem, but I want to keep this PR simple. ### How to use the compiler given this PR? This PR does not add any command line flags or features. It uses those which are already there. To compile with exceptions enabled, you need * to set the panic strategy to unwind, i.e. `-C panic=unwind` * to enable the exception-handling target feature, i.e. `-C target-feature=+exception-handling` * to tell LLVM about the exception handling, i.e. `-C llvm-args=-wasm-enable-eh` Since the standard library has not been adapted, you can only use it in [no_std] crates as of now. The intrinsic `core::intrinsics::r#try` works. To throw exceptions, you need the ```@llvm.wasm.throw``` intrinsic. I created a sample application which works for me: https://github.com/mirkootter/rust-wasm-demos This example can be run at https://webassembly.sh
2023-06-28Auto merge of #112307 - lcnr:operand-ref, r=compiler-errorsbors-29/+101
mir opt + codegen: handle subtyping fixes #107205 the same issue was caused in multiple places: - mir opts: both copy and destination propagation - codegen: assigning operands to locals (which also propagates values) I changed codegen to always update the type in the operands used for locals which should guard against any new occurrences of this bug going forward. I don't know how to make mir optimizations more resilient here. Hopefully the added tests will be enough to detect any trivially wrong optimizations going forward.
2023-06-26Move mir const to valtree conversion to its own method.Oli Scherer-23/+25
2023-06-26Make simd_shuffle_indices use valtreesOli Scherer-13/+21
2023-06-19Rollup merge of #112232 - fee1-dead-contrib:match-eq-const-msg, r=b-naberMichael Goulet-1/+1
Better error for non const `PartialEq` call generated by `match` Resolves #90237
2023-06-19Remove unchecked_add/sub/mul/shl/shr from CTFE/cg_ssa/cg_clifScott McMurray-43/+6
2023-06-19Promote unchecked_add/sub/mul/shl/shr to mir::BinOpScott McMurray-2/+31
2023-06-19add FIXME's for a later refactoringlcnr-0/+1
2023-06-19codegen: fix `OperandRef` subtype handlinglcnr-29/+100
2023-06-18Better error for non const `PartialEq` call generated by `match`Deadbeef-1/+1
2023-06-15Fix comment for ptr alignment checks in codegenNilstrieb-1/+1
2023-06-07wasm exception handlingJan-Mirko Otter-6/+14
2023-06-07add commentJan-Mirko Otter-0/+9
2023-06-02Rollup merge of #112168 - scottmcm:lower-div-rem-unchecked-to-mir, r=oli-obkMichael Goulet-16/+0
Lower `unchecked_div`/`_rem` to MIR's `BinOp::Div`/`Rem` As described in <https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/enum.BinOp.html#variant.Div>, the ordinary `BinOp`s for these are already UB for division by zero ([or overflow](https://llvm.org/docs/LangRef.html#sdiv-instruction), [demo](https://rust.godbolt.org/z/71e7P7Exh)), as MIR building is responsible for inserting code to panic for those cases regardless of whether the overflow checks are enabled. So we can lower these in the same arm that lowers `wrapping_add` to MIR `BinOp::Add` and such, as all these cases turn into ordinary `Rvalue::BinaryOp`s.
2023-06-01remove unchecked_div/_rem from cg_ssaScott McMurray-16/+0
2023-05-31Add a distinct `OperandValue::ZeroSized` variant for ZSTsScott McMurray-65/+81
These tend to have special handling in a bunch of places anyway, so the variant helps remember that. And I think it's easier to grok than non-Scalar Aggregates sometimes being `Immediates` (like I got wrong and caused 109992). As a minor bonus, it means we don't need to generate poison LLVM values for them to pass around in `OperandValue::Immediate`s.
2023-05-31Rollup merge of #112069 - clubby789:offset-of-sized-fields, r=WaffleLapkinMatthias Krüger-3/+8
offset_of: don't require type to be `Sized` Fixes #112051 ~~The RFC [explicitly forbids](https://rust-lang.github.io/rfcs/3308-offset_of.html#limitations) non-`Sized` types, but it looks like only the fields being recursed into were checked. The sized check also seemed to have been completely missing for tuples~~
2023-05-31Auto merge of #112070 - lcnr:disjoint-closure-capture-ub, r=oli-obkbors-1/+0
change `BorrowKind::Unique` to be a mutating `PlaceContext` fixes #112056 I believe that `BorrowKind::Unique` is a footgun in general, so I added a FIXME and opened https://github.com/rust-lang/rust/issues/112072. This is a bit too involved for this PR though.
2023-05-30Auto merge of #112102 - Nilstrieb:rollup-ivu1hmc, r=Nilstriebbors-1/+1
Rollup of 7 pull requests Successful merges: - #107916 (fix comment on Allocator trait) - #111543 (Uplift `clippy::invalid_utf8_in_unchecked` lint) - #111872 (fix: dedup `static_candidates` before report) - #111955 (bootstrap: Various Step refactors) - #112060 (`EarlyBinder::new` -> `EarlyBinder::bind`) - #112064 (Migrate GUI colors test to original CSS color format) - #112100 (Don't typecheck recovered method call from suggestion) r? `@ghost` `@rustbot` modify labels: rollup
2023-05-30Auto merge of #111768 - oli-obk:pair_const_llvm, r=cjgillotbors-3/+72
Optimize scalar and scalar pair representations loaded from ByRef in llvm in https://github.com/rust-lang/rust/pull/105653 I noticed that we were generating suboptimal LLVM IR if we had a `ConstValue::ByRef` that could be represented by a `ScalarPair`. Before https://github.com/rust-lang/rust/pull/105653 this is probably rare, but after it, every slice will go down this suboptimal code path that requires LLVM to untangle a bunch of indirections and translate static allocations that are only used once to read a scalar pair from.
2023-05-29offset_of: Don't require type to be sizedclubby789-3/+8
2023-05-29unique borrows are mutating useslcnr-1/+0
2023-05-29EarlyBinder::new -> EarlyBinder::bindlcnr-1/+1
2023-05-28Replace EarlyBinder(x) with EarlyBinder::new(x)Kyle Matsuda-1/+1
2023-05-27Rollup merge of #111952 - cjgillot:drop-replace, r=WaffleLapkinGuillaume Gomez-1/+1
Remove DesugaringKind::Replace. A simple boolean flag is enough.
2023-05-26Stop creating intermediate places just to immediate convert them to operandsOli Scherer-3/+72
2023-05-25Remove DesugaringKind::Replace.Camille GILLOT-1/+1