Skip to content

Commit

Permalink
remove global symbol copying
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Oct 21, 2024
1 parent b3ea663 commit 06b8533
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
4 changes: 4 additions & 0 deletions vyper/venom/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def chain_basic_blocks(self) -> None:
for fn in self.functions.values():
fn.chain_basic_blocks()

def float_allocas(self) -> None:
for fn in self.functions.values():
fn.float_allocas()

def append_data(self, opcode: str, args: list[IROperand]) -> None:
"""
Append data
Expand Down
19 changes: 19 additions & 0 deletions vyper/venom/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,25 @@ def chain_basic_blocks(self) -> None:
else:
bb.append_instruction("exit")

def float_allocas(self):
entry_bb = self.entry
assert entry_bb.is_terminated
tmp = entry_bb.instructions.pop()

for bb in self.get_basic_blocks():
if bb is entry_bb:
continue

# "fast" way to strip allocas from each basic block
def is_alloca(inst):
return inst.opcode in ("alloca", "palloca")

bb.instructions.sort(key=is_alloca)
while len(bb.instructions) > 0 and is_alloca(bb.instructions[-1]):
entry_bb.insert_instruction(bb.instructions.pop())

entry_bb.instructions.append(tmp)

def copy(self):
new = IRFunction(self.name)
new._basic_block_dict = self._basic_block_dict.copy()
Expand Down
12 changes: 5 additions & 7 deletions vyper/venom/ir_node_to_venom.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ def ir_node_to_venom(ir: IRnode) -> IRContext:

ctx.chain_basic_blocks()

# errors in make_ssa whether this is commented or not
#ctx.float_allocas()

return ctx


Expand Down Expand Up @@ -269,12 +272,14 @@ def _convert_ir_bb(fn, ir, symbols):
# Internal definition
var_list = ir.args[0].args[1]
does_return_data = IRnode.from_list(["return_buffer"]) in var_list.args
saved_global_symbols = _global_symbols
_global_symbols = {}
symbols = {}
new_fn = _handle_internal_func(fn, ir, does_return_data, symbols)
for ir_node in ir.args[1:]:
ret = _convert_ir_bb(new_fn, ir_node, symbols)

_global_symbols = saved_global_symbols
return ret
elif is_external:
ret = _convert_ir_bb(fn, ir.args[0], symbols)
Expand All @@ -297,8 +302,6 @@ def _convert_ir_bb(fn, ir, symbols):
cont_ret = _convert_ir_bb(fn, cond, symbols)
cond_block = fn.get_basic_block()

saved_global_symbols = _global_symbols.copy()

then_block = IRBasicBlock(ctx.get_next_label("then"), fn)
else_block = IRBasicBlock(ctx.get_next_label("else"), fn)

Expand All @@ -313,7 +316,6 @@ def _convert_ir_bb(fn, ir, symbols):

# convert "else"
cond_symbols = symbols.copy()
_global_symbols = saved_global_symbols.copy()
fn.append_basic_block(else_block)
else_ret_val = None
if len(ir.args) == 3:
Expand Down Expand Up @@ -342,8 +344,6 @@ def _convert_ir_bb(fn, ir, symbols):
if not then_block_finish.is_terminated:
then_block_finish.append_instruction("jmp", exit_bb.label)

_global_symbols = saved_global_symbols

return if_ret

elif ir.value == "with":
Expand Down Expand Up @@ -468,10 +468,8 @@ def emit_body_blocks():
global _break_target, _continue_target, _global_symbols
old_targets = _break_target, _continue_target
_break_target, _continue_target = exit_block, incr_block
saved_global_symbols = _global_symbols.copy()
_convert_ir_bb(fn, body, symbols.copy())
_break_target, _continue_target = old_targets
_global_symbols = saved_global_symbols

sym = ir.args[0]
start, end, _ = _convert_ir_bb_list(fn, ir.args[1:4], symbols)
Expand Down

0 comments on commit 06b8533

Please sign in to comment.