1
- use gccjit:: { RValue , Struct , Type } ;
1
+ use std:: convert:: TryInto ;
2
+
3
+ use gccjit:: { CType , RValue , Struct , Type } ;
2
4
use rustc_codegen_ssa:: common:: TypeKind ;
3
5
use rustc_codegen_ssa:: traits:: { BaseTypeMethods , DerivedTypeMethods , TypeMembershipMethods } ;
4
6
use rustc_middle:: ty:: layout:: TyAndLayout ;
@@ -120,10 +122,28 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
120
122
self . isize_type
121
123
}
122
124
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" ) ) ]
123
134
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
125
144
}
126
145
146
+ #[ cfg( not( feature = "master" ) ) ]
127
147
fn type_f32 ( & self ) -> Type < ' gcc > {
128
148
self . float_type
129
149
}
@@ -132,8 +152,17 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
132
152
self . double_type
133
153
}
134
154
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" ) ) ]
135
164
fn type_f128 ( & self ) -> Type < ' gcc > {
136
- unimplemented ! ( "f16_f128 " )
165
+ unimplemented ! ( "f128 " )
137
166
}
138
167
139
168
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> {
161
190
typ
162
191
}
163
192
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" ) ) ]
164
218
fn type_kind ( & self , typ : Type < ' gcc > ) -> TypeKind {
165
219
if self . is_int_type_or_bool ( typ) {
166
220
TypeKind :: Integer
@@ -210,6 +264,16 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
210
264
unimplemented ! ( ) ;
211
265
}
212
266
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" ) ) ]
213
277
fn float_width ( & self , typ : Type < ' gcc > ) -> usize {
214
278
let f32 = self . context . new_type :: < f32 > ( ) ;
215
279
let f64 = self . context . new_type :: < f64 > ( ) ;
0 commit comments