Skip to content
Draft
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
13 changes: 11 additions & 2 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,28 @@ struct CodegenParams
"""
sanitize_address::Cint

"""
When enabled, generate names that are globally unique in this Julia session,
across all code generated with this flag set. Intended for llvmpasses
tests.
"""
unique_names::Cint

function CodegenParams(; track_allocations::Bool=true, code_coverage::Bool=true,
prefer_specsig::Bool=false,
gnu_pubnames::Bool=true, debug_info_kind::Cint = default_debug_info_kind(),
debug_info_level::Cint = Cint(JLOptions().debug_level), safepoint_on_entry::Bool=true,
gcstack_arg::Bool=true, use_jlplt::Bool=true, force_emit_all::Bool=false,
sanitize_memory::Bool=false, sanitize_thread::Bool=false, sanitize_address::Bool=false)
sanitize_memory::Bool=false, sanitize_thread::Bool=false, sanitize_address::Bool=false,
unique_names::Bool=false)
return new(
Cint(track_allocations), Cint(code_coverage),
Cint(prefer_specsig),
Cint(gnu_pubnames), debug_info_kind,
debug_info_level, Cint(safepoint_on_entry),
Cint(gcstack_arg), Cint(use_jlplt), Cint(force_emit_all),
Cint(sanitize_memory), Cint(sanitize_thread), Cint(sanitize_address))
Cint(sanitize_memory), Cint(sanitize_thread), Cint(sanitize_address),
Cint(unique_names))
end
end

Expand Down
767 changes: 288 additions & 479 deletions src/aotcompile.cpp

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ static bool runtime_sym_gvs(jl_codectx_t &ctx, const native_sym_arg_t &symarg,
return false;
}

auto M = &ctx.emission_context.shared_module();
auto M = &ctx.emission_context.get_module();
bool runtime_lib = false;
GlobalVariable *libptrgv;
jl_codegen_params_t::SymMapGV *symMap;
jl_codegen_output_t::SymMapGV *symMap;
if ((intptr_t)f_lib == (intptr_t)JL_EXE_LIBNAME) {
libptrgv = prepare_global_in(M, jlexe_var);
symMap = &ctx.emission_context.symMapExe;
Expand Down Expand Up @@ -147,7 +147,7 @@ static bool runtime_sym_gvs(jl_codectx_t &ctx, const native_sym_arg_t &symarg,
}

static Value *runtime_sym_lookup(
jl_codegen_params_t &emission_context,
jl_codegen_output_t &emission_context,
IRBuilder<> &irbuilder,
jl_codectx_t *pctx,
const native_sym_arg_t &symarg, Function *f,
Expand Down Expand Up @@ -265,7 +265,7 @@ static GlobalVariable *emit_plt_thunk(
++PLTThunks;
bool shared = libptrgv != nullptr;
assert(shared && "not yet supported by runtime_sym_lookup");
Module *M = shared ? &ctx.emission_context.shared_module() : jl_Module;
auto M = &ctx.emission_context.get_module();
if (shared) {
assert(symarg.f_name);
libptrgv = prepare_global_in(M, libptrgv);
Expand Down Expand Up @@ -1177,7 +1177,7 @@ static jl_cgval_t emit_llvmcall(jl_codectx_t &ctx, jl_value_t **args, size_t nar
// save the module to be linked later.
// we cannot do this right now, because linking mutates the destination module,
// which might invalidate LLVM values cached in cgval_t's (specifically constant arrays)
ctx.llvmcall_modules.push_back(std::move(Mod));
ctx.emission_context.llvmcall_modules.push_back(std::move(Mod));

JL_GC_POP();

Expand Down Expand Up @@ -1242,9 +1242,9 @@ class function_sig_t {
jl_unionall_t *unionall_env; // UnionAll environment for `at` and `rt`
size_t nccallargs; // number of actual arguments
size_t nreqargs; // number of required arguments in ccall function definition
jl_codegen_params_t *ctx;
jl_codegen_output_t *ctx;

function_sig_t(const char *fname, Type *lrt, jl_value_t *rt, bool retboxed, bool gc_safe, jl_svec_t *at, jl_unionall_t *unionall_env, size_t nreqargs, CallingConv::ID cc, bool llvmcall, jl_codegen_params_t *ctx)
function_sig_t(const char *fname, Type *lrt, jl_value_t *rt, bool retboxed, bool gc_safe, jl_svec_t *at, jl_unionall_t *unionall_env, size_t nreqargs, CallingConv::ID cc, bool llvmcall, jl_codegen_output_t *ctx)
: lrt(lrt), retboxed(retboxed), gc_safe(gc_safe),
prt(NULL), sret(0), cc(cc), llvmcall(llvmcall),
at(at), rt(rt), unionall_env(unionall_env),
Expand Down Expand Up @@ -1470,7 +1470,7 @@ static bool verify_ref_type(jl_codectx_t &ctx, jl_value_t* ref, jl_unionall_t *u

static const std::string verify_ccall_sig(jl_value_t *&rt, jl_value_t *at,
jl_unionall_t *unionall_env, jl_svec_t *sparam_vals,
jl_codegen_params_t *ctx,
jl_codegen_output_t *ctx,
Type *&lrt, LLVMContext &ctxt,
bool &retboxed, bool &static_rt, bool llvmcall=false)
{
Expand Down
28 changes: 14 additions & 14 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ AtomicOrdering get_llvm_atomic_order(enum jl_memory_order order)

// --- string constants ---
static Value *stringConstPtr(
jl_codegen_params_t &emission_context,
jl_codegen_output_t &emission_context,
IRBuilder<> &irbuilder,
const Twine &txt)
{
Expand Down Expand Up @@ -187,7 +187,7 @@ static DICompileUnit *getOrCreateJuliaCU(Module &M,
return CU;
}

static DIType *_julia_type_to_di(jl_codegen_params_t *ctx, jl_debugcache_t &debuginfo, jl_value_t *jt, DIBuilder *dbuilder, bool isboxed)
static DIType *_julia_type_to_di(jl_codegen_output_t *ctx, jl_debugcache_t &debuginfo, jl_value_t *jt, DIBuilder *dbuilder, bool isboxed)
{
jl_datatype_t *jdt = (jl_datatype_t*)jt;
if (isboxed || !jl_is_datatype(jt) || !jdt->isconcretetype)
Expand Down Expand Up @@ -389,10 +389,10 @@ static llvm::SmallVector<Value*,0> get_gc_roots_for(jl_codectx_t &ctx, const jl_

// --- emitting pointers directly into code ---

static void jl_temporary_root(jl_codegen_params_t &ctx, jl_value_t *val);
static void jl_temporary_root(jl_codegen_output_t &ctx, jl_value_t *val);
static void jl_temporary_root(jl_codectx_t &ctx, jl_value_t *val);

static Constant *julia_pgv(jl_codegen_params_t &params, Module *M, const char *cname, void *addr)
static Constant *julia_pgv(jl_codegen_output_t &params, Module *M, const char *cname, void *addr)
{
// emit a GlobalVariable for a jl_value_t named "cname"
// store the name given so we can reuse it (facilitating merging later)
Expand All @@ -401,8 +401,7 @@ static Constant *julia_pgv(jl_codegen_params_t &params, Module *M, const char *c
StringRef localname;
std::string gvname;
if (!gv) {
uint64_t id = jl_atomic_fetch_add_relaxed(&globalUniqueGeneratedNames, 1); // TODO: use params.global_targets.size()
raw_string_ostream(gvname) << cname << id;
gvname = params.make_name(cname);
localname = StringRef(gvname);
}
else {
Expand All @@ -424,7 +423,7 @@ static Constant *julia_pgv(jl_codegen_params_t &params, Module *M, const char *c
return gv;
}

static Constant *julia_pgv(jl_codegen_params_t &params, Module *M, const char *prefix, jl_sym_t *name, jl_module_t *mod, void *addr)
static Constant *julia_pgv(jl_codegen_output_t &params, Module *M, const char *prefix, jl_sym_t *name, jl_module_t *mod, void *addr)
{
// emit a GlobalVariable for a jl_value_t, using the prefix, name, and module to
// to create a readable name of the form prefixModA.ModB.name#
Expand Down Expand Up @@ -453,8 +452,9 @@ static Constant *julia_pgv(jl_codegen_params_t &params, Module *M, const char *p
}

static JuliaVariable *julia_const_gv(jl_value_t *val);
Constant *literal_pointer_val_slot(jl_codegen_params_t &params, Module *M, jl_value_t *p)
Constant *literal_pointer_val_slot(jl_codegen_output_t &params, jl_value_t *p)
{
Module *M = &params.get_module();
// emit a pointer to a jl_value_t* which will allow it to be valid across reloading code
// also, try to give it a nice name for gdb, for easy identification
if (JuliaVariable *gv = julia_const_gv(p)) {
Expand Down Expand Up @@ -564,7 +564,7 @@ static Value *literal_pointer_val(jl_codectx_t &ctx, jl_value_t *p)
{
if (p == NULL)
return Constant::getNullValue(ctx.types().T_pjlvalue);
Value *pgv = literal_pointer_val_slot(ctx.emission_context, jl_Module, p);
Value *pgv = literal_pointer_val_slot(ctx.emission_context, p);
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_const);
auto load = ai.decorateInst(maybe_mark_load_dereferenceable(
ctx.builder.CreateAlignedLoad(ctx.types().T_pjlvalue, pgv, Align(sizeof(void*))),
Expand Down Expand Up @@ -626,9 +626,9 @@ static unsigned convert_struct_offset(jl_codectx_t &ctx, Type *lty, unsigned byt
return convert_struct_offset(ctx.builder.GetInsertBlock()->getModule()->getDataLayout(), lty, byte_offset);
}

static Type *_julia_struct_to_llvm(jl_codegen_params_t *ctx, LLVMContext &ctxt, jl_value_t *jt, bool *isboxed, bool llvmcall=false);
static Type *_julia_struct_to_llvm(jl_codegen_output_t *ctx, LLVMContext &ctxt, jl_value_t *jt, bool *isboxed, bool llvmcall=false);

static Type *_julia_type_to_llvm(jl_codegen_params_t *ctx, LLVMContext &ctxt, jl_value_t *jt, bool *isboxed)
static Type *_julia_type_to_llvm(jl_codegen_output_t *ctx, LLVMContext &ctxt, jl_value_t *jt, bool *isboxed)
{
// this function converts a Julia Type into the equivalent LLVM type
if (isboxed) *isboxed = false;
Expand Down Expand Up @@ -736,7 +736,7 @@ static StructType *get_memoryref_type(LLVMContext &ctxt, Type *T_size, const jl_
return get_jlmemoryref(ctxt, AS);
}

static Type *_julia_struct_to_llvm(jl_codegen_params_t *ctx, LLVMContext &ctxt, jl_value_t *jt, bool *isboxed, bool llvmcall)
static Type *_julia_struct_to_llvm(jl_codegen_output_t *ctx, LLVMContext &ctxt, jl_value_t *jt, bool *isboxed, bool llvmcall)
{
// this function converts a Julia Type into the equivalent LLVM struct
// use this where C-compatible (unboxed) structs are desired
Expand Down Expand Up @@ -1346,7 +1346,7 @@ static Value *emit_typeof(jl_codectx_t &ctx, const jl_cgval_t &p, bool maybenull
ptr = get_pointer_to_constant(ctx.emission_context, ConstantInt::get(expr_type, jt->smalltag << 4), Align(sizeof(jl_value_t*)), StringRef("_j_smalltag_") + jl_symbol_name(jt->name->name), *jl_Module);
}
else {
ptr = ConstantExpr::getBitCast(literal_pointer_val_slot(ctx.emission_context, jl_Module, (jl_value_t*)jt), datatype_or_p->getType());
ptr = ConstantExpr::getBitCast(literal_pointer_val_slot(ctx.emission_context, (jl_value_t*)jt), datatype_or_p->getType());
}
datatype_or_p = ctx.builder.CreateSelect(cmp, ptr, datatype_or_p);
setName(ctx.emission_context, datatype_or_p, "typetag_ptr");
Expand Down Expand Up @@ -4503,7 +4503,7 @@ static Value *emit_defer_signal(jl_codectx_t &ctx)
return emit_ptrgep(ctx, ptls, offsetof(jl_tls_states_t, defer_signal));
}

#ifndef JL_NDEBUG
#if 0
static int compare_cgparams(const jl_cgparams_t *a, const jl_cgparams_t *b)
{
return
Expand Down
Loading