11
11
use llvm:: { self , AttributePlace } ;
12
12
use base;
13
13
use builder:: { Builder , MemFlags } ;
14
- use common:: { ty_fn_sig, C_usize } ;
14
+ use common:: ty_fn_sig;
15
15
use context:: CodegenCx ;
16
16
use mir:: place:: PlaceRef ;
17
17
use mir:: operand:: OperandValue ;
18
18
use type_:: Type ;
19
19
use type_of:: { LayoutLlvmExt , PointerKind } ;
20
20
use value:: Value ;
21
21
22
+ use interfaces:: { BuilderMethods , ConstMethods , TypeMethods } ;
23
+
22
24
use rustc_target:: abi:: { LayoutOf , Size , TyLayout } ;
23
25
use rustc:: ty:: { self , Ty } ;
24
26
use rustc:: ty:: layout;
@@ -104,29 +106,29 @@ impl ArgAttributesExt for ArgAttributes {
104
106
}
105
107
106
108
pub trait LlvmType {
107
- fn llvm_type ( & self , cx : & CodegenCx < ' ll , ' _ > ) -> & ' ll Type ;
109
+ fn llvm_type ( & self , cx : & CodegenCx < ' ll , ' _ , & ' ll Value > ) -> & ' ll Type ;
108
110
}
109
111
110
112
impl LlvmType for Reg {
111
- fn llvm_type ( & self , cx : & CodegenCx < ' ll , ' _ > ) -> & ' ll Type {
113
+ fn llvm_type ( & self , cx : & CodegenCx < ' ll , ' _ , & ' ll Value > ) -> & ' ll Type {
112
114
match self . kind {
113
- RegKind :: Integer => Type :: ix ( cx , self . size . bits ( ) ) ,
115
+ RegKind :: Integer => cx . type_ix ( self . size . bits ( ) ) ,
114
116
RegKind :: Float => {
115
117
match self . size . bits ( ) {
116
- 32 => Type :: f32 ( cx ) ,
117
- 64 => Type :: f64 ( cx ) ,
118
+ 32 => cx . type_f32 ( ) ,
119
+ 64 => cx . type_f64 ( ) ,
118
120
_ => bug ! ( "unsupported float: {:?}" , self )
119
121
}
120
122
}
121
123
RegKind :: Vector => {
122
- Type :: vector ( Type :: i8 ( cx ) , self . size . bytes ( ) )
124
+ cx . type_vector ( cx . type_i8 ( ) , self . size . bytes ( ) )
123
125
}
124
126
}
125
127
}
126
128
}
127
129
128
130
impl LlvmType for CastTarget {
129
- fn llvm_type ( & self , cx : & CodegenCx < ' ll , ' _ > ) -> & ' ll Type {
131
+ fn llvm_type ( & self , cx : & CodegenCx < ' ll , ' _ , & ' ll Value > ) -> & ' ll Type {
130
132
let rest_ll_unit = self . rest . unit . llvm_type ( cx) ;
131
133
let ( rest_count, rem_bytes) = if self . rest . unit . size . bytes ( ) == 0 {
132
134
( 0 , 0 )
@@ -143,7 +145,7 @@ impl LlvmType for CastTarget {
143
145
144
146
// Simplify to array when all chunks are the same size and type
145
147
if rem_bytes == 0 {
146
- return Type :: array ( rest_ll_unit, rest_count) ;
148
+ return cx . type_array ( rest_ll_unit, rest_count) ;
147
149
}
148
150
}
149
151
@@ -158,35 +160,49 @@ impl LlvmType for CastTarget {
158
160
if rem_bytes != 0 {
159
161
// Only integers can be really split further.
160
162
assert_eq ! ( self . rest. unit. kind, RegKind :: Integer ) ;
161
- args. push ( Type :: ix ( cx , rem_bytes * 8 ) ) ;
163
+ args. push ( cx . type_ix ( rem_bytes * 8 ) ) ;
162
164
}
163
165
164
- Type :: struct_ ( cx , & args, false )
166
+ cx . type_struct ( & args, false )
165
167
}
166
168
}
167
169
168
170
pub trait ArgTypeExt < ' ll , ' tcx > {
169
- fn memory_ty ( & self , cx : & CodegenCx < ' ll , ' tcx > ) -> & ' ll Type ;
170
- fn store ( & self , bx : & Builder < ' _ , ' ll , ' tcx > , val : & ' ll Value , dst : PlaceRef < ' ll , ' tcx > ) ;
171
- fn store_fn_arg ( & self , bx : & Builder < ' _ , ' ll , ' tcx > , idx : & mut usize , dst : PlaceRef < ' ll , ' tcx > ) ;
171
+ fn memory_ty ( & self , cx : & CodegenCx < ' ll , ' tcx , & ' ll Value > ) -> & ' ll Type ;
172
+ fn store (
173
+ & self ,
174
+ bx : & Builder < ' _ , ' ll , ' tcx , & ' ll Value > ,
175
+ val : & ' ll Value ,
176
+ dst : PlaceRef < ' tcx , & ' ll Value >
177
+ ) ;
178
+ fn store_fn_arg (
179
+ & self ,
180
+ bx : & Builder < ' _ , ' ll , ' tcx , & ' ll Value > ,
181
+ idx : & mut usize , dst : PlaceRef < ' tcx , & ' ll Value >
182
+ ) ;
172
183
}
173
184
174
185
impl ArgTypeExt < ' ll , ' tcx > for ArgType < ' tcx , Ty < ' tcx > > {
175
186
/// Get the LLVM type for a place of the original Rust type of
176
187
/// this argument/return, i.e. the result of `type_of::type_of`.
177
- fn memory_ty ( & self , cx : & CodegenCx < ' ll , ' tcx > ) -> & ' ll Type {
188
+ fn memory_ty ( & self , cx : & CodegenCx < ' ll , ' tcx , & ' ll Value > ) -> & ' ll Type {
178
189
self . layout . llvm_type ( cx)
179
190
}
180
191
181
192
/// Store a direct/indirect value described by this ArgType into a
182
193
/// place for the original Rust type of this argument/return.
183
194
/// Can be used for both storing formal arguments into Rust variables
184
195
/// or results of call/invoke instructions into their destinations.
185
- fn store ( & self , bx : & Builder < ' _ , ' ll , ' tcx > , val : & ' ll Value , dst : PlaceRef < ' ll , ' tcx > ) {
196
+ fn store (
197
+ & self ,
198
+ bx : & Builder < ' _ , ' ll , ' tcx , & ' ll Value > ,
199
+ val : & ' ll Value ,
200
+ dst : PlaceRef < ' tcx , & ' ll Value >
201
+ ) {
186
202
if self . is_ignore ( ) {
187
203
return ;
188
204
}
189
- let cx = bx. cx ;
205
+ let cx = bx. cx ( ) ;
190
206
if self . is_sized_indirect ( ) {
191
207
OperandValue :: Ref ( val, None , self . layout . align ) . store ( bx, dst)
192
208
} else if self . is_unsized_indirect ( ) {
@@ -196,7 +212,7 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
196
212
// uses it for i16 -> {i8, i8}, but not for i24 -> {i8, i8, i8}.
197
213
let can_store_through_cast_ptr = false ;
198
214
if can_store_through_cast_ptr {
199
- let cast_dst = bx. pointercast ( dst. llval , cast. llvm_type ( cx) . ptr_to ( ) ) ;
215
+ let cast_dst = bx. pointercast ( dst. llval , cx . type_ptr_to ( cast. llvm_type ( cx) ) ) ;
200
216
bx. store ( val, cast_dst, self . layout . align ) ;
201
217
} else {
202
218
// The actual return type is a struct, but the ABI
@@ -224,9 +240,9 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
224
240
225
241
// ...and then memcpy it to the intended destination.
226
242
base:: call_memcpy ( bx,
227
- bx. pointercast ( dst. llval , Type :: i8p ( cx ) ) ,
228
- bx. pointercast ( llscratch, Type :: i8p ( cx ) ) ,
229
- C_usize ( cx , self . layout . size . bytes ( ) ) ,
243
+ bx. pointercast ( dst. llval , cx . type_i8p ( ) ) ,
244
+ bx. pointercast ( llscratch, cx . type_i8p ( ) ) ,
245
+ cx . const_usize ( self . layout . size . bytes ( ) ) ,
230
246
self . layout . align . min ( scratch_align) ,
231
247
MemFlags :: empty ( ) ) ;
232
248
@@ -237,7 +253,12 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
237
253
}
238
254
}
239
255
240
- fn store_fn_arg ( & self , bx : & Builder < ' a , ' ll , ' tcx > , idx : & mut usize , dst : PlaceRef < ' ll , ' tcx > ) {
256
+ fn store_fn_arg (
257
+ & self ,
258
+ bx : & Builder < ' a , ' ll , ' tcx , & ' ll Value > ,
259
+ idx : & mut usize ,
260
+ dst : PlaceRef < ' tcx , & ' ll Value >
261
+ ) {
241
262
let mut next = || {
242
263
let val = llvm:: get_param ( bx. llfn ( ) , * idx as c_uint ) ;
243
264
* idx += 1 ;
@@ -259,47 +280,47 @@ impl ArgTypeExt<'ll, 'tcx> for ArgType<'tcx, Ty<'tcx>> {
259
280
}
260
281
261
282
pub trait FnTypeExt < ' tcx > {
262
- fn of_instance ( cx : & CodegenCx < ' ll , ' tcx > , instance : & ty:: Instance < ' tcx > )
283
+ fn of_instance ( cx : & CodegenCx < ' ll , ' tcx , & ' ll Value > , instance : & ty:: Instance < ' tcx > )
263
284
-> Self ;
264
- fn new ( cx : & CodegenCx < ' ll , ' tcx > ,
285
+ fn new ( cx : & CodegenCx < ' ll , ' tcx , & ' ll Value > ,
265
286
sig : ty:: FnSig < ' tcx > ,
266
287
extra_args : & [ Ty < ' tcx > ] ) -> Self ;
267
- fn new_vtable ( cx : & CodegenCx < ' ll , ' tcx > ,
288
+ fn new_vtable ( cx : & CodegenCx < ' ll , ' tcx , & ' ll Value > ,
268
289
sig : ty:: FnSig < ' tcx > ,
269
290
extra_args : & [ Ty < ' tcx > ] ) -> Self ;
270
291
fn new_internal (
271
- cx : & CodegenCx < ' ll , ' tcx > ,
292
+ cx : & CodegenCx < ' ll , ' tcx , & ' ll Value > ,
272
293
sig : ty:: FnSig < ' tcx > ,
273
294
extra_args : & [ Ty < ' tcx > ] ,
274
295
mk_arg_type : impl Fn ( Ty < ' tcx > , Option < usize > ) -> ArgType < ' tcx , Ty < ' tcx > > ,
275
296
) -> Self ;
276
297
fn adjust_for_abi ( & mut self ,
277
- cx : & CodegenCx < ' ll , ' tcx > ,
298
+ cx : & CodegenCx < ' ll , ' tcx , & ' ll Value > ,
278
299
abi : Abi ) ;
279
- fn llvm_type ( & self , cx : & CodegenCx < ' ll , ' tcx > ) -> & ' ll Type ;
300
+ fn llvm_type ( & self , cx : & CodegenCx < ' ll , ' tcx , & ' ll Value > ) -> & ' ll Type ;
280
301
fn llvm_cconv ( & self ) -> llvm:: CallConv ;
281
302
fn apply_attrs_llfn ( & self , llfn : & ' ll Value ) ;
282
- fn apply_attrs_callsite ( & self , bx : & Builder < ' a , ' ll , ' tcx > , callsite : & ' ll Value ) ;
303
+ fn apply_attrs_callsite ( & self , bx : & Builder < ' a , ' ll , ' tcx , & ' ll Value > , callsite : & ' ll Value ) ;
283
304
}
284
305
285
306
impl < ' tcx > FnTypeExt < ' tcx > for FnType < ' tcx , Ty < ' tcx > > {
286
- fn of_instance ( cx : & CodegenCx < ' ll , ' tcx > , instance : & ty:: Instance < ' tcx > )
307
+ fn of_instance ( cx : & CodegenCx < ' ll , ' tcx , & ' ll Value > , instance : & ty:: Instance < ' tcx > )
287
308
-> Self {
288
309
let fn_ty = instance. ty ( cx. tcx ) ;
289
310
let sig = ty_fn_sig ( cx, fn_ty) ;
290
311
let sig = cx. tcx . normalize_erasing_late_bound_regions ( ty:: ParamEnv :: reveal_all ( ) , & sig) ;
291
312
FnType :: new ( cx, sig, & [ ] )
292
313
}
293
314
294
- fn new ( cx : & CodegenCx < ' ll , ' tcx > ,
315
+ fn new ( cx : & CodegenCx < ' ll , ' tcx , & ' ll Value > ,
295
316
sig : ty:: FnSig < ' tcx > ,
296
317
extra_args : & [ Ty < ' tcx > ] ) -> Self {
297
318
FnType :: new_internal ( cx, sig, extra_args, |ty, _| {
298
319
ArgType :: new ( cx. layout_of ( ty) )
299
320
} )
300
321
}
301
322
302
- fn new_vtable ( cx : & CodegenCx < ' ll , ' tcx > ,
323
+ fn new_vtable ( cx : & CodegenCx < ' ll , ' tcx , & ' ll Value > ,
303
324
sig : ty:: FnSig < ' tcx > ,
304
325
extra_args : & [ Ty < ' tcx > ] ) -> Self {
305
326
FnType :: new_internal ( cx, sig, extra_args, |ty, arg_idx| {
@@ -326,7 +347,7 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
326
347
}
327
348
328
349
fn new_internal (
329
- cx : & CodegenCx < ' ll , ' tcx > ,
350
+ cx : & CodegenCx < ' ll , ' tcx , & ' ll Value > ,
330
351
sig : ty:: FnSig < ' tcx > ,
331
352
extra_args : & [ Ty < ' tcx > ] ,
332
353
mk_arg_type : impl Fn ( Ty < ' tcx > , Option < usize > ) -> ArgType < ' tcx , Ty < ' tcx > > ,
@@ -507,7 +528,7 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
507
528
}
508
529
509
530
fn adjust_for_abi ( & mut self ,
510
- cx : & CodegenCx < ' ll , ' tcx > ,
531
+ cx : & CodegenCx < ' ll , ' tcx , & ' ll Value > ,
511
532
abi : Abi ) {
512
533
if abi == Abi :: Unadjusted { return }
513
534
@@ -574,7 +595,7 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
574
595
}
575
596
}
576
597
577
- fn llvm_type ( & self , cx : & CodegenCx < ' ll , ' tcx > ) -> & ' ll Type {
598
+ fn llvm_type ( & self , cx : & CodegenCx < ' ll , ' tcx , & ' ll Value > ) -> & ' ll Type {
578
599
let args_capacity: usize = self . args . iter ( ) . map ( |arg|
579
600
if arg. pad . is_some ( ) { 1 } else { 0 } +
580
601
if let PassMode :: Pair ( _, _) = arg. mode { 2 } else { 1 }
@@ -584,14 +605,14 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
584
605
) ;
585
606
586
607
let llreturn_ty = match self . ret . mode {
587
- PassMode :: Ignore => Type :: void ( cx ) ,
608
+ PassMode :: Ignore => cx . type_void ( ) ,
588
609
PassMode :: Direct ( _) | PassMode :: Pair ( ..) => {
589
610
self . ret . layout . immediate_llvm_type ( cx)
590
611
}
591
612
PassMode :: Cast ( cast) => cast. llvm_type ( cx) ,
592
613
PassMode :: Indirect ( ..) => {
593
- llargument_tys. push ( self . ret . memory_ty ( cx) . ptr_to ( ) ) ;
594
- Type :: void ( cx )
614
+ llargument_tys. push ( cx . type_ptr_to ( self . ret . memory_ty ( cx) ) ) ;
615
+ cx . type_void ( )
595
616
}
596
617
} ;
597
618
@@ -617,15 +638,15 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
617
638
continue ;
618
639
}
619
640
PassMode :: Cast ( cast) => cast. llvm_type ( cx) ,
620
- PassMode :: Indirect ( _, None ) => arg. memory_ty ( cx) . ptr_to ( ) ,
641
+ PassMode :: Indirect ( _, None ) => cx . type_ptr_to ( arg. memory_ty ( cx) ) ,
621
642
} ;
622
643
llargument_tys. push ( llarg_ty) ;
623
644
}
624
645
625
646
if self . variadic {
626
- Type :: variadic_func ( & llargument_tys, llreturn_ty)
647
+ cx . type_variadic_func ( & llargument_tys, llreturn_ty)
627
648
} else {
628
- Type :: func ( & llargument_tys, llreturn_ty)
649
+ cx . type_func ( & llargument_tys, llreturn_ty)
629
650
}
630
651
}
631
652
@@ -680,7 +701,7 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
680
701
}
681
702
}
682
703
683
- fn apply_attrs_callsite ( & self , bx : & Builder < ' a , ' ll , ' tcx > , callsite : & ' ll Value ) {
704
+ fn apply_attrs_callsite ( & self , bx : & Builder < ' a , ' ll , ' tcx , & ' ll Value > , callsite : & ' ll Value ) {
684
705
let mut i = 0 ;
685
706
let mut apply = |attrs : & ArgAttributes | {
686
707
attrs. apply_callsite ( llvm:: AttributePlace :: Argument ( i) , callsite) ;
@@ -699,7 +720,7 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
699
720
// by the LLVM verifier.
700
721
match scalar. value {
701
722
layout:: Int ( ..) if !scalar. is_bool ( ) => {
702
- let range = scalar. valid_range_exclusive ( bx. cx ) ;
723
+ let range = scalar. valid_range_exclusive ( bx. cx ( ) ) ;
703
724
if range. start != range. end {
704
725
bx. range_metadata ( callsite, range) ;
705
726
}
0 commit comments