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

RFC: CodegenParams for external language implementations #19046

Merged
merged 1 commit into from
Nov 10, 2016

Conversation

maleadt
Copy link
Member

@maleadt maleadt commented Oct 20, 2016

Part of #18338, codegen counterpart to #18496. Used in CUDAnative.jl.

What

This PR adds a CodegenParams struct containing parameters influencing how code is generated (surprise surprise). For now, it is only accepted as an argument to reflection entry-points (ie. _dump_function). The struct contains two types of fields:

  • 'regular' parameters, for now only cached
  • language feature parameters, enabling/disabling parts of the language

In addition, this PR also adds an optimized flag to _dump_function to dump IR, and adds a reference to the current line number for better error reporting (still need to rethink this one).

Why

The goal of the cached parameter is not to reuse from / pollute the cache with functions that have previously been compiled, because those functions might have been compiled with different parameters, or might already be registered with the Host EE in which case we'll just get a pointer.

The language feature parameters make sure we generate valid, GPU compatible IR, and generate a somewhat useful error message if we don't.

How

For us to use this functionality, there's some missing pieces still: codegen hooks (again, cfr. the inference hooks I've proposed in #18338). These allow overriding certain codegen functionality, eg. module_setup (create module with data layout, DWARF version) or module_activation (CPU: register with EE, active DI; GPU: collect IR, link and mcgen afterwards).

We could also generalize these hooks to replace the language features struct, eg. hooks.dynamic_alloc = throw().

Plan

Everything in this PR is up for discussion, but it's kind of the functionality I think I need to support GPU compilation. Nonetheless, I'd prefer to have it part of master (albeit undocumented/unsupported) and iterate on it from there on. This makes it much easier for people to try and use our GPU support, at which point we'll probably get to understand how to improve CUDAnative.jl and its interface with the compiler.

Also, keeping up with master is annoying.

cc @JeffBezanson @vtjnash @Keno @yuyichao @vchuravy

@maleadt maleadt added the compiler:codegen Generation of LLVM IR and native code label Oct 20, 2016
_feat_test(ctx, __FUNCTION__, (ctx)->params->feature, #feature)
static inline bool _feat_test(jl_codectx_t* ctx, const char *caller, int featval, const char *featname) {
if (featval < 0)
jl_errorf("%s for %s requires the %s language feature, which is not allowed",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing :%d for *ctx->line ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

@@ -1775,6 +1783,7 @@ static void cg_bdw(jl_binding_t *b, jl_codectx_t *ctx)
// try to statically evaluate, NULL if not possible
static jl_value_t *static_eval(jl_value_t *ex, jl_codectx_t *ctx, int sparams=true, int allow_alloc=true)
{
if (!JL_FEAT_TEST(ctx, static_alloc)) allow_alloc = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be allow_alloc=false similar to the function parameters.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

allow_alloc sounds ambiguous, maybe not in the context of static_eval but on its own as a codegen param. Also, to contrast against dynamic_alloc...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant if (!JL_FEAT_TEST(ctx, static_alloc)) allow_alloc = false; ;), just a minor nitpick

end

function _dump_function(linfo::Core.MethodInstance, native::Bool, wrapper::Bool, strip_ir_metadata::Bool, dump_module::Bool, syntax::Symbol=:att)
function _dump_function(linfo::Core.MethodInstance, native::Bool, wrapper::Bool, strip_ir_metadata::Bool, dump_module::Bool, syntax::Symbol=:att, optimize::Bool=true, params::CodegenParams=CodegenParams())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are getting long, line break?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️

@maleadt maleadt force-pushed the tb/codegen_params branch 11 times, most recently from c91c3c7 to cb0f01e Compare November 3, 2016 14:21
@maleadt maleadt changed the title RFC/WIP: CodegenParams for external language implementations RFC: CodegenParams for external language implementations Nov 3, 2016
@maleadt
Copy link
Member Author

maleadt commented Nov 3, 2016

Took of the WIP label; I'd like some comments & review before merging this.

Some things I know to be non-ideal/hacky, but can be fixed later:

@maleadt
Copy link
Member Author

maleadt commented Nov 7, 2016

macOS build failure seems unrelated.

Any final comments? I'd like to (rebase, retest and finally) merge this PR soon.

@maleadt
Copy link
Member Author

maleadt commented Nov 10, 2016

I'm going to go ahead and merge this, we can always improve it later.
For reference, the only consumer of this functionality is here.

@maleadt maleadt merged commit c263a6e into master Nov 10, 2016
@maleadt maleadt deleted the tb/codegen_params branch November 10, 2016 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:codegen Generation of LLVM IR and native code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants