summary refs log tree commit diff
path: root/src/librustc_codegen_ssa/mir
AgeCommit message (Collapse)AuthorLines
2020-06-01Auto merge of #71192 - oli-obk:eager_alloc_id_canonicalization, r=wesleywiserbors-0/+8
Make TLS accesses explicit in MIR r? @rust-lang/wg-mir-opt cc @RalfJung @vakaras for miri thread locals cc @bjorn3 for cranelift fixes #70685
2020-05-30Rollup merge of #72625 - Amanieu:asm-srcloc, r=petrochenkovRalf Jung-2/+10
Improve inline asm error diagnostics Previously we were just using the raw LLVM error output (with line, caret, etc) as the diagnostic message, which ends up looking rather out of place with our existing diagnostics. The new diagnostics properly format the diagnostics and also take advantage of LLVM's per-line `srcloc` attribute to map an error in inline assembly directly to the relevant line of source code. Incidentally also fixes #71639 by disabling `srcloc` metadata during LTO builds since we don't know what crate it might have come from. We can only resolve `srcloc`s from the currently crate since it indexes into the source map for the current crate. Fixes #72664 Fixes #71639 r? @petrochenkov ### Old style ```rust #![feature(llvm_asm)] fn main() { unsafe { let _x: i32; llvm_asm!( "mov $0, $1 invalid_instruction $0, $1 mov $0, $1" : "=&r" (_x) : "r" (0) :: "intel" ); } } ``` ``` error: <inline asm>:3:14: error: invalid instruction mnemonic 'invalid_instruction' invalid_instruction ecx, eax ^~~~~~~~~~~~~~~~~~~ --> src/main.rs:6:9 | 6 | / llvm_asm!( 7 | | "mov $0, $1 8 | | invalid_instruction $0, $1 9 | | mov $0, $1" ... | 12 | | :: "intel" 13 | | ); | |__________^ ``` ### New style ```rust #![feature(asm)] fn main() { unsafe { asm!( "mov {0}, {1} invalid_instruction {0}, {1} mov {0}, {1}", out(reg) _, in(reg) 0i64, ); } } ``` ``` error: invalid instruction mnemonic 'invalid_instruction' --> test.rs:7:14 | 7 | invalid_instruction {0}, {1} | ^ | note: instantiated into assembly here --> <inline asm>:3:14 | 3 | invalid_instruction rax, rcx | ^^^^^^^^^^^^^^^^^^^ ```
2020-05-30Rollup merge of #72521 - Amanieu:fix-72484, r=petrochenkovRalf Jung-2/+1
Properly handle InlineAsmOperand::SymFn when collecting monomorphized items Fixes #72484
2020-05-30Make TLS accesses explicit in MIROliver Scherer-0/+8
2020-05-29Improve inline asm error diagnosticsAmanieu d'Antras-2/+10
2020-05-28Auto merge of #72494 - lcnr:predicate-cleanup, r=nikomatsakisbors-9/+9
Pass more `Copy` types by value. There are a lot of locations where we pass `&T where T: Copy` by reference, which should both be slightly less performant and less readable IMO. This PR currently consists of three fairly self contained commits: - passes `ty::Predicate` by value and stops depending on `AsRef<ty::Predicate>`. - changes `<&List<_>>::into_iter` to iterate over the elements by value. This would break `List`s of non copy types. But as the only list constructor requires `T` to be copy anyways, I think the improved readability is worth this potential future restriction. - passes `mir::PlaceElem` by value. Mir currently has quite a few copy types which are passed by reference, e.g. `Local`. As I don't have a lot of experience working with MIR, I mostly did this to get some feedback from people who use MIR more frequently - tries to reuse `ty::Predicate` in case it did not change in some places, which should hopefully fix the regression caused by #72055 r? @nikomatsakis for the first commit, which continues the work of #72055 and makes adding `PredicateKind::ForAll` slightly more pleasant. Feel free to reassign though
2020-05-24Removed all instances of const_field.Rakshith Ravi-10/+6
2020-05-24Properly handle InlineAsmOperand::SymFn when collecting monomorphized itemsAmanieu d'Antras-2/+1
Fixes #72484
2020-05-23take mir::PlaceElem by valueBastian Kauschke-9/+9
2020-05-21Auto merge of #72205 - ecstatic-morse:nrvo, r=oli-obkbors-1/+2
Dumb NRVO This is a very simple version of an NRVO pass, which scans backwards from the `return` terminator to see if there is an an assignment like `_0 = _1`. If a basic block with two or more predecessors is encountered during this scan without first seeing an assignment to the return place, we bail out. This avoids running a full "reaching definitions" dataflow analysis. I wanted to see how much `rustc` would benefit from even a very limited version of this optimization. We should be able to use this as a point of comparison for more advanced versions that are based on live ranges. r? @ghost
2020-05-18Fix const handling and add tests for const operandsAmanieu d'Antras-91/+128
2020-05-18Minor fixesAmanieu d'Antras-1/+2
2020-05-18Implement asm! codegenAmanieu d'Antras-1/+95
2020-05-16Name return place in debuginfo if it is a user variableDylan MacKenzie-1/+2
2020-05-08Simplify the `tcx.alloc_map` APIOliver Scherer-1/+1
2020-05-06Define UB in float-to-int casts to saturateMark Rousskov-1/+1
- Round to zero, and representable values cast directly. - `NaN` goes to 0 - Values beyond the limits of the type are saturated to the "nearest value" (essentially rounding to zero, in some sense) in the integral type, so e.g. `f32::INFINITY` would go to `{u,i}N::MAX.`
2020-05-03Add `MutatingUseContext::Yield`Dylan MacKenzie-1/+2
...emulating `MutatingUseContext::Call`
2020-05-01Remove deadcode in eval_mir_constant_to_operandSantiago Pastorino-19/+3
2020-04-26Rollup merge of #71392 - ecstatic-morse:body-predecessor-cache-arc, ↵Dylan DPC-1/+1
r=nikomatsakis Don't hold the predecessor cache lock longer than necessary #71044 returns a `LockGuard` with the predecessor cache to callers of `Body::predecessors`. As a result, the lock around the predecessor cache could be held for an arbitrarily long time. This PR uses reference counting for ownership of the predecessor cache, meaning the lock is only ever held within `PredecessorCache::compute`. Checking this API for potential sources of deadlock is much easier now, since we no longer have to consider its consumers, only its internals. This required removing `predecessors_for`, since there is no equivalent to `LockGuard::map` for `Arc` and `Rc`. I believe this could be emulated with `owning_ref::{Arc,Rc}Ref`, but I don't think it's necessary. Also, we continue to return an opaque type from `Body::predecessors` with the lifetime of the `Body`, not `'static`. This depends on #71044. Only the last two commits are new. r? @nikomatsakis
2020-04-23Rename uneval_consts to required_constsSantiago Pastorino-1/+1
2020-04-23Evaluate unevaluated MIR constants in codegen_mirSantiago Pastorino-0/+14
2020-04-22Remove `predecessors_for`Dylan MacKenzie-1/+1
There is no `Arc::map` equivalent to `LockGuard::map`
2020-04-22Auto merge of #71044 - ecstatic-morse:body-predecessor-cache, r=oli-obkbors-15/+14
Remove `BodyAndCache` ...returning to the original approach using interior mutability within `Body`. This simplifies the API at the cost of some uncontended mutex locks when the parallel compiler is enabled. The current API requires you to either have a mutable reference to `Body` (`&mut BodyAndCache`), or to compute the predecessor graph ahead of time by creating a `ReadOnlyBodyAndCache`. This is not a good fit for, e.g., the dataflow framework, which 1. does not mutate the MIR 2. only sometimes needs the predecessor graph (for backward dataflow problems)
2020-04-22Use `Body` everywhereDylan MacKenzie-8/+7
2020-04-22Don't use `*` for deref-coercionDylan MacKenzie-7/+7
2020-04-22Rollup merge of #71401 - spastorino:remove-visit-place-base, r=wesleywiserDylan DPC-1/+1
visit_place_base is just visit_local r? @wesleywiser
2020-04-22Rollup merge of #70970 - eddyb:trait-vs-impl-mismatch, r=oli-obkDylan DPC-0/+1
Detect mistyped associated consts in `Instance::resolve`. *Based on #71049 to prevent redundant/misleading downstream errors.* Fixes #70942 by refusing to resolve an associated `const` if it doesn't have the same type in the `impl` that it does in the `trait` (which we assume had errored, and `delay_span_bug` guards against bugs).
2020-04-21visit_place_base is just visit_localSantiago Pastorino-1/+1
2020-04-19Dogfood more or_patterns in the compilerJosh Stone-20/+27
2020-04-18Detect mistyped associated consts in `Instance::resolve`.Eduard-Mihai Burtescu-0/+1
2020-04-17Rollup merge of #70467 - wesleywiser:invoke-vs-call, r=nagisaDylan DPC-1/+3
Use `call` instead of `invoke` for functions that cannot unwind The `FnAbi` now knows if the function is allowed to unwind. If a function isn't allowed to unwind, we can use a `call` instead of an `invoke`. This resolves an issue when calling LLVM intrinsics which cannot unwind LLVM will generate an error if you attempt to invoke them so we need to ignore cleanup blocks in codegen and generate a call instead. Fixes #69911 r? @eddyb cc @rust-lang/wg-ffi-unwind
2020-04-16mir/interpret: only use `ErrorHandled::Reported` for `ErrorReported`.Eduard-Mihai Burtescu-2/+5
2020-04-15Use `call` instead of `invoke` for functions that cannot unwindWesley Wiser-1/+3
The `FnAbi` now knows if the function is allowed to unwind. If a function isn't allowed to unwind, we can use a `call` instead of an `invoke`. This resolves an issue when calling LLVM intrinsics which cannot unwind LLVM will generate an error if you attempt to invoke them so we need to ignore cleanup blocks in codegen and generate a call instead.
2020-04-05Stop importing int/float modules in librustc_*Linus Färnstrand-2/+0
2020-04-02direct imports for langitem stuffMazdak Farrokhzad-2/+2
2020-04-02nix rustc_target::abi::* reexport in ty::layoutMazdak Farrokhzad-40/+38
2020-04-01Rollup merge of #70616 - anyska:fieldplacement-rename, r=oli-obkDylan DPC-1/+1
rustc_target::abi: rename FieldPlacement to FieldsShape. Originally suggested by @eddyb.
2020-03-31Use Place directly in codegen_place_to_pointer, it's CopySantiago Pastorino-3/+3
2020-03-31Use Place directly in evaluate_array_len, it's CopySantiago Pastorino-2/+2
2020-03-31Use Place directly in codegen_transmute, it's CopySantiago Pastorino-2/+2
2020-03-31Use Place directly on make_return_dest, it's CopySantiago Pastorino-2/+2
2020-03-31Use Place directly on codegen_drop_terminator, it's CopySantiago Pastorino-2/+2
2020-03-31rustc_target::abi: rename FieldPlacement to FieldsShape.Ana-Maria Mihalache-1/+1
2020-03-30rustc -> rustc_middle part 3 (rustfmt)Mazdak Farrokhzad-9/+9
2020-03-30rustc -> rustc_middle part 2Mazdak Farrokhzad-35/+35
2020-03-30Auto merge of #70449 - ecstatic-morse:visit-body, r=oli-obkbors-1/+1
Make `Visitor::visit_body` take a plain `&Body` `ReadOnlyBodyAndCache` has replaced `&Body` in many parts of the code base that don't care about basic block predecessors. This includes the MIR `Visitor` trait, which I suspect resulted in many unnecessary changes in #64736. This reverts part of that PR to reduce the number of places where we need to pass a `ReadOnlyBodyAndCache`. In the long term, we should either give `ReadOnlyBodyAndCache` more ergonomic name and replace all uses of `&mir::Body` with it at the cost of carrying an extra pointer everywhere, or use it only in places that actually need access to the predecessor cache. Perhaps there is an even nicer alternative. r? @Nashenas88
2020-03-29Use `&` to do deref coercion for `ReadOnlyBodyAndCache`Dylan MacKenzie-1/+1
2020-03-29Make `Visitor::visit_body` take a simple `Body`Dylan MacKenzie-1/+1
2020-03-27Rename TyLayout to TyAndLayout.Ana-Maria Mihalache-12/+16
2020-03-26Rename asm! to llvm_asm!Amanieu d'Antras-2/+2
asm! is left as a wrapper around llvm_asm! to maintain compatibility.