Encode RISCV specific ELF e_flag EF_RISCV_RVC to RISCV Binary
Diff Detail
- Repository
- rL LLVM
Event Timeline
Thanks Shiva - comments inline
lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp | ||
---|---|---|
15–25 | A number of these seem to be unused. | |
45–48 | I don't think this logic is doing what we want. The ABI EFLAGs should be determined by the target ABI rather than the target architecture. I'd suggest removing the FLOAT_ABI code and tests, and we can add this logic once alternative -target-abi are supported. | |
lib/Target/RISCV/RISCVTargetStreamer.h | ||
1 ↗ | (On Diff #128396) | Shouldn't this file be in lib/Target/RISCV/MCTargetDesc? |
13–17 ↗ | (On Diff #128396) | Most of these seem to be unused. |
test/CodeGen/RISCV/elf-header.ll | ||
1 ↗ | (On Diff #128396) | Doesn't this really belong as a test/MC/RISCV test? (obviously modified to use llvm-mc instead). |
lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp | ||
---|---|---|
15–25 | Remove unused including files. | |
45–48 | I think this should be reasonable default ABI EFLAGs setting before introducing -target-abi flag. OK, we could add the logic once -target-abi are supported. | |
lib/Target/RISCV/RISCVTargetStreamer.h | ||
1 ↗ | (On Diff #128396) | Move RISCVTargetStreamer.h to lib/Target/RISCV/MCTargetDesc |
13–17 ↗ | (On Diff #128396) | Remove unused including files. |
test/CodeGen/RISCV/elf-header.ll | ||
1 ↗ | (On Diff #128396) | Move the test case to test/MC/RISCV and rename to elf-flags.s |
With a couple of minor nits, looks good to me. Thanks as always Shiva
lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.h | ||
---|---|---|
23 | Nitpick: full-stop after comment. Does the comment add value? Maybe just delete it. | |
test/MC/RISCV/elf-flags.s | ||
2 | Need to set the target for llvm-mc. Should probably have RUN lines for both riscv32 and riscv64 as many of the other test/MC/RISCV tests do. |
Hi Shiva. I was just looking at applying this and the STI field is triggering a compiler warning as it's not used: it's initialised in the RISCVTargetELFStreamer constructor, but isn't actually read from anywhere.
The test could be modified slightly - given that we know all defined ELF flags for RISC-V are shared between RV32 and RV64 we can share check line, and we could also check that the RVC flag isn't improperly being when not targeting RVC. How about writing it like this:
# RUN: llvm-mc -triple=riscv32 -filetype=obj < %s | llvm-readobj -file-headers - | FileCheck -check-prefixes=CHECK-RVI %s # RUN: llvm-mc -triple=riscv64 -filetype=obj < %s | llvm-readobj -file-headers - | FileCheck -check-prefixes=CHECK-RVI %s # RUN: llvm-mc -triple=riscv32 -mattr=+c -filetype=obj < %s | llvm-readobj -file-headers - | FileCheck -check-prefixes=CHECK-RVIC %s # RUN: llvm-mc -triple=riscv64 -mattr=+c -filetype=obj < %s | llvm-readobj -file-headers - | FileCheck -check-prefixes=CHECK-RVIC %s # CHECK-RVI: Flags [ (0x0) # CHECK-RVI-NEXT: ] # CHECK-RVIC: Flags [ (0x1) # CHECK-RVIC-NEXT: EF_RISCV_RVC (0x1) # CHECK-RVIC-NEXT: ] nop
My suggestion would be to remove the MCSubtarget field (it can be reintroduced when future changes need it), but obviously keep it as an argument to the constructor where it is used.
lib/Target/RISCV/MCTargetDesc/RISCVMCTargetDesc.cpp | ||
---|---|---|
74 | Should'nt we check for ELF format, that is the only one supported now, but may change later? const Triple &TT = STI.getTargetTriple(); if (TT.isOSBinFormatELF()) return new RISCVTargetELFStreamer(S); return nullptr; | |
89 | Reading MCStreamer.h I understand when we define a target streamer we need to define two streamers, ELF and Asm. Is it how you interpreted? / Target specific streamer interface. This is used so that targets can | |
lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp | ||
42 | Shouldn't it be return static_cast<RISCVELFStreamer &>(Streamer); |
lib/Target/RISCV/MCTargetDesc/RISCVMCTargetDesc.cpp | ||
---|---|---|
74 | Add ELF format checking before new RISCVTargetELFStreamer. | |
89 | To my understanding, AsmStreamer is used to emit target specific assembly directives, | |
lib/Target/RISCV/MCTargetDesc/RISCVTargetStreamer.cpp | ||
42 | We didn't define RISCVELFStreamer class for emitting e_flags. It seems that we could introduce the class in the feature patch? |
clang-format shows me a few minor tweaks:
- RISCVELFStreamer.h include should come first in RISCVELFStreamer.cpp
- RISCVMCAsmInfo.h include is now improperly sorted in RISCVMCTargetDesc.cpp
- RISCVTargetStreamer constructor can fit on one line in 80 chars RISCVTargetStreamer::RISCVTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
Otherwise it looks good to me. I can't see any hard dependency on a custom RISCVAsmStreamer (though it's likely we'll want to add it later). Ana - are you happy for this patch to be committed as-is?
Thanks, this looks fine to me. You can merge it. I will rebase my change on top of this.
Hi Shiva, why don't you follow the instructions at http://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access and request commit access? Many many thanks again for all of your contributions to the RISC-V backend so far.
Hi Shiva. In the future it's worth nothing that if you include the review url in the commit, then Phabricator automatically picks it up.
e.g. if you included this line then phabricator would automatically close this review:
Differential Revision: https://reviews.llvm.org/D41658
It looks like you missed the minor sorting/whitespace fixes I suggested https://reviews.llvm.org/D41658#978491. If you have time to commit a follow-up cleanup I'd appreciate it (just committing directly for this cleanup is fine). Thanks!
Closed by commit rL323507: [RISCV] Encode RISCV specific ELF e_flags to RISCV Binary by RISCVTargetStreamer
Should'nt we check for ELF format, that is the only one supported now, but may change later?
const Triple &TT = STI.getTargetTriple();