@@ -200,6 +200,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
200
200
201
201
fn invoke (
202
202
& mut self ,
203
+ llty : & ' ll Type ,
203
204
llfn : & ' ll Value ,
204
205
args : & [ & ' ll Value ] ,
205
206
then : & ' ll BasicBlock ,
@@ -208,13 +209,14 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
208
209
) -> & ' ll Value {
209
210
debug ! ( "invoke {:?} with args ({:?})" , llfn, args) ;
210
211
211
- let args = self . check_call ( "invoke" , llfn, args) ;
212
+ let args = self . check_call ( "invoke" , llty , llfn, args) ;
212
213
let bundle = funclet. map ( |funclet| funclet. bundle ( ) ) ;
213
214
let bundle = bundle. as_ref ( ) . map ( |b| & * b. raw ) ;
214
215
215
216
unsafe {
216
217
llvm:: LLVMRustBuildInvoke (
217
218
self . llbuilder ,
219
+ llty,
218
220
llfn,
219
221
args. as_ptr ( ) ,
220
222
args. len ( ) as c_uint ,
@@ -369,8 +371,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
369
371
} ,
370
372
} ;
371
373
372
- let intrinsic = self . get_intrinsic ( & name) ;
373
- let res = self . call ( intrinsic, & [ lhs, rhs] , None ) ;
374
+ let res = self . call_intrinsic ( name, & [ lhs, rhs] ) ;
374
375
( self . extract_value ( res, 0 ) , self . extract_value ( res, 1 ) )
375
376
}
376
377
@@ -695,8 +696,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
695
696
let float_width = self . cx . float_width ( src_ty) ;
696
697
let int_width = self . cx . int_width ( dest_ty) ;
697
698
let name = format ! ( "llvm.fptoui.sat.i{}.f{}" , int_width, float_width) ;
698
- let intrinsic = self . get_intrinsic ( & name) ;
699
- return Some ( self . call ( intrinsic, & [ val] , None ) ) ;
699
+ return Some ( self . call_intrinsic ( & name, & [ val] ) ) ;
700
700
}
701
701
702
702
None
@@ -708,8 +708,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
708
708
let float_width = self . cx . float_width ( src_ty) ;
709
709
let int_width = self . cx . int_width ( dest_ty) ;
710
710
let name = format ! ( "llvm.fptosi.sat.i{}.f{}" , int_width, float_width) ;
711
- let intrinsic = self . get_intrinsic ( & name) ;
712
- return Some ( self . call ( intrinsic, & [ val] , None ) ) ;
711
+ return Some ( self . call_intrinsic ( & name, & [ val] ) ) ;
713
712
}
714
713
715
714
None
@@ -743,8 +742,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
743
742
_ => None ,
744
743
} ;
745
744
if let Some ( name) = name {
746
- let intrinsic = self . get_intrinsic ( name) ;
747
- return self . call ( intrinsic, & [ val] , None ) ;
745
+ return self . call_intrinsic ( name, & [ val] ) ;
748
746
}
749
747
}
750
748
}
@@ -766,8 +764,7 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
766
764
_ => None ,
767
765
} ;
768
766
if let Some ( name) = name {
769
- let intrinsic = self . get_intrinsic ( name) ;
770
- return self . call ( intrinsic, & [ val] , None ) ;
767
+ return self . call_intrinsic ( name, & [ val] ) ;
771
768
}
772
769
}
773
770
}
@@ -1115,12 +1112,17 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
1115
1112
) ;
1116
1113
1117
1114
let llfn = unsafe { llvm:: LLVMRustGetInstrProfIncrementIntrinsic ( self . cx ( ) . llmod ) } ;
1115
+ let llty = self . cx . type_func (
1116
+ & [ self . cx . type_i8p ( ) , self . cx . type_i64 ( ) , self . cx . type_i32 ( ) , self . cx . type_i32 ( ) ] ,
1117
+ self . cx . type_void ( ) ,
1118
+ ) ;
1118
1119
let args = & [ fn_name, hash, num_counters, index] ;
1119
- let args = self . check_call ( "call" , llfn, args) ;
1120
+ let args = self . check_call ( "call" , llty , llfn, args) ;
1120
1121
1121
1122
unsafe {
1122
1123
let _ = llvm:: LLVMRustBuildCall (
1123
1124
self . llbuilder ,
1125
+ llty,
1124
1126
llfn,
1125
1127
args. as_ptr ( ) as * const & llvm:: Value ,
1126
1128
args. len ( ) as c_uint ,
@@ -1131,19 +1133,21 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
1131
1133
1132
1134
fn call (
1133
1135
& mut self ,
1136
+ llty : & ' ll Type ,
1134
1137
llfn : & ' ll Value ,
1135
1138
args : & [ & ' ll Value ] ,
1136
1139
funclet : Option < & Funclet < ' ll > > ,
1137
1140
) -> & ' ll Value {
1138
1141
debug ! ( "call {:?} with args ({:?})" , llfn, args) ;
1139
1142
1140
- let args = self . check_call ( "call" , llfn, args) ;
1143
+ let args = self . check_call ( "call" , llty , llfn, args) ;
1141
1144
let bundle = funclet. map ( |funclet| funclet. bundle ( ) ) ;
1142
1145
let bundle = bundle. as_ref ( ) . map ( |b| & * b. raw ) ;
1143
1146
1144
1147
unsafe {
1145
1148
llvm:: LLVMRustBuildCall (
1146
1149
self . llbuilder ,
1150
+ llty,
1147
1151
llfn,
1148
1152
args. as_ptr ( ) as * const & llvm:: Value ,
1149
1153
args. len ( ) as c_uint ,
@@ -1313,15 +1317,10 @@ impl Builder<'a, 'll, 'tcx> {
1313
1317
fn check_call < ' b > (
1314
1318
& mut self ,
1315
1319
typ : & str ,
1320
+ fn_ty : & ' ll Type ,
1316
1321
llfn : & ' ll Value ,
1317
1322
args : & ' b [ & ' ll Value ] ,
1318
1323
) -> Cow < ' b , [ & ' ll Value ] > {
1319
- let mut fn_ty = self . cx . val_ty ( llfn) ;
1320
- // Strip off pointers
1321
- while self . cx . type_kind ( fn_ty) == TypeKind :: Pointer {
1322
- fn_ty = self . cx . element_type ( fn_ty) ;
1323
- }
1324
-
1325
1324
assert ! (
1326
1325
self . cx. type_kind( fn_ty) == TypeKind :: Function ,
1327
1326
"builder::{} not passed a function, but {:?}" ,
@@ -1362,6 +1361,11 @@ impl Builder<'a, 'll, 'tcx> {
1362
1361
unsafe { llvm:: LLVMBuildVAArg ( self . llbuilder , list, ty, UNNAMED ) }
1363
1362
}
1364
1363
1364
+ crate fn call_intrinsic ( & mut self , intrinsic : & str , args : & [ & ' ll Value ] ) -> & ' ll Value {
1365
+ let ( ty, f) = self . cx . get_intrinsic ( intrinsic) ;
1366
+ self . call ( ty, f, args, None )
1367
+ }
1368
+
1365
1369
fn call_lifetime_intrinsic ( & mut self , intrinsic : & str , ptr : & ' ll Value , size : Size ) {
1366
1370
let size = size. bytes ( ) ;
1367
1371
if size == 0 {
@@ -1372,10 +1376,8 @@ impl Builder<'a, 'll, 'tcx> {
1372
1376
return ;
1373
1377
}
1374
1378
1375
- let lifetime_intrinsic = self . cx . get_intrinsic ( intrinsic) ;
1376
-
1377
1379
let ptr = self . pointercast ( ptr, self . cx . type_i8p ( ) ) ;
1378
- self . call ( lifetime_intrinsic , & [ self . cx . const_u64 ( size) , ptr] , None ) ;
1380
+ self . call_intrinsic ( intrinsic , & [ self . cx . const_u64 ( size) , ptr] ) ;
1379
1381
}
1380
1382
1381
1383
pub ( crate ) fn phi (
0 commit comments