LLVM 23.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 "AArch64ISelLowering.h"
11#include "llvm/IR/InstrTypes.h"
13#include <cassert>
14
15using namespace llvm;
16
17void SMEAttrs::validate() const {
18 // Streaming Mode Attrs
20 "SM_Enabled and SM_Compatible are mutually exclusive");
21
22 // ZA Attrs
23 assert(!(isNewZA() && (Bitmask & SME_ABI_Routine)) &&
24 "ZA_New and SME_ABI_Routine are mutually exclusive");
25
26 assert(
27 (isNewZA() + isInZA() + isOutZA() + isInOutZA() + isPreservesZA()) <= 1 &&
28 "Attributes 'aarch64_new_za', 'aarch64_in_za', 'aarch64_out_za', "
29 "'aarch64_inout_za' and 'aarch64_preserves_za' are mutually exclusive");
30
31 // ZT0 Attrs
32 assert(
34 1 &&
35 "Attributes 'aarch64_new_zt0', 'aarch64_in_zt0', 'aarch64_out_zt0', "
36 "'aarch64_inout_zt0' and 'aarch64_preserves_zt0' are mutually exclusive");
37
39 "Function cannot have a shared-ZA interface and an agnostic-ZA "
40 "interface");
41}
42
43SMEAttrs::SMEAttrs(const AttributeList &Attrs) {
44 // Note: 'aarch64_zt0_undef' was previously used (and subsequently removed).
45 // To avoid introducing any compatibility issues don't reuse
46 // 'aarch64_zt0_undef' for another purpose.
47 Bitmask = 0;
48 if (Attrs.hasFnAttr("aarch64_pstate_sm_enabled"))
49 Bitmask |= SM_Enabled;
50 if (Attrs.hasFnAttr("aarch64_pstate_sm_compatible"))
51 Bitmask |= SM_Compatible;
52 if (Attrs.hasFnAttr("aarch64_pstate_sm_body"))
53 Bitmask |= SM_Body;
54 if (Attrs.hasFnAttr("aarch64_za_state_agnostic"))
55 Bitmask |= ZA_State_Agnostic;
56 if (Attrs.hasFnAttr("aarch64_in_za"))
57 Bitmask |= encodeZAState(StateValue::In);
58 if (Attrs.hasFnAttr("aarch64_out_za"))
60 if (Attrs.hasFnAttr("aarch64_inout_za"))
62 if (Attrs.hasFnAttr("aarch64_preserves_za"))
64 if (Attrs.hasFnAttr("aarch64_new_za"))
66 if (Attrs.hasFnAttr("aarch64_in_zt0"))
68 if (Attrs.hasFnAttr("aarch64_out_zt0"))
70 if (Attrs.hasFnAttr("aarch64_inout_zt0"))
72 if (Attrs.hasFnAttr("aarch64_preserves_zt0"))
74 if (Attrs.hasFnAttr("aarch64_new_zt0"))
76}
77
78void SMEAttrs::addKnownFunctionAttrs(StringRef FuncName,
79 const RTLIB::RuntimeLibcallsInfo &RTLCI) {
80 RTLIB::LibcallImpl Impl = RTLCI.getSupportedLibcallImpl(FuncName);
81 if (Impl == RTLIB::Unsupported)
82 return;
83 unsigned KnownAttrs = SMEAttrs::Normal;
84 RTLIB::Libcall LC = RTLIB::RuntimeLibcallsInfo::getLibcallFromImpl(Impl);
85 switch (LC) {
86 case RTLIB::SMEABI_SME_STATE:
87 case RTLIB::SMEABI_TPIDR2_SAVE:
88 case RTLIB::SMEABI_GET_CURRENT_VG:
89 case RTLIB::SMEABI_SME_STATE_SIZE:
90 case RTLIB::SMEABI_SME_SAVE:
91 case RTLIB::SMEABI_SME_RESTORE:
93 break;
94 case RTLIB::SMEABI_ZA_DISABLE:
95 case RTLIB::SMEABI_TPIDR2_RESTORE:
98 break;
99 case RTLIB::SC_MEMCPY:
100 case RTLIB::SC_MEMMOVE:
101 case RTLIB::SC_MEMSET:
102 case RTLIB::SC_MEMCHR:
103 KnownAttrs |= SMEAttrs::SM_Compatible;
104 break;
105 default:
106 break;
107 }
108 set(KnownAttrs);
109}
110
112 if (callee().hasStreamingCompatibleInterface())
113 return false;
114
115 // Both non-streaming
116 if (caller().hasNonStreamingInterfaceAndBody() &&
117 callee().hasNonStreamingInterface())
118 return false;
119
120 // Both streaming
121 if (caller().hasStreamingInterfaceOrBody() &&
122 callee().hasStreamingInterface())
123 return false;
124
125 return true;
126}
127
129 const RTLIB::RuntimeLibcallsInfo *RTLCI)
130 : CallerFn(*CB.getFunction()), CalledFn(SMEAttrs::Normal),
131 Callsite(CB.getAttributes()), IsIndirect(CB.isIndirectCall()) {
132 if (auto *CalledFunction = CB.getCalledFunction())
133 CalledFn = SMEAttrs(*CalledFunction, RTLCI);
134
135 // FIXME: We probably should not allow SME attributes on direct calls but
136 // clang duplicates streaming mode attributes at each callsite.
137 assert((IsIndirect || ((Callsite | CalledFn) == CalledFn)) &&
138 "SME attributes at callsite do not match declaration");
139
140 // An `invoke` of an agnostic ZA function may not return normally (it may
141 // resume in an exception block). In this case, it acts like a private ZA
142 // callee and may require a ZA save to be set up before it is called.
143 if (isa<InvokeInst>(CB))
144 CalledFn.set(SMEAttrs::ZA_State_Agnostic, /*Enable=*/false);
145}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static Function * getFunction(FunctionType *Ty, const Twine &Name, Module *M)
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
SMEAttrs is a utility class to parse the SME ACLE attributes on functions.
bool isPreservesZT0() const
bool hasStreamingInterface() const
static unsigned encodeZAState(StateValue S)
SMEAttrs()=default
bool hasStreamingCompatibleInterface() const
bool hasAgnosticZAInterface() const
bool isPreservesZA() const
void set(unsigned M, bool Enable=true)
bool hasSharedZAInterface() const
static unsigned encodeZT0State(StateValue S)
SMECallAttrs(SMEAttrs Caller, SMEAttrs Callee, SMEAttrs Callsite=SMEAttrs::Normal)
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
This is an optimization pass for GlobalISel generic memory operations.
static bool isIndirectCall(const MachineInstr &MI)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
A simple container for information about the supported runtime calls.
LLVM_ABI RTLIB::LibcallImpl getSupportedLibcallImpl(StringRef FuncName) const
Check if this is valid libcall for the current module, otherwise RTLIB::Unsupported.
static RTLIB::Libcall getLibcallFromImpl(RTLIB::LibcallImpl Impl)
Return the libcall provided by Impl.