Skip to content

Commit 6e15e7c

Browse files
committed
Integrate PassMode::UnsizedIndirect into PassMode::Indirect.
1 parent a0c422a commit 6e15e7c

File tree

5 files changed

+42
-53
lines changed

5 files changed

+42
-53
lines changed

src/librustc_codegen_llvm/abi.rs

+15-18
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
187187
return;
188188
}
189189
let cx = bx.cx;
190-
if self.is_indirect() {
190+
if self.is_sized_indirect() {
191191
OperandValue::Ref(val, self.layout.align).store(bx, dst)
192192
} else if self.is_unsized_indirect() {
193193
bug!("unsized ArgType must be handled through store_fn_arg");
@@ -248,10 +248,10 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
248248
PassMode::Pair(..) => {
249249
OperandValue::Pair(next(), next()).store(bx, dst);
250250
}
251-
PassMode::UnsizedIndirect(..) => {
251+
PassMode::Indirect(_, Some(_)) => {
252252
OperandValue::UnsizedRef(next(), next()).store(bx, dst);
253253
}
254-
PassMode::Direct(_) | PassMode::Indirect(_) | PassMode::Cast(_) => {
254+
PassMode::Direct(_) | PassMode::Indirect(_, None) | PassMode::Cast(_) => {
255255
self.store(bx, next(), dst);
256256
}
257257
}
@@ -547,9 +547,7 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
547547
}
548548

549549
let size = arg.layout.size;
550-
if arg.layout.is_unsized() {
551-
arg.make_unsized_indirect(None);
552-
} else if size > layout::Pointer.size(cx) {
550+
if arg.layout.is_unsized() || size > layout::Pointer.size(cx) {
553551
arg.make_indirect();
554552
} else {
555553
// We want to pass small aggregates as immediates, but using
@@ -565,7 +563,7 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
565563
for arg in &mut self.args {
566564
fixup(arg);
567565
}
568-
if let PassMode::Indirect(ref mut attrs) = self.ret.mode {
566+
if let PassMode::Indirect(ref mut attrs, _) = self.ret.mode {
569567
attrs.set(ArgAttribute::StructRet);
570568
}
571569
return;
@@ -582,7 +580,7 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
582580
if let PassMode::Pair(_, _) = arg.mode { 2 } else { 1 }
583581
).sum();
584582
let mut llargument_tys = Vec::with_capacity(
585-
if let PassMode::Indirect(_) = self.ret.mode { 1 } else { 0 } + args_capacity
583+
if let PassMode::Indirect(..) = self.ret.mode { 1 } else { 0 } + args_capacity
586584
);
587585

588586
let llreturn_ty = match self.ret.mode {
@@ -591,11 +589,10 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
591589
self.ret.layout.immediate_llvm_type(cx)
592590
}
593591
PassMode::Cast(cast) => cast.llvm_type(cx),
594-
PassMode::Indirect(_) => {
592+
PassMode::Indirect(..) => {
595593
llargument_tys.push(self.ret.memory_ty(cx).ptr_to());
596594
Type::void(cx)
597595
}
598-
PassMode::UnsizedIndirect(..) => bug!("return type must be sized"),
599596
};
600597

601598
for arg in &self.args {
@@ -612,15 +609,15 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
612609
llargument_tys.push(arg.layout.scalar_pair_element_llvm_type(cx, 1, true));
613610
continue;
614611
}
615-
PassMode::UnsizedIndirect(..) => {
612+
PassMode::Indirect(_, Some(_)) => {
616613
let ptr_ty = cx.tcx.mk_mut_ptr(arg.layout.ty);
617614
let ptr_layout = cx.layout_of(ptr_ty);
618615
llargument_tys.push(ptr_layout.scalar_pair_element_llvm_type(cx, 0, true));
619616
llargument_tys.push(ptr_layout.scalar_pair_element_llvm_type(cx, 1, true));
620617
continue;
621618
}
622619
PassMode::Cast(cast) => cast.llvm_type(cx),
623-
PassMode::Indirect(_) => arg.memory_ty(cx).ptr_to(),
620+
PassMode::Indirect(_, None) => arg.memory_ty(cx).ptr_to(),
624621
};
625622
llargument_tys.push(llarg_ty);
626623
}
@@ -659,7 +656,7 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
659656
PassMode::Direct(ref attrs) => {
660657
attrs.apply_llfn(llvm::AttributePlace::ReturnValue, llfn);
661658
}
662-
PassMode::Indirect(ref attrs) => apply(attrs),
659+
PassMode::Indirect(ref attrs, _) => apply(attrs),
663660
_ => {}
664661
}
665662
for arg in &self.args {
@@ -669,8 +666,8 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
669666
match arg.mode {
670667
PassMode::Ignore => {}
671668
PassMode::Direct(ref attrs) |
672-
PassMode::Indirect(ref attrs) => apply(attrs),
673-
PassMode::UnsizedIndirect(ref attrs, ref extra_attrs) => {
669+
PassMode::Indirect(ref attrs, None) => apply(attrs),
670+
PassMode::Indirect(ref attrs, Some(ref extra_attrs)) => {
674671
apply(attrs);
675672
apply(extra_attrs);
676673
}
@@ -693,7 +690,7 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
693690
PassMode::Direct(ref attrs) => {
694691
attrs.apply_callsite(llvm::AttributePlace::ReturnValue, callsite);
695692
}
696-
PassMode::Indirect(ref attrs) => apply(attrs),
693+
PassMode::Indirect(ref attrs, _) => apply(attrs),
697694
_ => {}
698695
}
699696
if let layout::Abi::Scalar(ref scalar) = self.ret.layout.abi {
@@ -717,8 +714,8 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
717714
match arg.mode {
718715
PassMode::Ignore => {}
719716
PassMode::Direct(ref attrs) |
720-
PassMode::Indirect(ref attrs) => apply(attrs),
721-
PassMode::UnsizedIndirect(ref attrs, ref extra_attrs) => {
717+
PassMode::Indirect(ref attrs, None) => apply(attrs),
718+
PassMode::Indirect(ref attrs, Some(ref extra_attrs)) => {
722719
apply(attrs);
723720
apply(extra_attrs);
724721
}

src/librustc_codegen_llvm/mir/block.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl FunctionCx<'a, 'll, 'tcx> {
225225

226226
mir::TerminatorKind::Return => {
227227
let llval = match self.fn_ty.ret.mode {
228-
PassMode::Ignore | PassMode::Indirect(_) => {
228+
PassMode::Ignore | PassMode::Indirect(..) => {
229229
bx.ret_void();
230230
return;
231231
}
@@ -270,8 +270,6 @@ impl FunctionCx<'a, 'll, 'tcx> {
270270
bx.pointercast(llslot, cast_ty.llvm_type(bx.cx).ptr_to()),
271271
self.fn_ty.ret.layout.align)
272272
}
273-
274-
PassMode::UnsizedIndirect(..) => bug!("return value must be sized"),
275273
};
276274
bx.ret(llval);
277275
}
@@ -667,7 +665,7 @@ impl FunctionCx<'a, 'll, 'tcx> {
667665
}
668666
_ => bug!("codegen_argument: {:?} invalid for pair arugment", op)
669667
}
670-
} else if let PassMode::UnsizedIndirect(..) = arg.mode {
668+
} else if arg.is_unsized_indirect() {
671669
match op.val {
672670
UnsizedRef(a, b) => {
673671
llargs.push(a);
@@ -682,7 +680,7 @@ impl FunctionCx<'a, 'll, 'tcx> {
682680
let (mut llval, align, by_ref) = match op.val {
683681
Immediate(_) | Pair(..) => {
684682
match arg.mode {
685-
PassMode::Indirect(_) | PassMode::Cast(_) => {
683+
PassMode::Indirect(..) | PassMode::Cast(_) => {
686684
let scratch = PlaceRef::alloca(bx, arg.layout, "arg");
687685
op.val.store(bx, scratch);
688686
(scratch.llval, scratch.align, true)

src/librustc_codegen_llvm/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ fn arg_local_refs(
541541
}
542542
}
543543

544-
let place = if arg.is_indirect() {
544+
let place = if arg.is_sized_indirect() {
545545
// Don't copy an indirect argument to an alloca, the caller
546546
// already put it in a temporary alloca and gave it up.
547547
// FIXME: lifetimes

src/librustc_target/abi/call/mod.rs

+21-27
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ pub enum PassMode {
4444
/// a single uniform or a pair of registers.
4545
Cast(CastTarget),
4646
/// Pass the argument indirectly via a hidden pointer.
47-
Indirect(ArgAttributes),
48-
/// Pass the unsized argument indirectly via a hidden pointer.
49-
UnsizedIndirect(ArgAttributes, ArgAttributes),
47+
/// The second value, if any, is for the extra data (vtable or length)
48+
/// which indicates that it refers to an unsized rvalue.
49+
Indirect(ArgAttributes, Option<ArgAttributes>),
5050
}
5151

5252
// Hack to disable non_upper_case_globals only for the bitflags! and not for the rest
@@ -370,38 +370,25 @@ impl<'a, Ty> ArgType<'a, Ty> {
370370
// i686-pc-windows-msvc, it results in wrong stack offsets.
371371
// attrs.pointee_align = Some(self.layout.align);
372372

373-
self.mode = PassMode::Indirect(attrs);
373+
let extra_attrs = if self.layout.is_unsized() {
374+
Some(ArgAttributes::new())
375+
} else {
376+
None
377+
};
378+
379+
self.mode = PassMode::Indirect(attrs, extra_attrs);
374380
}
375381

376382
pub fn make_indirect_byval(&mut self) {
377383
self.make_indirect();
378384
match self.mode {
379-
PassMode::Indirect(ref mut attrs) => {
385+
PassMode::Indirect(ref mut attrs, _) => {
380386
attrs.set(ArgAttribute::ByVal);
381387
}
382388
_ => unreachable!()
383389
}
384390
}
385391

386-
pub fn make_unsized_indirect(&mut self, vtable_size: Option<Size>) {
387-
self.make_indirect();
388-
389-
let attrs = if let PassMode::Indirect(attrs) = self.mode {
390-
attrs
391-
} else {
392-
unreachable!()
393-
};
394-
395-
let mut extra_attrs = ArgAttributes::new();
396-
if let Some(vtable_size) = vtable_size {
397-
extra_attrs.set(ArgAttribute::NoAlias)
398-
.set(ArgAttribute::NonNull);
399-
extra_attrs.pointee_size = vtable_size;
400-
}
401-
402-
self.mode = PassMode::UnsizedIndirect(attrs, extra_attrs);
403-
}
404-
405392
pub fn extend_integer_width_to(&mut self, bits: u64) {
406393
// Only integers have signedness
407394
if let Abi::Scalar(ref scalar) = self.layout.abi {
@@ -430,14 +417,21 @@ impl<'a, Ty> ArgType<'a, Ty> {
430417

431418
pub fn is_indirect(&self) -> bool {
432419
match self.mode {
433-
PassMode::Indirect(_) => true,
420+
PassMode::Indirect(..) => true,
421+
_ => false
422+
}
423+
}
424+
425+
pub fn is_sized_indirect(&self) -> bool {
426+
match self.mode {
427+
PassMode::Indirect(_, None) => true,
434428
_ => false
435429
}
436430
}
437431

438432
pub fn is_unsized_indirect(&self) -> bool {
439433
match self.mode {
440-
PassMode::UnsizedIndirect(..) => true,
434+
PassMode::Indirect(_, Some(_)) => true,
441435
_ => false
442436
}
443437
}
@@ -534,7 +528,7 @@ impl<'a, Ty> FnType<'a, Ty> {
534528
a => return Err(format!("unrecognized arch \"{}\" in target specification", a))
535529
}
536530

537-
if let PassMode::Indirect(ref mut attrs) = self.ret.mode {
531+
if let PassMode::Indirect(ref mut attrs, _) = self.ret.mode {
538532
attrs.set(ArgAttribute::StructRet);
539533
}
540534

src/librustc_target/abi/call/x86.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ pub fn compute_abi_info<'a, Ty, C>(cx: C, fty: &mut FnType<'a, Ty>, flavor: Flav
9999
for arg in &mut fty.args {
100100
let attrs = match arg.mode {
101101
PassMode::Ignore |
102-
PassMode::Indirect(_) => continue,
102+
PassMode::Indirect(_, None) => continue,
103103
PassMode::Direct(ref mut attrs) => attrs,
104104
PassMode::Pair(..) |
105-
PassMode::UnsizedIndirect(..) |
105+
PassMode::Indirect(_, Some(_)) |
106106
PassMode::Cast(_) => {
107107
unreachable!("x86 shouldn't be passing arguments by {:?}", arg.mode)
108108
}

0 commit comments

Comments
 (0)