Applies validations to a given function ir and returns a list of errors found.
(fn: FuncIR)
| 96 | |
| 97 | |
| 98 | def check_func_ir(fn: FuncIR) -> list[FnError]: |
| 99 | """Applies validations to a given function ir and returns a list of errors found.""" |
| 100 | errors = [] |
| 101 | |
| 102 | op_set = set() |
| 103 | |
| 104 | for block in fn.blocks: |
| 105 | if not block.terminated: |
| 106 | errors.append( |
| 107 | FnError(source=block.ops[-1] if block.ops else block, desc="Block not terminated") |
| 108 | ) |
| 109 | for op in block.ops[:-1]: |
| 110 | if isinstance(op, ControlOp): |
| 111 | errors.append(FnError(source=op, desc="Block has operations after control op")) |
| 112 | |
| 113 | if op in op_set: |
| 114 | errors.append(FnError(source=op, desc="Func has a duplicate op")) |
| 115 | op_set.add(op) |
| 116 | |
| 117 | errors.extend(check_op_sources_valid(fn)) |
| 118 | if errors: |
| 119 | return errors |
| 120 | |
| 121 | op_checker = OpChecker(fn) |
| 122 | for block in fn.blocks: |
| 123 | for op in block.ops: |
| 124 | op.accept(op_checker) |
| 125 | |
| 126 | return op_checker.errors |
| 127 | |
| 128 | |
| 129 | class IrCheckException(Exception): |
searching dependent graphs…