-
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.
+425
−57
Open
Changes from 6 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| if "clang" not in config.available_features or "RISCV" not in config.targets_to_build: | ||
| config.unsupported = True |
31 changes: 31 additions & 0 deletions
31
cross-project-tests/tools/llvm-objdump/RISCV/riscv32-ar-coverage.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,31 @@ | ||
| # RUN: %clang --target=fuchsia-elf-riscv32 -march=rv32g_zclsd_zilsd %s -nostdlib -o %t | ||
| # RUN: llvm-objdump -d %t | FileCheck %s | ||
|
|
||
| # CHECK: 00001000 <_start>: | ||
| # CHECK-NEXT: 1000: 00000517 auipc a0, 0x0 | ||
| # CHECK-NEXT: 1004: 0559 addi a0, a0, 0x16 <target> | ||
| # CHECK-NEXT: 1006: 00000517 auipc a0, 0x0 | ||
| # CHECK-NEXT: 100a: 6910 ld a2, 0x10(a0) <target> | ||
| # CHECK-NEXT: 100c: 00000517 auipc a0, 0x0 | ||
| # CHECK-NEXT: 1010: 00c53523 sd a2, 0xa(a0) <target> | ||
| # CHECK-NEXT: 1014: 0000 unimp | ||
|
|
||
| # the structure of this test file is similar to that of riscv64-ar-coverage | ||
| # with the major difference being that these tests are focused on instructions | ||
| # for 32 bit architecture | ||
|
|
||
| .global _start | ||
| .text | ||
| _start: | ||
| auipc a0, 0x0 | ||
| addi a0, a0, 0x16 # addi -- behavior changes with differentr architectures | ||
arjunUpatel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| auipc a0, 0x0 | ||
| c.ld a2, 0x10(a0) # zclsd instruction | ||
|
|
||
| auipc a0, 0x0 | ||
| sd a2, 0xa(a0) # zilsd instruction | ||
|
|
||
| .skip 0x2 | ||
| target: | ||
| ret: | ||
107 changes: 107 additions & 0 deletions
107
cross-project-tests/tools/llvm-objdump/RISCV/riscv64-ar-coverage.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,107 @@ | ||
| # RUN: %clang --target=fuchsia-elf-riscv64 -march=rv64gc_zcb %s -nostdlib -o %t | ||
| # RUN: llvm-objdump -d %t | FileCheck %s | ||
|
|
||
| # CHECK: 0000000000001000 <_start>: | ||
| # CHECK-NEXT: 1000: 00001517 auipc a0, 0x1 | ||
| # CHECK-NEXT: 1004: 00450513 addi a0, a0, 0x4 <target> | ||
| # CHECK-NEXT: 1008: 00001517 auipc a0, 0x1 | ||
| # CHECK-NEXT: 100c: 1571 addi a0, a0, -0x4 <target> | ||
| # CHECK-NEXT: 100e: 6509 lui a0, 0x2 | ||
| # CHECK-NEXT: 1010: 0045059b addiw a1, a0, 0x4 <target> | ||
| # CHECK-NEXT: 1014: 6509 lui a0, 0x2 | ||
| # CHECK-NEXT: 1016: 2511 addiw a0, a0, 0x4 <target> | ||
| # CHECK-NEXT: 1018: 00102537 lui a0, 0x102 | ||
| # CHECK-NEXT: 101c: c50c sw a1, 0x8(a0) <far_target> | ||
| # CHECK-NEXT: 101e: 00102537 lui a0, 0x102 | ||
| # CHECK-NEXT: 1022: 4508 lw a0, 0x8(a0) <far_target> | ||
| # CHECK-NEXT: 1024: 6509 lui a0, 0x2 | ||
| # CHECK-NEXT: 1026: 6585 lui a1, 0x1 | ||
| # CHECK-NEXT: 1028: 0306 slli t1, t1, 0x1 | ||
| # CHECK-NEXT: 102a: 0511 addi a0, a0, 0x4 <target> | ||
| # CHECK-NEXT: 102c: 0505 addi a0, a0, 0x1 | ||
| # CHECK-NEXT: 102e: 00200037 lui zero, 0x200 | ||
| # CHECK-NEXT: 1032: 00a02423 sw a0, 0x8(zero) | ||
arjunUpatel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # CHECK-NEXT: 1036: 00101097 auipc ra, 0x101 | ||
| # CHECK-NEXT: 103a: fd6080e7 jalr -0x2a(ra) <func> | ||
| # CHECK-NEXT: 103e: 640d lui s0, 0x3 | ||
| # CHECK-NEXT: 1040: 8800 sb s0, 0x0(s0) <zcb> | ||
| # CHECK-NEXT: 1042: 4522 lw a0, 0x8(sp) | ||
|
|
||
|
|
||
| .global _start | ||
| .text | ||
|
|
||
| # The core of the feature being added was address resolution for instruction | ||
| # sequences where an register is populated by immediate values via two | ||
| # separate instructions. First by an instruction that provides the upper bits | ||
| # (auipc, lui ...) followed by another instruction for the lower bits (addi, | ||
| # jalr, ld ...). | ||
|
|
||
| _start: | ||
| # Test block 1-3 each focus on a certain starting instruction in a sequences, | ||
| # the ones that provide the upper bits. The other sequence is another | ||
| # instruction the provides the lower bits. The second instruction is | ||
| # arbitrarily chosen to increase code coverage | ||
|
|
||
| # test block #1 | ||
| lla a0, target # addi | ||
| auipc a0, 0x1 | ||
| c.addi a0, -0x4 # c.addi | ||
|
|
||
| # test block #2 | ||
| c.lui a0, 0x2 | ||
| addiw a1, a0, 0x4 # addiw | ||
| c.lui a0, 0x2 | ||
| c.addiw a0, 0x4 # c.addiw | ||
|
|
||
| # test block #3 | ||
| lui a0, 0x102 | ||
| sw a1, 0x8(a0) # sw | ||
| lui a0, 0x102 | ||
| c.lw a0, 0x8(a0) # lw | ||
|
|
||
| # 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 | ||
|
|
||
| # test #4 | ||
| lui a0, 0x2 | ||
| lui a1, 0x1 # unrelated instruction | ||
| slli t1, t1, 0x1 # unrelated instruction | ||
| addi a0, a0, 0x4 | ||
| addi a0, a0, 0x1 # verify register tracking terminates | ||
|
|
||
| # Test 5 ensures that an instruction writing into the zero register does | ||
| # not trigger resolution because that register's value cannot change and | ||
| # the sequence is equivalent to never running the first instruction | ||
|
|
||
| # test #5 | ||
| lui x0, 0x200 | ||
| sw a0, 0x8(x0) | ||
|
|
||
| # Test 6 ensures that the newly added functionality is compatible with | ||
| # code that already worked for branch instructions | ||
|
|
||
| # test #6 | ||
| call func | ||
|
|
||
| # test #7 zcb extension | ||
| lui x8, 0x3 | ||
| c.sb x8, 0(x8) | ||
|
|
||
| # test #8 stack based load/stores | ||
| c.lwsp a0, 0x8(sp) | ||
|
|
||
| # these are the labels that the instructions above are expecteed to resolve to | ||
| .section .data | ||
| .skip 0x4 | ||
| target: | ||
| .word 1 | ||
| .skip 0xff8 | ||
| zcb: | ||
| .word 1 | ||
| .skip 0xff004 | ||
| far_target: | ||
| .word 2 | ||
| func: | ||
| ret | ||
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.
Uh oh!
There was an error while loading. Please reload this page.