Skip to content

Commit 7d7ad34

Browse files
committed
Move to a BackendRepr based sol
1 parent d25ed22 commit 7d7ad34

File tree

1 file changed

+5
-36
lines changed
  • compiler/rustc_monomorphize/src/partitioning

1 file changed

+5
-36
lines changed

compiler/rustc_monomorphize/src/partitioning/autodiff.rs

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rustc_abi::HasDataLayout;
21
use rustc_ast::expand::autodiff_attrs::{AutoDiffItem, DiffActivity};
32
use rustc_hir::def_id::LOCAL_CRATE;
43
use rustc_middle::bug;
@@ -17,7 +16,6 @@ fn adjust_activity_to_abi<'tcx>(tcx: TyCtxt<'tcx>, fn_ty: Ty<'tcx>, da: &mut Vec
1716
// We don't actually pass the types back into the type system.
1817
// All we do is decide how to handle the arguments.
1918
let sig = fn_ty.fn_sig(tcx).skip_binder();
20-
let pointer_size = tcx.data_layout().pointer_size;
2119

2220
let mut new_activities = vec![];
2321
let mut new_positions = vec![];
@@ -82,18 +80,12 @@ fn adjust_activity_to_abi<'tcx>(tcx: TyCtxt<'tcx>, fn_ty: Ty<'tcx>, da: &mut Vec
8280
}
8381
};
8482

85-
let is_product = |t: Ty<'tcx>| matches!(t.kind(), ty::Tuple(_) | ty::Adt(_, _));
86-
87-
// NOTE: When an ADT (Algebraic Data Type) has fewer than two fields and a total size less than pointer_size * 2,
88-
// LLVM will pass its fields separately instead of as a single aggregate.
89-
if layout.size() <= pointer_size * 2 && is_product(*ty) {
90-
let n_scalars = count_leaf_fields(tcx, *ty);
91-
if n_scalars <= 2 {
92-
for _ in 0..n_scalars.saturating_sub(1) {
93-
new_activities.push(da[i].clone());
94-
new_positions.push(i + 1);
95-
}
83+
match layout.backend_repr() {
84+
rustc_abi::BackendRepr::ScalarPair(_, _) => {
85+
new_activities.push(da[i].clone());
86+
new_positions.push(i + 1);
9687
}
88+
_ => {}
9789
}
9890
}
9991
// now add the extra activities coming from slices
@@ -105,29 +97,6 @@ fn adjust_activity_to_abi<'tcx>(tcx: TyCtxt<'tcx>, fn_ty: Ty<'tcx>, da: &mut Vec
10597
}
10698
}
10799

108-
fn count_leaf_fields<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> usize {
109-
match ty.kind() {
110-
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::FnPtr(_, _) => 1,
111-
ty::RawPtr(ty, _) => count_leaf_fields(tcx, *ty),
112-
ty::Ref(_, ty, _) => count_leaf_fields(tcx, *ty),
113-
ty::Array(ty, len) => {
114-
if let Some(len) = len.try_to_target_usize(tcx) {
115-
count_leaf_fields(tcx, *ty) * len as usize
116-
} else {
117-
1 // Not sure about how to handle this case
118-
}
119-
}
120-
ty::Adt(def, substs) if def.is_struct() => def
121-
.non_enum_variant()
122-
.fields
123-
.iter()
124-
.map(|f| count_leaf_fields(tcx, f.ty(tcx, substs)))
125-
.sum(),
126-
ty::Tuple(substs) => substs.iter().map(|t| count_leaf_fields(tcx, t)).sum(),
127-
_ => 0,
128-
}
129-
}
130-
131100
pub(crate) fn find_autodiff_source_functions<'tcx>(
132101
tcx: TyCtxt<'tcx>,
133102
usage_map: &UsageMap<'tcx>,

0 commit comments

Comments
 (0)