about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src/mir
AgeCommit message (Collapse)AuthorLines
2021-02-23Rollup merge of #82091 - henryboisdequin:use-place-ref-more, r=RalfJungDylan DPC-1/+1
use PlaceRef abstractions more consistently Addresses this [comment](https://github.com/rust-lang/rust/pull/80865/files#r558978715) Associated issue: #80647 r? ```@RalfJung```
2021-02-17Rollup merge of #81898 - ↵Dylan DPC-5/+25
nanguye2496:nanguye2496/fix_str_and_slice_visualization, r=varkor Fix debug information for function arguments of type &str or slice. Issue details: When lowering MIR to LLVM IR, the compiler decomposes every &str and slice argument into a data pointer and a usize. Then, the original argument is reconstructed from the pointer and the usize arguments in the body of the function that owns it. Since the original argument is declared in the body of a function, it should be marked as a LocalVariable instead of an ArgumentVairable. This confusion causes MSVC debuggers unable to visualize &str and slice arguments correctly. (See https://github.com/rust-lang/rust/issues/81894 for more details). Fix details: Making sure that the debug variable for every &str and slice argument is marked as LocalVariable instead of ArgumentVariable in computing_per_local_var_debug_info. This change has been verified on VS Code debugger, VS debugger, WinDbg and LLDB.
2021-02-16make `visit_projection` take a `PlaceRef`Henry Boisdequin-1/+1
2021-02-16avoid full-slicing slicesMatthias Krüger-1/+1
If we already have a slice, there is no need to get another full-range slice from that, just use the original. clippy::redundant_slicing
2021-02-09Set the kind for local variables created by &str and slice arguments to ↵Nam Nguyen-5/+25
LocalVariable
2021-01-31Auto merge of #81327 - RalfJung:codegen-no-const-fail, r=oli-obkbors-21/+12
codegen: assume constants cannot fail to evaluate https://github.com/rust-lang/rust/pull/80579 landed, so we can finally remove this old hack from codegen and instead assume that consts never fail to evaluate. :) r? `@oli-obk`
2021-01-30codegen: assume constants cannot fail to evaluateRalf Jung-21/+12
also don't submit code to LLVM when the session has errors
2021-01-29Rollup merge of #81333 - RalfJung:const-err-simplify, r=oli-obkYuki Okushi-6/+1
clean up some const error reporting around promoteds These are some error reporting simplifications enabled by https://github.com/rust-lang/rust/pull/80579. Further simplifications are possible but could be blocked on making `const_err` a hard error. r? ``````@oli-obk``````
2021-01-28Rollup merge of #79951 - LeSeulArtichaut:ty-ir, r=nikomatsakisYuki Okushi-12/+8
Refractor a few more types to `rustc_type_ir` In the continuation of #79169, ~~blocked on that PR~~. This PR: - moves `IntVarValue`, `FloatVarValue`, `InferTy` (and friends) and `Variance` - creates the `IntTy`, `UintTy` and `FloatTy` enums in `rustc_type_ir`, based on their `ast` and `chalk_ir` equilavents, and uses them for types in the rest of the compiler. ~~I will split up that commit to make this easier to review and to have a better commit history.~~ EDIT: done, I split the PR in commits of 200-ish lines each r? `````@nikomatsakis````` cc `````@jackh726`````
2021-01-24clean up some const error reporting around promotedsRalf Jung-6/+1
2021-01-18Use ty::{IntTy,UintTy,FloatTy} in rustcLeSeulArtichaut-12/+8
2021-01-16PlaceRef::ty: use method call syntaxRalf Jung-2/+2
2021-01-07Auto merge of #80200 - mahkoh:dst-offset, r=nagisabors-10/+44
Optimize DST field access For struct X<T: ?Sized>(T) struct Y<T: ?Sized>(u8, T) the offset of the unsized field is 0 mem::align_of_val(&self.1) respectively. This patch changes the expression used to compute these offsets so that the optimizer can perform this optimization. Consider ```rust fn f(x: &X<dyn Any>) -> &dyn Any { &x.0 } ``` Before: ```asm test: movq %rsi, %rdx movq 16(%rsi), %rax leaq -1(%rax), %rcx negq %rax andq %rcx, %rax addq %rdi, %rax retq ``` After: ```asm test: movq %rsi, %rdx movq %rdi, %rax retq ```
2021-01-03use PlaceRef more consistently instead of loosely coupled local+projectionRalf Jung-9/+4
2020-12-30Rollup merge of #80495 - jyn514:rename-empty, r=petrochenkovMara Bos-2/+2
Rename kw::Invalid -> kw::Empty See https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F/near/220054471 for context. r? `@petrochenkov`
2020-12-30Rename kw::Invalid -> kw::EmptyJoshua Nelson-2/+2
See https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Is.20there.20a.20symbol.20for.20the.20empty.20string.3F/near/220054471 for context.
2020-12-30where possible, pass slices instead of &Vec or &String (clippy::ptr_arg)Matthias Krüger-1/+1
2020-12-24use matches!() macro in more placesMatthias Krüger-4/+4
2020-12-20Use pointer type in AtomicPtr::swap implementationTomasz Miąsko-2/+13
2020-12-19Optimize DST field accessJulian Orth-10/+44
For struct X<T: ?Sized>(T) struct Y<T: ?Sized>(u8, T) the offset of the unsized field is 0 mem::align_of_val(&self.1) respectively. This patch changes the expression used to compute these offsets so that the optimizer can perform this optimization. Consider ```rust fn test(x: &X<dyn Any>) -> &dyn Any { &x.0 } ``` Before: ```asm test: movq %rsi, %rdx movq 16(%rsi), %rax leaq -1(%rax), %rcx negq %rax andq %rcx, %rax addq %rdi, %rax retq ``` After: ```asm test: movq %rsi, %rdx movq %rdi, %rax retq ```
2020-12-15Always run intrinsics lowering passTomasz Miąsko-15/+1
Move intrinsics lowering pass from the optimization phase (where it would not run if -Zmir-opt-level=0), to the drop lowering phase where it runs unconditionally. The implementation of those intrinsics in code generation and interpreter is unnecessary. Remove it.
2020-12-15Auto merge of #73210 - wesleywiser:consts_in_debuginfo, r=oli-obkbors-35/+76
[mir-opt] Allow debuginfo to be generated for a constant or a Place Prior to this commit, debuginfo was always generated by mapping a name to a Place. This has the side-effect that `SimplifyLocals` cannot remove locals that are only used for debuginfo because their other uses have been const-propagated. To allow these locals to be removed, we now allow debuginfo to point to a constant value. The `ConstProp` pass detects when debuginfo points to a local with a known constant value and replaces it with the value. This allows the later `SimplifyLocals` pass to remove the local.
2020-12-11Lower `discriminant_value` intrinsicTomasz Miąsko-0/+1
This allows const propagation to evaluate comparisons involving field-less enums using derived implementations of `PartialEq` (after inlining `eq`).
2020-12-10Auto merge of #79801 - eddyb:scalar-transmute, r=nagisabors-0/+19
rustc_codegen_ssa: use bitcasts instead of type punning for scalar transmutes. This specifically helps with `f32` <-> `u32` (`from_bits`, `to_bits`) in Rust-GPU (`rustc_codegen_spirv`), where (AFAIK) we don't yet have enough infrastructure to turn type punning memory accesses into SSA bitcasts. (There may be more instances, but the one I've seen myself is `f32::signum` from `num-traits` inspecting e.g. the sign bit) Sadly I've had to make an exception for `transmute`s between pointers and non-pointers, as LLVM disallows using `bitcast` for them. r? `@nagisa` cc `@khyperia`
2020-12-07rustc_codegen_ssa: use bitcasts instead of type punning for scalar transmutes.Eduard-Mihai Burtescu-0/+19
2020-12-06[mir-opt] Allow debuginfo to be generated for a constant or a PlaceWesley Wiser-35/+76
Prior to this commit, debuginfo was always generated by mapping a name to a Place. This has the side-effect that `SimplifyLocals` cannot remove locals that are only used for debuginfo because their other uses have been const-propagated. To allow these locals to be removed, we now allow debuginfo to point to a constant value. The `ConstProp` pass detects when debuginfo points to a local with a known constant value and replaces it with the value. This allows the later `SimplifyLocals` pass to remove the local.
2020-11-29Cast pointers to usize before passing them to atomic operations as some ↵oli-11/+38
platforms do not support atomic operations on pointers.
2020-11-28Directly use raw pointers in `AtomicPtr` store/loadoli-3/+3
2020-11-26Fix new 'unnecessary trailing semicolon' warningsAaron Hill-1/+1
2020-11-22Use Option::and_then instead of open-coding itLingMan-5/+2
2020-11-21Replace ByVal attribute with on_stack field for Indirectbjorn3-2/+2
This makes it clearer that only PassMode::Indirect allows ByVal
2020-11-16compiler: fold by valueBastian Kauschke-25/+25
2020-11-09Rollup merge of #78844 - tmiasko:monomorphize-sizeof, r=oli-obkDylan DPC-0/+1
Monomorphize a type argument of size-of operation during codegen This wasn't necessary until MIR inliner started to consider drop glue as a candidate for inlining; introducing for the first time a generic use of size-of operation. No test at this point since this only happens with a custom inlining threshold.
2020-11-09Rollup merge of #78674 - tmiasko:inline-substs-for-mir-body, r=oli-obkDylan DPC-9/+5
inliner: Use substs_for_mir_body Changes from 68965 extended the kind of instances that are being inlined. For some of those, the `instance_mir` returns a MIR body that is already expressed in terms of the types found in substitution array, and doesn't need further substitution. Use `substs_for_mir_body` to take that into account. Resolves #78529. Resolves #78560.
2020-11-07Monomorphize a type argument of size-of operation during codegenTomasz Miąsko-0/+1
This wasn't necessary until MIR inliner started to consider drop glue as a candidate for inlining; introducing for the first time a generic use of size-of operation. No test at this point since this only happens with a custom inlining threshold.
2020-11-05Addressed all feedback to dateRich Kadel-8/+9
2020-11-05Injecting expressions in place of counters where helpfulRich Kadel-2/+2
Implementing the Graph traits for the BasicCoverageBlock graph. optimized replacement of counters with expressions plus new BCB graphviz * Avoid adding coverage to unreachable blocks. * Special case for Goto at the end of the body. Make it non-reportable. Improved debugging and formatting options (from env) Don't automatically add counters to BCBs without CoverageSpans. They may still get counters but only if there are dependencies from other BCBs that have spans, I think. Make CodeRegions optional for Counters too. It is possible to inject counters (`llvm.instrprof.increment` intrinsic calls without corresponding code regions in the coverage map. An expression can still uses these counter values. Refactored instrument_coverage.rs -> instrument_coverage/mod.rs, and then broke up the mod into multiple files. Compiling with coverage, with the expression optimization, works on the json5format crate and its dependencies. Refactored debug features from mod.rs to debug.rs
2020-11-05Rust coverage before splitting instrument_coverage.rsRich Kadel-4/+15
2020-11-06inliner: Use substs_for_mir_bodyTomasz Miąsko-9/+5
Changes from 68965 extended the kind of instances that are being inlined. For some of those, the `instance_mir` returns a MIR body that is already expressed in terms of the types found in substitution array, and doesn't need further substitution. Use `substs_for_mir_body` to take that into account.
2020-10-26Auto merge of #68965 - eddyb:mir-inline-scope, r=nagisa,oli-obkbors-108/+136
rustc_mir: track inlined callees in SourceScopeData. We now record which MIR scopes are the roots of *other* (inlined) functions's scope trees, which allows us to generate the correct debuginfo in codegen, similar to what LLVM inlining generates. This PR makes the `ui` test `backtrace-debuginfo` pass, if the MIR inliner is turned on by default. Also, `#[track_caller]` is now correct in the face of MIR inlining (cc `@anp).` Fixes #76997. r? `@rust-lang/wg-mir-opt`
2020-10-26Deduplicate span and dbg_scope adjustmentoli-18/+19
2020-10-26Prefer `bug!` over `unwrap()`oli-1/+3
2020-10-23Make codegen coverage_context optional, and checkRich Kadel-12/+12
Addresses Issue #78286 Libraries compiled with coverage and linked with out enabling coverage would fail when attempting to add the library's coverage statements to the codegen coverage context (None). Now, if coverage statements are encountered while compiling / linking with `-Z instrument-coverage` disabled, codegen will *not* attempt to add code regions to a coverage map, and it will not inject the LLVM instrprof_increment intrinsic calls.
2020-10-21rustc_codegen_llvm: add support for inlined function debuginfo.Eduard-Mihai Burtescu-34/+63
2020-10-21rustc_codegen_llvm: expose DILocation to rustc_codegen_ssa.Eduard-Mihai Burtescu-69/+49
2020-10-21rustc_codegen_llvm: create `DIFile`s from just `SourceFile`s.Eduard-Mihai Burtescu-26/+5
2020-10-21rustc_mir: support MIR-inlining #[track_caller] functions.Eduard-Mihai Burtescu-14/+51
2020-10-16Auto merge of #77972 - Mark-Simulacrum:side-effect-loop, r=nagisabors-3/+19
Prevent miscompilation in trivial loop {} Ideally, we would want to handle a broader set of cases to fully fix the underlying bug here. That is currently relatively expensive at compile and runtime, so we don't do that for now. Performance results indicate this is not a major regression, if at all, so it should be safe to land. cc #28728
2020-10-15Prevent miscompilation in trivial loop {}Mark Rousskov-3/+19
Ideally, we would want to handle a broader set of cases to fully fix the underlying bug here. That is currently relatively expensive at compile and runtime, so we don't do that for now.
2020-10-15Replace target.target with target and target.ptr_width with target.pointer_widthest31-5/+9
Preparation for a subsequent change that replaces rustc_target::config::Config with its wrapped Target. On its own, this commit breaks the build. I don't like making build-breaking commits, but in this instance I believe that it makes review easier, as the "real" changes of this PR can be seen much more easily. Result of running: find compiler/ -type f -exec sed -i -e 's/target\.target\([)\.,; ]\)/target\1/g' {} \; find compiler/ -type f -exec sed -i -e 's/target\.target$/target/g' {} \; find compiler/ -type f -exec sed -i -e 's/target.ptr_width/target.pointer_width/g' {} \; ./x.py fmt