Skip to content

Commit

Permalink
eliminate pointertoref Intrinsic and just use jl_value_ptr function r…
Browse files Browse the repository at this point in the history
…eversably
  • Loading branch information
vtjnash committed Mar 7, 2015
1 parent 51fc652 commit c6ee2f9
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 24 deletions.
3 changes: 1 addition & 2 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2119,8 +2119,7 @@ function is_pure_builtin(f)
f === Intrinsics.pointerset || # this one is never effect-free
f === Intrinsics.ccall || # this one is never effect-free
f === Intrinsics.llvmcall || # this one is never effect-free
f === Intrinsics.jl_alloca || # this one is volatile, TODO: possibly also effect-free?
f === Intrinsics.pointertoref) # this one is volatile
f === Intrinsics.jl_alloca)
return true
end
end
Expand Down
2 changes: 1 addition & 1 deletion base/pointer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ unsafe_store!{T}(p::Ptr{T}, x, i::Integer) = pointerset(p, convert(T,x), Int(i))
unsafe_store!{T}(p::Ptr{T}, x) = pointerset(p, convert(T,x), 1)

# convert a raw Ptr to an object reference, and vice-versa
unsafe_pointer_to_objref(p::Ptr) = pointertoref(unbox(Ptr{Void},p))
unsafe_pointer_to_objref(x::Ptr) = ccall(:jl_value_ptr, Any, (Ptr{Void},), x)
pointer_from_objref(x::Any) = ccall(:jl_value_ptr, Ptr{Void}, (Any,), x)

integer(x::Ptr) = convert(UInt, x)
Expand Down
4 changes: 2 additions & 2 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -730,9 +730,9 @@ DLLEXPORT void *jl_array_ptr(jl_array_t *a)
{
return a->data;
}
DLLEXPORT void *jl_value_ptr(jl_value_t *a)
DLLEXPORT jl_value_t *jl_value_ptr(jl_value_t *a)
{
return (void*)a;
return a;
}

// printing -------------------------------------------------------------------
Expand Down
25 changes: 19 additions & 6 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1000,21 +1000,34 @@ static Value *emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
if (fptr == (void *) &jl_array_ptr ||
(f_lib==NULL && f_name && !strcmp(f_name,"jl_array_ptr"))) {
assert(lrt->isPointerTy());
Value *ary = emit_expr(args[4], ctx);
assert(!isVa);
assert(nargt==1);
jl_value_t *argi = args[4];
assert(!(jl_is_expr(argi) && ((jl_expr_t*)argi)->head == amp_sym));
Value *ary = emit_expr(argi, ctx);
JL_GC_POP();
return mark_or_box_ccall_result(builder.CreateBitCast(emit_arrayptr(ary),lrt),
args[2], rt, static_rt, ctx);
}
if (fptr == (void *) &jl_value_ptr ||
(f_lib==NULL && f_name && !strcmp(f_name,"jl_value_ptr"))) {
assert(lrt->isPointerTy());
assert(!isVa);
assert(nargt==1);
jl_value_t *argi = args[4];
bool addressOf = false;
if (jl_is_expr(argi) && ((jl_expr_t*)argi)->head == amp_sym) {
addressOf = true;
argi = jl_exprarg(argi,0);
}
Value *ary = boxed(emit_expr(argi, ctx),ctx);
Value *ary;
Type *largty = fargt[0];
if (largty == jl_pvalue_llvmt) {
ary = boxed(emit_expr(argi, ctx),ctx);
} else {
assert(!addressOf);
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),
args[2], rt, static_rt, ctx);
Expand Down Expand Up @@ -1067,7 +1080,7 @@ static Value *emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
bool needTempSpace = false;
bool needStackRestore = false;
for(i=4; i < nargs+1; i+=2) {
int ai = (i-4)/2;
size_t ai = (i-4)/2;
jl_value_t *argi = args[i];
bool addressOf = false;
if (jl_is_expr(argi) && ((jl_expr_t*)argi)->head == amp_sym) {
Expand All @@ -1076,9 +1089,9 @@ static Value *emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx)
}
Type *largty;
jl_value_t *jargty;
if (isVa && ai >= nargty-1) {
largty = fargt[nargty-1];
jargty = jl_tparam0(jl_tupleref(tt,nargty-1));
if (isVa && ai >= nargt-1) {
largty = fargt[nargt-1];
jargty = jl_tparam0(jl_tupleref(tt,nargt-1));
}
else {
largty = fargt[ai];
Expand Down
2 changes: 0 additions & 2 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -1822,7 +1822,6 @@ void jl_init_serializer(void)
jl_box_int32(45), jl_box_int32(46), jl_box_int32(47),
jl_box_int32(48), jl_box_int32(49), jl_box_int32(50),
jl_box_int32(51), jl_box_int32(52), jl_box_int32(53),
jl_box_int32(54), jl_box_int32(55), jl_box_int32(56),
#endif
jl_box_int64(0), jl_box_int64(1), jl_box_int64(2),
jl_box_int64(3), jl_box_int64(4), jl_box_int64(5),
Expand All @@ -1843,7 +1842,6 @@ void jl_init_serializer(void)
jl_box_int64(45), jl_box_int64(46), jl_box_int64(47),
jl_box_int64(48), jl_box_int64(49), jl_box_int64(50),
jl_box_int64(51), jl_box_int64(52), jl_box_int64(53),
jl_box_int64(54), jl_box_int64(55), jl_box_int64(56),
#endif
jl_labelnode_type, jl_linenumbernode_type, jl_gotonode_type,
jl_quotenode_type, jl_topnode_type, jl_type_type, jl_bottom_type,
Expand Down
11 changes: 2 additions & 9 deletions src/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace JL_I {
sqrt_llvm, powi_llvm,
sqrt_llvm_fast,
// pointer access
pointerref, pointerset, pointertoref,
pointerref, pointerset,
// c interface
ccall, cglobal, jl_alloca, llvmcall
};
Expand Down Expand Up @@ -803,13 +803,6 @@ static Value *emit_intrinsic(intrinsic f, jl_value_t **args, size_t nargs,
HANDLE(zext_int,2) return generic_zext(args[1], args[2], ctx);
HANDLE(pointerref,2) return emit_pointerref(args[1], args[2], ctx);
HANDLE(pointerset,3) return emit_pointerset(args[1], args[2], args[3], ctx);
HANDLE(pointertoref,1) {
Value *p = auto_unbox(args[1], ctx);
if (p->getType()->isIntegerTy()) {
return builder.CreateIntToPtr(p, jl_pvalue_llvmt);
}
return builder.CreateBitCast(p, jl_pvalue_llvmt);
}
HANDLE(checked_fptosi,2) {
Value *x = FP(auto_unbox(args[2], ctx));
return emit_checked_fptosi(args[1], x, ctx);
Expand Down Expand Up @@ -1361,7 +1354,7 @@ extern "C" void jl_init_intrinsic_functions(void)
ADD_I(ceil_llvm); ADD_I(floor_llvm); ADD_I(trunc_llvm); ADD_I(rint_llvm);
ADD_I(sqrt_llvm); ADD_I(powi_llvm);
ADD_I(sqrt_llvm_fast);
ADD_I(pointerref); ADD_I(pointerset); ADD_I(pointertoref);
ADD_I(pointerref); ADD_I(pointerset);
ADD_I(checked_sadd); ADD_I(checked_uadd);
ADD_I(checked_ssub); ADD_I(checked_usub);
ADD_I(checked_smul); ADD_I(checked_umul);
Expand Down
2 changes: 1 addition & 1 deletion src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ DLLEXPORT jl_value_t *jl_get_nth_field_checked(jl_value_t *v, size_t i);
DLLEXPORT void jl_set_nth_field(jl_value_t *v, size_t i, jl_value_t *rhs);
DLLEXPORT int jl_field_isdefined(jl_value_t *v, size_t i);
DLLEXPORT jl_value_t *jl_get_field(jl_value_t *o, char *fld);
DLLEXPORT void *jl_value_ptr(jl_value_t *a);
DLLEXPORT jl_value_t *jl_value_ptr(jl_value_t *a);

// arrays

Expand Down
2 changes: 1 addition & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
JULIAHOME = $(abspath ..)
include ../Make.inc

TESTS = all linalg sparse $(filter-out TestHelpers runtests testdefs,$(subst .jl,,$(wildcard *.jl)))
TESTS = all linalg $(filter-out TestHelpers runtests testdefs,$(subst .jl,,$(wildcard *.jl)))

default: all

Expand Down

0 comments on commit c6ee2f9

Please sign in to comment.