Commit Graph

283 Commits

Author SHA1 Message Date
983f080ea7 artiq: Implement handling for const generic variables 2023-12-08 18:02:14 +08:00
c93ad152d7 core: Codegen for ellipsis expression as NotImplemented
A lot of refactoring was performed, specifically with relaxing
expression codegen to return Option in case where ellipsis are used
within a subexpression.
2023-12-08 18:00:51 +08:00
c2ab6b58ff artiq: Implement with legacy_parallel block 2023-11-04 13:42:44 +08:00
0a84f7ac31 Add CodeGenerator::gen_block and refactor to use it 2023-11-04 13:42:44 +08:00
352f70b885 artiq: Update host exception list to match possibly thrown types 2023-11-01 13:28:48 +08:00
9518d3fe14 artiq: Fix timeline not resetting upon exiting sequential block 2023-10-30 14:04:53 +08:00
cbd333ab10 artiq: Extract parallel block timeline utilities 2023-10-30 14:04:53 +08:00
65d6104d00 artiq: Improve IR value naming and add documentation 2023-10-30 14:04:53 +08:00
8373a6cb0f artiq: Use gen_block when generating "with sequential" 2023-10-30 14:04:53 +08:00
e1487ed335 cargo: Update dependencies 2023-10-20 18:11:45 +08:00
7fc2a30c14 Force single-threaded compilation if LLVM is not thread-safe 2023-10-16 15:55:10 +08:00
c7de22287e core: Fix restoration of stack address
All allocas for temporary objects are now placed in the beginning of the
function. Allocas for on-temporary objects are not modified because
these variables may appear in a loop and thus must be uniquely
represented.
2023-10-06 11:34:23 +08:00
2a38d5160e meta: Respect opt flags when performing whole-module optimization 2023-09-28 19:58:54 +08:00
31dcd2dde9 core: Use i8 for boolean variable allocation
In LLVM, i1 represents a 1-byte integer with a single valid bit; The
rest of the 7 upper bits are undefined. This causes problems when
using these variables in memory operations (e.g. memcpy/memmove as
needed by List slicing and assignment).

We fix this by treating all local boolean variables as i8 so that they
are well-defined for memory operations. Function ABIs will continue to
use i1, as memory operations cannot be directly performed on function
arguments or return types, instead they are always converted back into
local boolean variables (which are i8s anyways).

Fixes #315.
2023-09-25 15:42:07 +08:00
6dfc43c8b0 core: Add name to build_gep_and_load 2023-09-22 17:16:29 +08:00
ab2360d7a0 core: Remove emit_llvm from CodeGenLLVMOptions
We instead output an LLVM bitcode file when the option is specified on
the command-line.
2023-09-22 17:16:29 +08:00
411837cacd artiq: Specify target CPU when creating LLVM target options
We can try to optimize for the host and Cortex-A9 chips; The RISC-V
ISAs do not target specific chips, so we will fallback to using the
generic CPU.
2023-09-18 11:35:20 +08:00
048fcb0a69 core: Switch to LLVM New Pass Manager 2023-09-18 11:35:15 +08:00
676d07657a core: Add target field to CodeGenLLVMOptions
For specifying the target machine options when optimizing and linking.

This field is currently unused but will be required in a future
commit.
2023-09-18 09:46:24 +08:00
2482a1ef9b core: Add CodeGenTargetMachineOptions
Needed in a future commit.
2023-09-18 09:41:49 +08:00
eb63f2ad48 meta: Update to Rust Edition 2021 2023-09-15 10:25:50 +08:00
3993a5cf3f core: Add LLVM options to WorkerRegistry 2023-09-12 10:57:05 +08:00
f1b0e05b3d core: Rename IR variables
Because it is unclear which variables are expressions and
subexpressions, all variables which are previously anonymous are named
using (1) the control flow statement if available, (2) the possible name
of the variable as inferred from the variable name in Rust, and (3) the
"addr" prefix to indicate that the values are pointers. These three
strings are joint together using '.', forming "for.i.addr" for instance.
2023-09-06 14:02:15 +08:00
ff23968544 core: Add name parameter to gen_{var_alloc,store_target}
This allows variables in the IR to be assigned a custom name as opposed
to names with a default prefix.
2023-09-06 11:00:02 +08:00
d37287a33d Cargo: Update dependencies 2023-09-04 10:43:57 +08:00
aead36f0fd update dependencies 2023-03-08 15:19:09 +08:00
c1c45373a6 update dependencies 2023-01-12 19:31:03 +08:00
f66ca02b2d update Rust dependencies 2022-08-05 16:58:57 +08:00
b514f91441 nac3artiq: inherit kernel constructors
Closes #139
Co-authored-by: z78078 <cc@m-labs.hk>
Co-committed-by: z78078 <cc@m-labs.hk>
2022-07-28 19:18:36 +08:00
8f95b79257 nac3artiq: throw error message when constructor use rpc decorator (#306)
Co-authored-by: z78078 <cc@m-labs.hk>
Co-committed-by: z78078 <cc@m-labs.hk>
2022-07-11 15:55:55 +08:00
ebd25af38b nac3standalone: allow classes without explicit init (#221)
Reviewed-on: #304
Co-authored-by: z78078 <cc@m-labs.hk>
Co-committed-by: z78078 <cc@m-labs.hk>
2022-07-07 10:36:25 +08:00
7cb9be0f81 nac3artiq: refactor compile methods
Avoids writing relocatable object to a file when linking with nac3ld.
2022-06-06 14:41:10 +08:00
ac560ba985 nac3artiq: switch ld.lld to nac3ld for non-host target 2022-06-06 14:40:13 +08:00
48fc5ceb8e nac3artiq: demote global value to private
... except typeinfo & now symbols.
typeinfo will be read by the runtime linker; now is for now-pinning.
2022-05-30 22:46:41 +08:00
09820e5aed nac3artiq: return err instead of panic for host object attribute error 2022-05-18 02:54:42 +08:00
2cb725b7ac nac3artiq: correct global name for const object 2022-05-16 02:50:42 +08:00
ae6434696c nac3artiq: rename the filename of modinit
rename from __nac3_synthesized_modinit__ to <nac3_synthesized_modinit> to be more idomatic python
2022-05-11 03:52:16 +08:00
3f327113b2 update dependencies, use upstream inkwell 2022-04-27 15:41:46 +08:00
27d509d70e nac3artiq: get_const_obj should no longer make a pointer. Closes #272 2022-04-27 15:28:58 +08:00
85f21060e4 update to LLVM 14 2022-04-18 18:47:20 +08:00
f14b32be67 nac3artiq: type check host int bound instead of panic when codegen 2022-04-16 03:01:37 +08:00
6972689469 nac3artiq: cleanup demo 2022-04-12 10:34:14 +08:00
3fb22c9182 nac3artiq: treat host numpy.float64 as float. Closes #90 2022-04-12 10:33:28 +08:00
722e3df086 nac3core, artiq: optimize kernel invariant for tuple index 2022-04-11 14:58:40 +08:00
ad9ad22cb8 nac3core: optimize unwrap KernelInvariant 2022-04-11 14:58:35 +08:00
6c485bc9dc nac3artiq: skip attribute writeback for option
option types do not have any fields to be written back to the host so it is ok to skip. If we do not skip, there will be error when getting the value of it since it can be `none`, whose type is not concrete
2022-04-10 01:28:30 +08:00
089bba96a3 nac3artiq: get_obj_value take an additional argument for expected type 2022-04-10 01:28:30 +08:00
0e0871bc38 nac3core, artiq: to_basic_value_enum takes an argument indicating the expected type 2022-04-10 01:28:22 +08:00
e52d7fc97a nac3artiq: resolve unsigned int host variable as defautl param 2022-03-30 04:05:47 +08:00
6ab73a223c nac3core/artiq: support default param of option type 2022-03-30 04:05:47 +08:00
201ca3f63d Revert "nac3artiq: use lld.exe on Windows"
This reverts commit 19182759cd.
2022-03-27 19:09:11 +08:00
19182759cd nac3artiq: use lld.exe on Windows 2022-03-27 18:41:38 +08:00
0600ee8efa nac3artiq: use correct lld invokation on Windows 2022-03-27 18:25:14 +08:00
0d2b844a2e nac3artiq: avoid getting tuple as pointer value 2022-03-27 10:31:20 +08:00
10d623e36f nac3core/artiq: fix tuple representation 2022-03-27 07:47:14 +08:00
000b128551 nac3artiq: cast none to correct ptr type (#241) 2022-03-26 23:32:50 +08:00
bf067e2481 nac3artiq: implement attribute writeback
We will only writeback attributes that are supported by the current RPC
implementation: primitives, tuple and lists of lists... of primitives.
2022-03-26 20:13:58 +08:00
ba8ed6c663 nac3artiq: handle recursive types properly 2022-03-26 18:54:21 +08:00
80631fc92b Option type support (#224)
Co-authored-by: ychenfo <yc@m-labs.hk>
Co-committed-by: ychenfo <yc@m-labs.hk>
2022-03-26 15:09:15 +08:00
1084ba2158 nac3core: fixed typevar with finite range
1. Function type variables should not include class type variables,
   because they are not bound to the function.
2. Defer type variable constraint evaluation until we get all fields
   definition.
2022-03-24 21:31:51 +08:00
41d62f7325 nac3core/toplevel: fixed typevar substitution bug 2022-03-23 00:25:10 +08:00
263bc82434 nac3artiq: remove debug print 2022-03-21 04:23:40 +08:00
35ac5cb6f6 nac3core: fixed typevar bug 2022-03-18 01:07:44 +08:00
fb8553311c nac3artiq: remove accidentally added print 2022-03-17 15:13:00 +08:00
04e7a7eb4b nac3artiq: support more exceptions 2022-03-17 15:03:22 +08:00
642e3b2bad nac3core: moved all builtin errors to nac3artiq code
This remove the need for hard-coding those definition IDs.
2022-03-17 00:04:49 +08:00
e126fef012 nac3artiq: support more builtin errors 2022-03-16 23:42:08 +08:00
94aac16cc5 nac3artiq: fixed RPC codegen for lists 2022-03-10 16:48:28 +08:00
79c469301a basic unsigned integer support 2022-03-08 13:34:02 +08:00
a5e1da0b92 nac3artiq/demo/embedding_map: avoid key 0
Object key 0 is reserved for builtin exceptions.
2022-03-05 00:27:23 +08:00
294943e303 nac3core: get exception ID from symbol resolver
We need to store the exception class somewhere in order to create them
back in the host. Fixes #200
2022-03-05 00:26:35 +08:00
84b4bd920b nac3artiq: remove cached pyid_to_type if error 2022-03-04 16:23:25 +08:00
d1e172501d nac3artiq: remove debug messages 2022-02-28 23:10:05 +08:00
323d77a455 nac3artiq: improve error message for out of range error 2022-02-28 23:09:14 +08:00
d41c923cfd nac3artiq: handle recursive types properly 2022-02-28 23:08:42 +08:00
a9c73a4915 fix some error strings 2022-02-28 11:10:33 +08:00
804d5db27e nac3artiq: make CompileError importable from Python 2022-02-26 17:29:13 +08:00
cbc77dddb0 nac3artiq: raise specific exception on error 2022-02-26 17:17:06 +08:00
d3cb5d6e52 Fixed type error messages 2022-02-22 17:22:15 +08:00
bb7c0a2d79 nac3artiq: remove errors from demo 2022-02-22 16:00:37 +08:00
f97f93d92c applied rustfmt and clippy auto fix 2022-02-21 18:27:46 +08:00
d9cb506f6a nac3core: refactored for better error messages 2022-02-21 18:24:19 +08:00
352831b2ca nac3core: removed legacy location definition 2022-02-13 22:39:24 +08:00
bf52e294ee nac3artiq: RPC support 2022-02-12 22:50:32 +08:00
0439bf6aef nac3artiq: fix errors of non-primitive object when running multiple kernels 2022-01-15 04:43:39 +08:00
fd4bf12808 fix grammar of some type error messages 2022-01-14 16:56:23 +08:00
9d342d9f0f nac3artiq: error msg improvement for synthesized __modinit__ 2022-01-14 16:28:37 +08:00
4a1a4dc076 nac3core/artiq/standalone: symbol resolver return error msg for type error of host variables 2022-01-14 16:28:34 +08:00
4a65d82db5 introduce IRRT, implement power
based on code by Yijia
#160
2022-01-09 00:57:50 +08:00
88f0da7bdd add file name to AST node location 2021-12-28 01:28:55 +08:00
521f136f2e redo "nac3artiq: fixed compilation error"
This reverts commit 3b5328d3cd.
2021-12-27 22:56:30 +08:00
fa04768a77 redo "nac3core: fix #84"
This reverts commit 86005da8e1.
2021-12-27 22:56:26 +08:00
6162d21a5b LLVM PGO support 2021-12-26 21:11:14 +08:00
86005da8e1 Revert "nac3core: fix #84"
This reverts commit 0902d8adf4.
2021-12-26 08:35:27 +08:00
3b5328d3cd Revert "nac3artiq: fixed compilation error"
This reverts commit 34cabe0e55.
2021-12-26 08:31:37 +08:00
d2a5cd6d57 update to LLVM 13 2021-12-25 22:49:47 +08:00
9e3f75255e update inkwell. Closes #67 2021-12-25 22:17:06 +08:00
34cabe0e55 nac3artiq: fixed compilation error 2021-12-23 15:47:54 +08:00
0902d8adf4 nac3core: fix #84 2021-12-23 15:26:48 +08:00
66320679be improve error messages
#112, #110, #108, #87

Reviewed-on: #145
Co-authored-by: ychenfo <yc@m-labs.hk>
Co-committed-by: ychenfo <yc@m-labs.hk>
2021-12-22 08:52:19 +08:00
91625dd327 update kernel-only attribute annotation
Reviewed-on: #127
Co-authored-by: ychenfo <yc@m-labs.hk>
Co-committed-by: ychenfo <yc@m-labs.hk>
2021-12-19 11:04:53 +08:00
3f73896477 remove a small amount of LLVM bloat
Also avoids libffi.dll dependency on Windows.
2021-12-08 17:41:34 +08:00
6d00d4dabb nac3artiq: cache python data if possible 2021-12-05 20:30:03 +08:00
65bc1e5fa4 nac3artiq: handle name_to_pyid in compilation
python variables can change between kernel invocations
2021-12-05 13:10:54 +08:00
2938eacd16 nac3artiq: supports running multiple kernels 2021-12-05 13:10:54 +08:00
41f88095a5 min_artiq: add round64, floor64, ceil64 2021-12-04 20:35:52 +08:00
c98f367f90 nac3artiq: enables inlining 2021-12-04 17:52:03 +08:00
4526c28edb Merge branch 'windows' 2021-12-02 22:26:55 +08:00
25fc9db66d cargo: specify inkwell LLVM target explicitly
Windows LLVM linking otherwise breaks on the non-existing targets.
2021-12-02 22:24:33 +08:00
c683958e4a nac3artiq: clarify comment about virtual class 2021-12-01 22:49:20 +08:00
142f82f987 remove debug prints 2021-12-01 22:48:06 +08:00
dfd3548ed2 TypeVar and virtual support in Symbol Resolver (#99)
Add `TypeVar` and `virtual` support for Symbol Resolver in nac3artiq and nac3standalone

Reviewed-on: #99
Co-authored-by: ychenfo <yc@m-labs.hk>
Co-committed-by: ychenfo <yc@m-labs.hk>
2021-12-01 22:44:53 +08:00
681d85d3be remove debug print 2021-11-28 12:57:28 +08:00
b35075245b nac3artiq: remove debug print 2021-11-27 21:29:57 +08:00
4b17511b4a Merge branch 'master' into KernelInvariant 2021-11-27 21:29:27 +08:00
4587088835 Constant Default Parameter Support (#98)
Add support for constant default parameter

Reviewed-on: #98
Co-authored-by: ychenfo <yc@m-labs.hk>
Co-committed-by: ychenfo <yc@m-labs.hk>
2021-11-23 07:32:09 +08:00
f5ec103c82 nac3artiq: kernel invariant support 2021-11-20 21:15:15 +08:00
ba08deada6 nac3core: refactor codegen 2021-11-20 19:50:25 +08:00
439cef636f runkernel: improve print_int debug functions 2021-11-19 12:39:57 +08:00
1e47b364c5 nac3artiq: support now-pinning on RISC-V with wide data bus (#97) 2021-11-16 17:37:40 +08:00
9ae08d6e3d nac3artiq: add stubs for now-pinning on rv32g (#97) 2021-11-13 12:10:55 +08:00
d6b92adf70 nac3artiq: add stack guard 2021-11-12 20:03:52 +08:00
978eaf16a4 nac3artiq: support RISC-V with and without FPU. Closes #83 2021-11-11 23:43:50 +08:00
612b6768c0 nac3artiq: bail early on non-NAC3 classes 2021-11-11 16:35:40 +08:00
c004da85f7 nac3artiq: drop host-only base classes. Closes #80 2021-11-11 16:08:29 +08:00
b57b869c49 min_artiq: remove unused imports 2021-11-10 14:01:39 +08:00
50f1aca1aa nac3artiq: move module registration list to CPython side
In ARTIQ, we cannot create a global NAC3 object because we do not
know the ISA in advance.
2021-11-07 10:29:14 +08:00
ffa89e9308 fix clippy warnings 2021-11-06 23:00:18 +08:00
34cf303e6c nac3artiq: modified demo to use KernelInvariants 2021-11-06 22:50:28 +08:00
b1e83a1fd4 nac3core: type check invariants
This rejects code that tries to assign to KernelInvariant fields and
methods.
2021-11-06 22:48:08 +08:00
7385b91113 nac3artiq: support kernel entry short form from original ARTIQ 2021-11-06 18:41:59 +08:00
016cbf2b90 nac3artiq: return bytes in compile_method_to_mem 2021-11-06 14:29:23 +08:00
37eae090e5 nac3artiq: fix linker inputs 2021-11-06 14:23:54 +08:00
204baabfd2 nac3artiq: add compile_method_to_mem 2021-11-06 14:14:53 +08:00
7d66195eae nac3artiq: embed linker script, put intermediate objects in temp dir 2021-11-06 13:04:00 +08:00
afb94dd299 nac3artiq: move demo to dedicated folder 2021-11-05 18:28:31 +08:00
d6f0607ff0 nac3artiq: rename class decorator to nac3 2021-11-05 18:08:36 +08:00
610448fa73 nac3artiq: include parallel in demo 2021-11-05 18:07:18 +08:00
e8228710e7 min_artiq: remove unnecessary definitions 2021-11-05 17:50:26 +08:00
bf7e2c295a integrate nac3parser 2021-11-03 17:11:00 +08:00
bc0f82cad8 Revert "nac3artiq/codegen: fixed smax problem"
We have LLVM 12 now and can use the intrinsic.

This reverts commit 98d9f73afb.
2021-11-02 14:00:28 +08:00
624dfe8cd1 upgrade to LLVM 12 2021-11-02 14:00:20 +08:00
e47597bb8a Merge branch 'context-manager' 2021-11-02 11:17:00 +08:00
98d9f73afb nac3artiq/codegen: fixed smax problem
It turns out the smax intrinsic I use is a new one that is not supported
in LLVM11. Now implemented with signed integer compare and select.
2021-11-02 11:10:21 +08:00
b37cf6de08 nac3artiq: share isa->time_fns map 2021-11-01 00:03:15 +08:00
083eacc268 with parallel/sequential support
Behavior of parallel and sequential:
Each function call (indirectly, can be inside a sequential block) within a parallel
block will update the end variable to the maximum now_mu in the block.
Each function call directly inside a parallel block will reset the timeline after
execution. A parallel block within a sequential block (or not within any block) will
set the timeline to the max now_mu within the block (and the outer max now_mu will also
be updated).

Implementation: We track the start and end separately.
- If there is a start variable, it indicates that we are directly inside a
parallel block and we have to reset the timeline after every function call.
- If there is a end variable, it indicates that we are (indirectly) inside a
parallel block, and we should update the max end value.

Note: requires testing, it is difficult to inspect the output IR
2021-10-31 23:54:37 +08:00
443b95d909 nac3artiq: do not use custom linker script when targeting host 2021-10-31 23:51:50 +08:00
8b73a123cc nac3artiq: support compiling for the host 2021-10-31 23:02:21 +08:00
84c5201243 with parallel/sequential support
Behavior of parallel and sequential:
Each function call (indirectly, can be inside a sequential block) within a parallel
block will update the end variable to the maximum now_mu in the block.
Each function call directly inside a parallel block will reset the timeline after
execution. A parallel block within a sequential block (or not within any block) will
set the timeline to the max now_mu within the block (and the outer max now_mu will also
be updated).

Implementation: We track the start and end separately.
- If there is a start variable, it indicates that we are directly inside a
parallel block and we have to reset the timeline after every function call.
- If there is a end variable, it indicates that we are (indirectly) inside a
parallel block, and we should update the max end value.

Note: requires testing, it is difficult to inspect the output IR
2021-10-31 17:16:21 +08:00
279f47f633 nac3core/codegen: avoid sending unifiers
Previously, we have to copy types from one unification table to another,
and make the table sendable. This requires cloning (processing) the
whole table 3 times per function call which is not efficient and uses
more memory than required when the unification table is large.

We now use a concrete type table to only copy the type we need. This
reduces the overhead as we only need to process the unification table
for once (when we do the function codegen), and reduces memory usage by
a bit (but not noticeable when the unification table is small, i.e. the
types are simple).
2021-10-17 13:02:18 +08:00