Skip to content

Commit afb14f7

Browse files
Unpin compiler-builtins
Co-authored-by: Antoni Boucher <[email protected]>
1 parent 3b45cf4 commit afb14f7

File tree

8 files changed

+54
-69
lines changed

8 files changed

+54
-69
lines changed

.github/workflows/m68k.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ jobs:
8585
- name: Build sample project with target defined as JSON spec
8686
run: |
8787
./y.sh prepare --only-libcore --cross
88-
./y.sh build --sysroot --target-triple m68k-unknown-linux-gnu --target ${{ github.workspace }}/target_specs/m68k-unknown-linux-gnu.json
88+
./y.sh build --sysroot --features compiler_builtins/no-f16-f128 --target-triple m68k-unknown-linux-gnu --target ${{ github.workspace }}/target_specs/m68k-unknown-linux-gnu.json
8989
./y.sh cargo build --manifest-path=./tests/hello-world/Cargo.toml --target ${{ github.workspace }}/target_specs/m68k-unknown-linux-gnu.json
9090
./y.sh clean all
9191
9292
- name: Build
9393
run: |
9494
./y.sh prepare --only-libcore --cross
95-
./y.sh build --sysroot --target-triple m68k-unknown-linux-gnu
95+
./y.sh build --sysroot --features compiler_builtins/no-f16-f128 --target-triple m68k-unknown-linux-gnu
9696
CG_GCC_TEST_TARGET=m68k-unknown-linux-gnu cargo test
9797
./y.sh clean all
9898
@@ -107,4 +107,4 @@ jobs:
107107

108108
- name: Run tests
109109
run: |
110-
./y.sh test --release --clean --build-sysroot ${{ matrix.commands }}
110+
./y.sh test --release --clean --build-sysroot --sysroot-features compiler_builtins/no-f16-f128 ${{ matrix.commands }}

build_system/build_sysroot/Cargo.toml

+16
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,22 @@ rustc-std-workspace-core = { path = "./sysroot_src/library/rustc-std-workspace-c
1717
rustc-std-workspace-alloc = { path = "./sysroot_src/library/rustc-std-workspace-alloc" }
1818
rustc-std-workspace-std = { path = "./sysroot_src/library/rustc-std-workspace-std" }
1919

20+
# For compiler-builtins we always use a high number of codegen units.
21+
# The goal here is to place every single intrinsic into its own object
22+
# file to avoid symbol clashes with the system libgcc if possible. Note
23+
# that this number doesn't actually produce this many object files, we
24+
# just don't create more than this number of object files.
25+
#
26+
# It's a bit of a bummer that we have to pass this here, unfortunately.
27+
# Ideally this would be specified through an env var to Cargo so Cargo
28+
# knows how many CGUs are for this specific crate, but for now
29+
# per-crate configuration isn't specifiable in the environment.
30+
[profile.dev.package.compiler_builtins]
31+
codegen-units = 10000
32+
33+
[profile.release.package.compiler_builtins]
34+
codegen-units = 10000
35+
2036
[profile.release]
2137
debug = "limited"
2238
#lto = "fat" # TODO(antoyo): re-enable when the failing LTO tests regarding proc-macros are fixed.

build_system/src/build.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,6 @@ impl BuildArg {
2424

2525
while let Some(arg) = args.next() {
2626
match arg.as_str() {
27-
"--features" => {
28-
if let Some(arg) = args.next() {
29-
build_arg.flags.push("--features".to_string());
30-
build_arg.flags.push(arg.as_str().into());
31-
} else {
32-
return Err(
33-
"Expected a value after `--features`, found nothing".to_string()
34-
);
35-
}
36-
}
3727
"--sysroot" => {
3828
build_arg.build_sysroot = true;
3929
}
@@ -56,7 +46,6 @@ impl BuildArg {
5646
r#"
5747
`build` command help:
5848
59-
--features [arg] : Add a new feature [arg]
6049
--sysroot : Build with sysroot"#
6150
);
6251
ConfigInfo::show_usage();
@@ -150,6 +139,10 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
150139
&"--features",
151140
&"std/compiler-builtins-no-f16-f128",
152141
];
142+
for feature in &config.features {
143+
args.push(&"--features");
144+
args.push(feature);
145+
}
153146

154147
if config.no_default_features {
155148
rustflags.push_str(" -Csymbol-mangling-version=v0");

build_system/src/config.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl ConfigFile {
9898
}
9999
}
100100

101-
#[derive(Default, Debug)]
101+
#[derive(Default, Debug, Clone)]
102102
pub struct ConfigInfo {
103103
pub target: String,
104104
pub target_triple: String,
@@ -123,6 +123,7 @@ pub struct ConfigInfo {
123123
pub no_download: bool,
124124
pub no_default_features: bool,
125125
pub backend: Option<String>,
126+
pub features: Vec<String>,
126127
}
127128

128129
impl ConfigInfo {
@@ -133,6 +134,13 @@ impl ConfigInfo {
133134
args: &mut impl Iterator<Item = String>,
134135
) -> Result<bool, String> {
135136
match arg {
137+
"--features" => {
138+
if let Some(arg) = args.next() {
139+
self.features.push(arg);
140+
} else {
141+
return Err("Expected a value after `--features`, found nothing".to_string());
142+
}
143+
}
136144
"--target" => {
137145
if let Some(arg) = args.next() {
138146
self.target = arg;
@@ -443,6 +451,7 @@ impl ConfigInfo {
443451
pub fn show_usage() {
444452
println!(
445453
"\
454+
--features [arg] : Add a new feature [arg]
446455
--target-triple [arg] : Set the target triple to [arg]
447456
--target [arg] : Set the target to [arg]
448457
--out-dir : Location where the files will be generated

build_system/src/test.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ struct TestArg {
9292
current_part: Option<usize>,
9393
sysroot_panic_abort: bool,
9494
config_info: ConfigInfo,
95+
sysroot_features: Vec<String>,
9596
}
9697

9798
impl TestArg {
@@ -127,6 +128,14 @@ impl TestArg {
127128
"--sysroot-panic-abort" => {
128129
test_arg.sysroot_panic_abort = true;
129130
}
131+
"--sysroot-features" => match args.next() {
132+
Some(feature) if !feature.is_empty() => {
133+
test_arg.sysroot_features.push(feature);
134+
}
135+
_ => {
136+
return Err(format!("Expected an argument after `{}`, found nothing", arg))
137+
}
138+
},
130139
"--help" => {
131140
show_usage();
132141
return Ok(None);
@@ -250,7 +259,9 @@ fn mini_tests(env: &Env, args: &TestArg) -> Result<(), String> {
250259
fn build_sysroot(env: &Env, args: &TestArg) -> Result<(), String> {
251260
// FIXME: create a function "display_if_not_quiet" or something along the line.
252261
println!("[BUILD] sysroot");
253-
build::build_sysroot(env, &args.config_info)?;
262+
let mut config = args.config_info.clone();
263+
config.features.extend(args.sysroot_features.iter().cloned());
264+
build::build_sysroot(env, &config)?;
254265
Ok(())
255266
}
256267

src/context.rs

-34
Original file line numberDiff line numberDiff line change
@@ -227,48 +227,14 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
227227
"__builtin_umul_overflow",
228228
"__builtin_usubll_overflow",
229229
"__builtin_usub_overflow",
230-
"sqrtf",
231-
"sqrt",
232230
"__builtin_powif",
233231
"__builtin_powi",
234-
"sinf",
235-
"sin",
236-
"cosf",
237-
"cos",
238-
"powf",
239-
"pow",
240-
"expf",
241-
"exp",
242-
"exp2f",
243-
"exp2",
244-
"logf",
245-
"log",
246-
"log10f",
247-
"log10",
248-
"log2f",
249-
"log2",
250-
"fmaf",
251-
"fma",
252232
"fabsf",
253233
"fabs",
254-
"fminf",
255-
"fmin",
256-
"fmaxf",
257-
"fmax",
258234
"copysignf",
259235
"copysign",
260-
"floorf",
261-
"floor",
262-
"ceilf",
263-
"ceil",
264-
"truncf",
265-
"trunc",
266-
"rintf",
267-
"rint",
268236
"nearbyintf",
269237
"nearbyint",
270-
"roundf",
271-
"round",
272238
];
273239

274240
for builtin in builtins.iter() {

src/intrinsic/mod.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -127,20 +127,13 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
127127
// https://github.com/rust-lang/rust-clippy/issues/12497
128128
// and leave `else if use_integer_compare` to be placed "as is".
129129
#[allow(clippy::suspicious_else_formatting)]
130-
let llval = match name {
130+
let value = match name {
131131
_ if simple.is_some() => {
132-
// FIXME(antoyo): remove this cast when the API supports function.
133-
let func = unsafe {
134-
std::mem::transmute::<Function<'gcc>, RValue<'gcc>>(simple.expect("simple"))
135-
};
136-
self.call(
137-
self.type_void(),
138-
None,
139-
None,
132+
let func = simple.expect("simple function");
133+
self.cx.context.new_call(
134+
self.location,
140135
func,
141136
&args.iter().map(|arg| arg.immediate()).collect::<Vec<_>>(),
142-
None,
143-
None,
144137
)
145138
}
146139
sym::likely => self.expect(args[0].immediate(), true),
@@ -383,7 +376,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
383376

384377
_ if name_str.starts_with("simd_") => {
385378
match generic_simd_intrinsic(self, name, callee_ty, args, ret_ty, llret_ty, span) {
386-
Ok(llval) => llval,
379+
Ok(value) => value,
387380
Err(()) => return Ok(()),
388381
}
389382
}
@@ -396,9 +389,9 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
396389
if let PassMode::Cast { cast: ref ty, .. } = fn_abi.ret.mode {
397390
let ptr_llty = self.type_ptr_to(ty.gcc_type(self));
398391
let ptr = self.pointercast(result.val.llval, ptr_llty);
399-
self.store(llval, ptr, result.val.align);
392+
self.store(value, ptr, result.val.align);
400393
} else {
401-
OperandRef::from_immediate_or_packed_pair(self, llval, result.layout)
394+
OperandRef::from_immediate_or_packed_pair(self, value, result.layout)
402395
.val
403396
.store(self, result);
404397
}

src/intrinsic/simd.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -763,10 +763,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
763763
_ => return_error!(InvalidMonomorphization::UnrecognizedIntrinsic { span, name }),
764764
};
765765
let builtin_name = format!("{}{}", intr_name, elem_ty_str);
766-
let funcs = bx.cx.functions.borrow();
767-
let function = funcs
768-
.get(&builtin_name)
769-
.unwrap_or_else(|| panic!("unable to find builtin function {}", builtin_name));
766+
let function = bx.context.get_builtin_function(builtin_name);
770767

771768
// TODO(antoyo): add platform-specific behavior here for architectures that have these
772769
// intrinsics as instructions (for instance, gpus)
@@ -784,7 +781,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
784781
.map(|arg| bx.extract_element(arg.immediate(), index).to_rvalue())
785782
.collect()
786783
};
787-
vector_elements.push(bx.context.new_call(None, *function, &arguments));
784+
vector_elements.push(bx.context.new_call(None, function, &arguments));
788785
}
789786
let c = bx.context.new_rvalue_from_vector(None, vec_ty, &vector_elements);
790787
Ok(c)

0 commit comments

Comments
 (0)