Auto merge of #32980 - Aatch:better-mir-building, r=nagisa
Various improvements to MIR and LLVM IR Construction Primarily affects the MIR construction, which indirectly improves LLVM IR generation, but some LLVM IR changes have been made too. * Handle "statement expressions" more intelligently. These are expressions that always evaluate to `()`. Previously a temporary would be generated as a destination to translate into, which is unnecessary. This affects assignment, augmented assignment, `return`, `break` and `continue`. * Avoid inserting drops for non-drop types in more places. Scheduled drops were already skipped for types that we knew wouldn't need dropping at construction time. However manually-inserted drops like those for `x` in `x = y;` were still generated. `build_drop` now takes a type parameter like its `schedule_drop` counterpart and checks to see if the type needs dropping. * Avoid generating an extra temporary for an assignment where the types involved don't need dropping. Previously an expression like `a = b + 1;` would result in a temporary for `b + 1`. This is so the RHS can be evaluated, then the LHS evaluated and dropped and have everything work correctly. However, this isn't necessary if the `LHS` doesn't need a drop, as we can just overwrite the existing value. * Improves lvalue analysis to allow treating an `Rvalue::Use` as an operand in certain conditions. The reason for it never being an operand is so it can be zeroed/drop-filled, but this is only true for types that need dropping. The first two changes result in significantly fewer MIR blocks being generated, as previously almost every statement would end up generating a new block due to the drop of the `()` temporary being generated.
This commit is contained in:
commit
009a64916e
18 changed files with 299 additions and 183 deletions
|
|
@ -32,5 +32,3 @@ pub fn generic_function<T>(x: T) -> (T, i32) {
|
|||
fn main() {
|
||||
0i64.foo();
|
||||
}
|
||||
|
||||
//~ TRANS_ITEM drop-glue i8
|
||||
|
|
|
|||
|
|
@ -59,5 +59,3 @@ fn main() {
|
|||
fn run_closure(f: &Fn(i32)) {
|
||||
f(3);
|
||||
}
|
||||
|
||||
//~ TRANS_ITEM drop-glue i8
|
||||
|
|
|
|||
|
|
@ -57,5 +57,3 @@ mod mod2 {
|
|||
cgu_explicit_inlining::never_inlined();
|
||||
}
|
||||
}
|
||||
|
||||
//~ TRANS_ITEM drop-glue i8
|
||||
|
|
|
|||
|
|
@ -50,5 +50,3 @@ mod non_user {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
//~ TRANS_ITEM drop-glue i8
|
||||
|
|
|
|||
|
|
@ -50,5 +50,3 @@ mod non_user {
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
//~ TRANS_ITEM drop-glue i8
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue