This is an archive of the discontinued LLVM Phabricator instance.

[clang][RISCV] Added target attributes to runtime functions
Needs ReviewPublic

Authored by eklepilkina on Dec 9 2022, 3:41 AM.

Details

Summary

RISCVTargetMachine::getSubtargetImpl creates subtargets based on target attributes of IR functions. As result now runtime functions are placed in another subtarget and have another ABI. That causes warning messages like Hard-float 'd' ABI can't be used for a target that doesn't support the D instruction set extension (ignoring target-abi) during linking with lld with -flto

Diff Detail

Event Timeline

eklepilkina created this revision.Dec 9 2022, 3:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 9 2022, 3:41 AM
eklepilkina requested review of this revision.Dec 9 2022, 3:41 AM
eklepilkina edited the summary of this revision. (Show Details)Dec 9 2022, 3:56 AM
eklepilkina added reviewers: rjmccall, khchen.
eklepilkina added a subscriber: anton-afanasyev.

How does this affect LTO? LTO for RISC-V is broken for various reasons, but LTO isn't Clang's responsibility beyond passing on driver arguments. Is this not just one of many symptoms of RISC-V not having the right module-level subtarget under LTO, which is a real problem that needs fixing?

The code changes/test changes seem innocuous enough, so from an 'attribute code owner perspective' I think this is alright. I think @rjmccall or @eli.friedman need to take a peak from CodeGen owner's perspective, and it seems useful if the commit message better described (at least in a way that the three of us could understand) the motivation/reasoning here.

How does this affect LTO?

This problem appeared only under lto as far as it's processed as one module.

Is this not just one of many symptoms of RISC-V not having the right module-level subtarget under LTO, which is a real problem that needs fixing?

Not exactly, to build right subtarget we need attributes. As far as mentioned in comments in code the main approach to provide subtarget information is adding information in functions attributes. Why not to provide this information for runtime functions? If we don't have right attributes what shall we use to find out proper target features?

How does this affect LTO?

More detailed answer. We work with bitcode files only when use lto. If we don't use lto clang produces .o file that are already contains target information. We don't work with function attributes to get subtarget without lto.

I've created one more patch connected with lto https://reviews.llvm.org/D142191 and it also uses attributes of functions as the way to get right TargetMachine in linker.