Skip to content

Commit ba526ef

Browse files
committed
Inline BuilderMethods::call for intrinsics
Intrinsics only need a fraction of the functionality offered by BuilderMethods::call and in particular don't need the FnAbi to be computed other than (currently) as step towards computing the function value type.
1 parent 209d94a commit ba526ef

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,12 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
314314
self.block.get_function()
315315
}
316316

317-
fn function_call(
317+
pub fn function_call(
318318
&mut self,
319-
func: RValue<'gcc>,
319+
func: Function<'gcc>,
320320
args: &[RValue<'gcc>],
321321
_funclet: Option<&Funclet>,
322322
) -> RValue<'gcc> {
323-
// TODO(antoyo): remove when the API supports a different type for functions.
324-
let func: Function<'gcc> = self.cx.rvalue_as_function(func);
325323
let args = self.check_call("call", func, args);
326324

327325
// gccjit requires to use the result of functions, even when it's not used.
@@ -1752,6 +1750,8 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
17521750
// FIXME(antoyo): remove when having a proper API.
17531751
let gcc_func = unsafe { std::mem::transmute::<RValue<'gcc>, Function<'gcc>>(func) };
17541752
let call = if self.functions.borrow().values().any(|value| *value == gcc_func) {
1753+
// TODO(antoyo): remove when the API supports a different type for functions.
1754+
let func: Function<'gcc> = self.cx.rvalue_as_function(func);
17551755
self.function_call(func, args, funclet)
17561756
} else {
17571757
// If it's a not function that was defined, it's a function pointer.

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
646646
args: &[OperandRef<'tcx, Self::Value>],
647647
is_cleanup: bool,
648648
) -> Self::Value {
649-
let fn_ptr = self.get_fn_addr(instance);
650-
let fn_ty = fn_ptr.get_type();
649+
let fn_val = self.get_fn(instance);
651650

652651
let mut llargs = vec![];
653652

@@ -680,7 +679,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
680679
}
681680

682681
// FIXME directly use the llvm intrinsic adjustment functions here
683-
let llret = self.call(fn_ty, None, None, fn_ptr, &llargs, None, None);
682+
let llret = self.function_call(fn_val, &llargs, None);
684683
if is_cleanup {
685684
self.apply_attrs_to_cleanup_callsite(llret);
686685
}

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1622,7 +1622,7 @@ impl<'a, 'll, CX: Borrow<SCx<'ll>>> GenericBuilder<'a, 'll, CX> {
16221622
ret.expect("LLVM does not have support for catchret")
16231623
}
16241624

1625-
fn check_call<'b>(
1625+
pub(crate) fn check_call<'b>(
16261626
&mut self,
16271627
typ: &str,
16281628
fn_ty: &'ll Type,

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::assert_matches::assert_matches;
22
use std::cmp::Ordering;
3+
use std::ffi::c_uint;
4+
use std::ptr;
35

46
use rustc_abi::{
57
Align, BackendRepr, ExternAbi, Float, HasDataLayout, Primitive, Size, WrappingRange,
@@ -661,7 +663,20 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
661663
}
662664
}
663665

664-
let llret = self.call(fn_ty, None, None, fn_ptr, &llargs, None, None);
666+
debug!("call intrinsic {:?} with args ({:?})", instance, llargs);
667+
let args = self.check_call("call", fn_ty, fn_ptr, &llargs);
668+
let llret = unsafe {
669+
llvm::LLVMBuildCallWithOperandBundles(
670+
self.llbuilder,
671+
fn_ty,
672+
fn_ptr,
673+
args.as_ptr() as *const &llvm::Value,
674+
args.len() as c_uint,
675+
ptr::dangling(),
676+
0,
677+
c"".as_ptr(),
678+
)
679+
};
665680
if is_cleanup {
666681
self.apply_attrs_to_cleanup_callsite(llret);
667682
}

0 commit comments

Comments
 (0)