LLVM 20.0.0git
AArch64SMEAttributes.cpp
Go to the documentation of this file.
1//===-- AArch64SMEAttributes.cpp - Helper for interpreting SME attributes -===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "llvm/IR/InstrTypes.h"
11#include <cassert>
12
13using namespace llvm;
14
15void SMEAttrs::set(unsigned M, bool Enable) {
16 if (Enable)
17 Bitmask |= M;
18 else
19 Bitmask &= ~M;
20
21 // Streaming Mode Attrs
23 "SM_Enabled and SM_Compatible are mutually exclusive");
24
25 // ZA Attrs
26 assert(!(isNewZA() && (Bitmask & SME_ABI_Routine)) &&
27 "ZA_New and SME_ABI_Routine are mutually exclusive");
28
29 assert(
30 (!sharesZA() ||
31 (isNewZA() ^ isInZA() ^ isInOutZA() ^ isOutZA() ^ isPreservesZA())) &&
32 "Attributes 'aarch64_new_za', 'aarch64_in_za', 'aarch64_out_za', "
33 "'aarch64_inout_za' and 'aarch64_preserves_za' are mutually exclusive");
34
35 // ZT0 Attrs
36 assert(
37 (!sharesZT0() || (isNewZT0() ^ isInZT0() ^ isInOutZT0() ^ isOutZT0() ^
38 isPreservesZT0())) &&
39 "Attributes 'aarch64_new_zt0', 'aarch64_in_zt0', 'aarch64_out_zt0', "
40 "'aarch64_inout_zt0' and 'aarch64_preserves_zt0' are mutually exclusive");
41}
42
44 *this = SMEAttrs(CB.getAttributes());
45 if (auto *F = CB.getCalledFunction()) {
46 set(SMEAttrs(*F).Bitmask | SMEAttrs(F->getName()).Bitmask);
47 }
48}
49
50SMEAttrs::SMEAttrs(StringRef FuncName) : Bitmask(0) {
51 if (FuncName == "__arm_tpidr2_save" || FuncName == "__arm_sme_state")
53 if (FuncName == "__arm_tpidr2_restore")
56 if (FuncName == "__arm_sc_memcpy" || FuncName == "__arm_sc_memset" ||
57 FuncName == "__arm_sc_memmove" || FuncName == "__arm_sc_memchr")
58 Bitmask |= SMEAttrs::SM_Compatible;
59}
60
62 Bitmask = 0;
63 if (Attrs.hasFnAttr("aarch64_pstate_sm_enabled"))
64 Bitmask |= SM_Enabled;
65 if (Attrs.hasFnAttr("aarch64_pstate_sm_compatible"))
66 Bitmask |= SM_Compatible;
67 if (Attrs.hasFnAttr("aarch64_pstate_sm_body"))
68 Bitmask |= SM_Body;
69 if (Attrs.hasFnAttr("aarch64_in_za"))
70 Bitmask |= encodeZAState(StateValue::In);
71 if (Attrs.hasFnAttr("aarch64_out_za"))
73 if (Attrs.hasFnAttr("aarch64_inout_za"))
75 if (Attrs.hasFnAttr("aarch64_preserves_za"))
77 if (Attrs.hasFnAttr("aarch64_new_za"))
79 if (Attrs.hasFnAttr("aarch64_in_zt0"))
81 if (Attrs.hasFnAttr("aarch64_out_zt0"))
83 if (Attrs.hasFnAttr("aarch64_inout_zt0"))
85 if (Attrs.hasFnAttr("aarch64_preserves_zt0"))
87 if (Attrs.hasFnAttr("aarch64_new_zt0"))
89}
90
91bool SMEAttrs::requiresSMChange(const SMEAttrs &Callee) const {
92 if (Callee.hasStreamingCompatibleInterface())
93 return false;
94
95 // Both non-streaming
96 if (hasNonStreamingInterfaceAndBody() && Callee.hasNonStreamingInterface())
97 return false;
98
99 // Both streaming
100 if (hasStreamingInterfaceOrBody() && Callee.hasStreamingInterface())
101 return false;
102
103 return true;
104}
@ Enable
Definition: DwarfDebug.cpp:87
#define F(x, y, z)
Definition: MD5.cpp:55
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1236
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Definition: InstrTypes.h:1465
AttributeList getAttributes() const
Return the parameter attributes for this call.
Definition: InstrTypes.h:1542
SMEAttrs is a utility class to parse the SME ACLE attributes on functions.
bool isPreservesZT0() const
bool sharesZT0() const
bool hasStreamingInterface() const
static unsigned encodeZAState(StateValue S)
bool hasNonStreamingInterfaceAndBody() const
SMEAttrs(unsigned Mask=Normal)
bool hasStreamingCompatibleInterface() const
bool requiresSMChange(const SMEAttrs &Callee) const
bool isOutZA() const
bool isInOutZT0() const
bool hasStreamingInterfaceOrBody() const
void set(unsigned M, bool Enable=true)
bool sharesZA() const
bool isInOutZA() const
bool isPreservesZA() const
bool isNewZA() const
static unsigned encodeZT0State(StateValue S)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Enable
Enable colors.