diff options
| author | bors <bors@rust-lang.org> | 2016-08-14 12:28:48 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-08-14 12:28:48 -0700 |
| commit | 1d5b758bab979b1db723bcc97ecd8398127bd8bc (patch) | |
| tree | 3375e24d086cd3d3927471388e8ade7fbf4f9666 /src/test/codegen | |
| parent | 92ae4ceb6c6563b983a046f5f273cc13247eb4b1 (diff) | |
| parent | 1bb14445160329c2ca5ff9c202e791ca0098d944 (diff) | |
| download | rust-1d5b758bab979b1db723bcc97ecd8398127bd8bc.tar.gz rust-1d5b758bab979b1db723bcc97ecd8398127bd8bc.zip | |
Auto merge of #35409 - eddyb:mir-storage-stmts, r=nikomatsakis
[MIR] Add Storage{Live,Dead} statements to emit llvm.lifetime.{start,end}.
Storage live ranges are tracked for all MIR variables and temporaries with a drop scope.
`StorageLive` is lowered to `llvm.lifetime.start` and `StorageDead` to `llvm.lifetime.end`.
There are some improvements possible here, such as:
* pack multiple storage liveness statements by using the index of first local + `u64` bitset
* enforce that locals are not directly accessed outside their storage live range
* shrink storage live ranges for never-borrowed locals to initialization -> last use
* emit storage liveness statements for *all* temporaries
* however, the remaining ones are *always* SSA immediates, so they'd be noop in MIR trans
* could have a flag on the temporary that its storage is irrelevant (a la C's old `register`)
* would also deny borrows if necessary
* this seems like an overcompliation and with packing & optimizations it may be pointless
Even in the current state, it helps stage2 `rustc` compile `boiler` without overflowing (see #35408).
A later addition fixes #26764 and closes #27372 by emitting `.section` directives for dylib metadata to avoid them being allocated into memory or read as `.note`. For this PR, those bugs were tripping valgrind.
Diffstat (limited to 'src/test/codegen')
| -rw-r--r-- | src/test/codegen/lifetime_start_end.rs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/test/codegen/lifetime_start_end.rs b/src/test/codegen/lifetime_start_end.rs new file mode 100644 index 00000000000..cf91e7a8bcb --- /dev/null +++ b/src/test/codegen/lifetime_start_end.rs @@ -0,0 +1,54 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags: -O -C no-prepopulate-passes + +#![crate_type = "lib"] +#![feature(rustc_attrs)] + +// CHECK-LABEL: @test +#[no_mangle] +#[rustc_mir] // FIXME #27840 MIR has different codegen. +pub fn test() { + let a = 0; + &a; // keep variable in an alloca + +// CHECK: [[S_a:%[0-9]+]] = bitcast i32* %a to i8* +// CHECK: call void @llvm.lifetime.start(i{{[0-9 ]+}}, i8* [[S_a]]) + + { + let b = &Some(a); + &b; // keep variable in an alloca + +// CHECK: [[S_b:%[0-9]+]] = bitcast %"2.std::option::Option<i32>"** %b to i8* +// CHECK: call void @llvm.lifetime.start(i{{[0-9 ]+}}, i8* [[S_b]]) + +// CHECK: [[S_tmp2:%[0-9]+]] = bitcast %"2.std::option::Option<i32>"* %tmp2 to i8* +// CHECK: call void @llvm.lifetime.start(i{{[0-9 ]+}}, i8* [[S_tmp2]]) + +// CHECK: [[E_tmp2:%[0-9]+]] = bitcast %"2.std::option::Option<i32>"* %tmp2 to i8* +// CHECK: call void @llvm.lifetime.end(i{{[0-9 ]+}}, i8* [[E_tmp2]]) + +// CHECK: [[E_b:%[0-9]+]] = bitcast %"2.std::option::Option<i32>"** %b to i8* +// CHECK: call void @llvm.lifetime.end(i{{[0-9 ]+}}, i8* [[E_b]]) + } + + let c = 1; + &c; // keep variable in an alloca + +// CHECK: [[S_c:%[0-9]+]] = bitcast i32* %c to i8* +// CHECK: call void @llvm.lifetime.start(i{{[0-9 ]+}}, i8* [[S_c]]) + +// CHECK: [[E_c:%[0-9]+]] = bitcast i32* %c to i8* +// CHECK: call void @llvm.lifetime.end(i{{[0-9 ]+}}, i8* [[E_c]]) + +// CHECK: [[E_a:%[0-9]+]] = bitcast i32* %a to i8* +// CHECK: call void @llvm.lifetime.end(i{{[0-9 ]+}}, i8* [[E_a]]) +} |
