Commit Graph

1508 Commits (master)

Author SHA1 Message Date
jacobly0 8a46d76bf9
Fix mergeable section flags and use .rodata.cst16 where appropriate (#9981)
On x86-64 ELF, the `.rodata.cst8` section was incorrectly used.
2020-10-18 13:57:53 +02:00
Greta Yorsh 855c13cd6e
ability to restart compilation from .cmir-linear IR files 2020-10-13 15:07:13 +02:00
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
Xavier Leroy 86c8a98f3c
Merge pull request #9948 from nojb/remove_spacetime
The Spacetime memory profiler is not going to be supported in Multicore OCaml, and  is already broken by some of the related changes in OCaml 4.12.  The core development team decided to remove Spacetime support from OCaml 4.12.
2020-10-09 14:43:23 +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
Greta Yorsh 04bceec6cc
Save Linear IR before emit (#8939)
* Save IR before emit

* Update .depend for linear_format

* Test for -save-ir-after command-line option

* Address review comments

* Add Changes entry
2020-10-07 11:32:40 +01:00
Vincent Laviron eb342da8a9
Ensure all structured constants are registered (#9940)
Allocated constants from other compilation units were not registered, resulting in missed opportunities for unboxing FP and boxed-integer constants.
2020-10-06 15:19:51 +02:00
Stephen Dolan e87b7ce437
Use Cmm_helpers for boxed int arithmetic (#9959)
This way, Cmm's arithmetic optimisations also apply to boxed integer arithmetic.
2020-10-05 19:19:35 +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 86fbea7fc3 Back-ends for 64-bit platforms do not need to be compilable on a 32-bit host
This commit simplifies a few integer constants that were obfuscated so
as to pass compilation on a 32-bit host, as "make check_all_arches"
would do if ran on a 32-bit host.  However, "make check_all_arches"
does not run on 32-bit hosts, unlike what is claimed in comments.

More generally, 32-bit hosts are no longer used for developing OCaml and
will not be used for cross-compilation.  So, let's not complicate the
back-ends unnecessarily.
2020-09-16 11:52:26 +02:00
Xavier Leroy cc25ceaaec ARM64: revised generation of ADD/SUB/CMP immediate
- Support a wider range of immediate values for ADD and SUB,
  using two instructions when needed (add/sub middle 12 bits then low 12 bits).

- Do not rely on the assembler to convert CMP immediate negative to
  CMN immediate.
2020-09-16 11:52:26 +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
David Allsopp c9d5294b78 Fix check-typo sins 2020-09-11 15:01:14 +01:00
Nicolás Ojeda Bär 6db41e4816
riscv: fix register usage (#9890) 2020-09-08 09:55:19 +02:00
Greta Yorsh 2bb2bde74c
Prologue size should not depend on stack_offset (power, arm64) (#9083)
* Prologue size does not depend on stack_offset (power, arm64)

Define `initial_stack_offset` of a function, independently
of stack_offset, and use it to compute both frame_size and
prologue_size.
2020-09-03 13:26:00 +02:00
Xavier Leroy 4c1654f135
z Systems: subtract immediate has its own range of valid immediate values (#9860)
Because it is turned into add immediate opposite in emit.mlp.
2020-08-26 09:23:44 +02:00
Stephen Dolan b735f187ac
Avoid Cconst_natint where Cconst_int will do (#9838)
Cconst_int generates better code, as it hits the instruction
selector's cases for small immediates.
2020-08-25 16:27:11 +01:00
Sébastien Hinderer 24744e8dd8 cehck-typo 2020-07-30 10:23:17 +02:00
Xavier Leroy a0a1ba4f1e
Merge pull request #9699 from EduardoRFS/trunk-ios
Add support for iOS and macOS on ARM64
2020-07-28 16:40:55 +02:00
Fourchaux 44e6cf4e0f
typos (#9806) 2020-07-28 12:22:03 +01:00
EduardoRFS 69d4ab80d0 arm64: use Arch.macosx instead of is_macosx
Also remove the duplicated declaration from proc.ml and emit.mlp

Co-authored-by: Xavier Leroy <xavier.leroy@college-de-france.fr>
2020-07-25 08:38:11 +00:00
EduardoRFS 9a98d40b86 arm64: add reference to Apple ARM64 ABI 2020-07-25 08:37:39 +00:00
EduardoRFS 8c38ac6bf6 arm64: support ios shared library
* the stub on iOS also saves x8 and x9
* use x8 for ADDITIONAL_ARG
* use only 8 regs for calling args
2020-07-25 08:37:39 +00:00
iOS Porting Team d189dcef62 arm64 emitter: support apple variant of assembler 2020-07-25 08:36:23 +00: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 ed8f3b427c ARM64 back-end: support the iOS/macOS ABI for calling external C functions
Unboxed arguments of type `int32` that are passed on the stack
are passed in 32-bit words instead of 64-bit words as in the AAPCS64 ABI.

To support this, we introduce a new specific operation, `Imove32`,
that compiles down to 32-bit moves or 32-bit stack loads or 32-bit
stack stores.

In the Selection pass, method `insert_move_extcall_arg`,
we generate `Imove32` instructions when required, i.e. if the
argument is an unboxed `int32` and needs to be passed on stack.

We then update `Proc.loc_external_arguments` to use 32-bit stack words
for `int32` arguments.
2020-07-24 17:39:27 +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
David Allsopp e6ab329541 Don't call the archiver/librarian for empty .cmxa 2020-04-22 14:56:02 +01:00
David Allsopp 793cd86785 Allow linking empty .cmxa files on MSVC
MSVC .lib format doesn't support having no .obj files in the library, so
ocamlopt -o foo.cmxa -a generates foo.cmxa but not foo.lib (there's no
error from the Microsoft Linker). The resulting foo.cmxa is unlinkable,
since OCaml passes foo.lib on to the linker.

This patch relaxes the requirement for foo.lib if the .cmxa contains no
units.
2019-10-03 10:44:54 +01:00
Xavier Leroy 7f5a137972 New representation of closures, native-code compilation
In code that builds closures, instead of the old arity field,
produce a closure information field encoding arity + position of environment.
2020-06-05 17:46:58 +02:00
Stephen Dolan 0d44a6cfe6 Remove Const_pointer from Lambda and Clambda (#9585)
Lambda and Clambda distinguish Const_int from Const_pointer only so
that they can pass the information to Cmm. But now that that
Const_pointer is gone from Cmm (#9578), there's no need for the
distinction in Lambda either.

This PR requires a bootstrap, because the .cmo format changes:
Lambda.structured_constant has one fewer constructor.  The bootstrap
is in the following commit.
2020-06-02 11:19:20 +02:00
Greta Yorsh 6cb283b1d8 Move float compare from cmmgen to cmm_helpers 2020-05-27 16:59:15 +01:00
Greta Yorsh 8fce17d902 Bind arguments of integer and float compare in cmmgen 2020-05-27 14:49:35 +01:00
Stephen Dolan 9e09fde735
Avoid creating ill-formed blocks in Cmm letrec (#9577)
Use "1" (integer 0) as filler value instead of "0" (null pointer).

Fixes: 7718
2020-05-25 10:11:45 +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
David Allsopp b6c8b35e2d
Make -flarge-toc the default for PowerPC (#9557)
Introduce -fsmall-toc in order to access the previous behaviour and
document both options in the manual and ocamlopt manpage.
2020-05-13 18:23:37 +02:00
Xavier Leroy ea6896f9f1 Update C calling conventions to the RISC-V ELF psABI
The original implementation of loc_external_arguments and
loc_external_results was following an older ABI,
where an FP argument passed in an FP register "burns" an integer register.

In the ELF psABI, integer registers and FP registers are used independently,
as in the OCaml calling convention.  Plus, if all FP registers are used
but an integer register remains, the integer register is used to pass
the next FP argument.

Fixes: #9515
2020-04-30 16:20:46 +02:00
Xavier Leroy 16794b9405 Support FP reg -> int reg moves
Using instruction fmv.x.d.

This is necessary to implement the ELF psABI calling conventions,
whereas some FP arguments may have to be passed in integer registers.
2020-04-30 16:20:46 +02:00
Stephen Dolan 0040c5d783 Print function names (derived from Lambda.scoped_location) in backtraces
Function names now appear in backtraces and are available via Printexc.
2020-04-27 12:58:53 +01:00
Stephen Dolan 2986beaa78 Replace Location.t with Lambda.scoped_location in Lambda code
This commit threads scopes through translation from Typedtree to
Lambda, extending the scopes when entering functions, modules,
classes and methods.
2020-04-27 12:58:53 +01:00
Nicolás Ojeda Bär 8f3833c4d0
Add RISC-V native-code backend (#9441)
This is a port of ocamlopt for the RISC-V processor in 64-bit mode.
2020-04-24 16:04:50 +02:00
Xavier Leroy 83598da1ab
Merge pull request #9392 from stedolan/visit-once
Visit registers at most once in Coloring.iter_preferred.
2020-04-22 09:38: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
Gabriel Scherer 702e34fbe5
Merge pull request #9463 from lthls/fix_int64_cmm_typ
Fix Cmm type of unboxed integers in Clet_mut
2020-04-20 11:34:15 +02:00
Nicolás Ojeda Bär ec6690fb53
x86 asm: handle unit names with special characters (#9465) 2020-04-19 11:17:00 +02:00
Vincent Laviron 8f006a366b Fix Cmm type of unboxed Int64 values in Clet_mut 2020-04-18 11:39:25 +02:00
Gabriel Scherer 9568154248
Merge pull request #9389 from Anukriti12/trunk
call_linker now returns exit_code for better user response on linking_error, fixes #7141
2020-04-17 17:05:56 +02:00