Skip to content

Commit 7f4aee7

Browse files
committed
Require backends to opt into implementing an intrinsic that has a fallback body
1 parent 74c0931 commit 7f4aee7

File tree

9 files changed

+39
-11
lines changed

9 files changed

+39
-11
lines changed

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,6 @@ fn codegen_regular_intrinsic_call<'tcx>(
443443

444444
ret.write_cvalue(fx, a);
445445
}
446-
sym::is_val_statically_known => {
447-
intrinsic_args!(fx, args => (_a); intrinsic);
448-
449-
let res = fx.bcx.ins().iconst(types::I8, 0);
450-
ret.write_cvalue(fx, CValue::by_val(res, ret.layout()));
451-
}
452446
sym::breakpoint => {
453447
intrinsic_args!(fx, args => (); intrinsic);
454448

compiler/rustc_codegen_cranelift/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ impl CodegenBackend for CraneliftCodegenBackend {
248248

249249
link_binary(sess, &crate::archive::ArArchiveBuilderBuilder, &codegen_results, outputs)
250250
}
251+
252+
fn implemented_intrinsics(&self) -> &'static [Symbol] {
253+
&[]
254+
}
251255
}
252256

253257
fn target_triple(sess: &Session) -> target_lexicon::Triple {

compiler/rustc_codegen_gcc/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ use rustc_session::Session;
110110
use rustc_span::Symbol;
111111
use rustc_span::fatal_error::FatalError;
112112
use tempfile::TempDir;
113+
use rustc_span::sym;
113114

114115
use crate::back::lto::ModuleBuffer;
115116
use crate::gcc_util::target_cpu;
@@ -242,6 +243,10 @@ impl CodegenBackend for GccCodegenBackend {
242243
fn target_features(&self, sess: &Session, allow_unstable: bool) -> Vec<Symbol> {
243244
target_features(sess, allow_unstable, &self.target_info)
244245
}
246+
247+
fn implemented_intrinsics(&self) -> &'static [Symbol] {
248+
&[sym::is_val_statically_known]
249+
}
245250
}
246251

247252
fn new_context<'gcc, 'tcx>(tcx: TyCtxt<'tcx>) -> Context<'gcc> {

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ use rustc_middle::ty::TyCtxt;
4444
use rustc_middle::util::Providers;
4545
use rustc_session::config::{OptLevel, OutputFilenames, PrintKind, PrintRequest};
4646
use rustc_session::Session;
47+
use rustc_span::sym;
4748
use rustc_span::symbol::Symbol;
4849

4950
use std::any::Any;
@@ -401,6 +402,10 @@ impl CodegenBackend for LlvmCodegenBackend {
401402
// This should produce either a finished executable or library.
402403
link_binary(sess, &LlvmArchiveBuilderBuilder, &codegen_results, outputs)
403404
}
405+
406+
fn implemented_intrinsics(&self) -> &'static [Symbol] {
407+
&[sym::is_val_statically_known]
408+
}
404409
}
405410

406411
pub struct ModuleLlvm {

compiler/rustc_codegen_ssa/src/traits/backend.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ pub trait CodegenBackend {
111111
codegen_results: CodegenResults,
112112
outputs: &OutputFilenames,
113113
) -> Result<(), ErrorGuaranteed>;
114+
115+
/// Returns the list of intrinsics that should not use their fallback body
116+
fn implemented_intrinsics(&self) -> &'static [Symbol];
114117
}
115118

116119
pub trait ExtraBackendMethods:

compiler/rustc_interface/src/queries.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ impl<'tcx> Queries<'tcx> {
165165
feed.crate_name(crate_name);
166166

167167
let feed = tcx.feed_unit_query();
168+
feed.intrinsics_implemented_by_backend(
169+
self.compiler.codegen_backend.implemented_intrinsics(),
170+
);
168171
feed.features_query(tcx.arena.alloc(rustc_expand::config::features(
169172
sess,
170173
&pre_configured_attrs,

compiler/rustc_middle/src/query/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,6 +2105,11 @@ rustc_queries! {
21052105
desc { "looking up enabled feature gates" }
21062106
}
21072107

2108+
query intrinsics_implemented_by_backend(_: ()) -> &'static [Symbol] {
2109+
feedable
2110+
desc { "list of intrinsics with default bodies supported by the codegen backend" }
2111+
}
2112+
21082113
query crate_for_resolver((): ()) -> &'tcx Steal<(rustc_ast::Crate, rustc_ast::AttrVec)> {
21092114
feedable
21102115
no_hash

compiler/rustc_middle/src/ty/util.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,12 +1544,12 @@ pub fn intrinsic(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<Symbol> {
15441544
{
15451545
Some(tcx.item_name(def_id.into()))
15461546
} else if let Some(name) = tcx.get_attr(def_id, sym::rustc_intrinsic) {
1547-
Some(
1547+
let name =
15481548
name.get_normal_item().meta(rustc_span::DUMMY_SP).unwrap().meta_item_list().unwrap()[0]
15491549
.ident()
15501550
.unwrap()
1551-
.name,
1552-
)
1551+
.name;
1552+
tcx.intrinsics_implemented_by_backend(()).contains(&name).then_some(name)
15531553
} else {
15541554
None
15551555
}

tests/run-make-fulldeps/hotplug_codegen_backend/the_backend.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ use std::any::Any;
2727
struct TheBackend;
2828

2929
impl CodegenBackend for TheBackend {
30-
fn locale_resource(&self) -> &'static str { "" }
30+
fn locale_resource(&self) -> &'static str {
31+
""
32+
}
3133

3234
fn codegen_crate<'a, 'tcx>(
3335
&self,
@@ -62,7 +64,10 @@ impl CodegenBackend for TheBackend {
6264
codegen_results: CodegenResults,
6365
outputs: &OutputFilenames,
6466
) -> Result<(), ErrorGuaranteed> {
65-
use rustc_session::{config::{CrateType, OutFileName}, output::out_filename};
67+
use rustc_session::{
68+
config::{CrateType, OutFileName},
69+
output::out_filename,
70+
};
6671
use std::io::Write;
6772
let crate_name = codegen_results.crate_info.local_crate_name;
6873
for &crate_type in sess.opts.crate_types.iter() {
@@ -83,6 +88,10 @@ impl CodegenBackend for TheBackend {
8388
}
8489
Ok(())
8590
}
91+
92+
fn implemented_intrinsics(&self) -> &'static [Symbol] {
93+
&[]
94+
}
8695
}
8796

8897
/// This is the entrypoint for a hot plugged rustc_codegen_llvm

0 commit comments

Comments
 (0)