Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve function attributes in prepare_call (plus clean up) #14084

Merged
merged 5 commits into from
Nov 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
26 changes: 7 additions & 19 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -540,11 +539,6 @@ static std::vector<Type *> three_pvalue_llvmt;

static std::map<jl_fptr_t, Function*> 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
Expand Down Expand Up @@ -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]));
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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());
}
}
}
Expand All @@ -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);
Expand Down Expand Up @@ -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<Type *> 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<Type *> exp_args(0);
exp_args.push_back(T_int1);
expect_func = Intrinsic::getDeclaration(m, Intrinsic::expect, exp_args);
Expand Down
6 changes: 3 additions & 3 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 9 additions & 3 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down