about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform
AgeCommit message (Collapse)AuthorLines
2022-11-15Introduce composite debuginfo.Camille GILLOT-0/+1
2022-11-15Auto merge of #104054 - RalfJung:byte-provenance, r=oli-obkbors-1/+1
interpret: support for per-byte provenance Also factors the provenance map into its own module. The third commit does the same for the init mask. I can move it in a separate PR if you prefer. Fixes https://github.com/rust-lang/miri/issues/2181 r? `@oli-obk`
2022-11-15mv utility methods into separate modulelcnr-5/+5
2022-11-15nll: correctly deal with bivariancelcnr-6/+6
2022-11-15Auto merge of #101168 - jachris:dataflow-const-prop, r=oli-obkbors-0/+532
Add new MIR constant propagation based on dataflow analysis The current constant propagation in `rustc_mir_transform/src/const_prop.rs` fails to handle many cases that would be expected from a constant propagation optimization. For example: ```rust let x = if true { 0 } else { 0 }; ``` This pull request adds a new constant propagation MIR optimization pass based on the existing dataflow analysis framework. Since most of the analysis is not unique to constant propagation, a generic framework has been extracted. It works on top of the existing framework and could be reused for other optimzations. Closes #80038. Closes #81605. ## Todo ### Essential - [x] [Writes to inactive enum variants](https://github.com/rust-lang/rust/pull/101168#pullrequestreview-1089493974). Resolved by rejecting the registration of places with downcast projections for now. Could be improved by flooding other variants if mutable access to a variant is observed. - [X] Handle [`StatementKind::CopyNonOverlapping`](https://github.com/rust-lang/rust/pull/101168#discussion_r957774914). Resolved by flooding the destination. - [x] Handle `UnsafeCell` / `!Freeze` correctly. - [X] Overflow propagation of `CheckedBinaryOp`: Decided to not propagate if overflow flag is `true` (`false` will still be propagated) - [x] More documentation in general. - [x] Arguments for correctness, documentation of necessary assumptions. - [x] Better performance, or alternatively, require `-Zmir-opt-level=3` for now. ### Extra - [x] Add explicit unreachability, i.e. upgrading the lattice from $\mathbb{P} \to \mathbb{V}$ to $\set{\bot} \cup (\mathbb{P} \to \mathbb{V})$. - [x] Use storage statements to improve precision. - [ ] Consider opening issue for duplicate diagnostics: https://github.com/rust-lang/rust/pull/101168#issuecomment-1276609950 - [ ] Flood moved-from places with $\bot$ (requires some changes for places with tracked projections). - [ ] Add downcast projections back in. - [ ] [Algebraic simplifications](https://github.com/rust-lang/rust/pull/101168#discussion_r957967878) (possibly with a shared API; done by old const prop). - [ ] Propagation through slices / arrays. - [ ] Find other optimizations that are done by old `const_prop.rs`, but not by this one.
2022-11-14assert that we are (de)seiralizing ProvenanceMap correctlyRalf Jung-1/+1
2022-11-13Store a LocalDefId in hir::Variant & hir::Field.Camille GILLOT-6/+5
2022-11-13add is_sized method on Abi and Layout, and use itRalf Jung-2/+2
2022-11-12Disable limits if mir-opt-level >= 4Jannis Christopher Köhl-2/+3
2022-11-12Expand upon comment regarding self-assignmentJannis Christopher Köhl-1/+1
2022-11-12Require -Zmir-opt-level >= 3 for nowJannis Christopher Köhl-1/+1
2022-11-12Add comment for guessed constantsJannis Christopher Köhl-0/+1
2022-11-10Simplify creation of mapJannis Christopher Köhl-1/+1
2022-11-10Don't ICE when encountering ConstKind::Error in RequiredConstsVisitorMichael Goulet-1/+1
2022-11-09Fix struct field tracking and add tests for itJannis Christopher Köhl-3/+1
2022-11-09Completely remove tracking of references for nowJannis Christopher Köhl-12/+12
2022-11-08Add support for custom MIR parsingJakob Degen-35/+46
2022-11-07Limit number of basic blocks and tracked places to 100 for nowJannis Christopher Köhl-2/+8
2022-11-07Use new cast methodsJannis Christopher Köhl-12/+15
2022-11-07Limit number of tracked places, and some other perf improvementsJannis Christopher Köhl-3/+20
2022-11-07Move HasTop and HasBottom into lattice.rsJannis Christopher Köhl-1/+1
2022-11-07Small documentation changesJannis Christopher Köhl-1/+7
2022-11-07Use ParamEnv consistentlyJannis Christopher Köhl-9/+8
2022-11-07Prevent propagation of overflow if overflow occuredJannis Christopher Köhl-16/+4
2022-11-07Fix unimplemented binary_ptr_opJannis Christopher Köhl-1/+1
2022-11-07Improve documentation, plus some small changesJannis Christopher Köhl-9/+15
2022-11-07Make overflow handling more preciseJannis Christopher Köhl-11/+18
2022-11-07Make overflow flag propagation conditionalJannis Christopher Köhl-2/+16
2022-11-07Fix rebased CastKindJannis Christopher Köhl-1/+8
2022-11-07Use the same is_enabled as the current const propJannis Christopher Köhl-2/+1
2022-11-07Prevent registration inside references if target is !FreezeJannis Christopher Köhl-2/+1
2022-11-07Remove `Unknown` state in favor of `Value(Top)`Jannis Christopher Köhl-7/+3
2022-11-07Track Scalar instead of ScalarInt for const propJannis Christopher Köhl-42/+29
2022-11-07Add tracking of unreachabilityJannis Christopher Köhl-3/+2
2022-11-07Ignore terminators explicitlyJannis Christopher Köhl-1/+0
2022-11-07Flood with bottom instead of top for unreachable branchesJannis Christopher Köhl-2/+2
2022-11-07Move handling of references and simplify floodingJannis Christopher Köhl-13/+21
2022-11-07Add initial version of value analysis and dataflow constant propagationJannis Christopher Köhl-0/+492
2022-11-06Auto merge of #103975 - oli-obk:tracing, r=jackh726bors-6/+2
Some tracing and comment cleanups Pulled out of https://github.com/rust-lang/rust/pull/101900 to see if that is the perf impact
2022-11-04Some tracing and comment cleanupsOli Scherer-6/+2
2022-11-04Formatting changes + add UI testclubby789-10/+9
2022-11-04Give a specific lint for unsafety not being inheritedclubby789-9/+35
2022-10-31Remove bounds check with enum castouz-a-3/+1
2022-10-30Rollup merge of #101428 - JakobDegen:build-tests, r=oli-obkMichael Howell-2/+2
Add mir building test directory The first commit renames `mir-map.0` mir dumps to `built.after` dumps. I am happy to drop this commit if someone can explain the origin of the name. The second commit moves a bunch of mir building tests into their own directory. I did my best to make sure that all of these tests are actually testing mir building, and not just incidentally using `built.after` r? ``@oli-obk``
2022-10-27Accept `TyCtxt` instead of `TyCtxtAt` in `Ty::is_*` functionsMaybe Waffle-6/+5
Functions in answer: - `Ty::is_freeze` - `Ty::is_sized` - `Ty::is_unpin` - `Ty::is_copy_modulo_regions`
2022-10-27Replace `mir_map.0` dump with `built` phase change dumpJakob Degen-2/+2
2022-10-23Split phase change from `MirPass`Jakob Degen-67/+67
2022-10-21Introduce deduced parameter attributes, and use them for deducing `readonly` onPatrick Walton-0/+251
indirect immutable freeze by-value function parameters. Right now, `rustc` only examines function signatures and the platform ABI when determining the LLVM attributes to apply to parameters. This results in missed optimizations, because there are some attributes that can be determined via analysis of the MIR making up the function body. In particular, `readonly` could be applied to most indirectly-passed by-value function arguments (specifically, those that are freeze and are observed not to be mutated), but it currently is not. This patch introduces the machinery that allows `rustc` to determine those attributes. It consists of a query, `deduced_param_attrs`, that, when evaluated, analyzes the MIR of the function to determine supplementary attributes. The results of this query for each function are written into the crate metadata so that the deduced parameter attributes can be applied to cross-crate functions. In this patch, we simply check the parameter for mutations to determine whether the `readonly` attribute should be applied to parameters that are indirect immutable freeze by-value. More attributes could conceivably be deduced in the future: `nocapture` and `noalias` come to mind. Adding `readonly` to indirect function parameters where applicable enables some potential optimizations in LLVM that are discussed in [issue 103103] and [PR 103070] around avoiding stack-to-stack memory copies that appear in functions like `core::fmt::Write::write_fmt` and `core::panicking::assert_failed`. These functions pass a large structure unchanged by value to a subfunction that also doesn't mutate it. Since the structure in this case is passed as an indirect parameter, it's a pointer from LLVM's perspective. As a result, the intermediate copy of the structure that our codegen emits could be optimized away by LLVM's MemCpyOptimizer if it knew that the pointer is `readonly nocapture noalias` in both the caller and callee. We already pass `nocapture noalias`, but we're missing `readonly`, as we can't determine whether a by-value parameter is mutated by examining the signature in Rust. I didn't have much success with having LLVM infer the `readonly` attribute, even with fat LTO; it seems that deducing it at the MIR level is necessary. No large benefits should be expected from this optimization *now*; LLVM needs some changes (discussed in [PR 103070]) to more aggressively use the `noalias nocapture readonly` combination in its alias analysis. I have some LLVM patches for these optimizations and have had them looked over. With all the patches applied locally, I enabled LLVM to remove all the `memcpy`s from the following code: ```rust fn main() { println!("Hello {}", 3); } ``` which is a significant codegen improvement over the status quo. I expect that if this optimization kicks in in multiple places even for such a simple program, then it will apply to Rust code all over the place. [issue 103103]: https://github.com/rust-lang/rust/issues/103103 [PR 103070]: https://github.com/rust-lang/rust/pull/103070
2022-10-08Rollup merge of #102778 - nbdd0121:mir, r=tmiaskoMatthias Krüger-25/+19
Fix MIR inlining of asm_unwind The MIR inlining currently doesn't handle inline asm's unwind edge correctly. This code will cause ICE: ```rust struct D; impl Drop for D { fn drop(&mut self) {} } #[inline(always)] fn foo() { let _d = D; unsafe { std::arch::asm!("", options(may_unwind)) }; } pub fn main() { foo(); } ``` This PR fixes this issue. I also take the opportunity to extract common code into a method.
2022-10-07make const_err a hard errorRalf Jung-26/+9