From 3a1b77ae6ba87287f8665f82c06c1d99c62966d0 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sun, 1 Nov 2015 09:49:39 +0300 Subject: [PATCH] analyses.domination: add PostDominatorTree. --- artiq/compiler/analyses/domination.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/artiq/compiler/analyses/domination.py b/artiq/compiler/analyses/domination.py index 7fbd4d231..50aacc52d 100644 --- a/artiq/compiler/analyses/domination.py +++ b/artiq/compiler/analyses/domination.py @@ -37,3 +37,30 @@ class DominatorTree: if not changed: break + +class PostDominatorTree: + def __init__(self, func): + exits = [block for block in func.basic_blocks if none(block.successors())] + + self.dominated_by = { exit: {exit} for exit in exits } + for block in func.basic_blocks: + if block != entry: + self.dominated_by[block] = set(func.basic_blocks) + + successors = {block: block.successors() for block in func.basic_blocks} + while True: + changed = False + + for block in func.basic_blocks: + if block in exits: + continue + + new_dominated_by = {block}.union( + reduce(lambda a, b: a.intersection(b), + (self.dominated_by[pred] for pred in successors[block]))) + if new_dominated_by != self.dominated_by[block]: + self.dominated_by[block] = new_dominated_by + changed = True + + if not changed: + break