Skip to content

Commit

Permalink
wip [ci-skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Feb 13, 2015
1 parent 56a57f7 commit 58d3033
Show file tree
Hide file tree
Showing 18 changed files with 409 additions and 396 deletions.
70 changes: 33 additions & 37 deletions src/alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,7 @@ static jl_value_t *jl_new_bits_internal(jl_value_t *dt, void *data, size_t *len)
if (bt == jl_int32_type) return jl_box_int32(*(int32_t*)data);
if (bt == jl_float64_type) return jl_box_float64(*(double*)data);

jl_value_t *v =
(jl_value_t*)allocobj((NWORDS(LLT_ALIGN(nb,sizeof(void*)))+1)*
sizeof(void*));
v->type = (jl_value_t*)bt;
jl_value_t *v = (jl_value_t*)newobj((jl_value_t*)bt, NWORDS(nb));
switch (nb) {
case 1: *(int8_t*) jl_data_ptr(v) = *(int8_t*)data; break;
case 2: *(int16_t*) jl_data_ptr(v) = *(int16_t*)data; break;
Expand Down Expand Up @@ -252,7 +249,7 @@ jl_value_t *jl_get_nth_field(jl_value_t *v, size_t i)
{
jl_datatype_t *st = (jl_datatype_t*)jl_typeof(v);
assert(i < jl_tuple_len(st->names));
size_t offs = jl_field_offset(st,i) + sizeof(void*);
size_t offs = jl_field_offset(st,i);
if (st->fields[i].isptr) {
return *(jl_value_t**)((char*)v + offs);
}
Expand All @@ -264,7 +261,7 @@ jl_value_t *jl_get_nth_field_checked(jl_value_t *v, size_t i)
jl_datatype_t *st = (jl_datatype_t*)jl_typeof(v);
if (i >= jl_tuple_len(st->names))
jl_bounds_error_int(v, i+1);
size_t offs = jl_field_offset(st,i) + sizeof(void*);
size_t offs = jl_field_offset(st,i);
if (st->fields[i].isptr) {
jl_value_t *fval = *(jl_value_t**)((char*)v + offs);
if (fval == NULL)
Expand All @@ -277,7 +274,7 @@ jl_value_t *jl_get_nth_field_checked(jl_value_t *v, size_t i)
void jl_set_nth_field(jl_value_t *v, size_t i, jl_value_t *rhs)
{
jl_datatype_t *st = (jl_datatype_t*)jl_typeof(v);
size_t offs = jl_field_offset(st,i) + sizeof(void*);
size_t offs = jl_field_offset(st,i);
if (st->fields[i].isptr) {
*(jl_value_t**)((char*)v + offs) = rhs;
if(rhs != NULL) gc_wb(v, rhs);
Expand All @@ -290,7 +287,7 @@ void jl_set_nth_field(jl_value_t *v, size_t i, jl_value_t *rhs)
int jl_field_isdefined(jl_value_t *v, size_t i)
{
jl_datatype_t *st = (jl_datatype_t*)jl_typeof(v);
size_t offs = jl_field_offset(st,i) + sizeof(void*);
size_t offs = jl_field_offset(st,i);
if (st->fields[i].isptr) {
return *(jl_value_t**)((char*)v + offs) != NULL;
}
Expand Down Expand Up @@ -321,7 +318,7 @@ DLLEXPORT jl_value_t *jl_new_structv(jl_datatype_t *type, jl_value_t **args, uin
}
for(size_t i=na; i < nf; i++) {
if (type->fields[i].isptr)
*(jl_value_t**)((char*)jv+jl_field_offset(type,i)+sizeof(void*)) = NULL;
*(jl_value_t**)((char*)jl_data_ptr(jv)+jl_field_offset(type,i)) = NULL;
}
return jv;
}
Expand All @@ -331,7 +328,7 @@ DLLEXPORT jl_value_t *jl_new_struct_uninit(jl_datatype_t *type)
if (type->instance != NULL) return type->instance;
jl_value_t *jv = newstruct(type);
if (type->size > 0)
memset(&((void**)jv)[1], 0, type->size);
memset(jl_data_ptr(jv), 0, type->size);
return jv;
}

Expand Down Expand Up @@ -360,11 +357,11 @@ DLLEXPORT jl_tuple_t *jl_tuplev(size_t n, jl_value_t **v)
jl_tuple_t *jl_tuple1(void *a)
{
#ifdef OVERLAP_TUPLE_LEN
jl_tuple_t *t = (jl_tuple_t*)alloc_2w();
jl_tuple_t *t = (jl_tuple_t*)alloc_1w();
#else
jl_tuple_t *t = (jl_tuple_t*)alloc_3w();
jl_tuple_t *t = (jl_tuple_t*)alloc_2w();
#endif
t->type = (jl_value_t*)jl_tuple_type;
jl_set_typeof(t, jl_tuple_type);
jl_tuple_set_len_unsafe(t, 1);
jl_tupleset(t, 0, a);
return t;
Expand All @@ -373,11 +370,11 @@ jl_tuple_t *jl_tuple1(void *a)
jl_tuple_t *jl_tuple2(void *a, void *b)
{
#ifdef OVERLAP_TUPLE_LEN
jl_tuple_t *t = (jl_tuple_t*)alloc_3w();
jl_tuple_t *t = (jl_tuple_t*)alloc_2w();
#else
jl_tuple_t *t = (jl_tuple_t*)alloc_4w();
jl_tuple_t *t = (jl_tuple_t*)alloc_3w();
#endif
t->type = (jl_value_t*)jl_tuple_type;
jl_set_typeof(t, jl_tuple_type);
jl_tuple_set_len_unsafe(t, 2);
jl_tupleset(t, 0, a);
jl_tupleset(t, 1, b);
Expand Down Expand Up @@ -434,8 +431,8 @@ jl_tuple_t *jl_tuple_fill(size_t n, jl_value_t *v)
DLLEXPORT jl_function_t *jl_new_closure(jl_fptr_t fptr, jl_value_t *env,
jl_lambda_info_t *linfo)
{
jl_function_t *f = (jl_function_t*)alloc_4w();
f->type = (jl_value_t*)jl_function_type;
jl_function_t *f = (jl_function_t*)alloc_3w(); assert(NWORDS(sizeof(jl_function_t))==3);
jl_set_typeof(f, jl_function_type);
f->fptr = (fptr!=NULL ? fptr : linfo->fptr);
f->env = env;
f->linfo = linfo;
Expand All @@ -447,7 +444,7 @@ jl_lambda_info_t *jl_new_lambda_info(jl_value_t *ast, jl_tuple_t *sparams)
{
jl_lambda_info_t *li =
(jl_lambda_info_t*)newobj((jl_value_t*)jl_lambda_info_type,
LAMBDA_INFO_NW);
NWORDS(sizeof(jl_lambda_info_t)));
li->ast = ast;
li->file = null_sym;
li->line = 0;
Expand Down Expand Up @@ -499,23 +496,23 @@ static jl_sym_t *mk_symbol(const char *str)
#endif
jl_sym_t *sym;
size_t len = strlen(str);
size_t nb = (sizeof(jl_sym_t)+len+1+7)&-8;
size_t nb = (sizeof(jl_typetag_t*)+sizeof(jl_sym_t)+len+1+7)&-8;

if (nb >= SYM_POOL_SIZE) {
jl_exceptionf(jl_argumenterror_type, "Symbol length exceeds maximum length");
}

#ifdef MEMDEBUG
sym = (jl_sym_t*)malloc(nb);
sym = (jl_sym_t*)((jl_typetag_t*)malloc(nb))->value;
#else
if (sym_pool == NULL || pool_ptr+nb > sym_pool+SYM_POOL_SIZE) {
sym_pool = (char*)malloc(SYM_POOL_SIZE);
pool_ptr = sym_pool;
}
sym = (jl_sym_t*)pool_ptr;
sym = (jl_sym_t*)((jl_typetag_t*)malloc(nb))->value;
pool_ptr += nb;
#endif
sym->type = (jl_value_t*)jl_sym_type;
jl_set_typeof(sym, jl_sym_type);
sym->left = sym->right = NULL;
sym->hash = hash_symbol(str, len);
strcpy(&sym->name[0], str);
Expand All @@ -525,7 +522,7 @@ static jl_sym_t *mk_symbol(const char *str)
static void unmark_symbols_(jl_sym_t *root)
{
while (root != NULL) {
root->type = (jl_value_t*)(((uptrint_t)root->type)&~3UL);
jl_set_typeof(root, jl_sym_type);
unmark_symbols_(root->left);
root = root->right;
}
Expand Down Expand Up @@ -619,7 +616,7 @@ DLLEXPORT jl_sym_t *jl_tagged_gensym(const char *str, int32_t len)

jl_typename_t *jl_new_typename(jl_sym_t *name)
{
jl_typename_t *tn=(jl_typename_t*)newobj((jl_value_t*)jl_typename_type, 6);
jl_typename_t *tn=(jl_typename_t*)newobj((jl_value_t*)jl_typename_type, NWORDS(sizeof(jl_typename_t)));
tn->name = name;
tn->module = jl_current_module;
tn->primary = NULL;
Expand All @@ -641,8 +638,7 @@ jl_datatype_t *jl_new_uninitialized_datatype(size_t nfields)
{
return (jl_datatype_t*)
newobj((jl_value_t*)jl_datatype_type,
NWORDS(sizeof(jl_datatype_t) - sizeof(void*) +
nfields*sizeof(jl_fielddesc_t)));
NWORDS(sizeof(jl_datatype_t) + nfields*sizeof(jl_fielddesc_t)));
}

void jl_compute_field_offsets(jl_datatype_t *st)
Expand Down Expand Up @@ -766,7 +762,7 @@ jl_datatype_t *jl_new_bitstype(jl_value_t *name, jl_datatype_t *super,

jl_uniontype_t *jl_new_uniontype(jl_tuple_t *types)
{
jl_uniontype_t *t = (jl_uniontype_t*)newobj((jl_value_t*)jl_uniontype_type,1);
jl_uniontype_t *t = (jl_uniontype_t*)newobj((jl_value_t*)jl_uniontype_type,NWORDS(sizeof(jl_uniontype_t)));
// don't make unions of 1 type; Union(T)==T
assert(jl_tuple_len(types) != 1);
t->types = types;
Expand All @@ -777,7 +773,7 @@ jl_uniontype_t *jl_new_uniontype(jl_tuple_t *types)

jl_typector_t *jl_new_type_ctor(jl_tuple_t *params, jl_value_t *body)
{
jl_typector_t *tc = (jl_typector_t*)newobj((jl_value_t*)jl_typector_type,2);
jl_typector_t *tc = (jl_typector_t*)newobj((jl_value_t*)jl_typector_type,NWORDS(sizeof(jl_typector_t)));
tc->parameters = params;
tc->body = body;
return (jl_typector_t*)tc;
Expand All @@ -791,7 +787,7 @@ jl_value_t *jl_box##nb(jl_datatype_t *t, int##nb##_t x) \
assert(jl_isbits(t)); \
assert(jl_datatype_size(t) == sizeof(x)); \
jl_value_t *v = (jl_value_t*)alloc_##nw##w(); \
v->type = (jl_value_t*)t; \
jl_set_typeof(v, t); \
*(int##nb##_t*)jl_data_ptr(v) = x; \
return v; \
}
Expand Down Expand Up @@ -829,7 +825,7 @@ UNBOX_FUNC(gensym, ssize_t)
jl_value_t *pfx##_##typ(c_type x) \
{ \
jl_value_t *v = (jl_value_t*)alloc_##nw##w(); \
v->type = (jl_value_t*)jl_##typ##_type; \
jl_set_typeof(v, jl_##typ##_type); \
*(c_type*)jl_data_ptr(v) = x; \
return v; \
}
Expand All @@ -851,7 +847,7 @@ jl_value_t *jl_box_##typ(c_type x) \
if ((u##c_type)idx < (u##c_type)NBOX_C) \
return boxed_##typ##_cache[idx]; \
jl_value_t *v = (jl_value_t*)alloc_##nw##w(); \
v->type = (jl_value_t*)jl_##typ##_type; \
jl_set_typeof(v, jl_##typ##_type); \
*(c_type*)jl_data_ptr(v) = x; \
return v; \
}
Expand All @@ -862,7 +858,7 @@ jl_value_t *jl_box_##typ(c_type x) \
if (x < NBOX_C) \
return boxed_##typ##_cache[x]; \
jl_value_t *v = (jl_value_t*)alloc_##nw##w(); \
v->type = (jl_value_t*)jl_##typ##_type; \
jl_set_typeof(v, jl_##typ##_type); \
*(c_type*)jl_data_ptr(v) = x; \
return v; \
}
Expand Down Expand Up @@ -955,8 +951,8 @@ jl_expr_t *jl_exprn(jl_sym_t *head, size_t n)
{
jl_array_t *ar = n==0 ? (jl_array_t*)jl_an_empty_cell : jl_alloc_cell_1d(n);
JL_GC_PUSH1(&ar);
jl_expr_t *ex = (jl_expr_t*)alloc_4w();
ex->type = (jl_value_t*)jl_expr_type;
jl_expr_t *ex = (jl_expr_t*)alloc_3w(); assert(NWORDS(sizeof(jl_expr_t))==3);
jl_set_typeof(ex, jl_expr_type);
ex->head = head;
ex->args = ar;
ex->etype = (jl_value_t*)jl_any_type;
Expand All @@ -972,8 +968,8 @@ JL_CALLABLE(jl_f_new_expr)
JL_GC_PUSH1(&ar);
for(size_t i=0; i < nargs-1; i++)
jl_cellset(ar, i, args[i+1]);
jl_expr_t *ex = (jl_expr_t*)alloc_4w();
ex->type = (jl_value_t*)jl_expr_type;
jl_expr_t *ex = (jl_expr_t*)alloc_3w(); assert(NWORDS(sizeof(jl_expr_t))==3);
jl_set_typeof(ex, jl_expr_type);
ex->head = (jl_sym_t*)args[0];
ex->args = ar;
ex->etype = (jl_value_t*)jl_any_type;
Expand Down
14 changes: 7 additions & 7 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static jl_array_t *_new_array_(jl_value_t *atype, uint32_t ndims, size_t *dims,
tsz += tot;
tsz = (tsz+15)&-16; // align whole object 16
a = (jl_array_t*)allocobj(tsz);
a->type = atype;
jl_set_typeof(a, atype);
a->how = 0;
data = (char*)a + doffs;
if (tot > 0 && !isunboxed) {
Expand All @@ -89,7 +89,7 @@ static jl_array_t *_new_array_(jl_value_t *atype, uint32_t ndims, size_t *dims,
tsz = (tsz+15)&-16; // align whole object size 16
a = (jl_array_t*)allocobj(tsz);
JL_GC_PUSH1(&a);
a->type = atype;
jl_set_typeof(a, atype);
// temporarily initialize to make gc-safe
a->data = NULL;
a->how = 2;
Expand Down Expand Up @@ -150,7 +150,7 @@ jl_array_t *jl_reshape_array(jl_value_t *atype, jl_array_t *data, jl_tuple_t *di
int ndimwords = jl_array_ndimwords(ndims);
int tsz = (sizeof(jl_array_t) + sizeof(void*) + ndimwords*sizeof(size_t) + 15)&-16;
a = (jl_array_t*)allocobj(tsz);
a->type = atype;
jl_set_typeof(a, atype);
a->pooled = tsz <= 2048;
a->ndims = ndims;
a->offset = 0;
Expand Down Expand Up @@ -216,8 +216,8 @@ jl_array_t *jl_ptr_to_array_1d(jl_value_t *atype, void *data, size_t nel,
elsz = sizeof(void*);
int tsz = (sizeof(jl_array_t)+jl_array_ndimwords(1)*sizeof(size_t)+15)&-16;
a = (jl_array_t*)allocobj(tsz);
jl_set_typeof(a, atype);
a->pooled = tsz <= 2048;
a->type = atype;
a->data = data;
#ifdef STORE_ARRAY_LEN
a->length = nel;
Expand Down Expand Up @@ -267,8 +267,8 @@ jl_array_t *jl_ptr_to_array(jl_value_t *atype, void *data, jl_tuple_t *dims,
int ndimwords = jl_array_ndimwords(ndims);
int tsz = (sizeof(jl_array_t) + ndimwords*sizeof(size_t)+15)&-16;
a = (jl_array_t*)allocobj(tsz);
jl_set_typeof(a, atype);
a->pooled = tsz <= 2048;
a->type = atype;
a->data = data;
#ifdef STORE_ARRAY_LEN
a->length = nel;
Expand Down Expand Up @@ -340,8 +340,8 @@ jl_value_t *jl_array_to_string(jl_array_t *a)
// TODO: check type of array?
jl_datatype_t *string_type = u8_isvalid((char*)a->data, jl_array_len(a)) == 1 ? // ASCII
jl_ascii_string_type : jl_utf8_string_type;
jl_value_t *s = (jl_value_t*)alloc_2w();
s->type = (jl_value_t*)string_type;
jl_value_t *s = (jl_value_t*)alloc_1w();
jl_set_typeof(s, string_type);
jl_set_nth_field(s, 0, (jl_value_t*)a);
return s;
}
Expand Down
4 changes: 2 additions & 2 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -1222,8 +1222,8 @@ size_t jl_static_show_x(JL_STREAM *out, jl_value_t *v, int depth)
else if (jl_typeof(v) == NULL) {
n += JL_PRINTF(out, "<?::#null>");
}
else if ((uptrint_t)v->type < 4096U) {
n += JL_PRINTF(out, "<?::#%d>", (int)(uptrint_t)v->type);
else if ((uptrint_t)jl_typetagof(v)->type < 4096U) {
n += JL_PRINTF(out, "<?::#%d>", (int)(uptrint_t)jl_typetagof(v)->type);
}
else if (jl_is_lambda_info(v)) {
jl_lambda_info_t *li = (jl_lambda_info_t*)v;
Expand Down
18 changes: 9 additions & 9 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ static Value *julia_to_native(Type *ty, jl_value_t *jt, Value *jv,
}
if (jl_is_mutable_datatype(ety)) {
// no copy, just reference the data field
return builder.CreateBitCast(emit_nthptr_addr(jv, (size_t)1), ty); // skip type tag field
return builder.CreateBitCast(jv, ty);
}
else if (jl_is_immutable_datatype(ety) && jt != (jl_value_t*)jl_voidpointer_type) {
// yes copy
Expand All @@ -336,12 +336,12 @@ static Value *julia_to_native(Type *ty, jl_value_t *jt, Value *jv,
else
nbytes = tbaa_decorate(tbaa_datatype, builder.CreateLoad(
builder.CreateGEP(builder.CreatePointerCast(emit_typeof(jv), T_pint32),
ConstantInt::get(T_size, offsetof(jl_datatype_t,size)/4)),
ConstantInt::get(T_size, offsetof(jl_datatype_t,size)/sizeof(int32_t))),
false));
*needStackRestore = true;
AllocaInst *ai = builder.CreateAlloca(T_int8, nbytes);
ai->setAlignment(16);
builder.CreateMemCpy(ai, builder.CreateBitCast(emit_nthptr_addr(jv, (size_t)1), T_pint8), nbytes, 1);
builder.CreateMemCpy(ai, builder.CreateBitCast(jv, T_pint8), nbytes, 1);
return builder.CreateBitCast(ai, ty);
}
// emit maybe copy
Expand All @@ -358,16 +358,16 @@ static Value *julia_to_native(Type *ty, jl_value_t *jt, Value *jv,
T_int1);
builder.CreateCondBr(ismutable, mutableBB, immutableBB);
builder.SetInsertPoint(mutableBB);
Value *p1 = builder.CreatePointerCast(emit_nthptr_addr(jv, (size_t)1), ty); // skip type tag field
Value *p1 = builder.CreatePointerCast(jv, ty);
builder.CreateBr(afterBB);
builder.SetInsertPoint(immutableBB);
Value *nbytes = tbaa_decorate(tbaa_datatype, builder.CreateLoad(
builder.CreateGEP(builder.CreatePointerCast(jvt, T_pint32),
ConstantInt::get(T_size, offsetof(jl_datatype_t,size)/4)),
ConstantInt::get(T_size, offsetof(jl_datatype_t,size)/sizeof(int32_t))),
false));
AllocaInst *ai = builder.CreateAlloca(T_int8, nbytes);
ai->setAlignment(16);
builder.CreateMemCpy(ai, builder.CreatePointerCast(emit_nthptr_addr(jv, (size_t)1), T_pint8), nbytes, 1);
builder.CreateMemCpy(ai, builder.CreatePointerCast(jv, T_pint8), nbytes, 1);
Value *p2 = builder.CreatePointerCast(ai, ty);
builder.CreateBr(afterBB);
builder.SetInsertPoint(afterBB);
Expand Down Expand Up @@ -1149,7 +1149,7 @@ static Value *emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
ary = emit_unbox(largty, emit_unboxed(argi, ctx), jl_tupleref(tt, 0));
}
JL_GC_POP();
return mark_or_box_ccall_result(builder.CreateBitCast(emit_nthptr_addr(ary, addressOf?1:0), lrt),
return mark_or_box_ccall_result(builder.CreateBitCast(ary, lrt),
args[2], rt, static_rt, ctx);
}
if (fptr == (void *) &jl_is_leaf_type ||
Expand Down Expand Up @@ -1226,7 +1226,7 @@ static Value *emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
result = mem;
argvals[0] = result;
} else {
argvals[0] = builder.CreateBitCast(emit_nthptr_addr(result, (size_t)1), fargt_sig[0]);
argvals[0] = builder.CreateBitCast(result, fargt_sig[0]);
}
}

Expand Down Expand Up @@ -1424,7 +1424,7 @@ static Value *emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
Value *newsym = emit_newsym(rt,1,NULL,ctx);
assert(newsym != NULL && "Type was not concrete");
if (newsym->getType()->isPointerTy()) {
builder.CreateStore(result,builder.CreateBitCast(emit_nthptr_addr(newsym, (size_t)1), prt->getPointerTo()));
builder.CreateStore(result,builder.CreateBitCast(newsym, prt->getPointerTo()));
result = newsym;
} else if (lrt != prt) {
result = llvm_type_rewrite(result,lrt,rt,true);
Expand Down
Loading

1 comment on commit 58d3033

@tkelman
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's not how to spell [ci skip] btw, no dash

Please sign in to comment.