Skip to content

Commit

Permalink
perf: speed up codegen (#48)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Adam Chidlow <achidlow@users.noreply.github.com>
  • Loading branch information
daniel-makerx and achidlow authored Dec 20, 2023
1 parent 3f180ec commit 4c2ed03
Show file tree
Hide file tree
Showing 15 changed files with 378 additions and 373 deletions.
20 changes: 10 additions & 10 deletions examples/bytes_ops/puya.log

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/unssa/puya.log

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/voting/out/voting.approval_unoptimized.debug.teal

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions examples/with_reentrancy/puya.log

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion src/puya/codegen/context.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
import attrs

from puya.codegen import ops as mir
from puya.codegen.vla import VariableLifetimeAnalysis
from puya.context import CompileContext
from puya.ir import models as ir
from puya.utils import attrs_extend


@attrs.frozen
@attrs.define
class ProgramCodeGenContext(CompileContext):
contract: ir.Contract
program: ir.Program

def for_subroutine(self, subroutine: mir.MemorySubroutine) -> "SubroutineCodeGenContext":
return attrs_extend(SubroutineCodeGenContext, self, subroutine=subroutine)


@attrs.define(frozen=False)
class SubroutineCodeGenContext(ProgramCodeGenContext):
subroutine: mir.MemorySubroutine
_vla: VariableLifetimeAnalysis | None = attrs.field(default=None)

@property
def vla(self) -> VariableLifetimeAnalysis:
if self._vla is None:
self._vla = VariableLifetimeAnalysis.analyze(self.subroutine)
return self._vla

def invalidate_vla(self) -> None:
self._vla = None
1 change: 1 addition & 0 deletions src/puya/codegen/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def __str__(self) -> str:
return f"pop {self.n}"


@t.final
@attrs.frozen(eq=False, init=False)
class VirtualStackOp(BaseOp):
original: Sequence[BaseOp]
Expand Down
Loading

0 comments on commit 4c2ed03

Please sign in to comment.