[PATCH] D137532: [LoongArch] Implement the TargetLowering::getRegisterByName hook

Xi Ruoyao via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 14 00:38:03 PST 2022


xry111 added a comment.

In D137532#3924134 <https://reviews.llvm.org/D137532#3924134>, @xen0n wrote:

> In D137532#3924037 <https://reviews.llvm.org/D137532#3924037>, @gonglingqin wrote:
>
>> In D137532#3923952 <https://reviews.llvm.org/D137532#3923952>, @xen0n wrote:
>>
>>> I'm curious what usage case motivated the change? Not to say it's unnecessary but it's better to have people know a bit more background behind this work.
>>
>> This interface is required by the code in https://github.com/loongson/linux/blob/master/arch/loongarch/include/asm/percpu.h#L12-L18. This patch can avoid crashes when compiling the kernel with llvm in the future.
>
> Very nice to know.
>
> BTW, are the normal GPRs already supported like this too (things like global `register long foo __asm__("$a0")`), even without this change, or are such usages invalid in the first place? Memory is failing me.

I've not built LLVM and Clang for LoongArch recently, but on gcc400.fsffrance.org (with Arch Linux for LoongArch installed) I got:

  $ clang -v 2>&1 | head -n1
  clang version 14.0.6
  $ cat t.c
  register int y __asm__("$s0");
  int o() { register int x __asm__("$t0"); return y; }
  $ clang t.c -S
  fatal error: error in backend: Invalid register name global variable
  ... ... (stack trace)

But if we change it to `return x;`, the code will be compiled successfully.  So it looks like local register variables with assigned GPR have been supported, but the global ones are not.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D137532/new/

https://reviews.llvm.org/D137532



More information about the llvm-commits mailing list