Skip to content

Commit

Permalink
fix stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Sep 29, 2024
1 parent 575478f commit f000e09
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
7 changes: 3 additions & 4 deletions vyper/venom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ def _run_passes(fn: IRFunction, optimize: OptimizationLevel) -> None:

FunctionInlinerPass(ac, fn).run_pass()

fn.remove_unreachable_blocks()
return

RemoveUnusedVariablesPass(ac, fn).run_pass()
StoreElimination(ac, fn).run_pass()

SimplifyCFGPass(ac, fn).run_pass()
MakeSSA(ac, fn).run_pass()
Expand All @@ -70,6 +69,6 @@ def generate_ir(ir: IRnode, optimize: OptimizationLevel) -> IRContext:
for fn in ctx.functions.values():
_run_passes(fn, optimize)

#ctx.prune_unreachable_functions()
ctx.prune_unreachable_functions()

return ctx
26 changes: 10 additions & 16 deletions vyper/venom/passes/function_inliner.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,9 @@ def _handle_invoke(self, invoke_inst, invoke_idx):
inst.parent = new_bb
new_bb.instructions.append(inst)

new_var = fn.get_next_variable()
var_map[inst.output] = new_var


for j, op in enumerate(inst.operands):
if isinstance(op, IRVariable):
inst.operands[j] = var_map[inst.operands[j]]
inst.operands[j] = var_map[op]
if inst.opcode in CFG_ALTERING_INSTRUCTIONS and isinstance(op, IRLabel):
inst.operands[j] = label_map[op]

Expand All @@ -90,18 +86,16 @@ def _handle_invoke(self, invoke_inst, invoke_idx):
inst.output = None
if inst.opcode.startswith("palloca"):
alloca_id = tuple(inst.operands)
var_map[inst.output] = self._alloca_map[alloca_id].output
print("ENTER0", var_map[inst.output], inst)
inst.opcode = "nop"
inst.operands = []
inst.output = None
inst.opcode = "store"
inst.operands = [self._alloca_map[alloca_id].output]
if inst.opcode == "param":
var_map[inst.output] = invoke_inst.operands[-i-1]
#print("ENTER", var_map[inst.output], inst)
inst.opcode = "nop"
inst.operands = []
inst.output = None
#print("ENTER", inst)
inst.opcode = "store"
op = invoke_inst.operands[-i-1]
inst.operands = [invoke_inst.operands[-i-1]]

new_var = fn.get_next_variable()
var_map[inst.output] = new_var
inst.output = new_var

fn.append_basic_block(new_bb)
self.worklist.append(new_bb)
Expand Down
1 change: 1 addition & 0 deletions vyper/venom/passes/remove_unused_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def run_pass(self):
self._process_instruction(inst)

self.analyses_cache.invalidate_analysis(LivenessAnalysis)
self.analyses_cache.invalidate_analysis(DFGAnalysis)

def _process_instruction(self, inst):
if inst.output is None:
Expand Down
2 changes: 1 addition & 1 deletion vyper/venom/passes/sccp/sccp.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _handle_SSA_work_item(self, work_item: SSAWorkListItem):
self._visit_expr(work_item.inst)

def _lookup_from_lattice(self, op: IROperand) -> LatticeItem:
assert isinstance(op, IRVariable), "Can't get lattice for non-variable"
assert isinstance(op, IRVariable), op
lat = self.lattice[op]
assert lat is not None, f"Got undefined var {op}"
return lat
Expand Down

0 comments on commit f000e09

Please sign in to comment.