Ajout du code pour la Liveness
This commit is contained in:
parent
ec366c8e07
commit
2c50bbaaa0
@ -48,16 +48,27 @@ class LivenessSSA:
|
|||||||
|
|
||||||
def liveout_at_block(self, block: Block, var: Temporary) -> None:
|
def liveout_at_block(self, block: Block, var: Temporary) -> None:
|
||||||
"""Backward propagation of liveness information at a block."""
|
"""Backward propagation of liveness information at a block."""
|
||||||
raise NotImplementedError("LivenessSSA") # TODO (Lab 5b, Exercise 1)
|
if(not var in self._seen[block]):
|
||||||
|
self._seen[block].add(var)
|
||||||
|
self.liveout_at_instruction(block,len(block.get_body_and_terminator())-1,var)
|
||||||
|
|
||||||
def liveout_at_instruction(self, block: Block, pos: int, var: Temporary) -> None:
|
def liveout_at_instruction(self, block: Block, pos: int, var: Temporary) -> None:
|
||||||
"""Backward propagation of liveness information at a non-phi instruction."""
|
"""Backward propagation of liveness information at a non-phi instruction."""
|
||||||
instr = block.get_body_and_terminator()[pos]
|
instr = block.get_body_and_terminator()[pos]
|
||||||
raise NotImplementedError("LivenessSSA") # TODO (Lab 5b, Exercise 1)
|
self._liveout[instr].add(var)
|
||||||
|
if (not var in instr.defined()):
|
||||||
|
self.livein_at_instruction(block,pos,var)
|
||||||
|
|
||||||
def livein_at_instruction(self, block: Block, pos: int, var: Temporary) -> None:
|
def livein_at_instruction(self, block: Block, pos: int, var: Temporary) -> None:
|
||||||
"""Backward propagation of liveness information at a non-phi instruction."""
|
"""Backward propagation of liveness information at a non-phi instruction."""
|
||||||
raise NotImplementedError("LivenessSSA") # TODO (Lab 5b, Exercise 1)
|
if(pos==0):
|
||||||
|
for phiS in block._phis:
|
||||||
|
self._liveout[phiS].add(var)
|
||||||
|
for predBlock in self._cfg.get_blocks():
|
||||||
|
if block in self._cfg.out_blocks(predBlock):
|
||||||
|
self.liveout_at_block(predBlock,var)
|
||||||
|
else:
|
||||||
|
self.liveout_at_instruction(block,pos-1,var)
|
||||||
|
|
||||||
def gather_uses(self) -> Dict[Temporary, Set[Tuple[Block, int | None, Statement]]]:
|
def gather_uses(self) -> Dict[Temporary, Set[Tuple[Block, int | None, Statement]]]:
|
||||||
"""
|
"""
|
||||||
@ -85,7 +96,11 @@ class LivenessSSA:
|
|||||||
|
|
||||||
def conflict_on_phis(self) -> None:
|
def conflict_on_phis(self) -> None:
|
||||||
"""Ensures that variables defined by phi instructions are in conflict with one-another."""
|
"""Ensures that variables defined by phi instructions are in conflict with one-another."""
|
||||||
raise NotImplementedError("LivenessSSA") # TODO (Lab 5b, Exercise 1)
|
for block in self._cfg.get_blocks():
|
||||||
|
varSets = set()
|
||||||
|
for phiS in block._phis:
|
||||||
|
varSets.add(phiS.defined()[0])
|
||||||
|
self._liveout[phiS] = self._liveout[phiS].union(varSets)
|
||||||
|
|
||||||
def print_map_in_out(self) -> None: # pragma: no cover
|
def print_map_in_out(self) -> None: # pragma: no cover
|
||||||
"""Print live out sets at each instruction, group by block, useful for debugging!"""
|
"""Print live out sets at each instruction, group by block, useful for debugging!"""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user