Skip to content

Commit

Permalink
Remove basic pointer types
Browse files Browse the repository at this point in the history
  • Loading branch information
Prem Chintalapudi committed Jan 11, 2022
1 parent 85aaa49 commit 132aee6
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 79 deletions.
28 changes: 14 additions & 14 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ static bool runtime_sym_gvs(jl_codegen_params_t &emission_context, const char *f
runtime_lib = true;
auto &libgv = emission_context.libMapGV[f_lib];
if (libgv.first == NULL) {
libptrgv = new GlobalVariable(*M, T_pint8, false,
libptrgv = new GlobalVariable(*M, llvm::Type::getInt8PtrTy(M->getContext()), false,
GlobalVariable::ExternalLinkage,
Constant::getNullValue(T_pint8), name);
Constant::getNullValue(llvm::Type::getInt8PtrTy(M->getContext())), name);
libgv.first = libptrgv;
}
else {
Expand Down Expand Up @@ -122,7 +122,7 @@ static Value *runtime_sym_lookup(
}
else {
// f_lib is actually one of the special sentinel values
libname = ConstantExpr::getIntToPtr(ConstantInt::get(T_size, (uintptr_t)f_lib), T_pint8);
libname = ConstantExpr::getIntToPtr(ConstantInt::get(T_size, (uintptr_t)f_lib), llvm::Type::getInt8PtrTy(irbuilder.getContext()));
}
llvmf = irbuilder.CreateCall(prepare_call_in(jl_builderModule(irbuilder), jldlsym_func),
{ libname, nameval, libptrgv });
Expand Down Expand Up @@ -654,10 +654,10 @@ static jl_cgval_t emit_cglobal(jl_codectx_t &ctx, jl_value_t **args, size_t narg
}
else {
if (sym.lib_expr) {
res = runtime_sym_lookup(ctx, cast<PointerType>(T_pint8), NULL, sym.lib_expr, sym.f_name, ctx.f);
res = runtime_sym_lookup(ctx, cast<PointerType>(llvm::Type::getInt8PtrTy(ctx.builder.getContext())), NULL, sym.lib_expr, sym.f_name, ctx.f);
}
else if (imaging_mode) {
res = runtime_sym_lookup(ctx, cast<PointerType>(T_pint8), sym.f_lib, NULL, sym.f_name, ctx.f);
res = runtime_sym_lookup(ctx, cast<PointerType>(llvm::Type::getInt8PtrTy(ctx.builder.getContext())), sym.f_lib, NULL, sym.f_name, ctx.f);
res = ctx.builder.CreatePtrToInt(res, lrt);
}
else {
Expand All @@ -667,7 +667,7 @@ static jl_cgval_t emit_cglobal(jl_codectx_t &ctx, jl_value_t **args, size_t narg
if (!libsym || !jl_dlsym(libsym, sym.f_name, &symaddr, 0)) {
// Error mode, either the library or the symbol couldn't be find during compiletime.
// Fallback to a runtime symbol lookup.
res = runtime_sym_lookup(ctx, cast<PointerType>(T_pint8), sym.f_lib, NULL, sym.f_name, ctx.f);
res = runtime_sym_lookup(ctx, cast<PointerType>(llvm::Type::getInt8PtrTy(ctx.builder.getContext())), sym.f_lib, NULL, sym.f_name, ctx.f);
res = ctx.builder.CreatePtrToInt(res, lrt);
} else {
// since we aren't saving this code, there's no sense in
Expand Down Expand Up @@ -1051,7 +1051,7 @@ std::string generate_func_sig(const char *fname)
bool isboxed;
if (jl_is_abstract_ref_type(tti)) {
tti = (jl_value_t*)jl_voidpointer_type;
t = T_pint8;
t = llvm::Type::getInt8PtrTy(lrt->getContext());
isboxed = false;
}
else if (llvmcall && jl_is_llvmpointer_type(tti)) {
Expand Down Expand Up @@ -1480,7 +1480,7 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
assert(lrt == llvm::Type::getInt16Ty(ctx.builder.getContext()));
assert(!isVa && !llvmcall && nccallargs == 0);
JL_GC_POP();
Value *ptask_i16 = emit_bitcast(ctx, get_current_task(ctx), T_pint16);
Value *ptask_i16 = emit_bitcast(ctx, get_current_task(ctx), llvm::Type::getInt16PtrTy(ctx.builder.getContext()));
const int tid_offset = offsetof(jl_task_t, tid);
Value *ptid = ctx.builder.CreateInBoundsGEP(llvm::Type::getInt16Ty(ctx.builder.getContext()), ptask_i16, ConstantInt::get(T_size, tid_offset / sizeof(int16_t)));
LoadInst *tid = ctx.builder.CreateAlignedLoad(llvm::Type::getInt16Ty(ctx.builder.getContext()), ptid, Align(sizeof(int16_t)));
Expand All @@ -1493,7 +1493,7 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
#endif
) {
JL_GC_POP();
Value *ptls_i32 = emit_bitcast(ctx, get_current_ptls(ctx), T_pint32);
Value *ptls_i32 = emit_bitcast(ctx, get_current_ptls(ctx), llvm::Type::getInt32PtrTy(ctx.builder.getContext()));
const int finh_offset = offsetof(jl_tls_states_t, finalizers_inhibited);
Value *pfinh = ctx.builder.CreateInBoundsGEP(llvm::Type::getInt32Ty(ctx.builder.getContext()), ptls_i32, ConstantInt::get(T_size, finh_offset / 4));
LoadInst *finh = ctx.builder.CreateAlignedLoad(llvm::Type::getInt32Ty(ctx.builder.getContext()), pfinh, Align(sizeof(int32_t)));
Expand Down Expand Up @@ -1702,11 +1702,11 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
Value *destp = emit_unbox(ctx, T_size, dst, (jl_value_t*)jl_voidpointer_type);

ctx.builder.CreateMemCpy(
emit_inttoptr(ctx, destp, T_pint8),
emit_inttoptr(ctx, destp, llvm::Type::getInt8PtrTy(ctx.builder.getContext())),
MaybeAlign(1),
emit_inttoptr(ctx,
emit_unbox(ctx, T_size, src, (jl_value_t*)jl_voidpointer_type),
T_pint8),
llvm::Type::getInt8PtrTy(ctx.builder.getContext())),
MaybeAlign(0),
emit_unbox(ctx, T_size, n, (jl_value_t*)jl_ulong_type),
false);
Expand All @@ -1722,7 +1722,7 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
Value *val32 = emit_unbox(ctx, llvm::Type::getInt32Ty(ctx.builder.getContext()), val, (jl_value_t*)jl_uint32_type);
Value *val8 = ctx.builder.CreateTrunc(val32, llvm::Type::getInt8Ty(ctx.builder.getContext()), "memset_val");
ctx.builder.CreateMemSet(
emit_inttoptr(ctx, destp, T_pint8),
emit_inttoptr(ctx, destp, llvm::Type::getInt8PtrTy(ctx.builder.getContext())),
val8,
emit_unbox(ctx, T_size, n, (jl_value_t*)jl_ulong_type),
MaybeAlign(1)
Expand All @@ -1738,11 +1738,11 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)
Value *destp = emit_unbox(ctx, T_size, dst, (jl_value_t*)jl_voidpointer_type);

ctx.builder.CreateMemMove(
emit_inttoptr(ctx, destp, T_pint8),
emit_inttoptr(ctx, destp, llvm::Type::getInt8PtrTy(ctx.builder.getContext())),
MaybeAlign(0),
emit_inttoptr(ctx,
emit_unbox(ctx, T_size, src, (jl_value_t*)jl_voidpointer_type),
T_pint8),
llvm::Type::getInt8PtrTy(ctx.builder.getContext())),
MaybeAlign(0),
emit_unbox(ctx, T_size, n, (jl_value_t*)jl_ulong_type),
false);
Expand Down
32 changes: 16 additions & 16 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,7 @@ static Value *emit_datatype_nfields(jl_codectx_t &ctx, Value *dt)

static Value *emit_datatype_size(jl_codectx_t &ctx, Value *dt)
{
Value *Ptr = emit_bitcast(ctx, decay_derived(ctx, dt), T_pint32);
Value *Ptr = emit_bitcast(ctx, decay_derived(ctx, dt), llvm::Type::getInt32PtrTy(ctx.builder.getContext()));
Value *Idx = ConstantInt::get(T_size, offsetof(jl_datatype_t, size) / sizeof(int));
return tbaa_decorate(tbaa_const, ctx.builder.CreateAlignedLoad(llvm::Type::getInt32Ty(ctx.builder.getContext()), ctx.builder.CreateInBoundsGEP(llvm::Type::getInt32Ty(ctx.builder.getContext()), Ptr, Idx), Align(sizeof(int32_t))));
}
Expand Down Expand Up @@ -971,7 +971,7 @@ static Value *emit_datatype_mutabl(jl_codectx_t &ctx, Value *dt)
Value *Ptr = emit_bitcast(ctx, decay_derived(ctx, dt), T_ppint8);
Value *Idx = ConstantInt::get(T_size, offsetof(jl_datatype_t, name));
Value *Nam = tbaa_decorate(tbaa_const,
ctx.builder.CreateAlignedLoad(T_pint8, ctx.builder.CreateInBoundsGEP(T_pint8, Ptr, Idx), Align(sizeof(int8_t*))));
ctx.builder.CreateAlignedLoad(llvm::Type::getInt8PtrTy(ctx.builder.getContext()), ctx.builder.CreateInBoundsGEP(llvm::Type::getInt8PtrTy(ctx.builder.getContext()), Ptr, Idx), Align(sizeof(int8_t*))));
Value *Idx2 = ConstantInt::get(T_size, offsetof(jl_typename_t, n_uninitialized) + sizeof(((jl_typename_t*)nullptr)->n_uninitialized));
Value *mutabl = tbaa_decorate(tbaa_const,
ctx.builder.CreateAlignedLoad(llvm::Type::getInt8Ty(ctx.builder.getContext()), ctx.builder.CreateInBoundsGEP(llvm::Type::getInt8Ty(ctx.builder.getContext()), Nam, Idx2), Align(1)));
Expand Down Expand Up @@ -1332,7 +1332,7 @@ static void emit_typecheck(jl_codectx_t &ctx, const jl_cgval_t &x, jl_value_t *t
static Value *emit_isconcrete(jl_codectx_t &ctx, Value *typ)
{
Value *isconcrete;
isconcrete = ctx.builder.CreateConstInBoundsGEP1_32(llvm::Type::getInt8Ty(ctx.builder.getContext()), emit_bitcast(ctx, decay_derived(ctx, typ), T_pint8), offsetof(jl_datatype_t, hash) + sizeof(((jl_datatype_t*)nullptr)->hash));
isconcrete = ctx.builder.CreateConstInBoundsGEP1_32(llvm::Type::getInt8Ty(ctx.builder.getContext()), emit_bitcast(ctx, decay_derived(ctx, typ), llvm::Type::getInt8PtrTy(ctx.builder.getContext())), offsetof(jl_datatype_t, hash) + sizeof(((jl_datatype_t*)nullptr)->hash));
isconcrete = tbaa_decorate(tbaa_const, ctx.builder.CreateAlignedLoad(llvm::Type::getInt8Ty(ctx.builder.getContext()), isconcrete, Align(1)));
isconcrete = ctx.builder.CreateLShr(isconcrete, 1);
isconcrete = ctx.builder.CreateTrunc(isconcrete, llvm::Type::getInt1Ty(ctx.builder.getContext()));
Expand Down Expand Up @@ -1380,7 +1380,7 @@ static Value *emit_bounds_check(jl_codectx_t &ctx, const jl_cgval_t &ainfo, jl_v
else { // unboxed jl_value_t*
Value *a = ainfo.V;
if (ainfo.isghost) {
a = Constant::getNullValue(T_pint8);
a = Constant::getNullValue(llvm::Type::getInt8PtrTy(ctx.builder.getContext()));
}
else if (!ainfo.ispointer()) {
// CreateAlloca is OK here since we are on an error branch
Expand All @@ -1389,7 +1389,7 @@ static Value *emit_bounds_check(jl_codectx_t &ctx, const jl_cgval_t &ainfo, jl_v
a = tempSpace;
}
ctx.builder.CreateCall(prepare_call(jluboundserror_func), {
emit_bitcast(ctx, decay_derived(ctx, a), T_pint8),
emit_bitcast(ctx, decay_derived(ctx, a), llvm::Type::getInt8PtrTy(ctx.builder.getContext())),
literal_pointer_val(ctx, ty),
i });
}
Expand Down Expand Up @@ -2213,7 +2213,7 @@ static jl_cgval_t emit_getfield_knownidx(jl_codectx_t &ctx, const jl_cgval_t &st
if (byte_offset > 0) {
addr = ctx.builder.CreateInBoundsGEP(
llvm::Type::getInt8Ty(ctx.builder.getContext()),
emit_bitcast(ctx, staddr, T_pint8),
emit_bitcast(ctx, staddr, llvm::Type::getInt8PtrTy(ctx.builder.getContext())),
ConstantInt::get(T_size, byte_offset));
}
else {
Expand Down Expand Up @@ -2246,7 +2246,7 @@ static jl_cgval_t emit_getfield_knownidx(jl_codectx_t &ctx, const jl_cgval_t &st
Value *ptindex;
if (isboxed) {
ptindex = ctx.builder.CreateConstInBoundsGEP1_32(
llvm::Type::getInt8Ty(ctx.builder.getContext()), emit_bitcast(ctx, staddr, T_pint8), byte_offset + fsz);
llvm::Type::getInt8Ty(ctx.builder.getContext()), emit_bitcast(ctx, staddr, llvm::Type::getInt8PtrTy(ctx.builder.getContext())), byte_offset + fsz);
}
else {
ptindex = emit_struct_gep(ctx, cast<StructType>(lt), staddr, byte_offset + fsz);
Expand Down Expand Up @@ -2304,7 +2304,7 @@ static jl_cgval_t emit_getfield_knownidx(jl_codectx_t &ctx, const jl_cgval_t &st
// emit remaining bytes up to tindex
if (i < ptindex - st_idx) {
Value *staddr = ctx.builder.CreateConstInBoundsGEP1_32(ET, lv, i);
staddr = ctx.builder.CreateBitCast(staddr, T_pint8);
staddr = ctx.builder.CreateBitCast(staddr, llvm::Type::getInt8PtrTy(ctx.builder.getContext()));
for (; i < ptindex - st_idx; i++) {
Value *fldv = ctx.builder.CreateExtractValue(obj, makeArrayRef(st_idx + i));
Value *fldp = ctx.builder.CreateConstInBoundsGEP1_32(llvm::Type::getInt8Ty(ctx.builder.getContext()), staddr, i);
Expand Down Expand Up @@ -3117,9 +3117,9 @@ static void emit_unionmove(jl_codectx_t &ctx, Value *dest, MDNode *tbaa_dst, con
if (skip)
tindex = ctx.builder.CreateSelect(skip, ConstantInt::get(llvm::Type::getInt8Ty(ctx.builder.getContext()), 0), tindex);
Value *src_ptr = data_pointer(ctx, src);
src_ptr = src_ptr ? maybe_bitcast(ctx, src_ptr, T_pint8) : src_ptr;
dest = maybe_bitcast(ctx, dest, T_pint8);
BasicBlock *defaultBB = BasicBlock::Create(jl_LLVMContext, "union_move_skip", ctx.f);
src_ptr = src_ptr ? maybe_bitcast(ctx, src_ptr, llvm::Type::getInt8PtrTy(ctx.builder.getContext())) : src_ptr;
dest = maybe_bitcast(ctx, dest, llvm::Type::getInt8PtrTy(ctx.builder.getContext()));
BasicBlock *defaultBB = BasicBlock::Create(ctx.builder.getContext(), "union_move_skip", ctx.f);
SwitchInst *switchInst = ctx.builder.CreateSwitch(tindex, defaultBB);
BasicBlock *postBB = BasicBlock::Create(jl_LLVMContext, "post_union_move", ctx.f);
unsigned counter = 0;
Expand Down Expand Up @@ -3204,7 +3204,7 @@ static Value *emit_allocobj(jl_codectx_t &ctx, size_t static_size, Value *jt)
// allocation for unknown object from an untracked pointer
static Value *emit_new_bits(jl_codectx_t &ctx, Value *jt, Value *pval)
{
pval = ctx.builder.CreateBitCast(pval, T_pint8);
pval = ctx.builder.CreateBitCast(pval, llvm::Type::getInt8PtrTy(ctx.builder.getContext()));
Function *F = prepare_call(jl_newbits_func);
auto call = ctx.builder.CreateCall(F, { jt, pval });
call->setAttributes(F->getAttributes());
Expand Down Expand Up @@ -3276,7 +3276,7 @@ static jl_cgval_t emit_setfield(jl_codectx_t &ctx,
if (byte_offset > 0) {
addr = ctx.builder.CreateInBoundsGEP(
llvm::Type::getInt8Ty(ctx.builder.getContext()),
emit_bitcast(ctx, maybe_decay_tracked(ctx, addr), T_pint8),
emit_bitcast(ctx, maybe_decay_tracked(ctx, addr), llvm::Type::getInt8PtrTy(ctx.builder.getContext())),
ConstantInt::get(T_size, byte_offset)); // TODO: use emit_struct_gep
}
jl_value_t *jfty = jl_field_type(sty, idx0);
Expand All @@ -3289,7 +3289,7 @@ static jl_cgval_t emit_setfield(jl_codectx_t &ctx,
jl_cgval_t rhs_union = convert_julia_type(ctx, rhs, jfty);
if (rhs_union.typ == jl_bottom_type)
return jl_cgval_t();
Value *ptindex = ctx.builder.CreateInBoundsGEP(llvm::Type::getInt8Ty(ctx.builder.getContext()), emit_bitcast(ctx, maybe_decay_tracked(ctx, addr), T_pint8), ConstantInt::get(T_size, fsz));
Value *ptindex = ctx.builder.CreateInBoundsGEP(llvm::Type::getInt8Ty(ctx.builder.getContext()), emit_bitcast(ctx, maybe_decay_tracked(ctx, addr), llvm::Type::getInt8PtrTy(ctx.builder.getContext())), ConstantInt::get(T_size, fsz));
if (needlock)
emit_lockstate_value(ctx, strct, true);
BasicBlock *ModifyBB;
Expand Down Expand Up @@ -3467,7 +3467,7 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
// emit remaining bytes up to tindex
if (i < ptindex - llvm_idx) {
Value *staddr = ctx.builder.CreateConstInBoundsGEP1_32(ET, lv, i);
staddr = ctx.builder.CreateBitCast(staddr, T_pint8);
staddr = ctx.builder.CreateBitCast(staddr, llvm::Type::getInt8PtrTy(ctx.builder.getContext()));
for (; i < ptindex - llvm_idx; i++) {
Value *fldp = ctx.builder.CreateConstInBoundsGEP1_32(llvm::Type::getInt8Ty(ctx.builder.getContext()), staddr, i);
Value *fldv = tbaa_decorate(tbaa_stack, ctx.builder.CreateAlignedLoad(llvm::Type::getInt8Ty(ctx.builder.getContext()), fldp, Align(1)));
Expand Down Expand Up @@ -3532,7 +3532,7 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
if (!jl_field_isptr(sty, i) && jl_is_uniontype(jl_field_type(sty, i))) {
tbaa_decorate(tbaa_unionselbyte, ctx.builder.CreateAlignedStore(
ConstantInt::get(llvm::Type::getInt8Ty(ctx.builder.getContext()), 0),
ctx.builder.CreateInBoundsGEP(llvm::Type::getInt8Ty(ctx.builder.getContext()), emit_bitcast(ctx, strct, T_pint8),
ctx.builder.CreateInBoundsGEP(llvm::Type::getInt8Ty(ctx.builder.getContext()), emit_bitcast(ctx, strct, llvm::Type::getInt8PtrTy(ctx.builder.getContext())),
ConstantInt::get(T_size, jl_field_offset(sty, i) + jl_field_size(sty, i) - 1)),
Align(1)));
}
Expand Down
Loading

0 comments on commit 132aee6

Please sign in to comment.