LLVM  17.0.0git
AArch64SMEAttributes.h
Go to the documentation of this file.
1 //===-- AArch64SMEAttributes.h - 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 
9 #include "llvm/IR/Function.h"
10 
11 #ifndef LLVM_LIB_TARGET_AARCH64_UTILS_AARCH64SMEATTRIBUTES_H
12 #define LLVM_LIB_TARGET_AARCH64_UTILS_AARCH64SMEATTRIBUTES_H
13 namespace llvm {
14 
15 class Function;
16 class CallBase;
17 class AttributeList;
18 
19 /// SMEAttrs is a utility class to parse the SME ACLE attributes on functions.
20 /// It helps determine a function's requirements for PSTATE.ZA and PSTATE.SM. It
21 /// has interfaces to query whether a streaming mode change or lazy-save
22 /// mechanism is required when going from one function to another (e.g. through
23 /// a call).
24 class SMEAttrs {
25  unsigned Bitmask;
26 
27 public:
28  // Enum with bitmasks for each individual SME feature.
29  enum Mask {
30  Normal = 0,
31  SM_Enabled = 1 << 0, // aarch64_pstate_sm_enabled
32  SM_Compatible = 1 << 1, // aarch64_pstate_sm_compatible
33  SM_Body = 1 << 2, // aarch64_pstate_sm_locally
34  ZA_Shared = 1 << 3, // aarch64_pstate_sm_shared
35  ZA_New = 1 << 4, // aarch64_pstate_sm_new
36  ZA_Preserved = 1 << 5, // aarch64_pstate_sm_preserved
38  };
39 
40  SMEAttrs(unsigned Mask = Normal) : Bitmask(0) { set(Mask); }
42  SMEAttrs(const CallBase &CB);
43  SMEAttrs(const AttributeList &L);
44 
45  void set(unsigned M, bool Enable = true);
46 
47  // Interfaces to query PSTATE.SM
48  bool hasStreamingBody() const { return Bitmask & SM_Body; }
49  bool hasStreamingInterface() const { return Bitmask & SM_Enabled; }
52  }
54  return Bitmask & SM_Compatible;
55  }
56  bool hasNonStreamingInterface() const {
58  }
61  }
62 
63  /// \return true if a call from Caller -> Callee requires a change in
64  /// streaming mode.
65  /// If \p BodyOverridesInterface is true and Callee has a streaming body,
66  /// then requiresSMChange considers a call to Callee as having a Streaming
67  /// interface. This can be useful when considering e.g. inlining, where we
68  /// explicitly want the body to overrule the interface (because after inlining
69  /// the interface is no longer relevant).
70  std::optional<bool>
71  requiresSMChange(const SMEAttrs &Callee,
72  bool BodyOverridesInterface = false) const;
73 
74  // Interfaces to query PSTATE.ZA
75  bool hasNewZAInterface() const { return Bitmask & ZA_New; }
76  bool hasSharedZAInterface() const { return Bitmask & ZA_Shared; }
77  bool hasPrivateZAInterface() const { return !hasSharedZAInterface(); }
78  bool preservesZA() const { return Bitmask & ZA_Preserved; }
79  bool hasZAState() const {
81  }
82  bool requiresLazySave(const SMEAttrs &Callee) const {
83  return hasZAState() && Callee.hasPrivateZAInterface() &&
84  !Callee.preservesZA();
85  }
86 };
87 
88 } // namespace llvm
89 
90 #endif // LLVM_LIB_TARGET_AARCH64_UTILS_AARCH64SMEATTRIBUTES_H
llvm::SMEAttrs::hasZAState
bool hasZAState() const
Definition: AArch64SMEAttributes.h:79
llvm::SMEAttrs::hasStreamingInterface
bool hasStreamingInterface() const
Definition: AArch64SMEAttributes.h:49
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::Function
Definition: Function.h:59
llvm::AttributeList
Definition: Attributes.h:432
llvm::Intrinsic::getAttributes
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
llvm::SMEAttrs::SM_Body
@ SM_Body
Definition: AArch64SMEAttributes.h:33
llvm::SMEAttrs::requiresSMChange
std::optional< bool > requiresSMChange(const SMEAttrs &Callee, bool BodyOverridesInterface=false) const
Definition: AArch64SMEAttributes.cpp:52
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::SMEAttrs
SMEAttrs is a utility class to parse the SME ACLE attributes on functions.
Definition: AArch64SMEAttributes.h:24
llvm::SMEAttrs::hasNewZAInterface
bool hasNewZAInterface() const
Definition: AArch64SMEAttributes.h:75
llvm::SMEAttrs::SMEAttrs
SMEAttrs(const Function &F)
Definition: AArch64SMEAttributes.h:41
llvm::SMEAttrs::ZA_Shared
@ ZA_Shared
Definition: AArch64SMEAttributes.h:34
llvm::SMEAttrs::SM_Enabled
@ SM_Enabled
Definition: AArch64SMEAttributes.h:31
llvm::SMEAttrs::Normal
@ Normal
Definition: AArch64SMEAttributes.h:30
llvm::SMEAttrs::SMEAttrs
SMEAttrs(unsigned Mask=Normal)
Definition: AArch64SMEAttributes.h:40
llvm::SMEAttrs::preservesZA
bool preservesZA() const
Definition: AArch64SMEAttributes.h:78
llvm::SMEAttrs::hasStreamingInterfaceOrBody
bool hasStreamingInterfaceOrBody() const
Definition: AArch64SMEAttributes.h:50
llvm::SMEAttrs::hasNonStreamingInterface
bool hasNonStreamingInterface() const
Definition: AArch64SMEAttributes.h:56
llvm::SMEAttrs::ZA_New
@ ZA_New
Definition: AArch64SMEAttributes.h:35
llvm::SMEAttrs::hasPrivateZAInterface
bool hasPrivateZAInterface() const
Definition: AArch64SMEAttributes.h:77
llvm::SMEAttrs::Mask
Mask
Definition: AArch64SMEAttributes.h:29
llvm::SMEAttrs::hasSharedZAInterface
bool hasSharedZAInterface() const
Definition: AArch64SMEAttributes.h:76
llvm::SMEAttrs::SM_Compatible
@ SM_Compatible
Definition: AArch64SMEAttributes.h:32
llvm::SMEAttrs::All
@ All
Definition: AArch64SMEAttributes.h:37
Callee
amdgpu Simplify well known AMD library false FunctionCallee Callee
Definition: AMDGPULibCalls.cpp:187
Function.h
llvm::SMEAttrs::hasStreamingCompatibleInterface
bool hasStreamingCompatibleInterface() const
Definition: AArch64SMEAttributes.h:53
llvm::CallBase
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1184
llvm::SMEAttrs::hasStreamingBody
bool hasStreamingBody() const
Definition: AArch64SMEAttributes.h:48
llvm::SMEAttrs::ZA_Preserved
@ ZA_Preserved
Definition: AArch64SMEAttributes.h:36
llvm::SMEAttrs::requiresLazySave
bool requiresLazySave(const SMEAttrs &Callee) const
Definition: AArch64SMEAttributes.h:82
llvm::codeview::PublicSymFlags::Function
@ Function
llvm::SMEAttrs::hasNonStreamingInterfaceAndBody
bool hasNonStreamingInterfaceAndBody() const
Definition: AArch64SMEAttributes.h:59
llvm::SMEAttrs::set
void set(unsigned M, bool Enable=true)
Definition: AArch64SMEAttributes.cpp:15