Commit Graph

759 Commits

Author SHA1 Message Date
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
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
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
cd757c0f16 generate device database from executable python file 2017-05-18 23:14:55 +08:00
whitequark
bb64992395 compiler: remove dead code. 2017-04-21 18:38:43 +00:00
whitequark
c5d7445973 compiler: reject reachable implicit return if not returning TNone.
Fixes #718.
2017-04-21 18:11:14 +00:00
whitequark
ed2b10c5aa compiler: in codegen for delay(), round fp instead of truncating.
Consider delay(8*us). It results in the following computation...
  >>> 8*1e-06/1e-09
  7999.999999999999
with the result promptly getting truncated to 7999.

Fixes #706.
2017-04-21 17:36:44 +00:00
whitequark
3a1fc729cf compiler: refactor type annotations recognizing in kernels.
The new implementation is much more generic, more robust,
and shares code with the same for syscalls as well as RPCs.

Fixes #713.
2017-04-13 08:26:10 +00:00
whitequark
31048f4b6a compiler: fix monomorphization of coerced integer literals.
Fixes #703.
2017-04-12 04:11:47 +00:00
whitequark
1bd4d13391 artiq_compile: make print() write to core log, not an invalid op.
Fixes #710.
2017-04-11 03:16:34 +00:00
whitequark
86dea869b3 compiler.types: add missing TTuple.__hash__ implementation. 2017-03-03 03:27:49 +00:00
whitequark
7e886ddc89 transforms.inferencer: do not unnecessarily mutate typedtree.
This caused the hash to change after every iteration of inference,
if the result of any coercion was an integer of indefinite width.
2017-03-02 16:15:37 +00:00
whitequark
8c9f157563 compiler.embedding: fix an overly lax hasher. 2017-03-02 15:28:24 +00:00
whitequark
a79c3c2cff compiler.transforms: implement a typedtree printer. 2017-03-02 15:28:04 +00:00
whitequark
4107938fd8 compiler.embedding: use attribute count in fixpoint condition.
Before this commit, we had a hack where inferencing would run
one more time, in case we can still infer more attributes even
after all the type information is there. This doesn't work
if *that* round of inferencing brings even more code, e.g.
this is easy to trigger with context managers.
2017-02-28 21:28:40 +00:00
whitequark
252cda6e7f compiler.llvm_ir_generator: fix string quoting. 2017-02-28 21:28:38 +00:00
whitequark
de015b994d compiler: allow dumping the object file with ARTIQ_DUMP_OBJ. 2017-02-26 17:09:21 +00:00
whitequark
3a1f14c16c compiler: fix overly strict constness analysis.
Before this commit, the following code would fail to compile...
  obj.foo.bar = True
... if foo is marked kernel_invariant in obj, even if bar is not
marked as such in obj.foo.
2017-02-26 01:58:21 +00:00
whitequark
d04e611232 firmware, compiler: rename rpc functions to be more consistent. 2017-02-25 14:12:58 +00:00
whitequark
c39394b4d5 firmware: port the exception handling routines to Rust. 2017-02-04 08:21:07 +00:00
whitequark
fd8b11532f compiler, firmware: use Pascal strings everywhere.
This removes a large amount of very ugly code, and also simplifies
the compiler and runtime.
2017-02-03 11:53:27 +00:00
whitequark
ee1b2fa3ea compiler: swap the order of ptr/len fields in lists.
This is to make them match the Rust slices.
Once the cslice crate becomes #![no_std] we'll also use its (tidier)
conversion functions.
2017-01-31 22:11:13 +00:00
whitequark
ab71c9a0ba compiler: the len builtin is not polymorphic, coerce the result.
Fixes #659.
2017-01-31 21:28:20 +00:00
whitequark
6acdcbb82a Fix 2f37b1d. 2017-01-30 10:25:11 +00:00
whitequark
2f37b1d1c0 compiler: support methods defined on singleton instances.
Fixes #638.
2017-01-30 10:10:21 +00:00
whitequark
57f54dbd12 llvm_ir_generator: recognize inline and forceinline flags. 2017-01-25 10:25:00 +00:00
whitequark
f68e4ae519 compiler: rein in overzealous cast monomorphization. 2016-12-05 05:08:57 +00:00
whitequark
218720cfa7 Revert "compiler: rein in overzealous cast monomorphization."
This reverts commit 4305903dde.

This broke the monomorphizer/round.py test.
2016-12-05 05:04:26 +00:00
whitequark
4305903dde compiler: rein in overzealous cast monomorphization.
This caused failures on e.g. "int32(var64a >> var64b)", where
the type of the argument is already fully known, but was unified
with the result of the cast anyway.
2016-12-05 04:38:25 +00:00
whitequark
b5a684830d compiler: fix parsing of TList annotations (fixes #632). 2016-12-05 03:18:56 +00:00
whitequark
68de724554 compiler: monomorphize int64(round(x)) to not lose precision.
This applies to any expression with an indeterminate integer type
cast to int64(), not just round().
2016-12-02 15:02:44 +00:00
whitequark
ac997daf95 compiler: disable remarks. 2016-11-21 19:12:11 +00:00
whitequark
55ea68da7f compiler: unbreak casts to int32/int64. 2016-11-21 14:20:28 +00:00
whitequark
53b7d59b6a analyses.constness: fix false positive on x[...]. 2016-11-21 14:20:26 +00:00
whitequark
35f4449ef2 inferencer: significantly improve the op-assignment diagnostic.
Before this commit, it displayed incorrect output if an error
appeared on 2nd run and beyond, and displayed messages for trying
to do "num32 -= num64" that made very little sense.
2016-11-21 14:20:24 +00:00
whitequark
009d396740 Move mu_to_seconds, seconds_to_mu to Core. 2016-11-21 05:37:30 +00:00
whitequark
7af41bd29c llvm_ir_generator: handle no-op coercions. 2016-11-21 02:25:34 +00:00
whitequark
cdb29f9caa Revert accidentally committed code. 2016-11-20 14:32:59 +00:00
whitequark
f5cca6b09e analyses.invariant_detection: implement (#622). 2016-11-20 12:48:26 +00:00
whitequark
d3ee858d16 llvm_ir_generator: use !{→unconditionally.}invariant.load metadata.
This helps LICM, among other things.
2016-11-12 04:08:58 +00:00
whitequark
0e76cbc414 artiq_compile: actually disable attribute writeback.
I wrote both halves of this condition but forgot to hook
them together.

Fixes #586.
2016-11-10 01:04:36 +00:00
David Nadlinger
bfbdba9205 compiler: Emit all-kernel_invariant objects as LLVM constants
This enables constant propagation optimisations, as verified by
the included test case. This is only a first stop-gap measure, though;
we should support optimisation based on kernel invariants on a more
fine-grained level.
2016-11-09 14:50:48 +00:00
whitequark
ec8fe6f8bd Revert "Revert "Revert "Revert "Update for LLVM 3.9.""""
This reverts commit 7b81ed1d18.
2016-11-08 14:22:47 +00:00
whitequark
7b81ed1d18 Revert "Revert "Revert "Update for LLVM 3.9."""
This reverts commit 0d7688017b.
2016-11-08 12:58:20 +00:00
whitequark
0d7688017b Revert "Revert "Update for LLVM 3.9.""
This reverts commit 5f5975844a.
2016-11-08 11:59:16 +00:00
whitequark
798a5f70df Revert "runtime: remove some redundant libm functions copied inline."
This reverts commit fee75bd50f.

LLVM does not have lround as a libcall and this inhibits LICM.
2016-11-08 11:54:17 +00:00
David Nadlinger
6e77f65d50 compiler: Clarify recv_rpc value names and documentation [nfc]
Previously, the phi emitted for the pointer parameter to recv_rpc was –
rather confusingly – called "size", and the pseudo-code in the comment
had bit-rotted.

Signed-off-by: David Nadlinger <code@klickverbot.at>
2016-11-07 14:38:21 +00:00
David Nadlinger
7dcc987dd7 compiler: Fix break/continue targets in loop else blocks
Previously, they would still target the respective labels in the
just-exited loop.

Signed-off-by: David Nadlinger <code@klickverbot.at>
2016-11-05 02:35:01 +00:00
whitequark
cd68577dbc compiler: add support for async RPCs. 2016-10-30 00:57:31 +00:00
whitequark
2a9e370840 llvm_ir_generator: make sure RPC allocations are not underaligned. 2016-10-16 16:43:03 +00:00
whitequark
7618907cad runtime: use i64 for watchdog timeout, not i32. 2016-10-16 16:32:43 +00:00
whitequark
a8c017bfcc runtime: port ksupport to Rust. 2016-10-16 16:32:43 +00:00
whitequark
fee75bd50f runtime: remove some redundant libm functions copied inline. 2016-10-16 16:25:29 +00:00
whitequark
1cbb187136 runtime: eliminate va_list from kernel interface. 2016-09-30 03:07:27 +00:00
whitequark
ed60ba8c4c compiler: skip kernel_invariant linting for exception types. 2016-09-14 23:34:57 +00:00
whitequark
feeb089505 compiler: warn about unused kernel_invariant entries.
Fixes #543.
2016-09-14 23:28:55 +00:00
c414026b29 import_cache: make sure last line ends with \n as linecache does. Closes #547 2016-09-02 11:01:28 +08:00
whitequark
f26f446724 artiq_run: unbreak 2016-08-17 10:20:04 +00:00
whitequark
5f5975844a Revert "Update for LLVM 3.9."
This reverts commit 3aa7b99b8f.
2016-08-13 04:43:19 +00:00
whitequark
3aa7b99b8f Update for LLVM 3.9. 2016-08-13 03:28:04 +00:00
whitequark
1a518ea7eb compiler.embedding: implement string concatenation.
Fixes #526.
2016-08-08 04:05:52 +00:00
whitequark
5a2306ae5a compiler.embedding: implement type annotations for function arguments.
Fixes #318.
2016-08-08 03:28:25 +00:00
84f4725015 cache source on import of modules that may contain kernels. Closes #416 2016-08-06 12:01:49 +08:00
whitequark
21bc285604 transforms.llvm_ir_generator: skip RPC values for attribute writeback. 2016-08-03 04:59:14 +00:00
whitequark
c50d436f0b ir: invoke is a valid delay decomposition.
Fixes #510.
2016-07-13 08:48:31 +00:00
whitequark
c5ba44b8a6 compiler.testbench.perf_embedding: more fine grained reporting. 2016-07-11 17:55:24 +00:00
whitequark
c4dc4e7bf5 compiler.testbench.perf_embedding: update for core changes. 2016-07-08 10:48:41 +00:00
whitequark
5a79fcf9ba embedding: reimplement 373578bc properly.
The core of the problem that 373578bc was attempting to solve is
that diagnostics sometimes should be chained; one way of chaining
is the loc.expanded_from feature, which handles macro-like expansion,
but another is providing context.

Before this commit, context was provided using an ad-hoc override
of a diagnostic engine, which did not work in cases where diagnostic
engine was not threaded through the call stack. This commit uses
the newly added pythonparser context feature to elegantly handle
the problem.
2016-07-07 11:49:21 +00:00
whitequark
373578bc02 embedding: fix location for diagnostics on quoted values.
Fixes #489.
2016-07-07 08:32:56 +00:00
whitequark
d90fd7dc00 compiler: implement numpy.full (#424). 2016-07-07 06:33:38 +00:00
whitequark
7a671fb2fd embedding: treat numpy.{int32,int64,array} specially (#424).
Also, remove them from prelude to not pollute the namespace.
2016-07-07 06:33:38 +00:00
whitequark
933ea53c77 compiler: add basic numpy array support (#424). 2016-07-06 09:51:57 +00:00
whitequark
906db876a6 language: replace coredevice int with numpy.{int32,int64}.
Fixes #453.
2016-07-06 04:44:21 +00:00
whitequark
fa71b40c80 compiler: print the builtin type int(width=...) as np.int... 2016-07-06 04:22:51 +00:00
whitequark
ef2af8c331 compiler.embedding: use the builtin print as RPC.
Fixes #206.
2016-06-28 04:42:41 +00:00
whitequark
6155f65366 compiler: remove now()/at().
Fixes #490.
2016-06-28 04:39:14 +00:00