- enable LTO need to pass target feature and abi to LTO code generation RISCV backend need the target feature to decide which extension used in code generation.
- move getTargetFeatures to CommonArgs.h and add ForLTOPlugin flag
- add general tools::getTargetABI in CommonArgs.h because different target uses different way to get the target ABI.
Details
Diff Detail
Event Timeline
Can you add a test for riscv64-unknown-linux-gnu? I think RISCVToolchain.cpp is only used by the riscv64-unknown-elf target, but I could be wrong.
clang/lib/Driver/ToolChains/Arch/RISCV.cpp | ||
---|---|---|
387 ↗ | (On Diff #219941) | gold doesn't support RISC-V, does it? |
clang/lib/Driver/ToolChains/Arch/RISCV.cpp | ||
---|---|---|
387 ↗ | (On Diff #219941) | Gold doesn't support RISC-V , but ld.bfd supported same plugin API, so this made clang can run LTO with ld.bfd. |
clang/lib/Driver/ToolChains/Arch/RISCV.cpp | ||
---|---|---|
387 ↗ | (On Diff #219941) | I reference AddGoldPlugin to naming this function, is it confusing? |
clang/lib/Driver/ToolChains/Arch/RISCV.cpp | ||
---|---|---|
414 ↗ | (On Diff #219941) | The single-dash form of mattr: -plugin-opt=-mattr= should be preferred. --mattr is rare. |
clang/lib/Driver/ToolChains/Arch/RISCV.h | ||
26 ↗ | (On Diff #219941) | The description should probably mention why clang::driver:tools::AddGoldPlugin is insufficient. |
This commit is inspired by @MaskRay's suggestion, I think maybe fix the insufficient of clang::driver:tools::AddGoldPlugin is good choose.
I have some nits about explicit comments for arguments and default argument values for backwards compatibility. Other than that, it looks like a nice code cleanup.
clang/lib/Driver/ToolChains/Clang.cpp | ||
---|---|---|
6071 ↗ | (On Diff #220214) | This needs /*ForAS=*/true, /*ForLTOPlugin=*/false) so it's clear what the booleans are for. Same for other calls to getTargetFeatures. |
clang/lib/Driver/ToolChains/CommonArgs.h | ||
134 ↗ | (On Diff #220214) | The final argument here should probably default to false, so that out-of-tree backends do not break immediately when this patch lands. |
rebase master,
https://reviews.llvm.org/D66003 changed the riscv::getRISCVTargetFeatures interface.
clang/lib/Driver/ToolChains/CommonArgs.cpp | ||
---|---|---|
498 ↗ | (On Diff #224854) | I don't think this change is right. In general, target features should be encoded in bitcode files. This allows compiling different files with different target features, and using runtime detection to only run certain codepaths. And it makes sure that we end up with a sane result if the user doesn't pass target feature flags on the link line. Also, it probably isn't appropriate to make target-independent changes in a commit tagged [RISCV]; most people would assume a change marked like that doesn't have target-independent effects. (Sorry about the delayed response to this review; I only just ran into this.) |
clang/lib/Driver/ToolChains/CommonArgs.cpp | ||
---|---|---|
498 ↗ | (On Diff #224854) |
I'm curious about your scenario, LTO will link two bitcodes file into one, so which target-features should be kept in final bitcode since different files have different target features? For example, one target features" is "+armv7-a" and another is "+armv8-a". I guess maybe your case is they are same target-features in different files, but this patch will overwrite the encoded target-feature as default. anyway, I agree with you. I found the target features does not encoded in bitcode files when enabling LTO in RISCV, I will fixed it and revert the target feature part, thanks.
sorry, I will take care of it in next time.
|
clang/lib/Driver/ToolChains/CommonArgs.cpp | ||
---|---|---|
498 ↗ | (On Diff #224854) | Target features are encoded into IR on a per-function basis, so we can keep both. But yes, I'm more worried about the implicit expectation that the target flags are specified on the link line; this isn't reliably true with common build systems. |
I've reverted in b1ac1f00716 until it can be fixed properly.
We noticed this in Chromium where we started seeing build spam like:
'+soft-float-abi' is not a recognized feature for this target (ignoring feature)
'+soft-float-abi' is not a recognized feature for this target (ignoring feature)
See https://bugs.chromium.org/p/chromium/issues/detail?id=1023280 for details.
Sorry for not reporting it earlier, but because it didn't break the build per se, we didn't notice until now.