<commit_before>from typing import Set, Dict, Union

from hwt.hdl.operatorDefs import OpDefinition
from hwt.hdl.value import HValue
from hwt.pyUtils.uniqList import UniqList
from hwtHls.hlsStreamProc.statements import HlsStreamProcRead
from hwtHls.ssa.basicBlock import SsaBasicBlock
from hwtHls.ssa.instr import SsaInstr
from hwtHls.ssa.phi import SsaPhi
from hwtHls.ssa.value import SsaValue
from hwtHls.ssa.transformation.ssaPass import SsaPass

_ValOrVal = (HValue, SsaValue)


class SsaPassConsystencyCheck(SsaPass):

    def visit_collect(self, bb: SsaBasicBlock, blocks: UniqList[SsaBasicBlock],
                      phis: UniqList[SsaPhi],
                      variables: Dict[SsaValue, SsaBasicBlock]):
        blocks.append(bb)
        for phi in bb.phis:
            phi: SsaPhi
            assert phi not in phis, ("phi has to be defined only once", phi, bb)
            assert phi.block is bb, ("phi has parent block correct", phi, phi.block, bb)
            phis.append(phi)
            assert phi not in variables, ("Each phi has to use unique value", phi, variables[phi])
            variables[phi] = phi
            for _, src_block in  phi.operands:
                assert src_block in bb.predecessors, (phi, src_block, bb.predecessors)<commit_msg>SsaPassConsystencyCheck: phis mus have more than 1 arg<commit_after>from typing import Set, Dict, Union

from hwt.hdl.operatorDefs import OpDefinition
from hwt.hdl.value import HValue
from hwt.pyUtils.uniqList import UniqList
from hwtHls.hlsStreamProc.statements import HlsStreamProcRead
from hwtHls.ssa.basicBlock import SsaBasicBlock
from hwtHls.ssa.instr import SsaInstr
from hwtHls.ssa.phi import SsaPhi
from hwtHls.ssa.value import SsaValue
from hwtHls.ssa.transformation.ssaPass import SsaPass

_ValOrVal = (HValue, SsaValue)


class SsaPassConsystencyCheck(SsaPass):

    def visit_collect(self, bb: SsaBasicBlock, blocks: UniqList[SsaBasicBlock],
                      phis: UniqList[SsaPhi],
                      variables: Dict[SsaValue, SsaBasicBlock]):
        blocks.append(bb)
        for phi in bb.phis:
            phi: SsaPhi
            assert phi not in phis, ("phi has to be defined only once", phi, bb)
            assert phi.block is bb, ("phi has parent block correct", phi, phi.block, bb)
            phis.append(phi)
            assert phi not in variables, ("Each phi has to use unique value", phi, variables[phi])
            assert len(phi.operands) >= 2, ("Each phi is not trivial", phi, phi.operands)
            variables[phi] = phi
            for _, src_block in  phi.operands:
                assert src_block in bb.predecessors, (phi, src_block, bb.predecessors)
{'fraction_non_alphanumeric': 0.07804878048780488, 'fraction_numerical': 0.00075046904315197, 'mean_word_length': 2.985052316890882, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2219660', 'n_tokens_mistral': 896, 'n_tokens_neox': 852, 'n_words': 254}