⚠️ THIS PROJECT IS NO LONGER MAINTAINED ⚠️
If your compiler emits pure lowercase Z80 mnemonics (ld, jp, jr), use
upeepz80 instead — it is the maintained
optimizer for that input.
upeep80 remains here for compilers that emit 8080 mnemonics (MOV, MVI,
LXI) needing translation to Z80; upeepz80 does not handle that case.
upeep80 - Universal Peephole Optimizer for 8080/Z80 (ARCHIVED)
A language-agnostic optimization library for 8080 and Z80 compilers.
Overview
upeep80 provides high-quality optimization passes for compilers targeting the Intel 8080 and Zilog Z80 processors. The library is designed to be reusable across different source languages.
Features
AST-Level Optimizations
- Constant Folding: Evaluate compile-time constant expressions
- Constant Propagation: Replace variables with their constant values
- Algebraic Simplification: x+0=x, x1=x, x0=0, etc.
- Strength Reduction: Replace expensive operations with cheaper equivalents
- Multiply/divide by power-of-2 → shifts
- Modulo by power-of-2 → bitwise AND
- Dead Code Elimination: Remove unreachable code
- Common Subexpression Elimination (CSE): Eliminate redundant calculations
- Copy Propagation: Track variable aliases
- Dead Store Elimination: Remove unused assignments
- Loop Optimizations:
- Loop-invariant code motion
- Loop unrolling (configurable)
- Boolean Simplification: x=x→true, x<>x→false
- Procedure Inlining: Inline small procedures
Peephole Optimizations
- Pattern-based optimization on Z80 assembly
- Redundant load/store elimination
- Jump optimization (including relative jumps for Z80)
- Stack operation combining
- Register allocation cleanup
- 8080 to Z80 mnemonic translation
Optimization Levels
- Level 0: No optimization
- Level 1: Basic (constant folding, algebraic simplification)
- Level 2: Standard (+ strength reduction, dead code elimination)
- Level 3: Aggressive (+ CSE, loop optimizations, inlining)
Optimization Targets
- Speed: Optimize for execution speed
- Size: Optimize for code size
- Balanced: Balance between speed and size
Installation
pip install upeep80
Or for development:
git clone https://github.com/avwohl/upeep80.git
cd upeep80
pip install -e ".[dev]"
Usage
AST Optimization
from upeep80 import ASTOptimizer, OptimizeFor
# Create optimizer
optimizer = ASTOptimizer(
opt_level=2,
optimize_for=OptimizeFor.BALANCED
)
# Optimize your AST
optimized_ast = optimizer.optimize(ast_tree)
# Check statistics
print(f"Constants folded: {optimizer.stats.constants_folded}")
print(f"Dead code eliminated: {optimizer.stats.dead_code_eliminated}")
Peephole Optimization
from upeep80 import PeepholeOptimizer, Target
# Create optimizer
optimizer = PeepholeOptimizer(
target=Target.Z80,
opt_level=2
)
# Optimize assembly code
optimized_asm = optimizer.optimize(assembly_lines)
# Check statistics
print(f"Patterns applied: {optimizer.stats.patterns_applied}")
print(f"Instructions eliminated: {optimizer.stats.instructions_eliminated}")
Architecture
upeep80 is designed to be language-agnostic:
AST Optimizer
- Works on generic expression trees
- Requires minimal AST node interface:
- Binary/unary expressions
- Literals (integer, real)
- Identifiers
- Statements (assignment, if, loop, etc.)
- Can be adapted to any language's AST
Peephole Optimizer
- Works directly on assembly text
- No knowledge of source language required
- Pattern-based transformation engine
- Configurable for 8080 or Z80 targets
Used By
Documentation
Development
Running Tests
pytest
Type Checking
mypy upeep80
Code Formatting
black upeep80
ruff check upeep80
Performance
Benchmarks on typical compiler workloads:
- AST optimization: ~10,000 nodes/second
- Peephole optimization: ~50,000 instructions/second
- Memory usage: ~100MB for typical compilation unit
Contributing
Contributions are welcome. Open an issue or a pull request.
License
This project is licensed under the GNU General Public License v2.0 - see LICENSE for details.
History
upeep80 was extracted from the uplm80 project to provide a reusable optimization library for multiple retro compiler projects targeting the 8080/Z80 architecture.
Acknowledgments
- Optimization techniques based on classic compiler optimization literature
- Pattern-based peephole optimization inspired by Davidson & Fraser's work
- Z80 instruction set reference from z80.info
See Also
- uplm80 - PL/M-80 compiler
- uada80 - Ada compiler for Z80
- Z80 CPU User Manual
Release files for upeep80 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| upeep80-0.2.1.tar.gz | 43.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| upeep80-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 84.2 kB
Release files / upeep80-0.2.1.tar.gz
| Download URL | upeep80-0.2.1.tar.gz |
|---|---|
| Size | 43.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bfb6d67825fec9ba73e2cde793078e221344735b7c658b486b947e91310ef383
|
|
BLAKE2b-256 checksum How to use checksums |
6e9076dda5f3ed76a82d03a91b1e882f9cdcdade50297b8196d23bb2712aba6c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.
Transparency logRelease files / upeep80-0.2.1-py3-none-any.whl
| Download URL | upeep80-0.2.1-py3-none-any.whl |
|---|---|
| Size | 40.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a46a02a3800369694285eb3a165eda7006ecb086e3c9da66e5ad81b12a9453b5
|
|
BLAKE2b-256 checksum How to use checksums |
935ed6d4db5efc14535040c524d592bcb1128c6d55fae97b699626e5f81ebaa9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.
Transparency log