Skip to content

Commit 6c1168a

Browse files
authored
Document and clean up CodegenParams (#51140)
- Add documentation to CodegenParams fields per request in #51123 - Fix compare_cgparams which hadn't been updated for recent additions - Remove unused and untested generic_context The latter was a codegen option that I added, but eventually ended up not using anywhere, so remove it for the time being. That said, I may end up in a situation where I need it again in the very near future, so I may end up eating my words here, but if I need to put it back, I'll include a test at least ;).
1 parent ec2f1d3 commit 6c1168a

File tree

4 files changed

+77
-20
lines changed

4 files changed

+77
-20
lines changed

base/reflection.jl

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,33 +1212,98 @@ default_debug_info_kind() = unsafe_load(cglobal(:jl_default_debug_info_kind, Cin
12121212

12131213
# this type mirrors jl_cgparams_t (documented in julia.h)
12141214
struct CodegenParams
1215+
"""
1216+
If enabled, generate the necessary code to support the --track-allocations
1217+
command line flag to julia itself. Note that the option itself does not enable
1218+
allocation tracking. Rather, it merely generates the support code necessary
1219+
to perform allocation tracking if requested by the command line option.
1220+
"""
12151221
track_allocations::Cint
1222+
1223+
"""
1224+
If enabled, generate the necessary code to support the --code-coverage
1225+
command line flag to julia itself. Note that the option itself does not enable
1226+
code coverage. Rather, it merely generates the support code necessary
1227+
to code coverage if requested by the command line option.
1228+
"""
12161229
code_coverage::Cint
1230+
1231+
"""
1232+
If enabled, force the compiler to use the specialized signature
1233+
for all generated functions, whenever legal. If disabled, the choice is made
1234+
heuristically and specsig is only used when deemed profitable.
1235+
"""
12171236
prefer_specsig::Cint
1237+
1238+
"""
1239+
If enabled, enable emission of `.debug_names` sections.
1240+
"""
12181241
gnu_pubnames::Cint
1242+
1243+
"""
1244+
Controls what level of debug info to emit. Currently supported values are:
1245+
- 0: no debug info
1246+
- 1: full debug info
1247+
- 2: Line tables only
1248+
- 3: Debug directives only
1249+
1250+
The integer values currently match the llvm::DICompilerUnit::DebugEmissionKind enum,
1251+
although this is not guaranteed.
1252+
"""
12191253
debug_info_kind::Cint
1254+
1255+
"""
1256+
If enabled, generate a GC safepoint at the entry to every function. Emitting
1257+
these extra safepoints can reduce the amount of time that other threads are
1258+
waiting for the currently running thread to reach a safepoint. The cost for
1259+
a safepoint is small, but non-zero. The option is enabled by default.
1260+
"""
12201261
safepoint_on_entry::Cint
1262+
1263+
"""
1264+
If enabled, add an implicit argument to each function call that is used to
1265+
pass down the current task local state pointer. This argument is passed
1266+
using the `swiftself` convention, which in the ordinary case means that the
1267+
pointer is kept in a register and accesses are thus very fast. If this option
1268+
is disabled, the task local state pointer must be loaded from thread local
1269+
stroage, which incurs a small amount of additional overhead. The option is enabled by
1270+
default.
1271+
"""
12211272
gcstack_arg::Cint
1273+
1274+
"""
1275+
If enabled, use the Julia PLT mechanism to support lazy-resolution of `ccall`
1276+
targets. The option may be disabled for use in environments where the julia
1277+
runtime is unavailable, but is otherwise recommended to be enabled, even if
1278+
lazy resolution is not required, as the Julia PLT mechanism may have superior
1279+
performance compared to the native platform mechanism. The options is enabled by default.
1280+
"""
12221281
use_jlplt::Cint
12231282

1224-
lookup::Ptr{Cvoid}
1283+
"""
1284+
A pointer of type
12251285
1226-
generic_context::Any
1286+
typedef jl_value_t *(*jl_codeinstance_lookup_t)(jl_method_instance_t *mi JL_PROPAGATES_ROOT,
1287+
size_t min_world, size_t max_world);
1288+
1289+
that may be used by external compilers as a callback to look up the code instance corresponding
1290+
to a particular method instance.
1291+
"""
1292+
lookup::Ptr{Cvoid}
12271293

12281294
function CodegenParams(; track_allocations::Bool=true, code_coverage::Bool=true,
12291295
prefer_specsig::Bool=false,
12301296
gnu_pubnames=true, debug_info_kind::Cint = default_debug_info_kind(),
12311297
safepoint_on_entry::Bool=true,
12321298
gcstack_arg::Bool=true, use_jlplt::Bool=true,
1233-
lookup::Ptr{Cvoid}=unsafe_load(cglobal(:jl_rettype_inferred_addr, Ptr{Cvoid})),
1234-
generic_context = nothing)
1299+
lookup::Ptr{Cvoid}=unsafe_load(cglobal(:jl_rettype_inferred_addr, Ptr{Cvoid})))
12351300
return new(
12361301
Cint(track_allocations), Cint(code_coverage),
12371302
Cint(prefer_specsig),
12381303
Cint(gnu_pubnames), debug_info_kind,
12391304
Cint(safepoint_on_entry),
12401305
Cint(gcstack_arg), Cint(use_jlplt),
1241-
lookup, generic_context)
1306+
lookup)
12421307
end
12431308
end
12441309

src/cgutils.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4146,8 +4146,10 @@ static int compare_cgparams(const jl_cgparams_t *a, const jl_cgparams_t *b)
41464146
(a->prefer_specsig == b->prefer_specsig) &&
41474147
(a->gnu_pubnames == b->gnu_pubnames) &&
41484148
(a->debug_info_kind == b->debug_info_kind) &&
4149-
(a->lookup == b->lookup) &&
4150-
(a->generic_context == b->generic_context);
4149+
(a->safepoint_on_entry == b->safepoint_on_entry) &&
4150+
(a->gcstack_arg == b->gcstack_arg) &&
4151+
(a->use_jlplt == b->use_jlplt) &&
4152+
(a->lookup == b->lookup);
41514153
}
41524154
#endif
41534155

src/codegen.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,8 +1366,7 @@ extern "C" {
13661366
/* safepoint_on_entry */ 1,
13671367
/* gcstack_arg */ 1,
13681368
/* use_jlplt*/ 1,
1369-
/* lookup */ jl_rettype_inferred_addr,
1370-
/* generic_context */ NULL };
1369+
/* lookup */ jl_rettype_inferred_addr };
13711370
}
13721371

13731372

@@ -4632,15 +4631,11 @@ static jl_cgval_t emit_call(jl_codectx_t &ctx, jl_expr_t *ex, jl_value_t *rt, bo
46324631
return emit_intrinsic(ctx, fi, args, nargs - 1);
46334632
}
46344633

4635-
jl_value_t *context = ctx.params->generic_context == jl_nothing ? nullptr : ctx.params->generic_context;
4636-
size_t n_generic_args = nargs + (context ? 1 : 0);
4634+
size_t n_generic_args = nargs;
46374635

46384636
SmallVector<jl_cgval_t> generic_argv(n_generic_args);
46394637
jl_cgval_t *argv = generic_argv.data();
4640-
if (context) {
4641-
generic_argv[0] = mark_julia_const(ctx, context);
4642-
argv = &generic_argv[1];
4643-
}
4638+
46444639
argv[0] = f;
46454640
for (size_t i = 1; i < nargs; ++i) {
46464641
argv[i] = emit_expr(ctx, args[i]);
@@ -9304,7 +9299,6 @@ extern "C" void jl_init_llvm(void)
93049299
{
93059300
jl_page_size = jl_getpagesize();
93069301
jl_default_debug_info_kind = (int) DICompileUnit::DebugEmissionKind::FullDebug;
9307-
jl_default_cgparams.generic_context = jl_nothing;
93089302

93099303
InitializeNativeTarget();
93109304
InitializeNativeTargetAsmPrinter();

src/julia.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,10 +2381,6 @@ typedef struct {
23812381

23822382
// Cache access. Default: jl_rettype_inferred.
23832383
jl_codeinstance_lookup_t lookup;
2384-
2385-
// If not `nothing`, rewrite all generic calls to call
2386-
// generic_context(f, args...) instead of f(args...).
2387-
jl_value_t *generic_context;
23882384
} jl_cgparams_t;
23892385
extern JL_DLLEXPORT int jl_default_debug_info_kind;
23902386

0 commit comments

Comments
 (0)