Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
142 commits
Select commit Hold shift + click to select a range
e2c962b
legacy code removed
matgla Dec 6, 2025
9285e60
working on ir code generation
matgla Dec 8, 2025
c241cc0
wip
matgla Dec 8, 2025
5c80815
wip
matgla Dec 9, 2025
44c8398
wip
matgla Dec 9, 2025
dd6006f
fixed bug in local variable assignment
matgla Dec 10, 2025
dc961db
working on ir
matgla Dec 11, 2025
6a67a66
more examples
matgla Dec 11, 2025
1f7c870
wip
matgla Dec 14, 2025
914d1ee
hello world example is running fine
matgla Dec 14, 2025
fdeeebb
trying to add qemu
matgla Dec 15, 2025
ecf710e
tinycc produces working hello world
matgla Dec 15, 2025
069f966
trying to add test
matgla Dec 15, 2025
235649c
working on tests
matgla Dec 17, 2025
6dd0d74
working on tests
matgla Dec 17, 2025
f80724d
working on if support
matgla Dec 18, 2025
f809bde
first basic tests are working, added linker script support with copil…
matgla Dec 20, 2025
d312a61
more tests are working
matgla Dec 21, 2025
b8eb7cd
added a lot of fixes, array tests is still failing
matgla Dec 22, 2025
218bb07
more fixes, arrays to be fixed
matgla Dec 23, 2025
e2b013e
fixed stubs lines processing, fixed 05_array test
matgla Dec 23, 2025
1578535
fixed switch/case
matgla Dec 23, 2025
60a2c20
fixed while and do/while
matgla Dec 24, 2025
e52b1bd
fixed all tests except pointers
matgla Dec 24, 2025
4d9566b
pointers partially fixed, but global structs access is wrong
matgla Dec 24, 2025
f74d459
literal pool access optimization, part one
matgla Dec 24, 2025
8f5777f
fixed struct test case, data is now correctly handled in linker
matgla Dec 24, 2025
b1c9042
added more tests
matgla Dec 25, 2025
038e09d
fixed precedence tests
matgla Dec 27, 2025
4c6f113
added more tests for logical operations
matgla Dec 27, 2025
7fe1a21
fixed recursive example
matgla Dec 27, 2025
d7a4d55
debugging 21_char_array
matgla Dec 27, 2025
00f0592
working on float support, a lot of failures are now in code
matgla Dec 28, 2025
493e207
huge refactoring is ongoing, to add support for long long type and ba…
matgla Dec 29, 2025
29ec676
fixed nested calls
matgla Dec 29, 2025
e1db635
fixed more tests
matgla Dec 30, 2025
89094d1
fixed tests, working on long long support, which is needed for softfp…
matgla Dec 31, 2025
c3d4fb9
fixed bugs, so no all added tests are running
matgla Jan 2, 2026
59d4b48
wip hanoi
matgla Jan 2, 2026
cfb7d73
refactoring of spilling
matgla Jan 3, 2026
0004846
load refactoring
matgla Jan 3, 2026
78f2fa5
wip, hanoi fails again
matgla Jan 3, 2026
4921ca3
added scratch register allocator
matgla Jan 3, 2026
9e90c48
fixed all existing tests
matgla Jan 3, 2026
2926449
removed some hardcoded registers usage
matgla Jan 3, 2026
fab0136
more tests
matgla Jan 4, 2026
7be3d90
added store cache to remove unnecessary loads
matgla Jan 4, 2026
c701481
fixed 33_tenary
matgla Jan 4, 2026
4ecb05c
trying to fix 42_function_pointer, still one crash exists
matgla Jan 4, 2026
b3fa570
huge refactoring, few tests are still failing
matgla Jan 6, 2026
1ffabf6
few next fixes
matgla Jan 6, 2026
9d3a93b
hard fault refactoring ongoing
matgla Jan 6, 2026
94da32a
fix for macos
matgla Jan 6, 2026
b9cdada
fixed macos
matgla Jan 6, 2026
d407502
fix for leaf functions
matgla Jan 6, 2026
64ad658
wip
matgla Jan 8, 2026
1d39c73
fixed tests before refactoring continue
matgla Jan 8, 2026
ea034f8
fixed tests
matgla Jan 8, 2026
0cc73cc
refactoring ongoing
matgla Jan 8, 2026
ded7da8
wip
matgla Jan 9, 2026
06380ff
refactoring ongoing
matgla Jan 9, 2026
a0dbe10
PREG_SPILL refactoring ongoing
matgla Jan 9, 2026
5893107
wip
matgla Jan 9, 2026
583a281
function fails, arguments passing needs to be refactored:
matgla Jan 10, 2026
b8df2fd
wip
matgla Jan 10, 2026
7596bff
WIP
matgla Jan 11, 2026
13d4de3
fixed nested calls
matgla Jan 11, 2026
f1c9908
all tests are passing now
matgla Jan 12, 2026
45fc3f9
materialization refactoring
matgla Jan 12, 2026
9eac39e
refactoring ongoing
matgla Jan 12, 2026
7b0263f
store refactoring
matgla Jan 12, 2026
9833b2f
wip
matgla Jan 13, 2026
f55daea
added profiling results
matgla Jan 13, 2026
eea0929
some optimizations
matgla Jan 13, 2026
3727995
fixed struct support
matgla Jan 14, 2026
d7db9b5
fixed few things
matgla Jan 14, 2026
1a4625e
fixed llong divisions
matgla Jan 14, 2026
a873aa5
fixed switch case handling
matgla Jan 14, 2026
fbbf849
fixed floating point support
matgla Jan 15, 2026
c6648ac
fixed double test
matgla Jan 16, 2026
c2bbb2c
working on fix for 101_cleanup
matgla Jan 16, 2026
bcd050b
debugging printf problem
matgla Jan 17, 2026
8c4e1da
restored requirements
matgla Jan 17, 2026
3d6c65f
added pexpect
matgla Jan 17, 2026
681952d
added tests for aeabi
matgla Jan 18, 2026
1fcb1ab
working on double support fixes
matgla Jan 20, 2026
f7b93d3
fixed double printf
matgla Jan 20, 2026
a2790e1
added new tests to regression
matgla Jan 20, 2026
4aec5b8
fixed doubles
matgla Jan 20, 2026
68e37ce
better profiler
matgla Jan 22, 2026
bc91d80
cleanup
matgla Jan 22, 2026
7f42573
fixed tests onmacos
matgla Jan 22, 2026
c0058b6
SValue porting ongoing
matgla Jan 22, 2026
7388fcb
Moved to compact instructions
matgla Jan 23, 2026
b9e5860
fixed compilation
matgla Jan 23, 2026
eaa4a68
added ubsan
matgla Jan 23, 2026
34d0aca
fixed all tests
matgla Jan 23, 2026
8eb259d
fixed compilation
matgla Jan 23, 2026
05c403d
removed pr0_reserved access
matgla Jan 23, 2026
a5d3e70
tests are now passing, but svalue->r still needs bits for register fo…
matgla Jan 23, 2026
bcb09b2
just before phase 3
matgla Jan 24, 2026
3052a57
optimized IROperand
matgla Jan 24, 2026
bc1537a
optimized IR
matgla Jan 24, 2026
a395594
fixed macos compilation
matgla Jan 24, 2026
8ce34f4
revert to SVAlue pool
matgla Jan 24, 2026
cb92ad4
refactoring ongoing
matgla Jan 24, 2026
06028f8
porting ongoing
matgla Jan 25, 2026
519573c
porting ongoing
matgla Jan 25, 2026
b6332f3
wip
matgla Jan 25, 2026
3d84dcc
wip
matgla Jan 25, 2026
068a7c9
fixed bug for returning 64-bit values
matgla Jan 25, 2026
6468441
cleanup
matgla Jan 25, 2026
25f0057
porting of store
matgla Jan 25, 2026
ab8ed64
refactoring ongoing
matgla Jan 26, 2026
173a9f1
WIP
matgla Jan 26, 2026
85b409f
fixes
matgla Jan 27, 2026
955e58e
all tests are passing before full removal
matgla Jan 27, 2026
90b7cc3
more optimization arrived
matgla Jan 27, 2026
f05c1fb
fixed bug with returns
matgla Jan 31, 2026
eb42383
benchmarking works
matgla Jan 31, 2026
1c6a73e
fixes for benchmarks
matgla Jan 31, 2026
8e93934
plan for next optimizations
matgla Jan 31, 2026
5089e4b
refactoring of tccir
matgla Feb 1, 2026
d65c736
tccir split
matgla Feb 1, 2026
72aecf0
updated plan
matgla Feb 1, 2026
cd490bf
added mla
matgla Feb 1, 2026
242f034
added test for mla
matgla Feb 1, 2026
ac14a95
tests are working
matgla Feb 7, 2026
22d614f
workflow
matgla Feb 7, 2026
4acfdb5
mob
matgla Feb 7, 2026
aa88d6e
changed newlib
matgla Feb 7, 2026
06941b9
fixes for ci
matgla Feb 7, 2026
bfc9929
wip
matgla Feb 7, 2026
e71587c
changed workflow to use container
matgla Feb 7, 2026
3ee5558
ci fix
matgla Feb 7, 2026
1ce7886
permission change
matgla Feb 7, 2026
4dffbf6
aa
matgla Feb 7, 2026
66ee46f
m
matgla Feb 7, 2026
2d48b45
some fixes
matgla Feb 7, 2026
adfad8a
wip
matgla Feb 7, 2026
f72ddd2
compilation on macos
matgla Feb 7, 2026
649bfdd
safety fix
matgla Feb 7, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
---


BasedOnStyle: LLVM
ColumnLimit: 120
AllowShortFunctionsOnASingleLine: None
BreakBeforeBraces: Allman
Copy link

Copilot AI Feb 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BreakBeforeBraces: Allman conflicts with the brace style documented in AGENTS.md (K&R style). This will cause churn and inconsistent formatting expectations. Align the documented style and .clang-format settings (either update the docs to Allman or adjust .clang-format to match the documented K&R approach).

Suggested change
BreakBeforeBraces: Allman
BreakBeforeBraces: Attach

Copilot uses AI. Check for mistakes.

AccessModifierOffset: -2

46 changes: 46 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Build artifacts
*.o
*.a
*.so
*.exe
armv8m-tcc
armv8m-*/

# Generated config files
config.h
config.mak
config.texi

# Virtual environments
.venv/
venv/

# Git
.git/
.gitignore

# IDE
.vscode/
.idea/

# Test artifacts
__pycache__/
*.pyc
.pytest_cache/
*.egg-info/
dist/
build/

# Documentation build artifacts
*.html
*.pdf

# Backup files
*~
*.swp
*.swo
*.bak

# OS files
.DS_Store
Thumbs.db
Empty file added .editorconfig
Empty file.
25 changes: 25 additions & 0 deletions .github/prompts/plan-aliasAnalysisStoreLoadOptimizations.prompt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## Plan: Phase 4 - Alias Analysis and Store/Load Optimizations

Implement store-load forwarding and redundant load/store elimination using a simple intra-procedural alias analysis to enable safe memory operation optimizations in the TinyCC IR.

### Steps

1. **Implement Memory Location Tracking in [tccir.c](tccir.c)** - Add data structures (`MemoryLocation`, `StoreEntry` hash table) to track recent store addresses and values, distinguishing stack locals (`VT_LOCAL`) from pointer-based accesses.

2. **Implement `tcc_ir_store_load_forwarding()` in [tccir.c](tccir.c)** - For `TCCIR_OP_LOAD` instructions, check if the address matches a tracked store entry; if so, replace the LOAD with an ASSIGN from the stored value.

3. **Implement Alias Analysis Invalidation Logic** - Invalidate store entries conservatively: clear all pointer-based entries on any unknown pointer store; clear all entries at basic block boundaries (`JUMP`, `JUMPIF`) and function calls (`FUNCCALLVOID`, `FUNCCALLVAL`); preserve provably non-aliasing stack locals.

4. **Implement `tcc_ir_redundant_store_elimination()` in [tccir.c](tccir.c)** - Remove stores to addresses that are overwritten before being read (dead stores to memory), using the same alias tracking infrastructure.

5. **Integrate Phase 4 into Optimization Pipeline in [tccgen.c](tccgen.c#L10027)** - Add `tcc_ir_store_load_forwarding()` and `tcc_ir_redundant_store_elimination()` after Phase 3 CSE, before final dead store elimination.

6. **Update [ir_optimization_plan.md](docs/ir_optimization_plan.md)** - Document Phase 4 implementation details, alias analysis rules, expected results for the `Move()` example, and mark as complete.

### Further Considerations

1. **Alias Precision Level?** Start with a conservative type-based approach (stack locals never alias pointer derefs) or implement offset-based tracking for array accesses? *Recommend: Start conservative, extend later.*

2. **Struct/Array Member Handling?** Track field offsets for structs (e.g., `dest[j-1]` vs `dest[j]` are different addresses)? *Recommend: Track base+offset pairs for indexed accesses.*

3. **Cross-Basic-Block Optimization?** Keep analysis local to basic blocks initially, or implement reaching-stores dataflow? *Recommend: Start with basic-block-local, simpler and safer.*
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI

on:
push:
branches: [mob]
pull_request:
branches: [mob]

jobs:
build-and-test:
runs-on: ubuntu-latest
permissions:
packages: read
container:
image: ghcr.io/matgla/tinycc-armv8m:latest
options: --user root
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Configure
run: ./configure --enable-cross --enable-O2

- name: Build and test
shell: bash
run: |
virtualenv .venv
source .venv/bin/activate
make test -j$(nproc)
60 changes: 60 additions & 0 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Build and Push Container Image

on:
push:
branches: [mob]
paths:
- 'Dockerfile'
- '.github/workflows/docker-build.yml'
workflow_dispatch:
inputs:
tag:
description: 'Image tag (default: latest)'
required: false
default: 'latest'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/tinycc-armv8m

jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ inputs.tag || 'latest' }}
type=sha,prefix=,suffix=,format=short

- name: Build and push image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,12 @@ tests/hello
tests/tests2/fred.txt
libtcc.dylib
build/
rootfs/
rootfs/
__pycache__/
tests/ir_tests/qemu/mps2-an505/newlib_build/
tests/ir_tests/profile_results
tests/ir_tests/profile_baselines

lib/fp/soft/test_aeabi_all
lib/fp/soft/test_dmul_host
lib/fp/soft/test_host
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
[submodule "tests/externals/c-testsuite"]
path = tests/externals/c-testsuite
url = https://github.com/c-testsuite/c-testsuite.git
[submodule "tests/ir_tests/qemu/mps2-an505/libs/newlib"]
path = tests/ir_tests/qemu/mps2-an505/libs/newlib
url = https://sourceware.org/git/newlib-cygwin.git
[submodule "tests/benchmarks/libs/pico-sdk"]
path = tests/benchmarks/libs/pico-sdk
url = https://github.com/raspberrypi/pico-sdk.git
[submodule "tests/benchmarks/mibench"]
path = tests/benchmarks/mibench
url = https://github.com/embecosm/mibench.git
23 changes: 23 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"TCC_TARGET_ARM=1",
"TCC_ARM_VFP=1",
"TCC_ARM_EABI=1",
"TCC_ARM_HARDFLOAT=1",
"TCC_TARGET_ARM_THUMB=1",
"TCC_TARGET_ARM_ARCHV8M=1"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "linux-clang-x64"
}
],
"version": 4
}
82 changes: 82 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/armv8m-tcc",
"args": [
"-dump-ir",
"-c",
"${workspaceFolder}/tests/ir_tests/simple0.c",
"-o",
"${workspaceFolder}/tests/ir_tests/simple0.o",
],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
},
{
"name": "QEMU mps2-an505 (gdb)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/tests/ir_tests/build/test_double_printf_literals.elf",
"MIMode": "gdb",
"miDebuggerPath": "arm-none-eabi-gdb",
"miDebuggerServerAddress": "localhost:1234",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
},
{
"name": "QEMU mps2-an505 (connect)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/tests/ir_tests/build/test_double_printf_literals.elf",
"MIMode": "gdb",
"miDebuggerPath": "arm-none-eabi-gdb",
"miDebuggerServerAddress": "localhost:1234",
"cwd": "${workspaceFolder}/tests/ir_tests/build",
"stopAtConnect": true,
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
32 changes: 32 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "QEMU: mps2-an505 (gdbserver)",
"type": "shell",
"command": "qemu-system-arm",
"args": [
"-machine",
"mps2-an505",
"-nographic",
"-semihosting",
"-kernel",
"${workspaceFolder}/tests/ir_tests/build/test_double_printf_literals.elf",
"-s",
"-S"
],
"isBackground": true,
"problemMatcher": []
},
{
"label": "QEMU: stop",
"type": "shell",
"command": "pkill",
"args": [
"-f",
"qemu-system-arm -machine mps2-an505"
],
"problemMatcher": []
}
]
}
Loading