Skip to content

Commit

Permalink
LLVMIRGenerator: fixup phis on expansion of ARTIQ instructions.
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed Aug 9, 2015
1 parent d4270cf commit f7b64db
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion artiq/compiler/transforms/llvm_ir_generator.py
Expand Up @@ -17,6 +17,7 @@ def __init__(self, engine, module_name, target):
self.llmodule.data_layout = target.data_layout
self.llfunction = None
self.llmap = {}
self.llblock_map = {}
self.fixups = []

def llty_of_type(self, typ, bare=False, for_return=False):
Expand Down Expand Up @@ -229,6 +230,13 @@ def process_function(self, func):
assert llinsn is not None
self.llmap[insn] = llinsn

# There is no 1:1 correspondence between ARTIQ and LLVM
# basic blocks, because sometimes we expand a single ARTIQ
# instruction so that the result spans several LLVM basic
# blocks. This only really matters for phis, which will
# use a different map.
self.llblock_map[block] = self.llbuilder.basic_block

# Fourth, fixup phis.
for fixup in self.fixups:
fixup()
Expand All @@ -241,7 +249,7 @@ def process_Phi(self, insn):
llinsn = self.llbuilder.phi(self.llty_of_type(insn.type), name=insn.name)
def fixup():
for value, block in insn.incoming():
llinsn.add_incoming(self.map(value), self.map(block))
llinsn.add_incoming(self.map(value), self.llblock_map[block])
self.fixups.append(fixup)
return llinsn

Expand Down

0 comments on commit f7b64db

Please sign in to comment.