-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[feature][riscv] handle target address calculation in llvm-objdump disassembly for riscv #144620
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
Open
arjunUpatel
wants to merge
30
commits into
llvm:main
Choose a base branch
from
arjunUpatel:riscv-address-resolution
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
52ebb65
Remove changes affecting non-RISCV targets
arjunUpatel 49f276e
Update test output to match previous functionality
arjunUpatel 5e1cf12
Add support for zclsd and zilsd extensions + tests
arjunUpatel 11c50dc
Pass subtargetinfo as function argument
arjunUpatel 2241583
Run clang format
arjunUpatel 7635b70
Remove precanned binaries from tests and invoke clang during tests
arjunUpatel 9dff558
Fix typo
arjunUpatel b738bf1
Enable address resolution for load/store instructions relative to zer…
arjunUpatel 9361828
Edit comments to follow LLVM coding style
arjunUpatel e942f63
Use llvm-mc over clang for compilation in tests
arjunUpatel 86d6bd5
Update comments
arjunUpatel 1e1a37c
Differentiate comments in tests from llvm-lit directives
arjunUpatel b2a8928
Merge evaluateInstruction into evaluateBranch
arjunUpatel 6034372
Run clang format
arjunUpatel 3723ffe
Rename evaluateBranch to findTargetAddress for MCInstrAnalysis
arjunUpatel 4156098
Update documentation for findTargetAddress
arjunUpatel dc35c0b
Formatting nits
arjunUpatel 4f92b91
Revert changes to cross-project-tests
arjunUpatel 090519f
Delete 32 bit tests
arjunUpatel 06841d3
Fix linux build error
arjunUpatel 49d69e1
Update tests. Improve test comments
arjunUpatel b356402
Rename test
arjunUpatel d666747
Add unit tests
arjunUpatel 279d53b
Update llvm/include/llvm/MC/MCInstrAnalysis.h
arjunUpatel f3b6d7b
Format unit tests + address nits
arjunUpatel 8c4cf89
Merge branch 'main' into riscv-address-resolution
arjunUpatel d177ccf
Add CMakeList for new unit test
arjunUpatel 15b7ece
Update RISCVMCInstAnalysis.cpp
arjunUpatel ec109f9
Update llvm/test/tools/llvm-objdump/RISCV/riscv-disassembly-address-r…
arjunUpatel dab085a
Update llvm/test/tools/llvm-objdump/RISCV/riscv-disassembly-address-r…
arjunUpatel 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
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
110 changes: 110 additions & 0 deletions
110
llvm/test/tools/llvm-objdump/RISCV/riscv-disassembly-address-resolution.s
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,110 @@ | ||
| # RUN: llvm-mc -riscv-add-build-attributes -triple=riscv64 -filetype=obj -mattr=+d,+c,+zcb %s -o %t | ||
| # RUN: llvm-objdump -d %t | FileCheck %s | ||
|
|
||
| # CHECK: 0000000000000000 <_start>: | ||
| # CHECK-NEXT: 0: 00010517 auipc a0, 0x10 | ||
| # CHECK-NEXT: 4: 01450513 addi a0, a0, 0x14 <target> | ||
| # CHECK-NEXT: 8: 00010517 auipc a0, 0x10 | ||
| # CHECK-NEXT: c: 0531 addi a0, a0, 0xc <target> | ||
| # CHECK-NEXT: e: 6541 lui a0, 0x10 | ||
| # CHECK-NEXT: 10: 0145059b addiw a1, a0, 0x14 <target> | ||
| # CHECK-NEXT: 14: 6541 lui a0, 0x10 | ||
| # CHECK-NEXT: 16: 2551 addiw a0, a0, 0x14 <target> | ||
| # CHECK-NEXT: 18: 00110537 lui a0, 0x110 | ||
| # CHECK-NEXT: 1c: c90c sw a1, 0x10(a0) <far_target> | ||
| # CHECK-NEXT: 1e: 00110537 lui a0, 0x110 | ||
| # CHECK-NEXT: 22: 4908 lw a0, 0x10(a0) <far_target> | ||
| # CHECK-NEXT: 24: 6541 lui a0, 0x10 | ||
| # CHECK-NEXT: 26: 6585 lui a1, 0x1 | ||
| # CHECK-NEXT: 28: 0306 slli t1, t1, 0x1 | ||
| # CHECK-NEXT: 2a: 0551 addi a0, a0, 0x14 <target> | ||
| # CHECK-NEXT: 2c: 0505 addi a0, a0, 0x1 | ||
| # CHECK-NEXT: 2e: 00002427 fsw ft0, 0x8(zero) <_start+0x8> | ||
| # CHECK-NEXT: 32: 00100017 auipc zero, 0x100 | ||
| # CHECK-NEXT: 36: 00002427 fsw ft0, 0x8(zero) <_start+0x8> | ||
| # CHECK-NEXT: 3a: 00110097 auipc ra, 0x110 | ||
| # CHECK-NEXT: 3e: fda080e7 jalr -0x26(ra) <func> | ||
| # CHECK-NEXT: 42: 01000517 auipc a0, 0x1000 | ||
| # CHECK-NEXT: 46: 00110517 auipc a0, 0x110 | ||
| # CHECK-NEXT: 4a: fca50513 addi a0, a0, -0x36 <far_target> | ||
|
|
||
|
|
||
| ## The core of the feature being added was address resolution for instruction | ||
| ## sequences where a register is populated by immediate values via two | ||
| ## separate instructions. First by an instruction that provides the upper bits | ||
| ## (auipc, lui, etc) followed by another instruction for the lower bits (addi, | ||
| ## jalr, ld, etc.). | ||
|
|
||
| .global _start | ||
| .text | ||
|
|
||
| _start: | ||
| ## Test block 1-3 each focus on a certain starting instruction in a sequence. | ||
| ## Starting instructions are the ones that provide the upper bits. The other | ||
| ## instruction in the sequence is the one that provides the lower bits. The | ||
| ## second instruction is arbitrarily chosen to increase code coverage. | ||
|
|
||
| ## Test block #1. | ||
| lla a0, target | ||
| auipc a0, 0x10 | ||
| c.addi a0, 0xc | ||
|
|
||
| ## Test block #2. | ||
| c.lui a0, 0x10 | ||
| addiw a1, a0, 0x14 | ||
| c.lui a0, 0x10 | ||
| c.addiw a0, 0x14 | ||
|
|
||
| ## Test block #3. | ||
| lui a0, 0x110 | ||
| sw a1, 0x10(a0) | ||
| lui a0, 0x110 | ||
| c.lw a0, 0x10(a0) | ||
|
|
||
| ## Test block 4 tests instruction interleaving. Essentially the code's | ||
| ## ability to keep track of a valid sequence even if multiple other unrelated | ||
| ## instructions separate the two. In effect, the resolution must occur | ||
| ## alongside the instruction marked below with the upper bits provided by the | ||
| ## first instruction in the test. The instructions marked to be unrelated | ||
| ## operate on unrelated registers and should not affect the instruction | ||
| ## sequence formed around them. The last instruction in the test operates on the same | ||
| ## register as the sequence but should NOT have an address resolution since | ||
| ## the sequence terminated in the previous instruction. | ||
| lui a0, 0x10 ## Part of sequence. Provides upper bits | ||
| lui a1, 0x1 ## Unrelated instruction. | ||
| slli t1, t1, 0x1 ## Unrelated instruction. | ||
| addi a0, a0, 0x14 ## End of sequence. Provides lower bits. Resolution here | ||
| addi a0, a0, 0x1 ## Verify register tracking terminates. NO resolution here | ||
|
|
||
| ## Test 5 checks that address resolution works for instructions that make | ||
| ## sense to have address resolution occur without an instruction providing | ||
| ## the upper bits. Such instructions include load/stores relative to the | ||
| ## zero register and short jumps pc-relative jumps | ||
| fsw f0, 0x8(x0) | ||
|
|
||
| ## Test 6 checks instructions providing upper bits do not change the tracked | ||
| ## value of zero register. | ||
| auipc x0, 0x100 | ||
| fsw f0, 0x8(x0) | ||
|
|
||
| ## Test 7 ensures that the newly added functionality is compatible with | ||
| ## code that already worked for branch instructions. | ||
| call func | ||
|
|
||
| ## Test 8 checks that subsequent upper bits operations on the same register | ||
| ## correctly updates the tracked register value to the value written by the | ||
arjunUpatel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ## latest instruction. Resolution must occur based on the update upper bit | ||
| ## value | ||
arjunUpatel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| auipc a0, 0x1000 ## Initial upper bit value | ||
| lla a0, far_target ## Pseudo instruction provides AUIPC. Resolution occurs | ||
| ## based on value written by this instruction | ||
|
|
||
| ## These are the labels that the instructions above are expected to resolve to. | ||
| .skip 0xffc6 | ||
| target: | ||
| .word 1 | ||
| .skip 0xffff8 | ||
| far_target: | ||
| .word 2 | ||
| func: | ||
| ret | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,8 @@ | ||
| set(LLVM_LINK_COMPONENTS | ||
| MC | ||
| Support | ||
| ) | ||
|
|
||
| add_llvm_unittest(RISCVMCMCTests | ||
| RISCVMCInstAnalysis.cpp | ||
| ) |
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.
Uh oh!
There was an error while loading. Please reload this page.