Mercurial > lcfOS
diff python/ppci/transform.py @ 316:56e6ff84f646
Fixed burn led demo
author | Windel Bouwman |
---|---|
date | Sat, 21 Dec 2013 13:13:26 +0100 |
parents | 6753763d3bec |
children | e30a77ae359b |
line wrap: on
line diff
--- a/python/ppci/transform.py Sat Dec 21 10:03:01 2013 +0100 +++ b/python/ppci/transform.py Sat Dec 21 13:13:26 2013 +0100 @@ -8,7 +8,7 @@ class FunctionPass: def __init__(self): - self.logger = logging.getLogger('optimize') + self.logger = logging.getLogger(str(self.__class__.__name__)) def run(self, ir): """ Main entry point for the pass """ @@ -116,27 +116,26 @@ else: constMap[k] = i.result for i in to_remove: - logging.debug('removing {}'.format(i)) + self.logger.debug('removing {}'.format(i)) bb.removeInstruction(i) class CleanPass(FunctionPass): def onFunction(self, f): - removeEmptyBasicBlocks(f) - + self.remove_empty_blocks(f) -def removeEmptyBlocks(f): - """ Remove empty basic blocks from function. """ - # If a block only contains a branch, it can be removed: - empty = lambda b: type(b.FirstInstruction) is ir.Jump - empty_blocks = list(filter(empty, f.Blocks)) - for b in empty_blocks: - # Update predecessors - preds = b.Predecessors - if b not in preds + [f.entry]: - # Do not remove if preceeded by itself - tgt = b.LastInstruction.target - for pred in preds: - pred.LastInstruction.changeTarget(b, tgt) - logging.debug('Removing empty block: {}'.format(b)) - f.removeBlock(b) + def remove_empty_blocks(self, f): + """ Remove empty basic blocks from function. """ + # If a block only contains a branch, it can be removed: + empty = lambda b: type(b.FirstInstruction) is ir.Jump + empty_blocks = list(filter(empty, f.Blocks)) + for b in empty_blocks: + # Update predecessors + preds = b.Predecessors + if b not in preds + [f.entry]: + # Do not remove if preceeded by itself + tgt = b.LastInstruction.target + for pred in preds: + pred.LastInstruction.changeTarget(b, tgt) + self.logger.debug('Removing empty block: {}'.format(b)) + f.removeBlock(b)