@@ -273,113 +273,22 @@ fn bump_ptr(bcx: block, t: ty::t, base: ValueRef, sz: ValueRef) ->
273
273
} else { bumped }
274
274
}
275
275
276
- // Replacement for the LLVM 'GEP' instruction when field-indexing into a
277
- // tuple-like structure (tup, rec) with a static index. This one is driven off
278
- // ty::struct and knows what to do when it runs into a ty_param stuck in the
279
- // middle of the thing it's GEP'ing into. Much like size_of and align_of,
280
- // above.
281
- fn GEP_tup_like ( bcx : block , t : ty:: t , base : ValueRef , ixs : [ int ] )
282
- -> result {
283
- fn compute_off ( bcx : block ,
284
- off : ValueRef ,
285
- t : ty:: t ,
286
- ixs : [ int ] ,
287
- n : uint ) -> ( block , ValueRef , ty:: t ) {
288
- if n == ixs. len ( ) {
289
- ret ( bcx, off, t) ;
290
- }
291
-
292
- let ix = ixs[ n] ;
293
- let bcx = bcx, off = off;
294
- int:: range ( 0 , ix) { |i|
295
- let comp_t = ty:: get_element_type ( t, i as uint ) ;
296
- let align = align_of ( bcx, comp_t) ;
297
- bcx = align. bcx ;
298
- off = align_to ( bcx, off, align. val ) ;
299
- let sz = size_of ( bcx, comp_t) ;
300
- bcx = sz. bcx ;
301
- off = Add ( bcx, off, sz. val ) ;
302
- }
303
-
304
- let comp_t = ty:: get_element_type ( t, ix as uint ) ;
305
- let align = align_of ( bcx, comp_t) ;
306
- bcx = align. bcx ;
307
- off = align_to ( bcx, off, align. val ) ;
308
-
309
- be compute_off ( bcx, off, comp_t, ixs, n+1 u) ;
310
- }
311
-
312
- if !ty:: type_has_dynamic_size ( bcx. tcx ( ) , t) {
313
- ret rslt ( bcx, GEPi ( bcx, base, ixs) ) ;
314
- }
315
-
316
- #debug[ "GEP_tup_like(t=%s,base=%s,ixs=%?)" ,
317
- ty_to_str ( bcx. tcx ( ) , t) ,
318
- val_str ( bcx. ccx ( ) . tn , base) ,
319
- ixs] ;
320
-
321
- // We require that ixs start with 0 and we expect the input to be a
322
- // pointer to an instance of type t, so we can safely ignore ixs[0],
323
- // basically.
324
- assert ixs[ 0 ] == 0 ;
325
-
326
- let ( bcx, off, tar_t) = {
327
- compute_off ( bcx, C_int ( bcx. ccx ( ) , 0 ) , t, ixs, 1 u)
328
- } ;
329
- ret rslt( bcx, bump_ptr ( bcx, tar_t, base, off) ) ;
330
- }
331
-
332
-
333
276
// Replacement for the LLVM 'GEP' instruction when field indexing into a enum.
334
- // This function uses GEP_tup_like() above and automatically performs casts as
335
- // appropriate. @llblobptr is the data part of a enum value; its actual type
277
+ // @llblobptr is the data part of a enum value; its actual type
336
278
// is meaningless, as it will be cast away.
337
- fn GEP_enum ( cx : block , llblobptr : ValueRef , enum_id : ast:: def_id ,
338
- variant_id : ast:: def_id , ty_substs : [ ty:: t ] ,
339
- ix : uint ) -> result {
340
- let variant = ty:: enum_variant_with_id ( cx. tcx ( ) , enum_id, variant_id) ;
279
+ fn GEP_enum ( bcx : block , llblobptr : ValueRef , enum_id : ast:: def_id ,
280
+ variant_id : ast:: def_id , ty_substs : [ ty:: t ] ,
281
+ ix : uint ) -> result {
282
+ let ccx = bcx. ccx ( ) ;
283
+ let variant = ty:: enum_variant_with_id ( ccx. tcx , enum_id, variant_id) ;
341
284
assert ix < variant. args . len ( ) ;
342
285
343
- // Synthesize a tuple type so that GEP_tup_like() can work its magic.
344
- // Separately, store the type of the element we're interested in.
345
-
346
- let arg_tys = variant. args ;
347
-
348
- let true_arg_tys: [ ty:: t ] = [ ] ;
349
- for aty: ty:: t in arg_tys {
350
- // Would be nice to have a way of stating the invariant
351
- // that ty_substs is valid for aty
352
- let arg_ty = ty:: substitute_type_params ( cx. tcx ( ) , ty_substs, aty) ;
353
- true_arg_tys += [ arg_ty] ;
354
- }
355
-
356
- // We know that ix < len(variant.args) -- so
357
- // it's safe to do this. (Would be nice to have
358
- // typestate guarantee that a dynamic bounds check
359
- // error can't happen here, but that's in the future.)
360
- let elem_ty = true_arg_tys[ ix] ;
361
-
362
- let tup_ty = ty:: mk_tup ( cx. tcx ( ) , true_arg_tys) ;
363
- // Cast the blob pointer to the appropriate type, if we need to (i.e. if
364
- // the blob pointer isn't dynamically sized).
365
-
366
- let llunionptr: ValueRef ;
367
- let ccx = cx. ccx ( ) ;
368
- if check type_has_static_size ( ccx, tup_ty) {
369
- let llty = type_of ( ccx, tup_ty) ;
370
- llunionptr = TruncOrBitCast ( cx, llblobptr, T_ptr ( llty) ) ;
371
- } else { llunionptr = llblobptr; }
372
-
373
- // Do the GEP_tup_like().
374
- let rs = GEP_tup_like ( cx, tup_ty, llunionptr, [ 0 , ix as int ] ) ;
375
- // Cast the result to the appropriate type, if necessary.
376
-
377
- let val = if check type_has_static_size ( ccx, elem_ty) {
378
- let llelemty = type_of ( ccx, elem_ty) ;
379
- PointerCast ( rs. bcx , rs. val , T_ptr ( llelemty) )
380
- } else { rs. val } ;
381
-
382
- ret rslt( rs. bcx , val) ;
286
+ let arg_lltys = vec:: map ( variant. args , { |aty|
287
+ type_of ( ccx, ty:: substitute_type_params ( ccx. tcx , ty_substs, aty) )
288
+ } ) ;
289
+ let typed_blobptr = PointerCast ( bcx, llblobptr,
290
+ T_ptr ( T_struct ( arg_lltys) ) ) ;
291
+ rslt ( bcx, GEPi ( bcx, typed_blobptr, [ 0 , ix as int ] ) )
383
292
}
384
293
385
294
// trans_shared_malloc: expects a type indicating which pointer type we want
@@ -823,11 +732,10 @@ fn trans_res_drop(bcx: block, rs: ValueRef, did: ast::def_id,
823
732
inner_t : ty:: t , tps : [ ty:: t ] ) -> block {
824
733
let ccx = bcx. ccx ( ) ;
825
734
let inner_t_s = ty:: substitute_type_params ( ccx. tcx , tps, inner_t) ;
826
- let tup_ty = ty:: mk_tup ( ccx. tcx , [ ty:: mk_int ( ccx. tcx ) , inner_t_s] ) ;
827
735
828
- let { bcx , val : drop_flag } = GEP_tup_like ( bcx, tup_ty , rs, [ 0 , 0 ] ) ;
736
+ let drop_flag = GEPi ( bcx, rs, [ 0 , 0 ] ) ;
829
737
with_cond ( bcx, IsNotNull ( bcx, Load ( bcx, drop_flag) ) ) { |bcx|
830
- let { bcx , val : valptr} = GEP_tup_like ( bcx, tup_ty , rs, [ 0 , 1 ] ) ;
738
+ let valptr = GEPi ( bcx, rs, [ 0 , 1 ] ) ;
831
739
// Find and call the actual destructor.
832
740
let dtor_addr = get_res_dtor ( ccx, did, tps) ;
833
741
let args = [ bcx. fcx . llretptr , null_env_ptr ( bcx) ] ;
@@ -840,7 +748,7 @@ fn trans_res_drop(bcx: block, rs: ValueRef, did: ast::def_id,
840
748
let val_cast = BitCast ( bcx, valptr, val_llty) ;
841
749
Call ( bcx, dtor_addr, args + [ val_cast] ) ;
842
750
843
- bcx = drop_ty ( bcx, valptr, inner_t_s) ;
751
+ let bcx = drop_ty ( bcx, valptr, inner_t_s) ;
844
752
Store ( bcx, C_u8 ( 0 u) , drop_flag) ;
845
753
bcx
846
754
}
@@ -1014,26 +922,24 @@ fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t,
1014
922
ty:: ty_rec ( fields) {
1015
923
let i: int = 0 ;
1016
924
for fld: ty:: field in fields {
1017
- let { bcx : bcx , val : llfld_a } = GEP_tup_like ( cx, t , av, [ 0 , i] ) ;
1018
- cx = f ( bcx , llfld_a, fld. mt . ty ) ;
925
+ let llfld_a = GEPi ( cx, av, [ 0 , i] ) ;
926
+ cx = f ( cx , llfld_a, fld. mt . ty ) ;
1019
927
i += 1 ;
1020
928
}
1021
929
}
1022
930
ty:: ty_tup ( args) {
1023
931
let i = 0 ;
1024
932
for arg in args {
1025
- let { bcx : bcx , val : llfld_a } = GEP_tup_like ( cx, t , av, [ 0 , i] ) ;
1026
- cx = f ( bcx , llfld_a, arg) ;
933
+ let llfld_a = GEPi ( cx, av, [ 0 , i] ) ;
934
+ cx = f ( cx , llfld_a, arg) ;
1027
935
i += 1 ;
1028
936
}
1029
937
}
1030
938
ty:: ty_res ( _, inner, tps) {
1031
939
let tcx = cx. tcx ( ) ;
1032
940
let inner1 = ty:: substitute_type_params ( tcx, tps, inner) ;
1033
- let inner_t_s = ty:: substitute_type_params ( tcx, tps, inner) ;
1034
- let tup_t = ty:: mk_tup ( tcx, [ ty:: mk_int ( tcx) , inner_t_s] ) ;
1035
- let { bcx: bcx , val : llfld_a } = GEP_tup_like ( cx, tup_t, av, [ 0 , 1 ] ) ;
1036
- ret f( bcx, llfld_a, inner1) ;
941
+ let llfld_a = GEPi ( cx, av, [ 0 , 1 ] ) ;
942
+ ret f( cx, llfld_a, inner1) ;
1037
943
}
1038
944
ty:: ty_enum ( tid, tps) {
1039
945
let variants = ty:: enum_variants ( cx. tcx ( ) , tid) ;
@@ -1074,8 +980,8 @@ fn iter_structural_ty(cx: block, av: ValueRef, t: ty::t,
1074
980
// a class is like a record type
1075
981
let i: int = 0 ;
1076
982
for fld: ty:: field in ty:: class_items_as_fields ( cx. tcx ( ) , did) {
1077
- let { bcx : bcx , val : llfld_a } = GEP_tup_like ( cx, t , av, [ 0 , i] ) ;
1078
- cx = f ( bcx , llfld_a, fld. mt . ty ) ;
983
+ let llfld_a = GEPi ( cx, av, [ 0 , i] ) ;
984
+ cx = f ( cx , llfld_a, fld. mt . ty ) ;
1079
985
i += 1 ;
1080
986
}
1081
987
}
@@ -2305,7 +2211,7 @@ fn trans_rec_field(bcx: block, base: @ast::expr,
2305
2211
base expr has non-record type") ; }
2306
2212
} ;
2307
2213
let ix = option:: get ( ty:: field_idx ( field, fields) ) ;
2308
- let { bcx , val} = GEP_tup_like ( bcx, ty , val, [ 0 , ix as int ] ) ;
2214
+ let val = GEPi ( bcx, val, [ 0 , ix as int ] ) ;
2309
2215
ret { bcx : bcx, val : val, kind : owned} ;
2310
2216
}
2311
2217
@@ -2837,9 +2743,7 @@ fn get_landing_pad(bcx: block) -> BasicBlockRef {
2837
2743
ret pad_bcx. llbb ;
2838
2744
}
2839
2745
2840
- fn trans_tup ( bcx : block , elts : [ @ast:: expr ] , id : ast:: node_id ,
2841
- dest : dest ) -> block {
2842
- let t = node_id_type ( bcx, id) ;
2746
+ fn trans_tup ( bcx : block , elts : [ @ast:: expr ] , dest : dest ) -> block {
2843
2747
let bcx = bcx;
2844
2748
let addr = alt dest {
2845
2749
ignore {
@@ -2851,11 +2755,11 @@ fn trans_tup(bcx: block, elts: [@ast::expr], id: ast::node_id,
2851
2755
} ;
2852
2756
let temp_cleanups = [ ] , i = 0 ;
2853
2757
for e in elts {
2854
- let dst = GEP_tup_like ( bcx, t , addr, [ 0 , i] ) ;
2758
+ let dst = GEPi ( bcx, addr, [ 0 , i] ) ;
2855
2759
let e_ty = expr_ty ( bcx, e) ;
2856
- bcx = trans_expr_save_in ( dst . bcx , e, dst. val ) ;
2857
- add_clean_temp_mem ( bcx, dst. val , e_ty) ;
2858
- temp_cleanups += [ dst. val ] ;
2760
+ bcx = trans_expr_save_in ( bcx, e, dst) ;
2761
+ add_clean_temp_mem ( bcx, dst, e_ty) ;
2762
+ temp_cleanups += [ dst] ;
2859
2763
i += 1 ;
2860
2764
}
2861
2765
for cleanup in temp_cleanups { revoke_clean ( bcx, cleanup) ; }
@@ -2887,10 +2791,10 @@ fn trans_rec(bcx: block, fields: [ast::field],
2887
2791
let ix = option:: get ( vec:: position ( ty_fields, { |ft|
2888
2792
str:: eq ( fld. node . ident , ft. ident )
2889
2793
} ) ) ;
2890
- let dst = GEP_tup_like ( bcx, t , addr, [ 0 , ix as int ] ) ;
2891
- bcx = trans_expr_save_in ( dst . bcx , fld. node . expr , dst. val ) ;
2892
- add_clean_temp_mem ( bcx, dst. val , ty_fields[ ix] . mt . ty ) ;
2893
- temp_cleanups += [ dst. val ] ;
2794
+ let dst = GEPi ( bcx, addr, [ 0 , ix as int ] ) ;
2795
+ bcx = trans_expr_save_in ( bcx, fld. node . expr , dst) ;
2796
+ add_clean_temp_mem ( bcx, dst, ty_fields[ ix] . mt . ty ) ;
2797
+ temp_cleanups += [ dst] ;
2894
2798
}
2895
2799
alt base {
2896
2800
some( bexp) {
@@ -2899,10 +2803,10 @@ fn trans_rec(bcx: block, fields: [ast::field],
2899
2803
// Copy over inherited fields
2900
2804
for tf in ty_fields {
2901
2805
if !vec:: any ( fields, { |f| str:: eq ( f. node . ident , tf. ident ) } ) {
2902
- let dst = GEP_tup_like ( bcx, t , addr, [ 0 , i] ) ;
2903
- let base = GEP_tup_like ( bcx, t , base_val, [ 0 , i] ) ;
2904
- let val = load_if_immediate ( base . bcx , base. val , tf. mt . ty ) ;
2905
- bcx = copy_val ( base . bcx , INIT , dst. val , val, tf. mt . ty ) ;
2806
+ let dst = GEPi ( bcx, addr, [ 0 , i] ) ;
2807
+ let base = GEPi ( bcx, base_val, [ 0 , i] ) ;
2808
+ let val = load_if_immediate ( bcx, base, tf. mt . ty ) ;
2809
+ bcx = copy_val ( bcx, INIT , dst, val, tf. mt . ty ) ;
2906
2810
}
2907
2811
i += 1 ;
2908
2812
}
@@ -2997,7 +2901,7 @@ fn trans_expr(bcx: block, e: @ast::expr, dest: dest) -> block {
2997
2901
ast:: expr_rec ( args, base) {
2998
2902
ret trans_rec ( bcx, args, base, e. id , dest) ;
2999
2903
}
3000
- ast:: expr_tup ( args) { ret trans_tup ( bcx, args, e . id , dest) ; }
2904
+ ast:: expr_tup ( args) { ret trans_tup ( bcx, args, dest) ; }
3001
2905
ast:: expr_lit ( lit) { ret trans_lit ( bcx, * lit, dest) ; }
3002
2906
ast:: expr_vec ( args, _) { ret tvec:: trans_vec ( bcx, args, e. id , dest) ; }
3003
2907
ast:: expr_binary ( op, lhs, rhs) {
@@ -3974,8 +3878,6 @@ fn trans_res_ctor(ccx: @crate_ctxt, path: path, dtor: ast::fn_decl,
3974
3878
let bcx = top_scope_block ( fcx, none) , lltop = bcx. llbb ;
3975
3879
let fty = node_id_type ( bcx, ctor_id) ;
3976
3880
let arg_t = ty:: ty_fn_args ( fty) [ 0 ] . ty ;
3977
- let tup_t = ty:: mk_tup ( ccx. tcx , [ ty:: mk_mach_uint ( ccx. tcx , ast:: ty_u8) ,
3978
- arg_t] ) ;
3979
3881
let arg = alt fcx. llargs . find ( dtor. inputs [ 0 ] . id ) {
3980
3882
some ( local_mem ( x) ) { x }
3981
3883
_ { ccx. sess . bug ( "Someone forgot to document an invariant \
@@ -3987,12 +3889,11 @@ fn trans_res_ctor(ccx: @crate_ctxt, path: path, dtor: ast::fn_decl,
3987
3889
llretptr = BitCast ( bcx, llretptr, llret_t) ;
3988
3890
}
3989
3891
3990
- let { bcx , val : dst } = GEP_tup_like ( bcx, tup_t , llretptr, [ 0 , 1 ] ) ;
3892
+ let dst = GEPi ( bcx, llretptr, [ 0 , 1 ] ) ;
3991
3893
bcx = memmove_ty ( bcx, dst, arg, arg_t) ;
3992
- let flag = GEP_tup_like ( bcx, tup_t, llretptr, [ 0 , 0 ] ) ;
3993
- bcx = flag. bcx ;
3894
+ let flag = GEPi ( bcx, llretptr, [ 0 , 0 ] ) ;
3994
3895
let one = C_u8 ( 1 u) ;
3995
- Store ( bcx, one, flag. val ) ;
3896
+ Store ( bcx, one, flag) ;
3996
3897
build_return ( bcx) ;
3997
3898
finish_fn ( fcx, lltop) ;
3998
3899
}
0 commit comments