[LoongArch] Support inline asm operand modifier 'z'
authorWeining Lu <luweining@loongson.cn>
Mon, 31 Oct 2022 01:15:29 +0000 (09:15 +0800)
committerWeining Lu <luweining@loongson.cn>
Mon, 31 Oct 2022 01:56:41 +0000 (09:56 +0800)
commite415cb1d61e798b6d69b5960a90f00518ca5008f
treedd8aa70f4e9749b3dbeb46730ac68607948a72b4
parentbe8a2b98da582d4cfd96be3b2cf561679a72bbb0
[LoongArch] Support inline asm operand modifier 'z'

Print $zero register if operand is zero, otherwise print it normally.

Clang is highly compatible [1] with GCC inline assembly extensions,
allowing the same set of constraints, modifiers and operands as GCC
inline assembly. This patch tries to make it compatible regarding
LoongArch specific operand modifiers.

GCC supports many modifiers [2], but it seems that only x86 and msp430
are documented [3][4]. I don't know if any other modifiers are being
used except the 'z' in Linux [5].

[1]: https://clang.llvm.org/compatibility.html#inline-asm
[2]: https://github.com/gcc-mirror/gcc/blob/master/gcc/config/loongarch/loongarch.cc#L4884-L4911
[3]: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#x86Operandmodifiers
[4]: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#msp430Operandmodifiers
[5]: https://github.com/torvalds/linux/blob/master/arch/loongarch/include/asm/cmpxchg.h#L17

Differential Revision: https://reviews.llvm.org/D136841
clang/test/CodeGen/LoongArch/inline-asm-operand-modifiers.c [new file with mode: 0644]
llvm/lib/Target/LoongArch/LoongArchAsmPrinter.cpp
llvm/test/CodeGen/LoongArch/inline-asm-operand-modifiers.ll [new file with mode: 0644]