Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 7c52910dc59d
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7687dae78882
Choose a head ref
  • 3 commits
  • 1 file changed
  • 1 contributor

Commits on Jul 13, 2015

  1. Fix Python default argument fiasco.

    whitequark committed Jul 13, 2015
    Copy the full SHA
    7c9afcc View commit details
  2. Add missing return.

    whitequark committed Jul 13, 2015
    Copy the full SHA
    dbdd45a View commit details
  3. Add printing of SSA functions.

    whitequark committed Jul 13, 2015
    Copy the full SHA
    7687dae View commit details
Showing with 35 additions and 12 deletions.
  1. +35 −12 artiq/compiler/ir.py
47 changes: 35 additions & 12 deletions artiq/compiler/ir.py
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ class Value:
:ivar uses: (list of :class:`Value`) values that use this value
"""

def __init__(self, typ=builtins.TNone()):
def __init__(self, typ):
self.uses, self.type = set(), typ

def replace_all_uses_with(self, value):
@@ -44,7 +44,7 @@ class NamedValue(Value):
:ivar function: (:class:`Function`) function containing this value
"""

def __init__(self, typ=builtins.TNone(), name=""):
def __init__(self, typ, name):
super().__init__(typ)
self.name, self.function = name, None

@@ -77,10 +77,11 @@ class User(NamedValue):
:ivar operands: (list of :class:`Value`) operands of this value
"""

def __init__(self, typ=builtins.TNone(), name="", operands=[]):
def __init__(self, operands, typ, name):
super().__init__(typ, name)
self.operands = []
self.set_operands(operands)
if operands is not None:
self.set_operands(operands)

def set_operands(self, new_operands):
for operand in self.operands:
@@ -107,8 +108,8 @@ class Instruction(User):
An SSA instruction.
"""

def __init__(self, typ=builtins.TNone(), name="", operands=[]):
super().__init__(typ, name, operands)
def __init__(self, operands, typ, name=""):
super().__init__(operands, typ, name)
self.basic_block = None

def set_basic_block(self, new_basic_block):
@@ -157,8 +158,14 @@ def __str__(self):
class Phi(Instruction):
"""
An SSA instruction that joins data flow.
Use :meth:`incoming` and :meth:`add_incoming` instead of
directly reading :attr:`operands` or calling :meth:`set_operands`.
"""

def __init__(self, typ, name=""):
super().__init__(typ, name)

def opcode(self):
return "phi"

@@ -202,20 +209,27 @@ class Terminator(Instruction):
"""

def successors(self):
[operand for operand in self.operands if isinstance(operand, BasicBlock)]
return [operand for operand in self.operands if isinstance(operand, BasicBlock)]

class BasicBlock(NamedValue):
"""
A block of instructions with no control flow inside it.
:ivar instructions: (list of :)
:ivar instructions: (list of :class:`Instruction`)
"""

def __init__(self, name="", instructions=[]):
def __init__(self, instructions, name=""):
super().__init__(TSSABasicBlock(), name)
self.instructions = []
self.set_instructions(instructions)

def set_instructions(self, new_insns):
for insn in self.instructions:
insn.detach()
self.instructions = new_insns
for insn in self.instructions:
insn.set_basic_block(self)

def remove_from_parent(self):
if self.function is not None:
self.function.remove(self)
@@ -274,10 +288,11 @@ class Function(Value):
"""

def __init__(self, typ, name, arguments):
self.type, self.name, self.arguments = typ, name, []
self.set_arguments(arguments)
self.type, self.name = typ, name
self.arguments = []
self.basic_blocks = set()
self.names = set()
self.set_arguments(arguments)

def _remove_name(self, name):
self.names.remove(name)
@@ -310,10 +325,18 @@ def remove(self, basic_block):
self.basic_block.remove(basic_block)

def predecessors_of(self, successor):
set(block for block in self.basic_blocks if successor in block.successors())
return set(block for block in self.basic_blocks if successor in block.successors())

def as_operand(self):
return "{} @{}".format(types.TypePrinter().name(self.type),
escape_name(self.name))

def __str__(self):
type_printer = types.TypePrinter()
lines = []
lines.append("{} {}({}) { ; type: {}".format(
printer.name(self.type.ret), self.name,
", ".join([arg.as_operand() for arg in self.arguments]),
printer.name(self.type))

# Python-specific SSA IR classes