Skip to content

Commit

Permalink
Simplify the code of fixup by making it's code flow more natural
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed Feb 20, 2022
1 parent cb4ee81 commit 2e374cf
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3194,7 +3194,22 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
}

match arg.layout.abi {
Abi::Aggregate { .. } => {}
Abi::Aggregate { .. } => {
// Pass and return structures up to 2 pointers in size by value,
// matching `ScalarPair`. LLVM will usually pass these in 2 registers
// which is more efficient than by-ref.
let max_by_val_size = Pointer.size(self) * 2;
let size = arg.layout.size;

if arg.layout.is_unsized() || size > max_by_val_size {
arg.make_indirect();
} else {
// We want to pass small aggregates as immediates, but using
// a LLVM aggregate type for this leads to bad optimizations,
// so we pick an appropriately sized integer type instead.
arg.cast_to(Reg { kind: RegKind::Integer, size });
}
}

// This is a fun case! The gist of what this is doing is
// that we want callers and callees to always agree on the
Expand All @@ -3220,24 +3235,9 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
&& self.tcx.sess.target.simd_types_indirect =>
{
arg.make_indirect();
return;
}

_ => return,
}

// Pass and return structures up to 2 pointers in size by value, matching `ScalarPair`.
// LLVM will usually pass these in 2 registers, which is more efficient than by-ref.
let max_by_val_size = Pointer.size(self) * 2;
let size = arg.layout.size;

if arg.layout.is_unsized() || size > max_by_val_size {
arg.make_indirect();
} else {
// We want to pass small aggregates as immediates, but using
// a LLVM aggregate type for this leads to bad optimizations,
// so we pick an appropriately sized integer type instead.
arg.cast_to(Reg { kind: RegKind::Integer, size });
_ => {},
}
};
fixup(&mut fn_abi.ret);
Expand Down

0 comments on commit 2e374cf

Please sign in to comment.