From 82b470891fe1ba16567439e2739d1fd03822c3d5 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 21 Nov 2015 03:32:53 +0800 Subject: [PATCH] transforms.interleaver: handle function calls (as atomic so far). This commit solves issue #2 described in 50e7b44; a function call is now a valid decomposition for a delay instruction, and this metadata is propagated when the interleaver converts delays. However, the interleaver does not yet detect that a called function is compound, i.e. it is not correct. --- artiq/compiler/transforms/interleaver.py | 2 +- lit-test/test/interleaving/indirect.py | 28 ++++++++++++++++++++++ lit-test/test/interleaving/indirect_arg.py | 28 ++++++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 lit-test/test/interleaving/indirect.py create mode 100644 lit-test/test/interleaving/indirect_arg.py diff --git a/artiq/compiler/transforms/interleaver.py b/artiq/compiler/transforms/interleaver.py index 23bf3d33d..1fc8b4e1e 100644 --- a/artiq/compiler/transforms/interleaver.py +++ b/artiq/compiler/transforms/interleaver.py @@ -104,7 +104,7 @@ class Interleaver: new_decomp.loc = old_decomp.loc source_terminator.basic_block.insert(source_terminator, new_decomp) else: - assert False # TODO + old_decomp, new_decomp = None, old_decomp source_terminator.replace_with(ir.Delay(iodelay.Const(target_time_delta), {}, new_decomp, source_terminator.target())) diff --git a/lit-test/test/interleaving/indirect.py b/lit-test/test/interleaving/indirect.py new file mode 100644 index 000000000..19f59c69f --- /dev/null +++ b/lit-test/test/interleaving/indirect.py @@ -0,0 +1,28 @@ +# RUN: %python -m artiq.compiler.testbench.jit %s >%t +# RUN: OutputCheck %s --file-to-check=%t + +def f(): + delay_mu(2) + +def g(): + with parallel: + with sequential: + print("A", now_mu()) + f() + # + print("B", now_mu()) + with sequential: + print("C", now_mu()) + f() + # + print("D", now_mu()) + f() + # + print("E", now_mu()) + +# CHECK-L: A 0 +# CHECK-L: C 0 +# CHECK-L: B 2 +# CHECK-L: D 2 +# CHECK-L: E 4 +g() diff --git a/lit-test/test/interleaving/indirect_arg.py b/lit-test/test/interleaving/indirect_arg.py new file mode 100644 index 000000000..e9af00034 --- /dev/null +++ b/lit-test/test/interleaving/indirect_arg.py @@ -0,0 +1,28 @@ +# RUN: %python -m artiq.compiler.testbench.jit %s >%t +# RUN: OutputCheck %s --file-to-check=%t + +def f(n): + delay_mu(n) + +def g(): + with parallel: + with sequential: + print("A", now_mu()) + f(2) + # + print("B", now_mu()) + with sequential: + print("C", now_mu()) + f(2) + # + print("D", now_mu()) + f(2) + # + print("E", now_mu()) + +# CHECK-L: A 0 +# CHECK-L: C 0 +# CHECK-L: B 2 +# CHECK-L: D 2 +# CHECK-L: E 4 +g()