about summary refs log tree commit diff
path: root/src/librustc_codegen_ssa/mir/rvalue.rs
AgeCommit message (Collapse)AuthorLines
2020-08-30mv compiler to compiler/mark-1006/+0
2020-08-24hir: consistent use and naming of lang itemsDavid Wood-2/+2
This commit adjusts the naming of various lang items so that they are consistent and don't include prefixes containing the target or "LangItem". In addition, lang item variants are no longer exported from the `lang_items` module. Signed-off-by: David Wood <david@davidtw.co>
2020-07-28rustc: Improving safe wasm float->int castsAlex Crichton-33/+134
This commit improves code generation for WebAssembly targets when translating floating to integer casts. This improvement is only relevant when the `nontrapping-fptoint` feature is not enabled, but the feature is not enabled by default right now. Additionally this improvement only affects safe casts since unchecked casts were improved in #74659. Some more background for this issue is present on #73591, but the general gist of the issue is that in LLVM the `fptosi` and `fptoui` instructions are defined to return an `undef` value if they execute on out-of-bounds values; they notably do not trap. To implement these instructions for WebAssembly the LLVM backend must therefore generate quite a few instructions before executing `i32.trunc_f32_s` (for example) because this WebAssembly instruction traps on out-of-bounds values. This codegen into wasm instructions happens very late in the code generator, so what ends up happening is that rustc inserts its own codegen to implement Rust's saturating semantics, and then LLVM also inserts its own codegen to make sure that the `fptosi` instruction doesn't trap. Overall this means that a function like this: #[no_mangle] pub unsafe extern "C" fn cast(x: f64) -> u32 { x as u32 } will generate this WebAssembly today: (func $cast (type 0) (param f64) (result i32) (local i32 i32) local.get 0 f64.const 0x1.fffffffep+31 (;=4.29497e+09;) f64.gt local.set 1 block ;; label = @1 block ;; label = @2 local.get 0 f64.const 0x0p+0 (;=0;) local.get 0 f64.const 0x0p+0 (;=0;) f64.gt select local.tee 0 f64.const 0x1p+32 (;=4.29497e+09;) f64.lt local.get 0 f64.const 0x0p+0 (;=0;) f64.ge i32.and i32.eqz br_if 0 (;@2;) local.get 0 i32.trunc_f64_u local.set 2 br 1 (;@1;) end i32.const 0 local.set 2 end i32.const -1 local.get 2 local.get 1 select) This PR improves the situation by updating the code generation for float-to-int conversions in rustc, specifically only for WebAssembly targets and only for some situations (float-to-u8 still has not great codegen). The fix here is to use basic blocks and control flow to avoid speculatively executing `fptosi`, and instead LLVM's raw intrinsic for the WebAssembly instruction is used instead. This effectively extends the support added in #74659 to checked casts. After this commit the codegen for the above Rust function looks like: (func $cast (type 0) (param f64) (result i32) (local i32) block ;; label = @1 local.get 0 f64.const 0x0p+0 (;=0;) f64.ge local.tee 1 i32.const 1 i32.xor br_if 0 (;@1;) local.get 0 f64.const 0x1.fffffffep+31 (;=4.29497e+09;) f64.le i32.eqz br_if 0 (;@1;) local.get 0 i32.trunc_f64_u return end i32.const -1 i32.const 0 local.get 1 select) For reference, in Rust 1.44, which did not have saturating float-to-integer casts, the codegen LLVM would emit is: (func $cast (type 0) (param f64) (result i32) block ;; label = @1 local.get 0 f64.const 0x1p+32 (;=4.29497e+09;) f64.lt local.get 0 f64.const 0x0p+0 (;=0;) f64.ge i32.and i32.eqz br_if 0 (;@1;) local.get 0 i32.trunc_f64_u return end i32.const 0) So we're relatively close to the original codegen, although it's slightly different because the semantics of the function changed where we're emulating the `i32.trunc_sat_f32_s` instruction rather than always replacing out-of-bounds values with zero. There is still work that could be done to improve casts such as `f32` to `u8`. That form of cast still uses the `fptosi` instruction which generates lots of branch-y code. This seems less important to tackle now though. In the meantime this should take care of most use cases of floating-point conversion and as a result I'm going to speculate that this... Closes #73591
2020-07-20mir: `unused_generic_params` queryDavid Wood-11/+10
This commit implements the `unused_generic_params` query, an initial version of polymorphization which detects when an item does not use generic parameters and is being needlessly monomorphized as a result. Signed-off-by: David Wood <david@davidtw.co>
2020-07-02Use WASM's saturating casts if they are availableChristopher Serr-3/+8
WebAssembly supports saturating floating point to integer casts behind a target feature. The feature is already available on many browsers. Beginning with 1.45 Rust will start defining the behavior of floating point to integer casts to be saturating as well. For this Rust constructs additional checks on top of the `fptoui` / `fptosi` instructions it emits. Here we introduce the possibility for the codegen backend to construct saturating casts itself and only fall back to constructing the checks ourselves if that is not possible.
2020-05-30Make TLS accesses explicit in MIROliver Scherer-0/+8
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-04-22Don't use `*` for deref-coercionDylan MacKenzie-3/+3
2020-04-19Dogfood more or_patterns in the compilerJosh Stone-4/+5
2020-04-05Stop importing int/float modules in librustc_*Linus Färnstrand-2/+0
2020-04-02direct imports for langitem stuffMazdak Farrokhzad-1/+1
2020-04-02nix rustc_target::abi::* reexport in ty::layoutMazdak Farrokhzad-5/+6
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-30rustc -> rustc_middle part 3 (rustfmt)Mazdak Farrokhzad-1/+1
2020-03-30rustc -> rustc_middle part 2Mazdak Farrokhzad-5/+5
2020-03-23Evaluate repeat expression lengths as late as possibleOliver Scherer-0/+3
2020-03-21Fix ICE caused by truncating a negative ZST enum discriminantWesley Wiser-1/+6
2020-02-27don't use .into() to convert types into identical types.Matthias Krüger-1/+1
example: let s: String = format!("hello").into();
2020-01-28codegen_place and related functions can take PlaceRef by valueSantiago Pastorino-3/+3
2020-01-02Normalize `syntax::symbol` imports.Mazdak Farrokhzad-1/+1
2020-01-02Normalize `syntax::source_map` imports.Mazdak Farrokhzad-1/+1
2019-12-22Format the worldMark Rousskov-217/+211
2019-12-20Rollup merge of #64588 - matthewjasper:mir-address-of, r=oli-obkMazdak Farrokhzad-20/+38
Add a raw "address of" operator * Parse and feature gate `&raw [const | mut] expr` (feature gate name is `raw_address_of`) * Add `mir::Rvalue::AddressOf` * Use the new `Rvalue` for: * the new syntax * reference to pointer casts * drop shims for slices and arrays * Stop using `mir::Rvalue::Cast` with a reference as the operand * Correctly evaluate `mir::Rvalue::{Ref, AddressOf}` in constant propagation cc @Centril @RalfJung @oli-obk @eddyb cc #64490
2019-12-18Add Rvalue::AddressOf to MIRMatthew Jasper-20/+38
This operator creates a raw pointer to a Place directly, without first creating a reference. See RFC #2582 for motivation. The Rvalue is currently unused.
2019-12-15Remove now-redundant range check on u128 -> f32 castsRobin Kruppe-36/+7
This code was added to avoid UB in LLVM 6 and earlier, but we no longer support those LLVM versions. Since https://reviews.llvm.org/D47807 (released in LLVM 7), uitofp does exactly what we need. Closes #51872
2019-12-03rustc: expose the mir::Body reference lifetime from mir::ReadOnlyBodyCache ↵Eduard-Mihai Burtescu-3/+3
(#64736 fallout).
2019-12-02Remove HasLocalDecls impl from BodyCache's, properly reborrow to Body, ↵Paul Daniel Faria-3/+3
rename all body_cache back to body
2019-12-02Remove BodyCache.body and rely on Deref as much as possible for ↵Paul Daniel Faria-3/+3
ReadOnlyBodyCache
2019-12-02Undo minor changes that weren't needed, fix one lifetime typoPaul Daniel Faria-5/+1
2019-12-02Simplify BodyCache impl and fix all remaining type errors in librustc_mir ↵Paul Daniel Faria-2/+2
(lifetime errors still exist)
2019-12-02Account for new maybe_sideeffect helper that requires predecessorsPaul Daniel Faria-3/+3
2019-12-02Revert back to using FunctionCx's BodyPaul Daniel Faria-29/+24
2019-12-02Add Body back as field of FunctionCx, but under a different lifetimePaul Daniel Faria-2/+2
2019-12-02Remove Body from FunctionCx, pass it along during librustc_codegen_ssaPaul Daniel Faria-25/+34
2019-12-02Simplify Cache wrapper to single type, impl Deref on it, fix all compilation ↵Paul Daniel Faria-3/+3
errors in librustc_codegen_ssa
2019-11-21Aggregation of drive-by cosmetic changes.Alexander Regueiro-28/+27
2019-10-25Don't cast directly from `&[T; N]` to `*const T`Matthew Jasper-0/+1
Instead coerce to `*const [T; N]` and then cast.
2019-10-22Pattern match over PlaceRef rather than PlaceSantiago Pastorino-4/+1
This prepares the code base for when projection is interned. Place's projection field is going to be `&List<PlaceElem<'tcx>>` so we won't be able to pattern match against it.
2019-10-19Remove unreachable unit tuple compare binop codegenCaleb Behunin-8/+1
2019-10-13Remove MiscMethods::instancesbjorn3-3/+3
2019-10-13Inline functions from cg_ssa::callee and remove the modbjorn3-2/+9
Fixes #65271
2019-10-13Remove is_const_integral method from ConstMethodsbjorn3-1/+1
2019-10-09Reifying callers of Instance::resolve use resolve_for_fn_ptr.Adam Perry-1/+1
2019-10-03generate ClosureSubsts from SubstsRefcsmoe-2/+3
2019-09-29remove ClosureSubsts with SubstsRefcsmoe-1/+3
2019-09-25Rename `sty` to `kind`varkor-3/+3
2019-09-14Rollup merge of #64435 - eddyb:arguments-against-arg, r=rkruppeMazdak Farrokhzad-1/+1
codegen: use "_N" (like for other locals) instead of "argN", for argument names. Based on #64408 (second commit is new), fixing something I mentioned in #64408 (which turned to be an immediate blocker for unifying relevant codepaths). Closes #64408 (by containing it). r? @rkruppe
2019-09-12codegen: be more explicit about setting giving names to allocas.Eduard-Mihai Burtescu-1/+1
2019-09-09Convert Place's projection to a boxed sliceSantiago Pastorino-1/+1