Skip to content

Commit dfa88b3

Browse files
committedFeb 16, 2024·
Auto merge of #120500 - oli-obk:intrinsics2.0, r=WaffleLapkin
Implement intrinsics with fallback bodies fixes #93145 (though we can port many more intrinsics) cc #63585 The way this works is that the backend logic for generating custom code for intrinsics has been made fallible. The only failure path is "this intrinsic is unknown". The `Instance` (that was `InstanceDef::Intrinsic`) then gets converted to `InstanceDef::Item`, which represents the fallback body. A regular function call to that body is then codegenned. This is currently implemented for * codegen_ssa (so llvm and gcc) * codegen_cranelift other backends will need to adjust, but they can just keep doing what they were doing if they prefer (though adding new intrinsics to the compiler will then require them to implement them, instead of getting the fallback body). cc `@scottmcm` `@WaffleLapkin` ### todo * [ ] miri support * [x] default intrinsic name to name of function instead of requiring it to be specified in attribute * [x] make sure that the bodies are always available (must be collected for metadata)
2 parents 1be4688 + 164b9c3 commit dfa88b3

File tree

49 files changed

+620
-451
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+620
-451
lines changed
 

‎compiler/rustc_borrowck/src/type_check/mod.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -1666,16 +1666,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
16661666

16671667
let func_ty = func.ty(body, self.infcx.tcx);
16681668
if let ty::FnDef(def_id, _) = *func_ty.kind() {
1669-
if self.tcx().is_intrinsic(def_id) {
1670-
match self.tcx().item_name(def_id) {
1671-
sym::simd_shuffle => {
1672-
if !matches!(args[2], Spanned { node: Operand::Constant(_), .. }) {
1673-
self.tcx()
1674-
.dcx()
1675-
.emit_err(SimdShuffleLastConst { span: term.source_info.span });
1676-
}
1677-
}
1678-
_ => {}
1669+
if let Some(sym::simd_shuffle) = self.tcx().intrinsic(def_id) {
1670+
if !matches!(args[2], Spanned { node: Operand::Constant(_), .. }) {
1671+
self.tcx().dcx().emit_err(SimdShuffleLastConst { span: term.source_info.span });
16791672
}
16801673
}
16811674
}

‎compiler/rustc_codegen_cranelift/src/abi/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -387,15 +387,17 @@ pub(crate) fn codegen_terminator_call<'tcx>(
387387

388388
match instance.def {
389389
InstanceDef::Intrinsic(_) => {
390-
crate::intrinsics::codegen_intrinsic_call(
390+
match crate::intrinsics::codegen_intrinsic_call(
391391
fx,
392392
instance,
393393
args,
394394
ret_place,
395395
target,
396396
source_info,
397-
);
398-
return;
397+
) {
398+
Ok(()) => return,
399+
Err(instance) => Some(instance),
400+
}
399401
}
400402
InstanceDef::DropGlue(_, None) => {
401403
// empty drop glue - a nop.

0 commit comments

Comments
 (0)
Please sign in to comment.