@@ -29,7 +29,7 @@ use type_of::LayoutLlvmExt;
29
29
use type_:: Type ;
30
30
31
31
use super :: super :: callee;
32
- use super :: MirContext ;
32
+ use super :: FunctionCx ;
33
33
34
34
fn to_const_int ( value : ValueRef , t : Ty , tcx : TyCtxt ) -> Option < ConstInt > {
35
35
match t. sty {
@@ -135,44 +135,44 @@ pub fn const_scalar_checked_binop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
135
135
}
136
136
}
137
137
138
- pub fn primval_to_llvm ( ccx : & CrateContext ,
138
+ pub fn primval_to_llvm ( cx : & CodegenCx ,
139
139
cv : PrimVal ,
140
140
scalar : & Scalar ,
141
141
llty : Type ) -> ValueRef {
142
- let bits = if scalar. is_bool ( ) { 1 } else { scalar. value . size ( ccx ) . bits ( ) } ;
142
+ let bits = if scalar. is_bool ( ) { 1 } else { scalar. value . size ( cx ) . bits ( ) } ;
143
143
match cv {
144
- PrimVal :: Undef => C_undef ( Type :: ix ( ccx , bits) ) ,
144
+ PrimVal :: Undef => C_undef ( Type :: ix ( cx , bits) ) ,
145
145
PrimVal :: Bytes ( b) => {
146
- let llval = C_uint_big ( Type :: ix ( ccx , bits) , b) ;
146
+ let llval = C_uint_big ( Type :: ix ( cx , bits) , b) ;
147
147
if scalar. value == layout:: Pointer {
148
148
unsafe { llvm:: LLVMConstIntToPtr ( llval, llty. to_ref ( ) ) }
149
149
} else {
150
150
consts:: bitcast ( llval, llty)
151
151
}
152
152
} ,
153
153
PrimVal :: Ptr ( ptr) => {
154
- let interpret_interner = ccx . tcx ( ) . interpret_interner . borrow ( ) ;
154
+ let interpret_interner = cx . tcx . interpret_interner . borrow ( ) ;
155
155
if let Some ( fn_instance) = interpret_interner. get_fn ( ptr. alloc_id ) {
156
- callee:: get_fn ( ccx , fn_instance)
156
+ callee:: get_fn ( cx , fn_instance)
157
157
} else {
158
158
let static_ = interpret_interner. get_corresponding_static_def_id ( ptr. alloc_id ) ;
159
159
let base_addr = if let Some ( def_id) = static_ {
160
- assert ! ( ccx . tcx( ) . is_static( def_id) . is_some( ) ) ;
161
- consts:: get_static ( ccx , def_id)
160
+ assert ! ( cx . tcx. is_static( def_id) . is_some( ) ) ;
161
+ consts:: get_static ( cx , def_id)
162
162
} else if let Some ( alloc) = interpret_interner. get_alloc ( ptr. alloc_id ) {
163
- let init = global_initializer ( ccx , alloc) ;
163
+ let init = global_initializer ( cx , alloc) ;
164
164
if alloc. mutable {
165
- consts:: addr_of_mut ( ccx , init, alloc. align , "byte_str" )
165
+ consts:: addr_of_mut ( cx , init, alloc. align , "byte_str" )
166
166
} else {
167
- consts:: addr_of ( ccx , init, alloc. align , "byte_str" )
167
+ consts:: addr_of ( cx , init, alloc. align , "byte_str" )
168
168
}
169
169
} else {
170
170
bug ! ( "missing allocation {:?}" , ptr. alloc_id) ;
171
171
} ;
172
172
173
173
let llval = unsafe { llvm:: LLVMConstInBoundsGEP (
174
- consts:: bitcast ( base_addr, Type :: i8p ( ccx ) ) ,
175
- & C_usize ( ccx , ptr. offset ) ,
174
+ consts:: bitcast ( base_addr, Type :: i8p ( cx ) ) ,
175
+ & C_usize ( cx , ptr. offset ) ,
176
176
1 ,
177
177
) } ;
178
178
if scalar. value != layout:: Pointer {
@@ -185,94 +185,94 @@ pub fn primval_to_llvm(ccx: &CrateContext,
185
185
}
186
186
}
187
187
188
- pub fn global_initializer ( ccx : & CrateContext , alloc : & Allocation ) -> ValueRef {
188
+ pub fn global_initializer ( cx : & CodegenCx , alloc : & Allocation ) -> ValueRef {
189
189
let mut llvals = Vec :: with_capacity ( alloc. relocations . len ( ) + 1 ) ;
190
- let layout = ccx . data_layout ( ) ;
190
+ let layout = cx . data_layout ( ) ;
191
191
let pointer_size = layout. pointer_size . bytes ( ) as usize ;
192
192
193
193
let mut next_offset = 0 ;
194
194
for ( & offset, & alloc_id) in & alloc. relocations {
195
195
assert_eq ! ( offset as usize as u64 , offset) ;
196
196
let offset = offset as usize ;
197
197
if offset > next_offset {
198
- llvals. push ( C_bytes ( ccx , & alloc. bytes [ next_offset..offset] ) ) ;
198
+ llvals. push ( C_bytes ( cx , & alloc. bytes [ next_offset..offset] ) ) ;
199
199
}
200
200
let ptr_offset = read_target_uint (
201
201
layout. endian ,
202
202
& alloc. bytes [ offset..( offset + pointer_size) ] ,
203
203
) . expect ( "global_initializer: could not read relocation pointer" ) as u64 ;
204
204
llvals. push ( primval_to_llvm (
205
- ccx ,
205
+ cx ,
206
206
PrimVal :: Ptr ( MemoryPointer { alloc_id, offset : ptr_offset } ) ,
207
207
& Scalar {
208
208
value : layout:: Primitive :: Pointer ,
209
209
valid_range : 0 ..=!0
210
210
} ,
211
- Type :: i8p ( ccx )
211
+ Type :: i8p ( cx )
212
212
) ) ;
213
213
next_offset = offset + pointer_size;
214
214
}
215
215
if alloc. bytes . len ( ) >= next_offset {
216
- llvals. push ( C_bytes ( ccx , & alloc. bytes [ next_offset ..] ) ) ;
216
+ llvals. push ( C_bytes ( cx , & alloc. bytes [ next_offset ..] ) ) ;
217
217
}
218
218
219
- C_struct ( ccx , & llvals, true )
219
+ C_struct ( cx , & llvals, true )
220
220
}
221
221
222
222
pub fn trans_static_initializer < ' a , ' tcx > (
223
223
cx : & CodegenCx < ' a , ' tcx > ,
224
224
def_id : DefId )
225
225
-> Result < ValueRef , ConstEvalErr < ' tcx > >
226
226
{
227
- let instance = ty:: Instance :: mono ( ccx . tcx ( ) , def_id) ;
227
+ let instance = ty:: Instance :: mono ( cx . tcx , def_id) ;
228
228
let cid = GlobalId {
229
229
instance,
230
230
promoted : None
231
231
} ;
232
232
let param_env = ty:: ParamEnv :: empty ( traits:: Reveal :: All ) ;
233
- ccx . tcx ( ) . const_eval ( param_env. and ( cid) ) ?;
233
+ cx . tcx . const_eval ( param_env. and ( cid) ) ?;
234
234
235
- let alloc_id = ccx
236
- . tcx ( )
235
+ let alloc_id = cx
236
+ . tcx
237
237
. interpret_interner
238
238
. borrow ( )
239
239
. get_cached ( def_id)
240
240
. expect ( "global not cached" ) ;
241
241
242
- let alloc = ccx
243
- . tcx ( )
242
+ let alloc = cx
243
+ . tcx
244
244
. interpret_interner
245
245
. borrow ( )
246
246
. get_alloc ( alloc_id)
247
247
. expect ( "miri allocation never successfully created" ) ;
248
- Ok ( global_initializer ( ccx , alloc) )
248
+ Ok ( global_initializer ( cx , alloc) )
249
249
}
250
250
251
251
impl < ' a , ' tcx > FunctionCx < ' a , ' tcx > {
252
252
fn const_to_miri_value (
253
253
& mut self ,
254
- bcx : & Builder < ' a , ' tcx > ,
254
+ bx : & Builder < ' a , ' tcx > ,
255
255
constant : & ' tcx ty:: Const < ' tcx > ,
256
256
) -> Result < MiriValue , ConstEvalErr < ' tcx > > {
257
257
match constant. val {
258
258
ConstVal :: Unevaluated ( def_id, ref substs) => {
259
- let tcx = bcx . tcx ( ) ;
259
+ let tcx = bx . tcx ( ) ;
260
260
let param_env = ty:: ParamEnv :: empty ( traits:: Reveal :: All ) ;
261
261
let instance = ty:: Instance :: resolve ( tcx, param_env, def_id, substs) . unwrap ( ) ;
262
262
let cid = GlobalId {
263
263
instance,
264
264
promoted : None ,
265
265
} ;
266
266
let c = tcx. const_eval ( param_env. and ( cid) ) ?;
267
- self . const_to_miri_value ( bcx , c)
267
+ self . const_to_miri_value ( bx , c)
268
268
} ,
269
269
ConstVal :: Value ( miri_val) => Ok ( miri_val) ,
270
270
}
271
271
}
272
272
273
273
pub fn mir_constant_to_miri_value (
274
274
& mut self ,
275
- bcx : & Builder < ' a , ' tcx > ,
275
+ bx : & Builder < ' a , ' tcx > ,
276
276
constant : & mir:: Constant < ' tcx > ,
277
277
) -> Result < MiriValue , ConstEvalErr < ' tcx > > {
278
278
match constant. literal {
@@ -282,49 +282,49 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
282
282
instance : self . instance ,
283
283
promoted : Some ( index) ,
284
284
} ;
285
- bcx . tcx ( ) . const_eval ( param_env. and ( cid) )
285
+ bx . tcx ( ) . const_eval ( param_env. and ( cid) )
286
286
}
287
287
mir:: Literal :: Value { value } => {
288
288
Ok ( self . monomorphize ( & value) )
289
289
}
290
- } . and_then ( |c| self . const_to_miri_value ( bcx , c) )
290
+ } . and_then ( |c| self . const_to_miri_value ( bx , c) )
291
291
}
292
292
293
293
// Old version of trans_constant now used just for SIMD shuffle
294
294
pub fn remove_me_shuffle_indices ( & mut self ,
295
- bcx : & Builder < ' a , ' tcx > ,
295
+ bx : & Builder < ' a , ' tcx > ,
296
296
constant : & mir:: Constant < ' tcx > )
297
297
-> ( ValueRef , Ty < ' tcx > )
298
298
{
299
- let layout = bcx . ccx . layout_of ( constant. ty ) ;
300
- self . mir_constant_to_miri_value ( bcx , constant)
299
+ let layout = bx . cx . layout_of ( constant. ty ) ;
300
+ self . mir_constant_to_miri_value ( bx , constant)
301
301
. and_then ( |c| {
302
302
let llval = match c {
303
303
MiriValue :: ByVal ( val) => {
304
304
let scalar = match layout. abi {
305
305
layout:: Abi :: Scalar ( ref x) => x,
306
306
_ => bug ! ( "from_const: invalid ByVal layout: {:#?}" , layout)
307
307
} ;
308
- primval_to_llvm ( bcx . ccx , val, scalar, layout. immediate_llvm_type ( bcx . ccx ) )
308
+ primval_to_llvm ( bx . cx , val, scalar, layout. immediate_llvm_type ( bx . cx ) )
309
309
} ,
310
310
MiriValue :: ByValPair ( a_val, b_val) => {
311
311
let ( a_scalar, b_scalar) = match layout. abi {
312
312
layout:: Abi :: ScalarPair ( ref a, ref b) => ( a, b) ,
313
313
_ => bug ! ( "from_const: invalid ByValPair layout: {:#?}" , layout)
314
314
} ;
315
315
let a_llval = primval_to_llvm (
316
- bcx . ccx ,
316
+ bx . cx ,
317
317
a_val,
318
318
a_scalar,
319
- layout. scalar_pair_element_llvm_type ( bcx . ccx , 0 ) ,
319
+ layout. scalar_pair_element_llvm_type ( bx . cx , 0 ) ,
320
320
) ;
321
321
let b_llval = primval_to_llvm (
322
- bcx . ccx ,
322
+ bx . cx ,
323
323
b_val,
324
324
b_scalar,
325
- layout. scalar_pair_element_llvm_type ( bcx . ccx , 1 ) ,
325
+ layout. scalar_pair_element_llvm_type ( bx . cx , 1 ) ,
326
326
) ;
327
- C_struct ( bcx . ccx , & [ a_llval, b_llval] , false )
327
+ C_struct ( bx . cx , & [ a_llval, b_llval] , false )
328
328
} ,
329
329
MiriValue :: ByRef ( ..) => {
330
330
let field_ty = constant. ty . builtin_index ( ) . unwrap ( ) ;
@@ -334,7 +334,7 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
334
334
} ;
335
335
let values: Result < Vec < ValueRef > , _ > = ( 0 ..fields) . map ( |field| {
336
336
let field = const_val_field (
337
- bcx . tcx ( ) ,
337
+ bx . tcx ( ) ,
338
338
ty:: ParamEnv :: empty ( traits:: Reveal :: All ) ,
339
339
self . instance ,
340
340
None ,
@@ -344,29 +344,29 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
344
344
) ?;
345
345
match field. val {
346
346
ConstVal :: Value ( MiriValue :: ByVal ( prim) ) => {
347
- let layout = bcx . ccx . layout_of ( field_ty) ;
347
+ let layout = bx . cx . layout_of ( field_ty) ;
348
348
let scalar = match layout. abi {
349
349
layout:: Abi :: Scalar ( ref x) => x,
350
350
_ => bug ! ( "from_const: invalid ByVal layout: {:#?}" , layout)
351
351
} ;
352
352
Ok ( primval_to_llvm (
353
- bcx . ccx , prim, scalar,
354
- layout. immediate_llvm_type ( bcx . ccx ) ,
353
+ bx . cx , prim, scalar,
354
+ layout. immediate_llvm_type ( bx . cx ) ,
355
355
) )
356
356
} ,
357
357
other => bug ! ( "simd shuffle field {:?}, {}" , other, constant. ty) ,
358
358
}
359
359
} ) . collect ( ) ;
360
- C_struct ( bcx . ccx , & values?, false )
360
+ C_struct ( bx . cx , & values?, false )
361
361
} ,
362
362
} ;
363
363
Ok ( ( llval, constant. ty ) )
364
364
} )
365
365
. unwrap_or_else ( |e| {
366
- e. report ( bcx . tcx ( ) , constant. span , "shuffle_indices" ) ;
366
+ e. report ( bx . tcx ( ) , constant. span , "shuffle_indices" ) ;
367
367
// We've errored, so we don't have to produce working code.
368
368
let ty = self . monomorphize ( & constant. ty ) ;
369
- let llty = bcx . ccx . layout_of ( ty) . llvm_type ( bcx . ccx ) ;
369
+ let llty = bx . cx . layout_of ( ty) . llvm_type ( bx . cx ) ;
370
370
( C_undef ( llty) , ty)
371
371
} )
372
372
}
0 commit comments