Commit Graph

759 Commits

Author SHA1 Message Date
David Nadlinger
778f2cf905 compiler: Fix numpy.full, implement for >1D 2020-08-09 23:46:45 +01:00
David Nadlinger
53d64d08a8 compiler: Fix multi-dim slice error message test, tweak wording 2020-08-09 23:14:56 +01:00
David Nadlinger
d35f659d25 compiler: Add additional math fns available from Rust libm 2020-08-09 20:09:43 +01:00
David Nadlinger
a39bd69ca4 compiler: Implement numpy.rint() using llvm.round() 2020-08-09 19:44:58 +01:00
David Nadlinger
8e262acd1e compiler: Slight array op implementation cleanup [nfc]
array_unaryop_funcs was never used; since the mangled names
are unique, a single dictionary would be nicer for overrides
anyway.s
2020-08-09 18:58:01 +01:00
David Nadlinger
33d931a5b7 compiler: Implement multi-dimensional indexing of arrays
This generates rather more code than necessary, but has
the advantage of automatically handling incomplete
multi-dimensional subscripts which still leave arrays
behind.
2020-08-09 17:08:43 +01:00
David Nadlinger
b00ba5ece1 compiler: Support explicit array(…, dtype=…) syntax 2020-08-09 17:08:43 +01:00
David Nadlinger
ad34df3de1 compiler: Support numpy.float
This would previously crash the compiler.
2020-08-09 17:08:43 +01:00
David Nadlinger
8783ba2072 compiler/firmware: RPCs for ndarrays 2020-08-09 17:08:43 +01:00
David Nadlinger
5472e830f6 compiler: Assume array()s are always rectangular 2020-08-09 03:54:42 +01:00
David Nadlinger
1c645d8857 compiler: Unbreak quoting of 1D ndarrays
Lists and arrays no longer have the same representation all
the way through codegen, as used to be the case.

This could/should be made more efficient later, eliding the
temporary copies.
2020-08-09 03:54:42 +01:00
David Nadlinger
df8f1c5c5a compiler: Annotate math functions nounwind/nowrite 2020-08-09 03:54:42 +01:00
David Nadlinger
cc00ae9580 compiler: Implement broadcasting of math functions 2020-08-09 03:54:42 +01:00
David Nadlinger
be7d78253f compiler: Implement 1D-/2D- array transpose
Left generic transpose (shape order inversion) for now, as that
would be less ugly if we implement forwarding to Python function
bodies for array function implementations.

Needs a runtime test case.
2020-08-09 03:54:42 +01:00
David Nadlinger
faea886c44 compiler: Implement array vs. scalar broadcasting 2020-08-09 03:54:42 +01:00
David Nadlinger
56a872ccc0 compiler: Insert array binop shape check in caller for location information 2020-08-09 03:54:42 +01:00
David Nadlinger
ef260adca8 compiler: Implement matrix multiplication
LLVM will take care of optimising the loops. This was still
unnecessarily painful; implementing generics and implementing
this in ARTIQ Python looks very attractive right now.
2020-08-09 03:54:42 +01:00
David Nadlinger
0da4a61d99 compiler: Fix method name typo [nfc] 2020-08-09 03:54:42 +01:00
David Nadlinger
78afa2ea8e compiler: Support MatMult in inferencer
Still needs actual codegen support.
2020-08-09 03:54:42 +01:00
David Nadlinger
4d48470320 compiler: Support common numpy.* math functions
Relies on the runtime to provide the necessary
(libm-compatible) functions.

The test is nifty, but a bit brittle; if this breaks in the
future because of optimizer changes, do not hesitate to convert
this into a more pedestrian test case.
2020-08-09 03:54:41 +01:00
David Nadlinger
d37503f21d compiler: T{C -> External}Function, clarify docs [nfc] 2020-08-09 03:54:41 +01:00
David Nadlinger
da255bee1b compiler: Implement element type coercion for arrays
So far, this is not exposed to the user beyond implicit conversions.

Note that all the implicit conversions, such as triggered by adding
arrays of mismatching types, or dividing integer arrays, are currently
emitted in a maximally inefficient way, where a temporary copy is first
made for the type conversion. The conversions would more sensibly be
implemented during the per-element operations to save on the extra
copies, but the current behaviour fell out of the rest of the IR
generator structure without extra changes.
2020-08-09 03:54:41 +01:00
David Nadlinger
4426e4144f compiler: Implement unary plus/minus for arrays
Implementation is needlessly generic to anticipate
coercion/transcendental functions.
2020-08-09 03:54:41 +01:00
David Nadlinger
4d002c7934 compiler: Explain use of rpc_tag() in array ops, formatting [nfc] 2020-08-09 03:54:41 +01:00
David Nadlinger
a7e855b319 compiler.types: Change invalid default value [nfc]
This wasn't actually ever used, but was a dict instead of a set.
2020-08-09 03:54:41 +01:00
David Nadlinger
48fb80017f compiler: Implement basic element-wise array operations 2020-08-09 03:54:41 +01:00
David Nadlinger
9af6e5747d compiler: Factor rpc_tag() out of llvm_ir_generator 2020-08-09 03:54:41 +01:00
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
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
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
85e92ae28c compiler: use more LLVM tools on ARM (#733) 2020-04-28 16:21:50 +08:00
140a26ad7e compiler: ld -> ld.lld 2020-04-28 16:07:26 +08:00
4228e0205c compiler: link with lld on ARM (#733) 2020-04-28 15:00:24 +08:00
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
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
cf47fa44d8 compiler: armv7-unknown-linux-gnueabihf -> armv7-linux-gnueabihf 2019-08-26 11:12:49 +08:00
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
421834fa3e compiler: document Target.little_endian 2018-12-02 19:07:18 +08:00
981a77834a compiler: use default triple to determine data_layout for JIT 2018-12-02 18:52:13 +08:00
d931967e5c fix previous commits 2018-12-02 18:32:03 +08:00
dd03fdfd1a typo 2018-12-02 18:26:54 +08:00
8940009e1a compiler: pass data_layout string to llvm.create_target_data before determining endianness 2018-12-02 18:26:19 +08:00
2e66788c6c compiler: support little endian target when storing now 2018-12-02 17:40:34 +08:00
7e14f3ca4e compiler,gateware: atomic now stores 2018-12-02 05:06:46 +08:00
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
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