Skip to content

Commit 3b66c4e

Browse files
committed
Remove usage of FnAbi in codegen_intrinsic_call
1 parent 50cccb5 commit 3b66c4e

File tree

5 files changed

+31
-63
lines changed

5 files changed

+31
-63
lines changed

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_middle::ty::layout::FnAbiOf;
2626
use rustc_middle::ty::layout::{HasTypingEnv, LayoutOf};
2727
use rustc_middle::ty::{self, Instance, Ty};
2828
use rustc_span::{Span, Symbol, sym};
29-
use rustc_target::callconv::{ArgAbi, FnAbi, PassMode};
29+
use rustc_target::callconv::{ArgAbi, PassMode};
3030
use rustc_target::spec::PanicStrategy;
3131

3232
#[cfg(feature = "master")]
@@ -200,7 +200,6 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
200200
fn codegen_intrinsic_call(
201201
&mut self,
202202
instance: Instance<'tcx>,
203-
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
204203
args: &[OperandRef<'tcx, RValue<'gcc>>],
205204
result: PlaceRef<'tcx, RValue<'gcc>>,
206205
span: Span,
@@ -285,17 +284,10 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
285284
}
286285

287286
sym::volatile_load | sym::unaligned_volatile_load => {
288-
let tp_ty = fn_args.type_at(0);
289287
let ptr = args[0].immediate();
290-
let layout = self.layout_of(tp_ty);
291-
let load = if let PassMode::Cast { cast: ref ty, pad_i32: _ } = fn_abi.ret.mode {
292-
let gcc_ty = ty.gcc_type(self);
293-
self.volatile_load(gcc_ty, ptr)
294-
} else {
295-
self.volatile_load(layout.gcc_type(self), ptr)
296-
};
288+
let load = self.volatile_load(result.layout.gcc_type(self), ptr);
297289
// TODO(antoyo): set alignment.
298-
if let BackendRepr::Scalar(scalar) = layout.backend_repr {
290+
if let BackendRepr::Scalar(scalar) = result.layout.backend_repr {
299291
self.to_immediate_scalar(load, scalar)
300292
} else {
301293
load
@@ -510,16 +502,14 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
510502
_ => return Err(Instance::new_raw(instance.def_id(), instance.args)),
511503
};
512504

513-
if !fn_abi.ret.is_ignore() {
514-
if let PassMode::Cast { cast: ref ty, .. } = fn_abi.ret.mode {
515-
let ptr_llty = self.type_ptr_to(ty.gcc_type(self));
516-
let ptr = self.pointercast(result.val.llval, ptr_llty);
517-
self.store(value, ptr, result.val.align);
518-
} else {
519-
OperandRef::from_immediate_or_packed_pair(self, value, result.layout)
520-
.val
521-
.store(self, result);
522-
}
505+
if result.layout.ty.is_bool() {
506+
OperandRef::from_immediate_or_packed_pair(self, value, result.layout)
507+
.val
508+
.store(self, result);
509+
} else if !result.layout.ty.is_unit() {
510+
let ptr_llty = self.type_ptr_to(result.layout.gcc_type(self));
511+
let ptr = self.pointercast(result.val.llval, ptr_llty);
512+
self.store(value, ptr, result.val.align);
523513
}
524514
Ok(())
525515
}

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,10 @@ use rustc_middle::ty::{self, GenericArgsRef, Ty};
1515
use rustc_middle::{bug, span_bug};
1616
use rustc_span::{Span, Symbol, sym};
1717
use rustc_symbol_mangling::mangle_internal_symbol;
18-
use rustc_target::callconv::{FnAbi, PassMode};
1918
use rustc_target::spec::{HasTargetSpec, PanicStrategy};
2019
use tracing::debug;
2120

22-
use crate::abi::{FnAbiLlvmExt, LlvmType};
21+
use crate::abi::FnAbiLlvmExt;
2322
use crate::builder::Builder;
2423
use crate::context::CodegenCx;
2524
use crate::llvm::{self, Metadata};
@@ -165,7 +164,6 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
165164
fn codegen_intrinsic_call(
166165
&mut self,
167166
instance: ty::Instance<'tcx>,
168-
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
169167
args: &[OperandRef<'tcx, &'ll Value>],
170168
result: PlaceRef<'tcx, &'ll Value>,
171169
span: Span,
@@ -263,7 +261,7 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
263261
self.call_intrinsic("llvm.va_copy", &[args[0].immediate(), args[1].immediate()])
264262
}
265263
sym::va_arg => {
266-
match fn_abi.ret.layout.backend_repr {
264+
match result.layout.backend_repr {
267265
BackendRepr::Scalar(scalar) => {
268266
match scalar.primitive() {
269267
Primitive::Int(..) => {
@@ -298,18 +296,12 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
298296
}
299297

300298
sym::volatile_load | sym::unaligned_volatile_load => {
301-
let tp_ty = fn_args.type_at(0);
302299
let ptr = args[0].immediate();
303-
let load = if let PassMode::Cast { cast: ty, pad_i32: _ } = &fn_abi.ret.mode {
304-
let llty = ty.llvm_type(self);
305-
self.volatile_load(llty, ptr)
306-
} else {
307-
self.volatile_load(self.layout_of(tp_ty).llvm_type(self), ptr)
308-
};
300+
let load = self.volatile_load(result.layout.llvm_type(self), ptr);
309301
let align = if name == sym::unaligned_volatile_load {
310302
1
311303
} else {
312-
self.align_of(tp_ty).bytes() as u32
304+
result.layout.align.abi.bytes() as u32
313305
};
314306
unsafe {
315307
llvm::LLVMSetAlignment(load, align);
@@ -628,14 +620,12 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
628620
}
629621
};
630622

631-
if !fn_abi.ret.is_ignore() {
632-
if let PassMode::Cast { .. } = &fn_abi.ret.mode {
633-
self.store(llval, result.val.llval, result.val.align);
634-
} else {
635-
OperandRef::from_immediate_or_packed_pair(self, llval, result.layout)
636-
.val
637-
.store(self, result);
638-
}
623+
if result.layout.ty.is_bool() {
624+
OperandRef::from_immediate_or_packed_pair(self, llval, result.layout)
625+
.val
626+
.store(self, result);
627+
} else if !result.layout.ty.is_unit() {
628+
self.store_to_place(llval, result.val);
639629
}
640630
Ok(())
641631
}

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -967,14 +967,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
967967

968968
let result = PlaceRef::new_sized(dest, fn_abi.ret.layout);
969969

970-
match self.codegen_intrinsic_call(
971-
bx,
972-
instance,
973-
fn_abi,
974-
&args,
975-
result,
976-
source_info,
977-
) {
970+
match self.codegen_intrinsic_call(bx, instance, &args, result, source_info)
971+
{
978972
Ok(()) => {
979973
if let ReturnDest::IndirectOperand(dst, _) = ret_dest {
980974
self.store_return(bx, ret_dest, &fn_abi.ret, dst.val.llval);

compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc_middle::ty::{self, Ty, TyCtxt};
44
use rustc_middle::{bug, span_bug};
55
use rustc_session::config::OptLevel;
66
use rustc_span::sym;
7-
use rustc_target::callconv::{FnAbi, PassMode};
87

98
use super::FunctionCx;
109
use super::operand::OperandRef;
@@ -56,7 +55,6 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
5655
&mut self,
5756
bx: &mut Bx,
5857
instance: ty::Instance<'tcx>,
59-
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
6058
args: &[OperandRef<'tcx, Bx::Value>],
6159
result: PlaceRef<'tcx, Bx::Value>,
6260
source_info: SourceInfo,
@@ -536,18 +534,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
536534

537535
_ => {
538536
// Need to use backend-specific things in the implementation.
539-
return bx.codegen_intrinsic_call(instance, fn_abi, args, result, span);
537+
return bx.codegen_intrinsic_call(instance, args, result, span);
540538
}
541539
};
542540

543-
if !fn_abi.ret.is_ignore() {
544-
if let PassMode::Cast { .. } = &fn_abi.ret.mode {
545-
bx.store_to_place(llval, result.val);
546-
} else {
547-
OperandRef::from_immediate_or_packed_pair(bx, llval, result.layout)
548-
.val
549-
.store(bx, result);
550-
}
541+
if result.layout.ty.is_bool() {
542+
OperandRef::from_immediate_or_packed_pair(bx, llval, result.layout)
543+
.val
544+
.store(bx, result);
545+
} else if !result.layout.ty.is_unit() {
546+
bx.store_to_place(llval, result.val);
551547
}
552548
Ok(())
553549
}

compiler/rustc_codegen_ssa/src/traits/intrinsic.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use rustc_middle::ty::{self, Ty};
1+
use rustc_middle::ty;
22
use rustc_span::Span;
3-
use rustc_target::callconv::FnAbi;
43

54
use super::BackendTypes;
65
use crate::mir::operand::OperandRef;
@@ -15,7 +14,6 @@ pub trait IntrinsicCallBuilderMethods<'tcx>: BackendTypes {
1514
fn codegen_intrinsic_call(
1615
&mut self,
1716
instance: ty::Instance<'tcx>,
18-
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
1917
args: &[OperandRef<'tcx, Self::Value>],
2018
result: PlaceRef<'tcx, Self::Value>,
2119
span: Span,

0 commit comments

Comments
 (0)