about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src/mir
AgeCommit message (Collapse)AuthorLines
2023-02-02Codegen SetDiscriminant after field assignment.Camille GILLOT-15/+11
This matches the order in which deaggregation was performed.
2023-02-02Interpret aggregates.Camille GILLOT-0/+5
2023-01-29Auto merge of #107435 - matthiaskrgr:rollup-if5h6yu, r=matthiaskrgrbors-11/+22
Rollup of 8 pull requests Successful merges: - #106618 (Disable `linux_ext` in wasm32 and fortanix rustdoc builds.) - #107097 (Fix def-use dominance check) - #107154 (library/std/sys_common: Define MIN_ALIGN for m68k-unknown-linux-gnu) - #107397 (Gracefully exit if --keep-stage flag is used on a clean source tree) - #107401 (remove the usize field from CandidateSource::AliasBound) - #107413 (make more pleasant to read) - #107422 (Also erase substs for new infcx in pin move error) - #107425 (Check for missing space between fat arrow and range pattern) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-01-29Rollup merge of #107097 - tmiasko:ssa, r=cjgillotMatthias Krüger-11/+22
Fix def-use dominance check A definition does not dominate a use in the same statement. For example in MIR generated for compound assignment x += a (when overflow checks are disabled).
2023-01-29Auto merge of #106227 - bryangarza:ctfe-limit, r=oli-obkbors-0/+1
Use stable metric for const eval limit instead of current terminator-based logic This patch adds a `MirPass` that inserts a new MIR instruction `ConstEvalCounter` to any loops and function calls in the CFG. This instruction is used during Const Eval to count against the `const_eval_limit`, and emit the `StepLimitReached` error, replacing the current logic which uses Terminators only. The new method of counting loops and function calls should be more stable across compiler versions (i.e., not cause crates that compiled successfully before, to no longer compile when changes to the MIR generation/optimization are made). Also see: #103877
2023-01-27Auto merge of #106959 - tmiasko:opt-funclets, r=davidtwcobors-43/+40
Omit needless funclet partitioning
2023-01-27Fix def-use dominance checkTomasz Miąsko-11/+22
A definition does not dominate a use in the same statement. For example in MIR generated for compound assignment x += a (when overflow checks are disabled).
2023-01-26Auto merge of #107314 - matthiaskrgr:rollup-j40lnlj, r=matthiaskrgrbors-9/+12
Rollup of 11 pull requests Successful merges: - #106407 (Improve proc macro attribute diagnostics) - #106960 (Teach parser to understand fake anonymous enum syntax) - #107085 (Custom MIR: Support binary and unary operations) - #107086 (Print PID holding bootstrap build lock on Linux) - #107175 (Fix escaping inference var ICE in `point_at_expr_source_of_inferred_type`) - #107204 (suggest qualifying bare associated constants) - #107248 (abi: add AddressSpace field to Primitive::Pointer ) - #107272 (Implement ObjectSafe and WF in the new solver) - #107285 (Implement `Generator` and `Future` in the new solver) - #107286 (ICE in new solver if we see an inference variable) - #107313 (Add Style Team Triagebot config) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-01-26Auto merge of #105582 - saethlin:instcombine-assert-inhabited, r=cjgillotbors-2/+2
InstCombine away intrinsic validity assertions This optimization (currently) fires 246 times on the standard library. It seems to fire hardly at all on the big crates in the benchmark suite. Interesting.
2023-01-23Thread a ParamEnv down to might_permit_raw_initBen Kimock-2/+2
2023-01-23Create stable metric to measure long computation in Const EvalBryan Garza-0/+1
This patch adds a `MirPass` that tracks the number of back-edges and function calls in the CFG, adds a new MIR instruction to increment a counter every time they are encountered during Const Eval, and emit a warning if a configured limit is breached.
2023-01-22abi: add `AddressSpace` field to `Primitive::Pointer`Erik Desjardins-9/+12
...and remove it from `PointeeInfo`, which isn't meant for this. There are still various places (marked with FIXMEs) that assume all pointers have the same size and alignment. Fixing this requires parsing non-default address spaces in the data layout string, which will be done in a followup.
2023-01-17Remove double spaces after dots in commentsMaybe Waffle-2/+2
2023-01-17Omit needless funclet partitioningTomasz Miąsko-43/+40
2023-01-10Add comment to cleanup_kindsTomasz Miąsko-0/+3
based on the original commit message 1ae7ae0c1c7ed68c616273f245647afa47f3cbde
2022-12-27ADD - create and emit Bug support for DiagnosticsJhonny Bill Mena-1/+5
UPDATE - migrate constant span_bug to translatable diagnostic.
2022-12-27[WIP] UPDATE - migrate intrinsic.rs to new diagnostic infrastructureJhonny Bill Mena-52/+12
WIP - replacing span_invalid_monomorphization_error function. Still in progress due to its use in codegen_llvm inside macros
2022-12-27UPDATE - migrate constant.rs to new diagnostics infrastructureJhonny Bill Mena-2/+3
2022-12-22abort immediately on bad mem::zeroed/uninitRalf Jung-5/+4
2022-12-21Auto merge of #105613 - Nilstrieb:rename-assert_uninit_valid, r=RalfJungbors-3/+3
Rename `assert_uninit_valid` intrinsic It's not about "uninit" anymore but about "filling with 0x01 bytes" so the name should at least try to reflect that. This is actually not fully correct though, as it does still panic for all uninit with `-Zstrict-init-checks`. I'm not sure what the best way is to deal with that not causing confusion. I guess we could just remove the flag? I don't think having it makes a lot of sense anymore with the direction that we have chose to go. It could be relevant again if #100423 lands so removing it may be a bit over eager. r? `@RalfJung`
2022-12-18Auto merge of #105446 - erikdesjardins:vt-size, r=nikicbors-3/+9
Add 0..=isize::MAX range metadata to size loads from vtables This is the (much belated) size counterpart to #91569. Inspired by https://rust-lang.zulipchat.com/#narrow/stream/187780-t-compiler.2Fwg-llvm/topic/Range.20metadata.20for.20.60size_of_val.60.20and.20other.20isize.3A.3AMAX.20limits. This could help optimize layout computations based on the size of a dyn trait. Though, admittedly, adding this to vtables wouldn't be as beneficial as adding it to slice len, which is used much more often. Miri detects this UB already: https://github.com/rust-lang/rust/blob/b7cc99142ad0cfe47e2fe9f7a82eaf5b672c0573/compiler/rustc_const_eval/src/interpret/traits.rs#L119-L121 (In fact Miri goes further, [assuming a 48-bit address space on 64-bit platforms](https://github.com/rust-lang/rust/blob/9db224fc908059986c179fc6ec433944e9cfce50/compiler/rustc_abi/src/lib.rs#L312-L331), but I don't think we can assume that in an optimization.)
2022-12-14Rollup merge of #105578 - erikdesjardins:addrspacecast, r=bjorn3Matthias Krüger-4/+9
Fix transmutes between pointers in different address spaces (e.g. fn ptrs on AVR) Currently, this causes a verifier error (https://godbolt.org/z/YYohed4bj), since it uses `bitcast`, which can't convert between address spaces. Uncovered due to https://github.com/rust-lang/rust/pull/105545#discussion_r1045269309 r? `@bjorn3`
2022-12-13Rename `assert_uninit_valid` intrinsicNilstrieb-3/+3
It's not about "uninit" anymore but about "filling with 0x01 bytes" so the name should at least try to reflect that.
2022-12-12Auto merge of #105252 - bjorn3:codegen_less_pair_values, r=nagisabors-20/+9
Use struct types during codegen in less places This makes it easier to use cg_ssa from a backend like Cranelift that doesn't have any struct types at all. After this PR struct types are still used for function arguments and return values. Removing those usages is harder but should still be doable.
2022-12-11fix transmutes between pointers in different address spacesErik Desjardins-4/+9
2022-12-11bug! with a better error message for failing Instance::resolveMichael Goulet-4/+7
2022-12-10Rollup merge of #105482 - wesleywiser:fix_debuginfo_ub, r=tmiaskoMatthias Krüger-29/+107
Fix invalid codegen during debuginfo lowering In order for LLVM to correctly generate debuginfo for msvc, we sometimes need to spill arguments to the stack and perform some direct & indirect offsets into the value. Previously, this code always performed those actions, even when not required as LLVM would clean it up during optimization. However, when MIR inlining is enabled, this can cause problems as the operations occur prior to the spilled value being initialized. To solve this, we first calculate the necessary offsets using just the type which is side-effect free and does not alter the LLVM IR. Then, if we are in a situation which requires us to generate the LLVM IR (and this situation only occurs for arguments, not local variables) then we perform the same calculation again, this time generating the appropriate LLVM IR as we go. r? `@tmiasko` but feel free to reassign if you want 🙂 Fixes #105386
2022-12-09Remove unneeded field from `SwitchTargets`Jakob Degen-5/+3
2022-12-08Don't generate pointer loads to spills unless necessaryWesley Wiser-2/+27
In order for LLVM to correctly generate debuginfo for msvc, we sometimes need to spill arguments to the stack and perform some direct & indirect offsets into the value. Previously, this code always performed those actions, even when not required as LLVM would clean it up during optimization. However, when MIR inlining is enabled, this can cause problems as the operations occur prior to the spilled value being initialized. To solve this, we first calculate the necessary offsets using just the type which is side-effect free and does not alter the LLVM IR. Then, if we are in a situation which requires us to generate the LLVM IR (and this situation only occurs for arguments, not local variables) then we perform the same calculation again, this time generating the appropriate LLVM IR as we go.
2022-12-08Make `debuginfo_offset_calcuation` generic so we can resuse the logicWesley Wiser-10/+41
This will allow us to separate the act of calculating the offsets from creating LLVM IR that performs the actions.
2022-12-08Factor out debuginfo offset calculationWesley Wiser-27/+49
2022-12-08Add 0..=isize::MAX range metadata to size loads from vtablesErik Desjardins-3/+9
2022-12-04Auto merge of #104535 - mikebenfield:discr-fix, r=pnkfelixbors-9/+18
rustc_codegen_ssa: Fix for codegen_get_discr When doing the optimized implementation of getting the discriminant, the arithmetic needs to be done in the tag type so wrapping behavior works correctly. Fixes #104519
2022-12-04Avoid from_immediate_or_packed_pair in ThreadLocalRef codegenbjorn3-1/+1
2022-12-03Destruct landing_pad return value before passing it to cg_ssabjorn3-19/+8
2022-11-27Prefer doc comments over `//`-comments in compilerMaybe Waffle-2/+2
2022-11-24Properly handle `Pin<&mut dyn* Trait>` receiver in codegenMichael Goulet-6/+24
2022-11-19deduplicate constant evaluation in cranelift backendRalf Jung-1/+8
also sync LLVM and cranelift structure a bit
2022-11-18rustc_codegen_ssa: Fix for codegen_get_discrMichael Benfield-9/+18
When doing the optimized implementation of getting the discriminant, the arithmetic needs to be done in the tag type so wrapping behavior works correctly. Fixes #104519
2022-11-17Auto merge of #103138 - nnethercote:merge-BBs, r=bjorn3bors-331/+406
Merge basic blocks where possible when generating LLVM IR. r? `@ghost`
2022-11-16cleanup and dedupe CTFE and Miri error reportingRalf Jung-1/+1
2022-11-16Merge basic blocks where possible when generating LLVM IR.Nicholas Nethercote-135/+251
In `codegen_assert_terminator` we decide if a BB's successor is a candidate for merging, which requires that it be the only successor, and that it only have one predecessor. That result then gets passed down, and if it reaches `funclet_br` with the appropriate BB characteristics, then no `br` instruction is issued, a `MergingSucc::True` result is passed back, and the merging proceeds in `codegen_block`. The commit also adds `CachedLlbb`, a new type to help keep track of each BB that has been merged into its predecessor.
2022-11-16Use `&mut Bx` more.Nicholas Nethercote-206/+165
For the next commit, `FunctionCx::codegen_*_terminator` need to take a `&mut Bx` instead of consuming a `Bx`. This triggers a cascade of similar changes across multiple functions. The resulting code is more concise and replaces many `&mut bx` expressions with `bx`.
2022-11-15Introduce composite debuginfo.Camille GILLOT-7/+64
2022-11-13add is_sized method on Abi and Layout, and use itRalf Jung-4/+4
2022-11-11rustc_codegen_ssa: Better code generation for niche discriminants.Michael Benfield-49/+145
In some cases we can avoid arithmetic before checking whether a niche represents an untagged variant. This is relevant to #101872
2022-10-31Use `br` instead of `switch` in more cases.Nicholas Nethercote-2/+28
`codegen_switchint_terminator` already uses `br` instead of `switch` when there is one normal target plus the `otherwise` target. But there's another common case with two normal targets and an `otherwise` target that points to an empty unreachable BB. This comes up a lot when switching on the tags of enums that use niches. The pattern looks like this: ``` bb1: ; preds = %bb6 %3 = load i8, ptr %_2, align 1, !range !9, !noundef !4 %4 = sub i8 %3, 2 %5 = icmp eq i8 %4, 0 %_6 = select i1 %5, i64 0, i64 1 switch i64 %_6, label %bb3 [ i64 0, label %bb4 i64 1, label %bb2 ] bb3: ; preds = %bb1 unreachable ``` This commit adds code to convert the `switch` to a `br`: ``` bb1: ; preds = %bb6 %3 = load i8, ptr %_2, align 1, !range !9, !noundef !4 %4 = sub i8 %3, 2 %5 = icmp eq i8 %4, 0 %_6 = select i1 %5, i64 0, i64 1 %6 = icmp eq i64 %_6, 0 br i1 %6, label %bb4, label %bb2 bb3: ; No predecessors! unreachable ``` This has a surprisingly large effect on compile times, with reductions of 5% on debug builds of some crates. The reduction is all due to LLVM taking less time. Maybe LLVM is just much better at handling `br` than `switch`. The resulting code is still suboptimal. - The `icmp`, `select`, `icmp` sequence is silly, converting an `i1` to an `i64` and back to an `i1`. But with the current code structure it's hard to avoid, and LLVM will easily clean it up, in opt builds at least. - `bb3` is usually now truly dead code (though not always, so it can't be removed universally).
2022-10-25Clarify some cleanup stuff.Nicholas Nethercote-6/+10
- Rearrange the match in `llbb_with_landing_pad` so the `(Some,Some)` cases are together. - Add assertions to indicate two MSVC-only paths.
2022-10-25Rename two `TerminatorCodegenHelper` methods.Nicholas Nethercote-13/+16
`TerminatorCodegenHelper` has three methods `llblock`, `llbb`, and `lltarget`. They're all similar, but the names given no indication of the differences. This commit renames `lltarget` as `llbb_with_landing_pad`, and `llblock` as `llbb_with_cleanup`. These aren't fantastic names, but at least it's now clear that `llbb` is the lowest-level of the three and the other two wrap it.
2022-10-25rustc_codegen_ssa: use more consistent naming.Nicholas Nethercote-30/+31
Ensure: - builders always have a `bx` suffix; - backend basic blocks always have an `llbb` suffix, - paired builders and basic blocks have consistent prefixes.