Skip to content

Commit 173773e

Browse files
authored
Merge pull request #534 from antoyo/master
Sync from fork
2 parents a63b83e + 70d3655 commit 173773e

File tree

8 files changed

+136
-12
lines changed

8 files changed

+136
-12
lines changed

Diff for: Cargo.lock

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: build_system/build_sysroot/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ resolver = "2"
66

77
[dependencies]
88
core = { path = "./sysroot_src/library/core" }
9-
compiler_builtins = "0.1"
9+
# TODO: after the sync, revert to using version 0.1.
10+
# compiler_builtins = "0.1"
11+
compiler_builtins = "=0.1.109"
1012
alloc = { path = "./sysroot_src/library/alloc" }
1113
std = { path = "./sysroot_src/library/std", features = ["panic_unwind", "backtrace"] }
1214
test = { path = "./sysroot_src/library/test" }

Diff for: libgccjit.version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b6f163f52
1+
d61ce945badf4c9d8237a13ca135e3c46ad13be3

Diff for: src/base.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::HashSet;
22
use std::env;
33
use std::time::Instant;
44

5-
use gccjit::{FunctionType, GlobalKind};
5+
use gccjit::{CType, FunctionType, GlobalKind};
66
use rustc_codegen_ssa::base::maybe_create_entry_wrapper;
77
use rustc_codegen_ssa::mono_item::MonoItemExt;
88
use rustc_codegen_ssa::traits::DebugInfoMethods;
@@ -181,7 +181,24 @@ pub fn compile_codegen_unit(
181181
context.set_allow_unreachable_blocks(true);
182182

183183
{
184-
let cx = CodegenCx::new(&context, cgu, tcx, target_info.supports_128bit_int());
184+
// TODO: to make it less error-prone (calling get_target_info() will add the flag
185+
// -fsyntax-only), forbid the compilation when get_target_info() is called on a
186+
// context.
187+
let f16_type_supported = target_info.supports_target_dependent_type(CType::Float16);
188+
let f32_type_supported = target_info.supports_target_dependent_type(CType::Float32);
189+
let f64_type_supported = target_info.supports_target_dependent_type(CType::Float64);
190+
let f128_type_supported = target_info.supports_target_dependent_type(CType::Float128);
191+
// TODO: improve this to avoid passing that many arguments.
192+
let cx = CodegenCx::new(
193+
&context,
194+
cgu,
195+
tcx,
196+
target_info.supports_128bit_int(),
197+
f16_type_supported,
198+
f32_type_supported,
199+
f64_type_supported,
200+
f128_type_supported,
201+
);
185202

186203
let mono_items = cgu.items_in_deterministic_order(tcx);
187204
for &(mono_item, data) in &mono_items {

Diff for: src/builder.rs

+18
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,24 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
748748
// FIXME(antoyo): this seems to produce the wrong result.
749749
return self.context.new_call(self.location, fmodf, &[a, b]);
750750
}
751+
752+
#[cfg(feature = "master")]
753+
match self.cx.type_kind(a_type) {
754+
TypeKind::Half | TypeKind::Float => {
755+
let fmodf = self.context.get_builtin_function("fmodf");
756+
return self.context.new_call(self.location, fmodf, &[a, b]);
757+
}
758+
TypeKind::Double => {
759+
let fmod = self.context.get_builtin_function("fmod");
760+
return self.context.new_call(self.location, fmod, &[a, b]);
761+
}
762+
TypeKind::FP128 => {
763+
let fmodl = self.context.get_builtin_function("fmodl");
764+
return self.context.new_call(self.location, fmodl, &[a, b]);
765+
}
766+
_ => (),
767+
}
768+
751769
if let Some(vector_type) = a_type_unqualified.dyncast_vector() {
752770
assert_eq!(a_type_unqualified, b.get_type().unqualified());
753771

Diff for: src/context.rs

+13
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ pub struct CodegenCx<'gcc, 'tcx> {
6868
pub sizet_type: Type<'gcc>,
6969

7070
pub supports_128bit_integers: bool,
71+
pub supports_f16_type: bool,
72+
pub supports_f32_type: bool,
73+
pub supports_f64_type: bool,
74+
pub supports_f128_type: bool,
7175

7276
pub float_type: Type<'gcc>,
7377
pub double_type: Type<'gcc>,
@@ -125,11 +129,16 @@ pub struct CodegenCx<'gcc, 'tcx> {
125129
}
126130

127131
impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
132+
#[allow(clippy::too_many_arguments)]
128133
pub fn new(
129134
context: &'gcc Context<'gcc>,
130135
codegen_unit: &'tcx CodegenUnit<'tcx>,
131136
tcx: TyCtxt<'tcx>,
132137
supports_128bit_integers: bool,
138+
supports_f16_type: bool,
139+
supports_f32_type: bool,
140+
supports_f64_type: bool,
141+
supports_f128_type: bool,
133142
) -> Self {
134143
let check_overflow = tcx.sess.overflow_checks();
135144

@@ -305,6 +314,10 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
305314
sizet_type,
306315

307316
supports_128bit_integers,
317+
supports_f16_type,
318+
supports_f32_type,
319+
supports_f64_type,
320+
supports_f128_type,
308321

309322
float_type,
310323
double_type,

Diff for: src/lib.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ use std::sync::Arc;
8989
use std::sync::Mutex;
9090

9191
use errors::LTONotSupported;
92-
#[cfg(not(feature = "master"))]
9392
use gccjit::CType;
9493
use gccjit::{Context, OptimizationLevel};
9594
#[cfg(feature = "master")]
@@ -147,6 +146,10 @@ impl TargetInfo {
147146
fn supports_128bit_int(&self) -> bool {
148147
self.supports_128bit_integers.load(Ordering::SeqCst)
149148
}
149+
150+
fn supports_target_dependent_type(&self, _typ: CType) -> bool {
151+
false
152+
}
150153
}
151154

152155
#[derive(Clone)]
@@ -168,6 +171,10 @@ impl LockedTargetInfo {
168171
fn supports_128bit_int(&self) -> bool {
169172
self.info.lock().expect("lock").supports_128bit_int()
170173
}
174+
175+
fn supports_target_dependent_type(&self, typ: CType) -> bool {
176+
self.info.lock().expect("lock").supports_target_dependent_type(typ)
177+
}
171178
}
172179

173180
#[derive(Clone)]
@@ -438,7 +445,8 @@ impl WriteBackendMethods for GccCodegenBackend {
438445
pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> {
439446
#[cfg(feature = "master")]
440447
let info = {
441-
// Check whether the target supports 128-bit integers.
448+
// Check whether the target supports 128-bit integers, and sized floating point types (like
449+
// Float16).
442450
let context = Context::default();
443451
Arc::new(Mutex::new(IntoDynSyncSend(context.get_target_info())))
444452
};

Diff for: src/type_.rs

+68-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
#[cfg(feature = "master")]
2+
use std::convert::TryInto;
3+
4+
#[cfg(feature = "master")]
5+
use gccjit::CType;
16
use gccjit::{RValue, Struct, Type};
27
use rustc_codegen_ssa::common::TypeKind;
38
use rustc_codegen_ssa::traits::{BaseTypeMethods, DerivedTypeMethods, TypeMembershipMethods};
@@ -121,19 +126,35 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
121126
}
122127

123128
fn type_f16(&self) -> Type<'gcc> {
124-
unimplemented!("f16_f128")
129+
#[cfg(feature = "master")]
130+
if self.supports_f16_type {
131+
return self.context.new_c_type(CType::Float16);
132+
}
133+
bug!("unsupported float width 16")
125134
}
126135

127136
fn type_f32(&self) -> Type<'gcc> {
137+
#[cfg(feature = "master")]
138+
if self.supports_f32_type {
139+
return self.context.new_c_type(CType::Float32);
140+
}
128141
self.float_type
129142
}
130143

131144
fn type_f64(&self) -> Type<'gcc> {
145+
#[cfg(feature = "master")]
146+
if self.supports_f64_type {
147+
return self.context.new_c_type(CType::Float64);
148+
}
132149
self.double_type
133150
}
134151

135152
fn type_f128(&self) -> Type<'gcc> {
136-
unimplemented!("f16_f128")
153+
#[cfg(feature = "master")]
154+
if self.supports_f128_type {
155+
return self.context.new_c_type(CType::Float128);
156+
}
157+
bug!("unsupported float width 128")
137158
}
138159

139160
fn type_func(&self, params: &[Type<'gcc>], return_type: Type<'gcc>) -> Type<'gcc> {
@@ -161,6 +182,41 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
161182
typ
162183
}
163184

185+
#[cfg(feature = "master")]
186+
fn type_kind(&self, typ: Type<'gcc>) -> TypeKind {
187+
if self.is_int_type_or_bool(typ) {
188+
TypeKind::Integer
189+
} else if typ.get_pointee().is_some() {
190+
TypeKind::Pointer
191+
} else if typ.is_vector() {
192+
TypeKind::Vector
193+
} else if typ.dyncast_array().is_some() {
194+
TypeKind::Array
195+
} else if typ.is_struct().is_some() {
196+
TypeKind::Struct
197+
} else if typ.dyncast_function_ptr_type().is_some() {
198+
TypeKind::Function
199+
} else if typ.is_compatible_with(self.float_type) {
200+
TypeKind::Float
201+
} else if typ.is_compatible_with(self.double_type) {
202+
TypeKind::Double
203+
} else if typ.is_floating_point() {
204+
match typ.get_size() {
205+
2 => TypeKind::Half,
206+
4 => TypeKind::Float,
207+
8 => TypeKind::Double,
208+
16 => TypeKind::FP128,
209+
size => unreachable!("Floating-point type of size {}", size),
210+
}
211+
} else if typ == self.type_void() {
212+
TypeKind::Void
213+
} else {
214+
// TODO(antoyo): support other types.
215+
unimplemented!();
216+
}
217+
}
218+
219+
#[cfg(not(feature = "master"))]
164220
fn type_kind(&self, typ: Type<'gcc>) -> TypeKind {
165221
if self.is_int_type_or_bool(typ) {
166222
TypeKind::Integer
@@ -210,6 +266,16 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
210266
unimplemented!();
211267
}
212268

269+
#[cfg(feature = "master")]
270+
fn float_width(&self, typ: Type<'gcc>) -> usize {
271+
if typ.is_floating_point() {
272+
(typ.get_size() * u8::BITS).try_into().unwrap()
273+
} else {
274+
panic!("Cannot get width of float type {:?}", typ);
275+
}
276+
}
277+
278+
#[cfg(not(feature = "master"))]
213279
fn float_width(&self, typ: Type<'gcc>) -> usize {
214280
let f32 = self.context.new_type::<f32>();
215281
let f64 = self.context.new_type::<f64>();

0 commit comments

Comments
 (0)