AArch64SMEAttributes.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. #include "llvm/IR/Function.h"
  9. #ifndef LLVM_LIB_TARGET_AARCH64_UTILS_AARCH64SMEATTRIBUTES_H
  10. #define LLVM_LIB_TARGET_AARCH64_UTILS_AARCH64SMEATTRIBUTES_H
  11. namespace llvm {
  12. class Function;
  13. class CallBase;
  14. class AttributeList;
  15. /// SMEAttrs is a utility class to parse the SME ACLE attributes on functions.
  16. /// It helps determine a function's requirements for PSTATE.ZA and PSTATE.SM. It
  17. /// has interfaces to query whether a streaming mode change or lazy-save
  18. /// mechanism is required when going from one function to another (e.g. through
  19. /// a call).
  20. class SMEAttrs {
  21. unsigned Bitmask;
  22. public:
  23. // Enum with bitmasks for each individual SME feature.
  24. enum Mask {
  25. Normal = 0,
  26. SM_Enabled = 1 << 0, // aarch64_pstate_sm_enabled
  27. SM_Compatible = 1 << 1, // aarch64_pstate_sm_compatible
  28. SM_Body = 1 << 2, // aarch64_pstate_sm_locally
  29. ZA_Shared = 1 << 3, // aarch64_pstate_sm_shared
  30. ZA_New = 1 << 4, // aarch64_pstate_sm_new
  31. ZA_Preserved = 1 << 5, // aarch64_pstate_sm_preserved
  32. All = ZA_Preserved - 1
  33. };
  34. SMEAttrs(unsigned Mask = Normal) : Bitmask(0) { set(Mask); }
  35. SMEAttrs(const Function &F) : SMEAttrs(F.getAttributes()) {}
  36. SMEAttrs(const CallBase &CB);
  37. SMEAttrs(const AttributeList &L);
  38. void set(unsigned M, bool Enable = true);
  39. // Interfaces to query PSTATE.SM
  40. bool hasStreamingBody() const { return Bitmask & SM_Body; }
  41. bool hasStreamingInterface() const { return Bitmask & SM_Enabled; }
  42. bool hasStreamingInterfaceOrBody() const {
  43. return hasStreamingBody() || hasStreamingInterface();
  44. }
  45. bool hasStreamingCompatibleInterface() const {
  46. return Bitmask & SM_Compatible;
  47. }
  48. bool hasNonStreamingInterface() const {
  49. return !hasStreamingInterface() && !hasStreamingCompatibleInterface();
  50. }
  51. bool hasNonStreamingInterfaceAndBody() const {
  52. return hasNonStreamingInterface() && !hasStreamingBody();
  53. }
  54. /// \return true if a call from Caller -> Callee requires a change in
  55. /// streaming mode.
  56. /// If \p BodyOverridesInterface is true and Callee has a streaming body,
  57. /// then requiresSMChange considers a call to Callee as having a Streaming
  58. /// interface. This can be useful when considering e.g. inlining, where we
  59. /// explicitly want the body to overrule the interface (because after inlining
  60. /// the interface is no longer relevant).
  61. std::optional<bool>
  62. requiresSMChange(const SMEAttrs &Callee,
  63. bool BodyOverridesInterface = false) const;
  64. // Interfaces to query PSTATE.ZA
  65. bool hasNewZAInterface() const { return Bitmask & ZA_New; }
  66. bool hasSharedZAInterface() const { return Bitmask & ZA_Shared; }
  67. bool hasPrivateZAInterface() const { return !hasSharedZAInterface(); }
  68. bool preservesZA() const { return Bitmask & ZA_Preserved; }
  69. bool hasZAState() const {
  70. return hasNewZAInterface() || hasSharedZAInterface();
  71. }
  72. bool requiresLazySave(const SMEAttrs &Callee) const {
  73. return hasZAState() && Callee.hasPrivateZAInterface() &&
  74. !Callee.preservesZA();
  75. }
  76. };
  77. } // namespace llvm
  78. #endif // LLVM_LIB_TARGET_AARCH64_UTILS_AARCH64SMEATTRIBUTES_H