Fix location of check for sized floating-point types
This commit is contained in:
parent
0dad11feb9
commit
c4e7c04de9
19
src/base.rs
19
src/base.rs
@ -2,7 +2,7 @@
|
||||
use std::env;
|
||||
use std::time::Instant;
|
||||
|
||||
use gccjit::{FunctionType, GlobalKind};
|
||||
use gccjit::{CType, FunctionType, GlobalKind};
|
||||
use rustc_codegen_ssa::base::maybe_create_entry_wrapper;
|
||||
use rustc_codegen_ssa::mono_item::MonoItemExt;
|
||||
use rustc_codegen_ssa::traits::DebugInfoMethods;
|
||||
@ -181,7 +181,22 @@ fn module_codegen(
|
||||
context.set_allow_unreachable_blocks(true);
|
||||
|
||||
{
|
||||
let cx = CodegenCx::new(&context, cgu, tcx, target_info.supports_128bit_int());
|
||||
// TODO: to make it less error-prone (calling get_target_info() will add the flag
|
||||
// -fsyntax-only), forbid the compilation when get_target_info() is called on a
|
||||
// context.
|
||||
let f16_type_supported = target_info.supports_target_dependent_type(CType::Float16);
|
||||
let f32_type_supported = target_info.supports_target_dependent_type(CType::Float32);
|
||||
let f128_type_supported = target_info.supports_target_dependent_type(CType::Float128);
|
||||
// TODO: improve this to avoid passing that many arguments.
|
||||
let cx = CodegenCx::new(
|
||||
&context,
|
||||
cgu,
|
||||
tcx,
|
||||
target_info.supports_128bit_int(),
|
||||
f16_type_supported,
|
||||
f32_type_supported,
|
||||
f128_type_supported,
|
||||
);
|
||||
|
||||
let mono_items = cgu.items_in_deterministic_order(tcx);
|
||||
for &(mono_item, data) in &mono_items {
|
||||
|
@ -68,6 +68,9 @@ pub struct CodegenCx<'gcc, 'tcx> {
|
||||
pub sizet_type: Type<'gcc>,
|
||||
|
||||
pub supports_128bit_integers: bool,
|
||||
pub supports_f16_type: bool,
|
||||
pub supports_f32_type: bool,
|
||||
pub supports_f128_type: bool,
|
||||
|
||||
pub float_type: Type<'gcc>,
|
||||
pub double_type: Type<'gcc>,
|
||||
@ -130,6 +133,9 @@ pub fn new(
|
||||
codegen_unit: &'tcx CodegenUnit<'tcx>,
|
||||
tcx: TyCtxt<'tcx>,
|
||||
supports_128bit_integers: bool,
|
||||
supports_f16_type: bool,
|
||||
supports_f32_type: bool,
|
||||
supports_f128_type: bool,
|
||||
) -> Self {
|
||||
let check_overflow = tcx.sess.overflow_checks();
|
||||
|
||||
@ -305,6 +311,9 @@ pub fn new(
|
||||
sizet_type,
|
||||
|
||||
supports_128bit_integers,
|
||||
supports_f16_type,
|
||||
supports_f32_type,
|
||||
supports_f128_type,
|
||||
|
||||
float_type,
|
||||
double_type,
|
||||
|
12
src/lib.rs
12
src/lib.rs
@ -89,7 +89,6 @@
|
||||
use std::sync::Mutex;
|
||||
|
||||
use errors::LTONotSupported;
|
||||
#[cfg(not(feature = "master"))]
|
||||
use gccjit::CType;
|
||||
use gccjit::{Context, OptimizationLevel};
|
||||
#[cfg(feature = "master")]
|
||||
@ -147,6 +146,10 @@ fn cpu_supports(&self, _feature: &str) -> bool {
|
||||
fn supports_128bit_int(&self) -> bool {
|
||||
self.supports_128bit_integers.load(Ordering::SeqCst)
|
||||
}
|
||||
|
||||
fn supports_target_dependent_type(&self, _typ: CType) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -168,6 +171,10 @@ fn cpu_supports(&self, feature: &str) -> bool {
|
||||
fn supports_128bit_int(&self) -> bool {
|
||||
self.info.lock().expect("lock").supports_128bit_int()
|
||||
}
|
||||
|
||||
fn supports_target_dependent_type(&self, typ: CType) -> bool {
|
||||
self.info.lock().expect("lock").supports_target_dependent_type(typ)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -438,7 +445,8 @@ fn run_link(
|
||||
pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> {
|
||||
#[cfg(feature = "master")]
|
||||
let info = {
|
||||
// Check whether the target supports 128-bit integers.
|
||||
// Check whether the target supports 128-bit integers, and sized floating point types (like
|
||||
// Float16).
|
||||
let context = Context::default();
|
||||
Arc::new(Mutex::new(IntoDynSyncSend(context.get_target_info())))
|
||||
};
|
||||
|
15
src/type_.rs
15
src/type_.rs
@ -1,6 +1,9 @@
|
||||
#[cfg(feature = "master")]
|
||||
use std::convert::TryInto;
|
||||
|
||||
use gccjit::{CType, RValue, Struct, Type};
|
||||
#[cfg(feature = "master")]
|
||||
use gccjit::CType;
|
||||
use gccjit::{RValue, Struct, Type};
|
||||
use rustc_codegen_ssa::common::TypeKind;
|
||||
use rustc_codegen_ssa::traits::{BaseTypeMethods, DerivedTypeMethods, TypeMembershipMethods};
|
||||
use rustc_middle::ty::layout::TyAndLayout;
|
||||
@ -124,7 +127,7 @@ fn type_isize(&self) -> Type<'gcc> {
|
||||
|
||||
#[cfg(feature = "master")]
|
||||
fn type_f16(&self) -> Type<'gcc> {
|
||||
if self.context.get_target_info().supports_target_dependent_type(CType::Float16) {
|
||||
if self.supports_f16_type {
|
||||
return self.context.new_c_type(CType::Float16);
|
||||
}
|
||||
unimplemented!("f16")
|
||||
@ -137,9 +140,9 @@ fn type_f16(&self) -> Type<'gcc> {
|
||||
|
||||
#[cfg(feature = "master")]
|
||||
fn type_f32(&self) -> Type<'gcc> {
|
||||
// if self.context.get_target_info().supports_target_dependent_type(CType::Float32) {
|
||||
// return self.context.new_c_type(CType::Float32);
|
||||
// }
|
||||
if self.supports_f32_type {
|
||||
return self.context.new_c_type(CType::Float32);
|
||||
}
|
||||
self.float_type
|
||||
}
|
||||
|
||||
@ -154,7 +157,7 @@ fn type_f64(&self) -> Type<'gcc> {
|
||||
|
||||
#[cfg(feature = "master")]
|
||||
fn type_f128(&self) -> Type<'gcc> {
|
||||
if self.context.get_target_info().supports_target_dependent_type(CType::Float128) {
|
||||
if self.supports_f128_type {
|
||||
return self.context.new_c_type(CType::Float128);
|
||||
}
|
||||
unimplemented!("f128")
|
||||
|
Loading…
Reference in New Issue
Block a user