@@ -646,7 +646,47 @@ 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_val = self . get_fn ( instance) ;
649+ let func = if let Some ( & func) = self . intrinsic_instances . borrow ( ) . get ( & instance) {
650+ func
651+ } else {
652+ let sym = self . tcx . symbol_name ( instance) . name ;
653+
654+ let func = if let Some ( func) = self . intrinsics . borrow ( ) . get ( sym) {
655+ * func
656+ } else {
657+ self . linkage . set ( FunctionType :: Extern ) ;
658+ let fn_abi = self . fn_abi_of_instance ( instance, ty:: List :: empty ( ) ) ;
659+ let fn_ty = fn_abi. gcc_type ( self ) ;
660+
661+ let func = match sym {
662+ "llvm.fma.f16" => {
663+ // fma is not a target builtin, but a normal builtin, so we handle it differently
664+ // here.
665+ self . context . get_builtin_function ( "fma" )
666+ }
667+ _ => llvm:: intrinsic ( sym, self ) ,
668+ } ;
669+
670+ self . intrinsics . borrow_mut ( ) . insert ( sym. to_string ( ) , func) ;
671+
672+ self . on_stack_function_params
673+ . borrow_mut ( )
674+ . insert ( func, fn_ty. on_stack_param_indices ) ;
675+ #[ cfg( feature = "master" ) ]
676+ for fn_attr in fn_ty. fn_attributes {
677+ func. add_attribute ( fn_attr) ;
678+ }
679+
680+ crate :: attributes:: from_fn_attrs ( self , func, instance) ;
681+
682+ func
683+ } ;
684+
685+ self . intrinsic_instances . borrow_mut ( ) . insert ( instance, func) ;
686+
687+ func
688+ } ;
689+ * self . current_func . borrow_mut ( ) = Some ( func) ;
650690
651691 let mut llargs = vec ! [ ] ;
652692
@@ -679,7 +719,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
679719 }
680720
681721 // FIXME directly use the llvm intrinsic adjustment functions here
682- let llret = self . function_call ( fn_val , & llargs, None ) ;
722+ let llret = self . function_call ( func , & llargs, None ) ;
683723 if is_cleanup {
684724 self . apply_attrs_to_cleanup_callsite ( llret) ;
685725 }
0 commit comments