Commit graph

1767 commits

Author SHA1 Message Date
Daniel Kochmański
f195f7d574 cmpc: get rid of an undocumented and unused code path for FFI:CLINES
We've supported syntax for clines that allowed inlining Lisp objects when they
were prepended with @, for example (ffi:clines "#include @my-variable"); that
said I have not seen a single use of this syntax and it compilcated the logic
(the read object needed to land in the data segment during the second pass).
2023-09-25 14:35:14 +02:00
Daniel Kochmański
5a8f6780b8 cmpc: sysfun: add default inline definitions for printer functions
This resolves a todo in cmpc-opt-printer.lsp:

    ;;; TODO move mundane inliners to the sysfun database.

We leave only the optimizer for CL:PRINC that is not mundane.
The default C inliner for CL:PRINC is also defined in the sysfun database.
2023-09-25 14:35:14 +02:00
Daniel Kochmański
6d60cf294a cmpc: move the c-inliner fully to the cmpc backend module 2023-09-25 14:35:14 +02:00
Daniel Kochmański
49668f8dda cmpc: %def-inline: remove an option :inline-or-warn 2023-09-25 14:35:14 +02:00
Daniel Kochmański
2d0ffd53b2 cmpc: remove the safety-level qualifier :SAFE from the inliner
This inlining qualifier was commented to be applied only in the safe code, but
in the code it was applied all the same as :always (as a second choice after the
unsafe optimizer). Moreover there was only single sysfun that specified it.
2023-09-25 14:35:14 +02:00
Daniel Kochmański
e32b5d5e1f cmp: cmpopt-cons: remove expand-simple-optimizer (rplaca, rplacd)
RPLACA and RPLACD macros were the only clients of SIMPLE-OPTIMIZER-FUNCTION and
said optimizer took more code than explicitly writing twice the expansion as the
compiler macro.
2023-09-25 14:35:14 +02:00
Daniel Kochmański
c9ced2504d cmp: simplify the ast node CL:FUNCTION
The old AST node for CL:FUNCTION accounted for a possibility that a lambda is
passed, although c1function (the only function that produces this node),
discarded that possibility in favor expanding lambda to explicit FLET.
2023-09-25 14:35:14 +02:00
Daniel Kochmański
8e3f1f0a36 cmp: add a kludge for C1CONSTANT-VALUE using *OPTIMIZABLE-CONSTANTS*
This commit will be reverted soon, so it is not squashed onto the AST node
separation for variables and locations.
2023-09-25 14:35:14 +02:00
Daniel Kochmański
816c08340b cmp: have separate AST nodes for variables and locations
That will aid moving inline optimizations to the backend.
2023-09-25 13:13:27 +02:00
Daniel Kochmański
faebc7b266 cmp: enforce valid shape of si:function-block-name delcaration
Also fix a declaration in clos::make-raw-lambda function.
2023-09-25 13:13:27 +02:00
Daniel Kochmański
33df93da14 cmp: supply an explicit value for the empty location
Previously we've passed a fixnum 0 that meant the empty loc. Even earlier
probably NIL was used for that purpose. That have lead to an accidental
complexity where fixnums could not be stored in the value vector.
2023-09-25 13:13:27 +02:00
Daniel Kochmański
592a2cca17 cmp: expand-typep: fix broken (complex type) expansion
This expansion did not account for the object not being a number. In that case
REALPART errored in the compiled code. Example:

    (typep *package* '(complex float))
2023-09-25 13:13:27 +02:00
Daniel Kochmański
338613fe07 cmp: add a comment describing fcall and mcall purpose 2023-09-15 09:35:43 +02:00
Daniel Kochmański
2a631151fd cmp: mcall: implement the type propagation, make similar to fcall
While there is less we can doc compared FCALL, we still can infer the function
type and propagate it. Both AST nodes FCALL and MCALL accept now the same set of
arguments and MCALL has a new type propagator.
2023-09-15 09:35:40 +02:00
Daniel Kochmański
d014360836 cmp: cosmetic: cmppass1-call: add a predicate lambda-form-p 2023-09-11 18:11:58 +02:00
Daniel Kochmański
9f2da346bb cmp: fcall: more through type propagation
We do the type propagation in the appropriate pass and in order. We also ensure
that all arguments have the type propagated and (when applicable) narrowed.
2023-09-11 18:11:58 +02:00
Daniel Kochmański
6e68703c38 cmp: c1call: remove the test for c-arguments-limit
We don't need this special clause anymore because FCALL caters to this edge case
that is specific to the C backend.
2023-09-11 18:11:58 +02:00
Daniel Kochmański
da985b945b cmp: merge AST nodes CALL-LOCAL and CALL-GLOBAL into FCALL
This yields simpler AST that is easier to reason about. One of the benefits is
that we propagate argument types for FCALL disregarding of whether it is a
short or long call.
2023-09-11 18:11:58 +02:00
Daniel Kochmański
29a37c339e cmp: merge AST nodes CL:FUNCALL and FCALL into the latter
The limit imposed on the number of arguments in the call is resolved in the
second pass. We get rid of the AST node CL:FUNCALL.
2023-09-11 18:11:58 +02:00
Daniel Kochmański
526663e069 cmpc: introduce a new loc CALL-STACK and simplify C2FCALL, C2MCALL 2023-09-11 18:11:58 +02:00
Daniel Kochmański
5e5db8be30 cmp: remove the special operator with-stack and company
These operators were a hack that reached to the code generation from the AST
transformation pass encoding things that were clearly targetting the c language.

Recent commits remove uses of this operator and it is no longer needed.
2023-09-11 18:11:55 +02:00
Daniel Kochmański
78d1add899 cmp: cmppass1-call: don't use with-stack for multiple value calls
WITH-STACK depends on FFI:C-INLINE so it can't be present in the first pass for
standard operators. As a bonus disassembled result is less obfuscated.
2023-09-11 16:54:21 +02:00
Daniel Kochmański
fb95debd48 cmp: cmppass1-call: don't use with-stack for unoptimized long calls
WITH-STACK depends on FFI:C-INLINE so it can't be present in the first pass for
standard operators. As a bonus disassembled result is less obfuscated.
2023-09-11 16:54:21 +02:00
Daniel Kochmański
a35b89866a cmp: cmppass1-call: refactor first pass operators funcall and apply 2023-09-11 16:54:21 +02:00
Daniel Kochmański
18e1a69ba7 cmp: add a new c1form mv-prog1
We should start with high-level ast and then we lower it depending on the
backend. Having a Common Lisp backend should be a good test. WITH-STACK does
not belong to the AST and this is the first commit that removes its usage.

This commit implements MULTIPLE-VALUES-PROG1 by means of adding a new AST type
instead of transforming to a call of WITH-STACK.
2023-09-11 16:54:21 +02:00
Daniel Kochmański
167a935eee cmp: move type propagators for arrays to a separate file
cmpprop is used to propagate types among forms while cmpprop-array contains
propagators for arrays.
2023-09-11 16:54:21 +02:00
Daniel Kochmański
0a739fa5ac cmp: cosmetic changes in cmparray 2023-09-11 16:54:21 +02:00
Marius Gerbershagen
d7330ae762 cmp: fix inline expansion of princ
Has to return the object to be printed.
2023-08-03 15:13:30 +02:00
Marius Gerbershagen
7761d0b27a cmp: fix coercion between lisp types and representation types
Signal an error if there is no function that coerces some C variable
c_object to a lisp object instead of emitting invalid C code like
`ECL_NIL(c_object)`.

Moreover, fix the table of representation types:

:object needs no coercion which is correctly implemented by using an
empty string for the function name.

:void should not use `nil` as the lisp type since nil is a subtype of
fixnum which lead to us previously choosing "ecl_fixnum" as the
coercion function in unsafe code. By using `t` as the lisp type we
avoid this.
2023-08-03 15:09:37 +02:00
Marius Gerbershagen
0885862e40 cmp: improve handling of potential miscompilations
Abort with a useful error message instead of trying to continue on.
2023-07-01 16:45:21 +02:00
Daniel Kochmański
29fb6009e4 cmp: disassemble: fix a regression
The function disassemble will end up in the backend too eventually, although for
now it is defined in cmpmain. Recently we've moved backend-specific variables to
the code generation pass, but disassemble still relies on that environment.
2023-06-27 09:18:02 +02:00
Marius Gerbershagen
99317ee401 cmp: fix inline expansion of (copy-readtable nil) 2023-06-25 16:08:41 +02:00
Marius Gerbershagen
48f42d8cb0 cmp: minor changes to optimizations for car/cdr
si:cons-car/cdr implement car and cdr on conses without type checks.

Replace those macros by functions and fix the previously ignored
inline definitions. This allows using si:cons-car/cdr in the
interpreter while keeping the code generated the native compiler the
same.

In the future we should probably improve the type inferencer to handle
these optimizations automatically and get rid of si:cons-car/cdr
alltogether.
2023-06-25 15:53:40 +02:00
Marius Gerbershagen
33aca4a57b cmp: don't output invalid C code if dead code elimination fails 2023-06-24 19:07:10 +02:00
Marius Gerbershagen
639d5f3ad3 cmp: fix errors in handling compound function types
These are valid in type declarations but must not be passed on as
arguments to typep.

Moreover, we were sometimes incorrectly simplifying code like

(typep x (function ...))

to (functionp x) in the native compiler.
2023-06-18 13:08:12 +02:00
Marius Gerbershagen
9084ab97bd cmp: remove duplicate type assertion handling 2023-06-18 11:12:45 +02:00
Daniel Kochmański
e10c2010d4 cosmetic: update headers 2023-06-11 10:40:21 +02:00
Daniel Kochmański
95e7bdd7d7 cmpc: change compiler-macro cl:float to c-inliner macro
The compiler macro expanded float to c-inline.
2023-06-11 10:40:21 +02:00
Daniel Kochmański
4a1902658c cmpc: move sysfun to the cxx backend
sysfun declarations revolve strictly around c function inlining that is specific
to the C backend.

Moreover be more explicit about symbol packages and check feature-conditioned
inlines at runtime (not at readtime) in case that we construct the inline
information for a cross-compiled target. This should be further improved.
2023-06-11 10:40:18 +02:00
Daniel Kochmański
8bb0b99499 cmpc: move c-inline expansions of PRINC to the backend
Instead of using DEFINE-COMPILER-MACRO we implement them with DEFINE-C-INLINER
because these optimizations are backend-specific.
2023-06-06 22:34:08 +02:00
Daniel Kochmański
c4b32c5905 cmpc: move produce-inline-loc and co to cmpc-inliner
These operators are used across different optimizations and clearly do not
belong to a specific pass.
2023-06-06 15:02:51 +02:00
Daniel Kochmański
ff67ebfa1a cmpc: move wt "call" routines to cmpc-wt 2023-06-06 14:48:58 +02:00
Daniel Kochmański
ae6614ebba cmpc: move variables related to code generation to the backend 2023-06-06 14:48:58 +02:00
Daniel Kochmański
220b7c7363 cmpc: move constant and inlining c/c++ optimizations
Move appropriate files to the C/C++ backend.
2023-06-06 14:48:58 +02:00
Daniel Kochmański
03be475fb9 cmpc: clean up numeric optimizers and propagators
- merge bits and numeric optimizers in a single file
- move c/c++ optimizers to the backend
- move bits and numeric propagators to a separate file
2023-06-06 14:48:58 +02:00
Daniel Kochmański
1472bb18e6 cmpc: move c/c++ backend to a separate directory 2023-06-06 14:48:58 +02:00
Daniel Kochmański
e9f05ac85e cmp: c1constant-value: remove defunct parameter ONLY-SMALL-VALUES
After inclusion of the externalizable NAN values the parameter
':ONLY-SMALL-VALUES T' is the same as ':ALWAYS NIL' (the default).

That makes the the operator slightly easier to understand.
2023-06-06 14:48:58 +02:00
Daniel Kochmański
d62cf434c6 cmp: enable externalizing NAN 2023-06-06 14:48:58 +02:00
Daniel Kochmański
3565c89ca9 cmp: cosmetic: write (function ,foo) instead of #',foo 2023-06-06 14:48:58 +02:00
Daniel Kochmański
0321023572 cmp: propagate types in functions too
The propagator for FSET did not descend to the function object while the
propagator for LOCALS did (that was inconsistent). Also cmpmain called
P1PROPAGATE on *LOCAL-FUNS* before the second pass so that was no-op.
2023-05-24 15:49:06 +02:00