Skip to content
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

Integrate SSA-based middle-end and snapshot tests #85

Merged
merged 9 commits into from
Nov 27, 2023

Conversation

vacantron
Copy link
Collaborator

@vacantron vacantron commented Nov 11, 2023

The current cfront and IR generation are high coupling that making the flow analysis harder. To introduce the further optimizations, the static single assignment (SSA) is imperative. This patch introduces the minimal changes for it, and also keeps the old first phase IR (ph1_ir) for the compatibility to the upcoming works.

The current unit test only covers the end to end case. It is hard the classify which part went wrong in the compilation. The new middle end can dump the IR with the dot file as a snapshot. We can also use the tool like graphviz to check the flow during the compilation.

Use make check-snapshots to invoke the snapshot test, and use tests/update-snapshots.sh to update the snapshots if there's any change for the cfont.

Notice: The snapshots should be updated under the ARM configure.

@vacantron
Copy link
Collaborator Author

The GitHub Action reports the broken pipe if the snapshot testing failed. It works fine on my local PC and only reports Files /dev/fd/63 and /dev/fd/62 differ. Do I mess up something?

https://github.com/vacantron/shecc/actions/runs/6834732304/job/18587784272#step:3:467

@jserv
Copy link
Collaborator

jserv commented Nov 11, 2023

It is a bit confusing that there are 'check' and 'test' targets which deal with the test suite. Can you clarify?

src/defs.h Outdated Show resolved Hide resolved
src/globals.c Show resolved Hide resolved
Copy link
Collaborator

@jserv jserv left a comment

Choose a reason for hiding this comment

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

Rename src/SSA.c to src/ssa.c (lowercase).
Don't check in JSON files which are generated by snapshot.

@jserv
Copy link
Collaborator

jserv commented Nov 11, 2023

The GitHub Action reports the broken pipe if the snapshot testing failed. It works fine on my local PC and only reports Files /dev/fd/63 and /dev/fd/62 differ. Do I mess up something?

I got the following messages from CI:

int main(int argc, int argv) { int i; int j; i=0; j=0; while (i<10) { j=j+i; i=i+1; } return j; }
exit code => 45
output => 
tests/driver.sh: line 16:  3327 Segmentation fault      (core dumped) "$SHECC" -o "$tmp_exe" "$tmp_in"
int main(int argc, int argv) { int x; x=0; do {x = x + 1; break;} while (1); return x; }
exit code => 1
output => 
tests/driver.sh: line 16:  3334 Aborted                 (core dumped) "$SHECC" -o "$tmp_exe" "$tmp_in"
int main(int argc, int argv) { int x; x=0; do {x++; continue; abort();} while (x < 2); return x; } => 2 expected, but got 1
input: /tmp/tmp.gUdRxRqzMl.c
make: *** [Makefile:54: test] Error 1

@vacantron
Copy link
Collaborator Author

https://github.com/vacantron/shecc/actions/runs/6834732304/job/18587784272#step:3:467

I forgot to provide the error messages from GitHub Action:

tests/check-snapshots.sh
Files /dev/fd/63 and /dev/fd/62 differ
Error: writing output failed: Broken pipe
cat: write error: Broken pipe
Files /dev/fd/63 and /dev/fd/62 differ
make: *** [Makefile:54: check] Error 1
Error: writing output failed: Broken pipe
cat: write error: Broken pipe
Error: Process completed with exit code 1.

I got the following messages from CI:

That message was caused by the mentioned control-flow change. The snapshot testing had been passed. I edited lib/c.c and tried to cause the test failed and received the above messages.

Copy link
Collaborator

@jserv jserv left a comment

Choose a reason for hiding this comment

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

Drop the generated JSON file and update .gitignore.

src/defs.h Outdated Show resolved Hide resolved
@vacantron
Copy link
Collaborator Author

vacantron commented Nov 12, 2023

Drop the generated JSON file and update .gitignore.

We need some JSON files as the baseline of tests in tests/snapshots, right? The other snapshots that generated by mktemp when running check-snapshots are already not in the work directory.

src/defs.h Outdated Show resolved Hide resolved
src/main.c Outdated Show resolved Hide resolved
src/main.c Outdated Show resolved Hide resolved
src/main.c Outdated Show resolved Hide resolved
src/main.c Outdated Show resolved Hide resolved
src/ssa.c Outdated Show resolved Hide resolved
src/ssa.c Outdated Show resolved Hide resolved
src/defs.h Outdated Show resolved Hide resolved
src/defs.h Outdated Show resolved Hide resolved
src/cfront.c Outdated Show resolved Hide resolved
src/globals.c Outdated Show resolved Hide resolved
src/globals.c Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
src/cfront.c Outdated Show resolved Hide resolved
src/cfront.c Outdated Show resolved Hide resolved
@vacantron
Copy link
Collaborator Author

vacantron commented Nov 20, 2023

shecc now passes all the unit tests before, but the cfront lacks the support for some syntax, likes structure declaration without typedef. So the self-hosting still fails now.

The instructions which loads/stores with a huge offset also need to be modified when self-hosting.

The current unit test only covers the end to end case. It is hard
the classify which part went wrong in the compilation. The new middle
end can dump the IR with the dot file as a snapshot. We can also use
the tool like `graphviz` to check the flow during the compilation.

Use `make check-snapshots` to invoke the snapshot test, and use
`tests/update-snapshots.sh` to update the snapshots if there's any
change for the cfont.
@vacantron vacantron changed the title Enhance first phase IR and add snapshot testing Introduce SSA-based middle end and snapshot test Nov 25, 2023
@jserv jserv changed the title Introduce SSA-based middle end and snapshot test Integrate SSA-based middle-end and snapshot tests Nov 25, 2023
src/arm-codegen.c Outdated Show resolved Hide resolved
@vacantron vacantron marked this pull request as ready for review November 25, 2023 10:47
src/arm-codegen.c Outdated Show resolved Hide resolved
src/arm-codegen.c Outdated Show resolved Hide resolved
src/arm-codegen.c Outdated Show resolved Hide resolved
src/globals.c Outdated Show resolved Hide resolved
src/riscv-codegen.c Outdated Show resolved Hide resolved
src/riscv-codegen.c Outdated Show resolved Hide resolved
src/ssa.c Outdated Show resolved Hide resolved
src/ssa.c Show resolved Hide resolved
src/ssa.c Outdated Show resolved Hide resolved
src/ssa.c Outdated Show resolved Hide resolved
@jserv jserv requested a review from ChAoSUnItY November 25, 2023 10:58
- add TODO
- refine debug message
- move lengthy logic out of `bb_dump`
- move common statement out of if-else
src/defs.h Outdated Show resolved Hide resolved
Copy link
Collaborator

@jserv jserv left a comment

Choose a reason for hiding this comment

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

Let's unify our terminology. From now on, use insn as the abbreviation for "Instruction," rather than "inst."

src/ssa.c Show resolved Hide resolved
@jserv jserv merged commit 97d28e1 into sysprog21:master Nov 27, 2023
3 checks passed
@jserv
Copy link
Collaborator

jserv commented Nov 27, 2023

Thank @vacantron for contributing!

@vacantron vacantron deleted the middle-end/SSA branch November 28, 2023 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants