forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
WebAssembly Branch Hinting? #1
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
Closed
Changes from all commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
552d29c
naive start
kripken 7294127
more
kripken 80210db
bad
kripken 7005833
Revert "bad"
kripken d989daf
Revert "more"
kripken bf22519
Revert "naive start"
kripken 678e2d5
newPASS
kripken 7a715ca
work
kripken 9157b12
work
kripken 7a6be7a
work
kripken ae889b4
work
kripken 88f4554
work
kripken fd8359d
reading builds?
kripken d794e4b
reading builds
kripken 0b68888
debug
kripken 1d122a2
using MachineBasicBlock
kripken 817a8e9
clean
kripken 5917102
emit a tiny empty branch hint section from AsmPrinter
kripken a7b1648
start to emit a hint
kripken 9d25bf3
emit hint from emitInstruction
kripken 9e8a8f7
gather for the end
kripken b1a29d2
fix
kripken 66ec0df
clean
kripken 05f533d
clean
kripken 698f1b4
leb.all.the.things
kripken dc0b272
undo
kripken 9d58dc9
wasm-ld: reorder branch hints section earlier
kripken 99186de
lower-level API, emit fixups
kripken 45899d5
Revert "lower-level API, emit fixups"
kripken 56005e7
horrible hacks but the final binary seems valid
kripken 7aa75c5
Remove horrible hacks by changing the core LLVM API in MC*Streamer
kripken 67dec35
test
kripken 4943a23
test
kripken 08f259c
Move fixup to MCAsmBackend
kripken a5eff3f
Add failing .s test
kripken 3c2e694
Fix + test for llvm-mc
kripken 51f2ada
avoid emitting trivial branch hints
kripken 7d282ea
cleanup and emit even fewer hints
kripken e341863
Add a pass to prune branch_weights we don't want
kripken 86296cf
test fixes
kripken 4b96033
fix
kripken 1fab176
horrible hack
kripken c708aa8
horribler hack, but wasm tests finally pass
kripken 4784fb4
simplify using emitAbsoluteSymbolDiffAsULEB128
kripken dc305e3
awful attempts to find the proper mbb
kripken 3956ad6
fix tests
kripken ee54625
clenaup
kripken 8b60261
typo
kripken bb921ee
cleanup
kripken 96b80ce
comments
kripken 31b8996
wild and misguided effort to merge branch hint sections
kripken 0599b04
Handle some corner cases of wasm control flow
kripken c492b05
Get MBB/Terminator code to compile
kripken aee5b2a
almost get lld changes to compile
kripken 6b32791
lld compiles
kripken e98fc21
fix tests for padded num functions
kripken 46650d9
start new tests
kripken 0627b7c
improve cfg analysis following feedback
kripken 87f0a68
DEBUG the bizarre problem
kripken 899ba0a
cleanup
kripken c87bcd1
multifile test passes
kripken File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
define i32 @bw_bh_test_2(i32 %a, i32 %b) { | ||
entry: | ||
%1 = icmp ult i32 %a, %b | ||
br i1 %1, label %fail, label %success, !prof !0 | ||
|
||
fail: | ||
ret i32 -1 | ||
|
||
success: | ||
ret i32 0 | ||
} | ||
|
||
!0 = !{!"branch_weights", !"expected", i32 1, i32 2000} | ||
|
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,30 @@ | ||
|
||
; RUN: llc -mtriple=wasm32-unknown-unknown -filetype=obj -o %t1.o < %s | ||
; RUN: llc -mtriple=wasm32-unknown-unknown -filetype=obj -o %t2.o < %S/Inputs/branch-hints-multifile.ll | ||
; RUN: wasm-ld -o %t.wasm %t1.o %t2.o --no-entry --no-gc-sections | ||
; RUN: obj2yaml %t.wasm | FileCheck %s | ||
|
||
define i32 @bw_bh_test_1(i32 %a, i32 %b) { | ||
entry: | ||
%1 = icmp ult i32 %a, %b | ||
br i1 %1, label %fail, label %success, !prof !0 | ||
|
||
fail: | ||
ret i32 -1 | ||
|
||
success: | ||
ret i32 0 | ||
} | ||
|
||
!0 = !{!"branch_weights", !"expected", i32 2000, i32 1} | ||
|
||
; Test that we combine branch hint sections properly. The number of functions | ||
; should be reported once at the start (even though it appears in each object | ||
; file, and the hints for each object file should then be concatenated). | ||
; CHECK: - Type: CUSTOM | ||
; CHECK-NEXT: Name: metadata.code.branch_hint | ||
; CHECK-NEXT: Payload: '8280808000818080800001080100828080800001080101' | ||
; ^^ two functions (5-byte padded LEB) | ||
; ^^hint for func 1^ | ||
; ^^hint for func 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,31 @@ | ||
|
||
; RUN: llc -mtriple=wasm32-unknown-unknown -filetype=obj -o %t.o < %s | ||
; RUN: wasm-ld -o %t.wasm %t.o --no-entry --no-gc-sections | ||
; RUN: obj2yaml %t.wasm | FileCheck %s | ||
|
||
define i32 @bw_bh_test(i32 %a, i32 %b) { | ||
; The weights below mean we are far more likely to go to %fail and return -1. | ||
; Codegen will emit the -1 first, so we emit a hint of 0, below, for the value | ||
; of the hint (as in llvm/test/Codegen/WebAssembly/branch-hints.ll). | ||
entry: | ||
%1 = icmp ult i32 %a, %b | ||
br i1 %1, label %fail, label %success, !prof !0 | ||
|
||
fail: | ||
ret i32 -1 | ||
|
||
success: | ||
ret i32 0 | ||
} | ||
|
||
!0 = !{!"branch_weights", !"expected", i32 2000, i32 1} | ||
|
||
; CHECK: - Type: CUSTOM | ||
; CHECK-NEXT: Name: metadata.code.branch_hint | ||
; CHECK-NEXT: Payload: '8180808000818080800001080100' | ||
; ^^ one function (5-byte padded LEB) | ||
; ^^^^^^^^^^ LEB of function index 1 | ||
; ^^ one hint in function | ||
; ^^ offset 8 | ||
; ^^ hint size 1 | ||
; ^^ hint value: 0 |
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
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
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
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
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
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
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.
To be even more specific here, the thing I was hoping for was that we could tell, based on some property of
Value
, whether there needs to be a relocation. If so, we can basically just assume that the size will be 5 (The only non-32-bit relocation I know of would be for memory addresses, so there could be i64.const instruction in code with 9-byte relocatable LEBs, but I guess those are handled differently elsewhere). And then we don't need the explicit PadTo in the streamer API or the separate assembler directive.The question of course, is whether that's possible. MCExpr has
evaluateAsRelocatable
alongsideevaluateAsAbsolute
but currently I'm not totally sure what it means.