diff --git a/src/cgutils.cpp b/src/cgutils.cpp index ee5ebcae1cec0..b83a130acb156 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -53,10 +53,13 @@ static llvm::Value *prepare_call(llvm::Value* Callee) return ModuleF; } else { - return Function::Create(F->getFunctionType(), - Function::ExternalLinkage, - F->getName(), - jl_Module); + Function *func = Function::Create(F->getFunctionType(), + Function::ExternalLinkage, + F->getName(), + jl_Module); + func->setAttributes(AttributeSet()); + func->copyAttributesFrom(F); + return func; } } #endif @@ -2120,3 +2123,13 @@ static jl_cgval_t emit_new_struct(jl_value_t *ty, size_t nargs, jl_value_t **arg return mark_julia_const(sty->instance); } } + +static Value *emit_pgcstack() +{ + return prepare_global(jlpgcstack_var); +} + +static Value *emit_exc_in_transit() +{ + return prepare_global(jlexc_var); +} diff --git a/src/codegen.cpp b/src/codegen.cpp index 7fa5f1e6e97ef..8844b8273a4d2 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -517,7 +517,6 @@ static Function *box8_func; static Function *box16_func; static Function *box32_func; static Function *box64_func; -static Function *wbfunc; static Function *queuerootfun; static Function *expect_func; static Function *jldlsym_func; @@ -540,11 +539,6 @@ static std::vector three_pvalue_llvmt; static std::map builtin_func_map; -extern "C" DLLEXPORT void jl_gc_wb_slow(jl_value_t* parent, jl_value_t* ptr) -{ - jl_gc_wb(parent, ptr); -} - // --- code generation --- // metadata tracking for a llvm Value* during codegen @@ -3775,7 +3769,9 @@ static jl_cgval_t emit_expr(jl_value_t *expr, jl_codectx_t *ctx, bool isboxed, b return mark_julia_type(val, true, ty); } else if (head == exc_sym) { // *jl_exception_in_transit - return mark_julia_type(builder.CreateLoad(prepare_global(jlexc_var), /*isvolatile*/true), true, jl_any_type); + return mark_julia_type(builder.CreateLoad(emit_exc_in_transit(), + /*isvolatile*/true), + true, jl_any_type); } else if (head == leave_sym) { assert(jl_is_long(args[0])); @@ -3811,7 +3807,7 @@ static jl_cgval_t emit_expr(jl_value_t *expr, jl_codectx_t *ctx, bool isboxed, b builder.SetInsertPoint(cond_resetstkoflw_blk); builder.CreateCondBr(builder.CreateICmpEQ( literal_pointer_val(jl_stackovf_exception), - builder.CreateLoad(prepare_global(jlexc_var), true)), + builder.CreateLoad(emit_exc_in_transit(), true)), resetstkoflw_blk, handlr); builder.SetInsertPoint(resetstkoflw_blk); builder.CreateCall(prepare_call(resetstkoflw_func) @@ -3954,7 +3950,7 @@ emit_gcpops(jl_codectx_t *ctx) (Instruction*)builder.CreateConstGEP1_32(ctx->gc.gcframe, 1); builder.CreateStore(builder.CreatePointerCast(builder.CreateLoad(gcpop), T_ppjlvalue), - prepare_global(jlpgcstack_var)); + emit_pgcstack()); } } } @@ -3976,9 +3972,9 @@ static void finalize_gc_frame(jl_codectx_t *ctx) gc->tempSlot->setOperand(1, ConstantInt::get(T_int32, 2 + gc->argSpaceSize)); // fix up the offset to the temp slot space builder.CreateStore(ConstantInt::get(T_size, (gc->argSpaceSize + gc->maxDepth) << 1), builder.CreateBitCast(builder.CreateConstGEP1_32(newgcframe, 0), T_psize)); - builder.CreateStore(builder.CreateLoad(prepare_global(jlpgcstack_var)), + builder.CreateStore(builder.CreateLoad(emit_pgcstack()), builder.CreatePointerCast(builder.CreateConstGEP1_32(newgcframe, 1), PointerType::get(T_ppjlvalue,0))); - builder.CreateStore(newgcframe, prepare_global(jlpgcstack_var)); + builder.CreateStore(newgcframe, emit_pgcstack()); // Initialize the slots for temporary variables to NULL for (int i = 0; i < gc->argSpaceSize; i++) { Value *argTempi = emit_local_slot(i, ctx); @@ -5809,14 +5805,6 @@ static void init_julia_llvm_env(Module *m) "jl_gc_queue_root", m); add_named_global(queuerootfun, (void*)&jl_gc_queue_root); - std::vector wbargs(0); - wbargs.push_back(T_pjlvalue); - wbargs.push_back(T_pjlvalue); - wbfunc = Function::Create(FunctionType::get(T_void, wbargs, false), - Function::ExternalLinkage, - "jl_gc_wb_slow", m); - add_named_global(wbfunc, (void*)&jl_gc_wb_slow); - std::vector exp_args(0); exp_args.push_back(T_int1); expect_func = Intrinsic::getDeclaration(m, Intrinsic::expect, exp_args); diff --git a/src/gc.c b/src/gc.c index a4ced998872a6..7ad24c86481c2 100644 --- a/src/gc.c +++ b/src/gc.c @@ -1862,7 +1862,6 @@ static void visit_mark_stack(int mark_mode) void jl_mark_box_caches(void); -extern JL_THREAD jl_value_t * volatile jl_task_arg_in_transit; #if defined(GCTIME) || defined(GC_FINAL_STATS) double clock_now(void); #endif @@ -2444,10 +2443,11 @@ void jl_print_gc_stats(JL_STREAM *s) #endif // Per-thread initialization (when threading is fully implemented) -struct _jl_thread_heap_t *jl_mk_thread_heap(void) +jl_thread_heap_t *jl_mk_thread_heap(void) { #ifdef JULIA_ENABLE_THREADING - jl_thread_heap = malloc(sizeof(jl_thread_heap_t)); // FIXME - should be cache-aligned malloc + // FIXME - should be cache-aligned malloc + jl_thread_heap = (jl_thread_heap_t*)malloc(sizeof(jl_thread_heap_t)); #endif FOR_CURRENT_HEAP () { const int* szc = sizeclasses; diff --git a/src/julia.h b/src/julia.h index 754aca0dc7702..921e2aacc8c74 100644 --- a/src/julia.h +++ b/src/julia.h @@ -40,10 +40,16 @@ extern "C" { #define NWORDS(sz) (((sz)+3)>>2) #endif -#if __GNUC__ -#define NORETURN __attribute__ ((noreturn)) +#if defined(__GNUC__) +# define NORETURN __attribute__ ((noreturn)) +# define JL_CONST_FUNC __attribute__((const)) +#elif defined(_COMPILER_MICROSOFT_) +# define NORETURN __declspec(noreturn) +// This is the closest I can find for __attribute__((const)) +# define JL_CONST_FUNC __declspec(noalias) #else -#define NORETURN +# define NORETURN +# define JL_CONST_FUNC #endif #define container_of(ptr, type, member) \