1- use gccjit:: { RValue , Struct , Type } ;
1+ use std:: convert:: TryInto ;
2+
3+ use gccjit:: { CType , RValue , Struct , Type } ;
24use rustc_codegen_ssa:: common:: TypeKind ;
35use rustc_codegen_ssa:: traits:: { BaseTypeMethods , DerivedTypeMethods , TypeMembershipMethods } ;
46use rustc_middle:: ty:: layout:: TyAndLayout ;
@@ -120,10 +122,28 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
120122 self . isize_type
121123 }
122124
125+ #[ cfg( feature = "master" ) ]
126+ fn type_f16 ( & self ) -> Type < ' gcc > {
127+ if self . context . get_target_info ( ) . supports_target_dependent_type ( CType :: Float16 ) {
128+ return self . context . new_c_type ( CType :: Float16 ) ;
129+ }
130+ unimplemented ! ( "f16" )
131+ }
132+
133+ #[ cfg( not( feature = "master" ) ) ]
123134 fn type_f16 ( & self ) -> Type < ' gcc > {
124- unimplemented ! ( "f16_f128" )
135+ unimplemented ! ( "f16" )
136+ }
137+
138+ #[ cfg( feature = "master" ) ]
139+ 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+ self . float_type
125144 }
126145
146+ #[ cfg( not( feature = "master" ) ) ]
127147 fn type_f32 ( & self ) -> Type < ' gcc > {
128148 self . float_type
129149 }
@@ -132,8 +152,17 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
132152 self . double_type
133153 }
134154
155+ #[ cfg( feature = "master" ) ]
156+ fn type_f128 ( & self ) -> Type < ' gcc > {
157+ if self . context . get_target_info ( ) . supports_target_dependent_type ( CType :: Float128 ) {
158+ return self . context . new_c_type ( CType :: Float128 ) ;
159+ }
160+ unimplemented ! ( "f128" )
161+ }
162+
163+ #[ cfg( not( feature = "master" ) ) ]
135164 fn type_f128 ( & self ) -> Type < ' gcc > {
136- unimplemented ! ( "f16_f128 " )
165+ unimplemented ! ( "f128 " )
137166 }
138167
139168 fn type_func ( & self , params : & [ Type < ' gcc > ] , return_type : Type < ' gcc > ) -> Type < ' gcc > {
@@ -161,6 +190,31 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
161190 typ
162191 }
163192
193+ #[ cfg( feature = "master" ) ]
194+ fn type_kind ( & self , typ : Type < ' gcc > ) -> TypeKind {
195+ if self . is_int_type_or_bool ( typ) {
196+ TypeKind :: Integer
197+ } else if typ. is_compatible_with ( self . float_type ) {
198+ TypeKind :: Float
199+ } else if typ. is_compatible_with ( self . double_type ) {
200+ TypeKind :: Double
201+ } else if typ. is_vector ( ) {
202+ TypeKind :: Vector
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+ _ => TypeKind :: Void ,
210+ }
211+ } else {
212+ // TODO(antoyo): support other types.
213+ TypeKind :: Void
214+ }
215+ }
216+
217+ #[ cfg( not( feature = "master" ) ) ]
164218 fn type_kind ( & self , typ : Type < ' gcc > ) -> TypeKind {
165219 if self . is_int_type_or_bool ( typ) {
166220 TypeKind :: Integer
@@ -210,6 +264,16 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
210264 unimplemented ! ( ) ;
211265 }
212266
267+ #[ cfg( feature = "master" ) ]
268+ fn float_width ( & self , typ : Type < ' gcc > ) -> usize {
269+ if typ. is_floating_point ( ) {
270+ ( typ. get_size ( ) * u8:: BITS ) . try_into ( ) . unwrap ( )
271+ } else {
272+ panic ! ( "Cannot get width of float type {:?}" , typ) ;
273+ }
274+ }
275+
276+ #[ cfg( not( feature = "master" ) ) ]
213277 fn float_width ( & self , typ : Type < ' gcc > ) -> usize {
214278 let f32 = self . context . new_type :: < f32 > ( ) ;
215279 let f64 = self . context . new_type :: < f64 > ( ) ;
0 commit comments