From 9639a831bcade783dca88ca39bc0adfabe99f96f Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 19 Nov 2015 23:44:39 +0800 Subject: [PATCH] transforms.artiq_ir_generator: correctly emit IfExpT with control flow. This can happen with nested if expressions, as well as if the if expression includes delays. --- artiq/compiler/transforms/artiq_ir_generator.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/artiq/compiler/transforms/artiq_ir_generator.py b/artiq/compiler/transforms/artiq_ir_generator.py index 9210be8b8..6a9c0c34a 100644 --- a/artiq/compiler/transforms/artiq_ir_generator.py +++ b/artiq/compiler/transforms/artiq_ir_generator.py @@ -729,23 +729,25 @@ class ARTIQIRGenerator(algorithm.Visitor): if_true = self.add_block() self.current_block = if_true true_result = self.visit(node.body) + post_if_true = self.current_block if_false = self.add_block() self.current_block = if_false false_result = self.visit(node.orelse) + post_if_false = self.current_block tail = self.add_block() self.current_block = tail - if not if_true.is_terminated(): - if_true.append(ir.Branch(tail)) - if not if_false.is_terminated(): - if_false.append(ir.Branch(tail)) + if not post_if_true.is_terminated(): + post_if_true.append(ir.Branch(tail)) + if not post_if_false.is_terminated(): + post_if_false.append(ir.Branch(tail)) head.append(ir.BranchIf(cond, if_true, if_false)) phi = self.append(ir.Phi(node.type)) - phi.add_incoming(true_result, if_true) - phi.add_incoming(false_result, if_false) + phi.add_incoming(true_result, post_if_true) + phi.add_incoming(false_result, post_if_false) return phi def visit_NumT(self, node):