@@ -31,8 +31,9 @@ use tracing::{debug, instrument, warn};
3131
3232use crate :: abi:: FnAbiLlvmExt ;
3333use crate :: attributes;
34- use crate :: common:: { AsCCharPtr , Funclet } ;
34+ use crate :: common:: Funclet ;
3535use crate :: context:: { CodegenCx , FullCx , GenericCx , SCx } ;
36+ use crate :: declare:: declare_simple_fn;
3637use crate :: llvm:: {
3738 self , AtomicOrdering , AtomicRmwBinOp , BasicBlock , False , GEPNoWrapFlags , Metadata , True ,
3839} ;
@@ -57,39 +58,6 @@ impl<'a, 'll, CX: Borrow<SCx<'ll>>> Drop for GenericBuilder<'a, 'll, CX> {
5758 }
5859}
5960
60- impl < ' a , ' ll > SBuilder < ' a , ' ll > {
61- pub ( crate ) fn call (
62- & mut self ,
63- llty : & ' ll Type ,
64- llfn : & ' ll Value ,
65- args : & [ & ' ll Value ] ,
66- funclet : Option < & Funclet < ' ll > > ,
67- ) -> & ' ll Value {
68- debug ! ( "call {:?} with args ({:?})" , llfn, args) ;
69-
70- let args = self . cast_arguments ( "call" , llty, llfn, args, false ) ;
71- let funclet_bundle = funclet. map ( |funclet| funclet. bundle ( ) ) ;
72- let mut bundles: SmallVec < [ _ ; 2 ] > = SmallVec :: new ( ) ;
73- if let Some ( funclet_bundle) = funclet_bundle {
74- bundles. push ( funclet_bundle) ;
75- }
76-
77- let call = unsafe {
78- llvm:: LLVMBuildCallWithOperandBundles (
79- self . llbuilder ,
80- llty,
81- llfn,
82- args. as_ptr ( ) ,
83- args. len ( ) as c_uint ,
84- bundles. as_ptr ( ) ,
85- bundles. len ( ) as c_uint ,
86- c"" . as_ptr ( ) ,
87- )
88- } ;
89- call
90- }
91- }
92-
9361impl < ' a , ' ll , CX : Borrow < SCx < ' ll > > > GenericBuilder < ' a , ' ll , CX > {
9462 fn with_cx ( scx : & ' a GenericCx < ' ll , CX > ) -> Self {
9563 // Create a fresh builder from the simple context.
@@ -1610,31 +1578,33 @@ impl<'a, 'll, CX: Borrow<SCx<'ll>>> GenericBuilder<'a, 'll, CX> {
16101578
16111579 pub ( crate ) fn simple_call (
16121580 & mut self ,
1613- name : & [ u8 ] ,
1614- fn_ty : & ' ll Type ,
1581+ llty : & ' ll Type ,
1582+ llfn : & ' ll Value ,
16151583 args : & [ & ' ll Value ] ,
1584+ funclet : Option < & Funclet < ' ll > > ,
16161585 ) -> & ' ll Value {
1617- let llfn = unsafe {
1618- llvm:: LLVMRustGetOrInsertFunction (
1619- self . cx . llmod ( ) ,
1620- name. as_c_char_ptr ( ) ,
1621- name. len ( ) ,
1622- fn_ty,
1623- )
1624- } ;
1586+ debug ! ( "simple_call {:?} with args ({:?})" , llfn, args) ;
16251587
1626- let args = self . cast_arguments ( "simple_call" , fn_ty, llfn, args, false ) ;
1588+ let args = self . cast_arguments ( "simple_call" , llty, llfn, args, false ) ;
1589+ let funclet_bundle = funclet. map ( |funclet| funclet. bundle ( ) ) ;
1590+ let mut bundles: SmallVec < [ _ ; 2 ] > = SmallVec :: new ( ) ;
1591+ if let Some ( funclet_bundle) = funclet_bundle {
1592+ bundles. push ( funclet_bundle) ;
1593+ }
16271594
1628- unsafe {
1629- llvm:: LLVMBuildCall2 (
1595+ let call = unsafe {
1596+ llvm:: LLVMBuildCallWithOperandBundles (
16301597 self . llbuilder ,
1631- fn_ty ,
1598+ llty ,
16321599 llfn,
16331600 args. as_ptr ( ) ,
1634- args. len ( ) as _ ,
1601+ args. len ( ) as c_uint ,
1602+ bundles. as_ptr ( ) ,
1603+ bundles. len ( ) as c_uint ,
16351604 c"" . as_ptr ( ) ,
16361605 )
1637- }
1606+ } ;
1607+ call
16381608 }
16391609
16401610 pub ( crate ) fn call_intrinsic (
@@ -1651,13 +1621,23 @@ impl<'a, 'll, CX: Borrow<SCx<'ll>>> GenericBuilder<'a, 'll, CX> {
16511621 let fn_ty = self . cx . intrinsic_type ( intrinsic, type_params) ;
16521622
16531623 let full_name = if intrinsic. is_overloaded ( ) {
1624+ assert ! ( !type_params. is_empty( ) ) ;
16541625 & intrinsic. overloaded_name ( self . cx . llmod ( ) , type_params)
16551626 } else {
16561627 assert ! ( type_params. is_empty( ) ) ;
16571628 base_name. as_bytes ( )
16581629 } ;
16591630
1660- self . simple_call ( full_name, fn_ty, args)
1631+ let llfn = declare_simple_fn (
1632+ self . cx ,
1633+ full_name,
1634+ llvm:: CCallConv ,
1635+ llvm:: UnnamedAddr :: No ,
1636+ llvm:: Visibility :: Default ,
1637+ fn_ty,
1638+ ) ;
1639+
1640+ self . simple_call ( fn_ty, llfn, args, None )
16611641 }
16621642}
16631643
@@ -1710,7 +1690,9 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
17101690 let fn_ty =
17111691 self . type_func ( & [ self . type_ptr ( ) , self . type_ptr ( ) , self . type_isize ( ) ] , llreturn_ty) ;
17121692
1713- self . simple_call ( b"memcmp" , fn_ty, & [ ptr1, ptr2, num] )
1693+ let llfn = self . declare_cfn ( "memcmp" , llvm:: UnnamedAddr :: No , fn_ty) ;
1694+
1695+ self . simple_call ( fn_ty, llfn, & [ ptr1, ptr2, num] , None )
17141696 }
17151697
17161698 fn cast_return (
0 commit comments