LLVM 19.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}
57
59 Bitmask = 0;
60 if (Attrs.hasFnAttr("aarch64_pstate_sm_enabled"))
61 Bitmask |= SM_Enabled;
62 if (Attrs.hasFnAttr("aarch64_pstate_sm_compatible"))
63 Bitmask |= SM_Compatible;
64 if (Attrs.hasFnAttr("aarch64_pstate_sm_body"))
65 Bitmask |= SM_Body;
66 if (Attrs.hasFnAttr("aarch64_in_za"))
67 Bitmask |= encodeZAState(StateValue::In);
68 if (Attrs.hasFnAttr("aarch64_out_za"))
70 if (Attrs.hasFnAttr("aarch64_inout_za"))
72 if (Attrs.hasFnAttr("aarch64_preserves_za"))
74 if (Attrs.hasFnAttr("aarch64_new_za"))
76 if (Attrs.hasFnAttr("aarch64_in_zt0"))
78 if (Attrs.hasFnAttr("aarch64_out_zt0"))
80 if (Attrs.hasFnAttr("aarch64_inout_zt0"))
82 if (Attrs.hasFnAttr("aarch64_preserves_zt0"))
84 if (Attrs.hasFnAttr("aarch64_new_zt0"))
86}
87
88bool SMEAttrs::requiresSMChange(const SMEAttrs &Callee) const {
89 if (Callee.hasStreamingCompatibleInterface())
90 return false;
91
92 // Both non-streaming
93 if (hasNonStreamingInterfaceAndBody() && Callee.hasNonStreamingInterface())
94 return false;
95
96 // Both streaming
97 if (hasStreamingInterfaceOrBody() && Callee.hasStreamingInterface())
98 return false;
99
100 return true;
101}
@ 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:1259
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Definition: InstrTypes.h:1481
AttributeList getAttributes() const
Return the parameter attributes for this call.
Definition: InstrTypes.h:1558
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.