-
Notifications
You must be signed in to change notification settings - Fork 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
Branch optimization #7
Conversation
be9bb87
to
ccffa67
Compare
This needs evidence that it's faster on a simple program with some huge basic blocks. |
Please rebase this on the latest master so I can more effectively review it. |
e9ddac3
to
9de63f0
Compare
Deleting `#br_aux` Storing the whole cell and using with continuation
9de63f0
to
476baf0
Compare
Done! |
For some reason that I couldn't spot easily, after my changes, poetry -C pykwasm run -- kwasm run tests/wasm-tests/test/core/call.wast > tests/wasm-tests/test/core/call.wast.llvm-out
/home/robertorosmaninho/rv/k/k-distribution/bin/../lib/kframework/k-util.sh: line 114: 1037198 Bus error (core dumped) "$@"
[Error] krun:
/home/robertorosmaninho/.cache/kdist-efbf2fa/wasm-semantics/llvm/interpreter
/tmp/.krun-2024-08-08-21-47-27-pYn6dr884r/tmp.in.PMv6wHOLHm -1
/tmp/.krun-2024-08-08-21-47-27-pYn6dr884r/result.kore
Syntax error at /tmp/.krun-2024-08-08-21-47-27-pYn6dr884r/result.kore:1.135162-135168: Expected: [:, {] Actual: <EOF>
[Error] krun: kore-print --definition
/home/robertorosmaninho/.cache/kdist-efbf2fa/wasm-semantics/llvm --output
pretty /tmp/.krun-2024-08-08-21-47-27-pYn6dr884r/result.kore --color off
make: *** [Makefile:51: tests/wasm-tests/test/core/call.wast.run-term] Error 255 |
This looks about what I expected. It's unfortunate that this doesn't end up helping performance, but I guess it's good that the existing code wasn't that bad in the first place. |
FIX: #1588
This PR implements a branch continuation optimization. Previously, we were popping values in the
<instrs>
cell once we found abr
instruction without a label after it, and once we found a label if theIDX
of the br instruction wasn't0
, we rewrote it until reaching the base case. This was fairly time-consuming and inefficient.This new optimization addresses the two issues by sacrificing space efficiency. Here, we introduce a new K list cell,
labels
, which contains the whole state continuation of a block. So, right now, instead of popping instructions, we just replace the whole<instr>
cell, and instead of rewriting thebr
instruction until it reaches the base case, we just use the list index to "jump" to the correct block and pop the others using therange
hook.So, in programs that don't have many changes in control flow, we may have some slowdown. However, for programs that contain such cases, we expect to see some great speedups.