@@ -87,15 +87,15 @@ static Value *runtime_sym_lookup(
87
87
BasicBlock *dlsym_lookup = BasicBlock::Create (jl_LLVMContext, " dlsym" );
88
88
BasicBlock *ccall_bb = BasicBlock::Create (jl_LLVMContext, " ccall" );
89
89
Constant *initnul = ConstantPointerNull::get ((PointerType*)T_pvoidfunc);
90
- LoadInst *llvmf_orig = irbuilder.CreateAlignedLoad (llvmgv, sizeof (void *));
90
+ LoadInst *llvmf_orig = irbuilder.CreateAlignedLoad (T_pvoidfunc, llvmgv, sizeof (void *));
91
91
// This in principle needs a consume ordering so that load from
92
92
// this pointer sees a valid value. However, this is not supported by
93
93
// LLVM (or agreed on in the C/C++ standard FWIW) and should be
94
94
// almost impossible to happen on every platform we support since this
95
95
// ordering is enforced by the hardware and LLVM has to speculate an
96
96
// invalid load from the `cglobal` but doesn't depend on the `cglobal`
97
97
// value for this to happen.
98
- // llvmf_orig->setAtomic(AtomicOrdering::Consume );
98
+ llvmf_orig->setAtomic (AtomicOrdering::Unordered );
99
99
irbuilder.CreateCondBr (
100
100
irbuilder.CreateICmpNE (llvmf_orig, initnul),
101
101
ccall_bb,
@@ -114,7 +114,7 @@ static Value *runtime_sym_lookup(
114
114
}
115
115
Value *llvmf = irbuilder.CreateCall (prepare_call_in (jl_builderModule (irbuilder), jldlsym_func),
116
116
{ libname, stringConstPtr (emission_context, irbuilder, f_name), libptrgv });
117
- auto store = irbuilder.CreateAlignedStore (llvmf, llvmgv, sizeof (void *));
117
+ StoreInst * store = irbuilder.CreateAlignedStore (llvmf, llvmgv, sizeof (void *));
118
118
store->setAtomic (AtomicOrdering::Release);
119
119
irbuilder.CreateBr (ccall_bb);
120
120
@@ -169,7 +169,7 @@ static GlobalVariable *emit_plt_thunk(
169
169
IRBuilder<> irbuilder (b0);
170
170
Value *ptr = runtime_sym_lookup (emission_context, irbuilder, funcptype, f_lib, f_name, plt, libptrgv,
171
171
llvmgv, runtime_lib);
172
- auto store = irbuilder.CreateAlignedStore (irbuilder.CreateBitCast (ptr, T_pvoidfunc), got, sizeof (void *));
172
+ StoreInst * store = irbuilder.CreateAlignedStore (irbuilder.CreateBitCast (ptr, T_pvoidfunc), got, sizeof (void *));
173
173
store->setAtomic (AtomicOrdering::Release);
174
174
SmallVector<Value*, 16 > args;
175
175
for (Function::arg_iterator arg = plt->arg_begin (), arg_e = plt->arg_end (); arg != arg_e; ++arg)
@@ -234,7 +234,7 @@ static Value *emit_plt(
234
234
// consume ordering too. This is even less likely to cause issues though
235
235
// since the only thing we do to this loaded pointer is to call it
236
236
// immediately.
237
- // got_val->setAtomic(AtomicOrdering::Consume );
237
+ got_val->setAtomic (AtomicOrdering::Unordered );
238
238
return ctx.builder .CreateBitCast (got_val, funcptype);
239
239
}
240
240
@@ -349,17 +349,19 @@ static Value *llvm_type_rewrite(
349
349
Value *from;
350
350
Value *to;
351
351
const DataLayout &DL = jl_data_layout;
352
+ unsigned align = std::max (DL.getPrefTypeAlignment (target_type), DL.getPrefTypeAlignment (from_type));
352
353
if (DL.getTypeAllocSize (target_type) >= DL.getTypeAllocSize (from_type)) {
353
354
to = emit_static_alloca (ctx, target_type);
355
+ cast<AllocaInst>(to)->setAlignment (Align (align));
354
356
from = emit_bitcast (ctx, to, from_type->getPointerTo ());
355
357
}
356
358
else {
357
359
from = emit_static_alloca (ctx, from_type);
360
+ cast<AllocaInst>(from)->setAlignment (Align (align));
358
361
to = emit_bitcast (ctx, from, target_type->getPointerTo ());
359
362
}
360
- // XXX: deal with possible alignment issues
361
- ctx.builder .CreateStore (v, from);
362
- return ctx.builder .CreateLoad (to);
363
+ ctx.builder .CreateAlignedStore (v, from, align);
364
+ return ctx.builder .CreateAlignedLoad (to, align);
363
365
}
364
366
365
367
// --- argument passing and scratch space utilities ---
@@ -1576,9 +1578,9 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
1576
1578
Value *ptls_i16 = emit_bitcast (ctx, ctx.ptlsStates , T_pint16);
1577
1579
const int tid_offset = offsetof (jl_tls_states_t , tid);
1578
1580
Value *ptid = ctx.builder .CreateGEP (ptls_i16, ConstantInt::get (T_size, tid_offset / 2 ));
1579
- return mark_or_box_ccall_result ( ctx,
1580
- tbaa_decorate (tbaa_const, ctx. builder . CreateLoad (ptid)),
1581
- retboxed, rt, unionall, static_rt);
1581
+ LoadInst *tid = ctx. builder . CreateAlignedLoad (ptid, sizeof ( int16_t ));
1582
+ tbaa_decorate (tbaa_const, tid);
1583
+ return mark_or_box_ccall_result (ctx, tid, retboxed, rt, unionall, static_rt);
1582
1584
}
1583
1585
else if (is_libjulia_func (jl_get_current_task)) {
1584
1586
assert (lrt == T_prjlvalue);
@@ -1587,9 +1589,9 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
1587
1589
Value *ptls_pv = emit_bitcast (ctx, ctx.ptlsStates , T_pprjlvalue);
1588
1590
const int ct_offset = offsetof (jl_tls_states_t , current_task);
1589
1591
Value *pct = ctx.builder .CreateGEP (ptls_pv, ConstantInt::get (T_size, ct_offset / sizeof (void *)));
1590
- return mark_or_box_ccall_result ( ctx,
1591
- tbaa_decorate (tbaa_const, ctx. builder . CreateLoad (pct)),
1592
- retboxed, rt, unionall, static_rt);
1592
+ LoadInst *ct = ctx. builder . CreateAlignedLoad (pct, sizeof ( void *));
1593
+ tbaa_decorate (tbaa_const, ct);
1594
+ return mark_or_box_ccall_result (ctx, ct, retboxed, rt, unionall, static_rt);
1593
1595
}
1594
1596
else if (is_libjulia_func (jl_set_next_task)) {
1595
1597
assert (lrt == T_void);
@@ -1608,8 +1610,7 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
1608
1610
ctx.builder .CreateCall (prepare_call (gcroot_flush_func));
1609
1611
Value *pdefer_sig = emit_defer_signal (ctx);
1610
1612
Value *defer_sig = ctx.builder .CreateLoad (pdefer_sig);
1611
- defer_sig = ctx.builder .CreateAdd (defer_sig,
1612
- ConstantInt::get (T_sigatomic, 1 ));
1613
+ defer_sig = ctx.builder .CreateAdd (defer_sig, ConstantInt::get (T_sigatomic, 1 ));
1613
1614
ctx.builder .CreateStore (defer_sig, pdefer_sig);
1614
1615
emit_signal_fence (ctx);
1615
1616
return ghostValue (jl_nothing_type);
@@ -1671,7 +1672,9 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
1671
1672
idx = ctx.builder .CreateAdd (idx, ConstantInt::get (T_size, ((jl_datatype_t *)ety)->layout ->first_ptr ));
1672
1673
}
1673
1674
Value *slot_addr = ctx.builder .CreateInBoundsGEP (T_prjlvalue, arrayptr, idx);
1674
- Value *load = tbaa_decorate (tbaa_ptrarraybuf, ctx.builder .CreateLoad (T_prjlvalue, slot_addr));
1675
+ LoadInst *load = ctx.builder .CreateAlignedLoad (T_prjlvalue, slot_addr, sizeof (void *));
1676
+ load->setAtomic (AtomicOrdering::Unordered);
1677
+ tbaa_decorate (tbaa_ptrarraybuf, load);
1675
1678
Value *res = ctx.builder .CreateZExt (ctx.builder .CreateICmpNE (load, Constant::getNullValue (T_prjlvalue)), T_int32);
1676
1679
JL_GC_POP ();
1677
1680
return mark_or_box_ccall_result (ctx, res, retboxed, rt, unionall, static_rt);
0 commit comments