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

Andreu Carminati via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 29 01:57:13 PST 2023


andcarminati wrote:

Hi @topperc,

> 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.

Now, the baseline is not empty, but it includes a basic arch like `Tag_RISCV_arch: "rv32i2p1"`
I tested the output of GNU objdump (from GCC 13) against clang+LTO generated ELFs, and I got the same result, no instruction decoding at all:

```
Disassembly of section .text:

000110d4 <main>:
   110d4:       4501                    .insn   2, 0x4501
   110d6:       8082                    .insn   2, 0x8082
```

As I can see, the problem is becoming interesting. I think for this to work on llvm-objdump side, we will need to rework the Disassembler interface to accept MCSubtargeInfo, as in MC layer.

> 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.

We can copy the command line ISA (`-march`), but feel that this is much more unpredictable than the `-mabi` option. For example, if the user provides such a command line we will get I small one representing the minimal set (supposing that the user provides a minimal `arch`), although if the user provides just `-mcpu` option, the frontend will need to infer the `arch`, and, as I see from multilib selection it can be a really a long `arch` string that appends all features of the chosen core. I think we will have two behaviors here, with and without the command line (which can be different). Maybe the best approach is to not rely on the user.

About taking the union, the last version of this PR includes it, by removing incompatible feature combinations. It means that the generated Elf attribute will be compatible with all functions, and the functions will also have the mapping symbols to specific and incompatible features concerning other functions.

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


More information about the llvm-commits mailing list