[AArch64][SME] Fix lowering of llvm.aarch64.get.pstatesm()
authorSander de Smalen <sander.desmalen@arm.com>
Wed, 14 Sep 2022 15:53:13 +0000 (15:53 +0000)
committerSander de Smalen <sander.desmalen@arm.com>
Thu, 15 Sep 2022 15:14:13 +0000 (15:14 +0000)
commit45d28779c5dc6c8afa6feb24d68606f01b9800f4
treeea5fcee24539871a03e415c17a2904cede77a162
parentb0eea8f440af48dfe52ada04a58198460694fb56
[AArch64][SME] Fix lowering of llvm.aarch64.get.pstatesm()

A thread may not have access to SME or TPIDR2_EL0, so in order to
safely query PSTATE.SM in a streaming-compatible function, the
code should call `__arm_sme_state()`, as described in the ABI:

  https://github.com/ARM-software/abi-aa/pull/123/commits/c2bb09c4d4ee60a5787baf1ccc7e92e67e4240b7

This means that the value of pstate.sm is:
* 0 if the function is non-streaming.
* 1 if the function has `arm_streaming` or `arm_locally_streaming`.
* evaluated at runtime by a call to __arm_sme_state() otherwise.

This patch also adds a calling convention for calls to SME support routines.

At some point we can remove the need for the llvm.aarch64.get.pstatesm() intrinsic
and use function calls (with the corresponding cc) directly instead.

Reviewed By: aemerson

Differential Revision: https://reviews.llvm.org/D131571
llvm/include/llvm/AsmParser/LLToken.h
llvm/include/llvm/IR/CallingConv.h
llvm/lib/AsmParser/LLLexer.cpp
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/IR/AsmWriter.cpp
llvm/lib/Target/AArch64/AArch64CallingConvention.td
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
llvm/lib/Target/AArch64/AArch64ISelLowering.h
llvm/lib/Target/AArch64/AArch64RegisterInfo.cpp
llvm/test/CodeGen/AArch64/sme-get-pstatesm.ll
llvm/test/CodeGen/AArch64/sme-support-routines-calling-convention.ll [new file with mode: 0644]