Skip to content

Commit e51de04

Browse files
committed
Rollup merge of rust-lang#30851 - jonas-schievink:unneeded-dropflags, r=pnkfelix
Apparently we allocate and maintain non-working dropflag hints since June... In anticipation of a working implementation of on-stack drop flag hints, let's not spend even more time on types that don't even need to be dropped. ```rust fn main() { let (i,j,k,l) = (0,0,0,0); } ``` used to translate to (unoptimized only, of course): ```llvm define internal void @_ZN4main20ha8deb085c47920d8eaaE() unnamed_addr #0 { entry-block: %dropflag_hint_10 = alloca i8 %dropflag_hint_11 = alloca i8 %dropflag_hint_12 = alloca i8 %dropflag_hint_13 = alloca i8 %const = alloca { i32, i32, i32, i32 } %i = alloca i32 %j = alloca i32 %k = alloca i32 %l = alloca i32 store i8 61, i8* %dropflag_hint_10 store i8 61, i8* %dropflag_hint_11 store i8 61, i8* %dropflag_hint_12 store i8 61, i8* %dropflag_hint_13 %0 = bitcast { i32, i32, i32, i32 }* %const to i8* call void @llvm.memcpy.p0i8.p0i8.i64(i8* %0, i8* bitcast ({ i32, i32, i32, i32 }* @const2752 to i8*), i64 16, i32 4, i1 false) %1 = getelementptr inbounds { i32, i32, i32, i32 }, { i32, i32, i32, i32 }* %const, i32 0, i32 0 %2 = load i32, i32* %1, align 4 store i32 %2, i32* %i, align 4 %3 = getelementptr inbounds { i32, i32, i32, i32 }, { i32, i32, i32, i32 }* %const, i32 0, i32 1 %4 = load i32, i32* %3, align 4 store i32 %4, i32* %j, align 4 %5 = getelementptr inbounds { i32, i32, i32, i32 }, { i32, i32, i32, i32 }* %const, i32 0, i32 2 %6 = load i32, i32* %5, align 4 store i32 %6, i32* %k, align 4 %7 = getelementptr inbounds { i32, i32, i32, i32 }, { i32, i32, i32, i32 }* %const, i32 0, i32 3 %8 = load i32, i32* %7, align 4 store i32 %8, i32* %l, align 4 ret void } ``` Now it gives: ```llvm define internal void @_ZN4main20ha8deb085c47920d8eaaE() unnamed_addr #0 { entry-block: %const = alloca { i32, i32, i32, i32 } %i = alloca i32 %j = alloca i32 %k = alloca i32 %l = alloca i32 %0 = bitcast { i32, i32, i32, i32 }* %const to i8* call void @llvm.memcpy.p0i8.p0i8.i64(i8* %0, i8* bitcast ({ i32, i32, i32, i32 }* @const2748 to i8*), i64 16, i32 4, i1 false) %1 = getelementptr inbounds { i32, i32, i32, i32 }, { i32, i32, i32, i32 }* %const, i32 0, i32 0 %2 = load i32, i32* %1, align 4 store i32 %2, i32* %i, align 4 %3 = getelementptr inbounds { i32, i32, i32, i32 }, { i32, i32, i32, i32 }* %const, i32 0, i32 1 %4 = load i32, i32* %3, align 4 store i32 %4, i32* %j, align 4 %5 = getelementptr inbounds { i32, i32, i32, i32 }, { i32, i32, i32, i32 }* %const, i32 0, i32 2 %6 = load i32, i32* %5, align 4 store i32 %6, i32* %k, align 4 %7 = getelementptr inbounds { i32, i32, i32, i32 }, { i32, i32, i32, i32 }* %const, i32 0, i32 3 %8 = load i32, i32* %7, align 4 store i32 %8, i32* %l, align 4 ret void } ``` Let's hope I didn't break anything!
2 parents 6ceaa2f + e3abc3c commit e51de04

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/librustc_trans/trans/base.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,7 @@ pub fn init_function<'a, 'tcx>(fcx: &'a FunctionContext<'a, 'tcx>,
16491649
// Create the drop-flag hints for every unfragmented path in the function.
16501650
let tcx = fcx.ccx.tcx();
16511651
let fn_did = tcx.map.local_def_id(fcx.id);
1652+
let tables = tcx.tables.borrow();
16521653
let mut hints = fcx.lldropflag_hints.borrow_mut();
16531654
let fragment_infos = tcx.fragment_infos.borrow();
16541655

@@ -1672,12 +1673,22 @@ pub fn init_function<'a, 'tcx>(fcx: &'a FunctionContext<'a, 'tcx>,
16721673
let (var, datum) = match info {
16731674
ty::FragmentInfo::Moved { var, .. } |
16741675
ty::FragmentInfo::Assigned { var, .. } => {
1675-
let datum = seen.get(&var).cloned().unwrap_or_else(|| {
1676-
let datum = make_datum(var);
1677-
seen.insert(var, datum.clone());
1678-
datum
1676+
let opt_datum = seen.get(&var).cloned().unwrap_or_else(|| {
1677+
let ty = tables.node_types[&var];
1678+
if fcx.type_needs_drop(ty) {
1679+
let datum = make_datum(var);
1680+
seen.insert(var, Some(datum.clone()));
1681+
Some(datum)
1682+
} else {
1683+
// No drop call needed, so we don't need a dropflag hint
1684+
None
1685+
}
16791686
});
1680-
(var, datum)
1687+
if let Some(datum) = opt_datum {
1688+
(var, datum)
1689+
} else {
1690+
continue
1691+
}
16811692
}
16821693
};
16831694
match info {

0 commit comments

Comments
 (0)