summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src/mir
AgeCommit message (Collapse)AuthorLines
2023-08-17Monomorphize constants before inspecting themOli Scherer-1/+1
(cherry picked from commit c7428d50520446ccd44ca89bbbf4ff7a4725570e)
2023-08-17Permit pre-evaluated constants in simd_shuffleOli Scherer-0/+14
(cherry picked from commit 9e5a67e57f715ec5eda915db1261cdf4c4a04642)
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
2023-05-25Remove ExpnKind::Inlined.Camille GILLOT-5/+1
2023-05-24Rollup merge of #111912 - WaffleLapkin:is_some_and_in_the_compiler, ↵Manish Goregaokar-1/+1
r=petrochenkov Use `Option::is_some_and` and `Result::is_ok_and` in the compiler `.is_some_and(..)`/`.is_ok_and(..)` replace `.map_or(false, ..)` and `.map(..).unwrap_or(false)`, making the code more readable. This PR is a sibling of https://github.com/rust-lang/rust/pull/111873#issuecomment-1561316515
2023-05-24Use `Option::is_some_and` and `Result::is_ok_and` in the compilerMaybe Waffle-1/+1
2023-05-17Cache dominators.Camille GILLOT-1/+1
2023-05-14Auto merge of #111440 - cjgillot:refprop-debuginfo, r=oli-obkbors-49/+101
Allow MIR debuginfo to point to a variable's address MIR optimizations currently do not to operate on borrowed locals. When enabling #106285, many borrows will be left as-is because they are used in debuginfo. This pass allows to replace this pattern directly in MIR debuginfo: ```rust a => _1 _1 = &raw? mut? _2 ``` becomes ```rust a => &_2 // No statement to borrow _2. ``` This pass is implemented as a drive-by in ReferencePropagation MIR pass. This transformation allows following following MIR opts to treat _2 as an unborrowed local, and optimize it as such, even in builds with debuginfo. In codegen, when encountering `a => &..&_2`, we create a list of allocas: ```llvm store ptr %_2.dbg.spill, ptr %a.ref0.dbg.spill store ptr %a.ref0.dbg.spill, ptr %a.ref1.dbg.spill ... call void `@llvm.dbg.declare(metadata` ptr %a.ref{n}.dbg.spill, /* ... */) ``` Caveat: this transformation looses the exact type, we do not differentiate `a` as a immutable, mutable reference or a raw pointer. Everything is declared to `*mut` to codegen. I'm not convinced this is a blocker.
2023-05-13Auto merge of #111374 - tmiasko:align-unsized-locals, r=cjgillotbors-11/+15
Align unsized locals Allocate an extra space for unsized locals and manually align the storage, since alloca doesn't support dynamic alignment. Fixes #71416. Fixes #71695.
2023-05-13Support ConstantIndex in debuginfo.Camille GILLOT-1/+23
2023-05-13Implement references VarDebugInfo.Camille GILLOT-12/+40
2023-05-13Extract debug_introduce_local_as_var.Camille GILLOT-48/+50
2023-05-08Align unsized localsTomasz Miąsko-11/+15
Allocate an extra space for unsized locals and manually align the storage, since alloca doesn't support dynamic alignment.
2023-05-08Rollup merge of #104070 - nbdd0121:unwind, r=AmanieuMichael Goulet-1/+1
Prevent aborting guard from aborting the process in a forced unwind Fix #101469
2023-05-08Rollup merge of #110297 - kylematsuda:earlybinder_tcx_subst, r=BoxyUwUDylan DPC-1/+1
Make `(try_)subst_and_normalize_erasing_regions` take `EarlyBinder` Changes `subst_and_normalize_erasing_regions` and `try_subst_and_normalize_erasing_regions` to take `EarlyBinder<T>` instead of `T`. (related to #105779) This was suggested by `@BoxyUwU` in https://github.com/rust-lang/rust/pull/107753#discussion_r1105828139. After changing `type_of` to return `EarlyBinder`, there were several places where the binder was immediately skipped to call `tcx.subst_and_normalize_erasing_regions`, only for the binder to be reconstructed inside of that method. r? `@BoxyUwU`
2023-05-07Use `landingpad filter` to encode aborting landing padGary Guo-1/+1
2023-05-06use EarlyBinder in tcx.(try_)subst_mir_and_normalize_erasing_regionsKyle Matsuda-1/+1
2023-05-05Address review comments.Luqman Aden-6/+0
Remove bitcasts in OperandRef::extract_field; only pointercasts should be needed.
2023-05-05Don't bitcast aggregate field.Luqman Aden-1/+26
2023-05-05Operand::extract_field: only cast llval if it's a pointer and replace ↵Luqman Aden-3/+13
bitcast w/ pointercast.