Beispiel #1
0
    def test_ssa(self):
        mod = from_c(source)
        f = mod.get_function('func_simple')
        verify(f)
        self.assertEqual(opcodes(f.startblock),
                         ['alloca', 'store', 'load', 'gt', 'cbranch'])

        # SSA
        CFG = cfa.cfg(f)
        cfa.ssa(f, CFG)

        assert len(f.blocks) == 4
        blocks = list(f.blocks)
        self.assertEqual(opcodes(blocks[0]), ['gt', 'cbranch'])
        self.assertEqual(opcodes(blocks[1]), ['jump'])
        self.assertEqual(opcodes(blocks[2]), ['jump'])
        self.assertEqual(opcodes(blocks[3]), ['phi', 'convert', 'ret'])

        phi = findop(f, 'phi')
        iblocks, ivals = phi.args
        self.assertEqual(sorted(iblocks), sorted([blocks[1], blocks[2]]))
        self.assertEqual(len(ivals), 2)
Beispiel #2
0
    def test_ssa(self):
        mod = from_c(source)
        f = mod.get_function('func_simple')
        verify(f)
        self.assertEqual(opcodes(f.startblock),
                         ['alloca', 'store', 'load', 'gt', 'cbranch'])

        # SSA
        CFG = cfa.cfg(f)
        cfa.ssa(f, CFG)

        assert len(f.blocks) == 4
        blocks = list(f.blocks)
        self.assertEqual(opcodes(blocks[0]), ['gt', 'cbranch'])
        self.assertEqual(opcodes(blocks[1]), ['jump'])
        self.assertEqual(opcodes(blocks[2]), ['jump'])
        self.assertEqual(opcodes(blocks[3]), ['phi', 'ret'])

        phi = findop(f, 'phi')
        iblocks, ivals = phi.args
        self.assertEqual(sorted(iblocks), sorted([blocks[1], blocks[2]]))
        self.assertEqual(len(ivals), 2)
Beispiel #3
0
def dataflow(func, env, sync_context=True):
    """
    Move all allocas to the start block and then use pykit's SSA pass.
    We can move all allocas since all our objects are immutable
    """
    allocas = [op for op in func.ops if op.opcode == 'alloca']
    cfa.move_allocas(func, allocas)

    CFG = cfa.cfg(func)
    phis = cfa.ssa(func, CFG)

    if sync_context:
        context = env['flypy.typing.context']
        for phi, alloc in phis.iteritems():
            type = context[alloc]
            context[phi] = type
            for arg in phi.args[1]:
                if isinstance(arg, Undef):
                    context[arg] = type
Beispiel #4
0
def dataflow(func, env, sync_context=True):
    """
    Move all allocas to the start block and then use pykit's SSA pass.
    We can move all allocas since all our objects are immutable
    """
    allocas = [op for op in func.ops if op.opcode == 'alloca']
    cfa.move_allocas(func, allocas)

    CFG = cfa.cfg(func)
    phis = cfa.ssa(func, CFG)

    if sync_context:
        context = env['flypy.typing.context']
        for phi, alloc in phis.iteritems():
            type = context[alloc]
            context[phi] = type
            for arg in phi.args[1]:
                if isinstance(arg, Undef):
                    context[arg] = type