@@ -221,24 +221,22 @@ static Constant *julia_const_to_llvm(jl_value_t *e)
221
221
}
222
222
JL_GC_POP ();
223
223
Type *t = julia_struct_to_llvm (jt);
224
- if (type_is_ghost (t ))
224
+ if (t == T_void || t-> isEmptyTy ( ))
225
225
return UndefValue::get (NoopType);
226
- if (t->isVectorTy ())
227
- return ConstantVector::get (ArrayRef<Constant*>(fields,llvm_nf));
228
-
229
- Constant *init;
230
226
if (t->isStructTy ()) {
231
227
StructType *st = dyn_cast<StructType>(t);
232
228
assert (st);
233
- init = ConstantStruct::get (st, ArrayRef<Constant*>(fields,llvm_nf));
229
+ return ConstantStruct::get (st, ArrayRef<Constant*>(fields,llvm_nf));
230
+ }
231
+ else if (t->isVectorTy ()) {
232
+ return ConstantVector::get (ArrayRef<Constant*>(fields,llvm_nf));
234
233
}
235
234
else {
236
235
assert (t->isArrayTy ());
237
236
ArrayType *at = dyn_cast<ArrayType>(t);
238
237
assert (at);
239
- init = ConstantArray::get (at, ArrayRef<Constant*>(fields,llvm_nf));
238
+ return ConstantArray::get (at, ArrayRef<Constant*>(fields,llvm_nf));
240
239
}
241
- return new GlobalVariable (*jl_Module, t, true , GlobalVariable::ExternalLinkage, init);
242
240
}
243
241
return NULL ;
244
242
}
@@ -265,19 +263,13 @@ static Value *emit_unbox(Type *to, Value *x, jl_value_t *jt)
265
263
return UndefValue::get (to);
266
264
}
267
265
if (ty != jl_pvalue_llvmt) {
268
- if (to->isAggregateType ()) {
269
- x = builder.CreateLoad (x); // something stack allocated
270
- ty = x->getType ();
271
- }
272
- else {
273
- // bools are stored internally as int8 (for now)
274
- if (ty == T_int1 && to == T_int8)
275
- return builder.CreateZExt (x, T_int8);
276
- if (ty->isPointerTy () && !to->isPointerTy ())
277
- return builder.CreatePtrToInt (x, to);
278
- if (!ty->isPointerTy () && to->isPointerTy ())
279
- return builder.CreateIntToPtr (x, to);
280
- }
266
+ // bools are stored internally as int8 (for now)
267
+ if (ty == T_int1 && to == T_int8)
268
+ return builder.CreateZExt (x, T_int8);
269
+ if (ty->isPointerTy () && !to->isPointerTy ())
270
+ return builder.CreatePtrToInt (x, to);
271
+ if (!ty->isPointerTy () && to->isPointerTy ())
272
+ return builder.CreateIntToPtr (x, to);
281
273
if (ty != to) {
282
274
// this can happen when a branch yielding a different type ends
283
275
// up being dead code, and type inference knows that the other
@@ -287,20 +279,21 @@ static Value *emit_unbox(Type *to, Value *x, jl_value_t *jt)
287
279
}
288
280
return x;
289
281
}
290
- Value *p = x ;
282
+ Value *p = data_pointer (x) ;
291
283
if (to == T_int1) {
292
284
// bools stored as int8, so an extra Trunc is needed to get an int1
293
285
return builder.CreateTrunc (builder.
294
286
CreateLoad (builder.
295
- CreateBitCast (p, T_pint8)),
287
+ CreateBitCast (p, T_pint8), false ),
296
288
T_int1);
297
289
}
298
290
if (to->isStructTy () && !to->isSized ()) {
299
291
// empty struct - TODO - is this a good way to represent it?
300
292
assert (to != T_void);
301
293
return UndefValue::get (to);
302
294
}
303
- return builder.CreateAlignedLoad (builder.CreateBitCast (p, to->getPointerTo ()), 16 ); // julia's gc gives 16-byte aligned addresses
295
+ // TODO: stricter alignment if possible
296
+ return builder.CreateAlignedLoad (builder.CreateBitCast (p, to->getPointerTo ()), sizeof (void *), false );
304
297
}
305
298
306
299
// unbox trying to determine type automatically
@@ -334,9 +327,7 @@ static Value *auto_unbox(jl_value_t *x, jl_codectx_t *ctx)
334
327
if (to == T_void) {
335
328
return NULL ;
336
329
}
337
- if (to->isAggregateType () && jl_is_immutable_datatype (bt)) // can lazy load on demand, no copy needed
338
- return builder.CreateBitCast (v, to->getPointerTo ());
339
- return emit_reg2mem (emit_unbox (to, v, bt), ctx);
330
+ return emit_unbox (to, v, bt);
340
331
}
341
332
342
333
// figure out how many bits a bitstype has at compile time, or -1
@@ -366,10 +357,7 @@ static Value *generic_unbox(jl_value_t *targ, jl_value_t *x, jl_codectx_t *ctx)
366
357
jl_value_t *p = jl_tparam0 (et);
367
358
if (jl_is_leaf_type (p)) {
368
359
Type *to = julia_type_to_llvm (p);
369
- Value *lx = emit_unboxed (x,ctx);
370
- if (to->isAggregateType () && lx->getType () == PointerType::get (to,0 ) && jl_is_immutable (p)) // can lazy load on demand, no copy needed
371
- return lx;
372
- return emit_reg2mem (emit_unbox (to, lx, p), ctx);
360
+ return emit_unbox (to, emit_unboxed (x,ctx), p);
373
361
}
374
362
}
375
363
int nb = try_to_determine_bitstype_nbits (targ, ctx);
@@ -441,9 +429,6 @@ static Value *generic_box(jl_value_t *targ, jl_value_t *x, jl_codectx_t *ctx)
441
429
442
430
Value *vx = auto_unbox (x, ctx);
443
431
Type *vxt = vx->getType ();
444
- if (llvmt->isAggregateType () && vxt->isPointerTy ()) {
445
- vxt = vxt->getContainedType (0 );
446
- }
447
432
// if (vx->getType()->getPrimitiveSizeInBits() != (unsigned)nb)
448
433
// jl_errorf("box: expected argument with %d bits, got %d", nb,
449
434
// vx->getType()->getPrimitiveSizeInBits());
@@ -487,10 +472,7 @@ static Value *generic_box(jl_value_t *targ, jl_value_t *x, jl_codectx_t *ctx)
487
472
}
488
473
489
474
// dynamically-determined type; evaluate.
490
- if (llvmt->isAggregateType ()) {
491
- vx = builder.CreateLoad (vx); // something stack allocated
492
- }
493
- return allocate_box_dynamic (emit_expr (targ, ctx), ConstantInt::get (T_size,nb), vx);
475
+ return allocate_box_dynamic (emit_expr (targ, ctx), ConstantInt::get (T_size,(nb+7 )/8 ), vx);
494
476
}
495
477
496
478
static Type *staticeval_bitstype (jl_value_t *targ, const char *fname, jl_codectx_t *ctx)
0 commit comments