Skip to content

Commit c4e7c04

Browse files
antoyoRobert Zakrzewski
authored andcommitted
Fix location of check for sized floating-point types
1 parent 0dad11f commit c4e7c04

File tree

4 files changed

+45
-10
lines changed

4 files changed

+45
-10
lines changed

src/base.rs

Lines changed: 17 additions & 2 deletions
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,22 @@ 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 f128_type_supported = target_info.supports_target_dependent_type(CType::Float128);
190+
// TODO: improve this to avoid passing that many arguments.
191+
let cx = CodegenCx::new(
192+
&context,
193+
cgu,
194+
tcx,
195+
target_info.supports_128bit_int(),
196+
f16_type_supported,
197+
f32_type_supported,
198+
f128_type_supported,
199+
);
185200

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

src/context.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ 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_f128_type: bool,
7174

7275
pub float_type: Type<'gcc>,
7376
pub double_type: Type<'gcc>,
@@ -130,6 +133,9 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
130133
codegen_unit: &'tcx CodegenUnit<'tcx>,
131134
tcx: TyCtxt<'tcx>,
132135
supports_128bit_integers: bool,
136+
supports_f16_type: bool,
137+
supports_f32_type: bool,
138+
supports_f128_type: bool,
133139
) -> Self {
134140
let check_overflow = tcx.sess.overflow_checks();
135141

@@ -305,6 +311,9 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
305311
sizet_type,
306312

307313
supports_128bit_integers,
314+
supports_f16_type,
315+
supports_f32_type,
316+
supports_f128_type,
308317

309318
float_type,
310319
double_type,

src/lib.rs

Lines changed: 10 additions & 2 deletions
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
};

src/type_.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
#[cfg(feature = "master")]
12
use std::convert::TryInto;
23

3-
use gccjit::{CType, RValue, Struct, Type};
4+
#[cfg(feature = "master")]
5+
use gccjit::CType;
6+
use gccjit::{RValue, Struct, Type};
47
use rustc_codegen_ssa::common::TypeKind;
58
use rustc_codegen_ssa::traits::{BaseTypeMethods, DerivedTypeMethods, TypeMembershipMethods};
69
use rustc_middle::ty::layout::TyAndLayout;
@@ -124,7 +127,7 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
124127

125128
#[cfg(feature = "master")]
126129
fn type_f16(&self) -> Type<'gcc> {
127-
if self.context.get_target_info().supports_target_dependent_type(CType::Float16) {
130+
if self.supports_f16_type {
128131
return self.context.new_c_type(CType::Float16);
129132
}
130133
unimplemented!("f16")
@@ -137,9 +140,9 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
137140

138141
#[cfg(feature = "master")]
139142
fn type_f32(&self) -> Type<'gcc> {
140-
// if self.context.get_target_info().supports_target_dependent_type(CType::Float32) {
141-
// return self.context.new_c_type(CType::Float32);
142-
// }
143+
if self.supports_f32_type {
144+
return self.context.new_c_type(CType::Float32);
145+
}
143146
self.float_type
144147
}
145148

@@ -154,7 +157,7 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
154157

155158
#[cfg(feature = "master")]
156159
fn type_f128(&self) -> Type<'gcc> {
157-
if self.context.get_target_info().supports_target_dependent_type(CType::Float128) {
160+
if self.supports_f128_type {
158161
return self.context.new_c_type(CType::Float128);
159162
}
160163
unimplemented!("f128")

0 commit comments

Comments
 (0)