Skip to content

Move some code from Asmgen to the middle end directory etc.#2288

Merged
chambart merged 3 commits intoocaml:trunkfrom
mshinwell:asmgen_to_middle_end
May 10, 2019
Merged

Move some code from Asmgen to the middle end directory etc.#2288
chambart merged 3 commits intoocaml:trunkfrom
mshinwell:asmgen_to_middle_end

Conversation

@mshinwell
Copy link
Copy Markdown
Contributor

@mshinwell mshinwell commented Mar 5, 2019

@chambart This is the followup to #2281. It moves some code that, morally speaking, belongs in the middle end but has thus far lived in Asmgen. The interfaces for Closure and Flambda are harmonised and various typos (e.g. "clambda" instead of "Closure") have been fixed. In the spirit of not reaching back into the middle end from the backend, Un_anf is not called from Cmmgen any more, but always invoked from Flambda_middle_end. We also pass constants used for instrumentation directly out of Flambda_to_clambda so they flow to Cmmgen without going through Compilenv (this will be important for a later patch).

This patch includes #2280 (just merged into trunk), #2281 and #2284. For the moment just read changeset 4a3b0a8.

@mshinwell
Copy link
Copy Markdown
Contributor Author

@chambart @lthls Could one of you please review and approve this if you are happy? I've fixed the mistake in the comment that @lthls told me about. This is looking like quite a nice patch now, it's simplified various parts in the backend and made the middle-end interfaces consistent.

Please double-check that Un_anf is being run as many times as it used to be -- the invocation point has changed.

@mshinwell
Copy link
Copy Markdown
Contributor Author

P.S. For reviewing closure_middle_end.ml and flambda_middle_end.ml I suggest you patdiff against the old asmgen.ml. There have been a few changes but those blocks are mainly moved verbatim IIRC.

Copy link
Copy Markdown
Contributor

@chambart chambart left a comment

Choose a reason for hiding this comment

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

This looks good. The comments are minor things except the thing about new_structured_constants that should be fixed.

The result is quite cleaner, this is a good change.

in
Asmgen.compile_implementation_flambda
prefixname ~backend ~required_globals:Ident.Set.empty ~ppf_dump flam;
Asmgen.compile_implementation ~backend
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That call could be factorised out.

let program, middle_end =
  if Config.flambda then
   ...
in
Asmgen.compile_implementation ...

I'm not certain that this is better.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It does seem to be better.

(clambda:clambda_and_constants) =
(clambda : Clambda.with_constants) =
Emit.begin_assembly ();
Cmmgen.reset ();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why was that required ? Ins't the one at the beginning of compile_fundecl sufficient ?

By the way, by quickly looking at it, no reset would be required if Cmmgen_state.constants and data_items where cleaning their state.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've fixed things so reset is not needed.

|> (fun { Flambda_to_clambda. expr; preallocated_blocks;
structured_constants; exported; } ->
Compilenv.set_export_info exported;
let clambda = Un_anf.apply ~ppf_dump expr in
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This code has a linkage_name, it could be printed. It doesn't really matter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This should be fixed now.

let str = Format.asprintf "%a" Flambda.print_named named in
let str_const =
let sym =
Compilenv.new_structured_constant (Uconst_string str) ~shared:true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This doesn't just create a symbol name, it also records the structured constant. This should probably be replaced by 'new_const_symbol'

Or at least, flambda should use clear_structured_constants if this is used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

in
let str_const =
let sym =
Compilenv.new_structured_constant (Uconst_string str) ~shared:true
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same thing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@mshinwell mshinwell force-pushed the asmgen_to_middle_end branch from 4e6cc05 to 67a4e71 Compare May 10, 2019 09:24
@mshinwell
Copy link
Copy Markdown
Contributor Author

@chambart All comments addressed; if you are happy and this passes CI please squash and merge.

@chambart chambart merged commit 6cbdfad into ocaml:trunk May 10, 2019
@chambart
Copy link
Copy Markdown
Contributor

This looks nice. merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants