about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAntoni Boucher <bouanto@zoho.com>2024-06-13 08:45:41 -0400
committerRobert Zakrzewski <robert.zakrzewski1@stellantis.com>2024-06-21 16:12:05 +0200
commitc4e7c04de9bc72190ef9911c7a481ebc2a406db7 (patch)
treefe8142b6944484c00d2d94f4bd3063e7d6ec3543 /src
parent0dad11feb9cf34f41d883f49518f9bf812314d57 (diff)
downloadrust-c4e7c04de9bc72190ef9911c7a481ebc2a406db7.tar.gz
rust-c4e7c04de9bc72190ef9911c7a481ebc2a406db7.zip
Fix location of check for sized floating-point types
Diffstat (limited to 'src')
-rw-r--r--src/base.rs19
-rw-r--r--src/context.rs9
-rw-r--r--src/lib.rs12
-rw-r--r--src/type_.rs15
4 files changed, 45 insertions, 10 deletions
diff --git a/src/base.rs b/src/base.rs
index 79a29a1135a..ea2b0b791b7 100644
--- a/src/base.rs
+++ b/src/base.rs
@@ -2,7 +2,7 @@ use std::collections::HashSet;
 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 @@ pub fn compile_codegen_unit(
         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 {
diff --git a/src/context.rs b/src/context.rs
index 890b4b15fc0..53a2b09217a 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -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 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
         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 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
             sizet_type,
 
             supports_128bit_integers,
+            supports_f16_type,
+            supports_f32_type,
+            supports_f128_type,
 
             float_type,
             double_type,
diff --git a/src/lib.rs b/src/lib.rs
index af110e3ab5e..9b9b97b9595 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -89,7 +89,6 @@ use std::sync::Arc;
 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 @@ impl TargetInfo {
     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 @@ impl LockedTargetInfo {
     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 @@ impl WriteBackendMethods for GccCodegenBackend {
 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())))
     };
diff --git a/src/type_.rs b/src/type_.rs
index c65301495b1..7bcc71e581d 100644
--- a/src/type_.rs
+++ b/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 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
 
     #[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 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
 
     #[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 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
 
     #[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")