def map_instructions(kernel, insn_match, f): from loopy.context_matching import parse_match match = parse_match(insn_match) new_insns = [] for insn in kernel.instructions: if match(kernel, insn): new_insns.append(f(insn)) else: new_insns.append(insn) return kernel.copy(instructions=new_insns)
def tag_instructions(kernel, new_tag, within=None): from loopy.context_matching import parse_match within = parse_match(within) new_insns = [] for insn in kernel.instructions: if within(kernel, insn): new_insns.append( insn.copy(tags=insn.tags + (new_tag,))) else: new_insns.append(insn) return kernel.copy(instructions=new_insns)
def find_instructions(kernel, insn_match): from loopy.context_matching import parse_match match = parse_match(insn_match) return [insn for insn in kernel.instructions if match(kernel, insn)]