-
Notifications
You must be signed in to change notification settings - Fork 0
[IN] Global register allocator #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
142 commits
Select commit
Hold shift + click to select a range
e2c962b
legacy code removed
matgla 9285e60
working on ir code generation
matgla c241cc0
wip
matgla 5c80815
wip
matgla 44c8398
wip
matgla dd6006f
fixed bug in local variable assignment
matgla dc961db
working on ir
matgla 6a67a66
more examples
matgla 1f7c870
wip
matgla 914d1ee
hello world example is running fine
matgla fdeeebb
trying to add qemu
matgla ecf710e
tinycc produces working hello world
matgla 069f966
trying to add test
matgla 235649c
working on tests
matgla 6dd0d74
working on tests
matgla f80724d
working on if support
matgla f809bde
first basic tests are working, added linker script support with copil…
matgla d312a61
more tests are working
matgla b8eb7cd
added a lot of fixes, array tests is still failing
matgla 218bb07
more fixes, arrays to be fixed
matgla e2b013e
fixed stubs lines processing, fixed 05_array test
matgla 1578535
fixed switch/case
matgla 60a2c20
fixed while and do/while
matgla e52b1bd
fixed all tests except pointers
matgla 4d9566b
pointers partially fixed, but global structs access is wrong
matgla f74d459
literal pool access optimization, part one
matgla 8f5777f
fixed struct test case, data is now correctly handled in linker
matgla b1c9042
added more tests
matgla 038e09d
fixed precedence tests
matgla 4c6f113
added more tests for logical operations
matgla 7fe1a21
fixed recursive example
matgla d7a4d55
debugging 21_char_array
matgla 00f0592
working on float support, a lot of failures are now in code
matgla 493e207
huge refactoring is ongoing, to add support for long long type and ba…
matgla 29ec676
fixed nested calls
matgla e1db635
fixed more tests
matgla 89094d1
fixed tests, working on long long support, which is needed for softfp…
matgla c3d4fb9
fixed bugs, so no all added tests are running
matgla 59d4b48
wip hanoi
matgla cfb7d73
refactoring of spilling
matgla 0004846
load refactoring
matgla 78f2fa5
wip, hanoi fails again
matgla 4921ca3
added scratch register allocator
matgla 9e90c48
fixed all existing tests
matgla 2926449
removed some hardcoded registers usage
matgla fab0136
more tests
matgla 7be3d90
added store cache to remove unnecessary loads
matgla c701481
fixed 33_tenary
matgla 4ecb05c
trying to fix 42_function_pointer, still one crash exists
matgla b3fa570
huge refactoring, few tests are still failing
matgla 1ffabf6
few next fixes
matgla 9d3a93b
hard fault refactoring ongoing
matgla 94da32a
fix for macos
matgla b9cdada
fixed macos
matgla d407502
fix for leaf functions
matgla 64ad658
wip
matgla 1d39c73
fixed tests before refactoring continue
matgla ea034f8
fixed tests
matgla 0cc73cc
refactoring ongoing
matgla ded7da8
wip
matgla 06380ff
refactoring ongoing
matgla a0dbe10
PREG_SPILL refactoring ongoing
matgla 5893107
wip
matgla 583a281
function fails, arguments passing needs to be refactored:
matgla b8df2fd
wip
matgla 7596bff
WIP
matgla 13d4de3
fixed nested calls
matgla f1c9908
all tests are passing now
matgla 45fc3f9
materialization refactoring
matgla 9eac39e
refactoring ongoing
matgla 7b0263f
store refactoring
matgla 9833b2f
wip
matgla f55daea
added profiling results
matgla eea0929
some optimizations
matgla 3727995
fixed struct support
matgla d7db9b5
fixed few things
matgla 1a4625e
fixed llong divisions
matgla a873aa5
fixed switch case handling
matgla fbbf849
fixed floating point support
matgla c6648ac
fixed double test
matgla c2bbb2c
working on fix for 101_cleanup
matgla bcd050b
debugging printf problem
matgla 8c4e1da
restored requirements
matgla 3d6c65f
added pexpect
matgla 681952d
added tests for aeabi
matgla 1fcb1ab
working on double support fixes
matgla f7b93d3
fixed double printf
matgla a2790e1
added new tests to regression
matgla 4aec5b8
fixed doubles
matgla 68e37ce
better profiler
matgla bc91d80
cleanup
matgla 7f42573
fixed tests onmacos
matgla c0058b6
SValue porting ongoing
matgla 7388fcb
Moved to compact instructions
matgla b9e5860
fixed compilation
matgla eaa4a68
added ubsan
matgla 34d0aca
fixed all tests
matgla 8eb259d
fixed compilation
matgla 05c403d
removed pr0_reserved access
matgla a5d3e70
tests are now passing, but svalue->r still needs bits for register fo…
matgla bcb09b2
just before phase 3
matgla 3052a57
optimized IROperand
matgla bc1537a
optimized IR
matgla a395594
fixed macos compilation
matgla 8ce34f4
revert to SVAlue pool
matgla cb92ad4
refactoring ongoing
matgla 06028f8
porting ongoing
matgla 519573c
porting ongoing
matgla b6332f3
wip
matgla 3d84dcc
wip
matgla 068a7c9
fixed bug for returning 64-bit values
matgla 6468441
cleanup
matgla 25f0057
porting of store
matgla ab8ed64
refactoring ongoing
matgla 173a9f1
WIP
matgla 85b409f
fixes
matgla 955e58e
all tests are passing before full removal
matgla 90b7cc3
more optimization arrived
matgla f05c1fb
fixed bug with returns
matgla eb42383
benchmarking works
matgla 1c6a73e
fixes for benchmarks
matgla 8e93934
plan for next optimizations
matgla 5089e4b
refactoring of tccir
matgla d65c736
tccir split
matgla 72aecf0
updated plan
matgla cd490bf
added mla
matgla 242f034
added test for mla
matgla ac14a95
tests are working
matgla 22d614f
workflow
matgla 4acfdb5
mob
matgla aa88d6e
changed newlib
matgla 06941b9
fixes for ci
matgla bfc9929
wip
matgla e71587c
changed workflow to use container
matgla 3ee5558
ci fix
matgla 1ce7886
permission change
matgla 4dffbf6
aa
matgla 66ee46f
m
matgla 2d48b45
some fixes
matgla adfad8a
wip
matgla f72ddd2
compilation on macos
matgla 649bfdd
safety fix
matgla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,10 @@ | ||
| --- | ||
|
|
||
|
|
||
| BasedOnStyle: LLVM | ||
| ColumnLimit: 120 | ||
| AllowShortFunctionsOnASingleLine: None | ||
| BreakBeforeBraces: Allman | ||
|
|
||
| AccessModifierOffset: -2 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
| # Backup files | ||
| *~ | ||
| *.swp | ||
| *.swo | ||
| *.bak | ||
|
|
||
| # OS files | ||
| .DS_Store | ||
| Thumbs.db |
Empty file.
25 changes: 25 additions & 0 deletions
25
.github/prompts/plan-aliasAnalysisStoreLoadOptimizations.prompt.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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": [] | ||
| } | ||
| ] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BreakBeforeBraces: Allmanconflicts with the brace style documented inAGENTS.md(K&R style). This will cause churn and inconsistent formatting expectations. Align the documented style and.clang-formatsettings (either update the docs to Allman or adjust.clang-formatto match the documented K&R approach).