Commit Graph

732 Commits

Author SHA1 Message Date
David Nadlinger e77c7d1c39 compiler: Add inferencer support for array operations 2020-08-09 03:54:41 +01:00
David Nadlinger a9a975e5d4 language: Allow instantating TArray using bare ints 2020-08-09 03:54:41 +01:00
David Nadlinger dea3c0c572 compiler: Don't store redundant ndarray buffer length, match list layout
This adds `elt` to _TPointer and the ir.Offset IR instruction,
which is like GetElem but without the final load.
2020-08-09 03:54:41 +01:00
David Nadlinger cb1cadb46a compiler: Fix/test 1D array construction from generic iterables 2020-08-09 03:54:41 +01:00
David Nadlinger 38c17622cc compiler: Axis-wise iteration of ndarrays
Matches NumPy. Slicing a TList reallocates, this doesn't; offsetting
couldn't be handled in the IR without introducing new semantics
(the Alloc kludge; could/should be made its own IR type).
2020-08-09 03:54:41 +01:00
David Nadlinger c95a978ab6 compiler: Iteration for 1D ndarrays 2020-08-09 03:54:41 +01:00
David Nadlinger bc17bb4d1a compiler: Parametrize TArray in number of dimensions 2020-08-09 03:54:41 +01:00
David Nadlinger 632c5bc937 compiler: Add ndarray .shape access 2020-08-09 03:54:41 +01:00
David Nadlinger d882f8a3f0 compiler: Implement len() for ndarrays 2020-08-09 03:54:41 +01:00
David Nadlinger 575be2aeca compiler: Basic support for creation of multidimensional arrays
Breaks all uses of array(), as indexing is not yet implemented.
2020-08-09 03:54:41 +01:00
David Nadlinger 56010c49fb compiler/inferencer: Detect rectangular array()s
Still needs support through all the rest of the compiler, and
support for higher-dimensional arrays.

Alternatively, we could always assume ndarrays of ndarrays
are rectangular (i.e. ban array/list element types), and
detect mismatch at runtime. This might turn out to be
preferrable to be able to construct matrices from rows/columns.

`array()` is disallowed for no particularly good reason but
numpy API compatibility.
2020-08-09 03:54:41 +01:00
pca006132 3bfd372c20 compiler: linker discard local symbols.
Fixes exception backtrace problem for ARM.
2020-08-06 16:07:28 +08:00
David Nadlinger ae999db8f6 compiler: Revert function call lifetime tracking fix
This reverts commits f8d1506922
and cf19c9512d.

While the commit just fixes a clear typo in the implementation,
it turns out the original algorithm isn't flexible enough to
capture functions that transitively return references to
long-lived data. For instance, while cache_get() is special-cased
in the compiler to be recognised as returning a value of Global()
lifetime, a function just forwarding to it (as seen in the
embedding tests) isn't anymore.

A separate issue is also that this makes implementing functions
that take lists and return references to global data in user code
impossible, which central parts of the Oxford codebase rely on.

Just reverting for now to unblock master; a fix is easily designed,
but needs testing.
2020-07-30 16:40:39 +01:00
David Nadlinger f8d1506922 compiler: Fix lifetime tracking for function call return values
GitHub: Fixes #1497.
2020-07-28 00:33:28 +01:00
David Nadlinger 1c72585c1b compiler: Handle None-returning function calls used as values
GitHub: Fixes #1493.
2020-07-25 02:20:53 +01:00
David Nadlinger 57e759a1ed compiler: Consistently use llunit through llvm_ir_generator [nfc] 2020-07-25 02:20:52 +01:00
Sebastien Bourdeauducq 95807234d9 compiler: use binutils for ARM
This is mostly due to Windoze, where installing anything is a PITA and the LLVM tools won't be available soon.
2020-06-28 17:33:03 +08:00
Sebastien Bourdeauducq 85e92ae28c compiler: use more LLVM tools on ARM (#733) 2020-04-28 16:21:50 +08:00
Sebastien Bourdeauducq 140a26ad7e compiler: ld -> ld.lld 2020-04-28 16:07:26 +08:00
Sebastien Bourdeauducq 4228e0205c compiler: link with lld on ARM (#733) 2020-04-28 15:00:24 +08:00
Sebastien Bourdeauducq 251a0101a6 compiler: support disabling now-pinning 2020-04-26 12:38:43 +08:00
David Nadlinger d8c81d6d05 compiler: Other types microoptimisations
Interestingly enough, these actually seem to give a measurable
speedup (if small – about 1% improvement out of 6s whole-program
compile-time in one particular test case).

The previous implementation of is_mono() had also interesting
behaviour if `name` wasn't given; it would test only for the
presence of any keys specified via keyword arguments,
disregarding their values. Looking at uses across the current
ARTIQ codebase, I could neither find a case where this would
have actually been triggered, nor any rationale for it.

With the short-circuited implementation from this commit,
is_mono() now checks name/all of params against any specified
conditions.
2020-01-01 08:49:19 +00:00
David Nadlinger 2c34f0214b compiler: Short-circuit Type.unify() with identical other type
This considerably improves performance; ~15% in terms of total
artiq_run-to-kernel-compiled duration in one test case.
2020-01-01 08:49:19 +00:00
David Nadlinger 8f518c6b05 compiler: Allow `None` in type hints
Similar to how Python itself interprets None as type(None),
make it translate to TNone in ARTIQ compiler type hints.
2019-12-19 09:36:45 +08:00
David Nadlinger 594ff45750 compiler: Revert support for `None` as `TNone`
This was mistakenly included in fb2b634c4a, and broke the test
case verifying that using None as an ARTIQ type annotation in fact
generates an error message.
2019-12-18 13:23:40 +00:00
David Nadlinger fb2b634c4a compiler, language: Implement @kernel_from_string
With support for polymorphism (or type erasure on pointers to
member functions) being absent in the ARTIQ compiler, code
generation is vital to be able to implement abstractions that
work with user-provided lists/trees of objects with uniform
interfaces (e.g. a common base class, or duck typing), but
different concrete types.

@kernel_from_string has been in production use for exactly
this use case in Oxford for the better part of a year now
(various places in ndscan).

GitHub: Fixes #1089.
2019-12-18 10:51:04 +08:00
David Nadlinger 611bcc4db4 compiler: Cache expensive target data layout queries
On one typical experiment, this shaves about 3 seconds (~25%)
off the overall kernel compilation time.

GitHub: Closes #1370.
2019-10-28 11:09:25 +00:00
David Nadlinger 5d7f22ffa4 compiler: Remove provision for unused four-parameter llptr_to_var() form [nfc]
`var_type` was presumably intended to convert to a target type,
but wasn't actually acted on in the function body (nor was it
used anywhere in the codebase).
2019-10-28 11:02:46 +00:00
Sebastien Bourdeauducq c03c35f375 Revert "compiler: armv7-unknown-linux-gnueabihf -> armv7-linux-gnueabihf"
rustc insists on -unknown.

This reverts commit cf47fa44d8.
2019-08-26 11:23:00 +08:00
Sebastien Bourdeauducq cf47fa44d8 compiler: armv7-unknown-linux-gnueabihf -> armv7-linux-gnueabihf 2019-08-26 11:12:49 +08:00
Sebastien Bourdeauducq 98cd9a539c compiler: support Cortex A9 target 2019-08-26 10:46:22 +08:00
David Nadlinger cdaf554736 compiler: Implement abs() for scalars
GitHub: Fixes #1303.
2019-04-13 13:39:16 +08:00
David Nadlinger 88fd5c8440 compiler: Fix crash in escape analysis for assigning string literals 2019-03-31 17:10:27 +01:00
David Nadlinger 990e0b7dd9 compiler: Fix comparison of tuples of lists 2019-03-31 17:10:27 +01:00
David Nadlinger baf102dbb2 compiler: Fix comparison of nested lists 2019-03-31 17:10:27 +01:00
David Nadlinger f9af058b96 compiler: Quote tuples as TTuple values
Previously, they would end up being TInstances,
rendering them useless.
2019-03-31 23:40:21 +08:00
whitequark d6eb2b023a compiler: monomorphize casts first, but more carefully.
This reverts 425cd7851, which broke the use of casts to define
integer width.

Instead of it, two steps are taken:
  * First, literals are monomorphized, leading to predictable result.
  * Second, casts are monomorphized, in a top-bottom way. I.e.
    consider the expression `int64(round(x))`. If round() was visited
    first, the intermediate precision would be 32-bit, which is
    clearly undesirable. Therefore, contextual rules should take
    priority over non-contextual ones.

Fixes #1252.
2019-02-07 06:24:32 +00:00
whitequark 425cd7851e compiler: first monomorphize ints, then casts.
Fixes #1242.
2019-01-12 13:40:12 +00:00
whitequark 49682d0159 Improve Python 3.7 compatibility.
async is now a full (non-contextual) keyword.

There are two more instances:
   - artiq/frontend/artiq_client.py
   - artiq/devices/thorlabs_tcube/driver.py

It is not immediately clear how to fix those, so they are left for
later work.
2019-01-12 13:17:59 +00:00
Sebastien Bourdeauducq 421834fa3e compiler: document Target.little_endian 2018-12-02 19:07:18 +08:00
Sebastien Bourdeauducq 981a77834a compiler: use default triple to determine data_layout for JIT 2018-12-02 18:52:13 +08:00
Sebastien Bourdeauducq d931967e5c fix previous commits 2018-12-02 18:32:03 +08:00
Sebastien Bourdeauducq dd03fdfd1a typo 2018-12-02 18:26:54 +08:00
Sebastien Bourdeauducq 8940009e1a compiler: pass data_layout string to llvm.create_target_data before determining endianness 2018-12-02 18:26:19 +08:00
Sebastien Bourdeauducq 2e66788c6c compiler: support little endian target when storing now 2018-12-02 17:40:34 +08:00
Sebastien Bourdeauducq 7e14f3ca4e compiler,gateware: atomic now stores 2018-12-02 05:06:46 +08:00
Sebastien Bourdeauducq 8caea0e6d3 gateware,runtime: optimize RTIO kernel interface further
* now pinning (TODO: atomicity)
* for inputs, merge request and timeout registers
2018-11-08 18:29:24 +08:00
David Nadlinger 2463e5667d compiler: Fix attribute writeback with skipped fields
offset wasn't advanced for skipped fields previously,
leading to memory corruption/unaligned accesses at runtime.
2018-08-14 13:34:32 +01:00
whitequark fab6e5cdff compiler: skip functional values in attribute writeback.
Fixes #1088.
2018-08-10 12:02:49 +00:00
whitequark 93af5d2a03 compiler: handle async RPC as last statement in try block.
Fixes #1107.
2018-08-07 07:06:53 +00:00
whitequark a74958f01f ksupport: raise RuntimeError on reraise with no inflight exception.
Fixes #1123.
2018-08-07 05:53:13 +00:00
David Nadlinger 768b970deb Fixup 4359a437 (tuples of lists), add regression tests 2018-07-10 01:18:51 +01:00
David Nadlinger 4359a43732 compiler: Indirection status of TTuple depends on elements
For instance, TTuple(TList(TInt32())) has indirections, while
TTuple(TInt32()) does not.

This fixes memory corruption with RPCs that return tuples of lists.

Signed-off-by: David Nadlinger <code@klickverbot.at>
2018-07-09 18:49:50 +08:00
Sebastien Bourdeauducq 9153c4d8a3 use tokenize.open() to open Python source files
Fixes encoding issues especially with device databases modified in obscure editors.
2018-07-07 17:04:56 +08:00
whitequark 9260cdb2e8 compiler: support conversion of list to bytearray and bytes.
Fixes #1077.
2018-06-21 00:40:45 +00:00
whitequark 38dac16041 compiler: don't crash when quoting builtin functions.
Fixes #1051.
2018-06-05 23:27:23 +00:00
whitequark db4d1878d3 compiler: remove debug print. 2018-05-25 09:37:18 +00:00
whitequark fbf2c9a2fb compiler: hoist loads of kernel invariants to function entry block.
Addresses intraprocedural cases of #1007.
2018-05-25 02:18:13 +00:00
whitequark 12d1b9819c compiler: handle direct calls to class methods.
Fixes #1005.
2018-05-25 02:02:18 +00:00
whitequark ce3c8fcd3e compiler: add source location to SSA arguments.
Fixes #1006.
2018-05-22 18:14:14 +00:00
whitequark 9b4ad8b5af compiler: implement local variable demotion. 2018-05-19 17:05:34 +00:00
whitequark fd110e9848 compiler: sort predecessors in IR dump output.
Makes diffs more useful.
2018-05-19 17:02:08 +00:00
whitequark dc1c4ebf1d compiler: use ARTIQ_IR_NO_LOC variable to control IR dump output.
Useful e.g. in tests or for running diff on irgen output.
2018-05-19 17:02:08 +00:00
whitequark 21a0f26cd1 compiler: do not emit nonstandard !unconditionally* LLVM metadata.
This metadata was added by an LLVM patch that was removed because
it was unsound.
2018-05-19 16:58:03 +00:00
whitequark 3b61b7c30b compiler: fix tests after 4d06c1d8. 2018-05-16 21:53:53 +00:00
whitequark 917a4185eb Unbreak 9dc7efef. 2018-05-05 03:00:30 +00:00
whitequark 9dc7efefe4 compiler: transparently handle Windows newlines in RunTool. 2018-05-05 01:43:00 +00:00
whitequark f7e08ec46b Unbreak f35f1001. 2018-04-28 01:03:08 +00:00
whitequark f35f100110 compiler: don't crash printing locations of specialized functions.
Fixes #987.
2018-04-28 00:49:25 +00:00
whitequark 58967f14fd compiler: do not try to re-coerce fully coerced numerics. 2018-04-21 18:25:52 +00:00
whitequark b4e3c30d8c compiler: desugar x != y into not x == y (fixes #974). 2018-04-20 12:20:45 +00:00
whitequark 4b5a78e231 compiler: do not pass files to external tools while they are opened.
This fixes access violations on Windows that are present both with
input and output files. For some reason, Cygwin-compiled binutils
did not exhibit this problem, but MSYS-compiled binutils do.

Fixes #961.
2018-03-15 22:21:29 +00:00
whitequark 86ceee570f compiler: reject calls with unexpected keyword arguments.
Fixes #924.
2018-02-21 11:37:12 +00:00
whitequark 34a5445802 compiler: don't die if addr2line cannot extract line from backtrace.
Fixes #885.
2018-01-08 21:53:04 +00:00
whitequark 4d915ad15b compiler: do not permit str(...). (#878) 2017-12-27 03:10:50 +00:00
whitequark 355acb5e13 compiler: fix typo in a0a2650f. 2017-12-26 21:55:22 +00:00
whitequark 9aec64093b compiler: do not ever emit !tbaa on invoke instructions. 2017-12-26 21:35:08 +00:00
whitequark b31b59f7ca compiler: update for llvmlite 0.20.0. 2017-12-26 16:25:19 +00:00
whitequark a0a2650fca compiler: do not use invoke for calls to nounwind ffi functions.
Otherwise, declarations such as:

  @syscall(flags={"nounwind", "nowrite"})
  def foo(...):

trip an LLVM assert because the invoke instruction and the !tbaa
metadata are no longer compatible since LLVM 4.0.
2017-12-26 16:24:57 +00:00
whitequark c939c6183e Update to LLVM 4.0. 2017-12-26 14:09:17 +00:00
Sebastien Bourdeauducq 4387b0be1e clean up rtio_log 2017-11-03 00:52:53 +08:00
whitequark ca254ec55e compiler: disallow op= on mutable lists only (fix #835).
This only really applies to lists since those use fat pointers.
`x.y += z` is fine.
2017-10-02 07:21:14 +00:00
whitequark e59b301a3b compiler: disallow op= on mutable values (fix #835).
In general, we can't reallocate a value in earlier stack frames,
or fixup references to it. This mainly impacts lists.
2017-10-02 01:55:26 +00:00
whitequark f86744c65c compiler: implement ~ operator (fix #836). 2017-10-01 19:33:18 +00:00
whitequark 843786a091 compiler: minor intrinsic refactoring. 2017-10-01 19:00:10 +00:00
whitequark 491c7ef898 compiler: correct semantics of floating point % operator (fix #830). 2017-10-01 18:57:45 +00:00
whitequark 62f2693e36 compiler: correct semantics of integer % operator (#830). 2017-10-01 18:32:57 +00:00
whitequark ea7549cfa4 compiler: coerce `while` condition to bool.
Fixes #768.
2017-07-01 18:59:07 +00:00
whitequark f7254dd3ce compiler.validators.constness: take AugAssign into account. 2017-06-09 07:31:08 +00:00
whitequark ad2ee714c2 compiler: do not permit iterating str values.
This currently breaks badly on UTF-8, and doesn't even return
a value of a correct type.
2017-06-09 07:29:31 +00:00
whitequark 4e7493843a compiler: Constness is a validator, not analysis. 2017-06-09 07:29:31 +00:00
whitequark 5d841d08e9 compiler: do not permit mutation of bytes values (#714). 2017-06-09 07:29:28 +00:00
whitequark 284382b1f5 compiler: add support for bytearray values in RPC (#714). 2017-06-09 07:15:25 +00:00
whitequark 9ed4e9c1cd compiler: add support for printing of bytearray values (#714). 2017-06-09 07:15:25 +00:00
whitequark e9564b15c8 compiler: add support for bytearray type (#714). 2017-06-09 07:15:24 +00:00
whitequark 5b4fde30a8 compiler: unbreak subscripts for bytes values (#714). 2017-06-09 07:10:48 +00:00
whitequark 66a683f583 compiler: add support for bytes values in RPC (#714). 2017-06-09 07:10:48 +00:00
whitequark 778e7dc2ab compiler: add support for concatenating bytes values (#714). 2017-06-09 07:10:48 +00:00
whitequark 7b2da5294f compiler: add support for printing of bytes values (#714). 2017-06-09 07:10:48 +00:00
whitequark dba4e1a28b compiler: add support for bytes type and b"x" literals (#714). 2017-06-09 07:10:48 +00:00