From 255ffec483740ff2058f28df266dbba9135c937b Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 18 Jul 2015 07:49:27 +0300 Subject: [PATCH] Generate more compact ARTIQ IR for else-less if. --- artiq/compiler/transforms/ir_generator.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/artiq/compiler/transforms/ir_generator.py b/artiq/compiler/transforms/ir_generator.py index 4ee4e4ddd..ef0214695 100644 --- a/artiq/compiler/transforms/ir_generator.py +++ b/artiq/compiler/transforms/ir_generator.py @@ -238,17 +238,22 @@ class IRGenerator(algorithm.Visitor): self.current_block = if_true self.visit(node.body) - if_false = self.add_block() - self.current_block = if_false - self.visit(node.orelse) + if any(node.orelse): + if_false = self.add_block() + self.current_block = if_false + self.visit(node.orelse) 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)) - head.append(ir.BranchIf(cond, if_true, if_false)) + + if any(node.orelse): + if not if_false.is_terminated(): + if_false.append(ir.Branch(tail)) + head.append(ir.BranchIf(cond, if_true, if_false)) + else: + head.append(ir.BranchIf(cond, if_true, tail)) def visit_While(self, node): try: