summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src/mir
AgeCommit message (Collapse)AuthorLines
2022-06-15fix codegen assertionDrMeepster-2/+2
2022-06-15remove box derefs from codgenDrMeepster-30/+8
2022-06-14Auto merge of #96285 - flip1995:pk-vfe, r=nagisabors-5/+13
Introduce `-Zvirtual-function-elimination` codegen flag Fixes #68262 This PR adds a codegen flag `-Zvirtual-function-elimination` to enable the VFE optimization in LLVM. To make this work, additonal information has to be added to vtables ([`!vcall_visibility` metadata](https://llvm.org/docs/TypeMetadata.html#vcall-visibility-metadata) and a `typeid` of the trait). Furthermore, instead of just `load`ing functions, the [`llvm.type.checked.load` intrinsic](https://llvm.org/docs/LangRef.html#llvm-type-checked-load-intrinsic) has to be used to map functions to vtables. For technical details of the changes, see the commit messages. I also tested this flag on https://github.com/tock/tock on different boards to verify that this fixes the issue https://github.com/tock/tock/issues/2594. This flag is able to improve the size of the resulting binary by about 8k-9k bytes by removing the unused debug print functions. [Rendered documentation update](https://github.com/flip1995/rust/blob/pk-vfe/src/doc/rustc/src/codegen-options/index.md#virtual-function-elimination)
2022-06-14implement valtrees as the type-system representation for constant valuesb-naber-4/+4
2022-06-14Add llvm.type.checked.load intrinsicflip1995-5/+13
Add the intrinsic declare {i8*, i1} @llvm.type.checked.load(i8* %ptr, i32 %offset, metadata %type) This is used in the VFE optimization when lowering loading functions from vtables to LLVM IR. The `metadata` is used to map the function to all vtables this function could belong to. This ensures that functions from vtables that might be used somewhere won't get removed.
2022-06-14Rename the `ConstS::val` field as `kind`.Nicholas Nethercote-2/+2
And likewise for the `Const::val` method. Because its type is called `ConstKind`. Also `val` is a confusing name because `ConstKind` is an enum with seven variants, one of which is called `Value`. Also, this gives consistency with `TyS` and `PredicateS` which have `kind` fields. The commit also renames a few `Const` variables from `val` to `c`, to avoid confusion with the `ConstKind::Value` variant.
2022-06-02commentRalf Jung-0/+3
Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
2022-06-02add cast kind of from_exposed_addr (int-to-ptr casts)Ralf Jung-1/+2
2022-06-01rename PointerAddress → PointerExposeAddressRalf Jung-1/+1
2022-05-31Add a pointer to address cast kindTomasz Miąsko-3/+7
A pointer to address cast are often special-cased. Introduce a dedicated cast kind to make them easy distinguishable.
2022-05-26clippy::complexity fixesMatthias Krüger-1/+1
clone_on_copy useless_format bind_instead_of_map filter_map_identity useless_conversion map_flatten unnecessary_unwrap
2022-05-26Auto merge of #97369 - tmiasko:codgen-ssa-atomic-ordering, r=michaelwoeristerbors-5/+5
rustc_codegen_ssa: cleanup `AtomicOrdering` * Remove unused `NotAtomic` ordering. * Rename `Monotonic` to `Relaxed` - a Rust specific name. * Derive copy and clone.
2022-05-25rustc_codegen_ssa: cleanup `AtomicOrdering`Tomasz Miąsko-5/+5
* Remove unused `NotAtomic` ordering. * Rename `Monotonic` to `Relaxed` - a Rust specific name.
2022-05-24Add flag for stricter checks on uninit/zeroed5225225-3/+5
2022-05-23Refactor call terminator to always hold a destination placeJakob Degen-17/+19
2022-05-17Change `Successors` to `impl Iterator<Item = BasicBlock>`SparrowLii-1/+1
2022-05-11Add `unsigned_offset_from` on pointersScott McMurray-7/+14
Like we have `add`/`sub` which are the `usize` version of `offset`, this adds the `usize` equivalent of `offset_from`. Like how `.add(d)` replaced a whole bunch of `.offset(d as isize)`, you can see from the changes here that it's fairly common that code actually knows the order between the pointers and *wants* a `usize`, not an `isize`. As a bonus, this can do `sub nuw`+`udiv exact`, rather than `sub`+`sdiv exact`, which can be optimized slightly better because it doesn't have to worry about negatives. That's why the slice iterators weren't using `offset_from`, though I haven't updated that code in this PR because slices are so perf-critical that I'll do it as its own change. This is an intrinsic, like `offset_from`, so that it can eventually be allowed in CTFE. It also allows checking the extra safety condition -- see the test confirming that CTFE catches it if you pass the pointers in the wrong order.
2022-05-01Use reverse postorder in `non_ssa_locals`Tomasz Miąsko-2/+2
The reverse postorder, unlike preorder, is now cached inside the MIR body. Code generation uses reverse postorder anyway, so it might be a small perf improvement to use it here as well.
2022-04-30Auto merge of #96500 - SparrowLii:rpo, r=tmiaskobors-1/+0
Reduce duplication of RPO calculation of mir Computing the RPO of mir is not a low-cost thing, but it is duplicate in many places. In particular the `iterate_to_fixpoint` method which is called multiple times when computing the data flow. This PR reduces the number of times the RPO is recalculated as much as possible, which should save some compile time.
2022-04-30Eliminate duplication of RPO calculation for mirSparrowLii-1/+0
add `postorder_cache` to mir Body add `ReversePostorderCache` struct correct struct name and comments
2022-04-29Auto merge of #96474 - SparrowLii:langcall, r=lcnrbors-19/+5
Eliminate duplication code of building panic langcall during codegen From the FIXME in the `codegen_panic_intrinsic` func.
2022-04-28use tcx.require_lang_item() insteadSparrowLii-4/+4
2022-04-27Eliminate duplication of building panic langcall in codegenSparrowLii-19/+5
2022-04-26not need `Option` for `dbg_scope`SparrowLii-9/+3
2022-04-14Add additional `extract_field` / `project_field` to take into account extra ↵Eduardo Sánchez Muñoz-2/+6
level of struct nesting.
2022-04-11Add new `MutatatingUseContext`s for deinit and `SetDiscriminant`Jakob Degen-0/+2
2022-04-11Add new `Deinit` statement kindJakob Degen-0/+6
2022-04-05Mark scalar layout unions so that backends that do not support partially ↵Oli Scherer-15/+20
initialized scalars can special case them.
2022-03-27fix other source of box derefDrMeepster-3/+11
2022-03-26check the the right fieldDrMeepster-1/+1
2022-03-25widen special case on deref to all non-zst allocatorsDrMeepster-4/+2
2022-03-16rustc_error: make ErrorReported impossible to constructmark-2/+1
There are a few places were we have to construct it, though, and a few places that are more invasive to change. To do this, we create a constructor with a long obvious name.
2022-03-12Auto merge of #94873 - DrMeepster:box_alloc_ice3, r=oli-obkbors-1/+8
Fix ICE when using Box<T, A>, again Sequel to #94043, fixes #94835.
2022-03-11fix another assumption about boxDrMeepster-1/+8
2022-03-11Improve `AdtDef` interning.Nicholas Nethercote-1/+1
This commit makes `AdtDef` use `Interned`. Much the commit is tedious changes to introduce getter functions. The interesting changes are in `compiler/rustc_middle/src/ty/adt.rs`.
2022-03-02rename ErrorReported -> ErrorGuaranteedmark-2/+2
2022-03-01Auto merge of #94402 - erikdesjardins:revert-coldland, r=nagisabors-3/+7
Revert "Auto merge of #92419 - erikdesjardins:coldland, r=nagisa" Should fix (untested) #94390 Reopens #46515, #87055 r? `@ehuss`
2022-02-27expadn abi check + condese & fix testsDrMeepster-1/+1
2022-02-27Revert "Auto merge of #92419 - erikdesjardins:coldland, r=nagisa"Erik Desjardins-3/+7
This reverts commit 4f49627c6fe2a32d1fed6310466bb0e1c535c0c0, reversing changes made to 028c6f1454787c068ff5117e9000a1de4fd98374.
2022-02-27fix box icing when it has aggregate abiDrMeepster-1/+12
2022-02-24Auto merge of #94123 - bjorn3:cg_ssa_singleton_builder, r=tmiaskobors-41/+41
Partially move cg_ssa towards using a single builder Not all codegen backends can handle hopping between blocks well. For example Cranelift requires blocks to be terminated before switching to building a new block. Rust-gpu requires a `RefCell` to allow hopping between blocks and cg_gcc currently has a buggy implementation of hopping between blocks. This PR reduces the amount of cases where cg_ssa switches between blocks before they are finished and mostly fixes the block hopping in cg_gcc. (~~only `scalar_to_backend` doesn't handle it correctly yet in cg_gcc~~ fixed that one.) `@antoyo` please review the cg_gcc changes.
2022-02-24Introduce Bx::switch_to_blockbjorn3-10/+9
2022-02-20Auto merge of #94062 - Mark-Simulacrum:drop-print-cfg, r=oli-obkbors-2/+2
Move ty::print methods to Drop-based scope guards Primary goal is reducing codegen of the TLS access for each closure, which shaves ~3 seconds of bootstrap time over rustc as a whole.
2022-02-20Inline build_blockbjorn3-7/+4
2022-02-20Remove FunctionCx::new_blockbjorn3-22/+24
2022-02-20Remove build_sibling_blockbjorn3-8/+10
2022-02-20Auto merge of #94174 - matthiaskrgr:rollup-snyrlhy, r=matthiaskrgrbors-45/+27
Rollup of 14 pull requests Successful merges: - #93580 (Stabilize pin_static_ref.) - #93639 (Release notes for 1.59) - #93686 (core: Implement ASCII trim functions on byte slices) - #94002 (rustdoc: Avoid duplicating macros in sidebar) - #94019 (removing architecture requirements for RustyHermit) - #94023 (adapt static-nobundle test to use llvm-nm) - #94091 (Fix rustdoc const computed value) - #94093 (Fix pretty printing of enums without variants) - #94097 (Add module-level docs for `rustc_middle::query`) - #94112 (Optimize char_try_from_u32) - #94113 (document rustc_middle::mir::Field) - #94122 (Fix miniz_oxide types showing up in std docs) - #94142 (rustc_typeck: adopt let else in more places) - #94146 (Adopt let else in more places) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-02-20Rollup merge of #94146 - est31:let_else, r=cjgillotMatthias Krüger-45/+27
Adopt let else in more places Continuation of #89933, #91018, #91481, #93046, #93590, #94011. I have extended my clippy lint to also recognize tuple passing and match statements. The diff caused by fixing it is way above 1 thousand lines. Thus, I split it up into multiple pull requests to make reviewing easier. This is the biggest of these PRs and handles the changes outside of rustdoc, rustc_typeck, rustc_const_eval, rustc_trait_selection, which were handled in PRs #94139, #94142, #94143, #94144.
2022-02-19Auto merge of #92911 - nbdd0121:unwind, r=Amanieubors-13/+60
Guard against unwinding in cleanup code Currently the only safe guard we have against double unwind is the panic count (which is local to Rust). When double unwinds indeed happen (e.g. C++ exception + Rust panic, or two C++ exceptions), then the second unwind actually goes through and the first unwind is leaked. This can cause UB. cc rust-lang/project-ffi-unwind#6 E.g. given the following C++ code: ```c++ extern "C" void foo() { throw "A"; } extern "C" void execute(void (*fn)()) { try { fn(); } catch(...) { } } ``` This program is well-defined to terminate: ```c++ struct dtor { ~dtor() noexcept(false) { foo(); } }; void a() { dtor a; dtor b; } int main() { execute(a); return 0; } ``` But this Rust code doesn't catch the double unwind: ```rust extern "C-unwind" { fn foo(); fn execute(f: unsafe extern "C-unwind" fn()); } struct Dtor; impl Drop for Dtor { fn drop(&mut self) { unsafe { foo(); } } } extern "C-unwind" fn a() { let _a = Dtor; let _b = Dtor; } fn main() { unsafe { execute(a) }; } ``` To address this issue, this PR adds an unwind edge to an abort block, so that the Rust example aborts. This is similar to how clang guards against double unwind (except clang calls terminate per C++ spec and we abort). The cost should be very small; it's an additional trap instruction (well, two for now, since we use TrapUnreachable, but that's a different issue) for each function with landing pads; if LLVM gains support to encode "abort/terminate" info directly in LSDA like GCC does, then it'll be free. It's an additional basic block though so compile time may be worse, so I'd like a perf run. r? `@ghost` `@rustbot` label: F-c_unwind
2022-02-19Adopt let else in more placesest31-45/+27