2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-25 11:18:27 +08:00

transforms.cfg_simplifier: implement.

This allows error reporting in LocalAccessValidator to proceed
even when the predecessor is an empty block with only a branch.
This commit is contained in:
whitequark 2015-12-29 02:13:44 +08:00
parent 57ebd57ddb
commit 8822db089f
3 changed files with 25 additions and 0 deletions

View File

@ -55,6 +55,7 @@ class Module:
artiq_ir_generator = transforms.ARTIQIRGenerator(engine=self.engine,
module_name=src.name,
ref_period=ref_period)
cfg_simplifier = transforms.CFGSimplifier(engine=self.engine)
dead_code_eliminator = transforms.DeadCodeEliminator(engine=self.engine)
local_access_validator = validators.LocalAccessValidator(engine=self.engine)
devirtualization = analyses.Devirtualization()
@ -70,6 +71,7 @@ class Module:
devirtualization.visit(src.typedtree)
self.artiq_ir = artiq_ir_generator.visit(src.typedtree)
artiq_ir_generator.annotate_calls(devirtualization)
cfg_simplifier.process(self.artiq_ir)
local_access_validator.process(self.artiq_ir)
dead_code_eliminator.process(self.artiq_ir)
interleaver.process(self.artiq_ir)

View File

@ -4,5 +4,6 @@ from .int_monomorphizer import IntMonomorphizer
from .iodelay_estimator import IODelayEstimator
from .artiq_ir_generator import ARTIQIRGenerator
from .dead_code_eliminator import DeadCodeEliminator
from .cfg_simplifier import CFGSimplifier
from .llvm_ir_generator import LLVMIRGenerator
from .interleaver import Interleaver

View File

@ -0,0 +1,22 @@
"""
:class:`CFGSimplifier` is a simple control flow graph
simplification transform: it removes empty basic blocks.
"""
from .. import ir
class CFGSimplifier:
def __init__(self, engine):
self.engine = engine
def process(self, functions):
for func in functions:
self.process_function(func)
def process_function(self, func):
for block in list(func.basic_blocks):
if len(block.instructions) == 1 and \
isinstance(block.terminator(), ir.Branch):
successor, = block.successors()
block.replace_all_uses_with(successor)
block.erase()