forked from M-Labs/artiq
1
0
Fork 0

transforms.artiq_ir_generator: emit ir.Parallel for with parallel:.

This commit is contained in:
whitequark 2015-10-09 03:10:39 +03:00
parent 48f1f48f09
commit 32ce33a1f9
2 changed files with 50 additions and 1 deletions

View File

@ -1000,6 +1000,7 @@ class IndirectBranch(Terminator):
return self.operands[1:] return self.operands[1:]
def add_destination(self, destination): def add_destination(self, destination):
destination.uses.add(self)
self.operands.append(destination) self.operands.append(destination)
def _operands_as_string(self): def _operands_as_string(self):
@ -1176,3 +1177,22 @@ class LandingPad(Terminator):
else: else:
table.append("{} => {}".format(types.TypePrinter().name(typ), target.as_operand())) table.append("{} => {}".format(types.TypePrinter().name(typ), target.as_operand()))
return "cleanup {}, [{}]".format(self.cleanup().as_operand(), ", ".join(table)) return "cleanup {}, [{}]".format(self.cleanup().as_operand(), ", ".join(table))
class Parallel(Terminator):
"""
An instruction that schedules several threads of execution
in parallel.
"""
def __init__(self, destinations=[], name=""):
super().__init__(destinations, builtins.TNone(), name)
def opcode(self):
return "parallel"
def destinations(self):
return self.operands
def add_destination(self, destination):
destination.uses.add(self)
self.operands.append(destination)

View File

@ -669,7 +669,36 @@ class ARTIQIRGenerator(algorithm.Visitor):
if not post_handler.is_terminated(): if not post_handler.is_terminated():
post_handler.append(ir.Branch(tail)) post_handler.append(ir.Branch(tail))
# TODO: With def visit_With(self, node):
if len(node.items) != 1:
diag = diagnostic.Diagnostic("fatal",
"only one expression per 'with' statement is supported",
{"type": types.TypePrinter().name(typ)},
node.context_expr.loc)
self.engine.process(diag)
context_expr_node = node.items[0].context_expr
optional_vars_node = node.items[0].optional_vars
if types.is_builtin(context_expr_node.type, "sequential"):
self.visit(node.body)
elif types.is_builtin(context_expr_node.type, "parallel"):
parallel = self.append(ir.Parallel())
heads, tails = [], []
for stmt in node.body:
self.current_block = self.add_block()
heads.append(self.current_block)
self.visit(stmt)
tails.append(self.current_block)
for head in heads:
parallel.add_destination(head)
self.current_block = self.add_block()
for tail in tails:
if not tail.is_terminated():
tail.append(ir.Branch(self.current_block))
# Expression visitors # Expression visitors
# These visitors return a node in addition to mutating # These visitors return a node in addition to mutating