@@ -309,7 +309,7 @@ impl<'ll, 'tcx> ArgAbiBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
309
309
}
310
310
311
311
pub ( crate ) trait FnAbiLlvmExt < ' ll , ' tcx > {
312
- fn llvm_type ( & self , cx : & CodegenCx < ' ll , ' tcx > ) -> & ' ll Type ;
312
+ fn llvm_type ( & self , cx : & CodegenCx < ' ll , ' tcx > , name : & [ u8 ] ) -> & ' ll Type ;
313
313
fn ptr_to_llvm_type ( & self , cx : & CodegenCx < ' ll , ' tcx > ) -> & ' ll Type ;
314
314
fn llvm_cconv ( & self , cx : & CodegenCx < ' ll , ' tcx > ) -> llvm:: CallConv ;
315
315
@@ -326,20 +326,22 @@ pub(crate) trait FnAbiLlvmExt<'ll, 'tcx> {
326
326
}
327
327
328
328
impl < ' ll , ' tcx > FnAbiLlvmExt < ' ll , ' tcx > for FnAbi < ' tcx , Ty < ' tcx > > {
329
- fn llvm_type ( & self , cx : & CodegenCx < ' ll , ' tcx > ) -> & ' ll Type {
329
+ fn llvm_type ( & self , cx : & CodegenCx < ' ll , ' tcx > , name : & [ u8 ] ) -> & ' ll Type {
330
330
// Ignore "extra" args from the call site for C variadic functions.
331
331
// Only the "fixed" args are part of the LLVM function signature.
332
332
let args =
333
333
if self . c_variadic { & self . args [ ..self . fixed_count as usize ] } else { & self . args } ;
334
334
335
+ // todo(sayantn): a better way is to look at the `link_name` instead of the function name, because function name can be "faked" using `#[export_name]`
336
+ let llvm_intrinsic = name. starts_with ( b"llvm." )
337
+ && !self . c_variadic
338
+ && self . conv == Conv :: C
339
+ && !self . can_unwind ;
340
+ let amx_intrinsic =
341
+ llvm_intrinsic && name. starts_with ( b"llvm.x86." ) && name. ends_with ( b".internal" ) ;
335
342
let adjust_ty = |ty| {
336
- // todo: rectify this to be more selective (help wanted)
337
- let probably_unadjusted = self . conv == Conv :: C && !self . can_unwind && !self . c_variadic ;
338
- let probably_amx_intrinsic = probably_unadjusted && cx. tcx . sess . target . arch == "x86_64" ;
339
343
// Change type to `x86amx` from `i32x256` for x86_64 AMX intrinsics
340
- if probably_amx_intrinsic
341
- && cx. type_kind ( ty) == TypeKind :: Vector
342
- && cx. vector_length ( ty) == 256
344
+ if amx_intrinsic && cx. type_kind ( ty) == TypeKind :: Vector && cx. vector_length ( ty) == 256
343
345
{
344
346
let element_ty = cx. element_type ( ty) ;
345
347
if cx. type_kind ( element_ty) == TypeKind :: Integer && cx. int_width ( element_ty) == 32 {
0 commit comments