[llvm] [RISCV] Collect function features in AsmPrinter before emission (#76231) (PR #76437)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 28 09:12:48 PST 2023


topperc wrote:

The ELF attributes are supposed to represent the minimum requirement for the binary. Someday we may want the loader to check this. Within a compilation unit an individual function can use `attribute(target_clones)`, `attribute(target)`, `attribute(target_clones)` to compile for a different ISA and at runtime determine if they should dispatch to those functions based on the supported ISA using hwprobe or some other mechanism.

The backend cannot tell the different a function with the baseline ISA and a function that used one of the attributes. Adding the ISA from an attributed function to the ELF attributes breaks the intent of the ELF attributes.

The backend is supposed to be emitting a mapping symbol if the ISA for a function differs from the baseline. This mapping symbol should specify the ISA for the function and the disassembler should be able to use that instead of the ELF attributes.

Right now in LTO, the baselines ISA is empty so there should be a mapping symbol emitted for every function. We need to check that is happening. After that, I don't know if llvm-objdump has been updated to look for mapping symbols. GNU objdump has support.

The best way I can think of to get a baseline ISA for LTO, is to copy the command line ISA into an IR module level attribute from the frontend at compile time. We already do this with target-abi. When LTO links the modules together, we should take the union of the attribute from each module and reject linking any incompatible modules. Then in backend, we should use this attribute to set the ELF attributes.

https://github.com/llvm/llvm-project/pull/76437


More information about the llvm-commits mailing list