Commit Graph

121 Commits (master)

Author SHA1 Message Date
Gabriel Scherer 82b29828d2
Allow `[@tailcall true]` and `[@tailcall false]` (#9754)
* remove the unused is_native_tail_call_heuristic forward reference

This forward-reference from Lambda to Asmcomp was used to generate
machine-specific tailcall information in -annot output; this only use
was removed in 57d329e07b, so we can now
remove it to simplify the codebase.

The logic was non-trivial and might be useful again in the future.

* [minor] testsuite: convert warnings/w51.ml to an expect-test

* [minor] translattribute: refactor attribute payload deconstruction

* [@tailcall false]: warn if the call *is* a tailcall

(+ constructor renaming suggested by Nicolás during review)

* Changes

* testsuite: add an example with the 'invalid payload' exception

(suggested by Nicolás during review)
2020-10-10 13:41:39 +02:00
Nicolás Ojeda Bär 43883ae4bc Remove labels after calls, checkbound, and GC points 2020-10-08 20:28:15 +02:00
Nicolás Ojeda Bär 3869f71e98 Remove Cblockheader 2020-10-08 20:28:15 +02:00
Nicolás Ojeda Bär 540996d21e Remove Spacetime 2020-10-08 20:28:12 +02:00
Xavier Leroy 8e246c41c2 Revised detection of arithmetic instructions with immediate operands, continued
- Rewrite the `is_immediate` methods in $ARCH/selection.ml in the style of
  other selection methods: operations that need platform-dependent handling
  are explicitly listed, all others fall through `super#is_immediate`.

- The `is_immediate` method from selectgen.ml knows how to handle shifts
  (and no other operation).  Remove the `select_shift_op` method,
  now unnecessary.

- ARM: remove special cases for multiply and multiply-high, no longer
  necessary.

- RISC-V: in emit.mlp, remove implementation of checkbound immediate,
  which is no longer generated.
2020-09-21 14:49:16 +02:00
Xavier Leroy 65544ffd1f Revised detection of arithmetic instructions with immediate operands
Replace the a single `is_immediate n` method that is supposed to apply
to all arithmetic instructions by two methods:

`is_immediate op n` : tests whether `n` is in the range of supported
   immediate arguments for integer operation `op`
`is_immediate_test cmp n` : tests whether `n` is in the range of supported
   immediate arguments for integer comparison `cmp`

This makes it easier to handle operations without immediate operands
(e.g. multiply or multiply-high on many platforms) and operations with
specific ranges of immediate operands (e.g. N-bit unsigned versus
N-bit signed).  Before, these operations had to be treated as special
cases in the platform-specific `select_operation` method.
2020-09-16 11:52:19 +02:00
Fourchaux 44e6cf4e0f
typos (#9806) 2020-07-28 12:22:03 +01:00
Xavier Leroy e41dc9c443
Merge pull request #9752 from xavierleroy/c-calling-conventions
Revised handing of calling conventions for external C functions
2020-07-25 09:50:42 +02:00
Xavier Leroy 9fcb295b98 Revised passing of arguments to external C functions
Introduce the type Cmm.exttype to precisely describe arguments to
external C functions, especially unboxed numerical arguments.

Annotate Cmm.Cextcall with the types of the arguments (Cmm.exttype list).
An empty list means "all arguments have default type XInt".

Annotate Mach.Iextcall with the type of the result (Cmm.machtype)
and the types of the arguments (Cmm.exttype list).

Change (slightly) the API for describing calling conventions in Proc:
- loc_external_arguments now takes a Cmm.exttype list,
  in order to know more precisely the types of the arguments.
- loc_arguments, loc_parameters, loc_results, loc_external_results
  now take a Cmm.machype instead of an array of pseudoregisters.
  (Only the types of the pseudoregisters mattered anyway.)

Update the implementations of module Proc accordingly, in every port.

Introduce a new overridable method in Selectgen, insert_move_extcall_arg,
to produce the code that moves an argument of an external C function
to the locations returned by Proc.loc_external_arguments.

Revise the selection of external calls accordingly
(method emit_extcall_args in Selectgen).
2020-07-24 17:39:22 +02:00
Xavier Leroy 1e71f75ec4
Selectgen#bind_let_mut: use self#regs_for to allocate target registers (#9782)
Software emulation of floating-point arithmetic, as in the ARM EABI port,
use pairs of pseudoregisters of type Int to represent values of type Float.

This is achieved by the `regs_for` method of class `selector_generic`,
which defaults to `Reg.createv` but is overriden for ARM EABI so
as to perform the transformation Float -> Int,Int on the fly.

The method `bind_let_mut` uses `Reg.createv` to associate
pseudoregisters to bound variables.  This is incorrect in a soft FP
context, as a bound variable of type Float will get a Float register
nonetheless.  `self#regs_for` must be used instead.  This is what this
commit does.
2020-07-20 11:24:37 +02:00
Stephen Dolan 2d92955749
Remove Const_pointer (#9578)
Since #9316 was merged, Cconst_pointer is compiled in exactly the same way as Cconst_int. This commit removes the now-redundant Cconst_pointer and Cconst_natpointer.
2020-05-19 15:31:08 +02:00
Stephen Dolan d5dadae8ed
Make Cconst_symbol have typ_int to fix no-naked-pointers mode (#9282) 2020-04-21 12:06:19 +01:00
Stephen Dolan 2208a4cbe6
Fix tail-call optimisation with a mutable ref (#9443)
Fix tail-call optimisation with a mutable ref
(Clet_mutable was not recognized properly in tail position.)

Add a test for tail-call optimisation with a mutable ref
2020-04-13 18:20:56 +02:00
Stephen Dolan de9e630852 Assert that Cassign is only used on Clet_mut-bound variables 2020-02-25 15:23:38 +00:00
Stephen Dolan 1336ce0c0d Use typing information from Clambda for mutable Cmm variables 2020-02-25 15:03:14 +00:00
Stephen Dolan 34f97941ec Retain debug information about allocation sizes, for statmemprof.
This code is adapted from jhjourdan's 2c93ca1e711. Comballoc is
extended to keep track of allocation sizes and debug info for each
allocation, and the frame table format is modified to store them.

The native code GC-entry logic is changed to match bytecode, by
calling the garbage collector at most once per allocation.

amd64 only, for now.
2019-10-22 11:47:31 +01:00
Greta Yorsh 1c128fdf25 Make contains_calls into a reference instance variable 2019-09-12 12:58:54 +01:00
Greta Yorsh aeebb62e9b Move contains_calls and num_stack_slots from Proc to Mach.fundecl 2019-09-09 11:33:03 +01:00
KC Sivaramakrishnan c06038a0ee Move backtrace support global variables to domain state.
Since we cannot access backtrace position in cmmgen.ml anymore,
Cmm.raise_kind in removed. Instead, we use Lambda.raise_kind. When
assembly code is generated, we reset the backtrace position to 0 in the
case of regular raise. Importantly, the semantics remains the same.
2019-08-23 09:50:05 +05:30
Vincent Laviron 4edac52bc5 Move size computations from Cmm to Selectgen
This removes a dependency to Arch in Cmm
2019-05-24 14:20:37 +02:00
Mark Shinwell e141d9e240
Add a few utility functions in Misc (#2284) 2019-03-15 11:28:19 +00:00
Mark Shinwell 618e5dbfbd More debugging information in Cmm terms (#2308)
Following on from GPR#851 and GPR#873, this pull request further enhances debugging information in Cmm terms. This was driven both by manually examining the debugger's behaviour and also by a report received from a user regarding substandard DWARF location information.
2019-03-13 15:40:04 +00:00
Mark Shinwell 765c4e659f Whitespace 2019-03-08 16:51:40 +00:00
Mark Shinwell 24e12ad9e1 Propagate environments further in Selectgen 2019-03-08 13:06:31 +00:00
Vincent Laviron 98654c77de Remove loop constructors in Cmm and Mach 2019-02-19 17:00:38 +01:00
Daniel Bünzli a7afd89003 s/string_of_int/Int.to_string/g 2018-11-07 13:52:02 +01:00
Daniel Bünzli f0aa5a1707 Avoid opening Misc in asmcomp/selectgen.ml
This shadows the standard Stdlib module.
2018-11-07 13:51:08 +01:00
Mark Shinwell 72378c0ad1
Phantom let support in Cmm (#2070) 2018-10-16 07:20:56 +01:00
Mark Shinwell dae65dacda
Rename Mach.Ialloc record field from _words_ to _bytes_ and fix logic in a couple of places (#2074) 2018-10-02 16:00:03 +01:00
Mark Shinwell 2b5f13c913 GPR#2056 (Backend_var) 2018-09-28 17:59:01 +02:00
Thomas Refis b134588f28 ident: split Local into Local and Scoped
Also rename [create] into [create_scoped] and [create_var] into
[create_local].
2018-09-21 11:47:44 -04:00
Thomas Refis 67f29d1a18 ident: add an explicit scope field
- Ident.create now takes a scope as argument
- added Ident.create_var to use when the scope doesn't matter
- the current_time and the current_level are unrelated as of this
  commit. But one has to remember to bump the level when creating new
  scopes.
2018-09-21 11:47:42 -04:00
Gabriel Radanne 1be47bf7ab Just some tbl things. (#1699) 2018-07-23 13:19:41 +01:00
David Allsopp 02a385f540 GPR#1833 check-typo compliance 2018-07-01 10:55:30 +01:00
Simon Fowler ace6af8fc7 Allow non-val payload types in CMM Ccatch (#1833)
Summary
-------
This patch adds explicit type annotations for Ccatch payloads in the CMM
IR, thus supporting payloads which are not of type `val`.

Rationale
---------
While CMM generated from OCaml source will always generate payloads of type
`val`, this is not the case when targeting CMM to compile from a different
language. As a concrete example, I am currently targeting the CMM backend for
compilation of WebAssembly, and require `float` payloads. Additionally, @mshinwell
has noted that such an extension will be useful for flambda2. As a result, this
patch will increase the applicability of the CMM IR as a compilation target.

Updates
-------

25/06/2018: Incorporate review comments by @xclerc

Design
------
The design of the patch is as follows:

  1. Add explicit type annotations to Ccatch handlers. Specifically,
        ```Ccatch (int * (Ident.t list) * expression)```
     becomes
        ```Ccatch (int * (Ident.t * machtype) list * expression)```

  2. By default, in `cmmgen`, select `typ_val` as the `machtype`

  3. Select an appropriate register using the type annotation in `selectgen`,
     instead of defaulting to `typ_val`

  4. Test updates:
     - Update the CMM parser and pretty-printer to require annotations on Ccatch
       handlers
     - Update the existing CMM tests to add the required annotations
     - Add new tests which require the use of floating-point registers, for
       which the compiler would generate invalid ASM prior to this patch

Since all OCaml code will use `typ_val` as before in `cmmgen` and therefore
`selectgen`, compilation for OCaml programs will be identical.
2018-06-29 00:08:50 +02:00
Damien Doligez e52f39cbe9 Revert "Replace constant pointers by regular integers (#1580)"
This reverts commit 022051e7bd.
2018-04-06 16:09:53 +02:00
Pierre Chambart 69fb40bb55 Disable CSE for the initialization function (#1455) 2018-03-15 12:59:51 +00:00
Vincent Laviron 022051e7bd Replace constant pointers by regular integers (#1580) 2018-03-15 09:57:53 +00:00
Leo White 1671e5a3af Treat negated float comparisons more directly (#1487)
* Add float comparison test

* Treat negated float comparisons more directly

* Add Changes entry
2018-02-28 14:19:46 +01:00
Mark Shinwell c1024f161c Fixes for out-of-range Ialloc 2017-07-31 15:10:47 +01:00
Mark Shinwell ea5fa10bac Fix evaluation order problem (#966) 2017-02-15 11:14:10 +00:00
Mark Shinwell d2281a2377 Fix Spacetime compilation (#984) 2016-12-27 12:39:41 +00:00
Frédéric Bour d1eecfc604 Distinguish root and heap values in Lambda.initialization (#673) 2016-12-27 11:43:36 +00:00
Pierre Chambart cadd4c5ba1 Add a recursive flag on the Ccatch construct
When this flag is Nonrecursive, we can avoid iterating on
various passes. This makes exponential time cases more unlikely.
2016-10-28 13:03:59 +02:00
Mark Shinwell 2e3b6ba249 code review 2016-10-28 13:03:59 +02:00
Pierre Chambart c3d056de68 Change Cmm Ccatch construct to allow recursive cases 2016-10-28 13:03:59 +02:00
Mark Shinwell 975f2e522d More debuginfo in Cmm 2016-10-12 14:13:05 +01:00
Mark Shinwell cd0bd8aa73 Spacetime: a new memory profiler (#585) 2016-07-29 15:07:10 +01:00
François Bobot bb4a1b4f5d Specialize raise_kind after cmmgen
since the semantic changed. There is no need to check Clflags.debug
   anymore Raise_withtrace, means that traces must be computed (if the
   runtime boolean is true).
2016-07-28 15:29:50 +02:00
Mark Shinwell c843ca0691 Labels after calls, call GC points and checkbound points (again) (#660) 2016-07-06 11:44:00 +01:00