Skip to content

Commit 8327e85

Browse files
Derive T_size from DataLayout (#49188)
1 parent dfc2cb5 commit 8327e85

11 files changed

+362
-341
lines changed

src/aotcompile.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,6 @@ static void jl_ci_cache_lookup(const jl_cgparams_t &cgparams, jl_method_instance
258258
*ci_out = codeinst;
259259
}
260260

261-
void replaceUsesWithLoad(Function &F, function_ref<GlobalVariable *(Instruction &I)> should_replace, MDNode *tbaa_const);
262-
263261
// takes the running content that has collected in the shadow module and dump it to disk
264262
// this builds the object file portion of the sysimage files for fast startup, and can
265263
// also be used be extern consumers like GPUCompiler.jl to obtain a module containing
@@ -1503,11 +1501,7 @@ void jl_dump_native_impl(void *native_code,
15031501
dataM->setTargetTriple(SourceTM->getTargetTriple().str());
15041502
dataM->setDataLayout(jl_create_datalayout(*SourceTM));
15051503

1506-
Type *T_size;
1507-
if (sizeof(size_t) == 8)
1508-
T_size = Type::getInt64Ty(Context);
1509-
else
1510-
T_size = Type::getInt32Ty(Context);
1504+
Type *T_size = dataM->getDataLayout().getIntPtrType(Context);
15111505
Type *T_psize = T_size->getPointerTo();
15121506

15131507
bool imaging_mode = imaging_default() || jl_options.outputo;

src/ccall.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,7 +1577,7 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
15771577
assert(!isVa && !llvmcall && nccallargs == 0);
15781578
JL_GC_POP();
15791579
ctx.builder.CreateCall(prepare_call(gcroot_flush_func));
1580-
emit_gc_safepoint(ctx.builder, get_current_ptls(ctx), ctx.tbaa().tbaa_const);
1580+
emit_gc_safepoint(ctx.builder, ctx.types().T_size, get_current_ptls(ctx), ctx.tbaa().tbaa_const);
15811581
return ghostValue(ctx, jl_nothing_type);
15821582
}
15831583
else if (is_libjulia_func("jl_get_ptls_states")) {
@@ -1682,7 +1682,7 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
16821682
ctx.builder.CreateLoad(
16831683
ctx.types().T_size,
16841684
ctx.builder.CreateConstInBoundsGEP1_32(ctx.types().T_size,
1685-
get_current_signal_page_from_ptls(ctx.builder, get_current_ptls(ctx), ctx.tbaa().tbaa_const), -1),
1685+
get_current_signal_page_from_ptls(ctx.builder, ctx.types().T_size, get_current_ptls(ctx), ctx.tbaa().tbaa_const), -1),
16861686
true);
16871687
ctx.builder.CreateBr(contBB);
16881688
ctx.f->getBasicBlockList().push_back(contBB);
@@ -1699,8 +1699,8 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
16991699
len = ConstantInt::get(ctx.types().T_size, jl_svec_len(svecv.constant));
17001700
}
17011701
else {
1702-
auto ptr = emit_bitcast(ctx, boxed(ctx, svecv), getSizePtrTy(ctx.builder.getContext()));
1703-
len = ctx.builder.CreateAlignedLoad(ctx.types().T_size, ptr, Align(sizeof(size_t)));
1702+
auto ptr = emit_bitcast(ctx, boxed(ctx, svecv), ctx.types().T_size->getPointerTo());
1703+
len = ctx.builder.CreateAlignedLoad(ctx.types().T_size, ptr, ctx.types().alignof_ptr);
17041704
// Only mark with TBAA if we are sure about the type.
17051705
// This could otherwise be in a dead branch
17061706
if (svecv.typ == (jl_value_t*)jl_simplevector_type) {
@@ -1868,9 +1868,9 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
18681868
if (val.typ == (jl_value_t*)jl_symbol_type) {
18691869
JL_GC_POP();
18701870
const int hash_offset = offsetof(jl_sym_t, hash);
1871-
Value *ph1 = emit_bitcast(ctx, decay_derived(ctx, boxed(ctx, val)), getSizePtrTy(ctx.builder.getContext()));
1872-
Value *ph2 = ctx.builder.CreateInBoundsGEP(ctx.types().T_size, ph1, ConstantInt::get(ctx.types().T_size, hash_offset / sizeof(size_t)));
1873-
LoadInst *hashval = ctx.builder.CreateAlignedLoad(ctx.types().T_size, ph2, Align(sizeof(size_t)));
1871+
Value *ph1 = emit_bitcast(ctx, decay_derived(ctx, boxed(ctx, val)), ctx.types().T_size->getPointerTo());
1872+
Value *ph2 = ctx.builder.CreateInBoundsGEP(ctx.types().T_size, ph1, ConstantInt::get(ctx.types().T_size, hash_offset / ctx.types().sizeof_ptr));
1873+
LoadInst *hashval = ctx.builder.CreateAlignedLoad(ctx.types().T_size, ph2, ctx.types().alignof_ptr);
18741874
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_const);
18751875
ai.decorateInst(hashval);
18761876
return mark_or_box_ccall_result(ctx, hashval, retboxed, rt, unionall, static_rt);

src/cgutils.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ static Value *maybe_bitcast(jl_codectx_t &ctx, Value *V, Type *to) {
554554
static Value *julia_binding_pvalue(jl_codectx_t &ctx, Value *bv)
555555
{
556556
bv = emit_bitcast(ctx, bv, ctx.types().T_pprjlvalue);
557-
Value *offset = ConstantInt::get(ctx.types().T_size, offsetof(jl_binding_t, value) / sizeof(size_t));
557+
Value *offset = ConstantInt::get(ctx.types().T_size, offsetof(jl_binding_t, value) / ctx.types().sizeof_ptr);
558558
return ctx.builder.CreateInBoundsGEP(ctx.types().T_prjlvalue, bv, offset);
559559
}
560560

@@ -1124,7 +1124,7 @@ static Value *emit_datatype_types(jl_codectx_t &ctx, Value *dt)
11241124

11251125
static Value *emit_datatype_nfields(jl_codectx_t &ctx, Value *dt)
11261126
{
1127-
Value *type_svec = emit_bitcast(ctx, emit_datatype_types(ctx, dt), getSizePtrTy(ctx.builder.getContext()));
1127+
Value *type_svec = emit_bitcast(ctx, emit_datatype_types(ctx, dt), ctx.types().T_size->getPointerTo());
11281128
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_const);
11291129
return ai.decorateInst(ctx.builder.CreateAlignedLoad(ctx.types().T_size, type_svec, Align(sizeof(void*))));
11301130
}
@@ -2715,7 +2715,7 @@ static Value *emit_arraylen_prim(jl_codectx_t &ctx, const jl_cgval_t &tinfo)
27152715
Value *addr = ctx.builder.CreateStructGEP(ctx.types().T_jlarray,
27162716
emit_bitcast(ctx, decay_derived(ctx, t), ctx.types().T_pjlarray),
27172717
1); //index (not offset) of length field in ctx.types().T_pjlarray
2718-
LoadInst *len = ctx.builder.CreateAlignedLoad(ctx.types().T_size, addr, Align(sizeof(size_t)));
2718+
LoadInst *len = ctx.builder.CreateAlignedLoad(ctx.types().T_size, addr, ctx.types().alignof_ptr);
27192719
len->setOrdering(AtomicOrdering::NotAtomic);
27202720
MDBuilder MDB(ctx.builder.getContext());
27212721
auto rng = MDB.createRange(Constant::getNullValue(ctx.types().T_size), ConstantInt::get(ctx.types().T_size, arraytype_maxsize(tinfo.typ)));
@@ -2923,7 +2923,7 @@ static Value *emit_array_nd_index(
29232923
// CreateAlloca is OK here since we are on an error branch
29242924
Value *tmp = ctx.builder.CreateAlloca(ctx.types().T_size, ConstantInt::get(ctx.types().T_size, nidxs));
29252925
for (size_t k = 0; k < nidxs; k++) {
2926-
ctx.builder.CreateAlignedStore(idxs[k], ctx.builder.CreateInBoundsGEP(ctx.types().T_size, tmp, ConstantInt::get(ctx.types().T_size, k)), Align(sizeof(size_t)));
2926+
ctx.builder.CreateAlignedStore(idxs[k], ctx.builder.CreateInBoundsGEP(ctx.types().T_size, tmp, ConstantInt::get(ctx.types().T_size, k)), ctx.types().alignof_ptr);
29272927
}
29282928
ctx.builder.CreateCall(prepare_call(jlboundserrorv_func),
29292929
{ mark_callee_rooted(ctx, a), tmp, ConstantInt::get(ctx.types().T_size, nidxs) });
@@ -3040,7 +3040,8 @@ static jl_value_t *static_constant_instance(const llvm::DataLayout &DL, Constant
30403040
return obj;
30413041
}
30423042

3043-
static Value *call_with_attrs(jl_codectx_t &ctx, JuliaFunction *intr, Value *v)
3043+
template<typename TypeFn_t>
3044+
static Value *call_with_attrs(jl_codectx_t &ctx, JuliaFunction<TypeFn_t> *intr, Value *v)
30443045
{
30453046
Function *F = prepare_call(intr);
30463047
CallInst *Call = ctx.builder.CreateCall(F, v);

0 commit comments

Comments
 (0)